8202994: Add support for undoing last TLAB allocation

Reviewed-by: shade, stefank
This commit is contained in:
Per Lidén 2018-05-14 15:42:58 +02:00
parent d822b86df8
commit a6b12a847c
2 changed files with 18 additions and 0 deletions

View file

@ -79,6 +79,8 @@ private:
size_t remaining() const { return end() == NULL ? 0 : pointer_delta(hard_end(), top()); } 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. // Make parsable and release it.
void reset(); void reset();
@ -129,6 +131,9 @@ public:
// Allocate size HeapWords. The memory is NOT initialized to zero. // Allocate size HeapWords. The memory is NOT initialized to zero.
inline HeapWord* allocate(size_t size); 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 // Reserve space at the end of TLAB
static size_t end_reserve() { static size_t end_reserve() {
int reserve_size = typeArrayOopDesc::header_size(T_INT); int reserve_size = typeArrayOopDesc::header_size(T_INT);

View file

@ -53,6 +53,19 @@ inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) {
return NULL; 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) { inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) {
// Compute the size for the new TLAB. // Compute the size for the new TLAB.
// The "last" tlab may be smaller to reduce fragmentation. // The "last" tlab may be smaller to reduce fragmentation.