< prev index next >

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

Print this page

340 oop MemAllocator::allocate() const {
341   oop obj = NULL;
342   {
343     Allocation allocation(*this, &obj);
344     HeapWord* mem = mem_allocate(allocation);
345     if (mem != NULL) {
346       obj = initialize(mem);
347     } else {
348       // The unhandled oop detector will poison local variable obj,
349       // so reset it to NULL if mem is NULL.
350       obj = NULL;
351     }
352   }
353   return obj;
354 }
355 
356 void MemAllocator::mem_clear(HeapWord* mem) const {
357   assert(mem != NULL, "cannot initialize NULL object");
358   const size_t hs = oopDesc::header_size();
359   assert(_word_size >= hs, "unexpected object size");
360   oopDesc::set_klass_gap(mem, 0);


361   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
362 }
363 
364 oop MemAllocator::finish(HeapWord* mem) const {
365   assert(mem != NULL, "NULL object pointer");
366   if (UseBiasedLocking) {
367     oopDesc::set_mark(mem, _klass->prototype_header());


368   } else {
369     // May be bootstrapping
370     oopDesc::set_mark(mem, markWord::prototype());
371   }
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   oopDesc::release_set_klass(mem, _klass);


376   return cast_to_oop(mem);
377 }
378 
379 oop ObjAllocator::initialize(HeapWord* mem) const {
380   mem_clear(mem);
381   return finish(mem);
382 }
383 
384 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
385   // Set array length before setting the _klass field because a
386   // non-NULL klass field indicates that the object is parsable by
387   // concurrent GC.
388   assert(_length >= 0, "length should be non-negative");
389   if (_do_zero) {
390     mem_clear(mem);
391   }
392   arrayOopDesc::set_length(mem, _length);
393   return finish(mem);
394 }
395 

340 oop MemAllocator::allocate() const {
341   oop obj = NULL;
342   {
343     Allocation allocation(*this, &obj);
344     HeapWord* mem = mem_allocate(allocation);
345     if (mem != NULL) {
346       obj = initialize(mem);
347     } else {
348       // The unhandled oop detector will poison local variable obj,
349       // so reset it to NULL if mem is NULL.
350       obj = NULL;
351     }
352   }
353   return obj;
354 }
355 
356 void MemAllocator::mem_clear(HeapWord* mem) const {
357   assert(mem != NULL, "cannot initialize NULL object");
358   const size_t hs = oopDesc::header_size();
359   assert(_word_size >= hs, "unexpected object size");
360   if (!UseCompactObjectHeaders) {
361     oopDesc::set_klass_gap(mem, 0);
362   }
363   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
364 }
365 
366 oop MemAllocator::finish(HeapWord* mem) const {
367   assert(mem != NULL, "NULL object pointer");
368   if (UseBiasedLocking) {
369     oopDesc::set_mark(mem, _klass->prototype_header());
370   } else if (UseCompactObjectHeaders) {
371     oopDesc::release_set_mark(mem, _klass->prototype_header());
372   } else {
373     // May be bootstrapping
374     oopDesc::set_mark(mem, markWord::prototype());
375   }
376   // Need a release store to ensure array/class length, mark word, and
377   // object zeroing are visible before setting the klass non-NULL, for
378   // concurrent collectors.
379   if (!UseCompactObjectHeaders) {
380     oopDesc::release_set_klass(mem, _klass);
381   }
382   return cast_to_oop(mem);
383 }
384 
385 oop ObjAllocator::initialize(HeapWord* mem) const {
386   mem_clear(mem);
387   return finish(mem);
388 }
389 
390 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
391   // Set array length before setting the _klass field because a
392   // non-NULL klass field indicates that the object is parsable by
393   // concurrent GC.
394   assert(_length >= 0, "length should be non-negative");
395   if (_do_zero) {
396     mem_clear(mem);
397   }
398   arrayOopDesc::set_length(mem, _length);
399   return finish(mem);
400 }
401 
< prev index next >