359 oop MemAllocator::allocate() const {
360 oop obj = NULL;
361 {
362 Allocation allocation(*this, &obj);
363 HeapWord* mem = mem_allocate(allocation);
364 if (mem != NULL) {
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 if (UseBiasedLocking) {
386 oopDesc::set_mark(mem, _klass->prototype_header());
387 } else {
388 // May be bootstrapping
389 oopDesc::set_mark(mem, markWord::prototype());
390 }
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 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
404 if (_do_zero) {
405 return MemAllocator::obj_memory_range(obj);
406 }
407 ArrayKlass* array_klass = ArrayKlass::cast(_klass);
408 const size_t hs = arrayOopDesc::header_size(array_klass->element_type());
409 return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
410 }
411
412 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
413 // Set array length before setting the _klass field because a
414 // non-NULL klass field indicates that the object is parsable by
415 // concurrent GC.
416 assert(_length >= 0, "length should be non-negative");
417 if (_do_zero) {
418 mem_clear(mem);
419 }
420 arrayOopDesc::set_length(mem, _length);
421 return finish(mem);
422 }
423
424 oop ClassAllocator::initialize(HeapWord* mem) const {
425 // Set oop_size field before setting the _klass field because a
426 // non-NULL _klass field indicates that the object is parsable by
427 // concurrent GC.
428 assert(_word_size > 0, "oop_size must be positive.");
|
359 oop MemAllocator::allocate() const {
360 oop obj = NULL;
361 {
362 Allocation allocation(*this, &obj);
363 HeapWord* mem = mem_allocate(allocation);
364 if (mem != NULL) {
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 if (!UseCompactObjectHeaders) {
380 oopDesc::set_klass_gap(mem, 0);
381 }
382 Copy::fill_to_aligned_words(mem + hs, _word_size - hs);
383 }
384
385 oop MemAllocator::finish(HeapWord* mem) const {
386 assert(mem != NULL, "NULL object pointer");
387 if (UseBiasedLocking) {
388 oopDesc::set_mark(mem, _klass->prototype_header());
389 } else if (UseCompactObjectHeaders) {
390 oopDesc::release_set_mark(mem, _klass->prototype_header());
391 } else {
392 // May be bootstrapping
393 oopDesc::set_mark(mem, markWord::prototype());
394 }
395 // Need a release store to ensure array/class length, mark word, and
396 // object zeroing are visible before setting the klass non-NULL, for
397 // concurrent collectors.
398 if (!UseCompactObjectHeaders) {
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 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const {
410 if (_do_zero) {
411 return MemAllocator::obj_memory_range(obj);
412 }
413 ArrayKlass* array_klass = ArrayKlass::cast(_klass);
414 const size_t hs = align_up(arrayOopDesc::base_offset_in_bytes(array_klass->element_type()), HeapWordSize) / HeapWordSize;
415 return MemRegion(cast_from_oop<HeapWord*>(obj) + hs, _word_size - hs);
416 }
417
418 oop ObjArrayAllocator::initialize(HeapWord* mem) const {
419 // Set array length before setting the _klass field because a
420 // non-NULL klass field indicates that the object is parsable by
421 // concurrent GC.
422 assert(_length >= 0, "length should be non-negative");
423 if (_do_zero) {
424 mem_clear(mem);
425 }
426 arrayOopDesc::set_length(mem, _length);
427 return finish(mem);
428 }
429
430 oop ClassAllocator::initialize(HeapWord* mem) const {
431 // Set oop_size field before setting the _klass field because a
432 // non-NULL _klass field indicates that the object is parsable by
433 // concurrent GC.
434 assert(_word_size > 0, "oop_size must be positive.");
|