< prev index next >

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

Print this page

380 
381 oop MemAllocator::try_allocate_in_existing_tlab() {
382   oop obj = NULL;
383   {
384     HeapWord* mem = allocate_inside_tlab_fast();
385     if (mem != NULL) {
386       obj = initialize(mem);
387     } else {
388       // The unhandled oop detector will poison local variable obj,
389       // so reset it to NULL if mem is NULL.
390       obj = NULL;
391     }
392   }
393   return obj;
394 }
395 
396 void MemAllocator::mem_clear(HeapWord* mem) const {
397   assert(mem != NULL, "cannot initialize NULL object");
398   const size_t hs = oopDesc::header_size();
399   assert(_word_size >= hs, "unexpected object size");
400   oopDesc::set_klass_gap(mem, 0);
401   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
402 }
403 
404 oop MemAllocator::finish(HeapWord* mem) const {
405   assert(mem != NULL, "NULL object pointer");
406   // May be bootstrapping
407   oopDesc::set_mark(mem, markWord::prototype());
408   // Need a release store to ensure array/class length, mark word, and
409   // object zeroing are visible before setting the klass non-NULL, for
410   // concurrent collectors.




411   oopDesc::release_set_klass(mem, _klass);

412   return cast_to_oop(mem);
413 }
414 
415 oop ObjAllocator::initialize(HeapWord* mem) const {
416   mem_clear(mem);
417   return finish(mem);
418 }
419 
420 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
421   if (_do_zero) {
422     return MemAllocator::obj_memory_range(obj);
423   }
424   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
425   const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
426   return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
427 }
428 
429 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
430   // Set array length before setting the _klass field because a
431   // non-NULL klass field indicates that the object is parsable by
432   // concurrent GC.
433   assert(_length >= 0, "length should be non-negative");
434   if (_do_zero) {
435     mem_clear(mem);
436   }
437   arrayOopDesc::set_length(mem, _length);
438   return finish(mem);
439 }
440 
441 oop ClassAllocator::initialize(HeapWord* mem) const {
442   // Set oop_size field before setting the _klass field because a
443   // non-NULL _klass field indicates that the object is parsable by
444   // concurrent GC.
445   assert(_word_size > 0, "oop_size must be positive.");

380 
381 oop MemAllocator::try_allocate_in_existing_tlab() {
382   oop obj = NULL;
383   {
384     HeapWord* mem = allocate_inside_tlab_fast();
385     if (mem != NULL) {
386       obj = initialize(mem);
387     } else {
388       // The unhandled oop detector will poison local variable obj,
389       // so reset it to NULL if mem is NULL.
390       obj = NULL;
391     }
392   }
393   return obj;
394 }
395 
396 void MemAllocator::mem_clear(HeapWord* mem) const {
397   assert(mem != NULL, "cannot initialize NULL object");
398   const size_t hs = oopDesc::header_size();
399   assert(_word_size >= hs, "unexpected object size");

400   Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
401 }
402 
403 oop MemAllocator::finish(HeapWord* mem) const {
404   assert(mem != NULL, "NULL object pointer");


405   // Need a release store to ensure array/class length, mark word, and
406   // object zeroing are visible before setting the klass non-NULL, for
407   // concurrent collectors.
408 #ifdef _LP64
409   oopDesc::release_set_mark(mem, _klass->prototype_header());
410 #else
411   oopDesc::set_mark(mem, _klass->prototype_header());
412   oopDesc::release_set_klass(mem, _klass);
413 #endif
414   return cast_to_oop(mem);
415 }
416 
417 oop ObjAllocator::initialize(HeapWord* mem) const {
418   mem_clear(mem);
419   return finish(mem);
420 }
421 
422 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
423   if (_do_zero) {
424     return MemAllocator::obj_memory_range(obj);
425   }
426   ArrayKlass* array_klass = ArrayKlass::cast(_klass);
427   const size_t hs = align_up(arrayOopDesc::base_offset_in_bytes(array_klass->element_type()), HeapWordSize) / HeapWordSize;
428   return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
429 }
430 
431 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
432   // Set array length before setting the _klass field because a
433   // non-NULL klass field indicates that the object is parsable by
434   // concurrent GC.
435   assert(_length >= 0, "length should be non-negative");
436   if (_do_zero) {
437     mem_clear(mem);
438   }
439   arrayOopDesc::set_length(mem, _length);
440   return finish(mem);
441 }
442 
443 oop ClassAllocator::initialize(HeapWord* mem) const {
444   // Set oop_size field before setting the _klass field because a
445   // non-NULL _klass field indicates that the object is parsable by
446   // concurrent GC.
447   assert(_word_size > 0, "oop_size must be positive.");
< prev index next >