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 }
|
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 oopDesc::set_mark(mem, Klass::default_prototype_header(_klass));
386 // Need a release store to ensure array/class length, mark word, and
387 // object zeroing are visible before setting the klass non-NULL, for
388 // concurrent collectors.
389 oopDesc::release_set_klass(mem, _klass);
390 return cast_to_oop(mem);
391 }
392
393 oop ObjAllocator::initialize(HeapWord* mem) const {
394 mem_clear(mem);
395 return finish(mem);
396 }
397
398 oop ObjBufferAllocator::initialize(HeapWord* mem) const {
399 oopDesc::set_klass_gap(mem, 0);
400 return finish(mem);
401 }
402
403
404 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
405 if (_do_zero) {
406 return MemAllocator::obj_memory_range(obj);
407 }
408 ArrayKlass* array_klass = ArrayKlass::cast(_klass);
409 const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
410 return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
411 }
412
413 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
414 // Set array length before setting the _klass field because a
415 // non-NULL klass field indicates that the object is parsable by
416 // concurrent GC.
417 assert(_length >= 0, "length should be non-negative");
418 if (_do_zero) {
419 mem_clear(mem);
420 }
421 arrayOopDesc::set_length(mem, _length);
422 return finish(mem);
423 }
|