Tue, 02 Aug 2011 14:37:35 +0100
7072527: CMS: JMM GC counters overcount in some cases
Summary: Avoid overcounting when CMS has concurrent mode failure.
Reviewed-by: ysr
Contributed-by: rednaxelafx@gmail.com
1.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Tue Jul 12 16:32:25 2011 -0700 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Tue Aug 02 14:37:35 2011 +0100 1.3 @@ -2025,9 +2025,6 @@ 1.4 _intra_sweep_estimate.padded_average()); 1.5 } 1.6 1.7 - { 1.8 - TraceCMSMemoryManagerStats tmms(gch->gc_cause()); 1.9 - } 1.10 GenMarkSweep::invoke_at_safepoint(_cmsGen->level(), 1.11 ref_processor(), clear_all_soft_refs); 1.12 #ifdef ASSERT 1.13 @@ -9345,15 +9342,3 @@ 1.14 } 1.15 } 1.16 1.17 -// when bailing out of cms in concurrent mode failure 1.18 -TraceCMSMemoryManagerStats::TraceCMSMemoryManagerStats(GCCause::Cause cause): TraceMemoryManagerStats() { 1.19 - initialize(true /* fullGC */ , 1.20 - cause /* cause of the GC */, 1.21 - true /* recordGCBeginTime */, 1.22 - true /* recordPreGCUsage */, 1.23 - true /* recordPeakUsage */, 1.24 - true /* recordPostGCusage */, 1.25 - true /* recordAccumulatedGCTime */, 1.26 - true /* recordGCEndTime */, 1.27 - true /* countCollection */ ); 1.28 -}
2.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp Tue Jul 12 16:32:25 2011 -0700 2.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp Tue Aug 02 14:37:35 2011 +0100 2.3 @@ -1900,7 +1900,6 @@ 2.4 2.5 public: 2.6 TraceCMSMemoryManagerStats(CMSCollector::CollectorState phase, GCCause::Cause cause); 2.7 - TraceCMSMemoryManagerStats(GCCause::Cause cause); 2.8 }; 2.9 2.10
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/gc/7072527/TestFullGCCount.java Tue Aug 02 14:37:35 2011 +0100 3.3 @@ -0,0 +1,95 @@ 3.4 +/* 3.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test TestFullGCount.java 3.29 + * @bug 7072527 3.30 + * @summary CMS: JMM GC counters overcount in some cases 3.31 + * @run main/othervm -XX:+UseConcMarkSweepGC TestFullGCCount 3.32 + * 3.33 + */ 3.34 +import java.util.*; 3.35 +import java.lang.management.*; 3.36 + 3.37 +public class TestFullGCCount { 3.38 + 3.39 + public String collectorName = "ConcurrentMarkSweep"; 3.40 + 3.41 + public static void main(String [] args) { 3.42 + 3.43 + TestFullGCCount t = null; 3.44 + if (args.length==2) { 3.45 + t = new TestFullGCCount(args[0], args[1]); 3.46 + } else { 3.47 + t = new TestFullGCCount(); 3.48 + } 3.49 + System.out.println("Monitoring collector: " + t.collectorName); 3.50 + t.run(); 3.51 + } 3.52 + 3.53 + public TestFullGCCount(String pool, String collector) { 3.54 + collectorName = collector; 3.55 + } 3.56 + 3.57 + public TestFullGCCount() { 3.58 + } 3.59 + 3.60 + public void run() { 3.61 + int count = 0; 3.62 + int iterations = 20; 3.63 + long counts[] = new long[iterations]; 3.64 + boolean diffAlways2 = true; // assume we will fail 3.65 + 3.66 + for (int i=0; i<iterations; i++) { 3.67 + System.gc(); 3.68 + counts[i] = getCollectionCount(); 3.69 + if (i>0) { 3.70 + if (counts[i] - counts[i-1] != 2) { 3.71 + diffAlways2 = false; 3.72 + } 3.73 + } 3.74 + } 3.75 + if (diffAlways2) { 3.76 + throw new RuntimeException("FAILED: System.gc must be incrementing count twice."); 3.77 + } 3.78 + System.out.println("Passed."); 3.79 + } 3.80 + 3.81 + private long getCollectionCount() { 3.82 + long count = 0; 3.83 + List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); 3.84 + List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); 3.85 + for (int i=0; i<collectors.size(); i++) { 3.86 + GarbageCollectorMXBean collector = collectors.get(i); 3.87 + String name = collector.getName(); 3.88 + if (name.contains(collectorName)) { 3.89 + System.out.println(name + ": collection count = " 3.90 + + collector.getCollectionCount()); 3.91 + count = collector.getCollectionCount(); 3.92 + } 3.93 + } 3.94 + return count; 3.95 + } 3.96 + 3.97 +} 3.98 +