use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class FloatArraysEqualsTest method testStableArray.
public void testStableArray(String methodName) {
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
Result expected = executeExpected(method, null);
StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
ConstantNode newConstantNode = ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess());
newConstantNode = graph.unique(newConstantNode);
constantNode.replaceAndDelete(newConstantNode);
}
}
CompilationResult result = compile(method, graph);
InstalledCode code = addMethod(graph.getDebug(), method, result);
Result actual;
try {
actual = new Result(code.executeVarargs(), null);
} catch (Exception e) {
actual = new Result(null, e);
}
assertEquals(expected, actual);
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class StringSubstitutionsTest method testSubstitution.
public void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, boolean optional, Object[] args1, Object[] args2) {
ResolvedJavaMethod realMethod = getResolvedJavaMethod(holder, methodName);
ResolvedJavaMethod testMethod = getResolvedJavaMethod(testMethodName);
StructuredGraph graph = testGraph(testMethodName);
// Check to see if the resulting graph contains the expected node
StructuredGraph replacement = getReplacements().getSubstitution(realMethod, -1, false, null);
if (replacement == null && !optional) {
assertInGraph(graph, intrinsicClass);
}
// Force compilation
InstalledCode code = getCode(testMethod);
assert optional || code != null;
for (int i = 0; i < args1.length; i++) {
Object arg1 = args1[i];
Object arg2 = args2[i];
Object expected = invokeSafe(realMethod, arg1, arg2);
// Verify that the original method and the substitution produce the same value
assertDeepEquals(expected, invokeSafe(testMethod, null, arg1, arg2));
// Verify that the generated code and the original produce the same value
assertDeepEquals(expected, executeVarargsSafe(code, arg1, arg2));
}
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class TestSHASubstitutions method testWithInstalledIntrinsic.
void testWithInstalledIntrinsic(String className, String methodName, String testSnippetName, Object... args) {
Class<?> c;
try {
c = Class.forName(className);
} catch (ClassNotFoundException e) {
// may have been installed
return;
}
InstalledCode code = null;
try {
ResolvedJavaMethod method = getResolvedJavaMethod(testSnippetName);
Object receiver = method.isStatic() ? null : this;
Result expect = executeExpected(method, receiver, args);
code = compileAndInstallSubstitution(c, methodName);
assertTrue("Failed to install " + methodName, code != null);
testAgainstExpected(method, expect, receiver, args);
} catch (AssumptionViolatedException e) {
// Suppress so that subsequent calls to this method within the
// same Junit @Test annotated method can proceed.
}
if (code != null) {
code.invalidate();
}
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class ExplicitExceptionTest method getCode.
@Override
protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
InstalledCode installedCode = super.getCode(method, graph, forceCompile, installAsDefault, options);
Assume.assumeTrue(exceptionWasSeen(method));
assertDeepEquals(expectedForeignCallCount, lastCompiledGraph.getNodes().filter(ForeignCallNode.class).count());
return installedCode;
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class ArrayCopyIntrinsificationTest method getCode.
@Override
protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph g, boolean forceCompile, boolean installAsDefault, OptionValues options) {
StructuredGraph graph = g == null ? parseForCompile(method) : g;
int nodeCount = graph.getNodeCount();
InstalledCode result = super.getCode(method, graph, forceCompile, installAsDefault, options);
boolean graphWasProcessed = nodeCount != graph.getNodeCount();
if (graphWasProcessed) {
if (mustIntrinsify) {
for (Node node : graph.getNodes()) {
if (node instanceof Invoke) {
Invoke invoke = (Invoke) node;
Assert.assertTrue(invoke.callTarget() instanceof DirectCallTargetNode);
LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
JavaMethod callee = directCall.targetMethod();
if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
// A partial snippet (e.g., ArrayCopySnippets.checkcastArraycopy) may
// call the original arraycopy method
} else {
Assert.assertTrue(callee.toString(), callee.getName().equals("<init>"));
Assert.assertTrue(getMetaAccess().lookupJavaType(ArrayIndexOutOfBoundsException.class).equals(callee.getDeclaringClass()) || getMetaAccess().lookupJavaType(NullPointerException.class).equals(callee.getDeclaringClass()));
}
}
}
} else {
boolean found = false;
for (Node node : graph.getNodes()) {
if (node instanceof Invoke) {
Invoke invoke = (Invoke) node;
LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
JavaMethod callee = directCall.targetMethod();
if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
found = true;
} else {
fail("found invoke to some method other than arraycopy: " + callee);
}
}
}
Assert.assertTrue("did not find invoke to arraycopy", found);
}
}
return result;
}
Aggregations