358 if (result != NULL) { 359 return result; 360 } 361 } 362 363 return allocate_outside_tlab(allocation); 364 } 365 366 oop MemAllocator::allocate() const { 367 oop obj = NULL; 368 { 369 Allocation allocation(*this, &obj); 370 HeapWord* mem = mem_allocate(allocation); 371 if (mem != NULL) { 372 obj = initialize(mem); 373 } 374 } 375 return obj; 376 } 377 378 void MemAllocator::mem_clear(HeapWord* mem) const { 379 assert(mem != NULL, "cannot initialize NULL object"); 380 const size_t hs = oopDesc::header_size(); 381 assert(_word_size >= hs, "unexpected object size"); 382 oopDesc::set_klass_gap(mem, 0); 383 Copy::fill_to_aligned_words(mem + hs, _word_size - hs); 384 } 385 386 oop MemAllocator::finish(HeapWord* mem) const { 387 assert(mem != NULL, "NULL object pointer"); 388 if (UseBiasedLocking) { 389 oopDesc::set_mark_raw(mem, _klass->prototype_header()); 390 } else { 391 // May be bootstrapping 392 oopDesc::set_mark_raw(mem, markOopDesc::prototype()); 393 } 394 // Need a release store to ensure array/class length, mark word, and 395 // object zeroing are visible before setting the klass non-NULL, for 396 // concurrent collectors. 397 oopDesc::release_set_klass(mem, _klass); 398 return oop(mem); 399 } 400 401 oop ObjAllocator::initialize(HeapWord* mem) const { 402 mem_clear(mem); 403 return finish(mem); 404 } 405 406 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const { 407 if (_do_zero) { 408 return MemAllocator::obj_memory_range(obj); 409 } 410 ArrayKlass* array_klass = ArrayKlass::cast(_klass); 411 const size_t hs = arrayOopDesc::header_size(array_klass->element_type()); 412 return MemRegion(((HeapWord*)obj) + hs, _word_size - hs); 413 } 414 415 oop ObjArrayAllocator::initialize(HeapWord* mem) const { 416 // Set array length before setting the _klass field because a 417 // non-NULL klass field indicates that the object is parsable by 418 // concurrent GC. 419 assert(_length >= 0, "length should be non-negative"); 420 if (_do_zero) { 421 mem_clear(mem); 422 } 423 arrayOopDesc::set_length(mem, _length); 424 return finish(mem); 425 } 426 427 oop ClassAllocator::initialize(HeapWord* mem) const { 428 // Set oop_size field before setting the _klass field because a 429 // non-NULL _klass field indicates that the object is parsable by 430 // concurrent GC. 431 assert(_word_size > 0, "oop_size must be positive."); 432 mem_clear(mem); 433 java_lang_Class::set_oop_size(mem, (int)_word_size); 434 return finish(mem); 435 } | 358 if (result != NULL) { 359 return result; 360 } 361 } 362 363 return allocate_outside_tlab(allocation); 364 } 365 366 oop MemAllocator::allocate() const { 367 oop obj = NULL; 368 { 369 Allocation allocation(*this, &obj); 370 HeapWord* mem = mem_allocate(allocation); 371 if (mem != NULL) { 372 obj = initialize(mem); 373 } 374 } 375 return obj; 376 } 377 378 HeapWord* MemAllocator::mem_clear(HeapWord* mem) const { 379 assert(mem != NULL, "cannot initialize NULL object"); 380 const size_t hs = oopDesc::header_size(); 381 assert(_word_size >= hs, "unexpected object size"); 382 oopDesc::set_klass_gap(mem, 0); 383 Copy::fill_to_aligned_words(mem + hs, _word_size - hs); 384 return mem; 385 } 386 387 oop MemAllocator::finish(HeapWord* mem) const { 388 assert(mem != NULL, "NULL object pointer"); 389 if (UseBiasedLocking) { 390 oopDesc::set_mark_raw(mem, _klass->prototype_header()); 391 } else { 392 // May be bootstrapping 393 oopDesc::set_mark_raw(mem, markOopDesc::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 oopDesc::release_set_klass(mem, _klass); 399 return oop(mem); 400 } 401 402 oop ObjAllocator::initialize(HeapWord* mem) const { 403 mem = mem_clear(mem); 404 return finish(mem); 405 } 406 407 MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const { 408 if (_do_zero) { 409 return MemAllocator::obj_memory_range(obj); 410 } 411 ArrayKlass* array_klass = ArrayKlass::cast(_klass); 412 const size_t hs = arrayOopDesc::header_size(array_klass->element_type()); 413 return MemRegion(((HeapWord*)obj) + hs, _word_size - hs); 414 } 415 416 oop ObjArrayAllocator::initialize(HeapWord* mem) const { 417 // Set array length before setting the _klass field because a 418 // non-NULL klass field indicates that the object is parsable by 419 // concurrent GC. 420 assert(_length >= 0, "length should be non-negative"); 421 if (_do_zero) { 422 mem = mem_clear(mem); 423 } 424 arrayOopDesc::set_length(mem, _length); 425 return finish(mem); 426 } 427 428 oop ClassAllocator::initialize(HeapWord* mem) const { 429 // Set oop_size field before setting the _klass field because a 430 // non-NULL _klass field indicates that the object is parsable by 431 // concurrent GC. 432 assert(_word_size > 0, "oop_size must be positive."); 433 mem = mem_clear(mem); 434 java_lang_Class::set_oop_size(mem, (int)_word_size); 435 return finish(mem); 436 } |