Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp @ 20501:c204e2044c29
8038624: interpretedVFrame::expressions() must respect InterpreterOopMap for liveness
Reviewed-by: coleenp, minqi
author | mgronlun |
---|---|
date | Mon, 29 Sep 2014 13:12:48 +0200 |
parents | 78bbf4d43a14 |
children | 52b4284cb496 |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17467
diff
changeset
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" | |
27 #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp" | |
28 #include "gc_implementation/parallelScavenge/psScavenge.hpp" | |
29 #include "gc_implementation/parallelScavenge/psYoungGen.hpp" | |
30 #include "gc_implementation/shared/gcUtil.hpp" | |
31 #include "gc_implementation/shared/mutableNUMASpace.hpp" | |
32 #include "gc_implementation/shared/spaceDecorator.hpp" | |
33 #include "oops/oop.inline.hpp" | |
34 #include "runtime/java.hpp" | |
0 | 35 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17467
diff
changeset
|
36 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17467
diff
changeset
|
37 |
0 | 38 PSYoungGen::PSYoungGen(size_t initial_size, |
39 size_t min_size, | |
40 size_t max_size) : | |
41 _init_gen_size(initial_size), | |
42 _min_gen_size(min_size), | |
43 _max_gen_size(max_size) | |
44 {} | |
45 | |
46 void PSYoungGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) { | |
47 assert(_init_gen_size != 0, "Should have a finite size"); | |
48 _virtual_space = new PSVirtualSpace(rs, alignment); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
49 if (!virtual_space()->expand_by(_init_gen_size)) { |
0 | 50 vm_exit_during_initialization("Could not reserve enough space for " |
51 "object heap"); | |
52 } | |
53 } | |
54 | |
55 void PSYoungGen::initialize(ReservedSpace rs, size_t alignment) { | |
56 initialize_virtual_space(rs, alignment); | |
57 initialize_work(); | |
58 } | |
59 | |
60 void PSYoungGen::initialize_work() { | |
61 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
62 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
63 (HeapWord*)virtual_space()->high_boundary()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
64 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
65 MemRegion cmr((HeapWord*)virtual_space()->low(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
66 (HeapWord*)virtual_space()->high()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
67 Universe::heap()->barrier_set()->resize_covered_region(cmr); |
0 | 68 |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
69 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
70 // Mangle newly committed space immediately because it |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
71 // can be done here more simply that after the new |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
72 // spaces have been computed. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
73 SpaceMangler::mangle_region(cmr); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
74 } |
0 | 75 |
76 if (UseNUMA) { | |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
77 _eden_space = new MutableNUMASpace(virtual_space()->alignment()); |
0 | 78 } else { |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
79 _eden_space = new MutableSpace(virtual_space()->alignment()); |
0 | 80 } |
535
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
81 _from_space = new MutableSpace(virtual_space()->alignment()); |
4e400c36026f
6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents:
269
diff
changeset
|
82 _to_space = new MutableSpace(virtual_space()->alignment()); |
0 | 83 |
84 if (_eden_space == NULL || _from_space == NULL || _to_space == NULL) { | |
85 vm_exit_during_initialization("Could not allocate a young gen space"); | |
86 } | |
87 | |
88 // Allocate the mark sweep views of spaces | |
89 _eden_mark_sweep = | |
90 new PSMarkSweepDecorator(_eden_space, NULL, MarkSweepDeadRatio); | |
91 _from_mark_sweep = | |
92 new PSMarkSweepDecorator(_from_space, NULL, MarkSweepDeadRatio); | |
93 _to_mark_sweep = | |
94 new PSMarkSweepDecorator(_to_space, NULL, MarkSweepDeadRatio); | |
95 | |
96 if (_eden_mark_sweep == NULL || | |
97 _from_mark_sweep == NULL || | |
98 _to_mark_sweep == NULL) { | |
99 vm_exit_during_initialization("Could not complete allocation" | |
100 " of the young generation"); | |
101 } | |
102 | |
103 // Generation Counters - generation 0, 3 subspaces | |
104 _gen_counters = new PSGenerationCounters("new", 0, 3, _virtual_space); | |
105 | |
106 // Compute maximum space sizes for performance counters | |
107 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
13060
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
108 size_t alignment = heap->space_alignment(); |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
109 size_t size = virtual_space()->reserved_size(); |
0 | 110 |
111 size_t max_survivor_size; | |
112 size_t max_eden_size; | |
113 | |
114 if (UseAdaptiveSizePolicy) { | |
115 max_survivor_size = size / MinSurvivorRatio; | |
116 | |
117 // round the survivor space size down to the nearest alignment | |
118 // and make sure its size is greater than 0. | |
119 max_survivor_size = align_size_down(max_survivor_size, alignment); | |
120 max_survivor_size = MAX2(max_survivor_size, alignment); | |
121 | |
122 // set the maximum size of eden to be the size of the young gen | |
123 // less two times the minimum survivor size. The minimum survivor | |
124 // size for UseAdaptiveSizePolicy is one alignment. | |
125 max_eden_size = size - 2 * alignment; | |
126 } else { | |
127 max_survivor_size = size / InitialSurvivorRatio; | |
128 | |
129 // round the survivor space size down to the nearest alignment | |
130 // and make sure its size is greater than 0. | |
131 max_survivor_size = align_size_down(max_survivor_size, alignment); | |
132 max_survivor_size = MAX2(max_survivor_size, alignment); | |
133 | |
134 // set the maximum size of eden to be the size of the young gen | |
135 // less two times the survivor size when the generation is 100% | |
136 // committed. The minimum survivor size for -UseAdaptiveSizePolicy | |
137 // is dependent on the committed portion (current capacity) of the | |
138 // generation - the less space committed, the smaller the survivor | |
139 // space, possibly as small as an alignment. However, we are interested | |
140 // in the case where the young generation is 100% committed, as this | |
141 // is the point where eden reachs its maximum size. At this point, | |
142 // the size of a survivor space is max_survivor_size. | |
143 max_eden_size = size - 2 * max_survivor_size; | |
144 } | |
145 | |
146 _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space, | |
147 _gen_counters); | |
148 _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space, | |
149 _gen_counters); | |
150 _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space, | |
151 _gen_counters); | |
152 | |
153 compute_initial_space_boundaries(); | |
154 } | |
155 | |
156 void PSYoungGen::compute_initial_space_boundaries() { | |
157 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
158 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
159 | |
160 // Compute sizes | |
13060
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
161 size_t alignment = heap->space_alignment(); |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
162 size_t size = virtual_space()->committed_size(); |
13060
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
163 assert(size >= 3 * alignment, "Young space is not large enough for eden + 2 survivors"); |
0 | 164 |
165 size_t survivor_size = size / InitialSurvivorRatio; | |
166 survivor_size = align_size_down(survivor_size, alignment); | |
167 // ... but never less than an alignment | |
168 survivor_size = MAX2(survivor_size, alignment); | |
169 | |
170 // Young generation is eden + 2 survivor spaces | |
171 size_t eden_size = size - (2 * survivor_size); | |
172 | |
173 // Now go ahead and set 'em. | |
174 set_space_boundaries(eden_size, survivor_size); | |
175 space_invariants(); | |
176 | |
177 if (UsePerfData) { | |
178 _eden_counters->update_capacity(); | |
179 _from_counters->update_capacity(); | |
180 _to_counters->update_capacity(); | |
181 } | |
182 } | |
183 | |
184 void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) { | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
185 assert(eden_size < virtual_space()->committed_size(), "just checking"); |
0 | 186 assert(eden_size > 0 && survivor_size > 0, "just checking"); |
187 | |
188 // Initial layout is Eden, to, from. After swapping survivor spaces, | |
189 // that leaves us with Eden, from, to, which is step one in our two | |
190 // step resize-with-live-data procedure. | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
191 char *eden_start = virtual_space()->low(); |
0 | 192 char *to_start = eden_start + eden_size; |
193 char *from_start = to_start + survivor_size; | |
194 char *from_end = from_start + survivor_size; | |
195 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
196 assert(from_end == virtual_space()->high(), "just checking"); |
0 | 197 assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); |
198 assert(is_object_aligned((intptr_t)to_start), "checking alignment"); | |
199 assert(is_object_aligned((intptr_t)from_start), "checking alignment"); | |
200 | |
201 MemRegion eden_mr((HeapWord*)eden_start, (HeapWord*)to_start); | |
202 MemRegion to_mr ((HeapWord*)to_start, (HeapWord*)from_start); | |
203 MemRegion from_mr((HeapWord*)from_start, (HeapWord*)from_end); | |
204 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
205 eden_space()->initialize(eden_mr, true, ZapUnusedHeapArea); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
206 to_space()->initialize(to_mr , true, ZapUnusedHeapArea); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
207 from_space()->initialize(from_mr, true, ZapUnusedHeapArea); |
0 | 208 } |
209 | |
210 #ifndef PRODUCT | |
211 void PSYoungGen::space_invariants() { | |
212 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
13060
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
213 const size_t alignment = heap->space_alignment(); |
0 | 214 |
215 // Currently, our eden size cannot shrink to zero | |
216 guarantee(eden_space()->capacity_in_bytes() >= alignment, "eden too small"); | |
217 guarantee(from_space()->capacity_in_bytes() >= alignment, "from too small"); | |
218 guarantee(to_space()->capacity_in_bytes() >= alignment, "to too small"); | |
219 | |
220 // Relationship of spaces to each other | |
221 char* eden_start = (char*)eden_space()->bottom(); | |
222 char* eden_end = (char*)eden_space()->end(); | |
223 char* from_start = (char*)from_space()->bottom(); | |
224 char* from_end = (char*)from_space()->end(); | |
225 char* to_start = (char*)to_space()->bottom(); | |
226 char* to_end = (char*)to_space()->end(); | |
227 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
228 guarantee(eden_start >= virtual_space()->low(), "eden bottom"); |
0 | 229 guarantee(eden_start < eden_end, "eden space consistency"); |
230 guarantee(from_start < from_end, "from space consistency"); | |
231 guarantee(to_start < to_end, "to space consistency"); | |
232 | |
233 // Check whether from space is below to space | |
234 if (from_start < to_start) { | |
235 // Eden, from, to | |
236 guarantee(eden_end <= from_start, "eden/from boundary"); | |
237 guarantee(from_end <= to_start, "from/to boundary"); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
238 guarantee(to_end <= virtual_space()->high(), "to end"); |
0 | 239 } else { |
240 // Eden, to, from | |
241 guarantee(eden_end <= to_start, "eden/to boundary"); | |
242 guarantee(to_end <= from_start, "to/from boundary"); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
243 guarantee(from_end <= virtual_space()->high(), "from end"); |
0 | 244 } |
245 | |
246 // More checks that the virtual space is consistent with the spaces | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
247 assert(virtual_space()->committed_size() >= |
0 | 248 (eden_space()->capacity_in_bytes() + |
249 to_space()->capacity_in_bytes() + | |
250 from_space()->capacity_in_bytes()), "Committed size is inconsistent"); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
251 assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(), |
0 | 252 "Space invariant"); |
253 char* eden_top = (char*)eden_space()->top(); | |
254 char* from_top = (char*)from_space()->top(); | |
255 char* to_top = (char*)to_space()->top(); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
256 assert(eden_top <= virtual_space()->high(), "eden top"); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
257 assert(from_top <= virtual_space()->high(), "from top"); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
258 assert(to_top <= virtual_space()->high(), "to top"); |
0 | 259 |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
260 virtual_space()->verify(); |
0 | 261 } |
262 #endif | |
263 | |
264 void PSYoungGen::resize(size_t eden_size, size_t survivor_size) { | |
265 // Resize the generation if needed. If the generation resize | |
266 // reports false, do not attempt to resize the spaces. | |
267 if (resize_generation(eden_size, survivor_size)) { | |
268 // Then we lay out the spaces inside the generation | |
269 resize_spaces(eden_size, survivor_size); | |
270 | |
271 space_invariants(); | |
272 | |
273 if (PrintAdaptiveSizePolicy && Verbose) { | |
274 gclog_or_tty->print_cr("Young generation size: " | |
275 "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT | |
276 " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT | |
277 " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT, | |
278 eden_size, survivor_size, used_in_bytes(), capacity_in_bytes(), | |
279 _max_gen_size, min_gen_size()); | |
280 } | |
281 } | |
282 } | |
283 | |
284 | |
285 bool PSYoungGen::resize_generation(size_t eden_size, size_t survivor_size) { | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
286 const size_t alignment = virtual_space()->alignment(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
287 size_t orig_size = virtual_space()->committed_size(); |
0 | 288 bool size_changed = false; |
289 | |
290 // There used to be this guarantee there. | |
291 // guarantee ((eden_size + 2*survivor_size) <= _max_gen_size, "incorrect input arguments"); | |
292 // Code below forces this requirement. In addition the desired eden | |
293 // size and disired survivor sizes are desired goals and may | |
294 // exceed the total generation size. | |
295 | |
296 assert(min_gen_size() <= orig_size && orig_size <= max_size(), "just checking"); | |
297 | |
298 // Adjust new generation size | |
299 const size_t eden_plus_survivors = | |
300 align_size_up(eden_size + 2 * survivor_size, alignment); | |
301 size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_size()), | |
302 min_gen_size()); | |
303 assert(desired_size <= max_size(), "just checking"); | |
304 | |
305 if (desired_size > orig_size) { | |
306 // Grow the generation | |
307 size_t change = desired_size - orig_size; | |
308 assert(change % alignment == 0, "just checking"); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
309 HeapWord* prev_high = (HeapWord*) virtual_space()->high(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
310 if (!virtual_space()->expand_by(change)) { |
0 | 311 return false; // Error if we fail to resize! |
312 } | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
313 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
314 // Mangle newly committed space immediately because it |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
315 // can be done here more simply that after the new |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
316 // spaces have been computed. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
317 HeapWord* new_high = (HeapWord*) virtual_space()->high(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
318 MemRegion mangle_region(prev_high, new_high); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
319 SpaceMangler::mangle_region(mangle_region); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
320 } |
0 | 321 size_changed = true; |
322 } else if (desired_size < orig_size) { | |
323 size_t desired_change = orig_size - desired_size; | |
324 assert(desired_change % alignment == 0, "just checking"); | |
325 | |
326 desired_change = limit_gen_shrink(desired_change); | |
327 | |
328 if (desired_change > 0) { | |
329 virtual_space()->shrink_by(desired_change); | |
330 reset_survivors_after_shrink(); | |
331 | |
332 size_changed = true; | |
333 } | |
334 } else { | |
335 if (Verbose && PrintGC) { | |
336 if (orig_size == gen_size_limit()) { | |
337 gclog_or_tty->print_cr("PSYoung generation size at maximum: " | |
338 SIZE_FORMAT "K", orig_size/K); | |
339 } else if (orig_size == min_gen_size()) { | |
340 gclog_or_tty->print_cr("PSYoung generation size at minium: " | |
341 SIZE_FORMAT "K", orig_size/K); | |
342 } | |
343 } | |
344 } | |
345 | |
346 if (size_changed) { | |
347 post_resize(); | |
348 | |
349 if (Verbose && PrintGC) { | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
350 size_t current_size = virtual_space()->committed_size(); |
0 | 351 gclog_or_tty->print_cr("PSYoung generation size changed: " |
352 SIZE_FORMAT "K->" SIZE_FORMAT "K", | |
353 orig_size/K, current_size/K); | |
354 } | |
355 } | |
356 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
357 guarantee(eden_plus_survivors <= virtual_space()->committed_size() || |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
358 virtual_space()->committed_size() == max_size(), "Sanity"); |
0 | 359 |
360 return true; | |
361 } | |
362 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
363 #ifndef PRODUCT |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
364 // In the numa case eden is not mangled so a survivor space |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
365 // moving into a region previously occupied by a survivor |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
366 // may find an unmangled region. Also in the PS case eden |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
367 // to-space and from-space may not touch (i.e., there may be |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
368 // gaps between them due to movement while resizing the |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
369 // spaces). Those gaps must be mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
370 void PSYoungGen::mangle_survivors(MutableSpace* s1, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
371 MemRegion s1MR, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
372 MutableSpace* s2, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
373 MemRegion s2MR) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
374 // Check eden and gap between eden and from-space, in deciding |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
375 // what to mangle in from-space. Check the gap between from-space |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
376 // and to-space when deciding what to mangle. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
377 // |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
378 // +--------+ +----+ +---+ |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
379 // | eden | |s1 | |s2 | |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
380 // +--------+ +----+ +---+ |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
381 // +-------+ +-----+ |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
382 // |s1MR | |s2MR | |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
383 // +-------+ +-----+ |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
384 // All of survivor-space is properly mangled so find the |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
385 // upper bound on the mangling for any portion above current s1. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
386 HeapWord* delta_end = MIN2(s1->bottom(), s1MR.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
387 MemRegion delta1_left; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
388 if (s1MR.start() < delta_end) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
389 delta1_left = MemRegion(s1MR.start(), delta_end); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
390 s1->mangle_region(delta1_left); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
391 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
392 // Find any portion to the right of the current s1. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
393 HeapWord* delta_start = MAX2(s1->end(), s1MR.start()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
394 MemRegion delta1_right; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
395 if (delta_start < s1MR.end()) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
396 delta1_right = MemRegion(delta_start, s1MR.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
397 s1->mangle_region(delta1_right); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
398 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
399 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
400 // Similarly for the second survivor space except that |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
401 // any of the new region that overlaps with the current |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
402 // region of the first survivor space has already been |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
403 // mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
404 delta_end = MIN2(s2->bottom(), s2MR.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
405 delta_start = MAX2(s2MR.start(), s1->end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
406 MemRegion delta2_left; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
407 if (s2MR.start() < delta_end) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
408 delta2_left = MemRegion(s2MR.start(), delta_end); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
409 s2->mangle_region(delta2_left); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
410 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
411 delta_start = MAX2(s2->end(), s2MR.start()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
412 MemRegion delta2_right; |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
413 if (delta_start < s2MR.end()) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
414 s2->mangle_region(delta2_right); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
415 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
416 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
417 if (TraceZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
418 // s1 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
419 gclog_or_tty->print_cr("Current region: [" PTR_FORMAT ", " PTR_FORMAT ") " |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
420 "New region: [" PTR_FORMAT ", " PTR_FORMAT ")", |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
421 s1->bottom(), s1->end(), s1MR.start(), s1MR.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
422 gclog_or_tty->print_cr(" Mangle before: [" PTR_FORMAT ", " |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
423 PTR_FORMAT ") Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")", |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
424 delta1_left.start(), delta1_left.end(), delta1_right.start(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
425 delta1_right.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
426 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
427 // s2 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
428 gclog_or_tty->print_cr("Current region: [" PTR_FORMAT ", " PTR_FORMAT ") " |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
429 "New region: [" PTR_FORMAT ", " PTR_FORMAT ")", |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
430 s2->bottom(), s2->end(), s2MR.start(), s2MR.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
431 gclog_or_tty->print_cr(" Mangle before: [" PTR_FORMAT ", " |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
432 PTR_FORMAT ") Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")", |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
433 delta2_left.start(), delta2_left.end(), delta2_right.start(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
434 delta2_right.end()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
435 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
436 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
437 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
438 #endif // NOT PRODUCT |
0 | 439 |
440 void PSYoungGen::resize_spaces(size_t requested_eden_size, | |
441 size_t requested_survivor_size) { | |
442 assert(UseAdaptiveSizePolicy, "sanity check"); | |
443 assert(requested_eden_size > 0 && requested_survivor_size > 0, | |
444 "just checking"); | |
445 | |
446 // We require eden and to space to be empty | |
447 if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) { | |
448 return; | |
449 } | |
450 | |
451 if (PrintAdaptiveSizePolicy && Verbose) { | |
452 gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: " | |
453 SIZE_FORMAT | |
454 ", requested_survivor_size: " SIZE_FORMAT ")", | |
455 requested_eden_size, requested_survivor_size); | |
456 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") " | |
457 SIZE_FORMAT, | |
458 eden_space()->bottom(), | |
459 eden_space()->end(), | |
460 pointer_delta(eden_space()->end(), | |
461 eden_space()->bottom(), | |
462 sizeof(char))); | |
463 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") " | |
464 SIZE_FORMAT, | |
465 from_space()->bottom(), | |
466 from_space()->end(), | |
467 pointer_delta(from_space()->end(), | |
468 from_space()->bottom(), | |
469 sizeof(char))); | |
470 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") " | |
471 SIZE_FORMAT, | |
472 to_space()->bottom(), | |
473 to_space()->end(), | |
474 pointer_delta( to_space()->end(), | |
475 to_space()->bottom(), | |
476 sizeof(char))); | |
477 } | |
478 | |
479 // There's nothing to do if the new sizes are the same as the current | |
480 if (requested_survivor_size == to_space()->capacity_in_bytes() && | |
481 requested_survivor_size == from_space()->capacity_in_bytes() && | |
482 requested_eden_size == eden_space()->capacity_in_bytes()) { | |
483 if (PrintAdaptiveSizePolicy && Verbose) { | |
484 gclog_or_tty->print_cr(" capacities are the right sizes, returning"); | |
485 } | |
486 return; | |
487 } | |
488 | |
489 char* eden_start = (char*)eden_space()->bottom(); | |
490 char* eden_end = (char*)eden_space()->end(); | |
491 char* from_start = (char*)from_space()->bottom(); | |
492 char* from_end = (char*)from_space()->end(); | |
493 char* to_start = (char*)to_space()->bottom(); | |
494 char* to_end = (char*)to_space()->end(); | |
495 | |
496 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
13060
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
497 const size_t alignment = heap->space_alignment(); |
0 | 498 const bool maintain_minimum = |
499 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size(); | |
500 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
501 bool eden_from_to_order = from_start < to_start; |
0 | 502 // Check whether from space is below to space |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
503 if (eden_from_to_order) { |
0 | 504 // Eden, from, to |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
505 eden_from_to_order = true; |
0 | 506 if (PrintAdaptiveSizePolicy && Verbose) { |
507 gclog_or_tty->print_cr(" Eden, from, to:"); | |
508 } | |
509 | |
510 // Set eden | |
511 // "requested_eden_size" is a goal for the size of eden | |
512 // and may not be attainable. "eden_size" below is | |
513 // calculated based on the location of from-space and | |
514 // the goal for the size of eden. from-space is | |
515 // fixed in place because it contains live data. | |
516 // The calculation is done this way to avoid 32bit | |
517 // overflow (i.e., eden_start + requested_eden_size | |
518 // may too large for representation in 32bits). | |
519 size_t eden_size; | |
520 if (maintain_minimum) { | |
521 // Only make eden larger than the requested size if | |
522 // the minimum size of the generation has to be maintained. | |
523 // This could be done in general but policy at a higher | |
524 // level is determining a requested size for eden and that | |
525 // should be honored unless there is a fundamental reason. | |
526 eden_size = pointer_delta(from_start, | |
527 eden_start, | |
528 sizeof(char)); | |
529 } else { | |
530 eden_size = MIN2(requested_eden_size, | |
531 pointer_delta(from_start, eden_start, sizeof(char))); | |
532 } | |
533 | |
534 eden_end = eden_start + eden_size; | |
1489
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
579
diff
changeset
|
535 assert(eden_end >= eden_start, "addition overflowed"); |
0 | 536 |
537 // To may resize into from space as long as it is clear of live data. | |
538 // From space must remain page aligned, though, so we need to do some | |
539 // extra calculations. | |
540 | |
541 // First calculate an optimal to-space | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
542 to_end = (char*)virtual_space()->high(); |
0 | 543 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size, |
544 sizeof(char)); | |
545 | |
546 // Does the optimal to-space overlap from-space? | |
547 if (to_start < (char*)from_space()->end()) { | |
548 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
549 | |
550 // Calculate the minimum offset possible for from_end | |
551 size_t from_size = pointer_delta(from_space()->top(), from_start, sizeof(char)); | |
552 | |
553 // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME! | |
554 if (from_size == 0) { | |
555 from_size = alignment; | |
556 } else { | |
557 from_size = align_size_up(from_size, alignment); | |
558 } | |
559 | |
560 from_end = from_start + from_size; | |
561 assert(from_end > from_start, "addition overflow or from_size problem"); | |
562 | |
563 guarantee(from_end <= (char*)from_space()->end(), "from_end moved to the right"); | |
564 | |
565 // Now update to_start with the new from_end | |
566 to_start = MAX2(from_end, to_start); | |
567 } | |
568 | |
569 guarantee(to_start != to_end, "to space is zero sized"); | |
570 | |
571 if (PrintAdaptiveSizePolicy && Verbose) { | |
572 gclog_or_tty->print_cr(" [eden_start .. eden_end): " | |
573 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, | |
574 eden_start, | |
575 eden_end, | |
576 pointer_delta(eden_end, eden_start, sizeof(char))); | |
577 gclog_or_tty->print_cr(" [from_start .. from_end): " | |
578 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, | |
579 from_start, | |
580 from_end, | |
581 pointer_delta(from_end, from_start, sizeof(char))); | |
582 gclog_or_tty->print_cr(" [ to_start .. to_end): " | |
583 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, | |
584 to_start, | |
585 to_end, | |
586 pointer_delta( to_end, to_start, sizeof(char))); | |
587 } | |
588 } else { | |
589 // Eden, to, from | |
590 if (PrintAdaptiveSizePolicy && Verbose) { | |
591 gclog_or_tty->print_cr(" Eden, to, from:"); | |
592 } | |
593 | |
594 // To space gets priority over eden resizing. Note that we position | |
595 // to space as if we were able to resize from space, even though from | |
596 // space is not modified. | |
597 // Giving eden priority was tried and gave poorer performance. | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
598 to_end = (char*)pointer_delta(virtual_space()->high(), |
0 | 599 (char*)requested_survivor_size, |
600 sizeof(char)); | |
601 to_end = MIN2(to_end, from_start); | |
602 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size, | |
603 sizeof(char)); | |
604 // if the space sizes are to be increased by several times then | |
605 // 'to_start' will point beyond the young generation. In this case | |
606 // 'to_start' should be adjusted. | |
607 to_start = MAX2(to_start, eden_start + alignment); | |
608 | |
609 // Compute how big eden can be, then adjust end. | |
610 // See comments above on calculating eden_end. | |
611 size_t eden_size; | |
612 if (maintain_minimum) { | |
613 eden_size = pointer_delta(to_start, eden_start, sizeof(char)); | |
614 } else { | |
615 eden_size = MIN2(requested_eden_size, | |
616 pointer_delta(to_start, eden_start, sizeof(char))); | |
617 } | |
618 eden_end = eden_start + eden_size; | |
1489
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
579
diff
changeset
|
619 assert(eden_end >= eden_start, "addition overflowed"); |
0 | 620 |
621 // Could choose to not let eden shrink | |
622 // to_start = MAX2(to_start, eden_end); | |
623 | |
624 // Don't let eden shrink down to 0 or less. | |
625 eden_end = MAX2(eden_end, eden_start + alignment); | |
626 to_start = MAX2(to_start, eden_end); | |
627 | |
628 if (PrintAdaptiveSizePolicy && Verbose) { | |
629 gclog_or_tty->print_cr(" [eden_start .. eden_end): " | |
630 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, | |
631 eden_start, | |
632 eden_end, | |
633 pointer_delta(eden_end, eden_start, sizeof(char))); | |
634 gclog_or_tty->print_cr(" [ to_start .. to_end): " | |
635 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, | |
636 to_start, | |
637 to_end, | |
638 pointer_delta( to_end, to_start, sizeof(char))); | |
639 gclog_or_tty->print_cr(" [from_start .. from_end): " | |
640 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT, | |
641 from_start, | |
642 from_end, | |
643 pointer_delta(from_end, from_start, sizeof(char))); | |
644 } | |
645 } | |
646 | |
647 | |
648 guarantee((HeapWord*)from_start <= from_space()->bottom(), | |
649 "from start moved to the right"); | |
650 guarantee((HeapWord*)from_end >= from_space()->top(), | |
651 "from end moved into live data"); | |
652 assert(is_object_aligned((intptr_t)eden_start), "checking alignment"); | |
653 assert(is_object_aligned((intptr_t)from_start), "checking alignment"); | |
654 assert(is_object_aligned((intptr_t)to_start), "checking alignment"); | |
655 | |
656 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end); | |
657 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end); | |
658 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end); | |
659 | |
660 // Let's make sure the call to initialize doesn't reset "top"! | |
661 HeapWord* old_from_top = from_space()->top(); | |
662 | |
663 // For PrintAdaptiveSizePolicy block below | |
664 size_t old_from = from_space()->capacity_in_bytes(); | |
665 size_t old_to = to_space()->capacity_in_bytes(); | |
666 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
667 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
668 // NUMA is a special case because a numa space is not mangled |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
669 // in order to not prematurely bind its address to memory to |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
670 // the wrong memory (i.e., don't want the GC thread to first |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
671 // touch the memory). The survivor spaces are not numa |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
672 // spaces and are mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
673 if (UseNUMA) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
674 if (eden_from_to_order) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
675 mangle_survivors(from_space(), fromMR, to_space(), toMR); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
676 } else { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
677 mangle_survivors(to_space(), toMR, from_space(), fromMR); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
678 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
679 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
680 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
681 // If not mangling the spaces, do some checking to verify that |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
682 // the spaces are already mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
683 // The spaces should be correctly mangled at this point so |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
684 // do some checking here. Note that they are not being mangled |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
685 // in the calls to initialize(). |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
686 // Must check mangling before the spaces are reshaped. Otherwise, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
687 // the bottom or end of one space may have moved into an area |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
688 // covered by another space and a failure of the check may |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
689 // not correctly indicate which space is not properly mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
690 HeapWord* limit = (HeapWord*) virtual_space()->high(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
691 eden_space()->check_mangled_unused_area(limit); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
692 from_space()->check_mangled_unused_area(limit); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
693 to_space()->check_mangled_unused_area(limit); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
694 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
695 // When an existing space is being initialized, it is not |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
696 // mangled because the space has been previously mangled. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
697 eden_space()->initialize(edenMR, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
698 SpaceDecorator::Clear, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
699 SpaceDecorator::DontMangle); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
700 to_space()->initialize(toMR, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
701 SpaceDecorator::Clear, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
702 SpaceDecorator::DontMangle); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
703 from_space()->initialize(fromMR, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
704 SpaceDecorator::DontClear, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
705 SpaceDecorator::DontMangle); |
0 | 706 |
707 assert(from_space()->top() == old_from_top, "from top changed!"); | |
708 | |
709 if (PrintAdaptiveSizePolicy) { | |
710 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
711 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
712 | |
713 gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: " | |
714 "collection: %d " | |
715 "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> " | |
716 "(" SIZE_FORMAT ", " SIZE_FORMAT ") ", | |
717 heap->total_collections(), | |
718 old_from, old_to, | |
719 from_space()->capacity_in_bytes(), | |
720 to_space()->capacity_in_bytes()); | |
721 gclog_or_tty->cr(); | |
722 } | |
723 } | |
724 | |
725 void PSYoungGen::swap_spaces() { | |
726 MutableSpace* s = from_space(); | |
727 _from_space = to_space(); | |
728 _to_space = s; | |
729 | |
730 // Now update the decorators. | |
731 PSMarkSweepDecorator* md = from_mark_sweep(); | |
732 _from_mark_sweep = to_mark_sweep(); | |
733 _to_mark_sweep = md; | |
734 | |
735 assert(from_mark_sweep()->space() == from_space(), "Sanity"); | |
736 assert(to_mark_sweep()->space() == to_space(), "Sanity"); | |
737 } | |
738 | |
739 size_t PSYoungGen::capacity_in_bytes() const { | |
740 return eden_space()->capacity_in_bytes() | |
741 + from_space()->capacity_in_bytes(); // to_space() is only used during scavenge | |
742 } | |
743 | |
744 | |
745 size_t PSYoungGen::used_in_bytes() const { | |
746 return eden_space()->used_in_bytes() | |
747 + from_space()->used_in_bytes(); // to_space() is only used during scavenge | |
748 } | |
749 | |
750 | |
751 size_t PSYoungGen::free_in_bytes() const { | |
752 return eden_space()->free_in_bytes() | |
753 + from_space()->free_in_bytes(); // to_space() is only used during scavenge | |
754 } | |
755 | |
756 size_t PSYoungGen::capacity_in_words() const { | |
757 return eden_space()->capacity_in_words() | |
758 + from_space()->capacity_in_words(); // to_space() is only used during scavenge | |
759 } | |
760 | |
761 | |
762 size_t PSYoungGen::used_in_words() const { | |
763 return eden_space()->used_in_words() | |
764 + from_space()->used_in_words(); // to_space() is only used during scavenge | |
765 } | |
766 | |
767 | |
768 size_t PSYoungGen::free_in_words() const { | |
769 return eden_space()->free_in_words() | |
770 + from_space()->free_in_words(); // to_space() is only used during scavenge | |
771 } | |
772 | |
773 void PSYoungGen::object_iterate(ObjectClosure* blk) { | |
774 eden_space()->object_iterate(blk); | |
775 from_space()->object_iterate(blk); | |
776 to_space()->object_iterate(blk); | |
777 } | |
778 | |
779 void PSYoungGen::precompact() { | |
780 eden_mark_sweep()->precompact(); | |
781 from_mark_sweep()->precompact(); | |
782 to_mark_sweep()->precompact(); | |
783 } | |
784 | |
785 void PSYoungGen::adjust_pointers() { | |
786 eden_mark_sweep()->adjust_pointers(); | |
787 from_mark_sweep()->adjust_pointers(); | |
788 to_mark_sweep()->adjust_pointers(); | |
789 } | |
790 | |
791 void PSYoungGen::compact() { | |
792 eden_mark_sweep()->compact(ZapUnusedHeapArea); | |
793 from_mark_sweep()->compact(ZapUnusedHeapArea); | |
794 // Mark sweep stores preserved markOops in to space, don't disturb! | |
795 to_mark_sweep()->compact(false); | |
796 } | |
797 | |
798 void PSYoungGen::print() const { print_on(tty); } | |
799 void PSYoungGen::print_on(outputStream* st) const { | |
800 st->print(" %-15s", "PSYoungGen"); | |
801 if (PrintGCDetails && Verbose) { | |
802 st->print(" total " SIZE_FORMAT ", used " SIZE_FORMAT, | |
803 capacity_in_bytes(), used_in_bytes()); | |
804 } else { | |
805 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", | |
806 capacity_in_bytes()/K, used_in_bytes()/K); | |
807 } | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
808 virtual_space()->print_space_boundaries_on(st); |
0 | 809 st->print(" eden"); eden_space()->print_on(st); |
810 st->print(" from"); from_space()->print_on(st); | |
811 st->print(" to "); to_space()->print_on(st); | |
812 } | |
813 | |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6008
diff
changeset
|
814 // Note that a space is not printed before the [NAME: |
0 | 815 void PSYoungGen::print_used_change(size_t prev_used) const { |
7455
0b54ffe4c2d3
8005672: Clean up some changes to GC logging with GCCause's
jmasa
parents:
6008
diff
changeset
|
816 gclog_or_tty->print("[%s:", name()); |
0 | 817 gclog_or_tty->print(" " SIZE_FORMAT "K" |
818 "->" SIZE_FORMAT "K" | |
819 "(" SIZE_FORMAT "K)", | |
820 prev_used / K, used_in_bytes() / K, | |
821 capacity_in_bytes() / K); | |
822 gclog_or_tty->print("]"); | |
823 } | |
824 | |
825 size_t PSYoungGen::available_for_expansion() { | |
826 ShouldNotReachHere(); | |
827 return 0; | |
828 } | |
829 | |
830 size_t PSYoungGen::available_for_contraction() { | |
831 ShouldNotReachHere(); | |
832 return 0; | |
833 } | |
834 | |
835 size_t PSYoungGen::available_to_min_gen() { | |
836 assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant"); | |
837 return virtual_space()->committed_size() - min_gen_size(); | |
838 } | |
839 | |
840 // This method assumes that from-space has live data and that | |
841 // any shrinkage of the young gen is limited by location of | |
842 // from-space. | |
843 size_t PSYoungGen::available_to_live() { | |
844 size_t delta_in_survivor = 0; | |
845 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
13060
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
846 const size_t space_alignment = heap->space_alignment(); |
8f07aa079343
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
7455
diff
changeset
|
847 const size_t gen_alignment = heap->generation_alignment(); |
0 | 848 |
849 MutableSpace* space_shrinking = NULL; | |
850 if (from_space()->end() > to_space()->end()) { | |
851 space_shrinking = from_space(); | |
852 } else { | |
853 space_shrinking = to_space(); | |
854 } | |
855 | |
856 // Include any space that is committed but not included in | |
857 // the survivor spaces. | |
858 assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(), | |
859 "Survivor space beyond high end"); | |
860 size_t unused_committed = pointer_delta(virtual_space()->high(), | |
861 space_shrinking->end(), sizeof(char)); | |
862 | |
863 if (space_shrinking->is_empty()) { | |
864 // Don't let the space shrink to 0 | |
865 assert(space_shrinking->capacity_in_bytes() >= space_alignment, | |
866 "Space is too small"); | |
867 delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment; | |
868 } else { | |
869 delta_in_survivor = pointer_delta(space_shrinking->end(), | |
870 space_shrinking->top(), | |
871 sizeof(char)); | |
872 } | |
873 | |
874 size_t delta_in_bytes = unused_committed + delta_in_survivor; | |
875 delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment); | |
876 return delta_in_bytes; | |
877 } | |
878 | |
879 // Return the number of bytes available for resizing down the young | |
880 // generation. This is the minimum of | |
881 // input "bytes" | |
882 // bytes to the minimum young gen size | |
883 // bytes to the size currently being used + some small extra | |
884 size_t PSYoungGen::limit_gen_shrink(size_t bytes) { | |
885 // Allow shrinkage into the current eden but keep eden large enough | |
886 // to maintain the minimum young gen size | |
887 bytes = MIN3(bytes, available_to_min_gen(), available_to_live()); | |
888 return align_size_down(bytes, virtual_space()->alignment()); | |
889 } | |
890 | |
891 void PSYoungGen::reset_after_change() { | |
892 ShouldNotReachHere(); | |
893 } | |
894 | |
895 void PSYoungGen::reset_survivors_after_shrink() { | |
896 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(), | |
897 (HeapWord*)virtual_space()->high_boundary()); | |
898 PSScavenge::reference_processor()->set_span(_reserved); | |
899 | |
900 MutableSpace* space_shrinking = NULL; | |
901 if (from_space()->end() > to_space()->end()) { | |
902 space_shrinking = from_space(); | |
903 } else { | |
904 space_shrinking = to_space(); | |
905 } | |
906 | |
907 HeapWord* new_end = (HeapWord*)virtual_space()->high(); | |
908 assert(new_end >= space_shrinking->bottom(), "Shrink was too large"); | |
909 // Was there a shrink of the survivor space? | |
910 if (new_end < space_shrinking->end()) { | |
911 MemRegion mr(space_shrinking->bottom(), new_end); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
912 space_shrinking->initialize(mr, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
913 SpaceDecorator::DontClear, |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
914 SpaceDecorator::Mangle); |
0 | 915 } |
916 } | |
917 | |
918 // This method currently does not expect to expand into eden (i.e., | |
919 // the virtual space boundaries is expected to be consistent | |
920 // with the eden boundaries.. | |
921 void PSYoungGen::post_resize() { | |
922 assert_locked_or_safepoint(Heap_lock); | |
923 assert((eden_space()->bottom() < to_space()->bottom()) && | |
924 (eden_space()->bottom() < from_space()->bottom()), | |
925 "Eden is assumed to be below the survivor spaces"); | |
926 | |
927 MemRegion cmr((HeapWord*)virtual_space()->low(), | |
928 (HeapWord*)virtual_space()->high()); | |
929 Universe::heap()->barrier_set()->resize_covered_region(cmr); | |
930 space_invariants(); | |
931 } | |
932 | |
933 | |
934 | |
935 void PSYoungGen::update_counters() { | |
936 if (UsePerfData) { | |
937 _eden_counters->update_all(); | |
938 _from_counters->update_all(); | |
939 _to_counters->update_all(); | |
940 _gen_counters->update_all(); | |
941 } | |
942 } | |
943 | |
6008 | 944 void PSYoungGen::verify() { |
945 eden_space()->verify(); | |
946 from_space()->verify(); | |
947 to_space()->verify(); | |
0 | 948 } |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
949 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
950 #ifndef PRODUCT |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
951 void PSYoungGen::record_spaces_top() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
952 assert(ZapUnusedHeapArea, "Not mangling unused space"); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
953 eden_space()->set_top_for_allocations(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
954 from_space()->set_top_for_allocations(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
955 to_space()->set_top_for_allocations(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
956 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
13
diff
changeset
|
957 #endif |