diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 41c2e08c16b..34d0f429490 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -1403,6 +1403,8 @@ class G1CollectedHeap : public CollectedHeap { G1HeapSummary create_g1_heap_summary(); G1EvacSummary create_g1_evac_summary(G1EvacStats* stats); + inline bool root_region_scanning(); + // Printing private: void print_heap_regions() const; diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp index d019a2dffac..bbb3e9121f2 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp @@ -289,4 +289,8 @@ inline void G1CollectedHeap::set_humongous_is_live(oop obj) { } } +inline bool G1CollectedHeap::root_region_scanning() { + return _cm->root_regions()->scan_in_progress(); +} + #endif // SHARE_VM_GC_G1_G1COLLECTEDHEAP_INLINE_HPP diff --git a/src/hotspot/share/runtime/safepoint.cpp b/src/hotspot/share/runtime/safepoint.cpp index a8b98c3585f..f5e7e4392ef 100644 --- a/src/hotspot/share/runtime/safepoint.cpp +++ b/src/hotspot/share/runtime/safepoint.cpp @@ -69,6 +69,9 @@ #ifdef COMPILER1 #include "c1/c1_globals.hpp" #endif +#if INCLUDE_G1GC +#include "gc/g1/g1CollectedHeap.inline.hpp" +#endif // INCLUDE_G1GC template static void set_current_safepoint_id(E* event, int adjustment = 0) { @@ -732,6 +735,13 @@ void SafepointSynchronize::do_cleanup_tasks() { TraceTime timer("safepoint cleanup tasks", TRACETIME_LOG(Info, safepoint, cleanup)); +#if INCLUDE_G1GC + if (UseCompactObjectHeaders && UseG1GC && G1CollectedHeap::heap()->root_region_scanning()) { + log_info(safepoint)("Safepoint cancels cleanup due to G1 root region scanning."); + return; + } +#endif // INCLUDE_G1GC + // Prepare for monitor deflation. DeflateMonitorCounters deflate_counters; ObjectSynchronizer::prepare_deflate_idle_monitors(&deflate_counters);