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 = ZUtils::bytes_to_words(64 * K);
52
53 if (_word_size <= segment_max) {
54 // To small to use segmented clearing
55 return ObjArrayAllocator::initialize(mem);
56 }
57
58 // Segmented clearing
59
60 // The array is going to be exposed before it has been completely
61 // cleared, therefore we can't expose the header at the end of this
62 // function. Instead explicitly initialize it according to our needs.
63
64 // Signal to the ZIterator that this is an invisible root, by setting
65 // the mark word to "marked". Reset to prototype() after the clearing.
66 arrayOopDesc::set_mark(mem, markWord::prototype().set_marked());
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 iterator
73 // and the marking logic will not attempt to follow its elements.
74 // Relocation and remembered set code know how to dodge iterating
75 // over such objects.
76 ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
77
78 const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
79 const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
80 const size_t process_start_offset_in_bytes = align_up(base_offset_in_bytes, BytesPerWord);
81
82 if (process_start_offset_in_bytes != base_offset_in_bytes) {
83 // initialize_memory can only fill word aligned memory,
84 // fill the first 4 bytes here.
85 assert(process_start_offset_in_bytes - base_offset_in_bytes == 4, "Must be 4-byte aligned");
86 assert(!is_reference_type(element_type), "Only TypeArrays can be 4-byte aligned");
87 *reinterpret_cast<int*>(reinterpret_cast<char*>(mem) + base_offset_in_bytes) = 0;
133 // The first time we observe a GC safepoint in the yield point,
134 // we have to restart processing with 11 remembered bits.
135 seen_gc_safepoint = true;
136 return false;
137 }
138 }
139 return true;
140 };
141
142 if (!initialize_memory()) {
143 // Re-color with 11 remset bits if we got intercepted by a GC safepoint
144 const bool result = initialize_memory();
145 assert(result, "Array initialization should always succeed the second time");
146 }
147
148 mem_zap_end_padding(mem);
149
150 ZThreadLocalData::clear_invisible_root(_thread);
151
152 // Signal to the ZIterator that this is no longer an invisible root
153 oopDesc::release_set_mark(mem, markWord::prototype());
154
155 return cast_to_oop(mem);
156 }
|
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 = ZUtils::bytes_to_words(64 * K);
52
53 if (_word_size <= segment_max) {
54 // To small to use segmented clearing
55 return ObjArrayAllocator::initialize(mem);
56 }
57
58 // Segmented clearing
59
60 // The array is going to be exposed before it has been completely
61 // cleared, therefore we can't expose the header at the end of this
62 // function. Instead explicitly initialize it according to our needs.
63
64 // Signal to the ZIterator that this is an invisible root, by setting
65 // the mark word to "marked". Reset to prototype() after the clearing.
66 if (UseCompactObjectHeaders) {
67 oopDesc::release_set_mark(mem, _klass->prototype_header().set_marked());
68 } else {
69 arrayOopDesc::set_mark(mem, markWord::prototype().set_marked());
70 arrayOopDesc::release_set_klass(mem, _klass);
71 }
72 assert(_length >= 0, "length should be non-negative");
73 arrayOopDesc::set_length(mem, _length);
74
75 // Keep the array alive across safepoints through an invisible
76 // root. Invisible roots are not visited by the heap iterator
77 // and the marking logic will not attempt to follow its elements.
78 // Relocation and remembered set code know how to dodge iterating
79 // over such objects.
80 ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
81
82 const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
83 const size_t base_offset_in_bytes = arrayOopDesc::base_offset_in_bytes(element_type);
84 const size_t process_start_offset_in_bytes = align_up(base_offset_in_bytes, BytesPerWord);
85
86 if (process_start_offset_in_bytes != base_offset_in_bytes) {
87 // initialize_memory can only fill word aligned memory,
88 // fill the first 4 bytes here.
89 assert(process_start_offset_in_bytes - base_offset_in_bytes == 4, "Must be 4-byte aligned");
90 assert(!is_reference_type(element_type), "Only TypeArrays can be 4-byte aligned");
91 *reinterpret_cast<int*>(reinterpret_cast<char*>(mem) + base_offset_in_bytes) = 0;
137 // The first time we observe a GC safepoint in the yield point,
138 // we have to restart processing with 11 remembered bits.
139 seen_gc_safepoint = true;
140 return false;
141 }
142 }
143 return true;
144 };
145
146 if (!initialize_memory()) {
147 // Re-color with 11 remset bits if we got intercepted by a GC safepoint
148 const bool result = initialize_memory();
149 assert(result, "Array initialization should always succeed the second time");
150 }
151
152 mem_zap_end_padding(mem);
153
154 ZThreadLocalData::clear_invisible_root(_thread);
155
156 // Signal to the ZIterator that this is no longer an invisible root
157 if (UseCompactObjectHeaders) {
158 oopDesc::release_set_mark(mem, _klass->prototype_header());
159 } else {
160 oopDesc::release_set_mark(mem, markWord::prototype());
161 }
162
163 return cast_to_oop(mem);
164 }
|