< prev index next >

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

Print this page

359 oop MemAllocator::allocate() const {
360   oop obj = NULL;
361   {
362     Allocation allocation(*this, &obj);
363     HeapWord* mem = mem_allocate(allocation);
364     if (mem != NULL) {
365       obj = initialize(mem);
366     } else {
367       // The unhandled oop detector will poison local variable obj,
368       // so reset it to NULL if mem is NULL.
369       obj = NULL;
370     }
371   }
372   return obj;
373 }
374 
375 void MemAllocator::mem_clear(HeapWord* mem) const {
376   assert(mem != NULL, "cannot initialize NULL object");
377   const size_t hs = oopDesc::header_size();
378   assert(_word_size >= hs, "unexpected object size");
379   oopDesc::set_klass_gap(mem, 0);
380   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
381 }
382 
383 oop MemAllocator::finish(HeapWord* mem) const {
384   assert(mem != NULL, "NULL object pointer");
385   // May be bootstrapping
386   oopDesc::set_mark(mem, markWord::prototype());
387   // Need a release store to ensure array/class length, mark word, and
388   // object zeroing are visible before setting the klass non-NULL, for
389   // concurrent collectors.




390   oopDesc::release_set_klass(mem, _klass);

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 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
400   if (_do_zero) {
401     return MemAllocator::obj_memory_range(obj);
402   }
403   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
404   const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
405   return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
406 }
407 
408 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
409   // Set array length before setting the _klass field because a
410   // non-NULL klass field indicates that the object is parsable by
411   // concurrent GC.
412   assert(_length >= 0, "length should be non-negative");
413   if (_do_zero) {
414     mem_clear(mem);
415   }
416   arrayOopDesc::set_length(mem, _length);
417   return finish(mem);
418 }
419 
420 oop ClassAllocator::initialize(HeapWord* mem) const {
421   // Set oop_size field before setting the _klass field because a
422   // non-NULL _klass field indicates that the object is parsable by
423   // concurrent GC.
424   assert(_word_size > 0, "oop_size must be positive.");

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

379   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
380 }
381 
382 oop MemAllocator::finish(HeapWord* mem) const {
383   assert(mem != NULL, "NULL object pointer");


384   // Need a release store to ensure array/class length, mark word, and
385   // object zeroing are visible before setting the klass non-NULL, for
386   // concurrent collectors.
387 #ifdef _LP64
388   oopDesc::release_set_mark(mem, _klass->prototype_header());
389 #else
390   oopDesc::set_mark(mem, _klass->prototype_header());
391   oopDesc::release_set_klass(mem, _klass);
392 #endif
393   return cast_to_oop(mem);
394 }
395 
396 oop ObjAllocator::initialize(HeapWord* mem) const {
397   mem_clear(mem);
398   return finish(mem);
399 }
400 
401 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
402   if (_do_zero) {
403     return MemAllocator::obj_memory_range(obj);
404   }
405   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
406   const size_t hs = align_up(arrayOopDesc::base_offset_in_bytes(array_klass->element_type()), HeapWordSize) / HeapWordSize;
407   return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
408 }
409 
410 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
411   // Set array length before setting the _klass field because a
412   // non-NULL klass field indicates that the object is parsable by
413   // concurrent GC.
414   assert(_length >= 0, "length should be non-negative");
415   if (_do_zero) {
416     mem_clear(mem);
417   }
418   arrayOopDesc::set_length(mem, _length);
419   return finish(mem);
420 }
421 
422 oop ClassAllocator::initialize(HeapWord* mem) const {
423   // Set oop_size field before setting the _klass field because a
424   // non-NULL _klass field indicates that the object is parsable by
425   // concurrent GC.
426   assert(_word_size > 0, "oop_size must be positive.");
< prev index next >