370 obj = initialize(mem);
371 } else {
372 // The unhandled oop detector will poison local variable obj,
373 // so reset it to null if mem is null.
374 obj = nullptr;
375 }
376 }
377 return obj;
378 }
379
380 void MemAllocator::mem_clear(HeapWord* mem) const {
381 assert(mem != nullptr, "cannot initialize null object");
382 const size_t hs = oopDesc::header_size();
383 assert(_word_size >= hs, "unexpected object size");
384 oopDesc::set_klass_gap(mem, 0);
385 Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
386 }
387
388 oop MemAllocator::finish(HeapWord* mem) const {
389 assert(mem != nullptr, "null object pointer");
390 // May be bootstrapping
391 oopDesc::set_mark(mem, markWord::prototype());
392 // Need a release store to ensure array/class length, mark word, and
393 // object zeroing are visible before setting the klass non-null, for
394 // concurrent collectors.
395 oopDesc::release_set_klass(mem, _klass);
396 return cast_to_oop(mem);
397 }
398
399 oop ObjAllocator::initialize(HeapWord* mem) const {
400 mem_clear(mem);
401 return finish(mem);
402 }
403
404 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
405 // Set array length before setting the _klass field because a
406 // non-null klass field indicates that the object is parsable by
407 // concurrent GC.
408 assert(_length >= 0, "length should be non-negative");
409 if (_do_zero) {
410 mem_clear(mem);
411 }
412 arrayOopDesc::set_length(mem, _length);
413 return finish(mem);
414 }
415
416 oop ClassAllocator::initialize(HeapWord* mem) const {
417 // Set oop_size field before setting the _klass field because a
418 // non-null _klass field indicates that the object is parsable by
419 // concurrent GC.
420 assert(_word_size > 0, "oop_size must be positive.");
421 mem_clear(mem);
422 java_lang_Class::set_oop_size(mem, _word_size);
423 return finish(mem);
|
370 obj = initialize(mem);
371 } else {
372 // The unhandled oop detector will poison local variable obj,
373 // so reset it to null if mem is null.
374 obj = nullptr;
375 }
376 }
377 return obj;
378 }
379
380 void MemAllocator::mem_clear(HeapWord* mem) const {
381 assert(mem != nullptr, "cannot initialize null object");
382 const size_t hs = oopDesc::header_size();
383 assert(_word_size >= hs, "unexpected object size");
384 oopDesc::set_klass_gap(mem, 0);
385 Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
386 }
387
388 oop MemAllocator::finish(HeapWord* mem) const {
389 assert(mem != nullptr, "null object pointer");
390 oopDesc::set_mark(mem, Klass::default_prototype_header(_klass));
391 // Need a release store to ensure array/class length, mark word, and
392 // object zeroing are visible before setting the klass non-null, for
393 // concurrent collectors.
394 oopDesc::release_set_klass(mem, _klass);
395 return cast_to_oop(mem);
396 }
397
398 oop ObjAllocator::initialize(HeapWord* mem) const {
399 mem_clear(mem);
400 return finish(mem);
401 }
402
403 oop ObjBufferAllocator::initialize(HeapWord* mem) const {
404 oopDesc::set_klass_gap(mem, 0);
405 return finish(mem);
406 }
407
408
409 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
410 // Set array length before setting the _klass field because a
411 // non-null klass field indicates that the object is parsable by
412 // concurrent GC.
413 assert(_length >= 0, "length should be non-negative");
414 if (_do_zero) {
415 mem_clear(mem);
416 }
417 arrayOopDesc::set_length(mem, _length);
418 return finish(mem);
419 }
420
421 oop ClassAllocator::initialize(HeapWord* mem) const {
422 // Set oop_size field before setting the _klass field because a
423 // non-null _klass field indicates that the object is parsable by
424 // concurrent GC.
425 assert(_word_size > 0, "oop_size must be positive.");
426 mem_clear(mem);
427 java_lang_Class::set_oop_size(mem, _word_size);
428 return finish(mem);
|