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 "gc/serial/genMarkSweep.hpp"
35 #include "gc/shared/collectedHeap.inline.hpp"
36 #include "gc/shared/gcHeapSummary.hpp"
37 #include "gc/shared/gcTimer.hpp"
38 #include "gc/shared/gcTrace.hpp"
39 #include "gc/shared/gcTraceTime.inline.hpp"
40 #include "gc/shared/genCollectedHeap.hpp"
41 #include "gc/shared/generation.hpp"
42 #include "gc/shared/genOopClosures.inline.hpp"
43 #include "gc/shared/modRefBarrierSet.hpp"
44 #include "gc/shared/referencePolicy.hpp"
45 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
46 #include "gc/shared/space.hpp"
47 #include "gc/shared/strongRootsScope.hpp"
48 #include "gc/shared/weakProcessor.hpp"
49 #if INCLUDE_JVMCI
50 #include "jvmci/jvmci.hpp"
51 #endif
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/synchronizer.hpp"
57 #include "runtime/thread.inline.hpp"
58 #include "runtime/vmThread.hpp"
59 #include "utilities/copy.hpp"
60 #include "utilities/events.hpp"
61 #include "utilities/stack.inline.hpp"
62
63 void GenMarkSweep::invoke_at_safepoint(ReferenceProcessor* rp, bool clear_all_softrefs) {
64 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
65
66 GenCollectedHeap* gch = GenCollectedHeap::heap();
67 #ifdef ASSERT
68 if (gch->soft_ref_policy()->should_clear_all_soft_refs()) {
69 assert(clear_all_softrefs, "Policy should have been checked earlier");
70 }
71 #endif
72
73 // hook up weak ref data so it can be used during Mark-Sweep
74 assert(ref_processor() == NULL, "no stomping");
75 assert(rp != NULL, "should be non-NULL");
76 set_ref_processor(rp);
77 rp->setup_policy(clear_all_softrefs);
78
79 gch->trace_heap_before_gc(_gc_tracer);
80
81 // Increment the invocation count
220 // This is the point where the entire marking should have completed.
221 assert(_marking_stack.is_empty(), "Marking should have completed");
222
223 {
224 GCTraceTime(Debug, gc, phases) tm_m("Weak Processing", gc_timer());
225 WeakProcessor::weak_oops_do(&is_alive, &do_nothing_cl);
226 }
227
228 {
229 GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", gc_timer());
230
231 // Unload classes and purge the SystemDictionary.
232 bool purged_class = SystemDictionary::do_unloading(gc_timer());
233
234 // Unload nmethods.
235 CodeCache::do_unloading(&is_alive, purged_class);
236
237 // Prune dead klasses from subklass/sibling/implementor lists.
238 Klass::clean_weak_klass_links(purged_class);
239
240 #if INCLUDE_JVMCI
241 // Clean JVMCI metadata handles.
242 JVMCI::do_unloading(&is_alive, purged_class);
243 #endif
244 }
245
246 gc_tracer()->report_object_count_after_gc(&is_alive);
247 }
248
249
250 void GenMarkSweep::mark_sweep_phase2() {
251 // Now all live objects are marked, compute the new object addresses.
252
253 // It is imperative that we traverse perm_gen LAST. If dead space is
254 // allowed a range of dead object may get overwritten by a dead int
255 // array. If perm_gen is not traversed last a Klass* may get
256 // overwritten. This is fine since it is dead, but if the class has dead
257 // instances we have to skip them, and in order to find their size we
258 // need the Klass*!
259 //
260 // It is not required that we traverse spaces in the same order in
261 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
262 // tracking expects us to do so. See comment under phase4.
263
|
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 "gc/serial/genMarkSweep.hpp"
35 #include "gc/shared/collectedHeap.inline.hpp"
36 #include "gc/shared/gcHeapSummary.hpp"
37 #include "gc/shared/gcTimer.hpp"
38 #include "gc/shared/gcTrace.hpp"
39 #include "gc/shared/gcTraceTime.inline.hpp"
40 #include "gc/shared/genCollectedHeap.hpp"
41 #include "gc/shared/generation.hpp"
42 #include "gc/shared/genOopClosures.inline.hpp"
43 #include "gc/shared/modRefBarrierSet.hpp"
44 #include "gc/shared/referencePolicy.hpp"
45 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
46 #include "gc/shared/space.hpp"
47 #include "gc/shared/strongRootsScope.hpp"
48 #include "gc/shared/weakProcessor.hpp"
49 #include "oops/instanceRefKlass.hpp"
50 #include "oops/oop.inline.hpp"
51 #include "prims/jvmtiExport.hpp"
52 #include "runtime/handles.inline.hpp"
53 #include "runtime/synchronizer.hpp"
54 #include "runtime/thread.inline.hpp"
55 #include "runtime/vmThread.hpp"
56 #include "utilities/copy.hpp"
57 #include "utilities/events.hpp"
58 #include "utilities/stack.inline.hpp"
59 #if INCLUDE_JVMCI
60 #include "jvmci/jvmci.hpp"
61 #endif
62
63 void GenMarkSweep::invoke_at_safepoint(ReferenceProcessor* rp, bool clear_all_softrefs) {
64 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
65
66 GenCollectedHeap* gch = GenCollectedHeap::heap();
67 #ifdef ASSERT
68 if (gch->soft_ref_policy()->should_clear_all_soft_refs()) {
69 assert(clear_all_softrefs, "Policy should have been checked earlier");
70 }
71 #endif
72
73 // hook up weak ref data so it can be used during Mark-Sweep
74 assert(ref_processor() == NULL, "no stomping");
75 assert(rp != NULL, "should be non-NULL");
76 set_ref_processor(rp);
77 rp->setup_policy(clear_all_softrefs);
78
79 gch->trace_heap_before_gc(_gc_tracer);
80
81 // Increment the invocation count
220 // This is the point where the entire marking should have completed.
221 assert(_marking_stack.is_empty(), "Marking should have completed");
222
223 {
224 GCTraceTime(Debug, gc, phases) tm_m("Weak Processing", gc_timer());
225 WeakProcessor::weak_oops_do(&is_alive, &do_nothing_cl);
226 }
227
228 {
229 GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", gc_timer());
230
231 // Unload classes and purge the SystemDictionary.
232 bool purged_class = SystemDictionary::do_unloading(gc_timer());
233
234 // Unload nmethods.
235 CodeCache::do_unloading(&is_alive, purged_class);
236
237 // Prune dead klasses from subklass/sibling/implementor lists.
238 Klass::clean_weak_klass_links(purged_class);
239
240 // Clean JVMCI metadata handles.
241 JVMCI_ONLY(JVMCI::do_unloading(&is_alive, purged_class));
242 }
243
244 gc_tracer()->report_object_count_after_gc(&is_alive);
245 }
246
247
248 void GenMarkSweep::mark_sweep_phase2() {
249 // Now all live objects are marked, compute the new object addresses.
250
251 // It is imperative that we traverse perm_gen LAST. If dead space is
252 // allowed a range of dead object may get overwritten by a dead int
253 // array. If perm_gen is not traversed last a Klass* may get
254 // overwritten. This is fine since it is dead, but if the class has dead
255 // instances we have to skip them, and in order to find their size we
256 // need the Klass*!
257 //
258 // It is not required that we traverse spaces in the same order in
259 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
260 // tracking expects us to do so. See comment under phase4.
261
|