< prev index next >

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

Print this page

363 oop MemAllocator::allocate() const {
364   oop obj = nullptr;
365   {
366     Allocation allocation(*this, &obj);
367     HeapWord* mem = mem_allocate(allocation);
368     if (mem != nullptr) {
369       obj = initialize(mem);
370     } else {
371       // The unhandled oop detector will poison local variable obj,
372       // so reset it to null if mem is null.
373       obj = nullptr;
374     }
375   }
376   return obj;
377 }
378 
379 void MemAllocator::mem_clear(HeapWord* mem) const {
380   assert(mem != nullptr, "cannot initialize null object");
381   const size_t hs = oopDesc::header_size();
382   assert(_word_size >= hs, "unexpected object size");
383   oopDesc::set_klass_gap(mem, 0);


384   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
385 }
386 
387 oop MemAllocator::finish(HeapWord* mem) const {
388   assert(mem != nullptr, "null object pointer");
389   // May be bootstrapping
390   oopDesc::set_mark(mem, markWord::prototype());
391   // Need a release store to ensure array/class length, mark word, and
392   // object zeroing are visible before setting the klass non-null, for
393   // concurrent collectors.
394   oopDesc::release_set_klass(mem, _klass);





395   return cast_to_oop(mem);
396 }
397 
398 oop ObjAllocator::initialize(HeapWord* mem) const {
399   mem_clear(mem);
400   return finish(mem);
401 }
402 
403 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
404   // Set array length before setting the _klass field because a
405   // non-null klass field indicates that the object is parsable by
406   // concurrent GC.
407   assert(_length >= 0, "length should be non-negative");
408   if (_do_zero) {
409     mem_clear(mem);
410   }
411   arrayOopDesc::set_length(mem, _length);
412   return finish(mem);
413 }
414 

363 oop MemAllocator::allocate() const {
364   oop obj = nullptr;
365   {
366     Allocation allocation(*this, &obj);
367     HeapWord* mem = mem_allocate(allocation);
368     if (mem != nullptr) {
369       obj = initialize(mem);
370     } else {
371       // The unhandled oop detector will poison local variable obj,
372       // so reset it to null if mem is null.
373       obj = nullptr;
374     }
375   }
376   return obj;
377 }
378 
379 void MemAllocator::mem_clear(HeapWord* mem) const {
380   assert(mem != nullptr, "cannot initialize null object");
381   const size_t hs = oopDesc::header_size();
382   assert(_word_size >= hs, "unexpected object size");
383   if (!UseCompactObjectHeaders) {
384     oopDesc::set_klass_gap(mem, 0);
385   }
386   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
387 }
388 
389 oop MemAllocator::finish(HeapWord* mem) const {
390   assert(mem != nullptr, "null object pointer");


391   // Need a release store to ensure array/class length, mark word, and
392   // object zeroing are visible before setting the klass non-null, for
393   // concurrent collectors.
394   if (UseCompactObjectHeaders) {
395     oopDesc::release_set_mark(mem, _klass->prototype_header());
396   } else {
397     oopDesc::set_mark(mem, markWord::prototype());
398     oopDesc::release_set_klass(mem, _klass);
399   }
400   return cast_to_oop(mem);
401 }
402 
403 oop ObjAllocator::initialize(HeapWord* mem) const {
404   mem_clear(mem);
405   return finish(mem);
406 }
407 
408 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
409   // Set array length before setting the _klass field because a
410   // non-null klass field indicates that the object is parsable by
411   // concurrent GC.
412   assert(_length >= 0, "length should be non-negative");
413   if (_do_zero) {
414     mem_clear(mem);
415   }
416   arrayOopDesc::set_length(mem, _length);
417   return finish(mem);
418 }
419 
< prev index next >