annotate src/share/vm/gc_implementation/parNew/asParNewGeneration.cpp @ 10185:d50cc62e94ff

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