Path: blob/master/test/hotspot/jtreg/gc/arguments/TestVerifyBeforeAndAfterGCFlags.java
40943 views
/*1* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.arguments;2425/*26* @test TestVerifyBeforeAndAfterGCFlags27* @bug 800083128* @summary Runs an simple application (GarbageProducer) with various29combinations of -XX:{+|-}Verify{After|Before}GC flags and checks that30output contain or doesn't contain expected patterns31* @requires vm.gc != "Z" & vm.gc != "Shenandoah"32* @modules java.base/jdk.internal.misc33* @modules java.management34* @library /test/lib35* @library /36* @run driver gc.arguments.TestVerifyBeforeAndAfterGCFlags37*/3839import java.util.ArrayList;40import java.util.Collections;4142import jdk.test.lib.Utils;43import jdk.test.lib.process.OutputAnalyzer;44import jdk.test.lib.process.ProcessTools;4546public class TestVerifyBeforeAndAfterGCFlags {4748// VerifyBeforeGC:[Verifying threads heap tenured eden syms strs zone dict metaspace chunks hand code cache ]49public static final String VERIFY_BEFORE_GC_PATTERN = "Verifying Before GC";50// VerifyBeforeGC: VerifyBeforeGC: VerifyBeforeGC:51public static final String VERIFY_BEFORE_GC_CORRUPTED_PATTERN = "VerifyBeforeGC:(?!\\[Verifying[^]]+\\])";5253// VerifyAfterGC:[Verifying threads heap tenured eden syms strs zone dict metaspace chunks hand code cache ]54public static final String VERIFY_AFTER_GC_PATTERN = "Verifying After GC";55// VerifyAfterGC: VerifyAfterGC: VerifyAfterGC:56public static final String VERIFY_AFTER_GC_CORRUPTED_PATTERN = "VerifyAfterGC:(?!\\[Verifying[^]]+\\])";5758public static void main(String args[]) throws Exception {59String[] filteredOpts = Utils.getFilteredTestJavaOpts(60new String[] { "-Xlog:gc+verify=debug",61"-XX:+UseGCLogFileRotation",62"-XX:-DisplayVMOutput",63"VerifyBeforeGC",64"VerifyAfterGC" });65testVerifyFlags(false, false, filteredOpts);66testVerifyFlags(true, true, filteredOpts);67testVerifyFlags(true, false, filteredOpts);68testVerifyFlags(false, true, filteredOpts);69}7071public static void testVerifyFlags(boolean verifyBeforeGC,72boolean verifyAfterGC,73String[] opts) throws Exception {74ArrayList<String> vmOpts = new ArrayList<>();75if (opts != null && (opts.length > 0)) {76Collections.addAll(vmOpts, opts);77}78Collections.addAll(vmOpts, new String[] {79"-Xlog:gc+verify=debug",80"-Xmx5m",81"-Xms5m",82"-Xmn3m",83"-XX:+UnlockDiagnosticVMOptions",84(verifyBeforeGC ? "-XX:+VerifyBeforeGC"85: "-XX:-VerifyBeforeGC"),86(verifyAfterGC ? "-XX:+VerifyAfterGC"87: "-XX:-VerifyAfterGC"),88GarbageProducer.class.getName() });89ProcessBuilder pb = GCArguments.createJavaProcessBuilder(vmOpts);90OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());9192analyzer.shouldHaveExitValue(0);93analyzer.shouldNotMatch(VERIFY_BEFORE_GC_CORRUPTED_PATTERN);94analyzer.shouldNotMatch(VERIFY_AFTER_GC_CORRUPTED_PATTERN);9596if (verifyBeforeGC) {97analyzer.shouldMatch(VERIFY_BEFORE_GC_PATTERN);98} else {99analyzer.shouldNotMatch(VERIFY_BEFORE_GC_PATTERN);100}101102if (verifyAfterGC) {103analyzer.shouldMatch(VERIFY_AFTER_GC_PATTERN);104} else {105analyzer.shouldNotMatch(VERIFY_AFTER_GC_PATTERN);106}107}108109public static class GarbageProducer {110static long[][] garbage = new long[10][];111112public static void main(String args[]) {113int j = 0;114for(int i = 0; i<1000; i++) {115garbage[j] = new long[10000];116j = (j+1)%garbage.length;117}118}119}120}121122123