344 oop MemAllocator::allocate() const {
345 oop obj = nullptr;
346 {
347 Allocation allocation(*this, &obj);
348 HeapWord* mem = mem_allocate(allocation);
349 if (mem != nullptr) {
350 obj = initialize(mem);
351 } else {
352 // The unhandled oop detector will poison local variable obj,
353 // so reset it to null if mem is null.
354 obj = nullptr;
355 }
356 }
357 return obj;
358 }
359
360 void MemAllocator::mem_clear(HeapWord* mem) const {
361 assert(mem != nullptr, "cannot initialize null object");
362 const size_t hs = oopDesc::header_size();
363 assert(_word_size >= hs, "unexpected object size");
364 oopDesc::set_klass_gap(mem, 0);
365 Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
366 }
367
368 oop MemAllocator::finish(HeapWord* mem) const {
369 assert(mem != nullptr, "null object pointer");
370 // May be bootstrapping
371 oopDesc::set_mark(mem, markWord::prototype());
372 // Need a release store to ensure array/class length, mark word, and
373 // object zeroing are visible before setting the klass non-null, for
374 // concurrent collectors.
375 oopDesc::release_set_klass(mem, _klass);
376 return cast_to_oop(mem);
377 }
378
379 oop ObjAllocator::initialize(HeapWord* mem) const {
380 mem_clear(mem);
381 return finish(mem);
382 }
383
384 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
385 // Set array length before setting the _klass field because a
386 // non-null klass field indicates that the object is parsable by
387 // concurrent GC.
388 assert(_length >= 0, "length should be non-negative");
389 if (_do_zero) {
390 mem_clear(mem);
391 mem_zap_end_padding(mem);
392 }
393 arrayOopDesc::set_length(mem, _length);
394 return finish(mem);
395 }
|
344 oop MemAllocator::allocate() const {
345 oop obj = nullptr;
346 {
347 Allocation allocation(*this, &obj);
348 HeapWord* mem = mem_allocate(allocation);
349 if (mem != nullptr) {
350 obj = initialize(mem);
351 } else {
352 // The unhandled oop detector will poison local variable obj,
353 // so reset it to null if mem is null.
354 obj = nullptr;
355 }
356 }
357 return obj;
358 }
359
360 void MemAllocator::mem_clear(HeapWord* mem) const {
361 assert(mem != nullptr, "cannot initialize null object");
362 const size_t hs = oopDesc::header_size();
363 assert(_word_size >= hs, "unexpected object size");
364 if (!UseCompactObjectHeaders) {
365 oopDesc::set_klass_gap(mem, 0);
366 }
367 Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
368 }
369
370 oop MemAllocator::finish(HeapWord* mem) const {
371 assert(mem != nullptr, "null object pointer");
372 // Need a release store to ensure array/class length, mark word, and
373 // object zeroing are visible before setting the klass non-null, for
374 // concurrent collectors.
375 if (UseCompactObjectHeaders) {
376 oopDesc::release_set_mark(mem, _klass->prototype_header());
377 } else {
378 oopDesc::set_mark(mem, markWord::prototype());
379 oopDesc::release_set_klass(mem, _klass);
380 }
381 return cast_to_oop(mem);
382 }
383
384 oop ObjAllocator::initialize(HeapWord* mem) const {
385 mem_clear(mem);
386 return finish(mem);
387 }
388
389 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
390 // Set array length before setting the _klass field because a
391 // non-null klass field indicates that the object is parsable by
392 // concurrent GC.
393 assert(_length >= 0, "length should be non-negative");
394 if (_do_zero) {
395 mem_clear(mem);
396 mem_zap_end_padding(mem);
397 }
398 arrayOopDesc::set_length(mem, _length);
399 return finish(mem);
400 }
|