Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp
41152 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_PARALLEL_PARALLELSCAVENGEHEAP_HPP
26
#define SHARE_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
27
28
#include "gc/parallel/objectStartArray.hpp"
29
#include "gc/parallel/psGCAdaptivePolicyCounters.hpp"
30
#include "gc/parallel/psOldGen.hpp"
31
#include "gc/parallel/psYoungGen.hpp"
32
#include "gc/shared/cardTableBarrierSet.hpp"
33
#include "gc/shared/collectedHeap.hpp"
34
#include "gc/shared/gcPolicyCounters.hpp"
35
#include "gc/shared/gcWhen.hpp"
36
#include "gc/shared/preGCValues.hpp"
37
#include "gc/shared/referenceProcessor.hpp"
38
#include "gc/shared/softRefPolicy.hpp"
39
#include "gc/shared/strongRootsScope.hpp"
40
#include "gc/shared/workgroup.hpp"
41
#include "logging/log.hpp"
42
#include "utilities/growableArray.hpp"
43
#include "utilities/ostream.hpp"
44
45
class GCHeapSummary;
46
class HeapBlockClaimer;
47
class MemoryManager;
48
class MemoryPool;
49
class PSAdaptiveSizePolicy;
50
class PSCardTable;
51
class PSHeapSummary;
52
53
class ParallelScavengeHeap : public CollectedHeap {
54
friend class VMStructs;
55
private:
56
static PSYoungGen* _young_gen;
57
static PSOldGen* _old_gen;
58
59
// Sizing policy for entire heap
60
static PSAdaptiveSizePolicy* _size_policy;
61
static PSGCAdaptivePolicyCounters* _gc_policy_counters;
62
63
SoftRefPolicy _soft_ref_policy;
64
65
unsigned int _death_march_count;
66
67
GCMemoryManager* _young_manager;
68
GCMemoryManager* _old_manager;
69
70
MemoryPool* _eden_pool;
71
MemoryPool* _survivor_pool;
72
MemoryPool* _old_pool;
73
74
WorkGang _workers;
75
76
virtual void initialize_serviceability();
77
78
void trace_actual_reserved_page_size(const size_t reserved_heap_size, const ReservedSpace rs);
79
void trace_heap(GCWhen::Type when, const GCTracer* tracer);
80
81
// Allocate in oldgen and record the allocation with the size_policy.
82
HeapWord* allocate_old_gen_and_record(size_t word_size);
83
84
protected:
85
static inline size_t total_invocations();
86
HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size);
87
88
inline bool should_alloc_in_eden(size_t size) const;
89
inline void death_march_check(HeapWord* const result, size_t size);
90
HeapWord* mem_allocate_old_gen(size_t size);
91
92
public:
93
ParallelScavengeHeap() :
94
CollectedHeap(),
95
_death_march_count(0),
96
_young_manager(NULL),
97
_old_manager(NULL),
98
_eden_pool(NULL),
99
_survivor_pool(NULL),
100
_old_pool(NULL),
101
_workers("GC Thread",
102
ParallelGCThreads,
103
true /* are_GC_task_threads */,
104
false /* are_ConcurrentGC_threads */) { }
105
106
// For use by VM operations
107
enum CollectionType {
108
Scavenge,
109
MarkSweep
110
};
111
112
virtual Name kind() const {
113
return CollectedHeap::Parallel;
114
}
115
116
virtual const char* name() const {
117
return "Parallel";
118
}
119
120
virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; }
121
122
virtual GrowableArray<GCMemoryManager*> memory_managers();
123
virtual GrowableArray<MemoryPool*> memory_pools();
124
125
static PSYoungGen* young_gen() { return _young_gen; }
126
static PSOldGen* old_gen() { return _old_gen; }
127
128
virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }
129
130
static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
131
132
static ParallelScavengeHeap* heap() {
133
return named_heap<ParallelScavengeHeap>(CollectedHeap::Parallel);
134
}
135
136
CardTableBarrierSet* barrier_set();
137
PSCardTable* card_table();
138
139
// Returns JNI_OK on success
140
virtual jint initialize();
141
142
void post_initialize();
143
void update_counters();
144
145
size_t capacity() const;
146
size_t used() const;
147
148
// Return "true" if all generations have reached the
149
// maximal committed limit that they can reach, without a garbage
150
// collection.
151
virtual bool is_maximal_no_gc() const;
152
153
virtual void register_nmethod(nmethod* nm);
154
virtual void unregister_nmethod(nmethod* nm);
155
virtual void verify_nmethod(nmethod* nm);
156
virtual void flush_nmethod(nmethod* nm);
157
158
void prune_scavengable_nmethods();
159
160
size_t max_capacity() const;
161
162
// Whether p is in the allocated part of the heap
163
bool is_in(const void* p) const;
164
165
bool is_in_reserved(const void* p) const;
166
167
bool is_in_young(oop p); // reserved part
168
bool is_in_old(oop p); // reserved part
169
170
MemRegion reserved_region() const { return _reserved; }
171
HeapWord* base() const { return _reserved.start(); }
172
173
// Memory allocation. "gc_time_limit_was_exceeded" will
174
// be set to true if the adaptive size policy determine that
175
// an excessive amount of time is being spent doing collections
176
// and caused a NULL to be returned. If a NULL is not returned,
177
// "gc_time_limit_was_exceeded" has an undefined meaning.
178
HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
179
180
// Allocation attempt(s) during a safepoint. It should never be called
181
// to allocate a new TLAB as this allocation might be satisfied out
182
// of the old generation.
183
HeapWord* failed_mem_allocate(size_t size);
184
185
// Support for System.gc()
186
void collect(GCCause::Cause cause);
187
188
// These also should be called by the vm thread at a safepoint (e.g., from a
189
// VM operation).
190
//
191
// The first collects the young generation only, unless the scavenge fails; it
192
// will then attempt a full gc. The second collects the entire heap; if
193
// maximum_compaction is true, it will compact everything and clear all soft
194
// references.
195
inline void invoke_scavenge();
196
197
// Perform a full collection
198
virtual void do_full_collection(bool clear_all_soft_refs);
199
200
bool supports_inline_contig_alloc() const { return !UseNUMA; }
201
202
HeapWord* volatile* top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord* volatile*)-1; }
203
HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; }
204
205
void ensure_parsability(bool retire_tlabs);
206
void resize_all_tlabs();
207
208
size_t tlab_capacity(Thread* thr) const;
209
size_t tlab_used(Thread* thr) const;
210
size_t unsafe_max_tlab_alloc(Thread* thr) const;
211
212
void object_iterate(ObjectClosure* cl);
213
void object_iterate_parallel(ObjectClosure* cl, HeapBlockClaimer* claimer);
214
virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num);
215
216
HeapWord* block_start(const void* addr) const;
217
bool block_is_obj(const HeapWord* addr) const;
218
219
void prepare_for_verify();
220
PSHeapSummary create_ps_heap_summary();
221
virtual void print_on(outputStream* st) const;
222
virtual void print_on_error(outputStream* st) const;
223
virtual void gc_threads_do(ThreadClosure* tc) const;
224
virtual void print_tracing_info() const;
225
226
virtual WorkGang* safepoint_workers() { return &_workers; }
227
228
PreGenGCValues get_pre_gc_values() const;
229
void print_heap_change(const PreGenGCValues& pre_gc_values) const;
230
231
// Used to print information about locations in the hs_err file.
232
virtual bool print_location(outputStream* st, void* addr) const;
233
234
void verify(VerifyOption option /* ignored */);
235
236
// Resize the young generation. The reserved space for the
237
// generation may be expanded in preparation for the resize.
238
void resize_young_gen(size_t eden_size, size_t survivor_size);
239
240
// Resize the old generation. The reserved space for the
241
// generation may be expanded in preparation for the resize.
242
void resize_old_gen(size_t desired_free_space);
243
244
// Save the tops of the spaces in all generations
245
void record_gen_tops_before_GC() PRODUCT_RETURN;
246
247
// Mangle the unused parts of all spaces in the heap
248
void gen_mangle_unused_area() PRODUCT_RETURN;
249
250
// Call these in sequential code around the processing of strong roots.
251
class ParStrongRootsScope : public MarkScope {
252
public:
253
ParStrongRootsScope();
254
~ParStrongRootsScope();
255
};
256
257
GCMemoryManager* old_gc_manager() const { return _old_manager; }
258
GCMemoryManager* young_gc_manager() const { return _young_manager; }
259
260
WorkGang& workers() {
261
return _workers;
262
}
263
};
264
265
// Class that can be used to print information about the
266
// adaptive size policy at intervals specified by
267
// AdaptiveSizePolicyOutputInterval. Only print information
268
// if an adaptive size policy is in use.
269
class AdaptiveSizePolicyOutput : AllStatic {
270
static bool enabled() {
271
return UseParallelGC &&
272
UseAdaptiveSizePolicy &&
273
log_is_enabled(Debug, gc, ergo);
274
}
275
public:
276
static void print() {
277
if (enabled()) {
278
ParallelScavengeHeap::heap()->size_policy()->print();
279
}
280
}
281
282
static void print(AdaptiveSizePolicy* size_policy, uint count) {
283
bool do_print =
284
enabled() &&
285
(AdaptiveSizePolicyOutputInterval > 0) &&
286
(count % AdaptiveSizePolicyOutputInterval) == 0;
287
288
if (do_print) {
289
size_policy->print();
290
}
291
}
292
};
293
294
#endif // SHARE_GC_PARALLEL_PARALLELSCAVENGEHEAP_HPP
295
296