1 /*
2  * Copyright (c) 2017, 2021, 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 /*
30  * @test HandshakeTransitionTest
31  * @summary This does a sanity test of the poll in the native wrapper.
32  * @requires vm.debug
33  * @library /testlibrary /test/lib
34  * @build HandshakeTransitionTest
35  * @run main/native HandshakeTransitionTest
36  */
37 
38 public class HandshakeTransitionTest {
someTime(int ms)39     public static native void someTime(int ms);
40 
main(String[] args)41     public static void main(String[] args) throws Exception {
42         ProcessBuilder pb =
43             ProcessTools.createTestJvm(
44                     "-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
45                     "-XX:+SafepointALot",
46                     "-XX:+HandshakeALot",
47                     "-XX:GuaranteedSafepointInterval=20",
48                     "-Xlog:ergo*",
49                     "-XX:ParallelGCThreads=1",
50                     "-XX:ConcGCThreads=1",
51                     "-XX:CICompilerCount=2",
52                     "HandshakeTransitionTest$Test");
53 
54         OutputAnalyzer output = ProcessTools.executeProcess(pb);
55         output.reportDiagnosticSummary();
56         output.shouldHaveExitValue(0);
57         output.stdoutShouldContain("JOINED");
58     }
59 
60     static class Test implements Runnable {
61         final static int testLoops = 2000;
62         final static int testSleep = 1; //ms
63 
main(String[] args)64         public static void main(String[] args) throws Exception {
65             System.loadLibrary("HandshakeTransitionTest");
66             Test test = new Test();
67             Thread[] threads = new Thread[64];
68             for (int i = 0; i<threads.length ; i++) {
69                 threads[i] = new Thread(test);
70                 threads[i].start();
71             }
72             for (Thread t : threads) {
73                 t.join();
74             }
75             System.out.println("JOINED");
76         }
77 
78         @Override
run()79         public void run() {
80             try {
81                 for (int i = 0; i<testLoops ; i++) {
82                     someTime(testSleep);
83                 }
84             } catch (Exception e) {
85                 System.out.println(e.getMessage());
86                 System.exit(1);
87             }
88         }
89     }
90 }
91