annotate src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents 183f41cf8bfe
children 850fdf70db2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 13
diff changeset
2 * Copyright 2001-2008 Sun Microsystems, Inc. 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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_psYoungGen.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 PSYoungGen::PSYoungGen(size_t initial_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
29 size_t min_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
30 size_t max_size) :
a61af66fc99e Initial load
duke
parents:
diff changeset
31 _init_gen_size(initial_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
32 _min_gen_size(min_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
33 _max_gen_size(max_size)
a61af66fc99e Initial load
duke
parents:
diff changeset
34 {}
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 void PSYoungGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 assert(_init_gen_size != 0, "Should have a finite size");
a61af66fc99e Initial load
duke
parents:
diff changeset
38 _virtual_space = new PSVirtualSpace(rs, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (!_virtual_space->expand_by(_init_gen_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 vm_exit_during_initialization("Could not reserve enough space for "
a61af66fc99e Initial load
duke
parents:
diff changeset
41 "object heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 void PSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 initialize_virtual_space(rs, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 initialize_work();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 void PSYoungGen::initialize_work() {
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _reserved = MemRegion((HeapWord*)_virtual_space->low_boundary(),
a61af66fc99e Initial load
duke
parents:
diff changeset
53 (HeapWord*)_virtual_space->high_boundary());
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 MemRegion cmr((HeapWord*)_virtual_space->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
56 (HeapWord*)_virtual_space->high());
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Universe::heap()->barrier_set()->resize_covered_region(cmr);
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (UseNUMA) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _eden_space = new MutableNUMASpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _eden_space = new MutableSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _from_space = new MutableSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _to_space = new MutableSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (_eden_space == NULL || _from_space == NULL || _to_space == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 vm_exit_during_initialization("Could not allocate a young gen space");
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // Allocate the mark sweep views of spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _eden_mark_sweep =
a61af66fc99e Initial load
duke
parents:
diff changeset
73 new PSMarkSweepDecorator(_eden_space, NULL, MarkSweepDeadRatio);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _from_mark_sweep =
a61af66fc99e Initial load
duke
parents:
diff changeset
75 new PSMarkSweepDecorator(_from_space, NULL, MarkSweepDeadRatio);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _to_mark_sweep =
a61af66fc99e Initial load
duke
parents:
diff changeset
77 new PSMarkSweepDecorator(_to_space, NULL, MarkSweepDeadRatio);
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (_eden_mark_sweep == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _from_mark_sweep == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _to_mark_sweep == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 vm_exit_during_initialization("Could not complete allocation"
a61af66fc99e Initial load
duke
parents:
diff changeset
83 " of the young generation");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Generation Counters - generation 0, 3 subspaces
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _gen_counters = new PSGenerationCounters("new", 0, 3, _virtual_space);
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Compute maximum space sizes for performance counters
a61af66fc99e Initial load
duke
parents:
diff changeset
90 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
13
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
91 size_t alignment = heap->intra_heap_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92 size_t size = _virtual_space->reserved_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 size_t max_survivor_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 size_t max_eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (UseAdaptiveSizePolicy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 max_survivor_size = size / MinSurvivorRatio;
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // round the survivor space size down to the nearest alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // and make sure its size is greater than 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 max_survivor_size = align_size_down(max_survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 max_survivor_size = MAX2(max_survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // set the maximum size of eden to be the size of the young gen
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // less two times the minimum survivor size. The minimum survivor
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // size for UseAdaptiveSizePolicy is one alignment.
a61af66fc99e Initial load
duke
parents:
diff changeset
108 max_eden_size = size - 2 * alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 max_survivor_size = size / InitialSurvivorRatio;
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // round the survivor space size down to the nearest alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // and make sure its size is greater than 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 max_survivor_size = align_size_down(max_survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 max_survivor_size = MAX2(max_survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // set the maximum size of eden to be the size of the young gen
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // less two times the survivor size when the generation is 100%
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // committed. The minimum survivor size for -UseAdaptiveSizePolicy
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // is dependent on the committed portion (current capacity) of the
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // generation - the less space committed, the smaller the survivor
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // space, possibly as small as an alignment. However, we are interested
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // in the case where the young generation is 100% committed, as this
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // is the point where eden reachs its maximum size. At this point,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // the size of a survivor space is max_survivor_size.
a61af66fc99e Initial load
duke
parents:
diff changeset
126 max_eden_size = size - 2 * max_survivor_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
130 _gen_counters);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _gen_counters);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _gen_counters);
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 compute_initial_space_boundaries();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void PSYoungGen::compute_initial_space_boundaries() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Compute sizes
13
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
144 size_t alignment = heap->intra_heap_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
145 size_t size = _virtual_space->committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 size_t survivor_size = size / InitialSurvivorRatio;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 survivor_size = align_size_down(survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // ... but never less than an alignment
a61af66fc99e Initial load
duke
parents:
diff changeset
150 survivor_size = MAX2(survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Young generation is eden + 2 survivor spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
153 size_t eden_size = size - (2 * survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Now go ahead and set 'em.
a61af66fc99e Initial load
duke
parents:
diff changeset
156 set_space_boundaries(eden_size, survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 space_invariants();
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (UsePerfData) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 _eden_counters->update_capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 _from_counters->update_capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 _to_counters->update_capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 assert(eden_size < _virtual_space->committed_size(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 assert(eden_size > 0 && survivor_size > 0, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Initial layout is Eden, to, from. After swapping survivor spaces,
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // that leaves us with Eden, from, to, which is step one in our two
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // step resize-with-live-data procedure.
a61af66fc99e Initial load
duke
parents:
diff changeset
173 char *eden_start = _virtual_space->low();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 char *to_start = eden_start + eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 char *from_start = to_start + survivor_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 char *from_end = from_start + survivor_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(from_end == _virtual_space->high(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 assert(is_object_aligned((intptr_t)to_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 assert(is_object_aligned((intptr_t)from_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 MemRegion eden_mr((HeapWord*)eden_start, (HeapWord*)to_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 MemRegion to_mr ((HeapWord*)to_start, (HeapWord*)from_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 MemRegion from_mr((HeapWord*)from_start, (HeapWord*)from_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 eden_space()->initialize(eden_mr, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 to_space()->initialize(to_mr , true);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 from_space()->initialize(from_mr, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
193 void PSYoungGen::space_invariants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
13
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
195 const size_t alignment = heap->intra_heap_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Currently, our eden size cannot shrink to zero
a61af66fc99e Initial load
duke
parents:
diff changeset
198 guarantee(eden_space()->capacity_in_bytes() >= alignment, "eden too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 guarantee(from_space()->capacity_in_bytes() >= alignment, "from too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
200 guarantee(to_space()->capacity_in_bytes() >= alignment, "to too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // Relationship of spaces to each other
a61af66fc99e Initial load
duke
parents:
diff changeset
203 char* eden_start = (char*)eden_space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 char* eden_end = (char*)eden_space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 char* from_start = (char*)from_space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 char* from_end = (char*)from_space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 char* to_start = (char*)to_space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 char* to_end = (char*)to_space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 guarantee(eden_start >= _virtual_space->low(), "eden bottom");
a61af66fc99e Initial load
duke
parents:
diff changeset
211 guarantee(eden_start < eden_end, "eden space consistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
212 guarantee(from_start < from_end, "from space consistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
213 guarantee(to_start < to_end, "to space consistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Check whether from space is below to space
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (from_start < to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Eden, from, to
a61af66fc99e Initial load
duke
parents:
diff changeset
218 guarantee(eden_end <= from_start, "eden/from boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 guarantee(from_end <= to_start, "from/to boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
220 guarantee(to_end <= _virtual_space->high(), "to end");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // Eden, to, from
a61af66fc99e Initial load
duke
parents:
diff changeset
223 guarantee(eden_end <= to_start, "eden/to boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
224 guarantee(to_end <= from_start, "to/from boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 guarantee(from_end <= _virtual_space->high(), "from end");
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // More checks that the virtual space is consistent with the spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
229 assert(_virtual_space->committed_size() >=
a61af66fc99e Initial load
duke
parents:
diff changeset
230 (eden_space()->capacity_in_bytes() +
a61af66fc99e Initial load
duke
parents:
diff changeset
231 to_space()->capacity_in_bytes() +
a61af66fc99e Initial load
duke
parents:
diff changeset
232 from_space()->capacity_in_bytes()), "Committed size is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
233 assert(_virtual_space->committed_size() <= _virtual_space->reserved_size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
234 "Space invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 char* eden_top = (char*)eden_space()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 char* from_top = (char*)from_space()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
237 char* to_top = (char*)to_space()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
238 assert(eden_top <= _virtual_space->high(), "eden top");
a61af66fc99e Initial load
duke
parents:
diff changeset
239 assert(from_top <= _virtual_space->high(), "from top");
a61af66fc99e Initial load
duke
parents:
diff changeset
240 assert(to_top <= _virtual_space->high(), "to top");
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 _virtual_space->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 void PSYoungGen::resize(size_t eden_size, size_t survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // Resize the generation if needed. If the generation resize
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // reports false, do not attempt to resize the spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (resize_generation(eden_size, survivor_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Then we lay out the spaces inside the generation
a61af66fc99e Initial load
duke
parents:
diff changeset
251 resize_spaces(eden_size, survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 space_invariants();
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 gclog_or_tty->print_cr("Young generation size: "
a61af66fc99e Initial load
duke
parents:
diff changeset
257 "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
258 " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
259 " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
260 eden_size, survivor_size, used_in_bytes(), capacity_in_bytes(),
a61af66fc99e Initial load
duke
parents:
diff changeset
261 _max_gen_size, min_gen_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 bool PSYoungGen::resize_generation(size_t eden_size, size_t survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 const size_t alignment = _virtual_space->alignment();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 size_t orig_size = _virtual_space->committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 bool size_changed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // There used to be this guarantee there.
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // guarantee ((eden_size + 2*survivor_size) <= _max_gen_size, "incorrect input arguments");
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Code below forces this requirement. In addition the desired eden
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // size and disired survivor sizes are desired goals and may
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // exceed the total generation size.
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 assert(min_gen_size() <= orig_size && orig_size <= max_size(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Adjust new generation size
a61af66fc99e Initial load
duke
parents:
diff changeset
281 const size_t eden_plus_survivors =
a61af66fc99e Initial load
duke
parents:
diff changeset
282 align_size_up(eden_size + 2 * survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_size()),
a61af66fc99e Initial load
duke
parents:
diff changeset
284 min_gen_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
285 assert(desired_size <= max_size(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (desired_size > orig_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // Grow the generation
a61af66fc99e Initial load
duke
parents:
diff changeset
289 size_t change = desired_size - orig_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 assert(change % alignment == 0, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (!_virtual_space->expand_by(change)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 return false; // Error if we fail to resize!
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 size_changed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 } else if (desired_size < orig_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 size_t desired_change = orig_size - desired_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
298 assert(desired_change % alignment == 0, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 desired_change = limit_gen_shrink(desired_change);
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 if (desired_change > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 virtual_space()->shrink_by(desired_change);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 reset_survivors_after_shrink();
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 size_changed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (Verbose && PrintGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (orig_size == gen_size_limit()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 gclog_or_tty->print_cr("PSYoung generation size at maximum: "
a61af66fc99e Initial load
duke
parents:
diff changeset
312 SIZE_FORMAT "K", orig_size/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
313 } else if (orig_size == min_gen_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 gclog_or_tty->print_cr("PSYoung generation size at minium: "
a61af66fc99e Initial load
duke
parents:
diff changeset
315 SIZE_FORMAT "K", orig_size/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (size_changed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 post_resize();
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (Verbose && PrintGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 size_t current_size = _virtual_space->committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
325 gclog_or_tty->print_cr("PSYoung generation size changed: "
a61af66fc99e Initial load
duke
parents:
diff changeset
326 SIZE_FORMAT "K->" SIZE_FORMAT "K",
a61af66fc99e Initial load
duke
parents:
diff changeset
327 orig_size/K, current_size/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 guarantee(eden_plus_survivors <= _virtual_space->committed_size() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
332 _virtual_space->committed_size() == max_size(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 void PSYoungGen::resize_spaces(size_t requested_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
339 size_t requested_survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 assert(UseAdaptiveSizePolicy, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
341 assert(requested_eden_size > 0 && requested_survivor_size > 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
342 "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // We require eden and to space to be empty
a61af66fc99e Initial load
duke
parents:
diff changeset
345 if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: "
a61af66fc99e Initial load
duke
parents:
diff changeset
351 SIZE_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
352 ", requested_survivor_size: " SIZE_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
353 requested_eden_size, requested_survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
a61af66fc99e Initial load
duke
parents:
diff changeset
355 SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
356 eden_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
357 eden_space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
358 pointer_delta(eden_space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
359 eden_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
360 sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
361 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") "
a61af66fc99e Initial load
duke
parents:
diff changeset
362 SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
363 from_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
364 from_space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
365 pointer_delta(from_space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
366 from_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
367 sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
368 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") "
a61af66fc99e Initial load
duke
parents:
diff changeset
369 SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
370 to_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
371 to_space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
372 pointer_delta( to_space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
373 to_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
374 sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // There's nothing to do if the new sizes are the same as the current
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if (requested_survivor_size == to_space()->capacity_in_bytes() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
379 requested_survivor_size == from_space()->capacity_in_bytes() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
380 requested_eden_size == eden_space()->capacity_in_bytes()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 gclog_or_tty->print_cr(" capacities are the right sizes, returning");
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 char* eden_start = (char*)eden_space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
388 char* eden_end = (char*)eden_space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
389 char* from_start = (char*)from_space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
390 char* from_end = (char*)from_space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
391 char* to_start = (char*)to_space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
392 char* to_end = (char*)to_space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
13
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
395 const size_t alignment = heap->intra_heap_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
396 const bool maintain_minimum =
a61af66fc99e Initial load
duke
parents:
diff changeset
397 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // Check whether from space is below to space
a61af66fc99e Initial load
duke
parents:
diff changeset
400 if (from_start < to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // Eden, from, to
a61af66fc99e Initial load
duke
parents:
diff changeset
402 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
403 gclog_or_tty->print_cr(" Eden, from, to:");
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 // Set eden
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // "requested_eden_size" is a goal for the size of eden
a61af66fc99e Initial load
duke
parents:
diff changeset
408 // and may not be attainable. "eden_size" below is
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // calculated based on the location of from-space and
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // the goal for the size of eden. from-space is
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // fixed in place because it contains live data.
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // The calculation is done this way to avoid 32bit
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // overflow (i.e., eden_start + requested_eden_size
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // may too large for representation in 32bits).
a61af66fc99e Initial load
duke
parents:
diff changeset
415 size_t eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (maintain_minimum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Only make eden larger than the requested size if
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // the minimum size of the generation has to be maintained.
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // This could be done in general but policy at a higher
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // level is determining a requested size for eden and that
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // should be honored unless there is a fundamental reason.
a61af66fc99e Initial load
duke
parents:
diff changeset
422 eden_size = pointer_delta(from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
423 eden_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
424 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
425 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 eden_size = MIN2(requested_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
427 pointer_delta(from_start, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 eden_end = eden_start + eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 assert(eden_end >= eden_start, "addition overflowed")
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 // To may resize into from space as long as it is clear of live data.
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // From space must remain page aligned, though, so we need to do some
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // extra calculations.
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // First calculate an optimal to-space
a61af66fc99e Initial load
duke
parents:
diff changeset
438 to_end = (char*)_virtual_space->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
440 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // Does the optimal to-space overlap from-space?
a61af66fc99e Initial load
duke
parents:
diff changeset
443 if (to_start < (char*)from_space()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // Calculate the minimum offset possible for from_end
a61af66fc99e Initial load
duke
parents:
diff changeset
447 size_t from_size = pointer_delta(from_space()->top(), from_start, sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // 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
450 if (from_size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 from_size = alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
452 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 from_size = align_size_up(from_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 from_end = from_start + from_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 assert(from_end > from_start, "addition overflow or from_size problem");
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 guarantee(from_end <= (char*)from_space()->end(), "from_end moved to the right");
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // Now update to_start with the new from_end
a61af66fc99e Initial load
duke
parents:
diff changeset
462 to_start = MAX2(from_end, to_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 guarantee(to_start != to_end, "to space is zero sized");
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 gclog_or_tty->print_cr(" [eden_start .. eden_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
469 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
470 eden_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
471 eden_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
472 pointer_delta(eden_end, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
473 gclog_or_tty->print_cr(" [from_start .. from_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
474 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
475 from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
476 from_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
477 pointer_delta(from_end, from_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
478 gclog_or_tty->print_cr(" [ to_start .. to_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
479 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
480 to_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
481 to_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
482 pointer_delta( to_end, to_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // Eden, to, from
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 gclog_or_tty->print_cr(" Eden, to, from:");
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // To space gets priority over eden resizing. Note that we position
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // to space as if we were able to resize from space, even though from
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // space is not modified.
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // Giving eden priority was tried and gave poorer performance.
a61af66fc99e Initial load
duke
parents:
diff changeset
494 to_end = (char*)pointer_delta(_virtual_space->high(),
a61af66fc99e Initial load
duke
parents:
diff changeset
495 (char*)requested_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
496 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
497 to_end = MIN2(to_end, from_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
498 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
499 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // if the space sizes are to be increased by several times then
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // 'to_start' will point beyond the young generation. In this case
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // 'to_start' should be adjusted.
a61af66fc99e Initial load
duke
parents:
diff changeset
503 to_start = MAX2(to_start, eden_start + alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // Compute how big eden can be, then adjust end.
a61af66fc99e Initial load
duke
parents:
diff changeset
506 // See comments above on calculating eden_end.
a61af66fc99e Initial load
duke
parents:
diff changeset
507 size_t eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 if (maintain_minimum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 eden_size = pointer_delta(to_start, eden_start, sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
510 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 eden_size = MIN2(requested_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
512 pointer_delta(to_start, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 eden_end = eden_start + eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
515 assert(eden_end >= eden_start, "addition overflowed")
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 // Could choose to not let eden shrink
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // to_start = MAX2(to_start, eden_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 // Don't let eden shrink down to 0 or less.
a61af66fc99e Initial load
duke
parents:
diff changeset
521 eden_end = MAX2(eden_end, eden_start + alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 to_start = MAX2(to_start, eden_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 gclog_or_tty->print_cr(" [eden_start .. eden_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
526 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
527 eden_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
528 eden_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
529 pointer_delta(eden_end, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
530 gclog_or_tty->print_cr(" [ to_start .. to_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
531 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
532 to_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
533 to_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
534 pointer_delta( to_end, to_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
535 gclog_or_tty->print_cr(" [from_start .. from_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
536 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
537 from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
538 from_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
539 pointer_delta(from_end, from_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
542
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 guarantee((HeapWord*)from_start <= from_space()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
545 "from start moved to the right");
a61af66fc99e Initial load
duke
parents:
diff changeset
546 guarantee((HeapWord*)from_end >= from_space()->top(),
a61af66fc99e Initial load
duke
parents:
diff changeset
547 "from end moved into live data");
a61af66fc99e Initial load
duke
parents:
diff changeset
548 assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
549 assert(is_object_aligned((intptr_t)from_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
550 assert(is_object_aligned((intptr_t)to_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Let's make sure the call to initialize doesn't reset "top"!
a61af66fc99e Initial load
duke
parents:
diff changeset
557 HeapWord* old_from_top = from_space()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
558
a61af66fc99e Initial load
duke
parents:
diff changeset
559 // For PrintAdaptiveSizePolicy block below
a61af66fc99e Initial load
duke
parents:
diff changeset
560 size_t old_from = from_space()->capacity_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
561 size_t old_to = to_space()->capacity_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 eden_space()->initialize(edenMR, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
564 to_space()->initialize(toMR , true);
a61af66fc99e Initial load
duke
parents:
diff changeset
565 from_space()->initialize(fromMR, false); // Note, not cleared!
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 assert(from_space()->top() == old_from_top, "from top changed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
568
a61af66fc99e Initial load
duke
parents:
diff changeset
569 if (PrintAdaptiveSizePolicy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
570 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
571 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
572
a61af66fc99e Initial load
duke
parents:
diff changeset
573 gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
a61af66fc99e Initial load
duke
parents:
diff changeset
574 "collection: %d "
a61af66fc99e Initial load
duke
parents:
diff changeset
575 "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
a61af66fc99e Initial load
duke
parents:
diff changeset
576 "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
a61af66fc99e Initial load
duke
parents:
diff changeset
577 heap->total_collections(),
a61af66fc99e Initial load
duke
parents:
diff changeset
578 old_from, old_to,
a61af66fc99e Initial load
duke
parents:
diff changeset
579 from_space()->capacity_in_bytes(),
a61af66fc99e Initial load
duke
parents:
diff changeset
580 to_space()->capacity_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
581 gclog_or_tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 void PSYoungGen::swap_spaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
586 MutableSpace* s = from_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
587 _from_space = to_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 _to_space = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // Now update the decorators.
a61af66fc99e Initial load
duke
parents:
diff changeset
591 PSMarkSweepDecorator* md = from_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
592 _from_mark_sweep = to_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 _to_mark_sweep = md;
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 assert(from_mark_sweep()->space() == from_space(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
596 assert(to_mark_sweep()->space() == to_space(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
597 }
a61af66fc99e Initial load
duke
parents:
diff changeset
598
a61af66fc99e Initial load
duke
parents:
diff changeset
599 size_t PSYoungGen::capacity_in_bytes() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 return eden_space()->capacity_in_bytes()
a61af66fc99e Initial load
duke
parents:
diff changeset
601 + from_space()->capacity_in_bytes(); // to_space() is only used during scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
602 }
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604
a61af66fc99e Initial load
duke
parents:
diff changeset
605 size_t PSYoungGen::used_in_bytes() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 return eden_space()->used_in_bytes()
a61af66fc99e Initial load
duke
parents:
diff changeset
607 + from_space()->used_in_bytes(); // to_space() is only used during scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
609
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 size_t PSYoungGen::free_in_bytes() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
612 return eden_space()->free_in_bytes()
a61af66fc99e Initial load
duke
parents:
diff changeset
613 + from_space()->free_in_bytes(); // to_space() is only used during scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 size_t PSYoungGen::capacity_in_words() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 return eden_space()->capacity_in_words()
a61af66fc99e Initial load
duke
parents:
diff changeset
618 + from_space()->capacity_in_words(); // to_space() is only used during scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 size_t PSYoungGen::used_in_words() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 return eden_space()->used_in_words()
a61af66fc99e Initial load
duke
parents:
diff changeset
624 + from_space()->used_in_words(); // to_space() is only used during scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 size_t PSYoungGen::free_in_words() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 return eden_space()->free_in_words()
a61af66fc99e Initial load
duke
parents:
diff changeset
630 + from_space()->free_in_words(); // to_space() is only used during scavenge
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 void PSYoungGen::object_iterate(ObjectClosure* blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 eden_space()->object_iterate(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 from_space()->object_iterate(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
636 to_space()->object_iterate(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
638
a61af66fc99e Initial load
duke
parents:
diff changeset
639 void PSYoungGen::precompact() {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 eden_mark_sweep()->precompact();
a61af66fc99e Initial load
duke
parents:
diff changeset
641 from_mark_sweep()->precompact();
a61af66fc99e Initial load
duke
parents:
diff changeset
642 to_mark_sweep()->precompact();
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 void PSYoungGen::adjust_pointers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 eden_mark_sweep()->adjust_pointers();
a61af66fc99e Initial load
duke
parents:
diff changeset
647 from_mark_sweep()->adjust_pointers();
a61af66fc99e Initial load
duke
parents:
diff changeset
648 to_mark_sweep()->adjust_pointers();
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651 void PSYoungGen::compact() {
a61af66fc99e Initial load
duke
parents:
diff changeset
652 eden_mark_sweep()->compact(ZapUnusedHeapArea);
a61af66fc99e Initial load
duke
parents:
diff changeset
653 from_mark_sweep()->compact(ZapUnusedHeapArea);
a61af66fc99e Initial load
duke
parents:
diff changeset
654 // Mark sweep stores preserved markOops in to space, don't disturb!
a61af66fc99e Initial load
duke
parents:
diff changeset
655 to_mark_sweep()->compact(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 void PSYoungGen::move_and_update(ParCompactionManager* cm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 PSParallelCompact::move_and_update(cm, PSParallelCompact::eden_space_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
660 PSParallelCompact::move_and_update(cm, PSParallelCompact::from_space_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 PSParallelCompact::move_and_update(cm, PSParallelCompact::to_space_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
663
a61af66fc99e Initial load
duke
parents:
diff changeset
664 void PSYoungGen::print() const { print_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
665 void PSYoungGen::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 st->print(" %-15s", "PSYoungGen");
a61af66fc99e Initial load
duke
parents:
diff changeset
667 if (PrintGCDetails && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
668 st->print(" total " SIZE_FORMAT ", used " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
669 capacity_in_bytes(), used_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
670 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
a61af66fc99e Initial load
duke
parents:
diff changeset
672 capacity_in_bytes()/K, used_in_bytes()/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
674 _virtual_space->print_space_boundaries_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
675 st->print(" eden"); eden_space()->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 st->print(" from"); from_space()->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
677 st->print(" to "); to_space()->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 void PSYoungGen::print_used_change(size_t prev_used) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 gclog_or_tty->print(" [%s:", name());
a61af66fc99e Initial load
duke
parents:
diff changeset
682 gclog_or_tty->print(" " SIZE_FORMAT "K"
a61af66fc99e Initial load
duke
parents:
diff changeset
683 "->" SIZE_FORMAT "K"
a61af66fc99e Initial load
duke
parents:
diff changeset
684 "(" SIZE_FORMAT "K)",
a61af66fc99e Initial load
duke
parents:
diff changeset
685 prev_used / K, used_in_bytes() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
686 capacity_in_bytes() / K);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 gclog_or_tty->print("]");
a61af66fc99e Initial load
duke
parents:
diff changeset
688 }
a61af66fc99e Initial load
duke
parents:
diff changeset
689
a61af66fc99e Initial load
duke
parents:
diff changeset
690 size_t PSYoungGen::available_for_expansion() {
a61af66fc99e Initial load
duke
parents:
diff changeset
691 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
692 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
694
a61af66fc99e Initial load
duke
parents:
diff changeset
695 size_t PSYoungGen::available_for_contraction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
697 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
699
a61af66fc99e Initial load
duke
parents:
diff changeset
700 size_t PSYoungGen::available_to_min_gen() {
a61af66fc99e Initial load
duke
parents:
diff changeset
701 assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
702 return virtual_space()->committed_size() - min_gen_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
704
a61af66fc99e Initial load
duke
parents:
diff changeset
705 // This method assumes that from-space has live data and that
a61af66fc99e Initial load
duke
parents:
diff changeset
706 // any shrinkage of the young gen is limited by location of
a61af66fc99e Initial load
duke
parents:
diff changeset
707 // from-space.
a61af66fc99e Initial load
duke
parents:
diff changeset
708 size_t PSYoungGen::available_to_live() {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 size_t delta_in_survivor = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
710 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
13
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
711 const size_t space_alignment = heap->intra_heap_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
712 const size_t gen_alignment = heap->young_gen_alignment();
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 MutableSpace* space_shrinking = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
715 if (from_space()->end() > to_space()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
716 space_shrinking = from_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
717 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
718 space_shrinking = to_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
719 }
a61af66fc99e Initial load
duke
parents:
diff changeset
720
a61af66fc99e Initial load
duke
parents:
diff changeset
721 // Include any space that is committed but not included in
a61af66fc99e Initial load
duke
parents:
diff changeset
722 // the survivor spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
723 assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
724 "Survivor space beyond high end");
a61af66fc99e Initial load
duke
parents:
diff changeset
725 size_t unused_committed = pointer_delta(virtual_space()->high(),
a61af66fc99e Initial load
duke
parents:
diff changeset
726 space_shrinking->end(), sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
727
a61af66fc99e Initial load
duke
parents:
diff changeset
728 if (space_shrinking->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
729 // Don't let the space shrink to 0
a61af66fc99e Initial load
duke
parents:
diff changeset
730 assert(space_shrinking->capacity_in_bytes() >= space_alignment,
a61af66fc99e Initial load
duke
parents:
diff changeset
731 "Space is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
732 delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
733 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 delta_in_survivor = pointer_delta(space_shrinking->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
735 space_shrinking->top(),
a61af66fc99e Initial load
duke
parents:
diff changeset
736 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
738
a61af66fc99e Initial load
duke
parents:
diff changeset
739 size_t delta_in_bytes = unused_committed + delta_in_survivor;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
741 return delta_in_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744 // Return the number of bytes available for resizing down the young
a61af66fc99e Initial load
duke
parents:
diff changeset
745 // generation. This is the minimum of
a61af66fc99e Initial load
duke
parents:
diff changeset
746 // input "bytes"
a61af66fc99e Initial load
duke
parents:
diff changeset
747 // bytes to the minimum young gen size
a61af66fc99e Initial load
duke
parents:
diff changeset
748 // bytes to the size currently being used + some small extra
a61af66fc99e Initial load
duke
parents:
diff changeset
749 size_t PSYoungGen::limit_gen_shrink(size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // Allow shrinkage into the current eden but keep eden large enough
a61af66fc99e Initial load
duke
parents:
diff changeset
751 // to maintain the minimum young gen size
a61af66fc99e Initial load
duke
parents:
diff changeset
752 bytes = MIN3(bytes, available_to_min_gen(), available_to_live());
a61af66fc99e Initial load
duke
parents:
diff changeset
753 return align_size_down(bytes, virtual_space()->alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755
a61af66fc99e Initial load
duke
parents:
diff changeset
756 void PSYoungGen::reset_after_change() {
a61af66fc99e Initial load
duke
parents:
diff changeset
757 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
759
a61af66fc99e Initial load
duke
parents:
diff changeset
760 void PSYoungGen::reset_survivors_after_shrink() {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
a61af66fc99e Initial load
duke
parents:
diff changeset
762 (HeapWord*)virtual_space()->high_boundary());
a61af66fc99e Initial load
duke
parents:
diff changeset
763 PSScavenge::reference_processor()->set_span(_reserved);
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 MutableSpace* space_shrinking = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
766 if (from_space()->end() > to_space()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 space_shrinking = from_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
768 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
769 space_shrinking = to_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772 HeapWord* new_end = (HeapWord*)virtual_space()->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
773 assert(new_end >= space_shrinking->bottom(), "Shrink was too large");
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // Was there a shrink of the survivor space?
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if (new_end < space_shrinking->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 MemRegion mr(space_shrinking->bottom(), new_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
777 space_shrinking->initialize(mr, false /* clear */);
a61af66fc99e Initial load
duke
parents:
diff changeset
778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
780
a61af66fc99e Initial load
duke
parents:
diff changeset
781 // This method currently does not expect to expand into eden (i.e.,
a61af66fc99e Initial load
duke
parents:
diff changeset
782 // the virtual space boundaries is expected to be consistent
a61af66fc99e Initial load
duke
parents:
diff changeset
783 // with the eden boundaries..
a61af66fc99e Initial load
duke
parents:
diff changeset
784 void PSYoungGen::post_resize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 assert_locked_or_safepoint(Heap_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
786 assert((eden_space()->bottom() < to_space()->bottom()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
787 (eden_space()->bottom() < from_space()->bottom()),
a61af66fc99e Initial load
duke
parents:
diff changeset
788 "Eden is assumed to be below the survivor spaces");
a61af66fc99e Initial load
duke
parents:
diff changeset
789
a61af66fc99e Initial load
duke
parents:
diff changeset
790 MemRegion cmr((HeapWord*)virtual_space()->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
791 (HeapWord*)virtual_space()->high());
a61af66fc99e Initial load
duke
parents:
diff changeset
792 Universe::heap()->barrier_set()->resize_covered_region(cmr);
a61af66fc99e Initial load
duke
parents:
diff changeset
793 space_invariants();
a61af66fc99e Initial load
duke
parents:
diff changeset
794 }
a61af66fc99e Initial load
duke
parents:
diff changeset
795
a61af66fc99e Initial load
duke
parents:
diff changeset
796
a61af66fc99e Initial load
duke
parents:
diff changeset
797
a61af66fc99e Initial load
duke
parents:
diff changeset
798 void PSYoungGen::update_counters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
799 if (UsePerfData) {
a61af66fc99e Initial load
duke
parents:
diff changeset
800 _eden_counters->update_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
801 _from_counters->update_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
802 _to_counters->update_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
803 _gen_counters->update_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
806
a61af66fc99e Initial load
duke
parents:
diff changeset
807 void PSYoungGen::verify(bool allow_dirty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 eden_space()->verify(allow_dirty);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 from_space()->verify(allow_dirty);
a61af66fc99e Initial load
duke
parents:
diff changeset
810 to_space()->verify(allow_dirty);
a61af66fc99e Initial load
duke
parents:
diff changeset
811 }