34 #include "gc/shared/gcHeapSummary.hpp" |
34 #include "gc/shared/gcHeapSummary.hpp" |
35 #include "gc/shared/gcTimer.hpp" |
35 #include "gc/shared/gcTimer.hpp" |
36 #include "gc/shared/gcTrace.hpp" |
36 #include "gc/shared/gcTrace.hpp" |
37 #include "gc/shared/gcTraceTime.hpp" |
37 #include "gc/shared/gcTraceTime.hpp" |
38 #include "gc/shared/genCollectedHeap.hpp" |
38 #include "gc/shared/genCollectedHeap.hpp" |
|
39 #include "gc/shared/generation.hpp" |
39 #include "gc/shared/genOopClosures.inline.hpp" |
40 #include "gc/shared/genOopClosures.inline.hpp" |
40 #include "gc/shared/modRefBarrierSet.hpp" |
41 #include "gc/shared/modRefBarrierSet.hpp" |
41 #include "gc/shared/referencePolicy.hpp" |
42 #include "gc/shared/referencePolicy.hpp" |
42 #include "gc/shared/space.hpp" |
43 #include "gc/shared/space.hpp" |
43 #include "gc/shared/strongRootsScope.hpp" |
44 #include "gc/shared/strongRootsScope.hpp" |
51 #include "runtime/vmThread.hpp" |
52 #include "runtime/vmThread.hpp" |
52 #include "utilities/copy.hpp" |
53 #include "utilities/copy.hpp" |
53 #include "utilities/events.hpp" |
54 #include "utilities/events.hpp" |
54 #include "utilities/stack.inline.hpp" |
55 #include "utilities/stack.inline.hpp" |
55 |
56 |
56 void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, bool clear_all_softrefs) { |
57 void GenMarkSweep::invoke_at_safepoint(ReferenceProcessor* rp, bool clear_all_softrefs) { |
57 guarantee(level == 1, "We always collect both old and young."); |
|
58 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
58 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); |
59 |
59 |
60 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
60 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
61 #ifdef ASSERT |
61 #ifdef ASSERT |
62 if (gch->collector_policy()->should_clear_all_soft_refs()) { |
62 if (gch->collector_policy()->should_clear_all_soft_refs()) { |
85 size_t gch_prev_used = gch->used(); |
85 size_t gch_prev_used = gch->used(); |
86 |
86 |
87 // Capture used regions for each generation that will be |
87 // Capture used regions for each generation that will be |
88 // subject to collection, so that card table adjustments can |
88 // subject to collection, so that card table adjustments can |
89 // be made intelligently (see clear / invalidate further below). |
89 // be made intelligently (see clear / invalidate further below). |
90 gch->save_used_regions(level); |
90 gch->save_used_regions(); |
91 |
91 |
92 allocate_stacks(); |
92 allocate_stacks(); |
93 |
93 |
94 mark_sweep_phase1(level, clear_all_softrefs); |
94 mark_sweep_phase1(clear_all_softrefs); |
95 |
95 |
96 mark_sweep_phase2(); |
96 mark_sweep_phase2(); |
97 |
97 |
98 // Don't add any more derived pointers during phase3 |
98 // Don't add any more derived pointers during phase3 |
99 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); |
99 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); |
100 COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); |
100 COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); |
101 |
101 |
102 mark_sweep_phase3(level); |
102 mark_sweep_phase3(); |
103 |
103 |
104 mark_sweep_phase4(); |
104 mark_sweep_phase4(); |
105 |
105 |
106 restore_marks(); |
106 restore_marks(); |
107 |
107 |
182 _preserved_oop_stack.clear(true); |
182 _preserved_oop_stack.clear(true); |
183 _marking_stack.clear(); |
183 _marking_stack.clear(); |
184 _objarray_stack.clear(true); |
184 _objarray_stack.clear(true); |
185 } |
185 } |
186 |
186 |
187 void GenMarkSweep::mark_sweep_phase1(int level, |
187 void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) { |
188 bool clear_all_softrefs) { |
|
189 // Recursively traverse all live objects and mark them |
188 // Recursively traverse all live objects and mark them |
190 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); |
189 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); |
191 |
190 |
192 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
191 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
193 |
192 |
194 // Because follow_root_closure is created statically, cannot |
193 // Because follow_root_closure is created statically, cannot |
195 // use OopsInGenClosure constructor which takes a generation, |
194 // use OopsInGenClosure constructor which takes a generation, |
196 // as the Universe has not been created when the static constructors |
195 // as the Universe has not been created when the static constructors |
197 // are run. |
196 // are run. |
198 assert(level == 1, "We don't use mark-sweep on young generations"); |
|
199 follow_root_closure.set_orig_generation(gch->old_gen()); |
197 follow_root_closure.set_orig_generation(gch->old_gen()); |
200 |
198 |
201 // Need new claim bits before marking starts. |
199 // Need new claim bits before marking starts. |
202 ClassLoaderDataGraph::clear_claimed_marks(); |
200 ClassLoaderDataGraph::clear_claimed_marks(); |
203 |
201 |
204 { |
202 { |
205 StrongRootsScope srs(1); |
203 StrongRootsScope srs(1); |
206 |
204 |
207 gch->gen_process_roots(&srs, |
205 gch->gen_process_roots(&srs, |
208 level, |
206 GenCollectedHeap::OldGen, |
209 false, // Younger gens are not roots. |
207 false, // Younger gens are not roots. |
210 GenCollectedHeap::SO_None, |
208 GenCollectedHeap::SO_None, |
211 ClassUnloading, |
209 ClassUnloading, |
212 &follow_root_closure, |
210 &follow_root_closure, |
213 &follow_root_closure, |
211 &follow_root_closure, |
271 void do_generation(Generation* gen) { |
269 void do_generation(Generation* gen) { |
272 gen->adjust_pointers(); |
270 gen->adjust_pointers(); |
273 } |
271 } |
274 }; |
272 }; |
275 |
273 |
276 void GenMarkSweep::mark_sweep_phase3(int level) { |
274 void GenMarkSweep::mark_sweep_phase3() { |
277 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
275 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
278 |
276 |
279 // Adjust the pointers to reflect the new locations |
277 // Adjust the pointers to reflect the new locations |
280 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); |
278 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); |
281 |
279 |
284 |
282 |
285 // Because the closure below is created statically, we cannot |
283 // Because the closure below is created statically, we cannot |
286 // use OopsInGenClosure constructor which takes a generation, |
284 // use OopsInGenClosure constructor which takes a generation, |
287 // as the Universe has not been created when the static constructors |
285 // as the Universe has not been created when the static constructors |
288 // are run. |
286 // are run. |
289 assert(level == 1, "We don't use mark-sweep on young generations."); |
|
290 adjust_pointer_closure.set_orig_generation(gch->old_gen()); |
287 adjust_pointer_closure.set_orig_generation(gch->old_gen()); |
291 |
288 |
292 { |
289 { |
293 StrongRootsScope srs(1); |
290 StrongRootsScope srs(1); |
294 |
291 |
295 gch->gen_process_roots(&srs, |
292 gch->gen_process_roots(&srs, |
296 level, |
293 GenCollectedHeap::OldGen, |
297 false, // Younger gens are not roots. |
294 false, // Younger gens are not roots. |
298 GenCollectedHeap::SO_AllCodeCache, |
295 GenCollectedHeap::SO_AllCodeCache, |
299 GenCollectedHeap::StrongAndWeakRoots, |
296 GenCollectedHeap::StrongAndWeakRoots, |
300 &adjust_pointer_closure, |
297 &adjust_pointer_closure, |
301 &adjust_pointer_closure, |
298 &adjust_pointer_closure, |