src/hotspot/share/gc/parallel/mutableSpace.cpp
changeset 59252 623722a6aeb9
parent 58980 47c20fc6a517
equal deleted inserted replaced
59251:4cbfa5077d68 59252:623722a6aeb9
   192 HeapWord* MutableSpace::cas_allocate(size_t size) {
   192 HeapWord* MutableSpace::cas_allocate(size_t size) {
   193   do {
   193   do {
   194     HeapWord* obj = top();
   194     HeapWord* obj = top();
   195     if (pointer_delta(end(), obj) >= size) {
   195     if (pointer_delta(end(), obj) >= size) {
   196       HeapWord* new_top = obj + size;
   196       HeapWord* new_top = obj + size;
   197       HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
   197       HeapWord* result = Atomic::cmpxchg(top_addr(), obj, new_top);
   198       // result can be one of two:
   198       // result can be one of two:
   199       //  the old top value: the exchange succeeded
   199       //  the old top value: the exchange succeeded
   200       //  otherwise: the new value of the top is returned.
   200       //  otherwise: the new value of the top is returned.
   201       if (result != obj) {
   201       if (result != obj) {
   202         continue; // another thread beat us to the allocation, try again
   202         continue; // another thread beat us to the allocation, try again
   211 }
   211 }
   212 
   212 
   213 // Try to deallocate previous allocation. Returns true upon success.
   213 // Try to deallocate previous allocation. Returns true upon success.
   214 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
   214 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
   215   HeapWord* expected_top = obj + size;
   215   HeapWord* expected_top = obj + size;
   216   return Atomic::cmpxchg(obj, top_addr(), expected_top) == expected_top;
   216   return Atomic::cmpxchg(top_addr(), expected_top, obj) == expected_top;
   217 }
   217 }
   218 
   218 
   219 void MutableSpace::oop_iterate(OopIterateClosure* cl) {
   219 void MutableSpace::oop_iterate(OopIterateClosure* cl) {
   220   HeapWord* obj_addr = bottom();
   220   HeapWord* obj_addr = bottom();
   221   HeapWord* t = top();
   221   HeapWord* t = top();