< prev index next >

src/hotspot/share/gc/shared/memAllocator.cpp

Print this page




 366 oop MemAllocator::allocate() const {
 367   oop obj = NULL;
 368   {
 369     Allocation allocation(*this, &obj);
 370     HeapWord* mem = mem_allocate(allocation);
 371     if (mem != NULL) {
 372       obj = initialize(mem);
 373     }
 374   }
 375   return obj;
 376 }
 377 
 378 void MemAllocator::mem_clear(HeapWord* mem) const {
 379   assert(mem != NULL, "cannot initialize NULL object");
 380   const size_t hs = oopDesc::header_size();
 381   assert(_word_size >= hs, "unexpected object size");
 382   oopDesc::set_klass_gap(mem, 0);
 383   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
 384 }
 385 
 386 oop MemAllocator::finish(HeapWord* mem) const {
 387   assert(mem != NULL, "NULL object pointer");
 388   if (UseBiasedLocking) {
 389     oopDesc::set_mark_raw(mem, _klass->prototype_header());
 390   } else {
 391     // May be bootstrapping
 392     oopDesc::set_mark_raw(mem, markOopDesc::prototype());
 393   }
 394   // Need a release store to ensure array/class length, mark word, and
 395   // object zeroing are visible before setting the klass non-NULL, for
 396   // concurrent collectors.
 397   oopDesc::release_set_klass(mem, _klass);
 398   return oop(mem);
 399 }
 400 






 401 oop ObjAllocator::initialize(HeapWord* mem) const {
 402   mem_clear(mem);
 403   return finish(mem);
 404 }
 405 
 406 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
 407   if (_do_zero) {
 408     return MemAllocator::obj_memory_range(obj);
 409   }
 410   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
 411   const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
 412   return MemRegion(((HeapWord*)obj) + hs, _word_size - hs);
 413 }
 414 
 415 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
 416   // Set array length before setting the _klass field because a
 417   // non-NULL klass field indicates that the object is parsable by
 418   // concurrent GC.
 419   assert(_length >= 0, "length should be non-negative");
 420   if (_do_zero) {
 421     mem_clear(mem);
 422   }
 423   arrayOopDesc::set_length(mem, _length);
 424   return finish(mem);


 425 }
 426 
 427 oop ClassAllocator::initialize(HeapWord* mem) const {
 428   // Set oop_size field before setting the _klass field because a
 429   // non-NULL _klass field indicates that the object is parsable by
 430   // concurrent GC.
 431   assert(_word_size > 0, "oop_size must be positive.");
 432   mem_clear(mem);
 433   java_lang_Class::set_oop_size(mem, (int)_word_size);
 434   return finish(mem);
 435 }


 366 oop MemAllocator::allocate() const {
 367   oop obj = NULL;
 368   {
 369     Allocation allocation(*this, &obj);
 370     HeapWord* mem = mem_allocate(allocation);
 371     if (mem != NULL) {
 372       obj = initialize(mem);
 373     }
 374   }
 375   return obj;
 376 }
 377 
 378 void MemAllocator::mem_clear(HeapWord* mem) const {
 379   assert(mem != NULL, "cannot initialize NULL object");
 380   const size_t hs = oopDesc::header_size();
 381   assert(_word_size >= hs, "unexpected object size");
 382   oopDesc::set_klass_gap(mem, 0);
 383   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
 384 }
 385 
 386 inline void MemAllocator::finish_mark(HeapWord* mem) const {
 387   assert(mem != NULL, "NULL object pointer");
 388   oopDesc::set_mark_raw(mem, Klass::default_prototype_header(_klass));
 389 }
 390 
 391 oop MemAllocator::finish(HeapWord* mem) const {
 392   finish_mark(mem);

 393   // Need a release store to ensure array/class length, mark word, and
 394   // object zeroing are visible before setting the klass non-NULL, for
 395   // concurrent collectors.
 396   oopDesc::release_set_klass(mem, _klass);
 397   return oop(mem);
 398 }
 399 
 400 oop MemAllocator::finish_with_properties(HeapWord* mem, ArrayStorageProperties storage_props) const {
 401   finish_mark(mem);
 402   oopDesc::release_set_metadata(mem, storage_props, _klass);
 403   return oop(mem);
 404 }
 405 
 406 oop ObjAllocator::initialize(HeapWord* mem) const {
 407   mem_clear(mem);
 408   return finish(mem);
 409 }
 410 
 411 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
 412   if (_do_zero) {
 413     return MemAllocator::obj_memory_range(obj);
 414   }
 415   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
 416   const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
 417   return MemRegion(((HeapWord*)obj) + hs, _word_size - hs);
 418 }
 419 
 420 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
 421   // Set array length before setting the _klass field because a
 422   // non-NULL klass field indicates that the object is parsable by
 423   // concurrent GC.
 424   assert(_length >= 0, "length should be non-negative");
 425   if (_do_zero) {
 426     mem_clear(mem);
 427   }
 428   arrayOopDesc::set_length(mem, _length);
 429   assert(ArrayKlass::cast(_klass)->storage_properties().is_empty() ||
 430       ArrayKlass::cast(_klass)->dimension() == 1, "Multidim should have no storage props");
 431   return finish_with_properties(mem, ArrayKlass::cast(_klass)->storage_properties());
 432 }
 433 
 434 oop ClassAllocator::initialize(HeapWord* mem) const {
 435   // Set oop_size field before setting the _klass field because a
 436   // non-NULL _klass field indicates that the object is parsable by
 437   // concurrent GC.
 438   assert(_word_size > 0, "oop_size must be positive.");
 439   mem_clear(mem);
 440   java_lang_Class::set_oop_size(mem, (int)_word_size);
 441   return finish(mem);
 442 }
< prev index next >