src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
changeset 55760 bf8128faace1
parent 55587 4644b3155fce
child 57533 a2912ba36422
equal deleted inserted replaced
55759:bf9fa29bb3dc 55760:bf8128faace1
    27 
    27 
    28 #include "gc/shared/gcArguments.hpp"
    28 #include "gc/shared/gcArguments.hpp"
    29 #include "gc/shared/gcTimer.hpp"
    29 #include "gc/shared/gcTimer.hpp"
    30 #include "gc/shared/gcTraceTime.inline.hpp"
    30 #include "gc/shared/gcTraceTime.inline.hpp"
    31 #include "gc/shared/memAllocator.hpp"
    31 #include "gc/shared/memAllocator.hpp"
    32 #include "gc/shared/parallelCleaning.hpp"
       
    33 #include "gc/shared/plab.hpp"
    32 #include "gc/shared/plab.hpp"
    34 
    33 
    35 #include "gc/shenandoah/shenandoahAllocTracker.hpp"
    34 #include "gc/shenandoah/shenandoahAllocTracker.hpp"
    36 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
    35 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
    37 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
    36 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
    51 #include "gc/shenandoah/shenandoahMetrics.hpp"
    50 #include "gc/shenandoah/shenandoahMetrics.hpp"
    52 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
    51 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
    53 #include "gc/shenandoah/shenandoahNormalMode.hpp"
    52 #include "gc/shenandoah/shenandoahNormalMode.hpp"
    54 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
    53 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
    55 #include "gc/shenandoah/shenandoahPacer.inline.hpp"
    54 #include "gc/shenandoah/shenandoahPacer.inline.hpp"
       
    55 #include "gc/shenandoah/shenandoahParallelCleaning.inline.hpp"
    56 #include "gc/shenandoah/shenandoahPassiveMode.hpp"
    56 #include "gc/shenandoah/shenandoahPassiveMode.hpp"
    57 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
    57 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
    58 #include "gc/shenandoah/shenandoahStringDedup.hpp"
    58 #include "gc/shenandoah/shenandoahStringDedup.hpp"
    59 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
    59 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
    60 #include "gc/shenandoah/shenandoahTraversalMode.hpp"
    60 #include "gc/shenandoah/shenandoahTraversalMode.hpp"
  1948   if (ShenandoahStringDedup::is_enabled()) {
  1948   if (ShenandoahStringDedup::is_enabled()) {
  1949     ShenandoahStringDedup::stop();
  1949     ShenandoahStringDedup::stop();
  1950   }
  1950   }
  1951 }
  1951 }
  1952 
  1952 
  1953 void ShenandoahHeap::unload_classes_and_cleanup_tables(bool full_gc) {
  1953 void ShenandoahHeap::stw_unload_classes(bool full_gc) {
  1954   assert(heuristics()->can_unload_classes(), "Class unloading should be enabled");
  1954   if (!unload_classes()) return;
  1955 
       
  1956   ShenandoahGCPhase root_phase(full_gc ?
       
  1957                                ShenandoahPhaseTimings::full_gc_purge :
       
  1958                                ShenandoahPhaseTimings::purge);
       
  1959 
       
  1960   ShenandoahIsAliveSelector alive;
       
  1961   BoolObjectClosure* is_alive = alive.is_alive_closure();
       
  1962 
       
  1963   bool purged_class;
  1955   bool purged_class;
  1964 
  1956 
  1965   // Unload classes and purge SystemDictionary.
  1957   // Unload classes and purge SystemDictionary.
  1966   {
  1958   {
  1967     ShenandoahGCPhase phase(full_gc ?
  1959     ShenandoahGCPhase phase(full_gc ?
  1972 
  1964 
  1973   {
  1965   {
  1974     ShenandoahGCPhase phase(full_gc ?
  1966     ShenandoahGCPhase phase(full_gc ?
  1975                             ShenandoahPhaseTimings::full_gc_purge_par :
  1967                             ShenandoahPhaseTimings::full_gc_purge_par :
  1976                             ShenandoahPhaseTimings::purge_par);
  1968                             ShenandoahPhaseTimings::purge_par);
  1977     uint active = _workers->active_workers();
  1969     ShenandoahIsAliveSelector is_alive;
  1978     ParallelCleaningTask unlink_task(is_alive, active, purged_class, true);
  1970     uint num_workers = _workers->active_workers();
       
  1971     ShenandoahClassUnloadingTask unlink_task(is_alive.is_alive_closure(), num_workers, purged_class);
  1979     _workers->run_task(&unlink_task);
  1972     _workers->run_task(&unlink_task);
  1980   }
  1973   }
  1981 
  1974 
  1982   {
  1975   {
  1983     ShenandoahGCPhase phase(full_gc ?
  1976     ShenandoahGCPhase phase(full_gc ?
  1984                       ShenandoahPhaseTimings::full_gc_purge_cldg :
  1977                             ShenandoahPhaseTimings::full_gc_purge_cldg :
  1985                       ShenandoahPhaseTimings::purge_cldg);
  1978                             ShenandoahPhaseTimings::purge_cldg);
  1986     ClassLoaderDataGraph::purge();
  1979     ClassLoaderDataGraph::purge();
  1987   }
  1980   }
       
  1981   // Resize and verify metaspace
       
  1982   MetaspaceGC::compute_new_size();
       
  1983   MetaspaceUtils::verify_metrics();
       
  1984 }
       
  1985 
       
  1986 // Process leftover weak oops: update them, if needed or assert they do not
       
  1987 // need updating otherwise.
       
  1988 // Weak processor API requires us to visit the oops, even if we are not doing
       
  1989 // anything to them.
       
  1990 void ShenandoahHeap::stw_process_weak_roots(bool full_gc) {
       
  1991   ShenandoahGCPhase root_phase(full_gc ?
       
  1992                                ShenandoahPhaseTimings::full_gc_purge :
       
  1993                                ShenandoahPhaseTimings::purge);
       
  1994   uint num_workers = _workers->active_workers();
       
  1995   ShenandoahPhaseTimings::Phase timing_phase = full_gc ?
       
  1996                                                ShenandoahPhaseTimings::full_gc_purge_par :
       
  1997                                                ShenandoahPhaseTimings::purge_par;
       
  1998   // Cleanup weak roots
       
  1999   ShenandoahGCPhase phase(timing_phase);
       
  2000   if (has_forwarded_objects()) {
       
  2001     ShenandoahForwardedIsAliveClosure is_alive;
       
  2002     ShenandoahUpdateRefsClosure keep_alive;
       
  2003     ShenandoahParallelWeakRootsCleaningTask<ShenandoahForwardedIsAliveClosure, ShenandoahUpdateRefsClosure>
       
  2004       cleaning_task(&is_alive, &keep_alive, num_workers);
       
  2005     _workers->run_task(&cleaning_task);
       
  2006   } else {
       
  2007     ShenandoahIsAliveClosure is_alive;
       
  2008 #ifdef ASSERT
       
  2009   ShenandoahAssertNotForwardedClosure verify_cl;
       
  2010   ShenandoahParallelWeakRootsCleaningTask<ShenandoahIsAliveClosure, ShenandoahAssertNotForwardedClosure>
       
  2011     cleaning_task(&is_alive, &verify_cl, num_workers);
       
  2012 #else
       
  2013   ShenandoahParallelWeakRootsCleaningTask<ShenandoahIsAliveClosure, DoNothingClosure>
       
  2014     cleaning_task(&is_alive, &do_nothing_cl, num_workers);
       
  2015 #endif
       
  2016     _workers->run_task(&cleaning_task);
       
  2017   }
       
  2018 }
       
  2019 
       
  2020 void ShenandoahHeap::parallel_cleaning(bool full_gc) {
       
  2021   assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
       
  2022   stw_process_weak_roots(full_gc);
       
  2023   stw_unload_classes(full_gc);
  1988 }
  2024 }
  1989 
  2025 
  1990 void ShenandoahHeap::set_has_forwarded_objects(bool cond) {
  2026 void ShenandoahHeap::set_has_forwarded_objects(bool cond) {
  1991   set_gc_state_mask(HAS_FORWARDED, cond);
  2027   set_gc_state_mask(HAS_FORWARDED, cond);
  1992 }
  2028 }