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