示例#1
0
void G1MarkSweep::mark_sweep_phase3() {
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
  Generation* pg = g1h->perm_gen();

  // Adjust the pointers to reflect the new locations
  EventMark m("3 adjust pointers");
  TraceTime tm("phase 3", PrintGC && Verbose, true, gclog_or_tty);
  GenMarkSweep::trace("3");

  SharedHeap* sh = SharedHeap::heap();

  sh->process_strong_roots(true,  // activate StrongRootsScope
                           true,  // Collecting permanent generation.
                           SharedHeap::SO_AllClasses,
                           &GenMarkSweep::adjust_root_pointer_closure,
                           NULL,  // do not touch code cache here
                           &GenMarkSweep::adjust_pointer_closure);

  g1h->ref_processor()->weak_oops_do(&GenMarkSweep::adjust_root_pointer_closure);

  // Now adjust pointers in remaining weak roots.  (All of which should
  // have been cleared if they pointed to non-surviving objects.)
  g1h->g1_process_weak_roots(&GenMarkSweep::adjust_root_pointer_closure,
                             &GenMarkSweep::adjust_pointer_closure);

  GenMarkSweep::adjust_marks();

  G1AdjustPointersClosure blk;
  g1h->heap_region_iterate(&blk);
  pg->adjust_pointers();
}
示例#2
0
void G1MarkSweep::mark_sweep_phase3() {
    G1CollectedHeap* g1h = G1CollectedHeap::heap();

    // Adjust the pointers to reflect the new locations
    GCTraceTime tm("phase 3", G1Log::fine() && Verbose, true, gc_timer());
    GenMarkSweep::trace("3");

    SharedHeap* sh = SharedHeap::heap();

    // Need cleared claim bits for the strong roots processing
    ClassLoaderDataGraph::clear_claimed_marks();

    sh->process_strong_roots(true,  // activate StrongRootsScope
                             false, // not scavenging.
                             SharedHeap::SO_AllClasses,
                             &GenMarkSweep::adjust_pointer_closure,
                             NULL,  // do not touch code cache here
                             &GenMarkSweep::adjust_klass_closure);

    assert(GenMarkSweep::ref_processor() == g1h->ref_processor_stw(), "Sanity");
    g1h->ref_processor_stw()->weak_oops_do(&GenMarkSweep::adjust_pointer_closure);

    // Now adjust pointers in remaining weak roots.  (All of which should
    // have been cleared if they pointed to non-surviving objects.)
    g1h->g1_process_weak_roots(&GenMarkSweep::adjust_pointer_closure);

    GenMarkSweep::adjust_marks();

    G1AdjustPointersClosure blk;
    g1h->heap_region_iterate(&blk);
}
示例#3
0
void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading,
                                    bool clear_all_softrefs) {
  // Recursively traverse all live objects and mark them
  EventMark m("1 mark object");
  TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty);
  GenMarkSweep::trace(" 1");

  SharedHeap* sh = SharedHeap::heap();

  sh->process_strong_roots(true,  // activeate StrongRootsScope
                           true,  // Collecting permanent generation.
                           SharedHeap::SO_SystemClasses,
                           &GenMarkSweep::follow_root_closure,
                           &GenMarkSweep::follow_code_root_closure,
                           &GenMarkSweep::follow_root_closure);

  // Process reference objects found during marking
  ReferenceProcessor* rp = GenMarkSweep::ref_processor();
  rp->setup_policy(clear_all_softrefs);
  rp->process_discovered_references(&GenMarkSweep::is_alive,
                                    &GenMarkSweep::keep_alive,
                                    &GenMarkSweep::follow_stack_closure,
                                    NULL);

  // Follow system dictionary roots and unload classes
  bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
  assert(GenMarkSweep::_marking_stack.is_empty(),
         "stack should be empty by now");

  // Follow code cache roots (has to be done after system dictionary,
  // assumes all live klasses are marked)
  CodeCache::do_unloading(&GenMarkSweep::is_alive,
                                   &GenMarkSweep::keep_alive,
                                   purged_class);
  GenMarkSweep::follow_stack();

  // Update subklass/sibling/implementor links of live klasses
  GenMarkSweep::follow_weak_klass_links();
  assert(GenMarkSweep::_marking_stack.is_empty(),
         "stack should be empty by now");

  // Visit memoized MDO's and clear any unmarked weak refs
  GenMarkSweep::follow_mdo_weak_refs();
  assert(GenMarkSweep::_marking_stack.is_empty(), "just drained");


  // Visit symbol and interned string tables and delete unmarked oops
  SymbolTable::unlink(&GenMarkSweep::is_alive);
  StringTable::unlink(&GenMarkSweep::is_alive);

  assert(GenMarkSweep::_marking_stack.is_empty(),
         "stack should be empty by now");
}
示例#4
0
void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading,
                                    bool clear_all_softrefs) {
    // Recursively traverse all live objects and mark them
    GCTraceTime tm("phase 1", G1Log::fine() && Verbose, true, gc_timer());
    GenMarkSweep::trace(" 1");

    SharedHeap* sh = SharedHeap::heap();

    // Need cleared claim bits for the strong roots processing
    ClassLoaderDataGraph::clear_claimed_marks();

    sh->process_strong_roots(true,  // activate StrongRootsScope
                             false, // not scavenging.
                             SharedHeap::SO_SystemClasses,
                             &GenMarkSweep::follow_root_closure,
                             &GenMarkSweep::follow_code_root_closure,
                             &GenMarkSweep::follow_klass_closure);

    // Process reference objects found during marking
    ReferenceProcessor* rp = GenMarkSweep::ref_processor();
    assert(rp == G1CollectedHeap::heap()->ref_processor_stw(), "Sanity");

    rp->setup_policy(clear_all_softrefs);
    const ReferenceProcessorStats& stats =
        rp->process_discovered_references(&GenMarkSweep::is_alive,
                                          &GenMarkSweep::keep_alive,
                                          &GenMarkSweep::follow_stack_closure,
                                          NULL,
                                          gc_timer());
    gc_tracer()->report_gc_reference_stats(stats);


    // This is the point where the entire marking should have completed.
    assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");

    // Unload classes and purge the SystemDictionary.
    bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);

    // Unload nmethods.
    CodeCache::do_unloading(&GenMarkSweep::is_alive, purged_class);

    // Prune dead klasses from subklass/sibling/implementor lists.
    Klass::clean_weak_klass_links(&GenMarkSweep::is_alive);

    // Delete entries for dead interned strings.
    StringTable::unlink(&GenMarkSweep::is_alive);

    // Clean up unreferenced symbols in symbol table.
    SymbolTable::unlink();

    if (VerifyDuringGC) {
        HandleMark hm;  // handle scope
        COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact);
        Universe::heap()->prepare_for_verify();
        // Note: we can verify only the heap here. When an object is
        // marked, the previous value of the mark word (including
        // identity hash values, ages, etc) is preserved, and the mark
        // word is set to markOop::marked_value - effectively removing
        // any hash values from the mark word. These hash values are
        // used when verifying the dictionaries and so removing them
        // from the mark word can make verification of the dictionaries
        // fail. At the end of the GC, the orginal mark word values
        // (including hash values) are restored to the appropriate
        // objects.
        if (!VerifySilently) {
            gclog_or_tty->print(" VerifyDuringGC:(full)[Verifying ");
        }
        Universe::heap()->verify(VerifySilently, VerifyOption_G1UseMarkWord);
        if (!VerifySilently) {
            gclog_or_tty->print_cr("]");
        }
    }

    gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
}