< prev index next >

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

Print this page

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


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





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

360 oop MemAllocator::allocate() const {
361   oop obj = nullptr;
362   {
363     Allocation allocation(*this, &obj);
364     HeapWord* mem = mem_allocate(allocation);
365     if (mem != nullptr) {
366       obj = initialize(mem);
367     } else {
368       // The unhandled oop detector will poison local variable obj,
369       // so reset it to null if mem is null.
370       obj = nullptr;
371     }
372   }
373   return obj;
374 }
375 
376 void MemAllocator::mem_clear(HeapWord* mem) const {
377   assert(mem != nullptr, "cannot initialize null object");
378   const size_t hs = oopDesc::header_size();
379   assert(_word_size >= hs, "unexpected object size");
380   if (!UseCompactObjectHeaders) {
381     oopDesc::set_klass_gap(mem, 0);
382   }
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   // Need a release store to ensure array/class length, mark word, and
389   // object zeroing are visible before setting the klass non-null, for
390   // concurrent collectors.
391   if (UseCompactObjectHeaders) {
392     oopDesc::release_set_mark(mem, _klass->prototype_header());
393   } else {
394     oopDesc::set_mark(mem, markWord::prototype());
395     oopDesc::release_set_klass(mem, _klass);
396   }
397   return cast_to_oop(mem);
398 }
399 
400 oop ObjAllocator::initialize(HeapWord* mem) const {
401   mem_clear(mem);
402   return finish(mem);
403 }
404 
405 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
406   // Set array length before setting the _klass field because a
407   // non-null klass field indicates that the object is parsable by
408   // concurrent GC.
409   assert(_length >= 0, "length should be non-negative");
410   if (_do_zero) {
411     mem_clear(mem);
412   }
413   arrayOopDesc::set_length(mem, _length);
414   return finish(mem);
415 }
416 
< prev index next >