use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StringEqualsConstantTest method testStringEquals.
private void testStringEquals(String s0, String s1) {
ResolvedJavaMethod method = getResolvedJavaMethod("stringEquals");
StructuredGraph graph = parseForCompile(method);
graph.getParameter(0).replaceAndDelete(asConstant(graph, s0));
graph.getParameter(1).replaceAndDelete(asConstant(graph, s1));
compile(method, graph);
FixedNode firstFixed = graph.start().next();
Assert.assertThat(firstFixed, instanceOf(ReturnNode.class));
ReturnNode ret = (ReturnNode) firstFixed;
JavaConstant result = ret.result().asJavaConstant();
if (result == null) {
Assert.fail("result not constant: " + ret.result());
} else {
int expected = s0.equals(s1) ? 1 : 0;
Assert.assertEquals("result", expected, result.asInt());
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StringHashConstantTest method test2.
@Test
public void test2() {
ResolvedJavaMethod method = getResolvedJavaMethod("constantHashCode");
StructuredGraph graph = parseForCompile(method);
FixedNode firstFixed = graph.start().next();
Assert.assertThat(firstFixed, instanceOf(ReturnNode.class));
ReturnNode ret = (ReturnNode) firstFixed;
JavaConstant result = ret.result().asJavaConstant();
if (result == null) {
Assert.fail("result not constant: " + ret.result());
} else {
int expected = A_CONSTANT_STRING.hashCode();
Assert.assertEquals("result", expected, result.asInt());
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StringHashConstantTest method test1.
@Test
public void test1() {
ResolvedJavaMethod method = getResolvedJavaMethod("parameterizedHashCode");
StructuredGraph graph = parseForCompile(method);
String s = "some string";
int expected = s.hashCode();
graph.getParameter(0).replaceAndDelete(asConstant(graph, s));
compile(method, graph);
FixedNode firstFixed = graph.start().next();
Assert.assertThat(firstFixed, instanceOf(ReturnNode.class));
ReturnNode ret = (ReturnNode) firstFixed;
JavaConstant result = ret.result().asJavaConstant();
if (result == null) {
Assert.fail("result not constant: " + ret.result());
} else {
Assert.assertEquals("result", expected, result.asInt());
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class SystemArrayCopyTest method parse.
@Override
protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
StructuredGraph graph = super.parse(builder, graphBuilderSuite);
if (argsToBind != null) {
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int index = param.index();
if (args[index] != null) {
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
}
}
return graph;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class ReflectionSubstitutionType method throwFailedCast.
private static void throwFailedCast(HostedGraphKit graphKit, ResolvedJavaType expectedType, ValueNode actual) {
ResolvedJavaMethod createFailedCast = graphKit.findMethod(ExceptionHelpers.class, "createFailedCast", true);
JavaConstant expected = graphKit.getConstantReflection().asJavaClass(expectedType);
ValueNode expectedNode = graphKit.createConstant(expected, JavaKind.Object);
ValueNode exception = graphKit.createJavaCallWithExceptionAndUnwind(InvokeKind.Static, createFailedCast, expectedNode, actual);
graphKit.append(new UnwindNode(exception));
}
Aggregations