author | tschatzl |
Fri, 29 Nov 2019 10:20:17 +0100 | |
changeset 59321 | 5775e4825e58 |
parent 54678 | 93f09ca4a7f8 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
54264
41af8d0546bc
8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents:
53117
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/parallel/adjoiningGenerations.hpp" |
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
27 |
#include "gc/parallel/adjoiningGenerationsForHeteroHeap.hpp" |
30764 | 28 |
#include "gc/parallel/adjoiningVirtualSpaces.hpp" |
29 |
#include "gc/parallel/parallelScavengeHeap.hpp" |
|
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
30 |
#include "gc/parallel/parallelArguments.hpp" |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
31 |
#include "gc/shared/genArguments.hpp" |
35061 | 32 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46625
diff
changeset
|
33 |
#include "logging/logStream.hpp" |
35061 | 34 |
#include "memory/resourceArea.hpp" |
46625 | 35 |
#include "utilities/align.hpp" |
35061 | 36 |
#include "utilities/ostream.hpp" |
1 | 37 |
|
38 |
// If boundary moving is being used, create the young gen and old |
|
39 |
// gen with ASPSYoungGen and ASPSOldGen, respectively. Revert to |
|
40 |
// the old behavior otherwise (with PSYoungGen and PSOldGen). |
|
41 |
||
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
42 |
AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs) : |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
43 |
_virtual_spaces(new AdjoiningVirtualSpaces(old_young_rs, MinOldSize, |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
44 |
MinNewSize, GenAlignment)) { |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
45 |
size_t init_low_byte_size = OldSize; |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
46 |
size_t min_low_byte_size = MinOldSize; |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
47 |
size_t max_low_byte_size = MaxOldSize; |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
48 |
size_t init_high_byte_size = NewSize; |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
49 |
size_t min_high_byte_size = MinNewSize; |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
50 |
size_t max_high_byte_size = MaxNewSize; |
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
13728
diff
changeset
|
51 |
|
1 | 52 |
assert(min_low_byte_size <= init_low_byte_size && |
53 |
init_low_byte_size <= max_low_byte_size, "Parameter check"); |
|
54 |
assert(min_high_byte_size <= init_high_byte_size && |
|
55 |
init_high_byte_size <= max_high_byte_size, "Parameter check"); |
|
56 |
// Create the generations differently based on the option to |
|
57 |
// move the boundary. |
|
58 |
if (UseAdaptiveGCBoundary) { |
|
59 |
// Initialize the adjoining virtual spaces. Then pass the |
|
60 |
// a virtual to each generation for initialization of the |
|
61 |
// generation. |
|
62 |
||
63 |
// Does the actual creation of the virtual spaces |
|
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
64 |
_virtual_spaces->initialize(max_low_byte_size, |
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
65 |
init_low_byte_size, |
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
66 |
init_high_byte_size); |
1 | 67 |
|
68 |
// Place the young gen at the high end. Passes in the virtual space. |
|
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
69 |
_young_gen = new ASPSYoungGen(_virtual_spaces->high(), |
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
70 |
_virtual_spaces->high()->committed_size(), |
1 | 71 |
min_high_byte_size, |
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
72 |
_virtual_spaces->high_byte_size_limit()); |
1 | 73 |
|
74 |
// Place the old gen at the low end. Passes in the virtual space. |
|
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
75 |
_old_gen = new ASPSOldGen(_virtual_spaces->low(), |
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
76 |
_virtual_spaces->low()->committed_size(), |
1 | 77 |
min_low_byte_size, |
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
78 |
_virtual_spaces->low_byte_size_limit(), |
1 | 79 |
"old", 1); |
80 |
||
81 |
young_gen()->initialize_work(); |
|
82 |
assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(), |
|
83 |
"Consistency check"); |
|
84 |
assert(old_young_rs.size() >= young_gen()->gen_size_limit(), |
|
85 |
"Consistency check"); |
|
86 |
||
87 |
old_gen()->initialize_work("old", 1); |
|
88 |
assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(), |
|
89 |
"Consistency check"); |
|
90 |
assert(old_young_rs.size() >= old_gen()->gen_size_limit(), |
|
91 |
"Consistency check"); |
|
92 |
} else { |
|
93 |
||
94 |
// Layout the reserved space for the generations. |
|
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
95 |
// If OldGen is allocated on nv-dimm, we need to split the reservation (this is required for windows). |
1 | 96 |
ReservedSpace old_rs = |
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
97 |
virtual_spaces()->reserved_space().first_part(max_low_byte_size, ParallelArguments::is_heterogeneous_heap() /* split */); |
1 | 98 |
ReservedSpace heap_rs = |
99 |
virtual_spaces()->reserved_space().last_part(max_low_byte_size); |
|
100 |
ReservedSpace young_rs = heap_rs.first_part(max_high_byte_size); |
|
101 |
assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap"); |
|
102 |
||
103 |
// Create the generations. Virtual spaces are not passed in. |
|
104 |
_young_gen = new PSYoungGen(init_high_byte_size, |
|
105 |
min_high_byte_size, |
|
106 |
max_high_byte_size); |
|
107 |
_old_gen = new PSOldGen(init_low_byte_size, |
|
108 |
min_low_byte_size, |
|
109 |
max_low_byte_size, |
|
110 |
"old", 1); |
|
111 |
||
112 |
// The virtual spaces are created by the initialization of the gens. |
|
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
113 |
_young_gen->initialize(young_rs, GenAlignment); |
1 | 114 |
assert(young_gen()->gen_size_limit() == young_rs.size(), |
115 |
"Consistency check"); |
|
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
116 |
_old_gen->initialize(old_rs, GenAlignment, "old", 1); |
1 | 117 |
assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check"); |
118 |
} |
|
119 |
} |
|
120 |
||
54264
41af8d0546bc
8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents:
53117
diff
changeset
|
121 |
AdjoiningGenerations::AdjoiningGenerations(): _young_gen(NULL), _old_gen(NULL), _virtual_spaces(NULL) { } |
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
122 |
|
1 | 123 |
size_t AdjoiningGenerations::reserved_byte_size() { |
124 |
return virtual_spaces()->reserved_space().size(); |
|
125 |
} |
|
126 |
||
35061 | 127 |
void log_before_expansion(bool old, size_t expand_in_bytes, size_t change_in_bytes, size_t max_size) { |
51978 | 128 |
Log(gc, ergo, heap) log; |
35061 | 129 |
if (!log.is_debug()) { |
130 |
return; |
|
131 |
} |
|
132 |
log.debug("Before expansion of %s gen with boundary move", old ? "old" : "young"); |
|
133 |
log.debug(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX, |
|
134 |
expand_in_bytes, change_in_bytes); |
|
135 |
ResourceMark rm; |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46625
diff
changeset
|
136 |
LogStream ls(log.debug()); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46625
diff
changeset
|
137 |
ParallelScavengeHeap::heap()->print_on(&ls); |
35061 | 138 |
log.debug(" PS%sGen max size: " SIZE_FORMAT "K", old ? "Old" : "Young", max_size/K); |
139 |
} |
|
140 |
||
141 |
void log_after_expansion(bool old, size_t max_size) { |
|
51978 | 142 |
Log(gc, ergo, heap) log; |
35061 | 143 |
if (!log.is_debug()) { |
144 |
return; |
|
145 |
} |
|
146 |
log.debug("After expansion of %s gen with boundary move", old ? "old" : "young"); |
|
147 |
ResourceMark rm; |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46625
diff
changeset
|
148 |
LogStream ls(log.debug()); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46625
diff
changeset
|
149 |
ParallelScavengeHeap::heap()->print_on(&ls); |
35061 | 150 |
log.debug(" PS%sGen max size: " SIZE_FORMAT "K", old ? "Old" : "Young", max_size/K); |
151 |
} |
|
1 | 152 |
|
153 |
// Make checks on the current sizes of the generations and |
|
22551 | 154 |
// the constraints on the sizes of the generations. Push |
155 |
// up the boundary within the constraints. A partial |
|
1 | 156 |
// push can occur. |
157 |
void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) { |
|
158 |
assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
|
159 |
||
160 |
assert_lock_strong(ExpandHeap_lock); |
|
161 |
assert_locked_or_safepoint(Heap_lock); |
|
162 |
||
163 |
// These sizes limit the amount the boundaries can move. Effectively, |
|
164 |
// the generation says how much it is willing to yield to the other |
|
165 |
// generation. |
|
166 |
const size_t young_gen_available = young_gen()->available_for_contraction(); |
|
167 |
const size_t old_gen_available = old_gen()->available_for_expansion(); |
|
168 |
const size_t alignment = virtual_spaces()->alignment(); |
|
169 |
size_t change_in_bytes = MIN3(young_gen_available, |
|
170 |
old_gen_available, |
|
46622
910fc72c03e8
8178501: Replace usages of align macros with calls to the align inline functions
stefank
parents:
46619
diff
changeset
|
171 |
align_up(expand_in_bytes, alignment)); |
1 | 172 |
|
173 |
if (change_in_bytes == 0) { |
|
174 |
return; |
|
175 |
} |
|
176 |
||
35061 | 177 |
log_before_expansion(true, expand_in_bytes, change_in_bytes, old_gen()->max_gen_size()); |
1 | 178 |
|
179 |
// Move the boundary between the generations up (smaller young gen). |
|
180 |
if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) { |
|
181 |
young_gen()->reset_after_change(); |
|
182 |
old_gen()->reset_after_change(); |
|
183 |
} |
|
184 |
||
185 |
// The total reserved for the generations should match the sum |
|
186 |
// of the two even if the boundary is moving. |
|
187 |
assert(reserved_byte_size() == |
|
188 |
old_gen()->max_gen_size() + young_gen()->max_size(), |
|
189 |
"Space is missing"); |
|
190 |
young_gen()->space_invariants(); |
|
191 |
old_gen()->space_invariants(); |
|
192 |
||
35061 | 193 |
log_after_expansion(true, old_gen()->max_gen_size()); |
1 | 194 |
} |
195 |
||
196 |
// See comments on request_old_gen_expansion() |
|
197 |
bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) { |
|
198 |
assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
|
199 |
||
200 |
// If eden is not empty, the boundary can be moved but no advantage |
|
201 |
// can be made of the move since eden cannot be moved. |
|
202 |
if (!young_gen()->eden_space()->is_empty()) { |
|
203 |
return false; |
|
204 |
} |
|
205 |
||
206 |
||
207 |
bool result = false; |
|
208 |
const size_t young_gen_available = young_gen()->available_for_expansion(); |
|
209 |
const size_t old_gen_available = old_gen()->available_for_contraction(); |
|
210 |
const size_t alignment = virtual_spaces()->alignment(); |
|
211 |
size_t change_in_bytes = MIN3(young_gen_available, |
|
212 |
old_gen_available, |
|
46622
910fc72c03e8
8178501: Replace usages of align macros with calls to the align inline functions
stefank
parents:
46619
diff
changeset
|
213 |
align_up(expand_in_bytes, alignment)); |
1 | 214 |
|
215 |
if (change_in_bytes == 0) { |
|
216 |
return false; |
|
217 |
} |
|
218 |
||
35061 | 219 |
log_before_expansion(false, expand_in_bytes, change_in_bytes, young_gen()->max_size()); |
1 | 220 |
|
221 |
// Move the boundary between the generations down (smaller old gen). |
|
222 |
MutexLocker x(ExpandHeap_lock); |
|
223 |
if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) { |
|
224 |
young_gen()->reset_after_change(); |
|
225 |
old_gen()->reset_after_change(); |
|
226 |
result = true; |
|
227 |
} |
|
228 |
||
229 |
// The total reserved for the generations should match the sum |
|
230 |
// of the two even if the boundary is moving. |
|
231 |
assert(reserved_byte_size() == |
|
232 |
old_gen()->max_gen_size() + young_gen()->max_size(), |
|
233 |
"Space is missing"); |
|
234 |
young_gen()->space_invariants(); |
|
235 |
old_gen()->space_invariants(); |
|
236 |
||
35061 | 237 |
log_after_expansion(false, young_gen()->max_size()); |
1 | 238 |
|
239 |
return result; |
|
240 |
} |
|
241 |
||
242 |
// Additional space is needed in the old generation. Try to move the boundary |
|
243 |
// up to meet the need. Moves boundary up only |
|
244 |
void AdjoiningGenerations::adjust_boundary_for_old_gen_needs( |
|
245 |
size_t desired_free_space) { |
|
246 |
assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
|
247 |
||
248 |
// Stress testing. |
|
249 |
if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) { |
|
250 |
MutexLocker x(ExpandHeap_lock); |
|
251 |
request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2); |
|
252 |
} |
|
253 |
||
254 |
// Expand only if the entire generation is already committed. |
|
255 |
if (old_gen()->virtual_space()->uncommitted_size() == 0) { |
|
256 |
if (old_gen()->free_in_bytes() < desired_free_space) { |
|
257 |
MutexLocker x(ExpandHeap_lock); |
|
258 |
request_old_gen_expansion(desired_free_space); |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
// See comment on adjust_boundary_for_old_gen_needss(). |
|
264 |
// Adjust boundary down only. |
|
265 |
void AdjoiningGenerations::adjust_boundary_for_young_gen_needs(size_t eden_size, |
|
266 |
size_t survivor_size) { |
|
267 |
||
268 |
assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check"); |
|
269 |
||
270 |
// Stress testing. |
|
271 |
if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 0) { |
|
272 |
request_young_gen_expansion(virtual_spaces()->alignment() * 3 / 2); |
|
273 |
eden_size = young_gen()->eden_space()->capacity_in_bytes(); |
|
274 |
} |
|
275 |
||
276 |
// Expand only if the entire generation is already committed. |
|
277 |
if (young_gen()->virtual_space()->uncommitted_size() == 0) { |
|
278 |
size_t desired_size = eden_size + 2 * survivor_size; |
|
279 |
const size_t committed = young_gen()->virtual_space()->committed_size(); |
|
280 |
if (desired_size > committed) { |
|
281 |
request_young_gen_expansion(desired_size - committed); |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
285 |
|
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
286 |
AdjoiningGenerations* AdjoiningGenerations::create_adjoining_generations(ReservedSpace old_young_rs) { |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
287 |
if (ParallelArguments::is_heterogeneous_heap() && UseAdaptiveGCBoundary) { |
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
288 |
return new AdjoiningGenerationsForHeteroHeap(old_young_rs); |
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
289 |
} else { |
54678
93f09ca4a7f8
8198505: Remove CollectorPolicy and its subclasses
stefank
parents:
54264
diff
changeset
|
290 |
return new AdjoiningGenerations(old_young_rs); |
53117
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
291 |
} |
37930c6ba6d7
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents:
51978
diff
changeset
|
292 |
} |