use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NegateNodeCanonicalizationTest method testShort.
@Test
public void testShort() {
short[] a = new short[] { Short.MIN_VALUE, Short.MIN_VALUE + 1, -1, 0, 1, Short.MAX_VALUE - 1, Short.MAX_VALUE };
for (short i : a) {
ConstantNode node = ConstantNode.forShort(i, graph);
JavaConstant expected = JavaConstant.forInt(-i);
assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NegateNodeCanonicalizationTest method testDouble.
@Test
public void testDouble() {
double[] a = new double[] { Double.MIN_VALUE, Double.MIN_VALUE + 1, -1, 0, 1, Double.MAX_VALUE - 1, Double.MAX_VALUE };
for (double i : a) {
ConstantNode node = ConstantNode.forDouble(i, graph);
JavaConstant expected = JavaConstant.forDouble(-i);
assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.
private static void registerGraalDirectivesPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, GraalDirectives.class);
r.register0("deoptimize", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
return true;
}
});
r.register0("deoptimizeAndInvalidate", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
return true;
}
});
r.register0("deoptimizeAndInvalidateWithSpeculation", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
GraalError.guarantee(b.getGraph().getSpeculationLog() != null, "A speculation log is need to use `deoptimizeAndInvalidateWithSpeculation`");
BytecodePosition pos = new BytecodePosition(null, b.getMethod(), b.bci());
DirectiveSpeculationReason reason = new DirectiveSpeculationReason(pos);
JavaConstant speculation;
if (b.getGraph().getSpeculationLog().maySpeculate(reason)) {
speculation = b.getGraph().getSpeculationLog().speculate(reason);
} else {
speculation = JavaConstant.defaultForKind(JavaKind.Object);
}
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter, speculation));
return true;
}
});
r.register0("inCompiledCode", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
return true;
}
});
r.register0("controlFlowAnchor", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new ControlFlowAnchorNode());
return true;
}
});
r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
return true;
}
});
InvocationPlugin blackholePlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BlackholeNode(value));
return true;
}
};
InvocationPlugin bindToRegisterPlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BindToRegisterNode(value));
return true;
}
};
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
r.register1("blackhole", javaClass, blackholePlugin);
r.register1("bindToRegister", javaClass, bindToRegisterPlugin);
r.register1("opaque", javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(kind, new OpaqueNode(value));
return true;
}
});
}
}
InvocationPlugin spillPlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new SpillRegistersNode());
return true;
}
};
r.register0("spillRegisters", spillPlugin);
r.register1("guardingNonNull", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(value.getStackKind(), b.nullCheckedValue(value));
return true;
}
});
r.register1("ensureVirtualized", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, false));
return true;
}
});
r.register1("ensureVirtualizedHere", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, true));
return true;
}
});
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StandardGraphBuilderPlugins method registerMethodHandleImplPlugins.
private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", bytecodeProvider);
r.register2("profileBoolean", boolean.class, int[].class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
if (result.isConstant()) {
b.push(JavaKind.Boolean, result);
return true;
}
if (counters.isConstant()) {
ValueNode newResult = result;
int[] ctrs = snippetReflection.asObject(int[].class, (JavaConstant) counters.asConstant());
if (ctrs != null && ctrs.length == 2) {
int falseCount = ctrs[0];
int trueCount = ctrs[1];
int totalCount = trueCount + falseCount;
if (totalCount == 0) {
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
} else if (falseCount == 0 || trueCount == 0) {
boolean expected = falseCount == 0;
LogicNode condition = b.addWithInputs(IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected)), NodeView.DEFAULT));
b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
newResult = b.add(ConstantNode.forBoolean(expected));
} else {
// We cannot use BranchProbabilityNode here since there's no guarantee
// the result of MethodHandleImpl.profileBoolean() is used as the
// test in an `if` statement (as required by BranchProbabilityNode).
}
}
b.addPush(JavaKind.Boolean, newResult);
return true;
}
return false;
}
});
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class ArrayEqualsNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode alias1 = tool.getAlias(array1);
ValueNode alias2 = tool.getAlias(array2);
if (alias1 == alias2) {
// the same virtual objects will always have the same contents
tool.replaceWithValue(ConstantNode.forBoolean(true, graph()));
} else if (alias1 instanceof VirtualObjectNode && alias2 instanceof VirtualObjectNode) {
VirtualObjectNode virtual1 = (VirtualObjectNode) alias1;
VirtualObjectNode virtual2 = (VirtualObjectNode) alias2;
if (virtual1.entryCount() == virtual2.entryCount()) {
int entryCount = virtual1.entryCount();
boolean allEqual = true;
for (int i = 0; i < entryCount; i++) {
ValueNode entry1 = tool.getEntry(virtual1, i);
ValueNode entry2 = tool.getEntry(virtual2, i);
if (entry1 != entry2) {
if (entry1 instanceof ConstantNode && entry2 instanceof ConstantNode) {
// equal in Arrays.equals([F[F) or Arrays.equals([D[D).
if (entry1.getStackKind() == JavaKind.Float && entry2.getStackKind() == JavaKind.Float) {
float value1 = ((JavaConstant) ((ConstantNode) entry1).asConstant()).asFloat();
float value2 = ((JavaConstant) ((ConstantNode) entry2).asConstant()).asFloat();
if (Float.floatToIntBits(value1) != Float.floatToIntBits(value2)) {
allEqual = false;
}
} else if (entry1.getStackKind() == JavaKind.Double && entry2.getStackKind() == JavaKind.Double) {
double value1 = ((JavaConstant) ((ConstantNode) entry1).asConstant()).asDouble();
double value2 = ((JavaConstant) ((ConstantNode) entry2).asConstant()).asDouble();
if (Double.doubleToLongBits(value1) != Double.doubleToLongBits(value2)) {
allEqual = false;
}
} else {
allEqual = false;
}
} else {
// the contents might be different
allEqual = false;
}
}
if (entry1.stamp(NodeView.DEFAULT).alwaysDistinct(entry2.stamp(NodeView.DEFAULT))) {
// the contents are different
tool.replaceWithValue(ConstantNode.forBoolean(false, graph()));
return;
}
}
if (allEqual) {
tool.replaceWithValue(ConstantNode.forBoolean(true, graph()));
}
}
}
}
Aggregations