< prev index next >

src/hotspot/share/gc/x/xObjArrayAllocator.cpp

Print this page

 33     ObjArrayAllocator(klass, word_size, length, do_zero, thread) {}
 34 
 35 void XObjArrayAllocator::yield_for_safepoint() const {
 36   ThreadBlockInVM tbivm(JavaThread::cast(_thread));
 37 }
 38 
 39 oop XObjArrayAllocator::initialize(HeapWord* mem) const {
 40   // ZGC specializes the initialization by performing segmented clearing
 41   // to allow shorter time-to-safepoints.
 42 
 43   if (!_do_zero) {
 44     // No need for ZGC specialization
 45     return ObjArrayAllocator::initialize(mem);
 46   }
 47 
 48   // A max segment size of 64K was chosen because microbenchmarking
 49   // suggested that it offered a good trade-off between allocation
 50   // time and time-to-safepoint
 51   const size_t segment_max = XUtils::bytes_to_words(64 * K);
 52   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 53   const size_t header = arrayOopDesc::header_size(element_type);
 54   const size_t payload_size = _word_size - header;







 55 


 56   if (payload_size <= segment_max) {
 57     // To small to use segmented clearing
 58     return ObjArrayAllocator::initialize(mem);
 59   }
 60 
 61   // Segmented clearing
 62 
 63   // The array is going to be exposed before it has been completely
 64   // cleared, therefore we can't expose the header at the end of this
 65   // function. Instead explicitly initialize it according to our needs.
 66   arrayOopDesc::set_mark(mem, markWord::prototype());
 67   arrayOopDesc::release_set_klass(mem, _klass);




 68   assert(_length >= 0, "length should be non-negative");
 69   arrayOopDesc::set_length(mem, _length);
 70 
 71   // Keep the array alive across safepoints through an invisible
 72   // root. Invisible roots are not visited by the heap itarator
 73   // and the marking logic will not attempt to follow its elements.
 74   // Relocation knows how to dodge iterating over such objects.
 75   XThreadLocalData::set_invisible_root(_thread, (oop*)&mem);
 76 
 77   for (size_t processed = 0; processed < payload_size; processed += segment_max) {
 78     // Calculate segment
 79     HeapWord* const start = (HeapWord*)(mem + header + processed);
 80     const size_t remaining = payload_size - processed;
 81     const size_t segment_size = MIN2(remaining, segment_max);
 82 
 83     // Clear segment
 84     Copy::zero_to_words(start, segment_size);
 85 
 86     // Safepoint
 87     yield_for_safepoint();

 33     ObjArrayAllocator(klass, word_size, length, do_zero, thread) {}
 34 
 35 void XObjArrayAllocator::yield_for_safepoint() const {
 36   ThreadBlockInVM tbivm(JavaThread::cast(_thread));
 37 }
 38 
 39 oop XObjArrayAllocator::initialize(HeapWord* mem) const {
 40   // ZGC specializes the initialization by performing segmented clearing
 41   // to allow shorter time-to-safepoints.
 42 
 43   if (!_do_zero) {
 44     // No need for ZGC specialization
 45     return ObjArrayAllocator::initialize(mem);
 46   }
 47 
 48   // A max segment size of 64K was chosen because microbenchmarking
 49   // suggested that it offered a good trade-off between allocation
 50   // time and time-to-safepoint
 51   const size_t segment_max = XUtils::bytes_to_words(64 * K);
 52   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 53 int base_offset = arrayOopDesc::base_offset_in_bytes(element_type);
 54 
 55   // Clear leading 32 bit, if necessary.
 56   if (!is_aligned(base_offset, HeapWordSize)) {
 57     assert(is_aligned(base_offset, BytesPerInt), "array base must be 32 bit aligned");
 58     *reinterpret_cast<jint*>(reinterpret_cast<char*>(mem) + base_offset) = 0;
 59     base_offset += BytesPerInt;
 60   }
 61   assert(is_aligned(base_offset, HeapWordSize), "remaining array base must be 64 bit aligned");
 62 
 63   const size_t header = heap_word_size(base_offset);
 64   const size_t payload_size = _word_size - header;
 65   if (payload_size <= segment_max) {
 66     // To small to use segmented clearing
 67     return ObjArrayAllocator::initialize(mem);
 68   }
 69 
 70   // Segmented clearing
 71 
 72   // The array is going to be exposed before it has been completely
 73   // cleared, therefore we can't expose the header at the end of this
 74   // function. Instead explicitly initialize it according to our needs.
 75   if (UseCompactObjectHeaders) {
 76     oopDesc::release_set_mark(mem, _klass->prototype_header());
 77   } else {
 78     arrayOopDesc::set_mark(mem, markWord::prototype());
 79     arrayOopDesc::release_set_klass(mem, _klass);
 80   }
 81   assert(_length >= 0, "length should be non-negative");
 82   arrayOopDesc::set_length(mem, _length);
 83 
 84   // Keep the array alive across safepoints through an invisible
 85   // root. Invisible roots are not visited by the heap itarator
 86   // and the marking logic will not attempt to follow its elements.
 87   // Relocation knows how to dodge iterating over such objects.
 88   XThreadLocalData::set_invisible_root(_thread, (oop*)&mem);
 89 
 90   for (size_t processed = 0; processed < payload_size; processed += segment_max) {
 91     // Calculate segment
 92     HeapWord* const start = (HeapWord*)(mem + header + processed);
 93     const size_t remaining = payload_size - processed;
 94     const size_t segment_size = MIN2(remaining, segment_max);
 95 
 96     // Clear segment
 97     Copy::zero_to_words(start, segment_size);
 98 
 99     // Safepoint
100     yield_for_safepoint();
< prev index next >