Mercurial > hg > truffle
comparison graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/StandardMethodSubstitutionsTest.java @ 18120:86ec7f6f71b3
refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 18 Oct 2014 00:08:19 +0200 |
parents | 1668de777c42 |
children | 7cefdad149ad |
comparison
equal
deleted
inserted
replaced
18119:6997fce99fa3 | 18120:86ec7f6f71b3 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.graal.replacements.test; | 23 package com.oracle.graal.replacements.test; |
24 | 24 |
25 import java.lang.reflect.*; | |
26 | |
27 import org.junit.*; | 25 import org.junit.*; |
28 | 26 |
29 import com.oracle.graal.api.code.*; | 27 import com.oracle.graal.api.code.*; |
28 import com.oracle.graal.api.meta.*; | |
30 import com.oracle.graal.api.replacements.*; | 29 import com.oracle.graal.api.replacements.*; |
31 import com.oracle.graal.nodes.*; | 30 import com.oracle.graal.nodes.*; |
32 import com.oracle.graal.nodes.calc.*; | 31 import com.oracle.graal.nodes.calc.*; |
33 import com.oracle.graal.replacements.*; | 32 import com.oracle.graal.replacements.*; |
34 import com.oracle.graal.replacements.nodes.*; | 33 import com.oracle.graal.replacements.nodes.*; |
62 return Math.sqrt(value) + Math.log(value) + Math.log10(value) + Math.sin(value) + Math.cos(value) + Math.tan(value); | 61 return Math.sqrt(value) + Math.log(value) + Math.log10(value) + Math.sin(value) + Math.cos(value) + Math.tan(value); |
63 // Math.exp(value) + | 62 // Math.exp(value) + |
64 // Math.pow(value, 13); | 63 // Math.pow(value, 13); |
65 } | 64 } |
66 | 65 |
67 private static Object executeVarargsSafe(InstalledCode code, Object... args) { | |
68 try { | |
69 return code.executeVarargs(args); | |
70 } catch (InvalidInstalledCodeException e) { | |
71 throw new RuntimeException(e); | |
72 } | |
73 } | |
74 | |
75 private static Object invokeSafe(Method method, Object... args) { | |
76 method.setAccessible(true); | |
77 try { | |
78 Object result = method.invoke(null, args); | |
79 return result; | |
80 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | |
81 throw new RuntimeException(e); | |
82 } | |
83 } | |
84 | |
85 public void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, boolean optional, Object... args) { | 66 public void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, boolean optional, Object... args) { |
86 Method realMethod = getMethod(holder, methodName); | 67 ResolvedJavaMethod realJavaMethod = getResolvedJavaMethod(holder, methodName); |
87 Method testMethod = getMethod(testMethodName); | 68 ResolvedJavaMethod testJavaMethod = getResolvedJavaMethod(testMethodName); |
88 StructuredGraph graph = test(testMethodName); | 69 StructuredGraph graph = test(testMethodName); |
89 | 70 |
90 // Check to see if the resulting graph contains the expected node | 71 // Check to see if the resulting graph contains the expected node |
91 StructuredGraph replacement = getReplacements().getMethodSubstitution(getMetaAccess().lookupJavaMethod(realMethod)); | 72 StructuredGraph replacement = getReplacements().getMethodSubstitution(realJavaMethod); |
92 if (replacement == null && !optional) { | 73 if (replacement == null && !optional) { |
93 assertInGraph(graph, intrinsicClass); | 74 assertInGraph(graph, intrinsicClass); |
94 } | 75 } |
95 | 76 |
96 // Force compilation | 77 // Force compilation |
97 InstalledCode code = getCode(getMetaAccess().lookupJavaMethod(testMethod), parseEager(testMethod)); | 78 InstalledCode code = getCode(testJavaMethod, parseEager(testJavaMethod)); |
98 assert optional || code != null; | 79 assert optional || code != null; |
99 for (Object l : args) { | 80 for (Object l : args) { |
100 // Verify that the original method and the substitution produce the same value | 81 // Verify that the original method and the substitution produce the same value |
101 assertDeepEquals(invokeSafe(testMethod, l), invokeSafe(realMethod, l)); | 82 Object expected = invokeSafe(realJavaMethod, null, l); |
83 assertDeepEquals(expected, invokeSafe(testJavaMethod, null, l)); | |
102 // Verify that the generated code and the original produce the same value | 84 // Verify that the generated code and the original produce the same value |
103 assertDeepEquals(executeVarargsSafe(code, l), invokeSafe(realMethod, l)); | 85 assertDeepEquals(expected, executeVarargsSafe(code, l)); |
104 } | 86 } |
105 } | 87 } |
106 | 88 |
107 @Test | 89 @Test |
108 public void testIntegerSubstitutions() { | 90 public void testIntegerSubstitutions() { |