Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parallelScavenge/psMarkSweepDecorator.cpp @ 4132:6d7d0790074d
7119584: UseParallelGC barrier task can be overwritten.
Summary: Provoke a GC for a metadata allocation failure.
Reviewed-by: johnc, iveresov
author | jmasa |
---|---|
date | Fri, 09 Dec 2011 19:28:34 -0800 |
parents | d06a2d7fcd5b |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
4091
d06a2d7fcd5b
7110718: -XX:MarkSweepAlwaysCompactCount=0 crashes the JVM
brutisso
parents:
1972
diff
changeset
|
2 * Copyright (c) 2001, 2011, 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:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
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:
579
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "gc_implementation/parallelScavenge/objectStartArray.hpp" | |
28 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" | |
29 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp" | |
30 #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp" | |
31 #include "gc_implementation/shared/liveRange.hpp" | |
32 #include "gc_implementation/shared/markSweep.inline.hpp" | |
33 #include "gc_implementation/shared/spaceDecorator.hpp" | |
34 #include "oops/oop.inline.hpp" | |
0 | 35 |
36 PSMarkSweepDecorator* PSMarkSweepDecorator::_destination_decorator = NULL; | |
37 | |
38 | |
39 void PSMarkSweepDecorator::set_destination_decorator_tenured() { | |
40 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
41 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
42 | |
43 _destination_decorator = heap->old_gen()->object_mark_sweep(); | |
44 } | |
45 | |
46 void PSMarkSweepDecorator::set_destination_decorator_perm_gen() { | |
47 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
48 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
49 | |
50 _destination_decorator = heap->perm_gen()->object_mark_sweep(); | |
51 } | |
52 | |
53 void PSMarkSweepDecorator::advance_destination_decorator() { | |
54 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); | |
55 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); | |
56 | |
57 assert(_destination_decorator != NULL, "Sanity"); | |
58 guarantee(_destination_decorator != heap->perm_gen()->object_mark_sweep(), "Cannot advance perm gen decorator"); | |
59 | |
60 PSMarkSweepDecorator* first = heap->old_gen()->object_mark_sweep(); | |
61 PSMarkSweepDecorator* second = heap->young_gen()->eden_mark_sweep(); | |
62 PSMarkSweepDecorator* third = heap->young_gen()->from_mark_sweep(); | |
63 PSMarkSweepDecorator* fourth = heap->young_gen()->to_mark_sweep(); | |
64 | |
65 if ( _destination_decorator == first ) { | |
66 _destination_decorator = second; | |
67 } else if ( _destination_decorator == second ) { | |
68 _destination_decorator = third; | |
69 } else if ( _destination_decorator == third ) { | |
70 _destination_decorator = fourth; | |
71 } else { | |
72 fatal("PSMarkSweep attempting to advance past last compaction area"); | |
73 } | |
74 } | |
75 | |
76 PSMarkSweepDecorator* PSMarkSweepDecorator::destination_decorator() { | |
77 assert(_destination_decorator != NULL, "Sanity"); | |
78 | |
79 return _destination_decorator; | |
80 } | |
81 | |
82 // FIX ME FIX ME FIX ME FIX ME!!!!!!!!! | |
83 // The object forwarding code is duplicated. Factor this out!!!!! | |
84 // | |
85 // This method "precompacts" objects inside its space to dest. It places forwarding | |
86 // pointers into markOops for use by adjust_pointers. If "dest" should overflow, we | |
87 // finish by compacting into our own space. | |
88 | |
89 void PSMarkSweepDecorator::precompact() { | |
90 // Reset our own compact top. | |
91 set_compaction_top(space()->bottom()); | |
92 | |
93 /* We allow some amount of garbage towards the bottom of the space, so | |
94 * we don't start compacting before there is a significant gain to be made. | |
95 * Occasionally, we want to ensure a full compaction, which is determined | |
96 * by the MarkSweepAlwaysCompactCount parameter. This is a significant | |
97 * performance improvement! | |
98 */ | |
4091
d06a2d7fcd5b
7110718: -XX:MarkSweepAlwaysCompactCount=0 crashes the JVM
brutisso
parents:
1972
diff
changeset
|
99 bool skip_dead = (MarkSweepAlwaysCompactCount < 1) |
d06a2d7fcd5b
7110718: -XX:MarkSweepAlwaysCompactCount=0 crashes the JVM
brutisso
parents:
1972
diff
changeset
|
100 || ((PSMarkSweep::total_invocations() % MarkSweepAlwaysCompactCount) != 0); |
0 | 101 |
438 | 102 size_t allowed_deadspace = 0; |
0 | 103 if (skip_dead) { |
438 | 104 const size_t ratio = allowed_dead_ratio(); |
105 allowed_deadspace = space()->capacity_in_words() * ratio / 100; | |
0 | 106 } |
107 | |
108 // Fetch the current destination decorator | |
109 PSMarkSweepDecorator* dest = destination_decorator(); | |
110 ObjectStartArray* start_array = dest->start_array(); | |
111 | |
112 HeapWord* compact_top = dest->compaction_top(); | |
113 HeapWord* compact_end = dest->space()->end(); | |
114 | |
115 HeapWord* q = space()->bottom(); | |
116 HeapWord* t = space()->top(); | |
117 | |
118 HeapWord* end_of_live= q; /* One byte beyond the last byte of the last | |
119 live object. */ | |
120 HeapWord* first_dead = space()->end(); /* The first dead object. */ | |
121 LiveRange* liveRange = NULL; /* The current live range, recorded in the | |
122 first header of preceding free area. */ | |
123 _first_dead = first_dead; | |
124 | |
125 const intx interval = PrefetchScanIntervalInBytes; | |
126 | |
127 while (q < t) { | |
128 assert(oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() || | |
129 oop(q)->mark()->has_bias_pattern(), | |
130 "these are the only valid states during a mark sweep"); | |
131 if (oop(q)->is_gc_marked()) { | |
132 /* prefetch beyond q */ | |
133 Prefetch::write(q, interval); | |
134 size_t size = oop(q)->size(); | |
135 | |
136 size_t compaction_max_size = pointer_delta(compact_end, compact_top); | |
137 | |
138 // This should only happen if a space in the young gen overflows the | |
139 // old gen. If that should happen, we null out the start_array, because | |
140 // the young spaces are not covered by one. | |
141 while(size > compaction_max_size) { | |
142 // First record the last compact_top | |
143 dest->set_compaction_top(compact_top); | |
144 | |
145 // Advance to the next compaction decorator | |
146 advance_destination_decorator(); | |
147 dest = destination_decorator(); | |
148 | |
149 // Update compaction info | |
150 start_array = dest->start_array(); | |
151 compact_top = dest->compaction_top(); | |
152 compact_end = dest->space()->end(); | |
153 assert(compact_top == dest->space()->bottom(), "Advanced to space already in use"); | |
154 assert(compact_end > compact_top, "Must always be space remaining"); | |
155 compaction_max_size = | |
156 pointer_delta(compact_end, compact_top); | |
157 } | |
158 | |
159 // store the forwarding pointer into the mark word | |
160 if (q != compact_top) { | |
161 oop(q)->forward_to(oop(compact_top)); | |
162 assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark"); | |
163 } else { | |
374
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
164 // if the object isn't moving we can just set the mark to the default |
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
165 // mark and handle it specially later on. |
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
166 oop(q)->init_mark(); |
0 | 167 assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL"); |
168 } | |
169 | |
170 // Update object start array | |
374
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
171 if (start_array) { |
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
172 start_array->allocate_block(compact_top); |
0 | 173 } |
174 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
175 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(oop(q), size)); |
0 | 176 compact_top += size; |
177 assert(compact_top <= dest->space()->end(), | |
178 "Exceeding space in destination"); | |
179 | |
180 q += size; | |
181 end_of_live = q; | |
182 } else { | |
183 /* run over all the contiguous dead objects */ | |
184 HeapWord* end = q; | |
185 do { | |
186 /* prefetch beyond end */ | |
187 Prefetch::write(end, interval); | |
188 end += oop(end)->size(); | |
189 } while (end < t && (!oop(end)->is_gc_marked())); | |
190 | |
191 /* see if we might want to pretend this object is alive so that | |
192 * we don't have to compact quite as often. | |
193 */ | |
194 if (allowed_deadspace > 0 && q == compact_top) { | |
195 size_t sz = pointer_delta(end, q); | |
196 if (insert_deadspace(allowed_deadspace, q, sz)) { | |
197 size_t compaction_max_size = pointer_delta(compact_end, compact_top); | |
198 | |
199 // This should only happen if a space in the young gen overflows the | |
200 // old gen. If that should happen, we null out the start_array, because | |
201 // the young spaces are not covered by one. | |
202 while (sz > compaction_max_size) { | |
203 // First record the last compact_top | |
204 dest->set_compaction_top(compact_top); | |
205 | |
206 // Advance to the next compaction decorator | |
207 advance_destination_decorator(); | |
208 dest = destination_decorator(); | |
209 | |
210 // Update compaction info | |
211 start_array = dest->start_array(); | |
212 compact_top = dest->compaction_top(); | |
213 compact_end = dest->space()->end(); | |
214 assert(compact_top == dest->space()->bottom(), "Advanced to space already in use"); | |
215 assert(compact_end > compact_top, "Must always be space remaining"); | |
216 compaction_max_size = | |
217 pointer_delta(compact_end, compact_top); | |
218 } | |
219 | |
220 // store the forwarding pointer into the mark word | |
221 if (q != compact_top) { | |
222 oop(q)->forward_to(oop(compact_top)); | |
223 assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark"); | |
224 } else { | |
225 // if the object isn't moving we can just set the mark to the default | |
374
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
226 // mark and handle it specially later on. |
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
227 oop(q)->init_mark(); |
0 | 228 assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL"); |
229 } | |
230 | |
374
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
231 // Update object start array |
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
232 if (start_array) { |
a4b729f5b611
6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents:
269
diff
changeset
|
233 start_array->allocate_block(compact_top); |
0 | 234 } |
235 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
236 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(oop(q), sz)); |
0 | 237 compact_top += sz; |
238 assert(compact_top <= dest->space()->end(), | |
239 "Exceeding space in destination"); | |
240 | |
241 q = end; | |
242 end_of_live = end; | |
243 continue; | |
244 } | |
245 } | |
246 | |
247 /* for the previous LiveRange, record the end of the live objects. */ | |
248 if (liveRange) { | |
249 liveRange->set_end(q); | |
250 } | |
251 | |
252 /* record the current LiveRange object. | |
253 * liveRange->start() is overlaid on the mark word. | |
254 */ | |
255 liveRange = (LiveRange*)q; | |
256 liveRange->set_start(end); | |
257 liveRange->set_end(end); | |
258 | |
259 /* see if this is the first dead region. */ | |
260 if (q < first_dead) { | |
261 first_dead = q; | |
262 } | |
263 | |
264 /* move on to the next object */ | |
265 q = end; | |
266 } | |
267 } | |
268 | |
269 assert(q == t, "just checking"); | |
270 if (liveRange != NULL) { | |
271 liveRange->set_end(q); | |
272 } | |
273 _end_of_live = end_of_live; | |
274 if (end_of_live < first_dead) { | |
275 first_dead = end_of_live; | |
276 } | |
277 _first_dead = first_dead; | |
278 | |
279 // Update compaction top | |
280 dest->set_compaction_top(compact_top); | |
281 } | |
282 | |
438 | 283 bool PSMarkSweepDecorator::insert_deadspace(size_t& allowed_deadspace_words, |
284 HeapWord* q, size_t deadlength) { | |
285 if (allowed_deadspace_words >= deadlength) { | |
286 allowed_deadspace_words -= deadlength; | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
438
diff
changeset
|
287 CollectedHeap::fill_with_object(q, deadlength); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
438
diff
changeset
|
288 oop(q)->set_mark(oop(q)->mark()->set_marked()); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
438
diff
changeset
|
289 assert((int) deadlength == oop(q)->size(), "bad filler object size"); |
0 | 290 // Recall that we required "q == compaction_top". |
291 return true; | |
292 } else { | |
293 allowed_deadspace_words = 0; | |
294 return false; | |
295 } | |
296 } | |
297 | |
298 void PSMarkSweepDecorator::adjust_pointers() { | |
299 // adjust all the interior pointers to point at the new locations of objects | |
300 // Used by MarkSweep::mark_sweep_phase3() | |
301 | |
302 HeapWord* q = space()->bottom(); | |
303 HeapWord* t = _end_of_live; // Established by "prepare_for_compaction". | |
304 | |
305 assert(_first_dead <= _end_of_live, "Stands to reason, no?"); | |
306 | |
307 if (q < t && _first_dead > q && | |
308 !oop(q)->is_gc_marked()) { | |
309 // we have a chunk of the space which hasn't moved and we've | |
310 // reinitialized the mark word during the previous pass, so we can't | |
311 // use is_gc_marked for the traversal. | |
312 HeapWord* end = _first_dead; | |
313 | |
314 while (q < end) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
315 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q))); |
0 | 316 // point all the oops to the new location |
317 size_t size = oop(q)->adjust_pointers(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
318 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
319 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size)); |
0 | 320 q += size; |
321 } | |
322 | |
323 if (_first_dead == t) { | |
324 q = t; | |
325 } else { | |
326 // $$$ This is funky. Using this to read the previously written | |
327 // LiveRange. See also use below. | |
328 q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); | |
329 } | |
330 } | |
331 const intx interval = PrefetchScanIntervalInBytes; | |
332 | |
333 debug_only(HeapWord* prev_q = NULL); | |
334 while (q < t) { | |
335 // prefetch beyond q | |
336 Prefetch::write(q, interval); | |
337 if (oop(q)->is_gc_marked()) { | |
338 // q is alive | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
339 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q))); |
0 | 340 // point all the oops to the new location |
341 size_t size = oop(q)->adjust_pointers(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
342 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
343 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size)); |
0 | 344 debug_only(prev_q = q); |
345 q += size; | |
346 } else { | |
347 // q is not a live object, so its mark should point at the next | |
348 // live object | |
349 debug_only(prev_q = q); | |
350 q = (HeapWord*) oop(q)->mark()->decode_pointer(); | |
351 assert(q > prev_q, "we should be moving forward through memory"); | |
352 } | |
353 } | |
354 | |
355 assert(q == t, "just checking"); | |
356 } | |
357 | |
358 void PSMarkSweepDecorator::compact(bool mangle_free_space ) { | |
359 // Copy all live objects to their new location | |
360 // Used by MarkSweep::mark_sweep_phase4() | |
361 | |
362 HeapWord* q = space()->bottom(); | |
363 HeapWord* const t = _end_of_live; | |
364 debug_only(HeapWord* prev_q = NULL); | |
365 | |
366 if (q < t && _first_dead > q && | |
367 !oop(q)->is_gc_marked()) { | |
368 #ifdef ASSERT | |
369 // we have a chunk of the space which hasn't moved and we've reinitialized the | |
370 // mark word during the previous pass, so we can't use is_gc_marked for the | |
371 // traversal. | |
372 HeapWord* const end = _first_dead; | |
373 | |
374 while (q < end) { | |
375 size_t size = oop(q)->size(); | |
376 assert(!oop(q)->is_gc_marked(), "should be unmarked (special dense prefix handling)"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
377 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q)); |
0 | 378 debug_only(prev_q = q); |
379 q += size; | |
380 } | |
381 #endif | |
382 | |
383 if (_first_dead == t) { | |
384 q = t; | |
385 } else { | |
386 // $$$ Funky | |
387 q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); | |
388 } | |
389 } | |
390 | |
391 const intx scan_interval = PrefetchScanIntervalInBytes; | |
392 const intx copy_interval = PrefetchCopyIntervalInBytes; | |
393 | |
394 while (q < t) { | |
395 if (!oop(q)->is_gc_marked()) { | |
396 // mark is pointer to next marked oop | |
397 debug_only(prev_q = q); | |
398 q = (HeapWord*) oop(q)->mark()->decode_pointer(); | |
399 assert(q > prev_q, "we should be moving forward through memory"); | |
400 } else { | |
401 // prefetch beyond q | |
402 Prefetch::read(q, scan_interval); | |
403 | |
404 // size and destination | |
405 size_t size = oop(q)->size(); | |
406 HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); | |
407 | |
408 // prefetch beyond compaction_top | |
409 Prefetch::write(compaction_top, copy_interval); | |
410 | |
411 // copy object and reinit its mark | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
412 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, compaction_top)); |
0 | 413 assert(q != compaction_top, "everything in this pass should be moving"); |
414 Copy::aligned_conjoint_words(q, compaction_top, size); | |
415 oop(compaction_top)->init_mark(); | |
416 assert(oop(compaction_top)->klass() != NULL, "should have a class"); | |
417 | |
418 debug_only(prev_q = q); | |
419 q += size; | |
420 } | |
421 } | |
422 | |
423 assert(compaction_top() >= space()->bottom() && compaction_top() <= space()->end(), | |
424 "should point inside space"); | |
425 space()->set_top(compaction_top()); | |
426 | |
263
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
427 if (mangle_free_space) { |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
428 space()->mangle_unused_area(); |
12eea04c8b06
6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
113
diff
changeset
|
429 } |
0 | 430 } |