< prev index next >

src/hotspot/share/gc/serial/genMarkSweep.cpp

Print this page

 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/classUnloadingContext.hpp"
 39 #include "gc/shared/collectedHeap.inline.hpp"
 40 #include "gc/shared/gcHeapSummary.hpp"
 41 #include "gc/shared/gcTimer.hpp"
 42 #include "gc/shared/gcTrace.hpp"
 43 #include "gc/shared/gcTraceTime.inline.hpp"
 44 #include "gc/shared/genCollectedHeap.hpp"
 45 #include "gc/shared/generation.hpp"
 46 #include "gc/shared/modRefBarrierSet.hpp"
 47 #include "gc/shared/referencePolicy.hpp"
 48 #include "gc/shared/referenceProcessorPhaseTimes.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   mark_sweep_phase2();
 92 
 93   // Don't add any more derived pointers during phase3
 94 #if COMPILER2_OR_JVMCI
 95   assert(DerivedPointerTable::is_active(), "Sanity");
 96   DerivedPointerTable::set_active(false);
 97 #endif
 98 
 99   mark_sweep_phase3();
100 
101   mark_sweep_phase4();
102 
103   restore_marks();
104 
105   // Set saved marks for allocation profiler (and other things? -- dld)
106   // (Should this be in general part?)
107   gch->save_marks();
108 


109   deallocate_stacks();
110 
111   MarkSweep::_string_dedup_requests->flush();
112 
113   bool is_young_gen_empty = (gch->young_gen()->used() == 0);
114   gch->rem_set()->maintain_old_to_young_invariant(gch->old_gen(), is_young_gen_empty);
115 
116   gch->prune_scavengable_nmethods();
117 
118   // Update heap occupancy information which is used as
119   // input to soft ref clearing policy at the next gc.
120   Universe::heap()->update_capacity_and_used_at_gc();
121 
122   // Signal that we have completed a visit to all live objects.
123   Universe::heap()->record_whole_heap_examined_timestamp();
124 
125   gch->trace_heap_after_gc(_gc_tracer);
126 }
127 
128 void GenMarkSweep::allocate_stacks() {

243   GCTraceTime(Info, gc, phases) tm("Phase 2: Compute new object addresses", _gc_timer);
244 
245   GenCollectedHeap::heap()->prepare_for_compaction();
246 }
247 
248 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
249 public:
250   void do_generation(Generation* gen) {
251     gen->adjust_pointers();
252   }
253 };
254 
255 void GenMarkSweep::mark_sweep_phase3() {
256   GenCollectedHeap* gch = GenCollectedHeap::heap();
257 
258   // Adjust the pointers to reflect the new locations
259   GCTraceTime(Info, gc, phases) tm("Phase 3: Adjust pointers", gc_timer());
260 
261   ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
262 
263   CodeBlobToOopClosure code_closure(&adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations);
264   gch->process_roots(GenCollectedHeap::SO_AllCodeCache,
265                      &adjust_pointer_closure,
266                      &adjust_cld_closure,
267                      &adjust_cld_closure,
268                      &code_closure);
269 
270   gch->gen_process_weak_roots(&adjust_pointer_closure);
271 












272   adjust_marks();
273   GenAdjustPointersClosure blk;
274   gch->generation_iterate(&blk, true);
275 }
276 
277 class GenCompactClosure: public GenCollectedHeap::GenClosure {
278 public:
279   void do_generation(Generation* gen) {
280     gen->compact();
281   }
282 };
283 
284 void GenMarkSweep::mark_sweep_phase4() {
285   // All pointers are now adjusted, move objects accordingly
286   GCTraceTime(Info, gc, phases) tm("Phase 4: Move objects", _gc_timer);
287 
288   GenCompactClosure blk;
289   GenCollectedHeap::heap()->generation_iterate(&blk, true);
290 }

 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/classUnloadingContext.hpp"
 39 #include "gc/shared/collectedHeap.inline.hpp"
 40 #include "gc/shared/gcHeapSummary.hpp"
 41 #include "gc/shared/gcTimer.hpp"
 42 #include "gc/shared/gcTrace.hpp"
 43 #include "gc/shared/gcTraceTime.inline.hpp"
 44 #include "gc/shared/genCollectedHeap.hpp"
 45 #include "gc/shared/generation.hpp"
 46 #include "gc/shared/modRefBarrierSet.hpp"
 47 #include "gc/shared/referencePolicy.hpp"
 48 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
 49 #include "gc/shared/slidingForwarding.hpp"
 50 #include "gc/shared/space.hpp"
 51 #include "gc/shared/strongRootsScope.hpp"
 52 #include "gc/shared/weakProcessor.hpp"
 53 #include "memory/universe.hpp"
 54 #include "oops/instanceRefKlass.hpp"
 55 #include "oops/oop.inline.hpp"
 56 #include "prims/jvmtiExport.hpp"
 57 #include "runtime/handles.inline.hpp"
 58 #include "runtime/javaThread.hpp"
 59 #include "runtime/synchronizer.hpp"
 60 #include "runtime/vmThread.hpp"
 61 #include "utilities/copy.hpp"
 62 #include "utilities/events.hpp"
 63 #include "utilities/stack.inline.hpp"
 64 #if INCLUDE_JVMCI
 65 #include "jvmci/jvmci.hpp"
 66 #endif
 67 
 68 void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) {
 69   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");

 72 #ifdef ASSERT
 73   if (gch->soft_ref_policy()->should_clear_all_soft_refs()) {
 74     assert(clear_all_softrefs, "Policy should have been checked earlier");
 75   }
 76 #endif
 77 
 78   gch->trace_heap_before_gc(_gc_tracer);
 79 
 80   // Increment the invocation count
 81   _total_invocations++;
 82 
 83   // Capture used regions for each generation that will be
 84   // subject to collection, so that card table adjustments can
 85   // be made intelligently (see clear / invalidate further below).
 86   gch->save_used_regions();
 87 
 88   allocate_stacks();
 89 
 90   mark_sweep_phase1(clear_all_softrefs);
 91 
 92   SlidingForwarding::begin();
 93 
 94   mark_sweep_phase2();
 95 
 96   // Don't add any more derived pointers during phase3
 97 #if COMPILER2_OR_JVMCI
 98   assert(DerivedPointerTable::is_active(), "Sanity");
 99   DerivedPointerTable::set_active(false);
100 #endif
101 
102   mark_sweep_phase3();
103 
104   mark_sweep_phase4();
105 
106   restore_marks();
107 
108   // Set saved marks for allocation profiler (and other things? -- dld)
109   // (Should this be in general part?)
110   gch->save_marks();
111 
112   SlidingForwarding::end();
113 
114   deallocate_stacks();
115 
116   MarkSweep::_string_dedup_requests->flush();
117 
118   bool is_young_gen_empty = (gch->young_gen()->used() == 0);
119   gch->rem_set()->maintain_old_to_young_invariant(gch->old_gen(), is_young_gen_empty);
120 
121   gch->prune_scavengable_nmethods();
122 
123   // Update heap occupancy information which is used as
124   // input to soft ref clearing policy at the next gc.
125   Universe::heap()->update_capacity_and_used_at_gc();
126 
127   // Signal that we have completed a visit to all live objects.
128   Universe::heap()->record_whole_heap_examined_timestamp();
129 
130   gch->trace_heap_after_gc(_gc_tracer);
131 }
132 
133 void GenMarkSweep::allocate_stacks() {

248   GCTraceTime(Info, gc, phases) tm("Phase 2: Compute new object addresses", _gc_timer);
249 
250   GenCollectedHeap::heap()->prepare_for_compaction();
251 }
252 
253 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
254 public:
255   void do_generation(Generation* gen) {
256     gen->adjust_pointers();
257   }
258 };
259 
260 void GenMarkSweep::mark_sweep_phase3() {
261   GenCollectedHeap* gch = GenCollectedHeap::heap();
262 
263   // Adjust the pointers to reflect the new locations
264   GCTraceTime(Info, gc, phases) tm("Phase 3: Adjust pointers", gc_timer());
265 
266   ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
267 
268   if (UseAltGCForwarding) {
269     AdjustPointerClosure<true> adjust_pointer_closure;
270     CLDToOopClosure adjust_cld_closure(&adjust_pointer_closure, ClassLoaderData::_claim_stw_fullgc_adjust);
271     CodeBlobToOopClosure code_closure(&adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations);
272     gch->process_roots(GenCollectedHeap::SO_AllCodeCache,
273                        &adjust_pointer_closure,
274                        &adjust_cld_closure,
275                        &adjust_cld_closure,
276                        &code_closure);
277     gch->gen_process_weak_roots(&adjust_pointer_closure);
278   } else {
279     AdjustPointerClosure<false> adjust_pointer_closure;
280     CLDToOopClosure adjust_cld_closure(&adjust_pointer_closure, ClassLoaderData::_claim_stw_fullgc_adjust);
281     CodeBlobToOopClosure code_closure(&adjust_pointer_closure, CodeBlobToOopClosure::FixRelocations);
282     gch->process_roots(GenCollectedHeap::SO_AllCodeCache,
283                        &adjust_pointer_closure,
284                        &adjust_cld_closure,
285                        &adjust_cld_closure,
286                        &code_closure);
287     gch->gen_process_weak_roots(&adjust_pointer_closure);
288   }
289   adjust_marks();
290   GenAdjustPointersClosure blk;
291   gch->generation_iterate(&blk, true);
292 }
293 
294 class GenCompactClosure: public GenCollectedHeap::GenClosure {
295 public:
296   void do_generation(Generation* gen) {
297     gen->compact();
298   }
299 };
300 
301 void GenMarkSweep::mark_sweep_phase4() {
302   // All pointers are now adjusted, move objects accordingly
303   GCTraceTime(Info, gc, phases) tm("Phase 4: Move objects", _gc_timer);
304 
305   GenCompactClosure blk;
306   GenCollectedHeap::heap()->generation_iterate(&blk, true);
307 }
< prev index next >