annotate src/share/vm/memory/collectorPolicy.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 183f41cf8bfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_collectorPolicy.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // CollectorPolicy methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 void CollectorPolicy::initialize_flags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 if (PermSize > MaxPermSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 MaxPermSize = PermSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34 PermSize = align_size_down(PermSize, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
35 MaxPermSize = align_size_up(MaxPermSize, max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 MinPermHeapExpansion = align_size_down(MinPermHeapExpansion, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
38 MaxPermHeapExpansion = align_size_down(MaxPermHeapExpansion, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 SharedReadOnlySize = align_size_up(SharedReadOnlySize, max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
43 SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
44 SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 assert(PermSize % min_alignment() == 0, "permanent space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
47 assert(MaxPermSize % max_alignment() == 0, "maximum permanent space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
48 assert(SharedReadOnlySize % max_alignment() == 0, "read-only space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
49 assert(SharedReadWriteSize % max_alignment() == 0, "read-write space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
50 assert(SharedMiscDataSize % max_alignment() == 0, "misc-data space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 if (PermSize < M) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 vm_exit_during_initialization("Too small initial permanent heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 void CollectorPolicy::initialize_size_info() {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // User inputs from -mx and ms are aligned
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _initial_heap_byte_size = align_size_up(Arguments::initial_heap_size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
59 min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _min_heap_byte_size = align_size_up(Arguments::min_heap_size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
61 min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _max_heap_byte_size = align_size_up(MaxHeapSize, max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Check validity of heap parameters from launcher
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (_initial_heap_byte_size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _initial_heap_byte_size = NewSize + OldSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 Universe::check_alignment(_initial_heap_byte_size, min_alignment(),
a61af66fc99e Initial load
duke
parents:
diff changeset
69 "initial heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (_min_heap_byte_size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _min_heap_byte_size = NewSize + OldSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 Universe::check_alignment(_min_heap_byte_size, min_alignment(),
a61af66fc99e Initial load
duke
parents:
diff changeset
75 "initial heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Check heap parameter properties
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (_initial_heap_byte_size < M) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 vm_exit_during_initialization("Too small initial heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // Check heap parameter properties
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (_min_heap_byte_size < M) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 vm_exit_during_initialization("Too small minimum heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (_initial_heap_byte_size <= NewSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // make sure there is at least some room in old space
a61af66fc99e Initial load
duke
parents:
diff changeset
88 vm_exit_during_initialization("Too small initial heap for new size specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if (_max_heap_byte_size < _min_heap_byte_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (_initial_heap_byte_size < _min_heap_byte_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (_max_heap_byte_size < _initial_heap_byte_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void CollectorPolicy::initialize_perm_generation(PermGen::Name pgnm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _permanent_generation =
a61af66fc99e Initial load
duke
parents:
diff changeset
103 new PermanentGenerationSpec(pgnm, PermSize, MaxPermSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
104 SharedReadOnlySize,
a61af66fc99e Initial load
duke
parents:
diff changeset
105 SharedReadWriteSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
106 SharedMiscDataSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
107 SharedMiscCodeSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (_permanent_generation == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 vm_exit_during_initialization("Unable to allocate gen spec");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 GenRemSet* CollectorPolicy::create_rem_set(MemRegion whole_heap,
a61af66fc99e Initial load
duke
parents:
diff changeset
115 int max_covered_regions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 switch (rem_set_name()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case GenRemSet::CardTable: {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (barrier_set_name() != BarrierSet::CardTableModRef)
a61af66fc99e Initial load
duke
parents:
diff changeset
119 vm_exit_during_initialization("Mismatch between RS and BS.");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 CardTableRS* res = new CardTableRS(whole_heap, max_covered_regions);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
124 guarantee(false, "unrecognized GenRemSet::Name");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // GenCollectorPolicy methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
132 size_t init_promo_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
133 size_t init_survivor_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 double max_gc_minor_pause_sec = ((double) MaxGCMinorPauseMillis)/1000.0;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 _size_policy = new AdaptiveSizePolicy(init_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
136 init_promo_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
137 init_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
138 max_gc_minor_pause_sec,
a61af66fc99e Initial load
duke
parents:
diff changeset
139 GCTimeRatio);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 size_t GenCollectorPolicy::compute_max_alignment() {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // The card marking array and the offset arrays for old generations are
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // committed in os pages as well. Make sure they are entirely full (to
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // byte entry and the os page size is 4096, the maximum heap size should
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // be 512*4096 = 2MB aligned.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 size_t alignment = GenRemSet::max_alignment_constraint(rem_set_name());
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Parallel GC does its own alignment of the generations to avoid requiring a
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // large page (256M on some platforms) for the permanent generation. The
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // other collectors should also be updated to do their own alignment and then
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // this use of lcm() should be removed.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (UseLargePages && !UseParallelGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // in presence of large pages we have to make sure that our
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // alignment is large page aware
a61af66fc99e Initial load
duke
parents:
diff changeset
157 alignment = lcm(os::large_page_size(), alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 void GenCollectorPolicy::initialize_flags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // All sizes must be multiples of the generation granularity.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 set_min_alignment((uintx) Generation::GenGrain);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 set_max_alignment(compute_max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
167 assert(max_alignment() >= min_alignment() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
168 max_alignment() % min_alignment() == 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
169 "invalid alignment constraints");
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 CollectorPolicy::initialize_flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // All generational heaps have a youngest gen; handle those flags here.
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Adjust max size parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (NewSize > MaxNewSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 MaxNewSize = NewSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 NewSize = align_size_down(NewSize, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
180 MaxNewSize = align_size_down(MaxNewSize, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Check validity of heap flags
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(NewSize % min_alignment() == 0, "eden space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 assert(MaxNewSize % min_alignment() == 0, "survivor space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 if (NewSize < 3*min_alignment()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // make sure there room for eden and two survivor spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
188 vm_exit_during_initialization("Too small new size specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (SurvivorRatio < 1 || NewRatio < 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 vm_exit_during_initialization("Invalid heap ratio specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 void TwoGenerationCollectorPolicy::initialize_flags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 GenCollectorPolicy::initialize_flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 OldSize = align_size_down(OldSize, min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (NewSize + OldSize > MaxHeapSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 MaxHeapSize = NewSize + OldSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 MaxHeapSize = align_size_up(MaxHeapSize, max_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 always_do_update_barrier = UseConcMarkSweepGC;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 BlockOffsetArrayUseUnallocatedBlock =
a61af66fc99e Initial load
duke
parents:
diff changeset
206 BlockOffsetArrayUseUnallocatedBlock || ParallelGCThreads > 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Check validity of heap flags
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(OldSize % min_alignment() == 0, "old space alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 assert(MaxHeapSize % max_alignment() == 0, "maximum heap alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void GenCollectorPolicy::initialize_size_info() {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 CollectorPolicy::initialize_size_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // Minimum sizes of the generations may be different than
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // the initial sizes.
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (!FLAG_IS_DEFAULT(NewSize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _min_gen0_size = NewSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 _min_gen0_size = align_size_down(_min_heap_byte_size / (NewRatio+1),
a61af66fc99e Initial load
duke
parents:
diff changeset
222 min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // We bound the minimum size by NewSize below (since it historically
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // would have been NewSize and because the NewRatio calculation could
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // yield a size that is too small) and bound it by MaxNewSize above.
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // This is not always best. The NewSize calculated by CMS (which has
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // a fixed minimum of 16m) can sometimes be "too" large. Consider
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // the case where -Xmx32m. The CMS calculated NewSize would be about
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // half the entire heap which seems too large. But the counter
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // example is seen when the client defaults for NewRatio are used.
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // An initial young generation size of 640k was observed
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // with -Xmx128m -XX:MaxNewSize=32m when NewSize was not used
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // as a lower bound as with
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // _min_gen0_size = MIN2(_min_gen0_size, MaxNewSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // and 640k seemed too small a young generation.
a61af66fc99e Initial load
duke
parents:
diff changeset
236 _min_gen0_size = MIN2(MAX2(_min_gen0_size, NewSize), MaxNewSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Parameters are valid, compute area sizes.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 size_t max_new_size = align_size_down(_max_heap_byte_size / (NewRatio+1),
a61af66fc99e Initial load
duke
parents:
diff changeset
241 min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
242 max_new_size = MIN2(MAX2(max_new_size, _min_gen0_size), MaxNewSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // desired_new_size is used to set the initial size. The
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // initial size must be greater than the minimum size.
a61af66fc99e Initial load
duke
parents:
diff changeset
246 size_t desired_new_size =
a61af66fc99e Initial load
duke
parents:
diff changeset
247 align_size_down(_initial_heap_byte_size / (NewRatio+1),
a61af66fc99e Initial load
duke
parents:
diff changeset
248 min_alignment());
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 size_t new_size = MIN2(MAX2(desired_new_size, _min_gen0_size), max_new_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 _initial_gen0_size = new_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 _max_gen0_size = max_new_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 void TwoGenerationCollectorPolicy::initialize_size_info() {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 GenCollectorPolicy::initialize_size_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // Minimum sizes of the generations may be different than
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // the initial sizes. An inconsistently is permitted here
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // in the total size that can be specified explicitly by
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // command line specification of OldSize and NewSize and
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // also a command line specification of -Xms. Issue a warning
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // but allow the values to pass.
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (!FLAG_IS_DEFAULT(OldSize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 _min_gen1_size = OldSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // The generation minimums and the overall heap mimimum should
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // be within one heap alignment.
a61af66fc99e Initial load
duke
parents:
diff changeset
269 if ((_min_gen1_size + _min_gen0_size + max_alignment()) <
a61af66fc99e Initial load
duke
parents:
diff changeset
270 _min_heap_byte_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 warning("Inconsistency between minimum heap size and minimum "
a61af66fc99e Initial load
duke
parents:
diff changeset
272 "generation sizes: using min heap = " SIZE_FORMAT,
a61af66fc99e Initial load
duke
parents:
diff changeset
273 _min_heap_byte_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 _min_gen1_size = _min_heap_byte_size - _min_gen0_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 _initial_gen1_size = _initial_heap_byte_size - _initial_gen0_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 _max_gen1_size = _max_heap_byte_size - _max_gen0_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
284 bool is_tlab,
a61af66fc99e Initial load
duke
parents:
diff changeset
285 bool* gc_overhead_limit_was_exceeded) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 GenCollectedHeap *gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 debug_only(gch->check_for_valid_allocation_state());
a61af66fc99e Initial load
duke
parents:
diff changeset
289 assert(gch->no_gc_in_progress(), "Allocation during gc not allowed");
a61af66fc99e Initial load
duke
parents:
diff changeset
290 HeapWord* result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // Loop until the allocation is satisified,
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // or unsatisfied after GC.
a61af66fc99e Initial load
duke
parents:
diff changeset
294 for (int try_count = 1; /* return or throw */; try_count += 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 HandleMark hm; // discard any handles allocated in each iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // First allocation attempt is lock-free.
a61af66fc99e Initial load
duke
parents:
diff changeset
298 Generation *gen0 = gch->get_gen(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 assert(gen0->supports_inline_contig_alloc(),
a61af66fc99e Initial load
duke
parents:
diff changeset
300 "Otherwise, must do alloc within heap lock");
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if (gen0->should_allocate(size, is_tlab)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 result = gen0->par_allocate(size, is_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 assert(gch->is_in_reserved(result), "result not in heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
305 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 unsigned int gc_count_before; // read inside the Heap_lock locked region
a61af66fc99e Initial load
duke
parents:
diff changeset
309 {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 MutexLocker ml(Heap_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (PrintGC && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 gclog_or_tty->print_cr("TwoGenerationCollectorPolicy::mem_allocate_work:"
a61af66fc99e Initial load
duke
parents:
diff changeset
313 " attempting locked slow path allocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // Note that only large objects get a shot at being
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // allocated in later generations.
a61af66fc99e Initial load
duke
parents:
diff changeset
317 bool first_only = ! should_try_older_generation_allocation(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 result = gch->attempt_allocation(size, is_tlab, first_only);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 assert(gch->is_in_reserved(result), "result not in heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
322 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
323 }
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // There are NULL's returned for different circumstances below.
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // In general gc_overhead_limit_was_exceeded should be false so
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // set it so here and reset it to true only if the gc time
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // limit is being exceeded as checked below.
a61af66fc99e Initial load
duke
parents:
diff changeset
329 *gc_overhead_limit_was_exceeded = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (GC_locker::is_active_and_needs_gc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if (is_tlab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 return NULL; // Caller will retry allocating individual object
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (!gch->is_maximal_no_gc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // Try and expand heap to satisfy request
a61af66fc99e Initial load
duke
parents:
diff changeset
337 result = expand_heap_and_allocate(size, is_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // result could be null if we are out of space
a61af66fc99e Initial load
duke
parents:
diff changeset
339 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // If this thread is not in a jni critical section, we stall
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // the requestor until the critical section has cleared and
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // GC allowed. When the critical section clears, a GC is
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // initiated by the last thread exiting the critical section; so
a61af66fc99e Initial load
duke
parents:
diff changeset
348 // we retry the allocation sequence from the beginning of the loop,
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // rather than causing more, now probably unnecessary, GC attempts.
a61af66fc99e Initial load
duke
parents:
diff changeset
350 JavaThread* jthr = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (!jthr->in_critical()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 MutexUnlocker mul(Heap_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // Wait for JNI critical section to be exited
a61af66fc99e Initial load
duke
parents:
diff changeset
354 GC_locker::stall_until_clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
355 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (CheckJNICalls) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 fatal("Possible deadlock due to allocating while"
a61af66fc99e Initial load
duke
parents:
diff changeset
359 " in jni critical section");
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // Read the gc count while the heap lock is held.
a61af66fc99e Initial load
duke
parents:
diff changeset
366 gc_count_before = Universe::heap()->total_collections();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // Allocation has failed and a collection is about
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // to be done. If the gc time limit was exceeded the
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // last time a collection was done, return NULL so
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // that an out-of-memory will be thrown. Clear
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // gc_time_limit_exceeded so that subsequent attempts
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // at a collection will be made.
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (size_policy()->gc_time_limit_exceeded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 *gc_overhead_limit_was_exceeded = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 size_policy()->set_gc_time_limit_exceeded(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 VM_GenCollectForAllocation op(size,
a61af66fc99e Initial load
duke
parents:
diff changeset
382 is_tlab,
a61af66fc99e Initial load
duke
parents:
diff changeset
383 gc_count_before);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 VMThread::execute(&op);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (op.prologue_succeeded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 result = op.result();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 if (op.gc_locked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 assert(result == NULL, "must be NULL if gc_locked() is true");
a61af66fc99e Initial load
duke
parents:
diff changeset
389 continue; // retry and/or stall as necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391 assert(result == NULL || gch->is_in_reserved(result),
a61af66fc99e Initial load
duke
parents:
diff changeset
392 "result not in heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
393 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // Give a warning if we seem to be looping forever.
a61af66fc99e Initial load
duke
parents:
diff changeset
397 if ((QueuedAllocationWarningCount > 0) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
398 (try_count % QueuedAllocationWarningCount == 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 warning("TwoGenerationCollectorPolicy::mem_allocate_work retries %d times \n\t"
a61af66fc99e Initial load
duke
parents:
diff changeset
400 " size=%d %s", try_count, size, is_tlab ? "(TLAB)" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 HeapWord* GenCollectorPolicy::expand_heap_and_allocate(size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
406 bool is_tlab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 GenCollectedHeap *gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
408 HeapWord* result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 for (int i = number_of_generations() - 1; i >= 0 && result == NULL; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 Generation *gen = gch->get_gen(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 if (gen->should_allocate(size, is_tlab)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 result = gen->expand_and_allocate(size, is_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415 assert(result == NULL || gch->is_in_reserved(result), "result not in heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
416 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 HeapWord* GenCollectorPolicy::satisfy_failed_allocation(size_t size,
a61af66fc99e Initial load
duke
parents:
diff changeset
420 bool is_tlab) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 GenCollectedHeap *gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
422 GCCauseSetter x(gch, GCCause::_allocation_failure);
a61af66fc99e Initial load
duke
parents:
diff changeset
423 HeapWord* result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 assert(size != 0, "Precondition violated");
a61af66fc99e Initial load
duke
parents:
diff changeset
426 if (GC_locker::is_active_and_needs_gc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // GC locker is active; instead of a collection we will attempt
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // to expand the heap, if there's room for expansion.
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (!gch->is_maximal_no_gc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 result = expand_heap_and_allocate(size, is_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432 return result; // could be null if we are out of space
a61af66fc99e Initial load
duke
parents:
diff changeset
433 } else if (!gch->incremental_collection_will_fail()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // The gc_prologues have not executed yet. The value
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // for incremental_collection_will_fail() is the remanent
a61af66fc99e Initial load
duke
parents:
diff changeset
436 // of the last collection.
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // Do an incremental collection.
a61af66fc99e Initial load
duke
parents:
diff changeset
438 gch->do_collection(false /* full */,
a61af66fc99e Initial load
duke
parents:
diff changeset
439 false /* clear_all_soft_refs */,
a61af66fc99e Initial load
duke
parents:
diff changeset
440 size /* size */,
a61af66fc99e Initial load
duke
parents:
diff changeset
441 is_tlab /* is_tlab */,
a61af66fc99e Initial load
duke
parents:
diff changeset
442 number_of_generations() - 1 /* max_level */);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // Try a full collection; see delta for bug id 6266275
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // for the original code and why this has been simplified
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // with from-space allocation criteria modified and
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // such allocation moved out of the safepoint path.
a61af66fc99e Initial load
duke
parents:
diff changeset
448 gch->do_collection(true /* full */,
a61af66fc99e Initial load
duke
parents:
diff changeset
449 false /* clear_all_soft_refs */,
a61af66fc99e Initial load
duke
parents:
diff changeset
450 size /* size */,
a61af66fc99e Initial load
duke
parents:
diff changeset
451 is_tlab /* is_tlab */,
a61af66fc99e Initial load
duke
parents:
diff changeset
452 number_of_generations() - 1 /* max_level */);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 result = gch->attempt_allocation(size, is_tlab, false /*first_only*/);
a61af66fc99e Initial load
duke
parents:
diff changeset
456
a61af66fc99e Initial load
duke
parents:
diff changeset
457 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
458 assert(gch->is_in_reserved(result), "result not in heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
459 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // OK, collection failed, try expansion.
a61af66fc99e Initial load
duke
parents:
diff changeset
463 result = expand_heap_and_allocate(size, is_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // If we reach this point, we're really out of memory. Try every trick
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // we can to reclaim memory. Force collection of soft references. Force
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // a complete compaction of the heap. Any additional methods for finding
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // free memory should be here, especially if they are expensive. If this
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // attempt fails, an OOM exception will be thrown.
a61af66fc99e Initial load
duke
parents:
diff changeset
473 {
a61af66fc99e Initial load
duke
parents:
diff changeset
474 IntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 gch->do_collection(true /* full */,
a61af66fc99e Initial load
duke
parents:
diff changeset
477 true /* clear_all_soft_refs */,
a61af66fc99e Initial load
duke
parents:
diff changeset
478 size /* size */,
a61af66fc99e Initial load
duke
parents:
diff changeset
479 is_tlab /* is_tlab */,
a61af66fc99e Initial load
duke
parents:
diff changeset
480 number_of_generations() - 1 /* max_level */);
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 result = gch->attempt_allocation(size, is_tlab, false /* first_only */);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 if (result != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 assert(gch->is_in_reserved(result), "result not in heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
486 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // What else? We might try synchronous finalization later. If the total
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // space available is large enough for the allocation, then a more
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // complete compaction phase than we've tried so far might be
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // appropriate.
a61af66fc99e Initial load
duke
parents:
diff changeset
493 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 size_t GenCollectorPolicy::large_typearray_limit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 return FastAllocateSizeLimit;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // Return true if any of the following is true:
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // . the allocation won't fit into the current young gen heap
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // . gc locker is occupied (jni critical section)
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // . heap memory is tight -- the most recent previous collection
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // was a full collection because a partial collection (would
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // have) failed and is likely to fail again
a61af66fc99e Initial load
duke
parents:
diff changeset
506 bool GenCollectorPolicy::should_try_older_generation_allocation(
a61af66fc99e Initial load
duke
parents:
diff changeset
507 size_t word_size) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 GenCollectedHeap* gch = GenCollectedHeap::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 size_t gen0_capacity = gch->get_gen(0)->capacity_before_gc();
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return (word_size > heap_word_size(gen0_capacity))
a61af66fc99e Initial load
duke
parents:
diff changeset
511 || (GC_locker::is_active_and_needs_gc())
a61af66fc99e Initial load
duke
parents:
diff changeset
512 || ( gch->last_incremental_collection_failed()
a61af66fc99e Initial load
duke
parents:
diff changeset
513 && gch->incremental_collection_will_fail());
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 //
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // MarkSweepPolicy methods
a61af66fc99e Initial load
duke
parents:
diff changeset
519 //
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 MarkSweepPolicy::MarkSweepPolicy() {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 initialize_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 void MarkSweepPolicy::initialize_generations() {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 initialize_perm_generation(PermGen::MarkSweepCompact);
a61af66fc99e Initial load
duke
parents:
diff changeset
527 _generations = new GenerationSpecPtr[number_of_generations()];
a61af66fc99e Initial load
duke
parents:
diff changeset
528 if (_generations == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
529 vm_exit_during_initialization("Unable to allocate gen spec");
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 if (UseParNewGC && ParallelGCThreads > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 _generations[0] = new GenerationSpec(Generation::ParNew, _initial_gen0_size, _max_gen0_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
533 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 _generations[0] = new GenerationSpec(Generation::DefNew, _initial_gen0_size, _max_gen0_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536 _generations[1] = new GenerationSpec(Generation::MarkSweepCompact, _initial_gen1_size, _max_gen1_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 if (_generations[0] == NULL || _generations[1] == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
539 vm_exit_during_initialization("Unable to allocate gen spec");
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 void MarkSweepPolicy::initialize_gc_policy_counters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // initialize the policy counters - 2 collectors, 3 generations
a61af66fc99e Initial load
duke
parents:
diff changeset
544 if (UseParNewGC && ParallelGCThreads > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 _gc_policy_counters = new GCPolicyCounters("ParNew:MSC", 2, 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
546 }
a61af66fc99e Initial load
duke
parents:
diff changeset
547 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 _gc_policy_counters = new GCPolicyCounters("Copy:MSC", 2, 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }