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