Search in sources :

Example 86 with JavaConstant

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

the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.

public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
    ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType), null);
    InvocationPlugin plugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant() && b.getAssumptions() != null) {
                JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
                if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
                    if (targetMethod.getName().equals("isValid")) {
                        b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
                    } else {
                        assert targetMethod.getName().equals("check") : targetMethod;
                    }
                    b.getAssumptions().record(new TruffleAssumption(assumption));
                } else {
                    if (targetMethod.getName().equals("isValid")) {
                        b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
                    } else {
                        assert targetMethod.getName().equals("check") : targetMethod;
                        b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    };
    r.register1("isValid", Receiver.class, plugin);
    r.register1("check", Receiver.class, plugin);
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) TruffleAssumption(org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 87 with JavaConstant

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

the class HotSpotTruffleGraphBuilderPlugins method registerCompilationFinalReferencePlugins.

static void registerCompilationFinalReferencePlugins(InvocationPlugins plugins, boolean canDelayIntrinsification, HotSpotKnownTruffleTypes types) {
    InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, Reference.class);
    r.register1("get", InvocationPlugin.Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (!canDelayIntrinsification && receiver.isConstant()) {
                JavaConstant constant = (JavaConstant) receiver.get().asConstant();
                if (constant.isNonNull()) {
                    if (types.classWeakReference.isInstance(constant) || types.classSoftReference.isInstance(constant)) {
                        JavaConstant referent = b.getConstantReflection().readFieldValue(types.referenceReferent, constant);
                        b.addPush(JavaKind.Object, ConstantNode.forConstant(referent, b.getMetaAccess()));
                        return true;
                    }
                }
            }
            return false;
        }
    });
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 88 with JavaConstant

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

the class NativeImageCodeCache method addConstantsToHeap.

public void addConstantsToHeap(DebugContext debug) {
    for (DataSection.Data data : dataSection) {
        if (data instanceof SubstrateDataBuilder.ObjectData) {
            JavaConstant constant = ((SubstrateDataBuilder.ObjectData) data).getConstant();
            Object obj = SubstrateObjectConstant.asObject(constant);
            if (!imageHeap.getMetaAccess().lookupJavaType(obj.getClass()).getWrapped().isInstantiated()) {
                throw VMError.shouldNotReachHere("Non-instantiated type referenced by a compiled method: " + obj.getClass().getName());
            }
            imageHeap.addObject(debug, obj, false, false, constantReasons.get(constant));
        }
    }
}
Also used : DataSection(org.graalvm.compiler.code.DataSection) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 89 with JavaConstant

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

the class NativeImageHeap method writeField.

private void writeField(RelocatableBuffer buffer, ObjectInfo fields, HostedField field, JavaConstant receiver, ObjectInfo info) {
    int index = fields.getIntIndexInSection(field.getLocation());
    JavaConstant value = field.readValue(receiver);
    if (value.getJavaKind() == JavaKind.Object && SubstrateObjectConstant.asObject(value) instanceof RelocatedPointer) {
        addNonDataRelocation(buffer, index, (RelocatedPointer) SubstrateObjectConstant.asObject(value));
    } else {
        write(buffer, index, value, info != null ? info : field);
    }
}
Also used : RelocatedPointer(org.graalvm.nativeimage.c.function.RelocatedPointer) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 90 with JavaConstant

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

the class HostedMemoryAccessProvider method readPrimitiveConstant.

@Override
public JavaConstant readPrimitiveConstant(JavaKind stackKind, Constant base, long displacement, int bits) {
    JavaConstant result = doRead(stackKind, (JavaConstant) base, displacement);
    if (result == null) {
        return null;
    }
    /* Wrap the result in the expected stack kind. */
    JavaConstant wrappedResult;
    switch(stackKind) {
        case Int:
            wrappedResult = JavaConstant.forInt(result.asInt());
            break;
        case Long:
        case Float:
        case Double:
            assert result.getJavaKind() == stackKind;
            wrappedResult = result;
            break;
        default:
            throw VMError.shouldNotReachHere();
    }
    return wrappedResult;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

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