1 /*
 2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  *
27  * @summary converted from VM Testbase nsk/jvmti/scenarios/general_functions/GF08/gf08t001.
28  * VM Testbase keywords: [quick, jpda, jvmti, onload_only_logic, noras]
29  * VM Testbase readme:
30  * DESCRIPTION
31  *    This test implements GF08 scenario of test plan for General
32  *    Functions:
33  *        Do the following:
34  *        Run simple java apllication with VM option '-verbose:gc'.
35  *        Run the same application with JVMTI agent. The agent should
36  *        set JVMTI_VERBOSE_GC with SetVerboseFlag. Check that outputs
37  *        in stderr in both runs are equal.
38  *    The test agent has a special input parameter 'setVerboseMode'.
39  *    When VM runs the test class 'gf08t001' with
40  *      '-agentlib:gf08t001=setVerboseMode=yes'
41  *    option, then the agent calls SetVerboseFlag with
42  *    JVMTI_VERBOSE_GC flag in Onload phase.
43  *    The test's script wrapper runs the 'gf08t001' class twice.
44  *    First time, with "setVerboseMode=yes" agent mode. Second
45  *    time, with "setVerboseMode=no" agent mode and with
46  *    "-verbose:gc" VM option. In both cases the output is
47  *    searched for 'Pause Full' string, unless ExplicitGCInvokesConcurrent
48  *    is enabled and G1 is enabled. If ExplicitGCInvokesConcurrent and
49  *    G1 is enabled the test searches for 'GC' string in output.
50  *    The test fails if this string is not found in the output.
51  * COMMENTS
52  *
53  * @library /vmTestbase
54  *          /test/lib
55  * @run driver jdk.test.lib.FileInstaller . .
56  * @build sun.hotspot.WhiteBox
57  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
58  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
59  * @run main/othervm/native
60  *      -Xbootclasspath/a:.
61  *      -XX:+UnlockDiagnosticVMOptions
62  *      -XX:+WhiteBoxAPI
63  *      TestDriver
64  */
65 
66 import sun.hotspot.code.Compiler;
67 
68 public class TestDriver {
69     public static void main(String[] args) throws Exception {
70         sun.hotspot.WhiteBox wb = sun.hotspot.WhiteBox.getWhiteBox();
71         Boolean isExplicitGCInvokesConcurrentOn = wb.getBooleanVMFlag("ExplicitGCInvokesConcurrent");
72         Boolean isUseG1GCon = wb.getBooleanVMFlag("UseG1GC");
73         Boolean isUseZGCon = wb.getBooleanVMFlag("UseZGC");
74         Boolean isShenandoahGCon = wb.getBooleanVMFlag("UseShenandoahGC");
75         Boolean isUseEpsilonGCon = wb.getBooleanVMFlag("UseEpsilonGC");
76 
77         if (Compiler.isGraalEnabled() &&
78             (isUseZGCon || isUseEpsilonGCon || isShenandoahGCon)) {
79             return; // Graal does not support these GCs
80         }
81 
82         String keyPhrase;
83         if ((isExplicitGCInvokesConcurrentOn && isUseG1GCon) || isUseZGCon || isShenandoahGCon) {
84             keyPhrase = "GC";
85         } else {
86             keyPhrase = "Pause Full";
87         }
88 
89         nsk.jvmti.scenarios.general_functions.GF08.gf08t.main(new String[] {
90                 "gf08t001",
91                 nsk.jvmti.scenarios.general_functions.GF08.gf08t001.class.getName(),
92                 keyPhrase,
93                 "gc"});
94     }
95 }
96