--- /dev/null 2013-08-12 13:03:05.207958275 +0400 +++ new/test/gc/arguments/TestVerifyBeforeAndAfterGCFlags.java 2013-10-08 17:20:46.880806130 +0400 @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 only, as +* published by the Free Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* version 2 for more details (a copy is included in the LICENSE file that +* accompanied this code). +* +* You should have received a copy of the GNU General Public License version +* 2 along with this work; if not, write to the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +* +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +* or visit www.oracle.com if you need additional information or have any +* questions. +*/ + +/* + * @test TestVerifyBeforeAndAfterGCFlags + * @key gc + * @bug 8000831 + * @summary Heap verification output incorrect/incomplete + * @library /testlibrary + * @build TestVerifyBeforeAndAfterGCFlags + * @run main/othervm TestVerifyBeforeAndAfterGCFlags + */ + +import com.oracle.java.testlibrary.*; + +public class TestVerifyBeforeAndAfterGCFlags { + + public static final String VERIFY_BEFORE_GC_PATTERN = "VerifyBeforeGC:\\[Verifying\\s+([^]\\s]+\\s+)+\\]"; + public static final String VERIFY_BEFORE_GC_CORRUPTED_PATTERN = "VerifyBeforeGC:(?!\\[Verifying[^]]+\\])"; + public static final String VERIFY_AFTER_GC_PATTERN = "VerifyAfterGC:\\[Verifying\\s+([^]\\s]+\\s+)+\\]"; + public static final String VERIFY_AFTER_GC_CORRUPTED_PATTERN = "VerifyAfterGC:(?!\\[Verifying[^]]+\\])"; + + public static void main(String args[]) throws Exception { + String options = System.getProperty("test.java.opts"); + if (options == null) { + options = ""; + } + options = options.replaceAll("(-Xloggc:[^ ]+)|(-XX:LogVMOutput[^ ]+)",""); + + testVerifyFlags(false, false, options); + testVerifyFlags(true, true, options); + testVerifyFlags(true, false, options); + testVerifyFlags(false, true, options); + } + + public static void testVerifyFlags(boolean verifyBeforeGC, + boolean verifyAfterGC, + String options) throws Exception { + options += " -XX:+UnlockDiagnosticVMOptions -Xmx5m" + + " -XX:" + (verifyBeforeGC ? "+" : "-") + "VerifyBeforeGC" + + " -XX:" + (verifyAfterGC ? "+" : "-") + "VerifyAfterGC" + + " " + GarbageProducer.class.getName(); + + options = options.replaceAll("[\\s]+", " ").trim(); + + ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(options.split(" ")); + OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); + + analyzer.shouldHaveExitValue(0); + analyzer.shouldNotMatch(VERIFY_BEFORE_GC_CORRUPTED_PATTERN); + analyzer.shouldNotMatch(VERIFY_AFTER_GC_CORRUPTED_PATTERN); + + if (verifyBeforeGC) { + analyzer.shouldMatch(VERIFY_BEFORE_GC_PATTERN); + } else { + analyzer.shouldNotMatch(VERIFY_BEFORE_GC_PATTERN); + } + + if (verifyAfterGC) { + analyzer.shouldMatch(VERIFY_AFTER_GC_PATTERN); + } else { + analyzer.shouldNotMatch(VERIFY_AFTER_GC_PATTERN); + } + } + + public static class GarbageProducer { + public static void main(String args[]) { + long[][] garbage = new long[10][]; + int j = 0; + for(int i = 0; i<1000; i++) { + garbage[j] = new long[10000]; + j = (j+1)%garbage.length; + } + } + } +}