1 /* 2 * Copyright (c) 2011, 2018, 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 /* 26 * @test 27 * 28 * @summary converted from VM Testbase vm/mlvm/meth/stress/jni/nativeAndMH. 29 * VM Testbase keywords: [feature_mlvm, nonconcurrent] 30 * VM Testbase readme: 31 * DESCRIPTION 32 * The test obtains a MH to a native method and call it. The native method in turn, calls 33 * another method handle and so on. 34 * The test verifies that arguments are correctly passed between native methods and MHs. 35 * 36 * @library /vmTestbase 37 * /test/lib 38 * @run driver jdk.test.lib.FileInstaller . . 39 * 40 * @comment build test class and indify classes 41 * @build vm.mlvm.meth.stress.jni.nativeAndMH.Test 42 * @run driver vm.mlvm.share.IndifiedClassesBuilder 43 * 44 * @run main/othervm/native 45 * vm.mlvm.meth.stress.jni.nativeAndMH.Test 46 * -stressIterationsFactor 1000 47 * -threadsPerCpu 20 48 * -threadsExtra 20 49 */ 50 51 package vm.mlvm.meth.stress.jni.nativeAndMH; 52 53 import java.lang.invoke.MethodHandle; 54 import java.lang.invoke.MethodHandles; 55 import java.lang.invoke.MethodType; 56 57 import nsk.share.test.Stresser; 58 import vm.mlvm.share.Env; 59 import vm.mlvm.share.MlvmTest; 60 import vm.mlvm.share.MultiThreadedTest; 61 62 public class Test extends MultiThreadedTest { 63 64 private static final String RETURN_VALUE = "test"; 65 66 static { 67 System.loadLibrary("nativeAndMH"); 68 } 69 70 private static native Object native01(Object a1, String a2, Object a3, Object a4, Object a5, Object a6, MethodHandle mh); 71 72 private static final MethodType MT_calledFromNative = MethodType.methodType( 73 Object.class, 74 Object.class, Object.class, int.class, long.class, double.class, float.class); 75 76 private static Object calledFromNative(Object s1, Object s2, int i, long l, double d, float f) { 77 return RETURN_VALUE; 78 } 79 80 @Override 81 protected boolean runThread(int threadNum) throws Throwable { 82 MethodHandle mh = MethodHandles.lookup().findStatic( 83 Test.class, 84 "calledFromNative", 85 MT_calledFromNative); 86 87 Stresser stresser = createStresser(); 88 stresser.start(1); 89 90 while ( stresser.continueExecution() ) { 91 stresser.iteration(); 92 93 String retValMH = (String) (Object) mh.invokeExact((Object) "test1", (Object) "test2", 3, 4L, 5D, 6F); 94 String retValNative = (String) native01("test1", "test2", 3, 4L, 5D, 6F, mh).toString(); 95 96 if ( ! retValMH.equals(RETURN_VALUE) || ! retValNative.equals(RETURN_VALUE) ) 97 markTestFailed("Gold value: " + RETURN_VALUE + "; MH returned: " + retValMH + "; Native returned: " + retValNative); 98 else 99 Env.traceVerbose("Gold value: " + RETURN_VALUE + "; MH returned: " + retValMH + "; Native returned: " + retValNative); 100 } 101 102 stresser.finish(); 103 stresser.printExecutionInfo(getLog().getOutStream()); 104 105 return true; 106 } 107 108 public static void main(String[] args) { MlvmTest.launch(args); } 109 }