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