@@ -193,80 +193,56 @@ HeapRegion* G1CollectedHeap::new_region(size_t word_size,
193
193
return res;
194
194
}
195
195
196
- HeapWord*
197
- G1CollectedHeap::humongous_obj_allocate_initialize_regions (HeapRegion* first_hr,
198
- uint num_regions,
199
- size_t word_size) {
200
- assert (first_hr != NULL , " pre-condition" );
201
- assert (is_humongous (word_size), " word_size should be humongous" );
202
- assert (num_regions * HeapRegion::GrainWords >= word_size, " pre-condition" );
203
-
204
- // Index of last region in the series.
205
- uint first = first_hr->hrm_index ();
206
- uint last = first + num_regions - 1 ;
207
-
208
- // We need to initialize the region(s) we just discovered. This is
209
- // a bit tricky given that it can happen concurrently with
210
- // refinement threads refining cards on these regions and
211
- // potentially wanting to refine the BOT as they are scanning
212
- // those cards (this can happen shortly after a cleanup; see CR
213
- // 6991377). So we have to set up the region(s) carefully and in
214
- // a specific order.
215
-
216
- // The word size sum of all the regions we will allocate.
217
- size_t word_size_sum = (size_t ) num_regions * HeapRegion::GrainWords;
196
+ void G1CollectedHeap::set_humongous_metadata (HeapRegion* first_hr,
197
+ uint num_regions,
198
+ size_t word_size,
199
+ bool update_remsets) {
200
+ // Calculate the new top of the humongous object.
201
+ HeapWord* obj_top = first_hr->bottom () + word_size;
202
+ // The word size sum of all the regions used
203
+ size_t word_size_sum = num_regions * HeapRegion::GrainWords;
218
204
assert (word_size <= word_size_sum, " sanity" );
219
205
220
- // The passed in hr will be the "starts humongous" region. The header
221
- // of the new object will be placed at the bottom of this region.
222
- HeapWord* new_obj = first_hr->bottom ();
223
- // This will be the new top of the new object.
224
- HeapWord* obj_top = new_obj + word_size;
225
-
226
- // First, we need to zero the header of the space that we will be
227
- // allocating. When we update top further down, some refinement
228
- // threads might try to scan the region. By zeroing the header we
229
- // ensure that any thread that will try to scan the region will
230
- // come across the zero klass word and bail out.
231
- //
232
- // NOTE: It would not have been correct to have used
233
- // CollectedHeap::fill_with_object() and make the space look like
234
- // an int array. The thread that is doing the allocation will
235
- // later update the object header to a potentially different array
236
- // type and, for a very short period of time, the klass and length
237
- // fields will be inconsistent. This could cause a refinement
238
- // thread to calculate the object size incorrectly.
239
- Copy::fill_to_words (new_obj, oopDesc::header_size (), 0 );
206
+ // How many words memory we "waste" which cannot hold a filler object.
207
+ size_t words_not_fillable = 0 ;
240
208
241
- // Next, pad out the unused tail of the last region with filler
209
+ // Pad out the unused tail of the last region with filler
242
210
// objects, for improved usage accounting.
243
- // How many words we use for filler objects.
244
- size_t word_fill_size = word_size_sum - word_size;
245
211
246
- // How many words memory we "waste" which cannot hold a filler object .
247
- size_t words_not_fillable = 0 ;
212
+ // How many words can we use for filler objects .
213
+ size_t words_fillable = word_size_sum - word_size ;
248
214
249
- if (word_fill_size >= min_fill_size ()) {
250
- fill_with_objects (obj_top, word_fill_size );
251
- } else if (word_fill_size > 0 ) {
215
+ if (words_fillable >= G1CollectedHeap:: min_fill_size ()) {
216
+ G1CollectedHeap:: fill_with_objects (obj_top, words_fillable );
217
+ } else {
252
218
// We have space to fill, but we cannot fit an object there.
253
- words_not_fillable = word_fill_size ;
254
- word_fill_size = 0 ;
219
+ words_not_fillable = words_fillable ;
220
+ words_fillable = 0 ;
255
221
}
256
222
257
223
// We will set up the first region as "starts humongous". This
258
224
// will also update the BOT covering all the regions to reflect
259
225
// that there is a single object that starts at the bottom of the
260
226
// first region.
261
- first_hr->set_starts_humongous (obj_top, word_fill_size);
262
- _policy->remset_tracker ()->update_at_allocate (first_hr);
263
- // Then, if there are any, we will set up the "continues
264
- // humongous" regions.
265
- HeapRegion* hr = NULL ;
227
+ first_hr->hr_clear (false /* clear_space */ );
228
+ first_hr->set_starts_humongous (obj_top, words_fillable);
229
+
230
+ if (update_remsets) {
231
+ _policy->remset_tracker ()->update_at_allocate (first_hr);
232
+ }
233
+
234
+ // Indices of first and last regions in the series.
235
+ uint first = first_hr->hrm_index ();
236
+ uint last = first + num_regions - 1 ;
237
+
238
+ HeapRegion* hr = nullptr ;
266
239
for (uint i = first + 1 ; i <= last; ++i) {
267
240
hr = region_at (i);
241
+ hr->hr_clear (false /* clear_space */ );
268
242
hr->set_continues_humongous (first_hr);
269
- _policy->remset_tracker ()->update_at_allocate (hr);
243
+ if (update_remsets) {
244
+ _policy->remset_tracker ()->update_at_allocate (hr);
245
+ }
270
246
}
271
247
272
248
// Up to this point no concurrent thread would have been able to
@@ -297,11 +273,57 @@ G1CollectedHeap::humongous_obj_allocate_initialize_regions(HeapRegion* first_hr,
297
273
assert (words_not_fillable == 0 ||
298
274
first_hr->bottom () + word_size_sum - words_not_fillable == hr->top (),
299
275
" Miscalculation in humongous allocation" );
276
+ }
277
+
278
+ HeapWord*
279
+ G1CollectedHeap::humongous_obj_allocate_initialize_regions (HeapRegion* first_hr,
280
+ uint num_regions,
281
+ size_t word_size) {
282
+ assert (first_hr != NULL , " pre-condition" );
283
+ assert (is_humongous (word_size), " word_size should be humongous" );
284
+ assert (num_regions * HeapRegion::GrainWords >= word_size, " pre-condition" );
285
+
286
+ // Index of last region in the series.
287
+ uint first = first_hr->hrm_index ();
288
+ uint last = first + num_regions - 1 ;
289
+
290
+ // We need to initialize the region(s) we just discovered. This is
291
+ // a bit tricky given that it can happen concurrently with
292
+ // refinement threads refining cards on these regions and
293
+ // potentially wanting to refine the BOT as they are scanning
294
+ // those cards (this can happen shortly after a cleanup; see CR
295
+ // 6991377). So we have to set up the region(s) carefully and in
296
+ // a specific order.
300
297
301
- increase_used ((word_size_sum - words_not_fillable) * HeapWordSize);
298
+ // The passed in hr will be the "starts humongous" region. The header
299
+ // of the new object will be placed at the bottom of this region.
300
+ HeapWord* new_obj = first_hr->bottom ();
301
+
302
+ // First, we need to zero the header of the space that we will be
303
+ // allocating. When we update top further down, some refinement
304
+ // threads might try to scan the region. By zeroing the header we
305
+ // ensure that any thread that will try to scan the region will
306
+ // come across the zero klass word and bail out.
307
+ //
308
+ // NOTE: It would not have been correct to have used
309
+ // CollectedHeap::fill_with_object() and make the space look like
310
+ // an int array. The thread that is doing the allocation will
311
+ // later update the object header to a potentially different array
312
+ // type and, for a very short period of time, the klass and length
313
+ // fields will be inconsistent. This could cause a refinement
314
+ // thread to calculate the object size incorrectly.
315
+ Copy::fill_to_words (new_obj, oopDesc::header_size (), 0 );
316
+
317
+ // Next, update the metadata for the regions.
318
+ set_humongous_metadata (first_hr, num_regions, word_size, true );
319
+
320
+ HeapRegion* last_hr = region_at (last);
321
+ size_t used = byte_size (first_hr->bottom (), last_hr->top ());
322
+
323
+ increase_used (used);
302
324
303
325
for (uint i = first; i <= last; ++i) {
304
- hr = region_at (i);
326
+ HeapRegion * hr = region_at (i);
305
327
_humongous_set.add (hr);
306
328
_hr_printer.alloc (hr);
307
329
}
1 commit comments
openjdk-notifier[bot] commentedon Mar 16, 2023
Review
Issues