364 oop MemAllocator::allocate() const {
365 oop obj = nullptr;
366 {
367 Allocation allocation(*this, &obj);
368 HeapWord* mem = mem_allocate(allocation);
369 if (mem != nullptr) {
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
|
364 oop MemAllocator::allocate() const {
365 oop obj = nullptr;
366 {
367 Allocation allocation(*this, &obj);
368 HeapWord* mem = mem_allocate(allocation);
369 if (mem != nullptr) {
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 if (!UseCompactObjectHeaders) {
385 oopDesc::set_klass_gap(mem, 0);
386 }
387 Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
388 }
389
390 oop MemAllocator::finish(HeapWord* mem) const {
391 assert(mem != nullptr, "null object pointer");
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 if (UseCompactObjectHeaders) {
396 oopDesc::release_set_mark(mem, _klass->prototype_header());
397 } else {
398 oopDesc::set_mark(mem, markWord::prototype());
399 oopDesc::release_set_klass(mem, _klass);
400 }
401 return cast_to_oop(mem);
402 }
403
404 oop ObjAllocator::initialize(HeapWord* mem) const {
405 mem_clear(mem);
406 return finish(mem);
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
|