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 package org.graalvm.compiler.core.test;
24
25 import java.lang.invoke.MethodHandle;
26 import java.lang.invoke.MethodHandles;
27 import java.lang.invoke.MethodType;
28
29 import org.graalvm.compiler.code.CompilationResult;
30 import org.graalvm.compiler.test.ExportingClassLoader;
31 import org.junit.Test;
32 import org.objectweb.asm.ClassWriter;
33 import org.objectweb.asm.Label;
34 import org.objectweb.asm.MethodVisitor;
35 import org.objectweb.asm.Opcodes;
36
37 import jdk.vm.ci.code.InstalledCode;
38 import jdk.vm.ci.meta.ResolvedJavaMethod;
39
40 public final class InterfaceMethodHandleTest extends GraalCompilerTest {
41 private static final MethodHandle INTERFACE_HANDLE_M;
42 private static final MethodHandle INTERFACE_HANDLE_M2;
43
44 public interface I {
45 int m();
46
47 int m2(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
48 }
49
87 public static Object invokeInterfaceHandle(I o) throws Throwable {
88 return (int) INTERFACE_HANDLE_M.invokeExact(o);
89 }
90
91 @Test
92 public void testInvokeInterface01() {
93 test("invokeInterfaceHandle", new A());
94
95 }
96
97 @Test
98 public void testInvokeInterface02() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
99 test("invokeInterfaceHandle", loader.findClass(NAME).newInstance());
100 }
101
102 public static Object invokeInterfaceHandle2(I o, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) throws Throwable {
103 return (int) INTERFACE_HANDLE_M2.invokeExact(o, a, b, c, d, e, f, g, h, i, j);
104 }
105
106 @Override
107 protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
108 if (method.getDeclaringClass().equals(getMetaAccess().lookupJavaType(M2Thrower.class))) {
109 // Make sure M2Thrower.m2 is invoked from normal code
110 return getBackend().createDefaultInstalledCode(method, compResult);
111 }
112 return super.addMethod(method, compResult);
113 }
114
115 /**
116 * Try to exercise a mixed calling sequence with regular JIT code calling a method handle that
117 * can't be inlined with an implementation compiled by Graal that throws an exception.
118 */
119 @Test
120 public void testInvokeInterface03() throws Throwable {
121 A goodInstance = new A();
122 I badInstance = new M2Thrower();
123 getCode(getMetaAccess().lookupJavaMethod(getMethod(M2Thrower.class, "m2")));
124 for (int x = 0; x < 1000; x++) {
125 final int limit = 20000;
126 for (int i = 0; i <= limit; i++) {
127 try {
128 invokeInterfaceHandle2(i < limit - 1 ? goodInstance : badInstance, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
129 } catch (InternalError e) {
130
131 }
132 }
|
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 package org.graalvm.compiler.core.test;
24
25 import java.lang.invoke.MethodHandle;
26 import java.lang.invoke.MethodHandles;
27 import java.lang.invoke.MethodType;
28
29 import org.graalvm.compiler.code.CompilationResult;
30 import org.graalvm.compiler.debug.DebugContext;
31 import org.graalvm.compiler.test.ExportingClassLoader;
32 import org.junit.Test;
33 import org.objectweb.asm.ClassWriter;
34 import org.objectweb.asm.Label;
35 import org.objectweb.asm.MethodVisitor;
36 import org.objectweb.asm.Opcodes;
37
38 import jdk.vm.ci.code.InstalledCode;
39 import jdk.vm.ci.meta.ResolvedJavaMethod;
40
41 public final class InterfaceMethodHandleTest extends GraalCompilerTest {
42 private static final MethodHandle INTERFACE_HANDLE_M;
43 private static final MethodHandle INTERFACE_HANDLE_M2;
44
45 public interface I {
46 int m();
47
48 int m2(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
49 }
50
88 public static Object invokeInterfaceHandle(I o) throws Throwable {
89 return (int) INTERFACE_HANDLE_M.invokeExact(o);
90 }
91
92 @Test
93 public void testInvokeInterface01() {
94 test("invokeInterfaceHandle", new A());
95
96 }
97
98 @Test
99 public void testInvokeInterface02() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
100 test("invokeInterfaceHandle", loader.findClass(NAME).newInstance());
101 }
102
103 public static Object invokeInterfaceHandle2(I o, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) throws Throwable {
104 return (int) INTERFACE_HANDLE_M2.invokeExact(o, a, b, c, d, e, f, g, h, i, j);
105 }
106
107 @Override
108 protected InstalledCode addMethod(DebugContext debug, ResolvedJavaMethod method, CompilationResult compResult) {
109 if (method.getDeclaringClass().equals(getMetaAccess().lookupJavaType(M2Thrower.class))) {
110 // Make sure M2Thrower.m2 is invoked from normal code
111 return getBackend().createDefaultInstalledCode(debug, method, compResult);
112 }
113 return super.addMethod(debug, method, compResult);
114 }
115
116 /**
117 * Try to exercise a mixed calling sequence with regular JIT code calling a method handle that
118 * can't be inlined with an implementation compiled by Graal that throws an exception.
119 */
120 @Test
121 public void testInvokeInterface03() throws Throwable {
122 A goodInstance = new A();
123 I badInstance = new M2Thrower();
124 getCode(getMetaAccess().lookupJavaMethod(getMethod(M2Thrower.class, "m2")));
125 for (int x = 0; x < 1000; x++) {
126 final int limit = 20000;
127 for (int i = 0; i <= limit; i++) {
128 try {
129 invokeInterfaceHandle2(i < limit - 1 ? goodInstance : badInstance, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
130 } catch (InternalError e) {
131
132 }
133 }
|