< prev index next >

src/hotspot/share/gc/parallel/mutableSpace.cpp

Print this page




 177           Thread::current()->is_VM_thread()),
 178          "not locked");
 179   HeapWord* obj = top();
 180   if (pointer_delta(end(), obj) >= size) {
 181     HeapWord* new_top = obj + size;
 182     set_top(new_top);
 183     assert(is_object_aligned(obj) && is_object_aligned(new_top),
 184            "checking alignment");
 185     return obj;
 186   } else {
 187     return NULL;
 188   }
 189 }
 190 
 191 // This version is lock-free.
 192 HeapWord* MutableSpace::cas_allocate(size_t size) {
 193   do {
 194     HeapWord* obj = top();
 195     if (pointer_delta(end(), obj) >= size) {
 196       HeapWord* new_top = obj + size;
 197       HeapWord* result = Atomic::cmpxchg(new_top, top_addr(), obj);
 198       // result can be one of two:
 199       //  the old top value: the exchange succeeded
 200       //  otherwise: the new value of the top is returned.
 201       if (result != obj) {
 202         continue; // another thread beat us to the allocation, try again
 203       }
 204       assert(is_object_aligned(obj) && is_object_aligned(new_top),
 205              "checking alignment");
 206       return obj;
 207     } else {
 208       return NULL;
 209     }
 210   } while (true);
 211 }
 212 
 213 // Try to deallocate previous allocation. Returns true upon success.
 214 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
 215   HeapWord* expected_top = obj + size;
 216   return Atomic::cmpxchg(obj, top_addr(), expected_top) == expected_top;
 217 }
 218 
 219 void MutableSpace::oop_iterate(OopIterateClosure* cl) {
 220   HeapWord* obj_addr = bottom();
 221   HeapWord* t = top();
 222   // Could call objects iterate, but this is easier.
 223   while (obj_addr < t) {
 224     obj_addr += oop(obj_addr)->oop_iterate_size(cl);
 225   }
 226 }
 227 
 228 void MutableSpace::object_iterate(ObjectClosure* cl) {
 229   HeapWord* p = bottom();
 230   while (p < top()) {
 231     cl->do_object(oop(p));
 232     p += oop(p)->size();
 233   }
 234 }
 235 
 236 void MutableSpace::print_short() const { print_short_on(tty); }




 177           Thread::current()->is_VM_thread()),
 178          "not locked");
 179   HeapWord* obj = top();
 180   if (pointer_delta(end(), obj) >= size) {
 181     HeapWord* new_top = obj + size;
 182     set_top(new_top);
 183     assert(is_object_aligned(obj) && is_object_aligned(new_top),
 184            "checking alignment");
 185     return obj;
 186   } else {
 187     return NULL;
 188   }
 189 }
 190 
 191 // This version is lock-free.
 192 HeapWord* MutableSpace::cas_allocate(size_t size) {
 193   do {
 194     HeapWord* obj = top();
 195     if (pointer_delta(end(), obj) >= size) {
 196       HeapWord* new_top = obj + size;
 197       HeapWord* result = Atomic::cmpxchg(top_addr(), obj, new_top);
 198       // result can be one of two:
 199       //  the old top value: the exchange succeeded
 200       //  otherwise: the new value of the top is returned.
 201       if (result != obj) {
 202         continue; // another thread beat us to the allocation, try again
 203       }
 204       assert(is_object_aligned(obj) && is_object_aligned(new_top),
 205              "checking alignment");
 206       return obj;
 207     } else {
 208       return NULL;
 209     }
 210   } while (true);
 211 }
 212 
 213 // Try to deallocate previous allocation. Returns true upon success.
 214 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
 215   HeapWord* expected_top = obj + size;
 216   return Atomic::cmpxchg(top_addr(), expected_top, obj) == expected_top;
 217 }
 218 
 219 void MutableSpace::oop_iterate(OopIterateClosure* cl) {
 220   HeapWord* obj_addr = bottom();
 221   HeapWord* t = top();
 222   // Could call objects iterate, but this is easier.
 223   while (obj_addr < t) {
 224     obj_addr += oop(obj_addr)->oop_iterate_size(cl);
 225   }
 226 }
 227 
 228 void MutableSpace::object_iterate(ObjectClosure* cl) {
 229   HeapWord* p = bottom();
 230   while (p < top()) {
 231     cl->do_object(oop(p));
 232     p += oop(p)->size();
 233   }
 234 }
 235 
 236 void MutableSpace::print_short() const { print_short_on(tty); }


< prev index next >