< prev index next >

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

Print this page

356   }
357   return obj;
358 }
359 
360 void MemAllocator::mem_clear(HeapWord* mem) const {
361   assert(mem != nullptr, "cannot initialize null object");
362   const size_t hs = oopDesc::header_size();
363   assert(_word_size >= hs, "unexpected object size");
364   if (oopDesc::has_klass_gap()) {
365     oopDesc::set_klass_gap(mem, 0);
366   }
367   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
368 }
369 
370 oop MemAllocator::finish(HeapWord* mem) const {
371   assert(mem != nullptr, "null object pointer");
372   // Need a release store to ensure array/class length, mark word, and
373   // object zeroing are visible before setting the klass non-null, for
374   // concurrent collectors.
375   if (UseCompactObjectHeaders) {
376     oopDesc::release_set_mark(mem, _klass->prototype_header());
377   } else {
378     oopDesc::set_mark(mem, markWord::prototype());




379     oopDesc::release_set_klass(mem, _klass);
380   }
381   return cast_to_oop(mem);
382 }
383 
384 oop ObjAllocator::initialize(HeapWord* mem) const {
385   mem_clear(mem);
386   return finish(mem);
387 }
388 






389 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
390   // Set array length before setting the _klass field because a
391   // non-null klass field indicates that the object is parsable by
392   // concurrent GC.
393   assert(_length >= 0, "length should be non-negative");
394   if (_do_zero) {
395     mem_clear(mem);
396     mem_zap_start_padding(mem);
397     mem_zap_end_padding(mem);
398   }
399   arrayOopDesc::set_length(mem, _length);
400   return finish(mem);
401 }
402 
403 #ifndef PRODUCT
404 void ObjArrayAllocator::mem_zap_start_padding(HeapWord* mem) const {
405   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
406   const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
407   const size_t header_size_in_bytes = arrayOopDesc::header_size_in_bytes();
408 

356   }
357   return obj;
358 }
359 
360 void MemAllocator::mem_clear(HeapWord* mem) const {
361   assert(mem != nullptr, "cannot initialize null object");
362   const size_t hs = oopDesc::header_size();
363   assert(_word_size >= hs, "unexpected object size");
364   if (oopDesc::has_klass_gap()) {
365     oopDesc::set_klass_gap(mem, 0);
366   }
367   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
368 }
369 
370 oop MemAllocator::finish(HeapWord* mem) const {
371   assert(mem != nullptr, "null object pointer");
372   // Need a release store to ensure array/class length, mark word, and
373   // object zeroing are visible before setting the klass non-null, for
374   // concurrent collectors.
375   if (UseCompactObjectHeaders) {
376     oopDesc::release_set_mark(mem, Klass::default_prototype_header(_klass));
377   } else {
378     if (EnableValhalla) {
379       oopDesc::set_mark(mem, Klass::default_prototype_header(_klass));
380     } else {
381       oopDesc::set_mark(mem, markWord::prototype());
382     }
383     oopDesc::release_set_klass(mem, _klass);
384   }
385   return cast_to_oop(mem);
386 }
387 
388 oop ObjAllocator::initialize(HeapWord* mem) const {
389   mem_clear(mem);
390   return finish(mem);
391 }
392 
393 oop ObjBufferAllocator::initialize(HeapWord* mem) const {
394   oopDesc::set_klass_gap(mem, 0);
395   return finish(mem);
396 }
397 
398 
399 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
400   // Set array length before setting the _klass field because a
401   // non-null klass field indicates that the object is parsable by
402   // concurrent GC.
403   assert(_length >= 0, "length should be non-negative");
404   if (_do_zero) {
405     mem_clear(mem);
406     mem_zap_start_padding(mem);
407     mem_zap_end_padding(mem);
408   }
409   arrayOopDesc::set_length(mem, _length);
410   return finish(mem);
411 }
412 
413 #ifndef PRODUCT
414 void ObjArrayAllocator::mem_zap_start_padding(HeapWord* mem) const {
415   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
416   const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
417   const size_t header_size_in_bytes = arrayOopDesc::header_size_in_bytes();
418 
< prev index next >