annotate src/share/vm/gc_implementation/parNew/asParNewGeneration.cpp @ 1951:899bbbdcb6ea

6997298: fatal error: must own lock CMS_markBitMap_lock during heap dump Summary: Since we are at a stop-world pause, the existing CMS-phase checks are sufficient for safety, and the locking check can be safely elided. Elaborated documentation comment to the case where class unloading and verification are disabled, and the query happens when we aren't in the sweeping phase, where the answer "false" would be (almost everywhere) too pessimistic. Reviewed-by: jmasa, johnc, tonyp
author ysr
date Fri, 05 Nov 2010 13:20:37 -0700
parents c18cbe5936b8
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
2 * Copyright (c) 2005, 2008, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_asParNewGeneration.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 ASParNewGeneration::ASParNewGeneration(ReservedSpace rs,
a61af66fc99e Initial load
duke
parents:
diff changeset
29 size_t initial_byte_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
30 size_t min_byte_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
31 int level) :
a61af66fc99e Initial load
duke
parents:
diff changeset
32 ParNewGeneration(rs, initial_byte_size, level),
a61af66fc99e Initial load
duke
parents:
diff changeset
33 _min_gen_size(min_byte_size) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 const char* ASParNewGeneration::name() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 return "adaptive size par new generation";
a61af66fc99e Initial load
duke
parents:
diff changeset
37 }
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 void ASParNewGeneration::adjust_desired_tenuring_threshold() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 assert(UseAdaptiveSizePolicy,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 "Should only be used with UseAdaptiveSizePolicy");
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 ASParNewGeneration::resize(size_t eden_size, size_t survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Resize the generation if needed. If the generation resize
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // reports false, do not attempt to resize the spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 if (resize_generation(eden_size, survivor_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Then we lay out the spaces inside the generation
a61af66fc99e Initial load
duke
parents:
diff changeset
49 resize_spaces(eden_size, survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 space_invariants();
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 gclog_or_tty->print_cr("Young generation size: "
a61af66fc99e Initial load
duke
parents:
diff changeset
55 "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
56 " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
57 " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
58 eden_size, survivor_size, used(), capacity(),
a61af66fc99e Initial load
duke
parents:
diff changeset
59 max_gen_size(), min_gen_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 size_t ASParNewGeneration::available_to_min_gen() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return virtual_space()->committed_size() - min_gen_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // This method assumes that from-space has live data and that
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // any shrinkage of the young gen is limited by location of
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // from-space.
a61af66fc99e Initial load
duke
parents:
diff changeset
72 size_t ASParNewGeneration::available_to_live() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 #undef SHRINKS_AT_END_OF_EDEN
a61af66fc99e Initial load
duke
parents:
diff changeset
74 #ifdef SHRINKS_AT_END_OF_EDEN
a61af66fc99e Initial load
duke
parents:
diff changeset
75 size_t delta_in_survivor = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
13
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
77 const size_t space_alignment = heap->intra_heap_alignment();
183f41cf8bfe 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 0
diff changeset
78 const size_t gen_alignment = heap->object_heap_alignment();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 MutableSpace* space_shrinking = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (from_space()->end() > to_space()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 space_shrinking = from_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 space_shrinking = to_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Include any space that is committed but not included in
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // the survivor spaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
89 assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
90 "Survivor space beyond high end");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 size_t unused_committed = pointer_delta(virtual_space()->high(),
a61af66fc99e Initial load
duke
parents:
diff changeset
92 space_shrinking->end(), sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (space_shrinking->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Don't let the space shrink to 0
a61af66fc99e Initial load
duke
parents:
diff changeset
96 assert(space_shrinking->capacity_in_bytes() >= space_alignment,
a61af66fc99e Initial load
duke
parents:
diff changeset
97 "Space is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 delta_in_survivor = pointer_delta(space_shrinking->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
101 space_shrinking->top(),
a61af66fc99e Initial load
duke
parents:
diff changeset
102 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 size_t delta_in_bytes = unused_committed + delta_in_survivor;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return delta_in_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // The only space available for shrinking is in to-space if it
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // is above from-space.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (to()->bottom() > from()->bottom()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 const size_t alignment = os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (to()->capacity() < alignment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return to()->capacity() - alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Return the number of bytes available for resizing down the young
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // generation. This is the minimum of
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // input "bytes"
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // bytes to the minimum young gen size
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // bytes to the size currently being used + some small extra
a61af66fc99e Initial load
duke
parents:
diff changeset
129 size_t ASParNewGeneration::limit_gen_shrink (size_t bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Allow shrinkage into the current eden but keep eden large enough
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // to maintain the minimum young gen size
a61af66fc99e Initial load
duke
parents:
diff changeset
132 bytes = MIN3(bytes, available_to_min_gen(), available_to_live());
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return align_size_down(bytes, os::vm_page_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Note that the the alignment used is the OS page size as
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // opposed to an alignment associated with the virtual space
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // (as is done in the ASPSYoungGen/ASPSOldGen)
a61af66fc99e Initial load
duke
parents:
diff changeset
139 bool ASParNewGeneration::resize_generation(size_t eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
140 size_t survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 const size_t alignment = os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 size_t orig_size = virtual_space()->committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 bool size_changed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // There used to be this guarantee there.
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // guarantee ((eden_size + 2*survivor_size) <= _max_gen_size, "incorrect input arguments");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Code below forces this requirement. In addition the desired eden
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // size and disired survivor sizes are desired goals and may
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // exceed the total generation size.
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 assert(min_gen_size() <= orig_size && orig_size <= max_gen_size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
152 "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Adjust new generation size
a61af66fc99e Initial load
duke
parents:
diff changeset
155 const size_t eden_plus_survivors =
a61af66fc99e Initial load
duke
parents:
diff changeset
156 align_size_up(eden_size + 2 * survivor_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_gen_size()),
a61af66fc99e Initial load
duke
parents:
diff changeset
158 min_gen_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
159 assert(desired_size <= max_gen_size(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (desired_size > orig_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Grow the generation
a61af66fc99e Initial load
duke
parents:
diff changeset
163 size_t change = desired_size - orig_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 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
165 if (expand(change)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return false; // Error if we fail to resize!
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 size_changed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 } else if (desired_size < orig_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 size_t desired_change = orig_size - desired_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 assert(desired_change % alignment == 0, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 desired_change = limit_gen_shrink(desired_change);
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (desired_change > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 virtual_space()->shrink_by(desired_change);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 reset_survivors_after_shrink();
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 size_changed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (Verbose && PrintGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (orig_size == max_gen_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 gclog_or_tty->print_cr("ASParNew generation size at maximum: "
a61af66fc99e Initial load
duke
parents:
diff changeset
185 SIZE_FORMAT "K", orig_size/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 } else if (orig_size == min_gen_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 gclog_or_tty->print_cr("ASParNew generation size at minium: "
a61af66fc99e Initial load
duke
parents:
diff changeset
188 SIZE_FORMAT "K", orig_size/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (size_changed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 MemRegion cmr((HeapWord*)virtual_space()->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
195 (HeapWord*)virtual_space()->high());
a61af66fc99e Initial load
duke
parents:
diff changeset
196 GenCollectedHeap::heap()->barrier_set()->resize_covered_region(cmr);
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (Verbose && PrintGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 size_t current_size = virtual_space()->committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 gclog_or_tty->print_cr("ASParNew generation size changed: "
a61af66fc99e Initial load
duke
parents:
diff changeset
201 SIZE_FORMAT "K->" SIZE_FORMAT "K",
a61af66fc99e Initial load
duke
parents:
diff changeset
202 orig_size/K, current_size/K);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
207 virtual_space()->committed_size() == max_gen_size(), "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 void ASParNewGeneration::reset_survivors_after_shrink() {
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
215 HeapWord* new_end = (HeapWord*)virtual_space()->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (from()->end() > to()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 assert(new_end >= from()->end(), "Shrinking past from-space");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 assert(new_end >= to()->bottom(), "Shrink was too large");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Was there a shrink of the survivor space?
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (new_end < to()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 MemRegion mr(to()->bottom(), new_end);
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
224 to()->initialize(mr,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
225 SpaceDecorator::DontClear,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
226 SpaceDecorator::DontMangle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 void ASParNewGeneration::resize_spaces(size_t requested_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
231 size_t requested_survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 assert(UseAdaptiveSizePolicy, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
233 assert(requested_eden_size > 0 && requested_survivor_size > 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
234 "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 CollectedHeap* heap = Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // We require eden and to space to be empty
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if ((!eden()->is_empty()) || (!to()->is_empty())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 size_t cur_eden_size = eden()->capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: "
a61af66fc99e Initial load
duke
parents:
diff changeset
248 SIZE_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
249 ", requested_survivor_size: " SIZE_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
250 requested_eden_size, requested_survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 gclog_or_tty->print_cr(" eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
a61af66fc99e Initial load
duke
parents:
diff changeset
252 SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
253 eden()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
254 eden()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
255 pointer_delta(eden()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
256 eden()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
257 sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
258 gclog_or_tty->print_cr(" from: [" PTR_FORMAT ".." PTR_FORMAT ") "
a61af66fc99e Initial load
duke
parents:
diff changeset
259 SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
260 from()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
261 from()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
262 pointer_delta(from()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
263 from()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
264 sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
265 gclog_or_tty->print_cr(" to: [" PTR_FORMAT ".." PTR_FORMAT ") "
a61af66fc99e Initial load
duke
parents:
diff changeset
266 SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
267 to()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
268 to()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
269 pointer_delta( to()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
270 to()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
271 sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // There's nothing to do if the new sizes are the same as the current
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (requested_survivor_size == to()->capacity() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
276 requested_survivor_size == from()->capacity() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
277 requested_eden_size == eden()->capacity()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 gclog_or_tty->print_cr(" capacities are the right sizes, returning");
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 char* eden_start = (char*)eden()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 char* eden_end = (char*)eden()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 char* from_start = (char*)from()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 char* from_end = (char*)from()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
288 char* to_start = (char*)to()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
289 char* to_end = (char*)to()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 const size_t alignment = os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
292 const bool maintain_minimum =
a61af66fc99e Initial load
duke
parents:
diff changeset
293 (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // Check whether from space is below to space
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (from_start < to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // Eden, from, to
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 gclog_or_tty->print_cr(" Eden, from, to:");
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // Set eden
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // "requested_eden_size" is a goal for the size of eden
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // and may not be attainable. "eden_size" below is
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // calculated based on the location of from-space and
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // the goal for the size of eden. from-space is
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // fixed in place because it contains live data.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // The calculation is done this way to avoid 32bit
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // overflow (i.e., eden_start + requested_eden_size
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // may too large for representation in 32bits).
a61af66fc99e Initial load
duke
parents:
diff changeset
311 size_t eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (maintain_minimum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // Only make eden larger than the requested size if
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // the minimum size of the generation has to be maintained.
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // This could be done in general but policy at a higher
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // level is determining a requested size for eden and that
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // should be honored unless there is a fundamental reason.
a61af66fc99e Initial load
duke
parents:
diff changeset
318 eden_size = pointer_delta(from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
319 eden_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
320 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
321 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 eden_size = MIN2(requested_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
323 pointer_delta(from_start, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 eden_size = align_size_down(eden_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 eden_end = eden_start + eden_size;
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 269
diff changeset
328 assert(eden_end >= eden_start, "addition overflowed");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // To may resize into from space as long as it is clear of live data.
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // From space must remain page aligned, though, so we need to do some
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // extra calculations.
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // First calculate an optimal to-space
a61af66fc99e Initial load
duke
parents:
diff changeset
335 to_end = (char*)virtual_space()->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
336 to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
337 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // Does the optimal to-space overlap from-space?
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (to_start < (char*)from()->end()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Calculate the minimum offset possible for from_end
a61af66fc99e Initial load
duke
parents:
diff changeset
342 size_t from_size = pointer_delta(from()->top(), from_start, sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // 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
345 if (from_size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 from_size = alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 from_size = align_size_up(from_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 from_end = from_start + from_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 assert(from_end > from_start, "addition overflow or from_size problem");
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 guarantee(from_end <= (char*)from()->end(), "from_end moved to the right");
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // Now update to_start with the new from_end
a61af66fc99e Initial load
duke
parents:
diff changeset
357 to_start = MAX2(from_end, to_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // If shrinking, move to-space down to abut the end of from-space
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // so that shrinking will move to-space down. If not shrinking
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // to-space is moving up to allow for growth on the next expansion.
a61af66fc99e Initial load
duke
parents:
diff changeset
362 if (requested_eden_size <= cur_eden_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 to_start = from_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 if (to_start + requested_survivor_size > to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 to_end = to_start + requested_survivor_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // else leave to_end pointing to the high end of the virtual space.
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 guarantee(to_start != to_end, "to space is zero sized");
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 gclog_or_tty->print_cr(" [eden_start .. eden_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
375 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
376 eden_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
377 eden_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
378 pointer_delta(eden_end, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
379 gclog_or_tty->print_cr(" [from_start .. from_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
380 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
381 from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
382 from_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
383 pointer_delta(from_end, from_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
384 gclog_or_tty->print_cr(" [ to_start .. to_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
385 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
386 to_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
387 to_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
388 pointer_delta( to_end, to_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // Eden, to, from
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 gclog_or_tty->print_cr(" Eden, to, from:");
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // Calculate the to-space boundaries based on
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // the start of from-space.
a61af66fc99e Initial load
duke
parents:
diff changeset
398 to_end = from_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
399 to_start = (char*)pointer_delta(from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
400 (char*)requested_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
401 sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
402 // Calculate the ideal eden boundaries.
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // eden_end is already at the bottom of the generation
a61af66fc99e Initial load
duke
parents:
diff changeset
404 assert(eden_start == virtual_space()->low(),
a61af66fc99e Initial load
duke
parents:
diff changeset
405 "Eden is not starting at the low end of the virtual space");
a61af66fc99e Initial load
duke
parents:
diff changeset
406 if (eden_start + requested_eden_size >= eden_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 eden_end = eden_start + requested_eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 eden_end = to_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // Does eden intrude into to-space? to-space
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // gets priority but eden is not allowed to shrink
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // to 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
415 if (eden_end > to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 eden_end = to_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // Don't let eden shrink down to 0 or less.
a61af66fc99e Initial load
duke
parents:
diff changeset
420 eden_end = MAX2(eden_end, eden_start + alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
421 assert(eden_start + alignment >= eden_start, "Overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 size_t eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (maintain_minimum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // Use all the space available.
a61af66fc99e Initial load
duke
parents:
diff changeset
426 eden_end = MAX2(eden_end, to_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
428 eden_size = MIN2(eden_size, cur_eden_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
429 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432 eden_size = align_size_down(eden_size, alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 assert(maintain_minimum || eden_size <= requested_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
434 "Eden size is too large");
a61af66fc99e Initial load
duke
parents:
diff changeset
435 assert(eden_size >= alignment, "Eden size is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
436 eden_end = eden_start + eden_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 // Move to-space down to eden.
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (requested_eden_size < cur_eden_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 to_start = eden_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (to_start + requested_survivor_size > to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 to_end = MIN2(from_start, to_start + requested_survivor_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 to_end = from_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 // eden_end may have moved so again make sure
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // the to-space and eden don't overlap.
a61af66fc99e Initial load
duke
parents:
diff changeset
450 to_start = MAX2(eden_end, to_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // from-space
a61af66fc99e Initial load
duke
parents:
diff changeset
453 size_t from_used = from()->used();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if (requested_survivor_size > from_used) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 if (from_start + requested_survivor_size >= from_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
456 from_end = from_start + requested_survivor_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (from_end > virtual_space()->high()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 from_end = virtual_space()->high();
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 assert(to_start >= eden_end, "to-space should be above eden");
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 gclog_or_tty->print_cr(" [eden_start .. eden_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
466 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
467 eden_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
468 eden_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
469 pointer_delta(eden_end, eden_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
470 gclog_or_tty->print_cr(" [ to_start .. to_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
471 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
472 to_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
473 to_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
474 pointer_delta( to_end, to_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
475 gclog_or_tty->print_cr(" [from_start .. from_end): "
a61af66fc99e Initial load
duke
parents:
diff changeset
476 "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
477 from_start,
a61af66fc99e Initial load
duke
parents:
diff changeset
478 from_end,
a61af66fc99e Initial load
duke
parents:
diff changeset
479 pointer_delta(from_end, from_start, sizeof(char)));
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 guarantee((HeapWord*)from_start <= from()->bottom(),
a61af66fc99e Initial load
duke
parents:
diff changeset
485 "from start moved to the right");
a61af66fc99e Initial load
duke
parents:
diff changeset
486 guarantee((HeapWord*)from_end >= from()->top(),
a61af66fc99e Initial load
duke
parents:
diff changeset
487 "from end moved into live data");
a61af66fc99e Initial load
duke
parents:
diff changeset
488 assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
489 assert(is_object_aligned((intptr_t)from_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
490 assert(is_object_aligned((intptr_t)to_start), "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
493 MemRegion toMR ((HeapWord*)to_start, (HeapWord*)to_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // Let's make sure the call to initialize doesn't reset "top"!
a61af66fc99e Initial load
duke
parents:
diff changeset
497 HeapWord* old_from_top = from()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // For PrintAdaptiveSizePolicy block below
a61af66fc99e Initial load
duke
parents:
diff changeset
500 size_t old_from = from()->capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
501 size_t old_to = to()->capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
502
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
503 // If not clearing 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
504 // the spaces are already mangled.
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
505
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
506 // 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
507 // the bottom or end of one space may have moved into another
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
508 // a failure of the check may not correctly indicate which space
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
509 // is not properly mangled.
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
510 if (ZapUnusedHeapArea) {
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
511 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
512 eden()->check_mangled_unused_area(limit);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
513 from()->check_mangled_unused_area(limit);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
514 to()->check_mangled_unused_area(limit);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
515 }
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
516
0
a61af66fc99e Initial load
duke
parents:
diff changeset
517 // The call to initialize NULL's the next compaction space
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
518 eden()->initialize(edenMR,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
519 SpaceDecorator::Clear,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
520 SpaceDecorator::DontMangle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
521 eden()->set_next_compaction_space(from());
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
522 to()->initialize(toMR ,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
523 SpaceDecorator::Clear,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
524 SpaceDecorator::DontMangle);
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
525 from()->initialize(fromMR,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
526 SpaceDecorator::DontClear,
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 13
diff changeset
527 SpaceDecorator::DontMangle);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 assert(from()->top() == old_from_top, "from top changed!");
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 if (PrintAdaptiveSizePolicy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
533 assert(gch->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
a61af66fc99e Initial load
duke
parents:
diff changeset
536 "collection: %d "
a61af66fc99e Initial load
duke
parents:
diff changeset
537 "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
a61af66fc99e Initial load
duke
parents:
diff changeset
538 "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
a61af66fc99e Initial load
duke
parents:
diff changeset
539 gch->total_collections(),
a61af66fc99e Initial load
duke
parents:
diff changeset
540 old_from, old_to,
a61af66fc99e Initial load
duke
parents:
diff changeset
541 from()->capacity(),
a61af66fc99e Initial load
duke
parents:
diff changeset
542 to()->capacity());
a61af66fc99e Initial load
duke
parents:
diff changeset
543 gclog_or_tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 void ASParNewGeneration::compute_new_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
549 assert(gch->kind() == CollectedHeap::GenCollectedHeap,
a61af66fc99e Initial load
duke
parents:
diff changeset
550 "not a CMS generational heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552
a61af66fc99e Initial load
duke
parents:
diff changeset
553 CMSAdaptiveSizePolicy* size_policy =
a61af66fc99e Initial load
duke
parents:
diff changeset
554 (CMSAdaptiveSizePolicy*)gch->gen_policy()->size_policy();
a61af66fc99e Initial load
duke
parents:
diff changeset
555 assert(size_policy->is_gc_cms_adaptive_size_policy(),
a61af66fc99e Initial load
duke
parents:
diff changeset
556 "Wrong type of size policy");
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 size_t survived = from()->used();
a61af66fc99e Initial load
duke
parents:
diff changeset
559 if (!survivor_overflow()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 // Keep running averages on how much survived
a61af66fc99e Initial load
duke
parents:
diff changeset
561 size_policy->avg_survived()->sample(survived);
a61af66fc99e Initial load
duke
parents:
diff changeset
562 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
563 size_t promoted =
a61af66fc99e Initial load
duke
parents:
diff changeset
564 (size_t) next_gen()->gc_stats()->avg_promoted()->last_sample();
a61af66fc99e Initial load
duke
parents:
diff changeset
565 assert(promoted < gch->capacity(), "Conversion problem?");
a61af66fc99e Initial load
duke
parents:
diff changeset
566 size_t survived_guess = survived + promoted;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 size_policy->avg_survived()->sample(survived_guess);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 size_t survivor_limit = max_survivor_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
571 _tenuring_threshold =
a61af66fc99e Initial load
duke
parents:
diff changeset
572 size_policy->compute_survivor_space_size_and_threshold(
a61af66fc99e Initial load
duke
parents:
diff changeset
573 _survivor_overflow,
a61af66fc99e Initial load
duke
parents:
diff changeset
574 _tenuring_threshold,
a61af66fc99e Initial load
duke
parents:
diff changeset
575 survivor_limit);
a61af66fc99e Initial load
duke
parents:
diff changeset
576 size_policy->avg_young_live()->sample(used());
a61af66fc99e Initial load
duke
parents:
diff changeset
577 size_policy->avg_eden_live()->sample(eden()->used());
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 size_policy->compute_young_generation_free_space(eden()->capacity(),
a61af66fc99e Initial load
duke
parents:
diff changeset
580 max_gen_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 resize(size_policy->calculated_eden_size_in_bytes(),
a61af66fc99e Initial load
duke
parents:
diff changeset
583 size_policy->calculated_survivor_size_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 if (UsePerfData) {
a61af66fc99e Initial load
duke
parents:
diff changeset
586 CMSGCAdaptivePolicyCounters* counters =
a61af66fc99e Initial load
duke
parents:
diff changeset
587 (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 assert(counters->kind() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
589 GCPolicyCounters::CMSGCAdaptivePolicyCountersKind,
a61af66fc99e Initial load
duke
parents:
diff changeset
590 "Wrong kind of counters");
a61af66fc99e Initial load
duke
parents:
diff changeset
591 counters->update_tenuring_threshold(_tenuring_threshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
592 counters->update_survivor_overflowed(_survivor_overflow);
a61af66fc99e Initial load
duke
parents:
diff changeset
593 counters->update_young_capacity(capacity());
a61af66fc99e Initial load
duke
parents:
diff changeset
594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
599 // Changes from PSYoungGen version
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // value of "alignment"
a61af66fc99e Initial load
duke
parents:
diff changeset
601 void ASParNewGeneration::space_invariants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 const size_t alignment = os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 // Currently, our eden size cannot shrink to zero
a61af66fc99e Initial load
duke
parents:
diff changeset
605 guarantee(eden()->capacity() >= alignment, "eden too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
606 guarantee(from()->capacity() >= alignment, "from too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
607 guarantee(to()->capacity() >= alignment, "to too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // Relationship of spaces to each other
a61af66fc99e Initial load
duke
parents:
diff changeset
610 char* eden_start = (char*)eden()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
611 char* eden_end = (char*)eden()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
612 char* from_start = (char*)from()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
613 char* from_end = (char*)from()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
614 char* to_start = (char*)to()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
615 char* to_end = (char*)to()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 guarantee(eden_start >= virtual_space()->low(), "eden bottom");
a61af66fc99e Initial load
duke
parents:
diff changeset
618 guarantee(eden_start < eden_end, "eden space consistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
619 guarantee(from_start < from_end, "from space consistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
620 guarantee(to_start < to_end, "to space consistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // Check whether from space is below to space
a61af66fc99e Initial load
duke
parents:
diff changeset
623 if (from_start < to_start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // Eden, from, to
a61af66fc99e Initial load
duke
parents:
diff changeset
625 guarantee(eden_end <= from_start, "eden/from boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
626 guarantee(from_end <= to_start, "from/to boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
627 guarantee(to_end <= virtual_space()->high(), "to end");
a61af66fc99e Initial load
duke
parents:
diff changeset
628 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // Eden, to, from
a61af66fc99e Initial load
duke
parents:
diff changeset
630 guarantee(eden_end <= to_start, "eden/to boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
631 guarantee(to_end <= from_start, "to/from boundary");
a61af66fc99e Initial load
duke
parents:
diff changeset
632 guarantee(from_end <= virtual_space()->high(), "from end");
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // More checks that the virtual space is consistent with the spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
636 assert(virtual_space()->committed_size() >=
a61af66fc99e Initial load
duke
parents:
diff changeset
637 (eden()->capacity() +
a61af66fc99e Initial load
duke
parents:
diff changeset
638 to()->capacity() +
a61af66fc99e Initial load
duke
parents:
diff changeset
639 from()->capacity()), "Committed size is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
640 assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
641 "Space invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
642 char* eden_top = (char*)eden()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
643 char* from_top = (char*)from()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
644 char* to_top = (char*)to()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
645 assert(eden_top <= virtual_space()->high(), "eden top");
a61af66fc99e Initial load
duke
parents:
diff changeset
646 assert(from_top <= virtual_space()->high(), "from top");
a61af66fc99e Initial load
duke
parents:
diff changeset
647 assert(to_top <= virtual_space()->high(), "to top");
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649 #endif