changeset 50650:1560c3a7fbbf

8202994: Add support for undoing last TLAB allocation Reviewed-by: shade, stefank
author pliden
date Mon, 14 May 2018 15:42:58 +0200
parents 78d93a34b81d
children 454fa295105c
files src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp src/hotspot/share/gc/shared/threadLocalAllocBuffer.inline.hpp
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp	Mon May 14 14:10:52 2018 +0200
+++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp	Mon May 14 15:42:58 2018 +0200
@@ -79,6 +79,8 @@
 
   size_t remaining() const                       { return end() == NULL ? 0 : pointer_delta(hard_end(), top()); }
 
+  bool is_last_allocation(HeapWord* obj, size_t size) { return pointer_delta(top(), obj) == size; }
+
   // Make parsable and release it.
   void reset();
 
@@ -129,6 +131,9 @@
   // Allocate size HeapWords. The memory is NOT initialized to zero.
   inline HeapWord* allocate(size_t size);
 
+  // Undo last allocation.
+  inline bool undo_allocate(HeapWord* obj, size_t size);
+
   // Reserve space at the end of TLAB
   static size_t end_reserve() {
     int reserve_size = typeArrayOopDesc::header_size(T_INT);
--- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.inline.hpp	Mon May 14 14:10:52 2018 +0200
+++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.inline.hpp	Mon May 14 15:42:58 2018 +0200
@@ -53,6 +53,19 @@
   return NULL;
 }
 
+inline bool ThreadLocalAllocBuffer::undo_allocate(HeapWord* obj, size_t size) {
+  invariants();
+
+  if (!is_last_allocation(obj, size)) {
+    return false;
+  }
+
+  set_top(obj);
+
+  invariants();
+  return true;
+}
+
 inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) {
   // Compute the size for the new TLAB.
   // The "last" tlab may be smaller to reduce fragmentation.