Mercurial > hg > graal-jvmci-8
annotate src/share/vm/memory/generation.cpp @ 1888:a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
Summary: Deprecated HandlePromotionFailure, removing the ability to turn off that feature, did away with one epoch look-ahead when deciding if a scavenge is likely to fail, relying on current data.
Reviewed-by: jmasa, johnc, poonam
author | ysr |
---|---|
date | Sat, 23 Oct 2010 23:03:49 -0700 |
parents | c18cbe5936b8 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1051
diff
changeset
|
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1051
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1051
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:
1051
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_generation.cpp.incl" | |
27 | |
28 Generation::Generation(ReservedSpace rs, size_t initial_size, int level) : | |
29 _level(level), | |
30 _ref_processor(NULL) { | |
31 if (!_virtual_space.initialize(rs, initial_size)) { | |
32 vm_exit_during_initialization("Could not reserve enough space for " | |
33 "object heap"); | |
34 } | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
35 // Mangle all of the the initial generation. |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
36 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
37 MemRegion mangle_region((HeapWord*)_virtual_space.low(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
38 (HeapWord*)_virtual_space.high()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
39 SpaceMangler::mangle_region(mangle_region); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
40 } |
0 | 41 _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(), |
42 (HeapWord*)_virtual_space.high_boundary()); | |
43 } | |
44 | |
45 GenerationSpec* Generation::spec() { | |
46 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
47 assert(0 <= level() && level() < gch->_n_gens, "Bad gen level"); | |
48 return gch->_gen_specs[level()]; | |
49 } | |
50 | |
51 size_t Generation::max_capacity() const { | |
52 return reserved().byte_size(); | |
53 } | |
54 | |
55 void Generation::print_heap_change(size_t prev_used) const { | |
56 if (PrintGCDetails && Verbose) { | |
57 gclog_or_tty->print(" " SIZE_FORMAT | |
58 "->" SIZE_FORMAT | |
59 "(" SIZE_FORMAT ")", | |
60 prev_used, used(), capacity()); | |
61 } else { | |
62 gclog_or_tty->print(" " SIZE_FORMAT "K" | |
63 "->" SIZE_FORMAT "K" | |
64 "(" SIZE_FORMAT "K)", | |
65 prev_used / K, used() / K, capacity() / K); | |
66 } | |
67 } | |
68 | |
69 // By default we get a single threaded default reference processor; | |
70 // generations needing multi-threaded refs discovery override this method. | |
71 void Generation::ref_processor_init() { | |
72 assert(_ref_processor == NULL, "a reference processor already exists"); | |
73 assert(!_reserved.is_empty(), "empty generation?"); | |
74 _ref_processor = | |
75 new ReferenceProcessor(_reserved, // span | |
76 refs_discovery_is_atomic(), // atomic_discovery | |
77 refs_discovery_is_mt()); // mt_discovery | |
78 if (_ref_processor == NULL) { | |
79 vm_exit_during_initialization("Could not allocate ReferenceProcessor object"); | |
80 } | |
81 } | |
82 | |
83 void Generation::print() const { print_on(tty); } | |
84 | |
85 void Generation::print_on(outputStream* st) const { | |
86 st->print(" %-20s", name()); | |
87 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K", | |
88 capacity()/K, used()/K); | |
89 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", | |
90 _virtual_space.low_boundary(), | |
91 _virtual_space.high(), | |
92 _virtual_space.high_boundary()); | |
93 } | |
94 | |
95 void Generation::print_summary_info() { print_summary_info_on(tty); } | |
96 | |
97 void Generation::print_summary_info_on(outputStream* st) { | |
98 StatRecord* sr = stat_record(); | |
99 double time = sr->accumulated_time.seconds(); | |
100 st->print_cr("[Accumulated GC generation %d time %3.7f secs, " | |
101 "%d GC's, avg GC time %3.7f]", | |
102 level(), time, sr->invocations, | |
103 sr->invocations > 0 ? time / sr->invocations : 0.0); | |
104 } | |
105 | |
106 // Utility iterator classes | |
107 | |
108 class GenerationIsInReservedClosure : public SpaceClosure { | |
109 public: | |
110 const void* _p; | |
111 Space* sp; | |
112 virtual void do_space(Space* s) { | |
113 if (sp == NULL) { | |
114 if (s->is_in_reserved(_p)) sp = s; | |
115 } | |
116 } | |
117 GenerationIsInReservedClosure(const void* p) : _p(p), sp(NULL) {} | |
118 }; | |
119 | |
120 class GenerationIsInClosure : public SpaceClosure { | |
121 public: | |
122 const void* _p; | |
123 Space* sp; | |
124 virtual void do_space(Space* s) { | |
125 if (sp == NULL) { | |
126 if (s->is_in(_p)) sp = s; | |
127 } | |
128 } | |
129 GenerationIsInClosure(const void* p) : _p(p), sp(NULL) {} | |
130 }; | |
131 | |
132 bool Generation::is_in(const void* p) const { | |
133 GenerationIsInClosure blk(p); | |
134 ((Generation*)this)->space_iterate(&blk); | |
135 return blk.sp != NULL; | |
136 } | |
137 | |
138 DefNewGeneration* Generation::as_DefNewGeneration() { | |
139 assert((kind() == Generation::DefNew) || | |
140 (kind() == Generation::ParNew) || | |
141 (kind() == Generation::ASParNew), | |
142 "Wrong youngest generation type"); | |
143 return (DefNewGeneration*) this; | |
144 } | |
145 | |
146 Generation* Generation::next_gen() const { | |
147 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
148 int next = level() + 1; | |
149 if (next < gch->_n_gens) { | |
150 return gch->_gens[next]; | |
151 } else { | |
152 return NULL; | |
153 } | |
154 } | |
155 | |
156 size_t Generation::max_contiguous_available() const { | |
157 // The largest number of contiguous free words in this or any higher generation. | |
158 size_t max = 0; | |
159 for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) { | |
160 size_t avail = gen->contiguous_available(); | |
161 if (avail > max) { | |
162 max = avail; | |
163 } | |
164 } | |
165 return max; | |
166 } | |
167 | |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
168 bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const { |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
169 size_t available = max_contiguous_available(); |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
170 bool res = (available >= max_promotion_in_bytes); |
0 | 171 if (PrintGC && Verbose) { |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
172 gclog_or_tty->print_cr( |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
173 "Generation: promo attempt is%s safe: available("SIZE_FORMAT") %s max_promo("SIZE_FORMAT")", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
174 res? "":" not", available, res? ">=":"<", |
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
175 max_promotion_in_bytes); |
0 | 176 } |
1888
a7214d79fcf1
6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
ysr
parents:
1552
diff
changeset
|
177 return res; |
0 | 178 } |
179 | |
180 // Ignores "ref" and calls allocate(). | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
181 oop Generation::promote(oop obj, size_t obj_size) { |
0 | 182 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in"); |
183 | |
184 #ifndef PRODUCT | |
185 if (Universe::heap()->promotion_should_fail()) { | |
186 return NULL; | |
187 } | |
188 #endif // #ifndef PRODUCT | |
189 | |
190 HeapWord* result = allocate(obj_size, false); | |
191 if (result != NULL) { | |
192 Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size); | |
193 return oop(result); | |
194 } else { | |
195 GenCollectedHeap* gch = GenCollectedHeap::heap(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
196 return gch->handle_failed_promotion(this, obj, obj_size); |
0 | 197 } |
198 } | |
199 | |
200 oop Generation::par_promote(int thread_num, | |
201 oop obj, markOop m, size_t word_sz) { | |
202 // Could do a bad general impl here that gets a lock. But no. | |
203 ShouldNotCallThis(); | |
204 return NULL; | |
205 } | |
206 | |
207 void Generation::par_promote_alloc_undo(int thread_num, | |
208 HeapWord* obj, size_t word_sz) { | |
209 // Could do a bad general impl here that gets a lock. But no. | |
210 guarantee(false, "No good general implementation."); | |
211 } | |
212 | |
213 Space* Generation::space_containing(const void* p) const { | |
214 GenerationIsInReservedClosure blk(p); | |
215 // Cast away const | |
216 ((Generation*)this)->space_iterate(&blk); | |
217 return blk.sp; | |
218 } | |
219 | |
220 // Some of these are mediocre general implementations. Should be | |
221 // overridden to get better performance. | |
222 | |
223 class GenerationBlockStartClosure : public SpaceClosure { | |
224 public: | |
225 const void* _p; | |
226 HeapWord* _start; | |
227 virtual void do_space(Space* s) { | |
228 if (_start == NULL && s->is_in_reserved(_p)) { | |
229 _start = s->block_start(_p); | |
230 } | |
231 } | |
232 GenerationBlockStartClosure(const void* p) { _p = p; _start = NULL; } | |
233 }; | |
234 | |
235 HeapWord* Generation::block_start(const void* p) const { | |
236 GenerationBlockStartClosure blk(p); | |
237 // Cast away const | |
238 ((Generation*)this)->space_iterate(&blk); | |
239 return blk._start; | |
240 } | |
241 | |
242 class GenerationBlockSizeClosure : public SpaceClosure { | |
243 public: | |
244 const HeapWord* _p; | |
245 size_t size; | |
246 virtual void do_space(Space* s) { | |
247 if (size == 0 && s->is_in_reserved(_p)) { | |
248 size = s->block_size(_p); | |
249 } | |
250 } | |
251 GenerationBlockSizeClosure(const HeapWord* p) { _p = p; size = 0; } | |
252 }; | |
253 | |
254 size_t Generation::block_size(const HeapWord* p) const { | |
255 GenerationBlockSizeClosure blk(p); | |
256 // Cast away const | |
257 ((Generation*)this)->space_iterate(&blk); | |
258 assert(blk.size > 0, "seems reasonable"); | |
259 return blk.size; | |
260 } | |
261 | |
262 class GenerationBlockIsObjClosure : public SpaceClosure { | |
263 public: | |
264 const HeapWord* _p; | |
265 bool is_obj; | |
266 virtual void do_space(Space* s) { | |
267 if (!is_obj && s->is_in_reserved(_p)) { | |
268 is_obj |= s->block_is_obj(_p); | |
269 } | |
270 } | |
271 GenerationBlockIsObjClosure(const HeapWord* p) { _p = p; is_obj = false; } | |
272 }; | |
273 | |
274 bool Generation::block_is_obj(const HeapWord* p) const { | |
275 GenerationBlockIsObjClosure blk(p); | |
276 // Cast away const | |
277 ((Generation*)this)->space_iterate(&blk); | |
278 return blk.is_obj; | |
279 } | |
280 | |
281 class GenerationOopIterateClosure : public SpaceClosure { | |
282 public: | |
283 OopClosure* cl; | |
284 MemRegion mr; | |
285 virtual void do_space(Space* s) { | |
286 s->oop_iterate(mr, cl); | |
287 } | |
288 GenerationOopIterateClosure(OopClosure* _cl, MemRegion _mr) : | |
289 cl(_cl), mr(_mr) {} | |
290 }; | |
291 | |
292 void Generation::oop_iterate(OopClosure* cl) { | |
293 GenerationOopIterateClosure blk(cl, _reserved); | |
294 space_iterate(&blk); | |
295 } | |
296 | |
297 void Generation::oop_iterate(MemRegion mr, OopClosure* cl) { | |
298 GenerationOopIterateClosure blk(cl, mr); | |
299 space_iterate(&blk); | |
300 } | |
301 | |
302 void Generation::younger_refs_in_space_iterate(Space* sp, | |
303 OopsInGenClosure* cl) { | |
304 GenRemSet* rs = SharedHeap::heap()->rem_set(); | |
305 rs->younger_refs_in_space_iterate(sp, cl); | |
306 } | |
307 | |
308 class GenerationObjIterateClosure : public SpaceClosure { | |
309 private: | |
310 ObjectClosure* _cl; | |
311 public: | |
312 virtual void do_space(Space* s) { | |
313 s->object_iterate(_cl); | |
314 } | |
315 GenerationObjIterateClosure(ObjectClosure* cl) : _cl(cl) {} | |
316 }; | |
317 | |
318 void Generation::object_iterate(ObjectClosure* cl) { | |
319 GenerationObjIterateClosure blk(cl); | |
320 space_iterate(&blk); | |
321 } | |
322 | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
323 class GenerationSafeObjIterateClosure : public SpaceClosure { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
324 private: |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
325 ObjectClosure* _cl; |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
326 public: |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
327 virtual void do_space(Space* s) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
328 s->safe_object_iterate(_cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
329 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
330 GenerationSafeObjIterateClosure(ObjectClosure* cl) : _cl(cl) {} |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
331 }; |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
332 |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
333 void Generation::safe_object_iterate(ObjectClosure* cl) { |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
334 GenerationSafeObjIterateClosure blk(cl); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
335 space_iterate(&blk); |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
336 } |
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
271
diff
changeset
|
337 |
0 | 338 void Generation::prepare_for_compaction(CompactPoint* cp) { |
339 // Generic implementation, can be specialized | |
340 CompactibleSpace* space = first_compaction_space(); | |
341 while (space != NULL) { | |
342 space->prepare_for_compaction(cp); | |
343 space = space->next_compaction_space(); | |
344 } | |
345 } | |
346 | |
347 class AdjustPointersClosure: public SpaceClosure { | |
348 public: | |
349 void do_space(Space* sp) { | |
350 sp->adjust_pointers(); | |
351 } | |
352 }; | |
353 | |
354 void Generation::adjust_pointers() { | |
355 // Note that this is done over all spaces, not just the compactible | |
356 // ones. | |
357 AdjustPointersClosure blk; | |
358 space_iterate(&blk, true); | |
359 } | |
360 | |
361 void Generation::compact() { | |
362 CompactibleSpace* sp = first_compaction_space(); | |
363 while (sp != NULL) { | |
364 sp->compact(); | |
365 sp = sp->next_compaction_space(); | |
366 } | |
367 } | |
368 | |
369 CardGeneration::CardGeneration(ReservedSpace rs, size_t initial_byte_size, | |
370 int level, | |
371 GenRemSet* remset) : | |
372 Generation(rs, initial_byte_size, level), _rs(remset) | |
373 { | |
374 HeapWord* start = (HeapWord*)rs.base(); | |
375 size_t reserved_byte_size = rs.size(); | |
376 assert((uintptr_t(start) & 3) == 0, "bad alignment"); | |
377 assert((reserved_byte_size & 3) == 0, "bad alignment"); | |
378 MemRegion reserved_mr(start, heap_word_size(reserved_byte_size)); | |
379 _bts = new BlockOffsetSharedArray(reserved_mr, | |
380 heap_word_size(initial_byte_size)); | |
381 MemRegion committed_mr(start, heap_word_size(initial_byte_size)); | |
382 _rs->resize_covered_region(committed_mr); | |
383 if (_bts == NULL) | |
384 vm_exit_during_initialization("Could not allocate a BlockOffsetArray"); | |
385 | |
386 // Verify that the start and end of this generation is the start of a card. | |
387 // If this wasn't true, a single card could span more than on generation, | |
388 // which would cause problems when we commit/uncommit memory, and when we | |
389 // clear and dirty cards. | |
390 guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned"); | |
391 if (reserved_mr.end() != Universe::heap()->reserved_region().end()) { | |
392 // Don't check at the very end of the heap as we'll assert that we're probing off | |
393 // the end if we try. | |
394 guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned"); | |
395 } | |
396 } | |
397 | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
398 bool CardGeneration::expand(size_t bytes, size_t expand_bytes) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
399 assert_locked_or_safepoint(Heap_lock); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
400 if (bytes == 0) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
401 return true; // That's what grow_by(0) would return |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
402 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
403 size_t aligned_bytes = ReservedSpace::page_align_size_up(bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
404 if (aligned_bytes == 0){ |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
405 // The alignment caused the number of bytes to wrap. An expand_by(0) will |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
406 // return true with the implication that an expansion was done when it |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
407 // was not. A call to expand implies a best effort to expand by "bytes" |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
408 // but not a guarantee. Align down to give a best effort. This is likely |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
409 // the most that the generation can expand since it has some capacity to |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
410 // start with. |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
411 aligned_bytes = ReservedSpace::page_align_size_down(bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
412 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
413 size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
414 bool success = false; |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
415 if (aligned_expand_bytes > aligned_bytes) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
416 success = grow_by(aligned_expand_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
417 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
418 if (!success) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
419 success = grow_by(aligned_bytes); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
420 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
421 if (!success) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
422 success = grow_to_reserved(); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
423 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
424 if (PrintGC && Verbose) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
425 if (success && GC_locker::is_active()) { |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
426 gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead"); |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
427 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
428 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
429 |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
430 return success; |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
431 } |
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
432 |
0 | 433 |
434 // No young generation references, clear this generation's cards. | |
435 void CardGeneration::clear_remembered_set() { | |
436 _rs->clear(reserved()); | |
437 } | |
438 | |
439 | |
440 // Objects in this generation may have moved, invalidate this | |
441 // generation's cards. | |
442 void CardGeneration::invalidate_remembered_set() { | |
443 _rs->invalidate(used_region()); | |
444 } | |
445 | |
446 | |
447 // Currently nothing to do. | |
448 void CardGeneration::prepare_for_verify() {} | |
449 | |
450 | |
451 void OneContigSpaceCardGeneration::collect(bool full, | |
452 bool clear_all_soft_refs, | |
453 size_t size, | |
454 bool is_tlab) { | |
455 SpecializationStats::clear(); | |
456 // Temporarily expand the span of our ref processor, so | |
457 // refs discovery is over the entire heap, not just this generation | |
458 ReferenceProcessorSpanMutator | |
459 x(ref_processor(), GenCollectedHeap::heap()->reserved_region()); | |
460 GenMarkSweep::invoke_at_safepoint(_level, ref_processor(), clear_all_soft_refs); | |
461 SpecializationStats::print(); | |
462 } | |
463 | |
464 HeapWord* | |
465 OneContigSpaceCardGeneration::expand_and_allocate(size_t word_size, | |
466 bool is_tlab, | |
467 bool parallel) { | |
468 assert(!is_tlab, "OneContigSpaceCardGeneration does not support TLAB allocation"); | |
469 if (parallel) { | |
470 MutexLocker x(ParGCRareEvent_lock); | |
471 HeapWord* result = NULL; | |
472 size_t byte_size = word_size * HeapWordSize; | |
473 while (true) { | |
474 expand(byte_size, _min_heap_delta_bytes); | |
475 if (GCExpandToAllocateDelayMillis > 0) { | |
476 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false); | |
477 } | |
478 result = _the_space->par_allocate(word_size); | |
479 if ( result != NULL) { | |
480 return result; | |
481 } else { | |
482 // If there's not enough expansion space available, give up. | |
483 if (_virtual_space.uncommitted_size() < byte_size) { | |
484 return NULL; | |
485 } | |
486 // else try again | |
487 } | |
488 } | |
489 } else { | |
490 expand(word_size*HeapWordSize, _min_heap_delta_bytes); | |
491 return _the_space->allocate(word_size); | |
492 } | |
493 } | |
494 | |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
495 bool OneContigSpaceCardGeneration::expand(size_t bytes, size_t expand_bytes) { |
0 | 496 GCMutexLocker x(ExpandHeap_lock); |
271
818a18cd69a8
6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents:
269
diff
changeset
|
497 return CardGeneration::expand(bytes, expand_bytes); |
0 | 498 } |
499 | |
500 | |
501 void OneContigSpaceCardGeneration::shrink(size_t bytes) { | |
502 assert_locked_or_safepoint(ExpandHeap_lock); | |
503 size_t size = ReservedSpace::page_align_size_down(bytes); | |
504 if (size > 0) { | |
505 shrink_by(size); | |
506 } | |
507 } | |
508 | |
509 | |
510 size_t OneContigSpaceCardGeneration::capacity() const { | |
511 return _the_space->capacity(); | |
512 } | |
513 | |
514 | |
515 size_t OneContigSpaceCardGeneration::used() const { | |
516 return _the_space->used(); | |
517 } | |
518 | |
519 | |
520 size_t OneContigSpaceCardGeneration::free() const { | |
521 return _the_space->free(); | |
522 } | |
523 | |
524 MemRegion OneContigSpaceCardGeneration::used_region() const { | |
525 return the_space()->used_region(); | |
526 } | |
527 | |
528 size_t OneContigSpaceCardGeneration::unsafe_max_alloc_nogc() const { | |
529 return _the_space->free(); | |
530 } | |
531 | |
532 size_t OneContigSpaceCardGeneration::contiguous_available() const { | |
533 return _the_space->free() + _virtual_space.uncommitted_size(); | |
534 } | |
535 | |
536 bool OneContigSpaceCardGeneration::grow_by(size_t bytes) { | |
537 assert_locked_or_safepoint(ExpandHeap_lock); | |
538 bool result = _virtual_space.expand_by(bytes); | |
539 if (result) { | |
540 size_t new_word_size = | |
541 heap_word_size(_virtual_space.committed_size()); | |
542 MemRegion mr(_the_space->bottom(), new_word_size); | |
543 // Expand card table | |
544 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
545 // Expand shared block offset array | |
546 _bts->resize(new_word_size); | |
547 | |
548 // Fix for bug #4668531 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
549 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
550 MemRegion mangle_region(_the_space->end(), |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
551 (HeapWord*)_virtual_space.high()); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
552 SpaceMangler::mangle_region(mangle_region); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
553 } |
0 | 554 |
555 // Expand space -- also expands space's BOT | |
556 // (which uses (part of) shared array above) | |
557 _the_space->set_end((HeapWord*)_virtual_space.high()); | |
558 | |
559 // update the space and generation capacity counters | |
560 update_counters(); | |
561 | |
562 if (Verbose && PrintGC) { | |
563 size_t new_mem_size = _virtual_space.committed_size(); | |
564 size_t old_mem_size = new_mem_size - bytes; | |
565 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by " | |
566 SIZE_FORMAT "K to " SIZE_FORMAT "K", | |
567 name(), old_mem_size/K, bytes/K, new_mem_size/K); | |
568 } | |
569 } | |
570 return result; | |
571 } | |
572 | |
573 | |
574 bool OneContigSpaceCardGeneration::grow_to_reserved() { | |
575 assert_locked_or_safepoint(ExpandHeap_lock); | |
576 bool success = true; | |
577 const size_t remaining_bytes = _virtual_space.uncommitted_size(); | |
578 if (remaining_bytes > 0) { | |
579 success = grow_by(remaining_bytes); | |
580 DEBUG_ONLY(if (!success) warning("grow to reserved failed");) | |
581 } | |
582 return success; | |
583 } | |
584 | |
585 void OneContigSpaceCardGeneration::shrink_by(size_t bytes) { | |
586 assert_locked_or_safepoint(ExpandHeap_lock); | |
587 // Shrink committed space | |
588 _virtual_space.shrink_by(bytes); | |
589 // Shrink space; this also shrinks the space's BOT | |
590 _the_space->set_end((HeapWord*) _virtual_space.high()); | |
591 size_t new_word_size = heap_word_size(_the_space->capacity()); | |
592 // Shrink the shared block offset array | |
593 _bts->resize(new_word_size); | |
594 MemRegion mr(_the_space->bottom(), new_word_size); | |
595 // Shrink the card table | |
596 Universe::heap()->barrier_set()->resize_covered_region(mr); | |
597 | |
598 if (Verbose && PrintGC) { | |
599 size_t new_mem_size = _virtual_space.committed_size(); | |
600 size_t old_mem_size = new_mem_size + bytes; | |
601 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K", | |
602 name(), old_mem_size/K, new_mem_size/K); | |
603 } | |
604 } | |
605 | |
606 // Currently nothing to do. | |
607 void OneContigSpaceCardGeneration::prepare_for_verify() {} | |
608 | |
609 | |
1051
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
610 // Override for a card-table generation with one contiguous |
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
611 // space. NOTE: For reasons that are lost in the fog of history, |
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
612 // this code is used when you iterate over perm gen objects, |
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
613 // even when one uses CDS, where the perm gen has a couple of |
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
614 // other spaces; this is because CompactingPermGenGen derives |
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
615 // from OneContigSpaceCardGeneration. This should be cleaned up, |
26f1542097f1
6801625: CDS: HeapDump tests crash with internal error in compactingPermGenGen.cpp
ysr
parents:
579
diff
changeset
|
616 // see CR 6897789.. |
0 | 617 void OneContigSpaceCardGeneration::object_iterate(ObjectClosure* blk) { |
618 _the_space->object_iterate(blk); | |
619 } | |
620 | |
621 void OneContigSpaceCardGeneration::space_iterate(SpaceClosure* blk, | |
622 bool usedOnly) { | |
623 blk->do_space(_the_space); | |
624 } | |
625 | |
626 void OneContigSpaceCardGeneration::object_iterate_since_last_GC(ObjectClosure* blk) { | |
627 // Deal with delayed initialization of _the_space, | |
628 // and lack of initialization of _last_gc. | |
629 if (_last_gc.space() == NULL) { | |
630 assert(the_space() != NULL, "shouldn't be NULL"); | |
631 _last_gc = the_space()->bottom_mark(); | |
632 } | |
633 the_space()->object_iterate_from(_last_gc, blk); | |
634 } | |
635 | |
636 void OneContigSpaceCardGeneration::younger_refs_iterate(OopsInGenClosure* blk) { | |
637 blk->set_generation(this); | |
638 younger_refs_in_space_iterate(_the_space, blk); | |
639 blk->reset_generation(); | |
640 } | |
641 | |
642 void OneContigSpaceCardGeneration::save_marks() { | |
643 _the_space->set_saved_mark(); | |
644 } | |
645 | |
646 | |
647 void OneContigSpaceCardGeneration::reset_saved_marks() { | |
648 _the_space->reset_saved_mark(); | |
649 } | |
650 | |
651 | |
652 bool OneContigSpaceCardGeneration::no_allocs_since_save_marks() { | |
653 return _the_space->saved_mark_at_top(); | |
654 } | |
655 | |
656 #define OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \ | |
657 \ | |
658 void OneContigSpaceCardGeneration:: \ | |
659 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \ | |
660 blk->set_generation(this); \ | |
661 _the_space->oop_since_save_marks_iterate##nv_suffix(blk); \ | |
662 blk->reset_generation(); \ | |
663 save_marks(); \ | |
664 } | |
665 | |
666 ALL_SINCE_SAVE_MARKS_CLOSURES(OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN) | |
667 | |
668 #undef OneContig_SINCE_SAVE_MARKS_ITERATE_DEFN | |
669 | |
670 | |
671 void OneContigSpaceCardGeneration::gc_epilogue(bool full) { | |
672 _last_gc = WaterMark(the_space(), the_space()->top()); | |
673 | |
674 // update the generation and space performance counters | |
675 update_counters(); | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
676 if (ZapUnusedHeapArea) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
677 the_space()->check_mangled_unused_area_complete(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
678 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
679 } |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
680 |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
681 void OneContigSpaceCardGeneration::record_spaces_top() { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
682 assert(ZapUnusedHeapArea, "Not mangling unused space"); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
683 the_space()->set_top_for_allocations(); |
0 | 684 } |
685 | |
686 void OneContigSpaceCardGeneration::verify(bool allow_dirty) { | |
687 the_space()->verify(allow_dirty); | |
688 } | |
689 | |
690 void OneContigSpaceCardGeneration::print_on(outputStream* st) const { | |
691 Generation::print_on(st); | |
692 st->print(" the"); | |
693 the_space()->print_on(st); | |
694 } |