Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp
41149 views
1
/*
2
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "code/codeCache.hpp"
27
#include "gc/parallel/parallelArguments.hpp"
28
#include "gc/parallel/objectStartArray.inline.hpp"
29
#include "gc/parallel/parallelInitLogger.hpp"
30
#include "gc/parallel/parallelScavengeHeap.inline.hpp"
31
#include "gc/parallel/psAdaptiveSizePolicy.hpp"
32
#include "gc/parallel/psMemoryPool.hpp"
33
#include "gc/parallel/psParallelCompact.inline.hpp"
34
#include "gc/parallel/psPromotionManager.hpp"
35
#include "gc/parallel/psScavenge.hpp"
36
#include "gc/parallel/psVMOperations.hpp"
37
#include "gc/shared/gcHeapSummary.hpp"
38
#include "gc/shared/gcLocker.hpp"
39
#include "gc/shared/gcWhen.hpp"
40
#include "gc/shared/genArguments.hpp"
41
#include "gc/shared/gcInitLogger.hpp"
42
#include "gc/shared/locationPrinter.inline.hpp"
43
#include "gc/shared/scavengableNMethods.hpp"
44
#include "logging/log.hpp"
45
#include "memory/iterator.hpp"
46
#include "memory/metaspaceCounters.hpp"
47
#include "memory/metaspaceUtils.hpp"
48
#include "memory/universe.hpp"
49
#include "oops/oop.inline.hpp"
50
#include "runtime/handles.inline.hpp"
51
#include "runtime/java.hpp"
52
#include "runtime/vmThread.hpp"
53
#include "services/memoryManager.hpp"
54
#include "services/memTracker.hpp"
55
#include "utilities/macros.hpp"
56
#include "utilities/vmError.hpp"
57
58
PSYoungGen* ParallelScavengeHeap::_young_gen = NULL;
59
PSOldGen* ParallelScavengeHeap::_old_gen = NULL;
60
PSAdaptiveSizePolicy* ParallelScavengeHeap::_size_policy = NULL;
61
PSGCAdaptivePolicyCounters* ParallelScavengeHeap::_gc_policy_counters = NULL;
62
63
jint ParallelScavengeHeap::initialize() {
64
const size_t reserved_heap_size = ParallelArguments::heap_reserved_size_bytes();
65
66
ReservedHeapSpace heap_rs = Universe::reserve_heap(reserved_heap_size, HeapAlignment);
67
68
trace_actual_reserved_page_size(reserved_heap_size, heap_rs);
69
70
initialize_reserved_region(heap_rs);
71
72
PSCardTable* card_table = new PSCardTable(heap_rs.region());
73
card_table->initialize();
74
CardTableBarrierSet* const barrier_set = new CardTableBarrierSet(card_table);
75
barrier_set->initialize();
76
BarrierSet::set_barrier_set(barrier_set);
77
78
// Make up the generations
79
assert(MinOldSize <= OldSize && OldSize <= MaxOldSize, "Parameter check");
80
assert(MinNewSize <= NewSize && NewSize <= MaxNewSize, "Parameter check");
81
82
// Layout the reserved space for the generations.
83
ReservedSpace old_rs = heap_rs.first_part(MaxOldSize);
84
ReservedSpace young_rs = heap_rs.last_part(MaxOldSize);
85
assert(young_rs.size() == MaxNewSize, "Didn't reserve all of the heap");
86
87
// Set up WorkGang
88
_workers.initialize_workers();
89
90
// Create and initialize the generations.
91
_young_gen = new PSYoungGen(
92
young_rs,
93
NewSize,
94
MinNewSize,
95
MaxNewSize);
96
_old_gen = new PSOldGen(
97
old_rs,
98
OldSize,
99
MinOldSize,
100
MaxOldSize,
101
"old", 1);
102
103
assert(young_gen()->max_gen_size() == young_rs.size(),"Consistency check");
104
assert(old_gen()->max_gen_size() == old_rs.size(), "Consistency check");
105
106
double max_gc_pause_sec = ((double) MaxGCPauseMillis)/1000.0;
107
double max_gc_minor_pause_sec = ((double) MaxGCMinorPauseMillis)/1000.0;
108
109
const size_t eden_capacity = _young_gen->eden_space()->capacity_in_bytes();
110
const size_t old_capacity = _old_gen->capacity_in_bytes();
111
const size_t initial_promo_size = MIN2(eden_capacity, old_capacity);
112
_size_policy =
113
new PSAdaptiveSizePolicy(eden_capacity,
114
initial_promo_size,
115
young_gen()->to_space()->capacity_in_bytes(),
116
GenAlignment,
117
max_gc_pause_sec,
118
max_gc_minor_pause_sec,
119
GCTimeRatio
120
);
121
122
assert((old_gen()->virtual_space()->high_boundary() ==
123
young_gen()->virtual_space()->low_boundary()),
124
"Boundaries must meet");
125
// initialize the policy counters - 2 collectors, 2 generations
126
_gc_policy_counters =
127
new PSGCAdaptivePolicyCounters("ParScav:MSC", 2, 2, _size_policy);
128
129
if (!PSParallelCompact::initialize()) {
130
return JNI_ENOMEM;
131
}
132
133
ParallelInitLogger::print();
134
135
return JNI_OK;
136
}
137
138
void ParallelScavengeHeap::initialize_serviceability() {
139
140
_eden_pool = new EdenMutableSpacePool(_young_gen,
141
_young_gen->eden_space(),
142
"PS Eden Space",
143
false /* support_usage_threshold */);
144
145
_survivor_pool = new SurvivorMutableSpacePool(_young_gen,
146
"PS Survivor Space",
147
false /* support_usage_threshold */);
148
149
_old_pool = new PSGenerationPool(_old_gen,
150
"PS Old Gen",
151
true /* support_usage_threshold */);
152
153
_young_manager = new GCMemoryManager("PS Scavenge", "end of minor GC");
154
_old_manager = new GCMemoryManager("PS MarkSweep", "end of major GC");
155
156
_old_manager->add_pool(_eden_pool);
157
_old_manager->add_pool(_survivor_pool);
158
_old_manager->add_pool(_old_pool);
159
160
_young_manager->add_pool(_eden_pool);
161
_young_manager->add_pool(_survivor_pool);
162
163
}
164
165
class PSIsScavengable : public BoolObjectClosure {
166
bool do_object_b(oop obj) {
167
return ParallelScavengeHeap::heap()->is_in_young(obj);
168
}
169
};
170
171
static PSIsScavengable _is_scavengable;
172
173
void ParallelScavengeHeap::post_initialize() {
174
CollectedHeap::post_initialize();
175
// Need to init the tenuring threshold
176
PSScavenge::initialize();
177
PSParallelCompact::post_initialize();
178
PSPromotionManager::initialize();
179
180
ScavengableNMethods::initialize(&_is_scavengable);
181
}
182
183
void ParallelScavengeHeap::update_counters() {
184
young_gen()->update_counters();
185
old_gen()->update_counters();
186
MetaspaceCounters::update_performance_counters();
187
}
188
189
size_t ParallelScavengeHeap::capacity() const {
190
size_t value = young_gen()->capacity_in_bytes() + old_gen()->capacity_in_bytes();
191
return value;
192
}
193
194
size_t ParallelScavengeHeap::used() const {
195
size_t value = young_gen()->used_in_bytes() + old_gen()->used_in_bytes();
196
return value;
197
}
198
199
bool ParallelScavengeHeap::is_maximal_no_gc() const {
200
return old_gen()->is_maximal_no_gc() && young_gen()->is_maximal_no_gc();
201
}
202
203
204
size_t ParallelScavengeHeap::max_capacity() const {
205
size_t estimated = reserved_region().byte_size();
206
if (UseAdaptiveSizePolicy) {
207
estimated -= _size_policy->max_survivor_size(young_gen()->max_gen_size());
208
} else {
209
estimated -= young_gen()->to_space()->capacity_in_bytes();
210
}
211
return MAX2(estimated, capacity());
212
}
213
214
bool ParallelScavengeHeap::is_in(const void* p) const {
215
return young_gen()->is_in(p) || old_gen()->is_in(p);
216
}
217
218
bool ParallelScavengeHeap::is_in_reserved(const void* p) const {
219
return young_gen()->is_in_reserved(p) || old_gen()->is_in_reserved(p);
220
}
221
222
// There are two levels of allocation policy here.
223
//
224
// When an allocation request fails, the requesting thread must invoke a VM
225
// operation, transfer control to the VM thread, and await the results of a
226
// garbage collection. That is quite expensive, and we should avoid doing it
227
// multiple times if possible.
228
//
229
// To accomplish this, we have a basic allocation policy, and also a
230
// failed allocation policy.
231
//
232
// The basic allocation policy controls how you allocate memory without
233
// attempting garbage collection. It is okay to grab locks and
234
// expand the heap, if that can be done without coming to a safepoint.
235
// It is likely that the basic allocation policy will not be very
236
// aggressive.
237
//
238
// The failed allocation policy is invoked from the VM thread after
239
// the basic allocation policy is unable to satisfy a mem_allocate
240
// request. This policy needs to cover the entire range of collection,
241
// heap expansion, and out-of-memory conditions. It should make every
242
// attempt to allocate the requested memory.
243
244
// Basic allocation policy. Should never be called at a safepoint, or
245
// from the VM thread.
246
//
247
// This method must handle cases where many mem_allocate requests fail
248
// simultaneously. When that happens, only one VM operation will succeed,
249
// and the rest will not be executed. For that reason, this method loops
250
// during failed allocation attempts. If the java heap becomes exhausted,
251
// we rely on the size_policy object to force a bail out.
252
HeapWord* ParallelScavengeHeap::mem_allocate(
253
size_t size,
254
bool* gc_overhead_limit_was_exceeded) {
255
assert(!SafepointSynchronize::is_at_safepoint(), "should not be at safepoint");
256
assert(Thread::current() != (Thread*)VMThread::vm_thread(), "should not be in vm thread");
257
assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
258
259
// In general gc_overhead_limit_was_exceeded should be false so
260
// set it so here and reset it to true only if the gc time
261
// limit is being exceeded as checked below.
262
*gc_overhead_limit_was_exceeded = false;
263
264
HeapWord* result = young_gen()->allocate(size);
265
266
uint loop_count = 0;
267
uint gc_count = 0;
268
uint gclocker_stalled_count = 0;
269
270
while (result == NULL) {
271
// We don't want to have multiple collections for a single filled generation.
272
// To prevent this, each thread tracks the total_collections() value, and if
273
// the count has changed, does not do a new collection.
274
//
275
// The collection count must be read only while holding the heap lock. VM
276
// operations also hold the heap lock during collections. There is a lock
277
// contention case where thread A blocks waiting on the Heap_lock, while
278
// thread B is holding it doing a collection. When thread A gets the lock,
279
// the collection count has already changed. To prevent duplicate collections,
280
// The policy MUST attempt allocations during the same period it reads the
281
// total_collections() value!
282
{
283
MutexLocker ml(Heap_lock);
284
gc_count = total_collections();
285
286
result = young_gen()->allocate(size);
287
if (result != NULL) {
288
return result;
289
}
290
291
// If certain conditions hold, try allocating from the old gen.
292
result = mem_allocate_old_gen(size);
293
if (result != NULL) {
294
return result;
295
}
296
297
if (gclocker_stalled_count > GCLockerRetryAllocationCount) {
298
return NULL;
299
}
300
301
// Failed to allocate without a gc.
302
if (GCLocker::is_active_and_needs_gc()) {
303
// If this thread is not in a jni critical section, we stall
304
// the requestor until the critical section has cleared and
305
// GC allowed. When the critical section clears, a GC is
306
// initiated by the last thread exiting the critical section; so
307
// we retry the allocation sequence from the beginning of the loop,
308
// rather than causing more, now probably unnecessary, GC attempts.
309
JavaThread* jthr = JavaThread::current();
310
if (!jthr->in_critical()) {
311
MutexUnlocker mul(Heap_lock);
312
GCLocker::stall_until_clear();
313
gclocker_stalled_count += 1;
314
continue;
315
} else {
316
if (CheckJNICalls) {
317
fatal("Possible deadlock due to allocating while"
318
" in jni critical section");
319
}
320
return NULL;
321
}
322
}
323
}
324
325
if (result == NULL) {
326
// Generate a VM operation
327
VM_ParallelGCFailedAllocation op(size, gc_count);
328
VMThread::execute(&op);
329
330
// Did the VM operation execute? If so, return the result directly.
331
// This prevents us from looping until time out on requests that can
332
// not be satisfied.
333
if (op.prologue_succeeded()) {
334
assert(is_in_or_null(op.result()), "result not in heap");
335
336
// If GC was locked out during VM operation then retry allocation
337
// and/or stall as necessary.
338
if (op.gc_locked()) {
339
assert(op.result() == NULL, "must be NULL if gc_locked() is true");
340
continue; // retry and/or stall as necessary
341
}
342
343
// Exit the loop if the gc time limit has been exceeded.
344
// The allocation must have failed above ("result" guarding
345
// this path is NULL) and the most recent collection has exceeded the
346
// gc overhead limit (although enough may have been collected to
347
// satisfy the allocation). Exit the loop so that an out-of-memory
348
// will be thrown (return a NULL ignoring the contents of
349
// op.result()),
350
// but clear gc_overhead_limit_exceeded so that the next collection
351
// starts with a clean slate (i.e., forgets about previous overhead
352
// excesses). Fill op.result() with a filler object so that the
353
// heap remains parsable.
354
const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded();
355
const bool softrefs_clear = soft_ref_policy()->all_soft_refs_clear();
356
357
if (limit_exceeded && softrefs_clear) {
358
*gc_overhead_limit_was_exceeded = true;
359
size_policy()->set_gc_overhead_limit_exceeded(false);
360
log_trace(gc)("ParallelScavengeHeap::mem_allocate: return NULL because gc_overhead_limit_exceeded is set");
361
if (op.result() != NULL) {
362
CollectedHeap::fill_with_object(op.result(), size);
363
}
364
return NULL;
365
}
366
367
return op.result();
368
}
369
}
370
371
// The policy object will prevent us from looping forever. If the
372
// time spent in gc crosses a threshold, we will bail out.
373
loop_count++;
374
if ((result == NULL) && (QueuedAllocationWarningCount > 0) &&
375
(loop_count % QueuedAllocationWarningCount == 0)) {
376
log_warning(gc)("ParallelScavengeHeap::mem_allocate retries %d times", loop_count);
377
log_warning(gc)("\tsize=" SIZE_FORMAT, size);
378
}
379
}
380
381
return result;
382
}
383
384
// A "death march" is a series of ultra-slow allocations in which a full gc is
385
// done before each allocation, and after the full gc the allocation still
386
// cannot be satisfied from the young gen. This routine detects that condition;
387
// it should be called after a full gc has been done and the allocation
388
// attempted from the young gen. The parameter 'addr' should be the result of
389
// that young gen allocation attempt.
390
void
391
ParallelScavengeHeap::death_march_check(HeapWord* const addr, size_t size) {
392
if (addr != NULL) {
393
_death_march_count = 0; // death march has ended
394
} else if (_death_march_count == 0) {
395
if (should_alloc_in_eden(size)) {
396
_death_march_count = 1; // death march has started
397
}
398
}
399
}
400
401
HeapWord* ParallelScavengeHeap::allocate_old_gen_and_record(size_t size) {
402
assert_locked_or_safepoint(Heap_lock);
403
HeapWord* res = old_gen()->allocate(size);
404
if (res != NULL) {
405
_size_policy->tenured_allocation(size * HeapWordSize);
406
}
407
return res;
408
}
409
410
HeapWord* ParallelScavengeHeap::mem_allocate_old_gen(size_t size) {
411
if (!should_alloc_in_eden(size) || GCLocker::is_active_and_needs_gc()) {
412
// Size is too big for eden, or gc is locked out.
413
return allocate_old_gen_and_record(size);
414
}
415
416
// If a "death march" is in progress, allocate from the old gen a limited
417
// number of times before doing a GC.
418
if (_death_march_count > 0) {
419
if (_death_march_count < 64) {
420
++_death_march_count;
421
return allocate_old_gen_and_record(size);
422
} else {
423
_death_march_count = 0;
424
}
425
}
426
return NULL;
427
}
428
429
void ParallelScavengeHeap::do_full_collection(bool clear_all_soft_refs) {
430
// The do_full_collection() parameter clear_all_soft_refs
431
// is interpreted here as maximum_compaction which will
432
// cause SoftRefs to be cleared.
433
bool maximum_compaction = clear_all_soft_refs;
434
PSParallelCompact::invoke(maximum_compaction);
435
}
436
437
// Failed allocation policy. Must be called from the VM thread, and
438
// only at a safepoint! Note that this method has policy for allocation
439
// flow, and NOT collection policy. So we do not check for gc collection
440
// time over limit here, that is the responsibility of the heap specific
441
// collection methods. This method decides where to attempt allocations,
442
// and when to attempt collections, but no collection specific policy.
443
HeapWord* ParallelScavengeHeap::failed_mem_allocate(size_t size) {
444
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
445
assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
446
assert(!is_gc_active(), "not reentrant");
447
assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
448
449
// We assume that allocation in eden will fail unless we collect.
450
451
// First level allocation failure, scavenge and allocate in young gen.
452
GCCauseSetter gccs(this, GCCause::_allocation_failure);
453
const bool invoked_full_gc = PSScavenge::invoke();
454
HeapWord* result = young_gen()->allocate(size);
455
456
// Second level allocation failure.
457
// Mark sweep and allocate in young generation.
458
if (result == NULL && !invoked_full_gc) {
459
do_full_collection(false);
460
result = young_gen()->allocate(size);
461
}
462
463
death_march_check(result, size);
464
465
// Third level allocation failure.
466
// After mark sweep and young generation allocation failure,
467
// allocate in old generation.
468
if (result == NULL) {
469
result = allocate_old_gen_and_record(size);
470
}
471
472
// Fourth level allocation failure. We're running out of memory.
473
// More complete mark sweep and allocate in young generation.
474
if (result == NULL) {
475
do_full_collection(true);
476
result = young_gen()->allocate(size);
477
}
478
479
// Fifth level allocation failure.
480
// After more complete mark sweep, allocate in old generation.
481
if (result == NULL) {
482
result = allocate_old_gen_and_record(size);
483
}
484
485
return result;
486
}
487
488
void ParallelScavengeHeap::ensure_parsability(bool retire_tlabs) {
489
CollectedHeap::ensure_parsability(retire_tlabs);
490
young_gen()->eden_space()->ensure_parsability();
491
}
492
493
size_t ParallelScavengeHeap::tlab_capacity(Thread* thr) const {
494
return young_gen()->eden_space()->tlab_capacity(thr);
495
}
496
497
size_t ParallelScavengeHeap::tlab_used(Thread* thr) const {
498
return young_gen()->eden_space()->tlab_used(thr);
499
}
500
501
size_t ParallelScavengeHeap::unsafe_max_tlab_alloc(Thread* thr) const {
502
return young_gen()->eden_space()->unsafe_max_tlab_alloc(thr);
503
}
504
505
HeapWord* ParallelScavengeHeap::allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) {
506
HeapWord* result = young_gen()->allocate(requested_size);
507
if (result != NULL) {
508
*actual_size = requested_size;
509
}
510
511
return result;
512
}
513
514
void ParallelScavengeHeap::resize_all_tlabs() {
515
CollectedHeap::resize_all_tlabs();
516
}
517
518
// This method is used by System.gc() and JVMTI.
519
void ParallelScavengeHeap::collect(GCCause::Cause cause) {
520
assert(!Heap_lock->owned_by_self(),
521
"this thread should not own the Heap_lock");
522
523
uint gc_count = 0;
524
uint full_gc_count = 0;
525
{
526
MutexLocker ml(Heap_lock);
527
// This value is guarded by the Heap_lock
528
gc_count = total_collections();
529
full_gc_count = total_full_collections();
530
}
531
532
if (GCLocker::should_discard(cause, gc_count)) {
533
return;
534
}
535
536
VM_ParallelGCSystemGC op(gc_count, full_gc_count, cause);
537
VMThread::execute(&op);
538
}
539
540
void ParallelScavengeHeap::object_iterate(ObjectClosure* cl) {
541
young_gen()->object_iterate(cl);
542
old_gen()->object_iterate(cl);
543
}
544
545
// The HeapBlockClaimer is used during parallel iteration over the heap,
546
// allowing workers to claim heap areas ("blocks"), gaining exclusive rights to these.
547
// The eden and survivor spaces are treated as single blocks as it is hard to divide
548
// these spaces.
549
// The old space is divided into fixed-size blocks.
550
class HeapBlockClaimer : public StackObj {
551
size_t _claimed_index;
552
553
public:
554
static const size_t InvalidIndex = SIZE_MAX;
555
static const size_t EdenIndex = 0;
556
static const size_t SurvivorIndex = 1;
557
static const size_t NumNonOldGenClaims = 2;
558
559
HeapBlockClaimer() : _claimed_index(EdenIndex) { }
560
// Claim the block and get the block index.
561
size_t claim_and_get_block() {
562
size_t block_index;
563
block_index = Atomic::fetch_and_add(&_claimed_index, 1u);
564
565
PSOldGen* old_gen = ParallelScavengeHeap::heap()->old_gen();
566
size_t num_claims = old_gen->num_iterable_blocks() + NumNonOldGenClaims;
567
568
return block_index < num_claims ? block_index : InvalidIndex;
569
}
570
};
571
572
void ParallelScavengeHeap::object_iterate_parallel(ObjectClosure* cl,
573
HeapBlockClaimer* claimer) {
574
size_t block_index = claimer->claim_and_get_block();
575
// Iterate until all blocks are claimed
576
if (block_index == HeapBlockClaimer::EdenIndex) {
577
young_gen()->eden_space()->object_iterate(cl);
578
block_index = claimer->claim_and_get_block();
579
}
580
if (block_index == HeapBlockClaimer::SurvivorIndex) {
581
young_gen()->from_space()->object_iterate(cl);
582
young_gen()->to_space()->object_iterate(cl);
583
block_index = claimer->claim_and_get_block();
584
}
585
while (block_index != HeapBlockClaimer::InvalidIndex) {
586
old_gen()->object_iterate_block(cl, block_index - HeapBlockClaimer::NumNonOldGenClaims);
587
block_index = claimer->claim_and_get_block();
588
}
589
}
590
591
class PSScavengeParallelObjectIterator : public ParallelObjectIterator {
592
private:
593
ParallelScavengeHeap* _heap;
594
HeapBlockClaimer _claimer;
595
596
public:
597
PSScavengeParallelObjectIterator() :
598
_heap(ParallelScavengeHeap::heap()),
599
_claimer() {}
600
601
virtual void object_iterate(ObjectClosure* cl, uint worker_id) {
602
_heap->object_iterate_parallel(cl, &_claimer);
603
}
604
};
605
606
ParallelObjectIterator* ParallelScavengeHeap::parallel_object_iterator(uint thread_num) {
607
return new PSScavengeParallelObjectIterator();
608
}
609
610
HeapWord* ParallelScavengeHeap::block_start(const void* addr) const {
611
if (young_gen()->is_in_reserved(addr)) {
612
assert(young_gen()->is_in(addr),
613
"addr should be in allocated part of young gen");
614
// called from os::print_location by find or VMError
615
if (Debugging || VMError::is_error_reported()) return NULL;
616
Unimplemented();
617
} else if (old_gen()->is_in_reserved(addr)) {
618
assert(old_gen()->is_in(addr),
619
"addr should be in allocated part of old gen");
620
return old_gen()->start_array()->object_start((HeapWord*)addr);
621
}
622
return 0;
623
}
624
625
bool ParallelScavengeHeap::block_is_obj(const HeapWord* addr) const {
626
return block_start(addr) == addr;
627
}
628
629
void ParallelScavengeHeap::prepare_for_verify() {
630
ensure_parsability(false); // no need to retire TLABs for verification
631
}
632
633
PSHeapSummary ParallelScavengeHeap::create_ps_heap_summary() {
634
PSOldGen* old = old_gen();
635
HeapWord* old_committed_end = (HeapWord*)old->virtual_space()->committed_high_addr();
636
VirtualSpaceSummary old_summary(old->reserved().start(), old_committed_end, old->reserved().end());
637
SpaceSummary old_space(old->reserved().start(), old_committed_end, old->used_in_bytes());
638
639
PSYoungGen* young = young_gen();
640
VirtualSpaceSummary young_summary(young->reserved().start(),
641
(HeapWord*)young->virtual_space()->committed_high_addr(), young->reserved().end());
642
643
MutableSpace* eden = young_gen()->eden_space();
644
SpaceSummary eden_space(eden->bottom(), eden->end(), eden->used_in_bytes());
645
646
MutableSpace* from = young_gen()->from_space();
647
SpaceSummary from_space(from->bottom(), from->end(), from->used_in_bytes());
648
649
MutableSpace* to = young_gen()->to_space();
650
SpaceSummary to_space(to->bottom(), to->end(), to->used_in_bytes());
651
652
VirtualSpaceSummary heap_summary = create_heap_space_summary();
653
return PSHeapSummary(heap_summary, used(), old_summary, old_space, young_summary, eden_space, from_space, to_space);
654
}
655
656
bool ParallelScavengeHeap::print_location(outputStream* st, void* addr) const {
657
return BlockLocationPrinter<ParallelScavengeHeap>::print_location(st, addr);
658
}
659
660
void ParallelScavengeHeap::print_on(outputStream* st) const {
661
if (young_gen() != NULL) {
662
young_gen()->print_on(st);
663
}
664
if (old_gen() != NULL) {
665
old_gen()->print_on(st);
666
}
667
MetaspaceUtils::print_on(st);
668
}
669
670
void ParallelScavengeHeap::print_on_error(outputStream* st) const {
671
this->CollectedHeap::print_on_error(st);
672
673
st->cr();
674
PSParallelCompact::print_on_error(st);
675
}
676
677
void ParallelScavengeHeap::gc_threads_do(ThreadClosure* tc) const {
678
ParallelScavengeHeap::heap()->workers().threads_do(tc);
679
}
680
681
void ParallelScavengeHeap::print_tracing_info() const {
682
AdaptiveSizePolicyOutput::print();
683
log_debug(gc, heap, exit)("Accumulated young generation GC time %3.7f secs", PSScavenge::accumulated_time()->seconds());
684
log_debug(gc, heap, exit)("Accumulated old generation GC time %3.7f secs", PSParallelCompact::accumulated_time()->seconds());
685
}
686
687
PreGenGCValues ParallelScavengeHeap::get_pre_gc_values() const {
688
const PSYoungGen* const young = young_gen();
689
const MutableSpace* const eden = young->eden_space();
690
const MutableSpace* const from = young->from_space();
691
const PSOldGen* const old = old_gen();
692
693
return PreGenGCValues(young->used_in_bytes(),
694
young->capacity_in_bytes(),
695
eden->used_in_bytes(),
696
eden->capacity_in_bytes(),
697
from->used_in_bytes(),
698
from->capacity_in_bytes(),
699
old->used_in_bytes(),
700
old->capacity_in_bytes());
701
}
702
703
void ParallelScavengeHeap::print_heap_change(const PreGenGCValues& pre_gc_values) const {
704
const PSYoungGen* const young = young_gen();
705
const MutableSpace* const eden = young->eden_space();
706
const MutableSpace* const from = young->from_space();
707
const PSOldGen* const old = old_gen();
708
709
log_info(gc, heap)(HEAP_CHANGE_FORMAT" "
710
HEAP_CHANGE_FORMAT" "
711
HEAP_CHANGE_FORMAT,
712
HEAP_CHANGE_FORMAT_ARGS(young->name(),
713
pre_gc_values.young_gen_used(),
714
pre_gc_values.young_gen_capacity(),
715
young->used_in_bytes(),
716
young->capacity_in_bytes()),
717
HEAP_CHANGE_FORMAT_ARGS("Eden",
718
pre_gc_values.eden_used(),
719
pre_gc_values.eden_capacity(),
720
eden->used_in_bytes(),
721
eden->capacity_in_bytes()),
722
HEAP_CHANGE_FORMAT_ARGS("From",
723
pre_gc_values.from_used(),
724
pre_gc_values.from_capacity(),
725
from->used_in_bytes(),
726
from->capacity_in_bytes()));
727
log_info(gc, heap)(HEAP_CHANGE_FORMAT,
728
HEAP_CHANGE_FORMAT_ARGS(old->name(),
729
pre_gc_values.old_gen_used(),
730
pre_gc_values.old_gen_capacity(),
731
old->used_in_bytes(),
732
old->capacity_in_bytes()));
733
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());
734
}
735
736
void ParallelScavengeHeap::verify(VerifyOption option /* ignored */) {
737
// Why do we need the total_collections()-filter below?
738
if (total_collections() > 0) {
739
log_debug(gc, verify)("Tenured");
740
old_gen()->verify();
741
742
log_debug(gc, verify)("Eden");
743
young_gen()->verify();
744
}
745
}
746
747
void ParallelScavengeHeap::trace_actual_reserved_page_size(const size_t reserved_heap_size, const ReservedSpace rs) {
748
// Check if Info level is enabled, since os::trace_page_sizes() logs on Info level.
749
if(log_is_enabled(Info, pagesize)) {
750
const size_t page_size = rs.page_size();
751
os::trace_page_sizes("Heap",
752
MinHeapSize,
753
reserved_heap_size,
754
page_size,
755
rs.base(),
756
rs.size());
757
}
758
}
759
760
void ParallelScavengeHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
761
const PSHeapSummary& heap_summary = create_ps_heap_summary();
762
gc_tracer->report_gc_heap_summary(when, heap_summary);
763
764
const MetaspaceSummary& metaspace_summary = create_metaspace_summary();
765
gc_tracer->report_metaspace_summary(when, metaspace_summary);
766
}
767
768
CardTableBarrierSet* ParallelScavengeHeap::barrier_set() {
769
return barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set());
770
}
771
772
PSCardTable* ParallelScavengeHeap::card_table() {
773
return static_cast<PSCardTable*>(barrier_set()->card_table());
774
}
775
776
void ParallelScavengeHeap::resize_young_gen(size_t eden_size,
777
size_t survivor_size) {
778
// Delegate the resize to the generation.
779
_young_gen->resize(eden_size, survivor_size);
780
}
781
782
void ParallelScavengeHeap::resize_old_gen(size_t desired_free_space) {
783
// Delegate the resize to the generation.
784
_old_gen->resize(desired_free_space);
785
}
786
787
ParallelScavengeHeap::ParStrongRootsScope::ParStrongRootsScope() {
788
// nothing particular
789
}
790
791
ParallelScavengeHeap::ParStrongRootsScope::~ParStrongRootsScope() {
792
// nothing particular
793
}
794
795
#ifndef PRODUCT
796
void ParallelScavengeHeap::record_gen_tops_before_GC() {
797
if (ZapUnusedHeapArea) {
798
young_gen()->record_spaces_top();
799
old_gen()->record_spaces_top();
800
}
801
}
802
803
void ParallelScavengeHeap::gen_mangle_unused_area() {
804
if (ZapUnusedHeapArea) {
805
young_gen()->eden_space()->mangle_unused_area();
806
young_gen()->to_space()->mangle_unused_area();
807
young_gen()->from_space()->mangle_unused_area();
808
old_gen()->object_space()->mangle_unused_area();
809
}
810
}
811
#endif
812
813
void ParallelScavengeHeap::register_nmethod(nmethod* nm) {
814
ScavengableNMethods::register_nmethod(nm);
815
}
816
817
void ParallelScavengeHeap::unregister_nmethod(nmethod* nm) {
818
ScavengableNMethods::unregister_nmethod(nm);
819
}
820
821
void ParallelScavengeHeap::verify_nmethod(nmethod* nm) {
822
ScavengableNMethods::verify_nmethod(nm);
823
}
824
825
void ParallelScavengeHeap::flush_nmethod(nmethod* nm) {
826
// nothing particular
827
}
828
829
void ParallelScavengeHeap::prune_scavengable_nmethods() {
830
ScavengableNMethods::prune_nmethods();
831
}
832
833
GrowableArray<GCMemoryManager*> ParallelScavengeHeap::memory_managers() {
834
GrowableArray<GCMemoryManager*> memory_managers(2);
835
memory_managers.append(_young_manager);
836
memory_managers.append(_old_manager);
837
return memory_managers;
838
}
839
840
GrowableArray<MemoryPool*> ParallelScavengeHeap::memory_pools() {
841
GrowableArray<MemoryPool*> memory_pools(3);
842
memory_pools.append(_eden_pool);
843
memory_pools.append(_survivor_pool);
844
memory_pools.append(_old_pool);
845
return memory_pools;
846
}
847
848