Search in sources :

Example 16 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class EarlyReadEliminationTest method testBadLoop2.

@Test
public void testBadLoop2() {
    ValueNode result = getReturn("testBadLoop2Snippet", false).result();
    assertDeepEquals(1, result.graph().getNodes().filter(LoadFieldNode.class).count());
    assertTrue(result instanceof LoadFieldNode);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 17 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class EarlyReadEliminationTest method testSimpleConflict.

@Test
public void testSimpleConflict() {
    ValueNode result = getReturn("testSimpleConflictSnippet", false).result();
    assertFalse(result.isConstant());
    assertTrue(result instanceof LoadFieldNode);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 18 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class IfNode method tryEliminateBoxedReferenceEquals.

/**
 * Attempts to replace the following pattern:
 *
 * <pre>
 * Integer x = ...;
 * Integer y = ...;
 * if ((x == y) || x.equals(y)) { ... }
 * </pre>
 *
 * with:
 *
 * <pre>
 * Integer x = ...;
 * Integer y = ...;
 * if (x.equals(y)) { ... }
 * </pre>
 *
 * whenever the probability that the reference check will pass is relatively small.
 *
 * See GR-1315 for more information.
 */
private boolean tryEliminateBoxedReferenceEquals(SimplifierTool tool) {
    if (!(condition instanceof ObjectEqualsNode)) {
        return false;
    }
    MetaAccessProvider meta = tool.getMetaAccess();
    ObjectEqualsNode equalsCondition = (ObjectEqualsNode) condition;
    ValueNode x = equalsCondition.getX();
    ValueNode y = equalsCondition.getY();
    ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
    // At least one argument for reference equal must be a boxed primitive.
    NodeView view = NodeView.from(tool);
    if (!x.stamp(view).javaType(meta).equals(integerType) && !y.stamp(view).javaType(meta).equals(integerType)) {
        return false;
    }
    // no sense to eliminate it.
    if (getTrueSuccessorProbability() > 0.4) {
        return false;
    }
    // True branch must be empty.
    if (trueSuccessor instanceof BeginNode || trueSuccessor instanceof LoopExitNode) {
        if (trueSuccessor.next() instanceof EndNode) {
        // Empty true branch.
        } else {
            return false;
        }
    } else {
        return false;
    }
    // False branch must only check the unboxed values.
    UnboxNode unbox = null;
    FixedGuardNode unboxCheck = null;
    for (FixedNode node : falseSuccessor.getBlockNodes()) {
        if (!(node instanceof BeginNode || node instanceof UnboxNode || node instanceof FixedGuardNode || node instanceof EndNode || node instanceof LoadFieldNode || node instanceof LoopExitNode)) {
            return false;
        }
        if (node instanceof UnboxNode) {
            if (unbox == null) {
                unbox = (UnboxNode) node;
            } else {
                return false;
            }
        }
        if (!(node instanceof FixedGuardNode)) {
            continue;
        }
        FixedGuardNode fixed = (FixedGuardNode) node;
        if (!(fixed.condition() instanceof IntegerEqualsNode)) {
            continue;
        }
        IntegerEqualsNode equals = (IntegerEqualsNode) fixed.condition();
        if ((isUnboxedFrom(meta, view, equals.getX(), x) && isUnboxedFrom(meta, view, equals.getY(), y)) || (isUnboxedFrom(meta, view, equals.getX(), y) && isUnboxedFrom(meta, view, equals.getY(), x))) {
            unboxCheck = fixed;
        }
    }
    if (unbox == null || unboxCheck == null) {
        return false;
    }
    // Falsify the reference check.
    setCondition(graph().addOrUniqueWithInputs(LogicConstantNode.contradiction()));
    return true;
}
Also used : IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 19 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class VerifyUsageWithEquals method isAssignableToRestrictedType.

/**
 * Determines whether the type of {@code node} is assignable to the {@link #restrictedClass}.
 */
private boolean isAssignableToRestrictedType(ValueNode node, MetaAccessProvider metaAccess) {
    if (node.stamp(NodeView.DEFAULT) instanceof ObjectStamp) {
        ResolvedJavaType restrictedType = metaAccess.lookupJavaType(restrictedClass);
        ResolvedJavaType nodeType = StampTool.typeOrNull(node);
        if (nodeType == null && node instanceof LoadFieldNode) {
            nodeType = (ResolvedJavaType) ((LoadFieldNode) node).field().getType();
        }
        if (nodeType == null && node instanceof Invoke) {
            ResolvedJavaMethod target = ((Invoke) node).callTarget().targetMethod();
            nodeType = (ResolvedJavaType) target.getSignature().getReturnType(target.getDeclaringClass());
        }
        if (nodeType == null && node instanceof UncheckedInterfaceProvider) {
            nodeType = StampTool.typeOrNull(((UncheckedInterfaceProvider) node).uncheckedStamp());
        }
        if (nodeType != null && restrictedType.isAssignableFrom(nodeType)) {
            return true;
        }
    }
    return false;
}
Also used : ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) UncheckedInterfaceProvider(org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)19 ValueNode (org.graalvm.compiler.nodes.ValueNode)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 StoreFieldNode (org.graalvm.compiler.nodes.java.StoreFieldNode)7 Node (org.graalvm.compiler.graph.Node)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)4 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)3 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)3 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)3 PhiNode (org.graalvm.compiler.nodes.PhiNode)3 RawLoadNode (org.graalvm.compiler.nodes.extended.RawLoadNode)3 RawStoreNode (org.graalvm.compiler.nodes.extended.RawStoreNode)3 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 NewInstanceNode (org.graalvm.compiler.nodes.java.NewInstanceNode)3 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)2