< prev index next >

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

Print this page

382 oop MemAllocator::allocate() const {
383   oop obj = nullptr;
384   {
385     Allocation allocation(*this, &obj);
386     HeapWord* mem = mem_allocate(allocation);
387     if (mem != nullptr) {
388       obj = initialize(mem);
389     } else {
390       // The unhandled oop detector will poison local variable obj,
391       // so reset it to null if mem is null.
392       obj = nullptr;
393     }
394   }
395   return obj;
396 }
397 
398 void MemAllocator::mem_clear(HeapWord* mem) const {
399   assert(mem != nullptr, "cannot initialize null object");
400   const size_t hs = oopDesc::header_size();
401   assert(_word_size >= hs, "unexpected object size");
402   oopDesc::set_klass_gap(mem, 0);


403   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
404 }
405 
406 oop MemAllocator::finish(HeapWord* mem) const {
407   assert(mem != nullptr, "null object pointer");
408   // May be bootstrapping
409   oopDesc::set_mark(mem, markWord::prototype());
410   // Need a release store to ensure array/class length, mark word, and
411   // object zeroing are visible before setting the klass non-null, for
412   // concurrent collectors.
413   oopDesc::release_set_klass(mem, _klass);





414   return cast_to_oop(mem);
415 }
416 
417 oop ObjAllocator::initialize(HeapWord* mem) const {
418   mem_clear(mem);
419   return finish(mem);
420 }
421 
422 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
423   if (_do_zero) {
424     return MemAllocator::obj_memory_range(obj);
425   }
426   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
427   const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
428   return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
429 }
430 
431 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
432   // Set array length before setting the _klass field because a
433   // non-null klass field indicates that the object is parsable by
434   // concurrent GC.
435   assert(_length >= 0, "length should be non-negative");
436   if (_do_zero) {
437     mem_clear(mem);
438   }
439   arrayOopDesc::set_length(mem, _length);
440   return finish(mem);
441 }
442 
443 oop ClassAllocator::initialize(HeapWord* mem) const {
444   // Set oop_size field before setting the _klass field because a
445   // non-null _klass field indicates that the object is parsable by
446   // concurrent GC.
447   assert(_word_size > 0, "oop_size must be positive.");

382 oop MemAllocator::allocate() const {
383   oop obj = nullptr;
384   {
385     Allocation allocation(*this, &obj);
386     HeapWord* mem = mem_allocate(allocation);
387     if (mem != nullptr) {
388       obj = initialize(mem);
389     } else {
390       // The unhandled oop detector will poison local variable obj,
391       // so reset it to null if mem is null.
392       obj = nullptr;
393     }
394   }
395   return obj;
396 }
397 
398 void MemAllocator::mem_clear(HeapWord* mem) const {
399   assert(mem != nullptr, "cannot initialize null object");
400   const size_t hs = oopDesc::header_size();
401   assert(_word_size >= hs, "unexpected object size");
402   if (!UseCompactObjectHeaders) {
403     oopDesc::set_klass_gap(mem, 0);
404   }
405   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
406 }
407 
408 oop MemAllocator::finish(HeapWord* mem) const {
409   assert(mem != nullptr, "null object pointer");


410   // Need a release store to ensure array/class length, mark word, and
411   // object zeroing are visible before setting the klass non-null, for
412   // concurrent collectors.
413   if (UseCompactObjectHeaders) {
414     oopDesc::release_set_mark(mem, _klass->prototype_header());
415   } else {
416     oopDesc::set_mark(mem, markWord::prototype());
417     oopDesc::release_set_klass(mem, _klass);
418   }
419   return cast_to_oop(mem);
420 }
421 
422 oop ObjAllocator::initialize(HeapWord* mem) const {
423   mem_clear(mem);
424   return finish(mem);
425 }
426 
427 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
428   if (_do_zero) {
429     return MemAllocator::obj_memory_range(obj);
430   }
431   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
432   const size_t hs = align_up(arrayOopDesc::base_offset_in_bytes(array_klass->element_type()), HeapWordSize) / HeapWordSize;
433   return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
434 }
435 
436 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
437   // Set array length before setting the _klass field because a
438   // non-null klass field indicates that the object is parsable by
439   // concurrent GC.
440   assert(_length >= 0, "length should be non-negative");
441   if (_do_zero) {
442     mem_clear(mem);
443   }
444   arrayOopDesc::set_length(mem, _length);
445   return finish(mem);
446 }
447 
448 oop ClassAllocator::initialize(HeapWord* mem) const {
449   // Set oop_size field before setting the _klass field because a
450   // non-null _klass field indicates that the object is parsable by
451   // concurrent GC.
452   assert(_word_size > 0, "oop_size must be positive.");
< prev index next >