hotspot/src/share/vm/memory/genMarkSweep.cpp
void GenMarkSweep::mark_sweep_phase1(int level,
bool clear_all_softrefs) {
{- -------------------------------------------
(1) (トレース出力)
---------------------------------------- -}
// Recursively traverse all live objects and mark them
EventMark m("1 mark object");
TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty);
trace(" 1");
{- -------------------------------------------
(1) (verify)
---------------------------------------- -}
VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
{- -------------------------------------------
(1) (変数宣言など)
---------------------------------------- -}
GenCollectedHeap* gch = GenCollectedHeap::heap();
{- -------------------------------------------
(1) まず, GenCollectedHeap::gen_process_strong_roots() を呼び出して root から参照されているオブジェクトを全て処理する.
---------------------------------------- -}
// Because follow_root_closure is created statically, cannot
// use OopsInGenClosure constructor which takes a generation,
// as the Universe has not been created when the static constructors
// are run.
follow_root_closure.set_orig_generation(gch->get_gen(level));
gch->gen_process_strong_roots(level,
false, // Younger gens are not roots.
true, // activate StrongRootsScope
true, // Collecting permanent generation.
SharedHeap::SO_SystemClasses,
&follow_root_closure,
true, // walk code active on stacks
&follow_root_closure);
{- -------------------------------------------
(1) 次に, ReferenceProcessor::process_discovered_references() を呼び出して,
上の処理中に発見された参照オブジェクト(java.lang.ref オブジェクト) の処理を行う.
---------------------------------------- -}
// Process reference objects found during marking
{
ref_processor()->setup_policy(clear_all_softrefs);
ref_processor()->process_discovered_references(
&is_alive, &keep_alive, &follow_stack_closure, NULL);
}
{- -------------------------------------------
(1)
---------------------------------------- -}
// Follow system dictionary roots and unload classes
bool purged_class = SystemDictionary::do_unloading(&is_alive);
// Follow code cache roots
CodeCache::do_unloading(&is_alive, &keep_alive, purged_class);
follow_stack(); // Flush marking stack
// Update subklass/sibling/implementor links of live klasses
follow_weak_klass_links();
assert(_marking_stack.is_empty(), "just drained");
// Visit memoized MDO's and clear any unmarked weak refs
follow_mdo_weak_refs();
assert(_marking_stack.is_empty(), "just drained");
// Visit interned string tables and delete unmarked oops
StringTable::unlink(&is_alive);
// Clean up unreferenced symbols in symbol table.
SymbolTable::unlink();
{- -------------------------------------------
(1) (assert)
---------------------------------------- -}
assert(_marking_stack.is_empty(), "stack should be empty by now");
}
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.