< prev index next >

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

Print this page

362 oop MemAllocator::allocate() const {
363   oop obj = nullptr;
364   {
365     Allocation allocation(*this, &obj);
366     HeapWord* mem = mem_allocate(allocation);
367     if (mem != nullptr) {
368       obj = initialize(mem);
369     } else {
370       // The unhandled oop detector will poison local variable obj,
371       // so reset it to null if mem is null.
372       obj = nullptr;
373     }
374   }
375   return obj;
376 }
377 
378 void MemAllocator::mem_clear(HeapWord* mem) const {
379   assert(mem != nullptr, "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 != nullptr, "null object pointer");
388   // May be bootstrapping
389   oopDesc::set_mark(mem, markWord::prototype());
390   // Need a release store to ensure array/class length, mark word, and
391   // object zeroing are visible before setting the klass non-null, for
392   // concurrent collectors.
393   oopDesc::release_set_klass(mem, _klass);





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

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


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