hotspot/test/gc/arguments/TestVerifyBeforeAndAfterGCFlags.java
author jlahoda
Mon, 13 Feb 2017 09:37:26 +0100
changeset 43772 4e5350b7be75
parent 41705 332239c052cc
permissions -rw-r--r--
8173777: Merge javac -Xmodule into javac--patch-module Summary: Merging -Xmodule: functionality into --patch-module. Reviewed-by: jjg, mchung, rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
     1
/*
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     4
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     7
 * published by the Free Software Foundation.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     8
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    13
 * accompanied this code).
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    14
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    18
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    21
 * questions.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40667
diff changeset
    22
 */
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    23
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    24
/*
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    25
 * @test TestVerifyBeforeAndAfterGCFlags
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    26
 * @key gc
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    27
 * @bug 8000831
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    28
 * @summary Runs an simple application (GarbageProducer) with various
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    29
         combinations of -XX:{+|-}Verify{After|Before}GC flags and checks that
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    30
         output contain or doesn't contain expected patterns
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 35061
diff changeset
    31
 * @modules java.base/jdk.internal.misc
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    32
 * @modules java.management
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    33
 * @library /test/lib
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    34
 * @run driver TestVerifyBeforeAndAfterGCFlags
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    35
 */
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    36
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    37
import java.util.ArrayList;
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    38
import java.util.Collections;
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    39
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30179
diff changeset
    40
import jdk.test.lib.Utils;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    41
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    42
import jdk.test.lib.process.ProcessTools;
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    43
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    44
public class TestVerifyBeforeAndAfterGCFlags {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    45
40667
f9cf2db7f59f 8163146: Remove os::check_heap on Windows
ctornqvi
parents: 40631
diff changeset
    46
    // VerifyBeforeGC:[Verifying threads heap tenured eden syms strs zone dict metaspace chunks hand code cache ]
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    47
    public static final String VERIFY_BEFORE_GC_PATTERN = "Verifying Before GC";
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    48
    // VerifyBeforeGC: VerifyBeforeGC: VerifyBeforeGC:
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    49
    public static final String VERIFY_BEFORE_GC_CORRUPTED_PATTERN = "VerifyBeforeGC:(?!\\[Verifying[^]]+\\])";
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    50
40667
f9cf2db7f59f 8163146: Remove os::check_heap on Windows
ctornqvi
parents: 40631
diff changeset
    51
    // VerifyAfterGC:[Verifying threads heap tenured eden syms strs zone dict metaspace chunks hand code cache ]
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    52
    public static final String VERIFY_AFTER_GC_PATTERN = "Verifying After GC";
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    53
    // VerifyAfterGC: VerifyAfterGC: VerifyAfterGC:
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    54
    public static final String VERIFY_AFTER_GC_CORRUPTED_PATTERN = "VerifyAfterGC:(?!\\[Verifying[^]]+\\])";
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    55
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    56
    public static void main(String args[]) throws Exception {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    57
        String[] filteredOpts = Utils.getFilteredTestJavaOpts(
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    58
                                    new String[] { "-Xlog:gc+verify=debug",
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    59
                                                   "-XX:+UseGCLogFileRotation",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    60
                                                   "-XX:-DisplayVMOutput",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    61
                                                   "VerifyBeforeGC",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    62
                                                   "VerifyAfterGC" });
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    63
        testVerifyFlags(false, false, filteredOpts);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    64
        testVerifyFlags(true,  true,  filteredOpts);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    65
        testVerifyFlags(true,  false, filteredOpts);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    66
        testVerifyFlags(false, true,  filteredOpts);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    67
    }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    68
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    69
    public static void testVerifyFlags(boolean verifyBeforeGC,
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    70
                                       boolean verifyAfterGC,
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    71
                                       String[] opts) throws Exception {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    72
        ArrayList<String> vmOpts = new ArrayList<>();
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    73
        if (opts != null && (opts.length > 0)) {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    74
            Collections.addAll(vmOpts, opts);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    75
        }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    76
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    77
        Collections.addAll(vmOpts, new String[] {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    78
                                       "-Xlog:gc+verify=debug",
30179
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    79
                                       "-Xmx5m",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    80
                                       "-Xms5m",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    81
                                       "-Xmn3m",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    82
                                       "-XX:+UnlockDiagnosticVMOptions",
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    83
                                       (verifyBeforeGC ? "-XX:+VerifyBeforeGC"
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    84
                                                       : "-XX:-VerifyBeforeGC"),
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    85
                                       (verifyAfterGC ? "-XX:+VerifyAfterGC"
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    86
                                                      : "-XX:-VerifyAfterGC"),
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    87
                                       GarbageProducer.class.getName() });
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    88
        ProcessBuilder procBuilder =
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    89
            ProcessTools.createJavaProcessBuilder(vmOpts.toArray(
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    90
                                                   new String[vmOpts.size()]));
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    91
        OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    92
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    93
        analyzer.shouldHaveExitValue(0);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    94
        analyzer.shouldNotMatch(VERIFY_BEFORE_GC_CORRUPTED_PATTERN);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    95
        analyzer.shouldNotMatch(VERIFY_AFTER_GC_CORRUPTED_PATTERN);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    96
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    97
        if (verifyBeforeGC) {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    98
            analyzer.shouldMatch(VERIFY_BEFORE_GC_PATTERN);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
    99
        } else {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   100
            analyzer.shouldNotMatch(VERIFY_BEFORE_GC_PATTERN);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   101
        }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   102
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   103
        if (verifyAfterGC) {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   104
            analyzer.shouldMatch(VERIFY_AFTER_GC_PATTERN);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   105
        } else {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   106
            analyzer.shouldNotMatch(VERIFY_AFTER_GC_PATTERN);
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   107
        }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   108
    }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   109
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   110
    public static class GarbageProducer {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   111
        static long[][] garbage = new long[10][];
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   112
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   113
        public static void main(String args[]) {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   114
            int j = 0;
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   115
            for(int i = 0; i<1000; i++) {
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   116
                garbage[j] = new long[10000];
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   117
                j = (j+1)%garbage.length;
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   118
            }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   119
        }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   120
    }
9901fb13c60e 8026043: Add regression test for JDK-8000831
eistepan
parents:
diff changeset
   121
}