Search in sources :

Example 1 with SubstrateObjectConstant

use of com.oracle.svm.core.meta.SubstrateObjectConstant in project graal by oracle.

the class SubstrateMemoryAccessProviderImpl method readPrimitiveConstant.

@Override
public JavaConstant readPrimitiveConstant(JavaKind kind, Constant baseConstant, long displacement, int bits) {
    SignedWord offset = WordFactory.signed(displacement);
    long rawValue;
    if (baseConstant instanceof SubstrateObjectConstant) {
        Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
        assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
        switch(bits) {
            case Byte.SIZE:
                rawValue = BarrieredAccess.readByte(baseObject, offset);
                break;
            case Short.SIZE:
                rawValue = BarrieredAccess.readShort(baseObject, offset);
                break;
            case Integer.SIZE:
                rawValue = BarrieredAccess.readInt(baseObject, offset);
                break;
            case Long.SIZE:
                rawValue = BarrieredAccess.readLong(baseObject, offset);
                break;
            default:
                throw shouldNotReachHere();
        }
    } else if (baseConstant instanceof PrimitiveConstant) {
        PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
        if (!prim.getJavaKind().isNumericInteger()) {
            return null;
        }
        Pointer basePointer = WordFactory.unsigned(prim.asLong());
        if (basePointer.equal(0)) {
            return null;
        }
        switch(bits) {
            case Byte.SIZE:
                rawValue = basePointer.readByte(offset);
                break;
            case Short.SIZE:
                rawValue = basePointer.readShort(offset);
                break;
            case Integer.SIZE:
                rawValue = basePointer.readInt(offset);
                break;
            case Long.SIZE:
                rawValue = basePointer.readLong(offset);
                break;
            default:
                throw shouldNotReachHere();
        }
    } else {
        return null;
    }
    return toConstant(kind, rawValue);
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) Pointer(org.graalvm.word.Pointer) SignedWord(org.graalvm.word.SignedWord)

Example 2 with SubstrateObjectConstant

use of com.oracle.svm.core.meta.SubstrateObjectConstant in project graal by oracle.

the class ConstantFoldLoadFieldPlugin method tryConstantFold.

private static boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant receiver) {
    ConstantNode result = ConstantFoldUtil.tryConstantFold(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), field, receiver, b.getOptions());
    if (result != null) {
        JavaConstant value = result.asJavaConstant();
        if (b.getMetaAccess() instanceof AnalysisMetaAccess && value.getJavaKind() == JavaKind.Object && value.isNonNull()) {
            SubstrateObjectConstant sValue = (SubstrateObjectConstant) value;
            SubstrateObjectConstant sReceiver = (SubstrateObjectConstant) receiver;
            Object root;
            if (receiver == null) {
                /* Found a root, map the constant value to the root field. */
                root = field;
            } else {
                /* Map the constant value to the root field of it's receiver. */
                root = sReceiver.getRoot();
                assert root != null : receiver.toValueString() + " : " + field + " : " + b.getGraph();
            }
            sValue.setRoot(root);
        }
        result = b.getGraph().unique(result);
        b.push(field.getJavaKind(), result);
        return true;
    }
    return false;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess)

Example 3 with SubstrateObjectConstant

use of com.oracle.svm.core.meta.SubstrateObjectConstant in project graal by oracle.

the class SubstrateMemoryAccessProviderImpl method readObjectConstant.

private static JavaConstant readObjectConstant(Constant baseConstant, long displacement, boolean requireCompressed) {
    SignedWord offset = WordFactory.signed(displacement);
    if (baseConstant instanceof SubstrateObjectConstant) {
        // always compressed (if enabled)
        assert !requireCompressed || ReferenceAccess.singleton().haveCompressedReferences();
        Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
        assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
        Object rawValue = BarrieredAccess.readObject(baseObject, offset);
        return SubstrateObjectConstant.forObject(rawValue, requireCompressed);
    }
    if (baseConstant instanceof PrimitiveConstant) {
        // never compressed
        assert !requireCompressed;
        PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
        if (!prim.getJavaKind().isNumericInteger()) {
            return null;
        }
        Word baseAddress = WordFactory.unsigned(prim.asLong());
        if (baseAddress.equal(0)) {
            return null;
        }
        Word address = baseAddress.add(offset);
        Object rawValue = ReferenceAccess.singleton().readObjectAt(address, false);
        return SubstrateObjectConstant.forObject(rawValue, false);
    }
    return null;
}
Also used : Word(org.graalvm.compiler.word.Word) SignedWord(org.graalvm.word.SignedWord) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) SignedWord(org.graalvm.word.SignedWord)

Aggregations

SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)3 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)2 SignedWord (org.graalvm.word.SignedWord)2 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 Word (org.graalvm.compiler.word.Word)1 Pointer (org.graalvm.word.Pointer)1