Search in sources :

Example 96 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class UnboxNode method findSynonym.

private static ValueNode findSynonym(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, ValueNode forValue, JavaKind boxingKind) {
    if (forValue.isConstant()) {
        JavaConstant constant = forValue.asJavaConstant();
        JavaConstant unboxed = constantReflection.unboxPrimitive(constant);
        if (unboxed != null && unboxed.getJavaKind() == boxingKind) {
            return ConstantNode.forConstant(unboxed, metaAccess);
        }
    } else if (forValue instanceof BoxNode) {
        BoxNode box = (BoxNode) forValue;
        if (boxingKind == box.getBoxingKind()) {
            return box.getValue();
        }
    }
    return null;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 97 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class Inflation method scanHub.

private void scanHub(ObjectScanner objectScanner, AnalysisType type) {
    SVMHost svmHost = (SVMHost) hostVM;
    JavaConstant hubConstant = SubstrateObjectConstant.forObject(svmHost.dynamicHub(type));
    objectScanner.scanConstant(hubConstant, "Hub");
}
Also used : SVMHost(com.oracle.svm.hosted.SVMHost) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 98 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class AnnotationSubstitutionField method readValue.

@Override
public JavaConstant readValue(JavaConstant receiver) {
    JavaConstant result = valueCache.get(receiver);
    if (result == null) {
        try {
            /*
                 * Invoke the accessor method of the annotation object. Since array attributes
                 * return a different, newly allocated, array at every invocation, we cache the
                 * result value.
                 */
            Proxy proxy = snippetReflection.asObject(Proxy.class, receiver);
            Method reflectionMethod = proxy.getClass().getDeclaredMethod(accessorMethod.getName());
            reflectionMethod.setAccessible(true);
            result = snippetReflection.forBoxed(getJavaKind(), reflectionMethod.invoke(proxy));
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException ex) {
            throw VMError.shouldNotReachHere(ex);
        }
        valueCache.put(receiver, result);
    }
    return result;
}
Also used : Proxy(java.lang.reflect.Proxy) JavaConstant(jdk.vm.ci.meta.JavaConstant) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 99 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class SPARCAddressLowering method lower.

private AddressNode lower(ValueNode base, long displacement) {
    if (base instanceof AddNode) {
        AddNode add = (AddNode) base;
        JavaConstant immX = asImmediate(add.getX());
        if (immX != null && SPARCAssembler.isSimm13(displacement + immX.asLong())) {
            return lower(add.getY(), displacement + immX.asLong());
        }
        JavaConstant immY = asImmediate(add.getY());
        if (immY != null && SPARCAssembler.isSimm13(displacement + immY.asLong())) {
            return lower(add.getX(), displacement + immY.asLong());
        }
        if (displacement == 0) {
            return lower(add.getX(), add.getY());
        }
    }
    assert SPARCAssembler.isSimm13(displacement);
    return base.graph().unique(new SPARCImmediateAddressNode(base, (int) displacement));
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 100 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class ConditionTest method testJoin.

@Test
public void testJoin() {
    Random rand = new Random(13);
    for (Condition c1 : Condition.values()) {
        for (Condition c2 : Condition.values()) {
            Condition join = c1.join(c2);
            assertEquals(join, c2.join(c1));
            if (join != null) {
                for (int i = 0; i < 1000; i++) {
                    JavaConstant a = JavaConstant.forInt(rand.nextInt());
                    JavaConstant b = JavaConstant.forInt(i < 100 ? a.asInt() : rand.nextInt());
                    boolean result1 = c1.foldCondition(a, b, null, false);
                    boolean result2 = c2.foldCondition(a, b, null, false);
                    boolean resultJoin = join.foldCondition(a, b, null, false);
                    if (result1 && result2) {
                        assertTrue(resultJoin);
                    } else {
                        assertFalse(resultJoin);
                    }
                }
            }
        }
    }
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) Random(java.util.Random) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5