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/java/sequences. 29 * VM Testbase keywords: [feature_mlvm, nonconcurrent, quarantine] 30 * VM Testbase comments: 8079714 31 * VM Testbase readme: 32 * DESCRIPTION 33 * Creates a sequence of method handles that manipulates arguments. The following manipulations are used: 34 * - Numeric conversions 35 * - Boxing and unboxing 36 * - Adding arguments, binding arguments 37 * - Deleting arguments 38 * - Reordering arguments 39 * - Array scattering and gathering 40 * - A MH that calls pair of methods ("guardWithTest") 41 * - The test calculates the "correct result" of calling the sequence of method handles by using it's own logic and compares it with the result of calling MHs. 42 * 43 * @library /vmTestbase 44 * /test/lib 45 * @run driver jdk.test.lib.FileInstaller . . 46 * 47 * @comment build test class and indify classes 48 * @build vm.mlvm.meth.stress.java.sequences.Test 49 * @run driver vm.mlvm.share.IndifiedClassesBuilder 50 * 51 * @run main/othervm vm.mlvm.meth.stress.java.sequences.Test 52 */ 53 54 package vm.mlvm.meth.stress.java.sequences; 55 56 import java.lang.invoke.MethodHandle; 57 import java.lang.invoke.MethodHandles; 58 import java.lang.invoke.MethodType; 59 60 import vm.mlvm.meth.share.Argument; 61 import vm.mlvm.meth.share.MHTransformationGen; 62 import vm.mlvm.meth.share.RandomArgumentsGen; 63 import vm.mlvm.share.MlvmTest; 64 65 public class Test extends MlvmTest { 66 67 public static void main(String[] args) { 68 MlvmTest.launch(args); 69 } 70 71 public static class Example { 72 private Argument[] finalArgs; 73 private boolean eqI; 74 private boolean eqS; 75 private boolean eqF; 76 77 public String m0(int i, String s, Float f) { 78 this.eqI = this.finalArgs[0].getValue().equals(i); 79 this.eqS = this.finalArgs[1].getValue().equals(s); 80 this.eqF = this.finalArgs[2].getValue().equals(f); 81 82 return "i=" + i + " (" + this.eqI + "); " + "s=" + s + " (" + this.eqS 83 + "); " + "f=" + f + " (" + this.eqF + "); "; 84 } 85 86 public void setFinalArgs(Argument[] finalArgs) { 87 this.finalArgs = finalArgs; 88 } 89 90 public boolean areParametersEqual() { 91 return this.eqI && this.eqS && this.eqF; 92 } 93 } 94 95 @Override 96 public boolean run() throws Throwable { 97 98 final Example e = new Example(); 99 100 final MethodHandle mhM0 = MethodHandles.lookup().findVirtual( 101 Example.class, 102 "m0", 103 MethodType.methodType(String.class, int.class, String.class, Float.class)); 104 105 Argument[] finalArgs = RandomArgumentsGen.createRandomArgs(true, mhM0.type()); 106 e.setFinalArgs(finalArgs); 107 108 Argument finalRetVal = Argument.fromValue(e.m0((int) (Integer) finalArgs[0].getValue(), (String) finalArgs[1].getValue(), (Float) finalArgs[2].getValue())); 109 110 MHTransformationGen.callSequence(MHTransformationGen.createSequence(finalRetVal, e, mhM0, finalArgs), false); 111 112 if (!e.areParametersEqual()) { 113 getLog().complain("Unexpected argument values were received at the final method"); 114 return false; 115 } 116 117 return true; 118 } 119 }