Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1Arguments.cpp
40957 views
1
/*
2
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
#include "precompiled.hpp"
27
#include "gc/g1/g1Arguments.hpp"
28
#include "gc/g1/g1CollectedHeap.inline.hpp"
29
#include "gc/g1/g1HeapVerifier.hpp"
30
#include "gc/g1/heapRegion.hpp"
31
#include "gc/g1/heapRegionRemSet.hpp"
32
#include "gc/shared/cardTableRS.hpp"
33
#include "gc/shared/gcArguments.hpp"
34
#include "gc/shared/workerPolicy.hpp"
35
#include "runtime/globals.hpp"
36
#include "runtime/globals_extension.hpp"
37
#include "runtime/java.hpp"
38
39
static size_t calculate_heap_alignment(size_t space_alignment) {
40
size_t card_table_alignment = CardTableRS::ct_max_alignment_constraint();
41
size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
42
return MAX3(card_table_alignment, space_alignment, page_size);
43
}
44
45
void G1Arguments::initialize_alignments() {
46
// Set up the region size and associated fields.
47
//
48
// There is a circular dependency here. We base the region size on the heap
49
// size, but the heap size should be aligned with the region size. To get
50
// around this we use the unaligned values for the heap.
51
HeapRegion::setup_heap_region_size(MaxHeapSize);
52
53
// The remembered set needs the heap regions set up.
54
HeapRegionRemSet::setup_remset_size();
55
// Needs remembered set initialization as the ergonomics are based
56
// on it.
57
if (FLAG_IS_DEFAULT(G1EagerReclaimRemSetThreshold)) {
58
FLAG_SET_ERGO(G1EagerReclaimRemSetThreshold, G1RSetSparseRegionEntries);
59
}
60
61
SpaceAlignment = HeapRegion::GrainBytes;
62
HeapAlignment = calculate_heap_alignment(SpaceAlignment);
63
}
64
65
size_t G1Arguments::conservative_max_heap_alignment() {
66
return HeapRegion::max_region_size();
67
}
68
69
void G1Arguments::initialize_verification_types() {
70
if (strlen(VerifyGCType) > 0) {
71
const char delimiter[] = " ,\n";
72
size_t length = strlen(VerifyGCType);
73
char* type_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal);
74
strncpy(type_list, VerifyGCType, length + 1);
75
char* save_ptr;
76
77
char* token = strtok_r(type_list, delimiter, &save_ptr);
78
while (token != NULL) {
79
parse_verification_type(token);
80
token = strtok_r(NULL, delimiter, &save_ptr);
81
}
82
FREE_C_HEAP_ARRAY(char, type_list);
83
}
84
}
85
86
void G1Arguments::parse_verification_type(const char* type) {
87
if (strcmp(type, "young-normal") == 0) {
88
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyYoungNormal);
89
} else if (strcmp(type, "concurrent-start") == 0) {
90
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyConcurrentStart);
91
} else if (strcmp(type, "mixed") == 0) {
92
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyMixed);
93
} else if (strcmp(type, "remark") == 0) {
94
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyRemark);
95
} else if (strcmp(type, "cleanup") == 0) {
96
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyCleanup);
97
} else if (strcmp(type, "full") == 0) {
98
G1HeapVerifier::enable_verification_type(G1HeapVerifier::G1VerifyFull);
99
} else {
100
log_warning(gc, verify)("VerifyGCType: '%s' is unknown. Available types are: "
101
"young-normal, concurrent-start, mixed, remark, cleanup and full", type);
102
}
103
}
104
105
// Returns the maximum number of workers to be used in a concurrent
106
// phase based on the number of GC workers being used in a STW
107
// phase.
108
static uint scale_concurrent_worker_threads(uint num_gc_workers) {
109
return MAX2((num_gc_workers + 2) / 4, 1U);
110
}
111
112
void G1Arguments::initialize_mark_stack_size() {
113
if (FLAG_IS_DEFAULT(MarkStackSize)) {
114
size_t mark_stack_size = MIN2(MarkStackSizeMax,
115
MAX2(MarkStackSize, (size_t)ConcGCThreads * TASKQUEUE_SIZE));
116
FLAG_SET_ERGO(MarkStackSize, mark_stack_size);
117
}
118
119
log_trace(gc)("MarkStackSize: %uk MarkStackSizeMax: %uk", (uint)(MarkStackSize / K), (uint)(MarkStackSizeMax / K));
120
}
121
122
void G1Arguments::initialize() {
123
GCArguments::initialize();
124
assert(UseG1GC, "Error");
125
FLAG_SET_DEFAULT(ParallelGCThreads, WorkerPolicy::parallel_worker_threads());
126
if (ParallelGCThreads == 0) {
127
assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0.");
128
vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL);
129
}
130
131
// When dumping the CDS archive we want to reduce fragmentation by
132
// triggering a full collection. To get as low fragmentation as
133
// possible we only use one worker thread.
134
if (DumpSharedSpaces) {
135
FLAG_SET_ERGO(ParallelGCThreads, 1);
136
}
137
138
if (FLAG_IS_DEFAULT(G1ConcRefinementThreads)) {
139
FLAG_SET_ERGO(G1ConcRefinementThreads, ParallelGCThreads);
140
}
141
142
if (FLAG_IS_DEFAULT(ConcGCThreads) || ConcGCThreads == 0) {
143
// Calculate the number of concurrent worker threads by scaling
144
// the number of parallel GC threads.
145
uint marking_thread_num = scale_concurrent_worker_threads(ParallelGCThreads);
146
FLAG_SET_ERGO(ConcGCThreads, marking_thread_num);
147
}
148
149
if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
150
// In G1, we want the default GC overhead goal to be higher than
151
// it is for PS, or the heap might be expanded too aggressively.
152
// We set it here to ~8%.
153
FLAG_SET_DEFAULT(GCTimeRatio, 12);
154
}
155
156
// Below, we might need to calculate the pause time interval based on
157
// the pause target. When we do so we are going to give G1 maximum
158
// flexibility and allow it to do pauses when it needs to. So, we'll
159
// arrange that the pause interval to be pause time target + 1 to
160
// ensure that a) the pause time target is maximized with respect to
161
// the pause interval and b) we maintain the invariant that pause
162
// time target < pause interval. If the user does not want this
163
// maximum flexibility, they will have to set the pause interval
164
// explicitly.
165
166
if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
167
// The default pause time target in G1 is 200ms
168
FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
169
}
170
171
// Then, if the interval parameter was not set, set it according to
172
// the pause time target (this will also deal with the case when the
173
// pause time target is the default value).
174
if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
175
FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
176
}
177
178
if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) {
179
FLAG_SET_DEFAULT(ParallelRefProcEnabled, true);
180
}
181
182
// By default do not let the target stack size to be more than 1/4 of the entries
183
if (FLAG_IS_DEFAULT(GCDrainStackTargetSize)) {
184
FLAG_SET_ERGO(GCDrainStackTargetSize, MIN2(GCDrainStackTargetSize, (uintx)TASKQUEUE_SIZE / 4));
185
}
186
187
#ifdef COMPILER2
188
// Enable loop strip mining to offer better pause time guarantees
189
if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) {
190
FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true);
191
if (FLAG_IS_DEFAULT(LoopStripMiningIter)) {
192
FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);
193
}
194
}
195
#endif
196
197
initialize_mark_stack_size();
198
initialize_verification_types();
199
}
200
201
void G1Arguments::initialize_heap_flags_and_sizes() {
202
GCArguments::initialize_heap_flags_and_sizes();
203
}
204
205
CollectedHeap* G1Arguments::create_heap() {
206
return new G1CollectedHeap();
207
}
208
209
size_t G1Arguments::heap_reserved_size_bytes() {
210
return MaxHeapSize;
211
}
212
213
214