23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "code/codeCache.hpp"
31 #include "code/icBuffer.hpp"
32 #include "gc_implementation/shared/gcHeapSummary.hpp"
33 #include "gc_implementation/shared/gcTimer.hpp"
34 #include "gc_implementation/shared/gcTrace.hpp"
35 #include "gc_implementation/shared/gcTraceTime.hpp"
36 #include "gc_interface/collectedHeap.inline.hpp"
37 #include "memory/genCollectedHeap.hpp"
38 #include "memory/genMarkSweep.hpp"
39 #include "memory/genOopClosures.inline.hpp"
40 #include "memory/modRefBarrierSet.hpp"
41 #include "memory/referencePolicy.hpp"
42 #include "memory/space.hpp"
43 #include "oops/instanceRefKlass.hpp"
44 #include "oops/oop.inline.hpp"
45 #include "prims/jvmtiExport.hpp"
46 #include "runtime/fprofiler.hpp"
47 #include "runtime/handles.inline.hpp"
48 #include "runtime/synchronizer.hpp"
49 #include "runtime/thread.inline.hpp"
50 #include "runtime/vmThread.hpp"
51 #include "utilities/copy.hpp"
52 #include "utilities/events.hpp"
53 #include "utilities/stack.inline.hpp"
54
55 void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, bool clear_all_softrefs) {
56 guarantee(level == 1, "We always collect both old and young.");
57 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
58
59 GenCollectedHeap* gch = GenCollectedHeap::heap();
60 #ifdef ASSERT
61 if (gch->collector_policy()->should_clear_all_soft_refs()) {
62 assert(clear_all_softrefs, "Policy should have been checked earlier");
183 _objarray_stack.clear(true);
184 }
185
186 void GenMarkSweep::mark_sweep_phase1(int level,
187 bool clear_all_softrefs) {
188 // Recursively traverse all live objects and mark them
189 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id());
190
191 GenCollectedHeap* gch = GenCollectedHeap::heap();
192
193 // Because follow_root_closure is created statically, cannot
194 // use OopsInGenClosure constructor which takes a generation,
195 // as the Universe has not been created when the static constructors
196 // are run.
197 assert(level == 1, "We don't use mark-sweep on young generations");
198 follow_root_closure.set_orig_generation(gch->old_gen());
199
200 // Need new claim bits before marking starts.
201 ClassLoaderDataGraph::clear_claimed_marks();
202
203 gch->gen_process_roots(level,
204 false, // Younger gens are not roots.
205 true, // activate StrongRootsScope
206 GenCollectedHeap::SO_None,
207 GenCollectedHeap::StrongRootsOnly,
208 &follow_root_closure,
209 &follow_root_closure,
210 &follow_cld_closure);
211
212 // Process reference objects found during marking
213 {
214 ref_processor()->setup_policy(clear_all_softrefs);
215 const ReferenceProcessorStats& stats =
216 ref_processor()->process_discovered_references(
217 &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer, _gc_tracer->gc_id());
218 gc_tracer()->report_gc_reference_stats(stats);
219 }
220
221 // This is the point where the entire marking should have completed.
222 assert(_marking_stack.is_empty(), "Marking should have completed");
223
224 // Unload classes and purge the SystemDictionary.
225 bool purged_class = SystemDictionary::do_unloading(&is_alive);
226
227 // Unload nmethods.
228 CodeCache::do_unloading(&is_alive, purged_class);
229
230 // Prune dead klasses from subklass/sibling/implementor lists.
267 gen->adjust_pointers();
268 }
269 };
270
271 void GenMarkSweep::mark_sweep_phase3(int level) {
272 GenCollectedHeap* gch = GenCollectedHeap::heap();
273
274 // Adjust the pointers to reflect the new locations
275 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id());
276
277 // Need new claim bits for the pointer adjustment tracing.
278 ClassLoaderDataGraph::clear_claimed_marks();
279
280 // Because the closure below is created statically, we cannot
281 // use OopsInGenClosure constructor which takes a generation,
282 // as the Universe has not been created when the static constructors
283 // are run.
284 assert(level == 1, "We don't use mark-sweep on young generations.");
285 adjust_pointer_closure.set_orig_generation(gch->old_gen());
286
287 gch->gen_process_roots(level,
288 false, // Younger gens are not roots.
289 true, // activate StrongRootsScope
290 GenCollectedHeap::SO_AllCodeCache,
291 GenCollectedHeap::StrongAndWeakRoots,
292 &adjust_pointer_closure,
293 &adjust_pointer_closure,
294 &adjust_cld_closure);
295
296 gch->gen_process_weak_roots(&adjust_pointer_closure);
297
298 adjust_marks();
299 GenAdjustPointersClosure blk;
300 gch->generation_iterate(&blk, true);
301 }
302
303 class GenCompactClosure: public GenCollectedHeap::GenClosure {
304 public:
305 void do_generation(Generation* gen) {
306 gen->compact();
307 }
308 };
309
310 void GenMarkSweep::mark_sweep_phase4() {
311 // All pointers are now adjusted, move objects accordingly
312
313 // It is imperative that we traverse perm_gen first in phase4. All
314 // classes must be allocated earlier than their instances, and traversing
|
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "code/codeCache.hpp"
31 #include "code/icBuffer.hpp"
32 #include "gc_implementation/shared/gcHeapSummary.hpp"
33 #include "gc_implementation/shared/gcTimer.hpp"
34 #include "gc_implementation/shared/gcTrace.hpp"
35 #include "gc_implementation/shared/gcTraceTime.hpp"
36 #include "gc_interface/collectedHeap.inline.hpp"
37 #include "memory/genCollectedHeap.hpp"
38 #include "memory/genMarkSweep.hpp"
39 #include "memory/genOopClosures.inline.hpp"
40 #include "memory/modRefBarrierSet.hpp"
41 #include "memory/referencePolicy.hpp"
42 #include "memory/space.hpp"
43 #include "memory/strongRootsScope.hpp"
44 #include "oops/instanceRefKlass.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "prims/jvmtiExport.hpp"
47 #include "runtime/fprofiler.hpp"
48 #include "runtime/handles.inline.hpp"
49 #include "runtime/synchronizer.hpp"
50 #include "runtime/thread.inline.hpp"
51 #include "runtime/vmThread.hpp"
52 #include "utilities/copy.hpp"
53 #include "utilities/events.hpp"
54 #include "utilities/stack.inline.hpp"
55
56 void GenMarkSweep::invoke_at_safepoint(int level, 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");
59
60 GenCollectedHeap* gch = GenCollectedHeap::heap();
61 #ifdef ASSERT
62 if (gch->collector_policy()->should_clear_all_soft_refs()) {
63 assert(clear_all_softrefs, "Policy should have been checked earlier");
184 _objarray_stack.clear(true);
185 }
186
187 void GenMarkSweep::mark_sweep_phase1(int level,
188 bool clear_all_softrefs) {
189 // Recursively traverse all live objects and mark them
190 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id());
191
192 GenCollectedHeap* gch = GenCollectedHeap::heap();
193
194 // Because follow_root_closure is created statically, cannot
195 // use OopsInGenClosure constructor which takes a generation,
196 // as the Universe has not been created when the static constructors
197 // 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());
200
201 // Need new claim bits before marking starts.
202 ClassLoaderDataGraph::clear_claimed_marks();
203
204 {
205 StrongRootsScope srs(1);
206
207 gch->gen_process_roots(&srs,
208 level,
209 false, // Younger gens are not roots.
210 GenCollectedHeap::SO_None,
211 GenCollectedHeap::StrongRootsOnly,
212 &follow_root_closure,
213 &follow_root_closure,
214 &follow_cld_closure);
215 }
216
217 // Process reference objects found during marking
218 {
219 ref_processor()->setup_policy(clear_all_softrefs);
220 const ReferenceProcessorStats& stats =
221 ref_processor()->process_discovered_references(
222 &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer, _gc_tracer->gc_id());
223 gc_tracer()->report_gc_reference_stats(stats);
224 }
225
226 // This is the point where the entire marking should have completed.
227 assert(_marking_stack.is_empty(), "Marking should have completed");
228
229 // Unload classes and purge the SystemDictionary.
230 bool purged_class = SystemDictionary::do_unloading(&is_alive);
231
232 // Unload nmethods.
233 CodeCache::do_unloading(&is_alive, purged_class);
234
235 // Prune dead klasses from subklass/sibling/implementor lists.
272 gen->adjust_pointers();
273 }
274 };
275
276 void GenMarkSweep::mark_sweep_phase3(int level) {
277 GenCollectedHeap* gch = GenCollectedHeap::heap();
278
279 // Adjust the pointers to reflect the new locations
280 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id());
281
282 // Need new claim bits for the pointer adjustment tracing.
283 ClassLoaderDataGraph::clear_claimed_marks();
284
285 // Because the closure below is created statically, we cannot
286 // use OopsInGenClosure constructor which takes a generation,
287 // as the Universe has not been created when the static constructors
288 // 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());
291
292 {
293 StrongRootsScope srs(1);
294
295 gch->gen_process_roots(&srs,
296 level,
297 false, // Younger gens are not roots.
298 GenCollectedHeap::SO_AllCodeCache,
299 GenCollectedHeap::StrongAndWeakRoots,
300 &adjust_pointer_closure,
301 &adjust_pointer_closure,
302 &adjust_cld_closure);
303 }
304
305 gch->gen_process_weak_roots(&adjust_pointer_closure);
306
307 adjust_marks();
308 GenAdjustPointersClosure blk;
309 gch->generation_iterate(&blk, true);
310 }
311
312 class GenCompactClosure: public GenCollectedHeap::GenClosure {
313 public:
314 void do_generation(Generation* gen) {
315 gen->compact();
316 }
317 };
318
319 void GenMarkSweep::mark_sweep_phase4() {
320 // All pointers are now adjusted, move objects accordingly
321
322 // It is imperative that we traverse perm_gen first in phase4. All
323 // classes must be allocated earlier than their instances, and traversing
|