use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode 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()));
}
}
}
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class PartialEvaluator method postPartialEvaluation.
private static void postPartialEvaluation(final StructuredGraph graph) {
NeverPartOfCompilationNode.verifyNotFoundIn(graph);
for (AllowMaterializeNode materializeNode : graph.getNodes(AllowMaterializeNode.TYPE).snapshot()) {
materializeNode.replaceAtUsages(materializeNode.getFrame());
graph.removeFixed(materializeNode);
}
TruffleCompilerRuntime rt = TruffleCompilerRuntime.getRuntime();
for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
if (virtualObjectNode instanceof VirtualInstanceNode) {
VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
ResolvedJavaType type = virtualInstanceNode.type();
if (rt.isValueType(type)) {
virtualInstanceNode.setIdentity(false);
}
}
}
if (!TruffleCompilerOptions.getValue(TruffleInlineAcrossTruffleBoundary)) {
// Do not inline across Truffle boundaries.
for (MethodCallTargetNode mct : graph.getNodes(MethodCallTargetNode.TYPE)) {
InlineInfo inlineInfo = rt.getInlineInfo(mct.targetMethod(), false);
if (!inlineInfo.allowsInlining()) {
mct.invoke().setUseForInlining(false);
}
}
}
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class AllowMaterializeNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode alias = tool.getAlias(frame);
if (alias instanceof VirtualObjectNode) {
VirtualObjectNode virtual = (VirtualObjectNode) alias;
tool.setEnsureVirtualized(virtual, false);
tool.replaceWithVirtual(virtual);
} else {
tool.replaceWithValue(alias);
}
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class VirtualFrameGetNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
ValueNode dataAlias = tool.getAlias(TruffleCompilerRuntime.getRuntime().getJavaKindForFrameSlotKind(accessTag) == JavaKind.Object ? frame.virtualFrameObjectArray : frame.virtualFramePrimitiveArray);
if (tagAlias instanceof VirtualObjectNode && dataAlias instanceof VirtualObjectNode) {
VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
VirtualObjectNode dataVirtual = (VirtualObjectNode) dataAlias;
if (frameSlotIndex < tagVirtual.entryCount() && frameSlotIndex < dataVirtual.entryCount()) {
ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
if (!actualTag.isConstant() || actualTag.asJavaConstant().asInt() != accessTag) {
/*
* We cannot constant fold the tag-check immediately, so we need to create a
* guard comparing the actualTag with the accessTag.
*/
LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
tool.addNode(comparison);
tool.addNode(new FixedGuardNode(comparison, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.InvalidateRecompile));
}
ValueNode dataEntry = tool.getEntry(dataVirtual, frameSlotIndex);
if (dataEntry.getStackKind() == getStackKind()) {
tool.replaceWith(dataEntry);
return;
}
}
}
/*
* We could "virtualize" to a UnsafeLoadNode here that remains a memory access. However,
* that could prevent further escape analysis for parts of the method that actually matter.
* So we just deoptimize.
*/
insertDeoptimization(tool);
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class VirtualFrameIsNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
if (tagAlias instanceof VirtualObjectNode) {
VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
if (frameSlotIndex < tagVirtual.entryCount()) {
ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
if (actualTag.isConstant()) {
tool.replaceWith(getConstant(actualTag.asJavaConstant().asInt() == accessTag ? 1 : 0));
} else {
LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
tool.addNode(comparison);
ConditionalNode result = new ConditionalNode(comparison, getConstant(1), getConstant(0));
tool.addNode(result);
tool.replaceWith(result);
}
return;
}
}
/*
* We could "virtualize" to a UnsafeLoadNode here that remains a memory access. But it is
* simpler, and consistent with the get and set intrinsification, to deoptimize.
*/
insertDeoptimization(tool);
}
Aggregations