Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1CollectedHeap.hpp
40959 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
#ifndef SHARE_GC_G1_G1COLLECTEDHEAP_HPP
26
#define SHARE_GC_G1_G1COLLECTEDHEAP_HPP
27
28
#include "gc/g1/g1BarrierSet.hpp"
29
#include "gc/g1/g1BiasedArray.hpp"
30
#include "gc/g1/g1CardTable.hpp"
31
#include "gc/g1/g1CollectionSet.hpp"
32
#include "gc/g1/g1CollectorState.hpp"
33
#include "gc/g1/g1ConcurrentMark.hpp"
34
#include "gc/g1/g1EdenRegions.hpp"
35
#include "gc/g1/g1EvacFailure.hpp"
36
#include "gc/g1/g1EvacStats.hpp"
37
#include "gc/g1/g1EvacuationInfo.hpp"
38
#include "gc/g1/g1GCPhaseTimes.hpp"
39
#include "gc/g1/g1GCPauseType.hpp"
40
#include "gc/g1/g1HeapTransition.hpp"
41
#include "gc/g1/g1HeapVerifier.hpp"
42
#include "gc/g1/g1HRPrinter.hpp"
43
#include "gc/g1/g1HeapRegionAttr.hpp"
44
#include "gc/g1/g1MonitoringSupport.hpp"
45
#include "gc/g1/g1NUMA.hpp"
46
#include "gc/g1/g1RedirtyCardsQueue.hpp"
47
#include "gc/g1/g1SurvivorRegions.hpp"
48
#include "gc/g1/heapRegionManager.hpp"
49
#include "gc/g1/heapRegionSet.hpp"
50
#include "gc/shared/barrierSet.hpp"
51
#include "gc/shared/collectedHeap.hpp"
52
#include "gc/shared/gcHeapSummary.hpp"
53
#include "gc/shared/plab.hpp"
54
#include "gc/shared/preservedMarks.hpp"
55
#include "gc/shared/softRefPolicy.hpp"
56
#include "gc/shared/taskqueue.hpp"
57
#include "memory/memRegion.hpp"
58
#include "utilities/stack.hpp"
59
60
// A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
61
// It uses the "Garbage First" heap organization and algorithm, which
62
// may combine concurrent marking with parallel, incremental compaction of
63
// heap subsets that will yield large amounts of garbage.
64
65
// Forward declarations
66
class HeapRegion;
67
class GenerationSpec;
68
class G1ParScanThreadState;
69
class G1ParScanThreadStateSet;
70
class G1ParScanThreadState;
71
class MemoryPool;
72
class MemoryManager;
73
class ObjectClosure;
74
class SpaceClosure;
75
class CompactibleSpaceClosure;
76
class Space;
77
class G1BatchedGangTask;
78
class G1CardTableEntryClosure;
79
class G1CollectionSet;
80
class G1Policy;
81
class G1HotCardCache;
82
class G1RemSet;
83
class G1ServiceTask;
84
class G1ServiceThread;
85
class G1ConcurrentMark;
86
class G1ConcurrentMarkThread;
87
class G1ConcurrentRefine;
88
class GenerationCounters;
89
class STWGCTimer;
90
class G1NewTracer;
91
class EvacuationFailedInfo;
92
class nmethod;
93
class WorkGang;
94
class G1Allocator;
95
class G1ArchiveAllocator;
96
class G1FullGCScope;
97
class G1HeapVerifier;
98
class G1HeapSizingPolicy;
99
class G1HeapSummary;
100
class G1EvacSummary;
101
102
typedef OverflowTaskQueue<ScannerTask, mtGC> G1ScannerTasksQueue;
103
typedef GenericTaskQueueSet<G1ScannerTasksQueue, mtGC> G1ScannerTasksQueueSet;
104
105
typedef int RegionIdx_t; // needs to hold [ 0..max_reserved_regions() )
106
typedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion )
107
108
// The G1 STW is alive closure.
109
// An instance is embedded into the G1CH and used as the
110
// (optional) _is_alive_non_header closure in the STW
111
// reference processor. It is also extensively used during
112
// reference processing during STW evacuation pauses.
113
class G1STWIsAliveClosure : public BoolObjectClosure {
114
G1CollectedHeap* _g1h;
115
public:
116
G1STWIsAliveClosure(G1CollectedHeap* g1h) : _g1h(g1h) {}
117
bool do_object_b(oop p);
118
};
119
120
class G1STWSubjectToDiscoveryClosure : public BoolObjectClosure {
121
G1CollectedHeap* _g1h;
122
public:
123
G1STWSubjectToDiscoveryClosure(G1CollectedHeap* g1h) : _g1h(g1h) {}
124
bool do_object_b(oop p);
125
};
126
127
class G1RegionMappingChangedListener : public G1MappingChangedListener {
128
private:
129
void reset_from_card_cache(uint start_idx, size_t num_regions);
130
public:
131
virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);
132
};
133
134
class G1CollectedHeap : public CollectedHeap {
135
friend class VM_CollectForMetadataAllocation;
136
friend class VM_G1CollectForAllocation;
137
friend class VM_G1CollectFull;
138
friend class VM_G1TryInitiateConcMark;
139
friend class VMStructs;
140
friend class MutatorAllocRegion;
141
friend class G1FullCollector;
142
friend class G1GCAllocRegion;
143
friend class G1HeapVerifier;
144
145
// Closures used in implementation.
146
friend class G1ParScanThreadState;
147
friend class G1ParScanThreadStateSet;
148
friend class G1EvacuateRegionsTask;
149
friend class G1PLABAllocator;
150
151
// Other related classes.
152
friend class HeapRegionClaimer;
153
154
// Testing classes.
155
friend class G1CheckRegionAttrTableClosure;
156
157
private:
158
G1ServiceThread* _service_thread;
159
G1ServiceTask* _periodic_gc_task;
160
161
WorkGang* _workers;
162
G1CardTable* _card_table;
163
164
Ticks _collection_pause_end;
165
166
SoftRefPolicy _soft_ref_policy;
167
168
static size_t _humongous_object_threshold_in_words;
169
170
// These sets keep track of old, archive and humongous regions respectively.
171
HeapRegionSet _old_set;
172
HeapRegionSet _archive_set;
173
HeapRegionSet _humongous_set;
174
175
void rebuild_free_region_list();
176
// Start a new incremental collection set for the next pause.
177
void start_new_collection_set();
178
179
// The block offset table for the G1 heap.
180
G1BlockOffsetTable* _bot;
181
182
public:
183
void prepare_region_for_full_compaction(HeapRegion* hr);
184
185
private:
186
// Rebuilds the region sets / lists so that they are repopulated to
187
// reflect the contents of the heap. The only exception is the
188
// humongous set which was not torn down in the first place. If
189
// free_list_only is true, it will only rebuild the free list.
190
void rebuild_region_sets(bool free_list_only);
191
192
// Callback for region mapping changed events.
193
G1RegionMappingChangedListener _listener;
194
195
// Handle G1 NUMA support.
196
G1NUMA* _numa;
197
198
// The sequence of all heap regions in the heap.
199
HeapRegionManager _hrm;
200
201
// Manages all allocations with regions except humongous object allocations.
202
G1Allocator* _allocator;
203
204
// Manages all heap verification.
205
G1HeapVerifier* _verifier;
206
207
// Outside of GC pauses, the number of bytes used in all regions other
208
// than the current allocation region(s).
209
volatile size_t _summary_bytes_used;
210
211
void increase_used(size_t bytes);
212
void decrease_used(size_t bytes);
213
214
void set_used(size_t bytes);
215
216
// Number of bytes used in all regions during GC. Typically changed when
217
// retiring a GC alloc region.
218
size_t _bytes_used_during_gc;
219
220
// Class that handles archive allocation ranges.
221
G1ArchiveAllocator* _archive_allocator;
222
223
// GC allocation statistics policy for survivors.
224
G1EvacStats _survivor_evac_stats;
225
226
// GC allocation statistics policy for tenured objects.
227
G1EvacStats _old_evac_stats;
228
229
// It specifies whether we should attempt to expand the heap after a
230
// region allocation failure. If heap expansion fails we set this to
231
// false so that we don't re-attempt the heap expansion (it's likely
232
// that subsequent expansion attempts will also fail if one fails).
233
// Currently, it is only consulted during GC and it's reset at the
234
// start of each GC.
235
bool _expand_heap_after_alloc_failure;
236
237
// Helper for monitoring and management support.
238
G1MonitoringSupport* _g1mm;
239
240
// Records whether the region at the given index is (still) a
241
// candidate for eager reclaim. Only valid for humongous start
242
// regions; other regions have unspecified values. Humongous start
243
// regions are initialized at start of collection pause, with
244
// candidates removed from the set as they are found reachable from
245
// roots or the young generation.
246
class HumongousReclaimCandidates : public G1BiasedMappedArray<bool> {
247
protected:
248
bool default_value() const { return false; }
249
public:
250
void clear() { G1BiasedMappedArray<bool>::clear(); }
251
void set_candidate(uint region, bool value) {
252
set_by_index(region, value);
253
}
254
bool is_candidate(uint region) {
255
return get_by_index(region);
256
}
257
};
258
259
HumongousReclaimCandidates _humongous_reclaim_candidates;
260
uint _num_humongous_objects; // Current amount of (all) humongous objects found in the heap.
261
uint _num_humongous_reclaim_candidates; // Number of humongous object eager reclaim candidates.
262
public:
263
uint num_humongous_objects() const { return _num_humongous_objects; }
264
uint num_humongous_reclaim_candidates() const { return _num_humongous_reclaim_candidates; }
265
bool has_humongous_reclaim_candidates() const { return _num_humongous_reclaim_candidates > 0; }
266
267
bool should_do_eager_reclaim() const;
268
269
private:
270
271
G1HRPrinter _hr_printer;
272
273
// Return true if an explicit GC should start a concurrent cycle instead
274
// of doing a STW full GC. A concurrent cycle should be started if:
275
// (a) cause == _g1_humongous_allocation,
276
// (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent,
277
// (c) cause == _dcmd_gc_run and +ExplicitGCInvokesConcurrent,
278
// (d) cause == _wb_conc_mark or _wb_breakpoint,
279
// (e) cause == _g1_periodic_collection and +G1PeriodicGCInvokesConcurrent.
280
bool should_do_concurrent_full_gc(GCCause::Cause cause);
281
282
// Attempt to start a concurrent cycle with the indicated cause.
283
// precondition: should_do_concurrent_full_gc(cause)
284
bool try_collect_concurrently(GCCause::Cause cause,
285
uint gc_counter,
286
uint old_marking_started_before);
287
288
// Return true if should upgrade to full gc after an incremental one.
289
bool should_upgrade_to_full_gc(GCCause::Cause cause);
290
291
// indicates whether we are in young or mixed GC mode
292
G1CollectorState _collector_state;
293
294
// Keeps track of how many "old marking cycles" (i.e., Full GCs or
295
// concurrent cycles) we have started.
296
volatile uint _old_marking_cycles_started;
297
298
// Keeps track of how many "old marking cycles" (i.e., Full GCs or
299
// concurrent cycles) we have completed.
300
volatile uint _old_marking_cycles_completed;
301
302
// This is a non-product method that is helpful for testing. It is
303
// called at the end of a GC and artificially expands the heap by
304
// allocating a number of dead regions. This way we can induce very
305
// frequent marking cycles and stress the cleanup / concurrent
306
// cleanup code more (as all the regions that will be allocated by
307
// this method will be found dead by the marking cycle).
308
void allocate_dummy_regions() PRODUCT_RETURN;
309
310
// If the HR printer is active, dump the state of the regions in the
311
// heap after a compaction.
312
void print_hrm_post_compaction();
313
314
// Create a memory mapper for auxiliary data structures of the given size and
315
// translation factor.
316
static G1RegionToSpaceMapper* create_aux_memory_mapper(const char* description,
317
size_t size,
318
size_t translation_factor);
319
320
void trace_heap(GCWhen::Type when, const GCTracer* tracer);
321
322
// These are macros so that, if the assert fires, we get the correct
323
// line number, file, etc.
324
325
#define heap_locking_asserts_params(_extra_message_) \
326
"%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \
327
(_extra_message_), \
328
BOOL_TO_STR(Heap_lock->owned_by_self()), \
329
BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), \
330
BOOL_TO_STR(Thread::current()->is_VM_thread())
331
332
#define assert_heap_locked() \
333
do { \
334
assert(Heap_lock->owned_by_self(), \
335
heap_locking_asserts_params("should be holding the Heap_lock")); \
336
} while (0)
337
338
#define assert_heap_locked_or_at_safepoint(_should_be_vm_thread_) \
339
do { \
340
assert(Heap_lock->owned_by_self() || \
341
(SafepointSynchronize::is_at_safepoint() && \
342
((_should_be_vm_thread_) == Thread::current()->is_VM_thread())), \
343
heap_locking_asserts_params("should be holding the Heap_lock or " \
344
"should be at a safepoint")); \
345
} while (0)
346
347
#define assert_heap_locked_and_not_at_safepoint() \
348
do { \
349
assert(Heap_lock->owned_by_self() && \
350
!SafepointSynchronize::is_at_safepoint(), \
351
heap_locking_asserts_params("should be holding the Heap_lock and " \
352
"should not be at a safepoint")); \
353
} while (0)
354
355
#define assert_heap_not_locked() \
356
do { \
357
assert(!Heap_lock->owned_by_self(), \
358
heap_locking_asserts_params("should not be holding the Heap_lock")); \
359
} while (0)
360
361
#define assert_heap_not_locked_and_not_at_safepoint() \
362
do { \
363
assert(!Heap_lock->owned_by_self() && \
364
!SafepointSynchronize::is_at_safepoint(), \
365
heap_locking_asserts_params("should not be holding the Heap_lock and " \
366
"should not be at a safepoint")); \
367
} while (0)
368
369
#define assert_at_safepoint_on_vm_thread() \
370
do { \
371
assert_at_safepoint(); \
372
assert(Thread::current_or_null() != NULL, "no current thread"); \
373
assert(Thread::current()->is_VM_thread(), "current thread is not VM thread"); \
374
} while (0)
375
376
#ifdef ASSERT
377
#define assert_used_and_recalculate_used_equal(g1h) \
378
do { \
379
size_t cur_used_bytes = g1h->used(); \
380
size_t recal_used_bytes = g1h->recalculate_used(); \
381
assert(cur_used_bytes == recal_used_bytes, "Used(" SIZE_FORMAT ") is not" \
382
" same as recalculated used(" SIZE_FORMAT ").", \
383
cur_used_bytes, recal_used_bytes); \
384
} while (0)
385
#else
386
#define assert_used_and_recalculate_used_equal(g1h) do {} while(0)
387
#endif
388
389
static const uint MaxYoungGCNameLength = 128;
390
// Sets given young_gc_name to the canonical young gc pause string. Young_gc_name
391
// must be at least of length MaxYoungGCNameLength.
392
void set_young_gc_name(char* young_gc_name);
393
394
// The young region list.
395
G1EdenRegions _eden;
396
G1SurvivorRegions _survivor;
397
398
STWGCTimer* _gc_timer_stw;
399
400
G1NewTracer* _gc_tracer_stw;
401
402
void gc_tracer_report_gc_start();
403
void gc_tracer_report_gc_end(bool concurrent_operation_is_full_mark, G1EvacuationInfo& evacuation_info);
404
405
// The current policy object for the collector.
406
G1Policy* _policy;
407
G1HeapSizingPolicy* _heap_sizing_policy;
408
409
G1CollectionSet _collection_set;
410
411
// Try to allocate a single non-humongous HeapRegion sufficient for
412
// an allocation of the given word_size. If do_expand is true,
413
// attempt to expand the heap if necessary to satisfy the allocation
414
// request. 'type' takes the type of region to be allocated. (Use constants
415
// Old, Eden, Humongous, Survivor defined in HeapRegionType.)
416
HeapRegion* new_region(size_t word_size,
417
HeapRegionType type,
418
bool do_expand,
419
uint node_index = G1NUMA::AnyNodeIndex);
420
421
// Initialize a contiguous set of free regions of length num_regions
422
// and starting at index first so that they appear as a single
423
// humongous region.
424
HeapWord* humongous_obj_allocate_initialize_regions(HeapRegion* first_hr,
425
uint num_regions,
426
size_t word_size);
427
428
// Attempt to allocate a humongous object of the given size. Return
429
// NULL if unsuccessful.
430
HeapWord* humongous_obj_allocate(size_t word_size);
431
432
// The following two methods, allocate_new_tlab() and
433
// mem_allocate(), are the two main entry points from the runtime
434
// into the G1's allocation routines. They have the following
435
// assumptions:
436
//
437
// * They should both be called outside safepoints.
438
//
439
// * They should both be called without holding the Heap_lock.
440
//
441
// * All allocation requests for new TLABs should go to
442
// allocate_new_tlab().
443
//
444
// * All non-TLAB allocation requests should go to mem_allocate().
445
//
446
// * If either call cannot satisfy the allocation request using the
447
// current allocating region, they will try to get a new one. If
448
// this fails, they will attempt to do an evacuation pause and
449
// retry the allocation.
450
//
451
// * If all allocation attempts fail, even after trying to schedule
452
// an evacuation pause, allocate_new_tlab() will return NULL,
453
// whereas mem_allocate() will attempt a heap expansion and/or
454
// schedule a Full GC.
455
//
456
// * We do not allow humongous-sized TLABs. So, allocate_new_tlab
457
// should never be called with word_size being humongous. All
458
// humongous allocation requests should go to mem_allocate() which
459
// will satisfy them with a special path.
460
461
virtual HeapWord* allocate_new_tlab(size_t min_size,
462
size_t requested_size,
463
size_t* actual_size);
464
465
virtual HeapWord* mem_allocate(size_t word_size,
466
bool* gc_overhead_limit_was_exceeded);
467
468
// First-level mutator allocation attempt: try to allocate out of
469
// the mutator alloc region without taking the Heap_lock. This
470
// should only be used for non-humongous allocations.
471
inline HeapWord* attempt_allocation(size_t min_word_size,
472
size_t desired_word_size,
473
size_t* actual_word_size);
474
475
// Second-level mutator allocation attempt: take the Heap_lock and
476
// retry the allocation attempt, potentially scheduling a GC
477
// pause. This should only be used for non-humongous allocations.
478
HeapWord* attempt_allocation_slow(size_t word_size);
479
480
// Takes the Heap_lock and attempts a humongous allocation. It can
481
// potentially schedule a GC pause.
482
HeapWord* attempt_allocation_humongous(size_t word_size);
483
484
// Allocation attempt that should be called during safepoints (e.g.,
485
// at the end of a successful GC). expect_null_mutator_alloc_region
486
// specifies whether the mutator alloc region is expected to be NULL
487
// or not.
488
HeapWord* attempt_allocation_at_safepoint(size_t word_size,
489
bool expect_null_mutator_alloc_region);
490
491
// These methods are the "callbacks" from the G1AllocRegion class.
492
493
// For mutator alloc regions.
494
HeapRegion* new_mutator_alloc_region(size_t word_size, bool force, uint node_index);
495
void retire_mutator_alloc_region(HeapRegion* alloc_region,
496
size_t allocated_bytes);
497
498
// For GC alloc regions.
499
bool has_more_regions(G1HeapRegionAttr dest);
500
HeapRegion* new_gc_alloc_region(size_t word_size, G1HeapRegionAttr dest, uint node_index);
501
void retire_gc_alloc_region(HeapRegion* alloc_region,
502
size_t allocated_bytes, G1HeapRegionAttr dest);
503
504
// - if explicit_gc is true, the GC is for a System.gc() etc,
505
// otherwise it's for a failed allocation.
506
// - if clear_all_soft_refs is true, all soft references should be
507
// cleared during the GC.
508
// - if do_maximum_compaction is true, full gc will do a maximally
509
// compacting collection, leaving no dead wood.
510
// - it returns false if it is unable to do the collection due to the
511
// GC locker being active, true otherwise.
512
bool do_full_collection(bool explicit_gc,
513
bool clear_all_soft_refs,
514
bool do_maximum_compaction);
515
516
// Callback from VM_G1CollectFull operation, or collect_as_vm_thread.
517
virtual void do_full_collection(bool clear_all_soft_refs);
518
519
// Callback from VM_G1CollectForAllocation operation.
520
// This function does everything necessary/possible to satisfy a
521
// failed allocation request (including collection, expansion, etc.)
522
HeapWord* satisfy_failed_allocation(size_t word_size,
523
bool* succeeded);
524
// Internal helpers used during full GC to split it up to
525
// increase readability.
526
void abort_concurrent_cycle();
527
void verify_before_full_collection(bool explicit_gc);
528
void prepare_heap_for_full_collection();
529
void prepare_heap_for_mutators();
530
void abort_refinement();
531
void verify_after_full_collection();
532
void print_heap_after_full_collection(G1HeapTransition* heap_transition);
533
534
// Helper method for satisfy_failed_allocation()
535
HeapWord* satisfy_failed_allocation_helper(size_t word_size,
536
bool do_gc,
537
bool clear_all_soft_refs,
538
bool expect_null_mutator_alloc_region,
539
bool* gc_succeeded);
540
541
// Attempting to expand the heap sufficiently
542
// to support an allocation of the given "word_size". If
543
// successful, perform the allocation and return the address of the
544
// allocated block, or else "NULL".
545
HeapWord* expand_and_allocate(size_t word_size);
546
547
// Process any reference objects discovered.
548
void process_discovered_references(G1ParScanThreadStateSet* per_thread_states);
549
550
// If during a concurrent start pause we may install a pending list head which is not
551
// otherwise reachable, ensure that it is marked in the bitmap for concurrent marking
552
// to discover.
553
void make_pending_list_reachable();
554
555
void verify_numa_regions(const char* desc);
556
557
public:
558
G1ServiceThread* service_thread() const { return _service_thread; }
559
560
WorkGang* workers() const { return _workers; }
561
562
// Runs the given AbstractGangTask with the current active workers,
563
// returning the total time taken.
564
Tickspan run_task_timed(AbstractGangTask* task);
565
// Run the given batch task using the work gang.
566
void run_batch_task(G1BatchedGangTask* cl);
567
568
G1Allocator* allocator() {
569
return _allocator;
570
}
571
572
G1HeapVerifier* verifier() {
573
return _verifier;
574
}
575
576
G1MonitoringSupport* g1mm() {
577
assert(_g1mm != NULL, "should have been initialized");
578
return _g1mm;
579
}
580
581
void resize_heap_if_necessary();
582
583
// Check if there is memory to uncommit and if so schedule a task to do it.
584
void uncommit_regions_if_necessary();
585
// Immediately uncommit uncommittable regions.
586
uint uncommit_regions(uint region_limit);
587
bool has_uncommittable_regions();
588
589
G1NUMA* numa() const { return _numa; }
590
591
// Expand the garbage-first heap by at least the given size (in bytes!).
592
// Returns true if the heap was expanded by the requested amount;
593
// false otherwise.
594
// (Rounds up to a HeapRegion boundary.)
595
bool expand(size_t expand_bytes, WorkGang* pretouch_workers = NULL, double* expand_time_ms = NULL);
596
bool expand_single_region(uint node_index);
597
598
// Returns the PLAB statistics for a given destination.
599
inline G1EvacStats* alloc_buffer_stats(G1HeapRegionAttr dest);
600
601
// Determines PLAB size for a given destination.
602
inline size_t desired_plab_sz(G1HeapRegionAttr dest);
603
604
// Do anything common to GC's.
605
void gc_prologue(bool full);
606
void gc_epilogue(bool full);
607
608
// Does the given region fulfill remembered set based eager reclaim candidate requirements?
609
bool is_potential_eager_reclaim_candidate(HeapRegion* r) const;
610
611
// Modify the reclaim candidate set and test for presence.
612
// These are only valid for starts_humongous regions.
613
inline void set_humongous_reclaim_candidate(uint region, bool value);
614
inline bool is_humongous_reclaim_candidate(uint region);
615
616
// Remove from the reclaim candidate set. Also remove from the
617
// collection set so that later encounters avoid the slow path.
618
inline void set_humongous_is_live(oop obj);
619
620
// Register the given region to be part of the collection set.
621
inline void register_humongous_region_with_region_attr(uint index);
622
623
// We register a region with the fast "in collection set" test. We
624
// simply set to true the array slot corresponding to this region.
625
void register_young_region_with_region_attr(HeapRegion* r) {
626
_region_attr.set_in_young(r->hrm_index());
627
}
628
inline void register_region_with_region_attr(HeapRegion* r);
629
inline void register_old_region_with_region_attr(HeapRegion* r);
630
inline void register_optional_region_with_region_attr(HeapRegion* r);
631
632
void clear_region_attr(const HeapRegion* hr) {
633
_region_attr.clear(hr);
634
}
635
636
void clear_region_attr() {
637
_region_attr.clear();
638
}
639
640
// Verify that the G1RegionAttr remset tracking corresponds to actual remset tracking
641
// for all regions.
642
void verify_region_attr_remset_update() PRODUCT_RETURN;
643
644
bool is_user_requested_concurrent_full_gc(GCCause::Cause cause);
645
646
// This is called at the start of either a concurrent cycle or a Full
647
// GC to update the number of old marking cycles started.
648
void increment_old_marking_cycles_started();
649
650
// This is called at the end of either a concurrent cycle or a Full
651
// GC to update the number of old marking cycles completed. Those two
652
// can happen in a nested fashion, i.e., we start a concurrent
653
// cycle, a Full GC happens half-way through it which ends first,
654
// and then the cycle notices that a Full GC happened and ends
655
// too. The concurrent parameter is a boolean to help us do a bit
656
// tighter consistency checking in the method. If concurrent is
657
// false, the caller is the inner caller in the nesting (i.e., the
658
// Full GC). If concurrent is true, the caller is the outer caller
659
// in this nesting (i.e., the concurrent cycle). Further nesting is
660
// not currently supported. The end of this call also notifies
661
// the G1OldGCCount_lock in case a Java thread is waiting for a full
662
// GC to happen (e.g., it called System.gc() with
663
// +ExplicitGCInvokesConcurrent).
664
// whole_heap_examined should indicate that during that old marking
665
// cycle the whole heap has been examined for live objects (as opposed
666
// to only parts, or aborted before completion).
667
void increment_old_marking_cycles_completed(bool concurrent, bool whole_heap_examined);
668
669
uint old_marking_cycles_completed() {
670
return _old_marking_cycles_completed;
671
}
672
673
G1HRPrinter* hr_printer() { return &_hr_printer; }
674
675
// Allocates a new heap region instance.
676
HeapRegion* new_heap_region(uint hrs_index, MemRegion mr);
677
678
// Allocate the highest free region in the reserved heap. This will commit
679
// regions as necessary.
680
HeapRegion* alloc_highest_free_region();
681
682
// Frees a region by resetting its metadata and adding it to the free list
683
// passed as a parameter (this is usually a local list which will be appended
684
// to the master free list later or NULL if free list management is handled
685
// in another way).
686
// Callers must ensure they are the only one calling free on the given region
687
// at the same time.
688
void free_region(HeapRegion* hr, FreeRegionList* free_list);
689
690
// It dirties the cards that cover the block so that the post
691
// write barrier never queues anything when updating objects on this
692
// block. It is assumed (and in fact we assert) that the block
693
// belongs to a young region.
694
inline void dirty_young_block(HeapWord* start, size_t word_size);
695
696
// Frees a humongous region by collapsing it into individual regions
697
// and calling free_region() for each of them. The freed regions
698
// will be added to the free list that's passed as a parameter (this
699
// is usually a local list which will be appended to the master free
700
// list later).
701
// The method assumes that only a single thread is ever calling
702
// this for a particular region at once.
703
void free_humongous_region(HeapRegion* hr,
704
FreeRegionList* free_list);
705
706
// Facility for allocating in 'archive' regions in high heap memory and
707
// recording the allocated ranges. These should all be called from the
708
// VM thread at safepoints, without the heap lock held. They can be used
709
// to create and archive a set of heap regions which can be mapped at the
710
// same fixed addresses in a subsequent JVM invocation.
711
void begin_archive_alloc_range(bool open = false);
712
713
// Check if the requested size would be too large for an archive allocation.
714
bool is_archive_alloc_too_large(size_t word_size);
715
716
// Allocate memory of the requested size from the archive region. This will
717
// return NULL if the size is too large or if no memory is available. It
718
// does not trigger a garbage collection.
719
HeapWord* archive_mem_allocate(size_t word_size);
720
721
// Optionally aligns the end address and returns the allocated ranges in
722
// an array of MemRegions in order of ascending addresses.
723
void end_archive_alloc_range(GrowableArray<MemRegion>* ranges,
724
size_t end_alignment_in_bytes = 0);
725
726
// Facility for allocating a fixed range within the heap and marking
727
// the containing regions as 'archive'. For use at JVM init time, when the
728
// caller may mmap archived heap data at the specified range(s).
729
// Verify that the MemRegions specified in the argument array are within the
730
// reserved heap.
731
bool check_archive_addresses(MemRegion* range, size_t count);
732
733
// Commit the appropriate G1 regions containing the specified MemRegions
734
// and mark them as 'archive' regions. The regions in the array must be
735
// non-overlapping and in order of ascending address.
736
bool alloc_archive_regions(MemRegion* range, size_t count, bool open);
737
738
// Insert any required filler objects in the G1 regions around the specified
739
// ranges to make the regions parseable. This must be called after
740
// alloc_archive_regions, and after class loading has occurred.
741
void fill_archive_regions(MemRegion* range, size_t count);
742
743
// Populate the G1BlockOffsetTablePart for archived regions with the given
744
// memory ranges.
745
void populate_archive_regions_bot_part(MemRegion* range, size_t count);
746
747
// For each of the specified MemRegions, uncommit the containing G1 regions
748
// which had been allocated by alloc_archive_regions. This should be called
749
// rather than fill_archive_regions at JVM init time if the archive file
750
// mapping failed, with the same non-overlapping and sorted MemRegion array.
751
void dealloc_archive_regions(MemRegion* range, size_t count);
752
753
private:
754
755
// Shrink the garbage-first heap by at most the given size (in bytes!).
756
// (Rounds down to a HeapRegion boundary.)
757
void shrink(size_t shrink_bytes);
758
void shrink_helper(size_t expand_bytes);
759
760
#if TASKQUEUE_STATS
761
static void print_taskqueue_stats_hdr(outputStream* const st);
762
void print_taskqueue_stats() const;
763
void reset_taskqueue_stats();
764
#endif // TASKQUEUE_STATS
765
766
// Start a concurrent cycle.
767
void start_concurrent_cycle(bool concurrent_operation_is_full_mark);
768
769
// Schedule the VM operation that will do an evacuation pause to
770
// satisfy an allocation request of word_size. *succeeded will
771
// return whether the VM operation was successful (it did do an
772
// evacuation pause) or not (another thread beat us to it or the GC
773
// locker was active). Given that we should not be holding the
774
// Heap_lock when we enter this method, we will pass the
775
// gc_count_before (i.e., total_collections()) as a parameter since
776
// it has to be read while holding the Heap_lock. Currently, both
777
// methods that call do_collection_pause() release the Heap_lock
778
// before the call, so it's easy to read gc_count_before just before.
779
HeapWord* do_collection_pause(size_t word_size,
780
uint gc_count_before,
781
bool* succeeded,
782
GCCause::Cause gc_cause);
783
784
void wait_for_root_region_scanning();
785
786
// Perform an incremental collection at a safepoint, possibly
787
// followed by a by-policy upgrade to a full collection. Returns
788
// false if unable to do the collection due to the GC locker being
789
// active, true otherwise.
790
// precondition: at safepoint on VM thread
791
// precondition: !is_gc_active()
792
bool do_collection_pause_at_safepoint(double target_pause_time_ms);
793
794
// Helper for do_collection_pause_at_safepoint, containing the guts
795
// of the incremental collection pause, executed by the vm thread.
796
void do_collection_pause_at_safepoint_helper(double target_pause_time_ms);
797
798
G1HeapVerifier::G1VerifyType young_collection_verify_type() const;
799
void verify_before_young_collection(G1HeapVerifier::G1VerifyType type);
800
void verify_after_young_collection(G1HeapVerifier::G1VerifyType type);
801
802
void calculate_collection_set(G1EvacuationInfo& evacuation_info, double target_pause_time_ms);
803
804
// Actually do the work of evacuating the parts of the collection set.
805
// The has_optional_evacuation_work flag for the initial collection set
806
// evacuation indicates whether one or more optional evacuation steps may
807
// follow.
808
// If not set, G1 can avoid clearing the card tables of regions that we scan
809
// for roots from the heap: when scanning the card table for dirty cards after
810
// all remembered sets have been dumped onto it, for optional evacuation we
811
// mark these cards as "Scanned" to know that we do not need to re-scan them
812
// in the additional optional evacuation passes. This means that in the "Clear
813
// Card Table" phase we need to clear those marks. However, if there is no
814
// optional evacuation, g1 can immediately clean the dirty cards it encounters
815
// as nobody else will be looking at them again, saving the clear card table
816
// work later.
817
// This case is very common (young only collections and most mixed gcs), so
818
// depending on the ratio between scanned and evacuated regions (which g1 always
819
// needs to clear), this is a big win.
820
void evacuate_initial_collection_set(G1ParScanThreadStateSet* per_thread_states,
821
bool has_optional_evacuation_work);
822
void evacuate_optional_collection_set(G1ParScanThreadStateSet* per_thread_states);
823
private:
824
// Evacuate the next set of optional regions.
825
void evacuate_next_optional_regions(G1ParScanThreadStateSet* per_thread_states);
826
827
public:
828
void pre_evacuate_collection_set(G1EvacuationInfo& evacuation_info, G1ParScanThreadStateSet* pss);
829
void post_evacuate_collection_set(G1EvacuationInfo& evacuation_info,
830
G1RedirtyCardsQueueSet* rdcqs,
831
G1ParScanThreadStateSet* pss);
832
833
void expand_heap_after_young_collection();
834
// Update object copying statistics.
835
void record_obj_copy_mem_stats();
836
837
// The hot card cache for remembered set insertion optimization.
838
G1HotCardCache* _hot_card_cache;
839
840
// The g1 remembered set of the heap.
841
G1RemSet* _rem_set;
842
843
void post_evacuate_cleanup_1(G1ParScanThreadStateSet* per_thread_states,
844
G1RedirtyCardsQueueSet* rdcqs);
845
void post_evacuate_cleanup_2(PreservedMarksSet* preserved_marks,
846
G1RedirtyCardsQueueSet* rdcqs,
847
G1EvacuationInfo* evacuation_info,
848
const size_t* surviving_young_words);
849
850
// After a collection pause, reset eden and the collection set.
851
void clear_eden();
852
void clear_collection_set();
853
854
// Abandon the current collection set without recording policy
855
// statistics or updating free lists.
856
void abandon_collection_set(G1CollectionSet* collection_set);
857
858
// The concurrent marker (and the thread it runs in.)
859
G1ConcurrentMark* _cm;
860
G1ConcurrentMarkThread* _cm_thread;
861
862
// The concurrent refiner.
863
G1ConcurrentRefine* _cr;
864
865
// The parallel task queues
866
G1ScannerTasksQueueSet *_task_queues;
867
868
// Number of regions evacuation failed in the current collection.
869
volatile uint _num_regions_failed_evacuation;
870
871
EvacuationFailedInfo* _evacuation_failed_info_array;
872
873
PreservedMarksSet _preserved_marks_set;
874
875
// Preserve the mark of "obj", if necessary, in preparation for its mark
876
// word being overwritten with a self-forwarding-pointer.
877
void preserve_mark_during_evac_failure(uint worker_id, oop obj, markWord m);
878
879
#ifndef PRODUCT
880
// Support for forcing evacuation failures. Analogous to
881
// PromotionFailureALot for the other collectors.
882
883
// Records whether G1EvacuationFailureALot should be in effect
884
// for the current GC
885
bool _evacuation_failure_alot_for_current_gc;
886
887
// Used to record the GC number for interval checking when
888
// determining whether G1EvaucationFailureALot is in effect
889
// for the current GC.
890
size_t _evacuation_failure_alot_gc_number;
891
892
// Count of the number of evacuations between failures.
893
volatile size_t _evacuation_failure_alot_count;
894
895
// Set whether G1EvacuationFailureALot should be in effect
896
// for the current GC (based upon the type of GC and which
897
// command line flags are set);
898
inline bool evacuation_failure_alot_for_gc_type(bool for_young_gc,
899
bool during_concurrent_start,
900
bool mark_or_rebuild_in_progress);
901
902
inline void set_evacuation_failure_alot_for_current_gc();
903
904
// Return true if it's time to cause an evacuation failure.
905
inline bool evacuation_should_fail();
906
907
// Reset the G1EvacuationFailureALot counters. Should be called at
908
// the end of an evacuation pause in which an evacuation failure occurred.
909
inline void reset_evacuation_should_fail();
910
#endif // !PRODUCT
911
912
// ("Weak") Reference processing support.
913
//
914
// G1 has 2 instances of the reference processor class. One
915
// (_ref_processor_cm) handles reference object discovery
916
// and subsequent processing during concurrent marking cycles.
917
//
918
// The other (_ref_processor_stw) handles reference object
919
// discovery and processing during full GCs and incremental
920
// evacuation pauses.
921
//
922
// During an incremental pause, reference discovery will be
923
// temporarily disabled for _ref_processor_cm and will be
924
// enabled for _ref_processor_stw. At the end of the evacuation
925
// pause references discovered by _ref_processor_stw will be
926
// processed and discovery will be disabled. The previous
927
// setting for reference object discovery for _ref_processor_cm
928
// will be re-instated.
929
//
930
// At the start of marking:
931
// * Discovery by the CM ref processor is verified to be inactive
932
// and it's discovered lists are empty.
933
// * Discovery by the CM ref processor is then enabled.
934
//
935
// At the end of marking:
936
// * Any references on the CM ref processor's discovered
937
// lists are processed (possibly MT).
938
//
939
// At the start of full GC we:
940
// * Disable discovery by the CM ref processor and
941
// empty CM ref processor's discovered lists
942
// (without processing any entries).
943
// * Verify that the STW ref processor is inactive and it's
944
// discovered lists are empty.
945
// * Temporarily set STW ref processor discovery as single threaded.
946
// * Temporarily clear the STW ref processor's _is_alive_non_header
947
// field.
948
// * Finally enable discovery by the STW ref processor.
949
//
950
// The STW ref processor is used to record any discovered
951
// references during the full GC.
952
//
953
// At the end of a full GC we:
954
// * Enqueue any reference objects discovered by the STW ref processor
955
// that have non-live referents. This has the side-effect of
956
// making the STW ref processor inactive by disabling discovery.
957
// * Verify that the CM ref processor is still inactive
958
// and no references have been placed on it's discovered
959
// lists (also checked as a precondition during concurrent start).
960
961
// The (stw) reference processor...
962
ReferenceProcessor* _ref_processor_stw;
963
964
// During reference object discovery, the _is_alive_non_header
965
// closure (if non-null) is applied to the referent object to
966
// determine whether the referent is live. If so then the
967
// reference object does not need to be 'discovered' and can
968
// be treated as a regular oop. This has the benefit of reducing
969
// the number of 'discovered' reference objects that need to
970
// be processed.
971
//
972
// Instance of the is_alive closure for embedding into the
973
// STW reference processor as the _is_alive_non_header field.
974
// Supplying a value for the _is_alive_non_header field is
975
// optional but doing so prevents unnecessary additions to
976
// the discovered lists during reference discovery.
977
G1STWIsAliveClosure _is_alive_closure_stw;
978
979
G1STWSubjectToDiscoveryClosure _is_subject_to_discovery_stw;
980
981
// The (concurrent marking) reference processor...
982
ReferenceProcessor* _ref_processor_cm;
983
984
// Instance of the concurrent mark is_alive closure for embedding
985
// into the Concurrent Marking reference processor as the
986
// _is_alive_non_header field. Supplying a value for the
987
// _is_alive_non_header field is optional but doing so prevents
988
// unnecessary additions to the discovered lists during reference
989
// discovery.
990
G1CMIsAliveClosure _is_alive_closure_cm;
991
992
G1CMSubjectToDiscoveryClosure _is_subject_to_discovery_cm;
993
public:
994
995
G1ScannerTasksQueue* task_queue(uint i) const;
996
997
uint num_task_queues() const;
998
999
// Create a G1CollectedHeap.
1000
// Must call the initialize method afterwards.
1001
// May not return if something goes wrong.
1002
G1CollectedHeap();
1003
1004
private:
1005
jint initialize_concurrent_refinement();
1006
jint initialize_service_thread();
1007
public:
1008
// Initialize the G1CollectedHeap to have the initial and
1009
// maximum sizes and remembered and barrier sets
1010
// specified by the policy object.
1011
jint initialize();
1012
1013
virtual void stop();
1014
virtual void safepoint_synchronize_begin();
1015
virtual void safepoint_synchronize_end();
1016
1017
// Does operations required after initialization has been done.
1018
void post_initialize();
1019
1020
// Initialize weak reference processing.
1021
void ref_processing_init();
1022
1023
virtual Name kind() const {
1024
return CollectedHeap::G1;
1025
}
1026
1027
virtual const char* name() const {
1028
return "G1";
1029
}
1030
1031
const G1CollectorState* collector_state() const { return &_collector_state; }
1032
G1CollectorState* collector_state() { return &_collector_state; }
1033
1034
// The current policy object for the collector.
1035
G1Policy* policy() const { return _policy; }
1036
// The remembered set.
1037
G1RemSet* rem_set() const { return _rem_set; }
1038
1039
inline G1GCPhaseTimes* phase_times() const;
1040
1041
const G1CollectionSet* collection_set() const { return &_collection_set; }
1042
G1CollectionSet* collection_set() { return &_collection_set; }
1043
1044
virtual SoftRefPolicy* soft_ref_policy();
1045
1046
virtual void initialize_serviceability();
1047
virtual MemoryUsage memory_usage();
1048
virtual GrowableArray<GCMemoryManager*> memory_managers();
1049
virtual GrowableArray<MemoryPool*> memory_pools();
1050
1051
// Try to minimize the remembered set.
1052
void scrub_rem_set();
1053
1054
// Apply the given closure on all cards in the Hot Card Cache, emptying it.
1055
void iterate_hcc_closure(G1CardTableEntryClosure* cl, uint worker_id);
1056
1057
// The shared block offset table array.
1058
G1BlockOffsetTable* bot() const { return _bot; }
1059
1060
// Reference Processing accessors
1061
1062
// The STW reference processor....
1063
ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; }
1064
1065
G1NewTracer* gc_tracer_stw() const { return _gc_tracer_stw; }
1066
1067
// The Concurrent Marking reference processor...
1068
ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }
1069
1070
size_t unused_committed_regions_in_bytes() const;
1071
1072
virtual size_t capacity() const;
1073
virtual size_t used() const;
1074
// This should be called when we're not holding the heap lock. The
1075
// result might be a bit inaccurate.
1076
size_t used_unlocked() const;
1077
size_t recalculate_used() const;
1078
1079
// These virtual functions do the actual allocation.
1080
// Some heaps may offer a contiguous region for shared non-blocking
1081
// allocation, via inlined code (by exporting the address of the top and
1082
// end fields defining the extent of the contiguous allocation region.)
1083
// But G1CollectedHeap doesn't yet support this.
1084
1085
virtual bool is_maximal_no_gc() const {
1086
return _hrm.available() == 0;
1087
}
1088
1089
// Returns whether there are any regions left in the heap for allocation.
1090
bool has_regions_left_for_allocation() const {
1091
return !is_maximal_no_gc() || num_free_regions() != 0;
1092
}
1093
1094
// The current number of regions in the heap.
1095
uint num_regions() const { return _hrm.length(); }
1096
1097
// The max number of regions reserved for the heap. Except for static array
1098
// sizing purposes you probably want to use max_regions().
1099
uint max_reserved_regions() const { return _hrm.reserved_length(); }
1100
1101
// Max number of regions that can be committed.
1102
uint max_regions() const { return _hrm.max_length(); }
1103
1104
// The number of regions that are completely free.
1105
uint num_free_regions() const { return _hrm.num_free_regions(); }
1106
1107
// The number of regions that can be allocated into.
1108
uint num_free_or_available_regions() const { return num_free_regions() + _hrm.available(); }
1109
1110
MemoryUsage get_auxiliary_data_memory_usage() const {
1111
return _hrm.get_auxiliary_data_memory_usage();
1112
}
1113
1114
// The number of regions that are not completely free.
1115
uint num_used_regions() const { return num_regions() - num_free_regions(); }
1116
1117
#ifdef ASSERT
1118
bool is_on_master_free_list(HeapRegion* hr) {
1119
return _hrm.is_free(hr);
1120
}
1121
#endif // ASSERT
1122
1123
inline void old_set_add(HeapRegion* hr);
1124
inline void old_set_remove(HeapRegion* hr);
1125
1126
inline void archive_set_add(HeapRegion* hr);
1127
1128
size_t non_young_capacity_bytes() {
1129
return (old_regions_count() + _archive_set.length() + humongous_regions_count()) * HeapRegion::GrainBytes;
1130
}
1131
1132
// Determine whether the given region is one that we are using as an
1133
// old GC alloc region.
1134
bool is_old_gc_alloc_region(HeapRegion* hr);
1135
1136
// Perform a collection of the heap; intended for use in implementing
1137
// "System.gc". This probably implies as full a collection as the
1138
// "CollectedHeap" supports.
1139
virtual void collect(GCCause::Cause cause);
1140
1141
// Perform a collection of the heap with the given cause.
1142
// Returns whether this collection actually executed.
1143
bool try_collect(GCCause::Cause cause);
1144
1145
// True iff an evacuation has failed in the most-recent collection.
1146
inline bool evacuation_failed() const;
1147
inline uint num_regions_failed_evacuation() const;
1148
// Notify that the garbage collection encountered an evacuation failure in a
1149
// region. Should only be called once per region.
1150
inline void notify_region_failed_evacuation();
1151
1152
void remove_from_old_gen_sets(const uint old_regions_removed,
1153
const uint archive_regions_removed,
1154
const uint humongous_regions_removed);
1155
void prepend_to_freelist(FreeRegionList* list);
1156
void decrement_summary_bytes(size_t bytes);
1157
1158
virtual bool is_in(const void* p) const;
1159
1160
// Return "TRUE" iff the given object address is within the collection
1161
// set. Assumes that the reference points into the heap.
1162
inline bool is_in_cset(const HeapRegion *hr);
1163
inline bool is_in_cset(oop obj);
1164
inline bool is_in_cset(HeapWord* addr);
1165
1166
inline bool is_in_cset_or_humongous(const oop obj);
1167
1168
private:
1169
// This array is used for a quick test on whether a reference points into
1170
// the collection set or not. Each of the array's elements denotes whether the
1171
// corresponding region is in the collection set or not.
1172
G1HeapRegionAttrBiasedMappedArray _region_attr;
1173
1174
public:
1175
1176
inline G1HeapRegionAttr region_attr(const void* obj) const;
1177
inline G1HeapRegionAttr region_attr(uint idx) const;
1178
1179
MemRegion reserved() const {
1180
return _hrm.reserved();
1181
}
1182
1183
bool is_in_reserved(const void* addr) const {
1184
return reserved().contains(addr);
1185
}
1186
1187
G1HotCardCache* hot_card_cache() const { return _hot_card_cache; }
1188
1189
G1CardTable* card_table() const {
1190
return _card_table;
1191
}
1192
1193
// Iteration functions.
1194
1195
void object_iterate_parallel(ObjectClosure* cl, uint worker_id, HeapRegionClaimer* claimer);
1196
1197
// Iterate over all objects, calling "cl.do_object" on each.
1198
virtual void object_iterate(ObjectClosure* cl);
1199
1200
virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num);
1201
1202
// Keep alive an object that was loaded with AS_NO_KEEPALIVE.
1203
virtual void keep_alive(oop obj);
1204
1205
// Iterate over heap regions, in address order, terminating the
1206
// iteration early if the "do_heap_region" method returns "true".
1207
void heap_region_iterate(HeapRegionClosure* blk) const;
1208
1209
// Return the region with the given index. It assumes the index is valid.
1210
inline HeapRegion* region_at(uint index) const;
1211
inline HeapRegion* region_at_or_null(uint index) const;
1212
1213
// Return the next region (by index) that is part of the same
1214
// humongous object that hr is part of.
1215
inline HeapRegion* next_region_in_humongous(HeapRegion* hr) const;
1216
1217
// Calculate the region index of the given address. Given address must be
1218
// within the heap.
1219
inline uint addr_to_region(HeapWord* addr) const;
1220
1221
inline HeapWord* bottom_addr_for_region(uint index) const;
1222
1223
// Two functions to iterate over the heap regions in parallel. Threads
1224
// compete using the HeapRegionClaimer to claim the regions before
1225
// applying the closure on them.
1226
// The _from_worker_offset version uses the HeapRegionClaimer and
1227
// the worker id to calculate a start offset to prevent all workers to
1228
// start from the point.
1229
void heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,
1230
HeapRegionClaimer* hrclaimer,
1231
uint worker_id) const;
1232
1233
void heap_region_par_iterate_from_start(HeapRegionClosure* cl,
1234
HeapRegionClaimer* hrclaimer) const;
1235
1236
// Iterate over all regions in the collection set in parallel.
1237
void collection_set_par_iterate_all(HeapRegionClosure* cl,
1238
HeapRegionClaimer* hr_claimer,
1239
uint worker_id);
1240
1241
// Iterate over all regions currently in the current collection set.
1242
void collection_set_iterate_all(HeapRegionClosure* blk);
1243
1244
// Iterate over the regions in the current increment of the collection set.
1245
// Starts the iteration so that the start regions of a given worker id over the
1246
// set active_workers are evenly spread across the set of collection set regions
1247
// to be iterated.
1248
// The variant with the HeapRegionClaimer guarantees that the closure will be
1249
// applied to a particular region exactly once.
1250
void collection_set_iterate_increment_from(HeapRegionClosure *blk, uint worker_id) {
1251
collection_set_iterate_increment_from(blk, NULL, worker_id);
1252
}
1253
void collection_set_iterate_increment_from(HeapRegionClosure *blk, HeapRegionClaimer* hr_claimer, uint worker_id);
1254
1255
// Returns the HeapRegion that contains addr. addr must not be NULL.
1256
template <class T>
1257
inline HeapRegion* heap_region_containing(const T addr) const;
1258
1259
// Returns the HeapRegion that contains addr, or NULL if that is an uncommitted
1260
// region. addr must not be NULL.
1261
template <class T>
1262
inline HeapRegion* heap_region_containing_or_null(const T addr) const;
1263
1264
// A CollectedHeap is divided into a dense sequence of "blocks"; that is,
1265
// each address in the (reserved) heap is a member of exactly
1266
// one block. The defining characteristic of a block is that it is
1267
// possible to find its size, and thus to progress forward to the next
1268
// block. (Blocks may be of different sizes.) Thus, blocks may
1269
// represent Java objects, or they might be free blocks in a
1270
// free-list-based heap (or subheap), as long as the two kinds are
1271
// distinguishable and the size of each is determinable.
1272
1273
// Returns the address of the start of the "block" that contains the
1274
// address "addr". We say "blocks" instead of "object" since some heaps
1275
// may not pack objects densely; a chunk may either be an object or a
1276
// non-object.
1277
HeapWord* block_start(const void* addr) const;
1278
1279
// Requires "addr" to be the start of a block, and returns "TRUE" iff
1280
// the block is an object.
1281
bool block_is_obj(const HeapWord* addr) const;
1282
1283
// Section on thread-local allocation buffers (TLABs)
1284
// See CollectedHeap for semantics.
1285
1286
size_t tlab_capacity(Thread* ignored) const;
1287
size_t tlab_used(Thread* ignored) const;
1288
size_t max_tlab_size() const;
1289
size_t unsafe_max_tlab_alloc(Thread* ignored) const;
1290
1291
inline bool is_in_young(const oop obj);
1292
1293
// Returns "true" iff the given word_size is "very large".
1294
static bool is_humongous(size_t word_size) {
1295
// Note this has to be strictly greater-than as the TLABs
1296
// are capped at the humongous threshold and we want to
1297
// ensure that we don't try to allocate a TLAB as
1298
// humongous and that we don't allocate a humongous
1299
// object in a TLAB.
1300
return word_size > _humongous_object_threshold_in_words;
1301
}
1302
1303
// Returns the humongous threshold for a specific region size
1304
static size_t humongous_threshold_for(size_t region_size) {
1305
return (region_size / 2);
1306
}
1307
1308
// Returns the number of regions the humongous object of the given word size
1309
// requires.
1310
static size_t humongous_obj_size_in_regions(size_t word_size);
1311
1312
// Print the maximum heap capacity.
1313
virtual size_t max_capacity() const;
1314
1315
Tickspan time_since_last_collection() const { return Ticks::now() - _collection_pause_end; }
1316
1317
// Convenience function to be used in situations where the heap type can be
1318
// asserted to be this type.
1319
static G1CollectedHeap* heap() {
1320
return named_heap<G1CollectedHeap>(CollectedHeap::G1);
1321
}
1322
1323
void set_region_short_lived_locked(HeapRegion* hr);
1324
// add appropriate methods for any other surv rate groups
1325
1326
const G1SurvivorRegions* survivor() const { return &_survivor; }
1327
1328
uint eden_regions_count() const { return _eden.length(); }
1329
uint eden_regions_count(uint node_index) const { return _eden.regions_on_node(node_index); }
1330
uint survivor_regions_count() const { return _survivor.length(); }
1331
uint survivor_regions_count(uint node_index) const { return _survivor.regions_on_node(node_index); }
1332
size_t eden_regions_used_bytes() const { return _eden.used_bytes(); }
1333
size_t survivor_regions_used_bytes() const { return _survivor.used_bytes(); }
1334
uint young_regions_count() const { return _eden.length() + _survivor.length(); }
1335
uint old_regions_count() const { return _old_set.length(); }
1336
uint archive_regions_count() const { return _archive_set.length(); }
1337
uint humongous_regions_count() const { return _humongous_set.length(); }
1338
1339
#ifdef ASSERT
1340
bool check_young_list_empty();
1341
#endif
1342
1343
bool is_marked_next(oop obj) const;
1344
1345
// Determine if an object is dead, given the object and also
1346
// the region to which the object belongs.
1347
bool is_obj_dead(const oop obj, const HeapRegion* hr) const {
1348
return hr->is_obj_dead(obj, _cm->prev_mark_bitmap());
1349
}
1350
1351
// This function returns true when an object has been
1352
// around since the previous marking and hasn't yet
1353
// been marked during this marking, and is not in a closed archive region.
1354
bool is_obj_ill(const oop obj, const HeapRegion* hr) const {
1355
return
1356
!hr->obj_allocated_since_next_marking(obj) &&
1357
!is_marked_next(obj) &&
1358
!hr->is_closed_archive();
1359
}
1360
1361
// Determine if an object is dead, given only the object itself.
1362
// This will find the region to which the object belongs and
1363
// then call the region version of the same function.
1364
1365
// Added if it is NULL it isn't dead.
1366
1367
inline bool is_obj_dead(const oop obj) const;
1368
1369
inline bool is_obj_ill(const oop obj) const;
1370
1371
inline bool is_obj_dead_full(const oop obj, const HeapRegion* hr) const;
1372
inline bool is_obj_dead_full(const oop obj) const;
1373
1374
G1ConcurrentMark* concurrent_mark() const { return _cm; }
1375
1376
// Refinement
1377
1378
G1ConcurrentRefine* concurrent_refine() const { return _cr; }
1379
1380
// Optimized nmethod scanning support routines
1381
1382
// Register the given nmethod with the G1 heap.
1383
virtual void register_nmethod(nmethod* nm);
1384
1385
// Unregister the given nmethod from the G1 heap.
1386
virtual void unregister_nmethod(nmethod* nm);
1387
1388
// No nmethod flushing needed.
1389
virtual void flush_nmethod(nmethod* nm) {}
1390
1391
// No nmethod verification implemented.
1392
virtual void verify_nmethod(nmethod* nm) {}
1393
1394
// Recalculate amount of used memory after GC. Must be called after all allocation
1395
// has finished.
1396
void update_used_after_gc();
1397
// Reset and re-enable the hot card cache.
1398
// Note the counts for the cards in the regions in the
1399
// collection set are reset when the collection set is freed.
1400
void reset_hot_card_cache();
1401
// Free up superfluous code root memory.
1402
void purge_code_root_memory();
1403
1404
// Rebuild the strong code root lists for each region
1405
// after a full GC.
1406
void rebuild_strong_code_roots();
1407
1408
// Performs cleaning of data structures after class unloading.
1409
void complete_cleaning(BoolObjectClosure* is_alive, bool class_unloading_occurred);
1410
1411
// Verification
1412
1413
// Perform any cleanup actions necessary before allowing a verification.
1414
virtual void prepare_for_verify();
1415
1416
// Perform verification.
1417
1418
// vo == UsePrevMarking -> use "prev" marking information,
1419
// vo == UseNextMarking -> use "next" marking information
1420
// vo == UseFullMarking -> use "next" marking bitmap but no TAMS
1421
//
1422
// NOTE: Only the "prev" marking information is guaranteed to be
1423
// consistent most of the time, so most calls to this should use
1424
// vo == UsePrevMarking.
1425
// Currently, there is only one case where this is called with
1426
// vo == UseNextMarking, which is to verify the "next" marking
1427
// information at the end of remark.
1428
// Currently there is only one place where this is called with
1429
// vo == UseFullMarking, which is to verify the marking during a
1430
// full GC.
1431
void verify(VerifyOption vo);
1432
1433
// WhiteBox testing support.
1434
virtual bool supports_concurrent_gc_breakpoints() const;
1435
1436
virtual WorkGang* safepoint_workers() { return _workers; }
1437
1438
virtual bool is_archived_object(oop object) const;
1439
1440
// The methods below are here for convenience and dispatch the
1441
// appropriate method depending on value of the given VerifyOption
1442
// parameter. The values for that parameter, and their meanings,
1443
// are the same as those above.
1444
1445
bool is_obj_dead_cond(const oop obj,
1446
const HeapRegion* hr,
1447
const VerifyOption vo) const;
1448
1449
bool is_obj_dead_cond(const oop obj,
1450
const VerifyOption vo) const;
1451
1452
G1HeapSummary create_g1_heap_summary();
1453
G1EvacSummary create_g1_evac_summary(G1EvacStats* stats);
1454
1455
// Printing
1456
private:
1457
void print_heap_regions() const;
1458
void print_regions_on(outputStream* st) const;
1459
1460
public:
1461
virtual void print_on(outputStream* st) const;
1462
virtual void print_extended_on(outputStream* st) const;
1463
virtual void print_on_error(outputStream* st) const;
1464
1465
virtual void gc_threads_do(ThreadClosure* tc) const;
1466
1467
// Override
1468
void print_tracing_info() const;
1469
1470
// The following two methods are helpful for debugging RSet issues.
1471
void print_cset_rsets() PRODUCT_RETURN;
1472
void print_all_rsets() PRODUCT_RETURN;
1473
1474
// Used to print information about locations in the hs_err file.
1475
virtual bool print_location(outputStream* st, void* addr) const;
1476
};
1477
1478
class G1ParEvacuateFollowersClosure : public VoidClosure {
1479
private:
1480
double _start_term;
1481
double _term_time;
1482
size_t _term_attempts;
1483
1484
void start_term_time() { _term_attempts++; _start_term = os::elapsedTime(); }
1485
void end_term_time() { _term_time += (os::elapsedTime() - _start_term); }
1486
protected:
1487
G1CollectedHeap* _g1h;
1488
G1ParScanThreadState* _par_scan_state;
1489
G1ScannerTasksQueueSet* _queues;
1490
TaskTerminator* _terminator;
1491
G1GCPhaseTimes::GCParPhases _phase;
1492
1493
G1ParScanThreadState* par_scan_state() { return _par_scan_state; }
1494
G1ScannerTasksQueueSet* queues() { return _queues; }
1495
TaskTerminator* terminator() { return _terminator; }
1496
1497
public:
1498
G1ParEvacuateFollowersClosure(G1CollectedHeap* g1h,
1499
G1ParScanThreadState* par_scan_state,
1500
G1ScannerTasksQueueSet* queues,
1501
TaskTerminator* terminator,
1502
G1GCPhaseTimes::GCParPhases phase)
1503
: _start_term(0.0), _term_time(0.0), _term_attempts(0),
1504
_g1h(g1h), _par_scan_state(par_scan_state),
1505
_queues(queues), _terminator(terminator), _phase(phase) {}
1506
1507
void do_void();
1508
1509
double term_time() const { return _term_time; }
1510
size_t term_attempts() const { return _term_attempts; }
1511
1512
private:
1513
inline bool offer_termination();
1514
};
1515
1516
#endif // SHARE_GC_G1_G1COLLECTEDHEAP_HPP
1517
1518