1 /*
2  * Copyright (c) 2017, 2020, 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 import jdk.test.lib.Utils;
26 import jdk.test.lib.process.ProcessTools;
27 import jdk.test.lib.process.OutputAnalyzer;
28 
29 import sun.hotspot.WhiteBox;
30 
31 /*
32  * @test HandshakeTransitionTest
33  * @summary This does a sanity test of the poll in the native wrapper.
34  * @requires vm.debug
35  * @library /testlibrary /test/lib
36  * @build HandshakeTransitionTest
37  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
38  * @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI HandshakeTransitionTest
39  */
40 
41 public class HandshakeTransitionTest {
someTime(int ms)42     public static native void someTime(int ms);
43 
main(String[] args)44     public static void main(String[] args) throws Exception {
45         WhiteBox wb = WhiteBox.getWhiteBox();
46         Boolean useJVMCICompiler = wb.getBooleanVMFlag("UseJVMCICompiler");
47         String useJVMCICompilerStr;
48         if (useJVMCICompiler != null) {
49             useJVMCICompilerStr = useJVMCICompiler ?  "-XX:+UseJVMCICompiler" : "-XX:-UseJVMCICompiler";
50         } else {
51             // pass something innocuous
52             useJVMCICompilerStr = "-XX:+UnlockExperimentalVMOptions";
53         }
54         ProcessBuilder pb =
55             ProcessTools.createTestJvm(
56                     "-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
57                     "-XX:+SafepointALot",
58                     "-XX:+HandshakeALot",
59                     "-XX:GuaranteedSafepointInterval=20",
60                     "-Xlog:ergo*",
61                     "-XX:ParallelGCThreads=1",
62                     "-XX:ConcGCThreads=1",
63                     "-XX:CICompilerCount=2",
64                     "-XX:+UnlockExperimentalVMOptions",
65                     useJVMCICompilerStr,
66                     "HandshakeTransitionTest$Test");
67 
68         OutputAnalyzer output = ProcessTools.executeProcess(pb);
69         output.reportDiagnosticSummary();
70         output.shouldHaveExitValue(0);
71         output.stdoutShouldContain("JOINED");
72     }
73 
74     static class Test implements Runnable {
75         final static int testLoops = 2000;
76         final static int testSleep = 1; //ms
77 
main(String[] args)78         public static void main(String[] args) throws Exception {
79             System.loadLibrary("HandshakeTransitionTest");
80             Test test = new Test();
81             Thread[] threads = new Thread[64];
82             for (int i = 0; i<threads.length ; i++) {
83                 threads[i] = new Thread(test);
84                 threads[i].start();
85             }
86             for (Thread t : threads) {
87                 t.join();
88             }
89             System.out.println("JOINED");
90         }
91 
92         @Override
run()93         public void run() {
94             try {
95                 for (int i = 0; i<testLoops ; i++) {
96                     someTime(testSleep);
97                 }
98             } catch (Exception e) {
99                 System.out.println(e.getMessage());
100                 System.exit(1);
101             }
102         }
103     }
104 }
105