28 #include "classfile/stringTable.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/codeCache.hpp"
33 #include "code/icBuffer.hpp"
34 #include "compiler/oopMap.hpp"
35 #include "gc/serial/cardTableRS.hpp"
36 #include "gc/serial/genMarkSweep.hpp"
37 #include "gc/serial/serialGcRefProcProxyTask.hpp"
38 #include "gc/shared/collectedHeap.inline.hpp"
39 #include "gc/shared/gcHeapSummary.hpp"
40 #include "gc/shared/gcTimer.hpp"
41 #include "gc/shared/gcTrace.hpp"
42 #include "gc/shared/gcTraceTime.inline.hpp"
43 #include "gc/shared/genCollectedHeap.hpp"
44 #include "gc/shared/generation.hpp"
45 #include "gc/shared/modRefBarrierSet.hpp"
46 #include "gc/shared/referencePolicy.hpp"
47 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
48 #include "gc/shared/space.hpp"
49 #include "gc/shared/strongRootsScope.hpp"
50 #include "gc/shared/weakProcessor.hpp"
51 #include "memory/universe.hpp"
52 #include "oops/instanceRefKlass.hpp"
53 #include "oops/oop.inline.hpp"
54 #include "prims/jvmtiExport.hpp"
55 #include "runtime/handles.inline.hpp"
56 #include "runtime/javaThread.hpp"
57 #include "runtime/synchronizer.hpp"
58 #include "runtime/vmThread.hpp"
59 #include "utilities/copy.hpp"
60 #include "utilities/events.hpp"
61 #include "utilities/stack.inline.hpp"
62 #if INCLUDE_JVMCI
63 #include "jvmci/jvmci.hpp"
64 #endif
65
66 void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) {
67 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
70 #ifdef ASSERT
71 if (gch->soft_ref_policy()->should_clear_all_soft_refs()) {
72 assert(clear_all_softrefs, "Policy should have been checked earlier");
73 }
74 #endif
75
76 gch->trace_heap_before_gc(_gc_tracer);
77
78 // Increment the invocation count
79 _total_invocations++;
80
81 // Capture used regions for each generation that will be
82 // subject to collection, so that card table adjustments can
83 // be made intelligently (see clear / invalidate further below).
84 gch->save_used_regions();
85
86 allocate_stacks();
87
88 mark_sweep_phase1(clear_all_softrefs);
89
90 mark_sweep_phase2();
91
92 // Don't add any more derived pointers during phase3
93 #if COMPILER2_OR_JVMCI
94 assert(DerivedPointerTable::is_active(), "Sanity");
95 DerivedPointerTable::set_active(false);
96 #endif
97
98 mark_sweep_phase3();
99
100 mark_sweep_phase4();
101
102 restore_marks();
103
104 // Set saved marks for allocation profiler (and other things? -- dld)
105 // (Should this be in general part?)
106 gch->save_marks();
107
108 deallocate_stacks();
109
110 MarkSweep::_string_dedup_requests->flush();
111
112 bool is_young_gen_empty = (gch->young_gen()->used() == 0);
113 gch->rem_set()->maintain_old_to_young_invariant(gch->old_gen(), is_young_gen_empty);
114
115 gch->prune_scavengable_nmethods();
116
117 // Update heap occupancy information which is used as
118 // input to soft ref clearing policy at the next gc.
119 Universe::heap()->update_capacity_and_used_at_gc();
120
121 // Signal that we have completed a visit to all live objects.
122 Universe::heap()->record_whole_heap_examined_timestamp();
123
124 gch->trace_heap_after_gc(_gc_tracer);
125 }
126
127 void GenMarkSweep::allocate_stacks() {
222 GCTraceTime(Info, gc, phases) tm("Phase 2: Compute new object addresses", _gc_timer);
223
224 GenCollectedHeap::heap()->prepare_for_compaction();
225 }
226
227 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
228 public:
229 void do_generation(Generation* gen) {
230 gen->adjust_pointers();
231 }
232 };
233
234 void GenMarkSweep::mark_sweep_phase3() {
235 GenCollectedHeap* gch = GenCollectedHeap::heap();
236
237 // Adjust the pointers to reflect the new locations
238 GCTraceTime(Info, gc, phases) tm("Phase 3: Adjust pointers", gc_timer());
239
240 ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
241
242 CodeBlobToOopClosure code_closure(&adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations);
243 gch->process_roots(GenCollectedHeap::SO_AllCodeCache,
244 &adjust_pointer_closure,
245 &adjust_cld_closure,
246 &adjust_cld_closure,
247 &code_closure);
248
249 gch->gen_process_weak_roots(&adjust_pointer_closure);
250
251 adjust_marks();
252 GenAdjustPointersClosure blk;
253 gch->generation_iterate(&blk, true);
254 }
255
256 class GenCompactClosure: public GenCollectedHeap::GenClosure {
257 public:
258 void do_generation(Generation* gen) {
259 gen->compact();
260 }
261 };
262
263 void GenMarkSweep::mark_sweep_phase4() {
264 // All pointers are now adjusted, move objects accordingly
265 GCTraceTime(Info, gc, phases) tm("Phase 4: Move objects", _gc_timer);
266
267 GenCompactClosure blk;
268 GenCollectedHeap::heap()->generation_iterate(&blk, true);
269 }
|
28 #include "classfile/stringTable.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/codeCache.hpp"
33 #include "code/icBuffer.hpp"
34 #include "compiler/oopMap.hpp"
35 #include "gc/serial/cardTableRS.hpp"
36 #include "gc/serial/genMarkSweep.hpp"
37 #include "gc/serial/serialGcRefProcProxyTask.hpp"
38 #include "gc/shared/collectedHeap.inline.hpp"
39 #include "gc/shared/gcHeapSummary.hpp"
40 #include "gc/shared/gcTimer.hpp"
41 #include "gc/shared/gcTrace.hpp"
42 #include "gc/shared/gcTraceTime.inline.hpp"
43 #include "gc/shared/genCollectedHeap.hpp"
44 #include "gc/shared/generation.hpp"
45 #include "gc/shared/modRefBarrierSet.hpp"
46 #include "gc/shared/referencePolicy.hpp"
47 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
48 #include "gc/shared/slidingForwarding.hpp"
49 #include "gc/shared/space.hpp"
50 #include "gc/shared/strongRootsScope.hpp"
51 #include "gc/shared/weakProcessor.hpp"
52 #include "memory/universe.hpp"
53 #include "oops/instanceRefKlass.hpp"
54 #include "oops/oop.inline.hpp"
55 #include "prims/jvmtiExport.hpp"
56 #include "runtime/handles.inline.hpp"
57 #include "runtime/javaThread.hpp"
58 #include "runtime/synchronizer.hpp"
59 #include "runtime/vmThread.hpp"
60 #include "utilities/copy.hpp"
61 #include "utilities/events.hpp"
62 #include "utilities/stack.inline.hpp"
63 #if INCLUDE_JVMCI
64 #include "jvmci/jvmci.hpp"
65 #endif
66
67 void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) {
68 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
71 #ifdef ASSERT
72 if (gch->soft_ref_policy()->should_clear_all_soft_refs()) {
73 assert(clear_all_softrefs, "Policy should have been checked earlier");
74 }
75 #endif
76
77 gch->trace_heap_before_gc(_gc_tracer);
78
79 // Increment the invocation count
80 _total_invocations++;
81
82 // Capture used regions for each generation that will be
83 // subject to collection, so that card table adjustments can
84 // be made intelligently (see clear / invalidate further below).
85 gch->save_used_regions();
86
87 allocate_stacks();
88
89 mark_sweep_phase1(clear_all_softrefs);
90
91 SlidingForwarding::begin();
92
93 mark_sweep_phase2();
94
95 // Don't add any more derived pointers during phase3
96 #if COMPILER2_OR_JVMCI
97 assert(DerivedPointerTable::is_active(), "Sanity");
98 DerivedPointerTable::set_active(false);
99 #endif
100
101 mark_sweep_phase3();
102
103 mark_sweep_phase4();
104
105 restore_marks();
106
107 // Set saved marks for allocation profiler (and other things? -- dld)
108 // (Should this be in general part?)
109 gch->save_marks();
110
111 SlidingForwarding::end();
112
113 deallocate_stacks();
114
115 MarkSweep::_string_dedup_requests->flush();
116
117 bool is_young_gen_empty = (gch->young_gen()->used() == 0);
118 gch->rem_set()->maintain_old_to_young_invariant(gch->old_gen(), is_young_gen_empty);
119
120 gch->prune_scavengable_nmethods();
121
122 // Update heap occupancy information which is used as
123 // input to soft ref clearing policy at the next gc.
124 Universe::heap()->update_capacity_and_used_at_gc();
125
126 // Signal that we have completed a visit to all live objects.
127 Universe::heap()->record_whole_heap_examined_timestamp();
128
129 gch->trace_heap_after_gc(_gc_tracer);
130 }
131
132 void GenMarkSweep::allocate_stacks() {
227 GCTraceTime(Info, gc, phases) tm("Phase 2: Compute new object addresses", _gc_timer);
228
229 GenCollectedHeap::heap()->prepare_for_compaction();
230 }
231
232 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
233 public:
234 void do_generation(Generation* gen) {
235 gen->adjust_pointers();
236 }
237 };
238
239 void GenMarkSweep::mark_sweep_phase3() {
240 GenCollectedHeap* gch = GenCollectedHeap::heap();
241
242 // Adjust the pointers to reflect the new locations
243 GCTraceTime(Info, gc, phases) tm("Phase 3: Adjust pointers", gc_timer());
244
245 ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
246
247 if (UseAltGCForwarding) {
248 AdjustPointerClosure<true> adjust_pointer_closure;
249 CLDToOopClosure adjust_cld_closure(&adjust_pointer_closure, ClassLoaderData::_claim_stw_fullgc_adjust);
250 CodeBlobToOopClosure code_closure(&adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations);
251 gch->process_roots(GenCollectedHeap::SO_AllCodeCache,
252 &adjust_pointer_closure,
253 &adjust_cld_closure,
254 &adjust_cld_closure,
255 &code_closure);
256 gch->gen_process_weak_roots(&adjust_pointer_closure);
257 } else {
258 AdjustPointerClosure<false> adjust_pointer_closure;
259 CLDToOopClosure adjust_cld_closure(&adjust_pointer_closure, ClassLoaderData::_claim_stw_fullgc_adjust);
260 CodeBlobToOopClosure code_closure(&adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations);
261 gch->process_roots(GenCollectedHeap::SO_AllCodeCache,
262 &adjust_pointer_closure,
263 &adjust_cld_closure,
264 &adjust_cld_closure,
265 &code_closure);
266 gch->gen_process_weak_roots(&adjust_pointer_closure);
267 }
268 adjust_marks();
269 GenAdjustPointersClosure blk;
270 gch->generation_iterate(&blk, true);
271 }
272
273 class GenCompactClosure: public GenCollectedHeap::GenClosure {
274 public:
275 void do_generation(Generation* gen) {
276 gen->compact();
277 }
278 };
279
280 void GenMarkSweep::mark_sweep_phase4() {
281 // All pointers are now adjusted, move objects accordingly
282 GCTraceTime(Info, gc, phases) tm("Phase 4: Move objects", _gc_timer);
283
284 GenCompactClosure blk;
285 GenCollectedHeap::heap()->generation_iterate(&blk, true);
286 }
|