# HG changeset patch # User ysr # Date 1236977761 25200 # Node ID 3c71d9b4b8e6ac275180501fd48d57736494381c # Parent 2f308c52f0a5296cb8cf68078fe4efcc7e05d33f 6808322: ParNew, CMS, G1: ParGCAllocBuffer overflow Summary: Correct the overflow check in ParGCAllocBuffer::allocate(); simplify ParGCAllocBuffer::undo_allocation(). Reviewed-by: apetrusenko, jcoomes, jmasa, minqi, phh, tonyp diff -r 2f308c52f0a5 -r 3c71d9b4b8e6 hotspot/src/share/vm/gc_implementation/parNew/parGCAllocBuffer.hpp --- a/hotspot/src/share/vm/gc_implementation/parNew/parGCAllocBuffer.hpp Thu Mar 12 14:01:36 2009 -0700 +++ b/hotspot/src/share/vm/gc_implementation/parNew/parGCAllocBuffer.hpp Fri Mar 13 13:56:01 2009 -0700 @@ -63,9 +63,8 @@ // return NULL. HeapWord* allocate(size_t word_sz) { HeapWord* res = _top; - HeapWord* new_top = _top + word_sz; - if (new_top <= _end) { - _top = new_top; + if (pointer_delta(_end, _top) >= word_sz) { + _top = _top + word_sz; return res; } else { return NULL; @@ -75,10 +74,9 @@ // Undo the last allocation in the buffer, which is required to be of the // "obj" of the given "word_sz". void undo_allocation(HeapWord* obj, size_t word_sz) { - assert(_top - word_sz >= _bottom - && _top - word_sz == obj, - "Bad undo_allocation"); - _top = _top - word_sz; + assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo"); + assert(pointer_delta(_top, obj) == word_sz, "Bad undo"); + _top = obj; } // The total (word) size of the buffer, including both allocated and