--- old/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp 2013-03-04 15:36:59.081478279 +0100 +++ new/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp 2013-03-04 15:36:58.981478501 +0100 @@ -186,6 +186,12 @@ } }; +class CMSPhaseTracing: public StackObj { + public: + CMSPhaseTracing(bool print, const char* phase); + ~CMSPhaseTracing(); +}; + ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration( ReservedSpace rs, size_t initial_byte_size, int level, CardTableRS* ct, bool use_adaptive_freelists, @@ -2164,10 +2170,12 @@ _collection_count_start = gch->total_full_collections(); } - // Used for PrintGC - size_t prev_used; - if (PrintGC && Verbose) { - prev_used = _cmsGen->used(); // XXXPERM + // Used for PrintGCDetails + size_t prev_used = 0; + size_t metaspace_pre_unloading = 0; + if (PrintGCDetails) { + prev_used = _cmsGen->used(); + metaspace_pre_unloading = MetaspaceAux::used_in_bytes(); } // The change of the collection state is normally done at this level; @@ -2318,6 +2326,15 @@ CMSTokenSync z(true); // not strictly needed. if (_collectorState == Resizing) { compute_new_size(); + if (PrintGCDetails) { + CMSPhaseTracing pt(true, "[CMS-resizing: "); + gclog_or_tty->print("[%s:", cmsGen()->short_name()); + cmsGen()->print_heap_change(prev_used); + gclog_or_tty->print("]"); + MetaspaceAux::print_metaspace_change(metaspace_pre_unloading); + gclog_or_tty->print_cr(" ]"); + } + _collectorState = Resetting; } else { assert(_collectorState == Idling, "The state should only change" @@ -2371,9 +2388,6 @@ " exiting collection CMS state %d", Thread::current(), _collectorState); } - if (PrintGC && Verbose) { - _cmsGen->print_heap_change(prev_used); - } } void CMSCollector::collect_in_foreground(bool clear_all_soft_refs) { @@ -3364,10 +3378,19 @@ return; } +CMSPhaseTracing::CMSPhaseTracing(bool print, const char* phase) { + if (print) { + gclog_or_tty->date_stamp(PrintGCDateStamps); + gclog_or_tty->stamp(PrintGCTimeStamps); + gclog_or_tty->print("%s", phase); + } +} + +CMSPhaseTracing::~CMSPhaseTracing() {} // Simple ctor/dtor wrapper for accounting & timer chores around concurrent // phases. -class CMSPhaseAccounting: public StackObj { +class CMSPhaseAccounting: public CMSPhaseTracing { public: CMSPhaseAccounting(CMSCollector *collector, const char *phase, @@ -3395,15 +3418,14 @@ CMSPhaseAccounting::CMSPhaseAccounting(CMSCollector *collector, const char *phase, bool print_cr) : - _collector(collector), _phase(phase), _print_cr(print_cr) { + CMSPhaseTracing(PrintGCDetails, ""), + _collector(collector), _phase(phase), _print_cr(print_cr) { if (PrintCMSStatistics != 0) { _collector->resetYields(); } if (PrintGCDetails && PrintGCTimeStamps) { - gclog_or_tty->date_stamp(PrintGCDateStamps); - gclog_or_tty->stamp(); - gclog_or_tty->print_cr(": [%s-concurrent-%s-start]", + gclog_or_tty->print_cr("[%s-concurrent-%s-start]", _collector->cmsGen()->short_name(), _phase); } _collector->resetTimer(); @@ -6073,6 +6095,10 @@ verify_work_stacks_empty(); verify_overflow_empty(); + if (should_unload_classes()) { + ClassLoaderDataGraph::purge(); + } + _intra_sweep_timer.stop(); _intra_sweep_estimate.sample(_intra_sweep_timer.seconds()); --- old/src/share/vm/memory/genCollectedHeap.cpp 2013-03-04 15:36:59.717476868 +0100 +++ new/src/share/vm/memory/genCollectedHeap.cpp 2013-03-04 15:36:59.629477064 +0100 @@ -554,6 +554,8 @@ } if (complete) { + // Delete metaspaces for unloaded class loaders and clean up loader_data graph + ClassLoaderDataGraph::purge(); // Resize the metaspace capacity after full collections MetaspaceGC::compute_new_size(); update_full_collections_completed(); @@ -564,11 +566,6 @@ gc_epilogue(complete); - // Delete metaspaces for unloaded class loaders and clean up loader_data graph - if (complete) { - ClassLoaderDataGraph::purge(); - } - if (must_restore_marks_for_biased_locking) { BiasedLocking::restore_marks(); } --- old/src/share/vm/memory/metaspace.cpp 2013-03-04 15:37:00.201475795 +0100 +++ new/src/share/vm/memory/metaspace.cpp 2013-03-04 15:37:00.113475990 +0100 @@ -1309,8 +1309,7 @@ gclog_or_tty->print_cr(" metaspace HWM: %.1fK", new_capacity_until_GC / (double) K); } } - assert(vsl->used_bytes_sum() == used_after_gc && - used_after_gc <= vsl->capacity_bytes_sum(), + assert(used_after_gc <= vsl->capacity_bytes_sum(), "sanity check"); } @@ -1970,6 +1969,7 @@ } SpaceManager::~SpaceManager() { + const size_t in_use_before = sum_capacity_in_chunks_in_use(); MutexLockerEx fcl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag); @@ -1987,7 +1987,7 @@ // Have to update before the chunks_in_use lists are emptied // below. - chunk_manager->inc_free_chunks_total(sum_capacity_in_chunks_in_use(), + chunk_manager->inc_free_chunks_total(in_use_before, sum_count_in_chunks_in_use()); // Add all the chunks in use by this space manager