< prev index next >

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

Print this page

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "classfile/javaClasses.hpp"
 26 #include "classfile/vmClasses.hpp"
 27 #include "gc/shared/allocTracer.hpp"
 28 #include "gc/shared/collectedHeap.hpp"
 29 #include "gc/shared/memAllocator.hpp"
 30 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
 31 #include "gc/shared/tlab_globals.hpp"
 32 #include "memory/universe.hpp"
 33 #include "oops/arrayOop.hpp"
 34 #include "oops/oop.inline.hpp"
 35 #include "prims/jvmtiExport.hpp"

 36 #include "runtime/continuationJavaClasses.inline.hpp"
 37 #include "runtime/handles.inline.hpp"
 38 #include "runtime/javaThread.hpp"
 39 #include "runtime/sharedRuntime.hpp"
 40 #include "services/lowMemoryDetector.hpp"
 41 #include "utilities/align.hpp"
 42 #include "utilities/copy.hpp"
 43 #include "utilities/globalDefinitions.hpp"
 44 
 45 class MemAllocator::Allocation: StackObj {
 46   friend class MemAllocator;
 47 
 48   const MemAllocator& _allocator;
 49   JavaThread*         _thread;
 50   oop*                _obj_ptr;
 51   bool                _allocated_outside_tlab;
 52   size_t              _allocated_tlab_size;
 53 
 54   bool check_out_of_memory();
 55   void verify_before();

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




384     oopDesc::release_set_klass(mem, _klass);
385   }
386   return cast_to_oop(mem);
387 }
388 
389 oop ObjAllocator::initialize(HeapWord* mem) const {
390   mem_clear(mem);
391   return finish(mem);
392 }
393 
394 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
395   // Set array length before setting the _klass field because a
396   // non-null klass field indicates that the object is parsable by
397   // concurrent GC.
398   assert(_length >= 0, "length should be non-negative");
399   if (_do_zero) {
400     mem_clear(mem);
401     mem_zap_start_padding(mem);
402     mem_zap_end_padding(mem);
403   }

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "classfile/javaClasses.hpp"
 26 #include "classfile/vmClasses.hpp"
 27 #include "gc/shared/allocTracer.hpp"
 28 #include "gc/shared/collectedHeap.hpp"
 29 #include "gc/shared/memAllocator.hpp"
 30 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
 31 #include "gc/shared/tlab_globals.hpp"
 32 #include "memory/universe.hpp"
 33 #include "oops/arrayOop.hpp"
 34 #include "oops/oop.inline.hpp"
 35 #include "prims/jvmtiExport.hpp"
 36 #include "runtime/arguments.hpp"
 37 #include "runtime/continuationJavaClasses.inline.hpp"
 38 #include "runtime/handles.inline.hpp"
 39 #include "runtime/javaThread.hpp"
 40 #include "runtime/sharedRuntime.hpp"
 41 #include "services/lowMemoryDetector.hpp"
 42 #include "utilities/align.hpp"
 43 #include "utilities/copy.hpp"
 44 #include "utilities/globalDefinitions.hpp"
 45 
 46 class MemAllocator::Allocation: StackObj {
 47   friend class MemAllocator;
 48 
 49   const MemAllocator& _allocator;
 50   JavaThread*         _thread;
 51   oop*                _obj_ptr;
 52   bool                _allocated_outside_tlab;
 53   size_t              _allocated_tlab_size;
 54 
 55   bool check_out_of_memory();
 56   void verify_before();

364 }
365 
366 void MemAllocator::mem_clear(HeapWord* mem) const {
367   assert(mem != nullptr, "cannot initialize null object");
368   const size_t hs = oopDesc::header_size();
369   assert(_word_size >= hs, "unexpected object size");
370   if (oopDesc::has_klass_gap()) {
371     oopDesc::set_klass_gap(mem, 0);
372   }
373   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
374 }
375 
376 oop MemAllocator::finish(HeapWord* mem) const {
377   assert(mem != nullptr, "null object pointer");
378   // Need a release store to ensure array/class length, mark word, and
379   // object zeroing are visible before setting the klass non-null, for
380   // concurrent collectors.
381   if (UseCompactObjectHeaders) {
382     oopDesc::release_set_mark(mem, _klass->prototype_header());
383   } else {
384     if (Arguments::is_valhalla_enabled()) {
385       oopDesc::set_mark(mem, _klass->prototype_header());
386     } else {
387       oopDesc::set_mark(mem, markWord::prototype());
388     }
389     oopDesc::release_set_klass(mem, _klass);
390   }
391   return cast_to_oop(mem);
392 }
393 
394 oop ObjAllocator::initialize(HeapWord* mem) const {
395   mem_clear(mem);
396   return finish(mem);
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   }
< prev index next >