annotate src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp @ 17524:89152779163c

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