annotate src/share/vm/gc_implementation/parallelScavenge/psMarkSweepDecorator.cpp @ 4091:d06a2d7fcd5b

7110718: -XX:MarkSweepAlwaysCompactCount=0 crashes the JVM Summary: Interpret MarkSweepAlwaysCompactCount < 1 as never do full compaction Reviewed-by: ysr, tonyp, jmasa, johnc
author brutisso
date Mon, 21 Nov 2011 07:47:34 +0100
parents f95d63e2154a
children da91efe96a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "gc_implementation/shared/liveRange.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "gc_implementation/shared/markSweep.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "gc_implementation/shared/spaceDecorator.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "oops/oop.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 PSMarkSweepDecorator* PSMarkSweepDecorator::_destination_decorator = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 void PSMarkSweepDecorator::set_destination_decorator_tenured() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
41 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _destination_decorator = heap->old_gen()->object_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 void PSMarkSweepDecorator::set_destination_decorator_perm_gen() {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _destination_decorator = heap->perm_gen()->object_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 void PSMarkSweepDecorator::advance_destination_decorator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 assert(_destination_decorator != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 guarantee(_destination_decorator != heap->perm_gen()->object_mark_sweep(), "Cannot advance perm gen decorator");
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 PSMarkSweepDecorator* first = heap->old_gen()->object_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 PSMarkSweepDecorator* second = heap->young_gen()->eden_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 PSMarkSweepDecorator* third = heap->young_gen()->from_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 PSMarkSweepDecorator* fourth = heap->young_gen()->to_mark_sweep();
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if ( _destination_decorator == first ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _destination_decorator = second;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else if ( _destination_decorator == second ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _destination_decorator = third;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else if ( _destination_decorator == third ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 _destination_decorator = fourth;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 fatal("PSMarkSweep attempting to advance past last compaction area");
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 PSMarkSweepDecorator* PSMarkSweepDecorator::destination_decorator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 assert(_destination_decorator != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return _destination_decorator;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // FIX ME FIX ME FIX ME FIX ME!!!!!!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // The object forwarding code is duplicated. Factor this out!!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
84 //
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // This method "precompacts" objects inside its space to dest. It places forwarding
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // pointers into markOops for use by adjust_pointers. If "dest" should overflow, we
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // finish by compacting into our own space.
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void PSMarkSweepDecorator::precompact() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Reset our own compact top.
a61af66fc99e Initial load
duke
parents:
diff changeset
91 set_compaction_top(space()->bottom());
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 /* We allow some amount of garbage towards the bottom of the space, so
a61af66fc99e Initial load
duke
parents:
diff changeset
94 * we don't start compacting before there is a significant gain to be made.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 * Occasionally, we want to ensure a full compaction, which is determined
a61af66fc99e Initial load
duke
parents:
diff changeset
96 * by the MarkSweepAlwaysCompactCount parameter. This is a significant
a61af66fc99e Initial load
duke
parents:
diff changeset
97 * performance improvement!
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
101
438
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
102 size_t allowed_deadspace = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (skip_dead) {
438
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
104 const size_t ratio = allowed_dead_ratio();
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
105 allowed_deadspace = space()->capacity_in_words() * ratio / 100;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Fetch the current destination decorator
a61af66fc99e Initial load
duke
parents:
diff changeset
109 PSMarkSweepDecorator* dest = destination_decorator();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 ObjectStartArray* start_array = dest->start_array();
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 HeapWord* compact_top = dest->compaction_top();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 HeapWord* compact_end = dest->space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 HeapWord* q = space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 HeapWord* t = space()->top();
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
a61af66fc99e Initial load
duke
parents:
diff changeset
119 live object. */
a61af66fc99e Initial load
duke
parents:
diff changeset
120 HeapWord* first_dead = space()->end(); /* The first dead object. */
a61af66fc99e Initial load
duke
parents:
diff changeset
121 LiveRange* liveRange = NULL; /* The current live range, recorded in the
a61af66fc99e Initial load
duke
parents:
diff changeset
122 first header of preceding free area. */
a61af66fc99e Initial load
duke
parents:
diff changeset
123 _first_dead = first_dead;
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 const intx interval = PrefetchScanIntervalInBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 while (q < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert(oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
129 oop(q)->mark()->has_bias_pattern(),
a61af66fc99e Initial load
duke
parents:
diff changeset
130 "these are the only valid states during a mark sweep");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (oop(q)->is_gc_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 /* prefetch beyond q */
a61af66fc99e Initial load
duke
parents:
diff changeset
133 Prefetch::write(q, interval);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 size_t size = oop(q)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 size_t compaction_max_size = pointer_delta(compact_end, compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // This should only happen if a space in the young gen overflows the
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // old gen. If that should happen, we null out the start_array, because
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // the young spaces are not covered by one.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 while(size > compaction_max_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // First record the last compact_top
a61af66fc99e Initial load
duke
parents:
diff changeset
143 dest->set_compaction_top(compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // Advance to the next compaction decorator
a61af66fc99e Initial load
duke
parents:
diff changeset
146 advance_destination_decorator();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 dest = destination_decorator();
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // Update compaction info
a61af66fc99e Initial load
duke
parents:
diff changeset
150 start_array = dest->start_array();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 compact_top = dest->compaction_top();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 compact_end = dest->space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(compact_top == dest->space()->bottom(), "Advanced to space already in use");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 assert(compact_end > compact_top, "Must always be space remaining");
a61af66fc99e Initial load
duke
parents:
diff changeset
155 compaction_max_size =
a61af66fc99e Initial load
duke
parents:
diff changeset
156 pointer_delta(compact_end, compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // store the forwarding pointer into the mark word
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (q != compact_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 oop(q)->forward_to(oop(compact_top));
a61af66fc99e Initial load
duke
parents:
diff changeset
162 assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark");
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
167 assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
176 compact_top += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 assert(compact_top <= dest->space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
178 "Exceeding space in destination");
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 q += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 end_of_live = q;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 /* run over all the contiguous dead objects */
a61af66fc99e Initial load
duke
parents:
diff changeset
184 HeapWord* end = q;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 /* prefetch beyond end */
a61af66fc99e Initial load
duke
parents:
diff changeset
187 Prefetch::write(end, interval);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 end += oop(end)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 } while (end < t && (!oop(end)->is_gc_marked()));
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 /* see if we might want to pretend this object is alive so that
a61af66fc99e Initial load
duke
parents:
diff changeset
192 * we don't have to compact quite as often.
a61af66fc99e Initial load
duke
parents:
diff changeset
193 */
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (allowed_deadspace > 0 && q == compact_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 size_t sz = pointer_delta(end, q);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (insert_deadspace(allowed_deadspace, q, sz)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 size_t compaction_max_size = pointer_delta(compact_end, compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // This should only happen if a space in the young gen overflows the
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // old gen. If that should happen, we null out the start_array, because
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // the young spaces are not covered by one.
a61af66fc99e Initial load
duke
parents:
diff changeset
202 while (sz > compaction_max_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // First record the last compact_top
a61af66fc99e Initial load
duke
parents:
diff changeset
204 dest->set_compaction_top(compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // Advance to the next compaction decorator
a61af66fc99e Initial load
duke
parents:
diff changeset
207 advance_destination_decorator();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 dest = destination_decorator();
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Update compaction info
a61af66fc99e Initial load
duke
parents:
diff changeset
211 start_array = dest->start_array();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 compact_top = dest->compaction_top();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 compact_end = dest->space()->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 assert(compact_top == dest->space()->bottom(), "Advanced to space already in use");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 assert(compact_end > compact_top, "Must always be space remaining");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 compaction_max_size =
a61af66fc99e Initial load
duke
parents:
diff changeset
217 pointer_delta(compact_end, compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // store the forwarding pointer into the mark word
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (q != compact_top) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 oop(q)->forward_to(oop(compact_top));
a61af66fc99e Initial load
duke
parents:
diff changeset
223 assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark");
a61af66fc99e Initial load
duke
parents:
diff changeset
224 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
228 assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
237 compact_top += sz;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 assert(compact_top <= dest->space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
239 "Exceeding space in destination");
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 q = end;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 end_of_live = end;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 /* for the previous LiveRange, record the end of the live objects. */
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if (liveRange) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 liveRange->set_end(q);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 /* record the current LiveRange object.
a61af66fc99e Initial load
duke
parents:
diff changeset
253 * liveRange->start() is overlaid on the mark word.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 */
a61af66fc99e Initial load
duke
parents:
diff changeset
255 liveRange = (LiveRange*)q;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 liveRange->set_start(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 liveRange->set_end(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 /* see if this is the first dead region. */
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (q < first_dead) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 first_dead = q;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 /* move on to the next object */
a61af66fc99e Initial load
duke
parents:
diff changeset
265 q = end;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 assert(q == t, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
270 if (liveRange != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 liveRange->set_end(q);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273 _end_of_live = end_of_live;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (end_of_live < first_dead) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 first_dead = end_of_live;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 _first_dead = first_dead;
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // Update compaction top
a61af66fc99e Initial load
duke
parents:
diff changeset
280 dest->set_compaction_top(compact_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
438
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
283 bool PSMarkSweepDecorator::insert_deadspace(size_t& allowed_deadspace_words,
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
284 HeapWord* q, size_t deadlength) {
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
285 if (allowed_deadspace_words >= deadlength) {
122d10c82f3f 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 374
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // Recall that we required "q == compaction_top".
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 allowed_deadspace_words = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 void PSMarkSweepDecorator::adjust_pointers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // adjust all the interior pointers to point at the new locations of objects
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // Used by MarkSweep::mark_sweep_phase3()
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 HeapWord* q = space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 HeapWord* t = _end_of_live; // Established by "prepare_for_compaction".
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 assert(_first_dead <= _end_of_live, "Stands to reason, no?");
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (q < t && _first_dead > q &&
a61af66fc99e Initial load
duke
parents:
diff changeset
308 !oop(q)->is_gc_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // we have a chunk of the space which hasn't moved and we've
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // reinitialized the mark word during the previous pass, so we can't
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // use is_gc_marked for the traversal.
a61af66fc99e Initial load
duke
parents:
diff changeset
312 HeapWord* end = _first_dead;
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // point all the oops to the new location
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
320 q += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (_first_dead == t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 q = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // $$$ This is funky. Using this to read the previously written
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // LiveRange. See also use below.
a61af66fc99e Initial load
duke
parents:
diff changeset
328 q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 const intx interval = PrefetchScanIntervalInBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 debug_only(HeapWord* prev_q = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 while (q < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // prefetch beyond q
a61af66fc99e Initial load
duke
parents:
diff changeset
336 Prefetch::write(q, interval);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (oop(q)->is_gc_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // point all the oops to the new location
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
344 debug_only(prev_q = q);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 q += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // q is not a live object, so its mark should point at the next
a61af66fc99e Initial load
duke
parents:
diff changeset
348 // live object
a61af66fc99e Initial load
duke
parents:
diff changeset
349 debug_only(prev_q = q);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 q = (HeapWord*) oop(q)->mark()->decode_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 assert(q > prev_q, "we should be moving forward through memory");
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 assert(q == t, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 void PSMarkSweepDecorator::compact(bool mangle_free_space ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // Copy all live objects to their new location
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // Used by MarkSweep::mark_sweep_phase4()
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 HeapWord* q = space()->bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 HeapWord* const t = _end_of_live;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 debug_only(HeapWord* prev_q = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 if (q < t && _first_dead > q &&
a61af66fc99e Initial load
duke
parents:
diff changeset
367 !oop(q)->is_gc_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // we have a chunk of the space which hasn't moved and we've reinitialized the
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // mark word during the previous pass, so we can't use is_gc_marked for the
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // traversal.
a61af66fc99e Initial load
duke
parents:
diff changeset
372 HeapWord* const end = _first_dead;
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 while (q < end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 size_t size = oop(q)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
378 debug_only(prev_q = q);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 q += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (_first_dead == t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 q = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
385 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // $$$ Funky
a61af66fc99e Initial load
duke
parents:
diff changeset
387 q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 const intx scan_interval = PrefetchScanIntervalInBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 const intx copy_interval = PrefetchCopyIntervalInBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 while (q < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (!oop(q)->is_gc_marked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // mark is pointer to next marked oop
a61af66fc99e Initial load
duke
parents:
diff changeset
397 debug_only(prev_q = q);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 q = (HeapWord*) oop(q)->mark()->decode_pointer();
a61af66fc99e Initial load
duke
parents:
diff changeset
399 assert(q > prev_q, "we should be moving forward through memory");
a61af66fc99e Initial load
duke
parents:
diff changeset
400 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // prefetch beyond q
a61af66fc99e Initial load
duke
parents:
diff changeset
402 Prefetch::read(q, scan_interval);
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // size and destination
a61af66fc99e Initial load
duke
parents:
diff changeset
405 size_t size = oop(q)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
406 HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 // prefetch beyond compaction_top
a61af66fc99e Initial load
duke
parents:
diff changeset
409 Prefetch::write(compaction_top, copy_interval);
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
413 assert(q != compaction_top, "everything in this pass should be moving");
a61af66fc99e Initial load
duke
parents:
diff changeset
414 Copy::aligned_conjoint_words(q, compaction_top, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
415 oop(compaction_top)->init_mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 assert(oop(compaction_top)->klass() != NULL, "should have a class");
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 debug_only(prev_q = q);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 q += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 assert(compaction_top() >= space()->bottom() && compaction_top() <= space()->end(),
a61af66fc99e Initial load
duke
parents:
diff changeset
424 "should point inside space");
a61af66fc99e Initial load
duke
parents:
diff changeset
425 space()->set_top(compaction_top());
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
430 }