Search in sources :

Example 1 with HotSpotMetaspaceConstant

use of jdk.vm.ci.hotspot.HotSpotMetaspaceConstant in project graal by oracle.

the class ResolveConstantStubCall method generate.

@Override
public void generate(NodeLIRBuilderTool gen) {
    assert constant != null : "Expected the value to fold: " + value;
    Value stringValue = gen.operand(string);
    Value result;
    LIRFrameState fs = gen.state(this);
    assert fs != null : "The stateAfter is null";
    if (constant instanceof HotSpotObjectConstant) {
        result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitObjectConstantRetrieval(constant, stringValue, fs);
    } else if (constant instanceof HotSpotMetaspaceConstant) {
        if (action == HotSpotConstantLoadAction.RESOLVE) {
            result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitMetaspaceConstantRetrieval(constant, stringValue, fs);
        } else {
            assert action == HotSpotConstantLoadAction.INITIALIZE;
            result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitKlassInitializationAndRetrieval(constant, stringValue, fs);
        }
    } else {
        throw new PermanentBailoutException("Unsupported constant type: " + constant);
    }
    gen.setResult(this, result);
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) HotSpotLIRGenerator(org.graalvm.compiler.hotspot.HotSpotLIRGenerator) Value(jdk.vm.ci.meta.Value) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException)

Example 2 with HotSpotMetaspaceConstant

use of jdk.vm.ci.hotspot.HotSpotMetaspaceConstant in project graal by oracle.

the class Stub method checkStubInvariants.

/**
 * Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
 */
private boolean checkStubInvariants(CompilationResult compResult) {
    assert compResult.getExceptionHandlers().isEmpty() : this;
    // assumptions and there is no point in recording evol_method dependencies
    assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this;
    for (DataPatch data : compResult.getDataPatches()) {
        if (data.reference instanceof ConstantReference) {
            ConstantReference ref = (ConstantReference) data.reference;
            if (ref.getConstant() instanceof HotSpotMetaspaceConstant) {
                HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant();
                if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) {
                    // embedding the type '[I' is safe, since it is never unloaded
                    continue;
                }
            }
        }
        assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference;
    }
    for (Infopoint infopoint : compResult.getInfopoints()) {
        assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint;
        Call call = (Call) infopoint;
        assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target;
        HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target;
        assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage;
    }
    return true;
}
Also used : Call(jdk.vm.ci.code.site.Call) ConstantReference(jdk.vm.ci.code.site.ConstantReference) DataPatch(jdk.vm.ci.code.site.DataPatch) HotSpotForeignCallLinkage(org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage) Infopoint(jdk.vm.ci.code.site.Infopoint) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 3 with HotSpotMetaspaceConstant

use of jdk.vm.ci.hotspot.HotSpotMetaspaceConstant in project graal by oracle.

the class AMD64HotSpotLIRGenerator method emitLoadMetaspaceAddress.

@Override
public Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) {
    HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant;
    LIRKind kind = metaspaceConstant.isCompressed() ? getLIRKindTool().getNarrowPointerKind() : getLIRKindTool().getWordKind();
    Variable result = newVariable(kind);
    append(new AMD64HotSpotLoadAddressOp(result, constant, action));
    return result;
}
Also used : Variable(org.graalvm.compiler.lir.Variable) LIRKind(org.graalvm.compiler.core.common.LIRKind) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 4 with HotSpotMetaspaceConstant

use of jdk.vm.ci.hotspot.HotSpotMetaspaceConstant in project graal by oracle.

the class ReplaceConstantNodesPhase method replaceWithResolution.

/**
 * Replace the uses of a constant with either {@link LoadConstantIndirectlyNode} or
 * {@link ResolveConstantNode}.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private static void replaceWithResolution(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) node.asConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) metaspaceConstant.asResolvedJavaType();
    ResolvedJavaType topMethodHolder = graph.method().getDeclaringClass();
    ValueNode replacement;
    if (type.isArray() && type.getComponentType().isPrimitive()) {
        // Special case for primitive arrays. The AOT runtime pre-resolves them, so we may
        // omit the resolution call.
        replacement = graph.addOrUnique(new LoadConstantIndirectlyNode(node));
    } else if (type.equals(topMethodHolder) || (type.isAssignableFrom(topMethodHolder) && !type.isInterface())) {
        // If it's a supertype of or the same class that declares the top method, we are
        // guaranteed to have it resolved already. If it's an interface, we just test for
        // equality.
        replacement = graph.addOrUnique(new LoadConstantIndirectlyNode(node));
    } else {
        FixedWithNextNode fixedReplacement;
        if (builtIns.contains(type.mirror())) {
            // Special case of klass constants that come from {@link BoxingSnippets}.
            fixedReplacement = graph.add(new ResolveConstantNode(node, HotSpotConstantLoadAction.INITIALIZE));
        } else {
            fixedReplacement = graph.add(new ResolveConstantNode(node));
        }
        insertReplacement(graph, stateMapper, node, fixedReplacement);
        replacement = fixedReplacement;
    }
    node.replaceAtUsages(replacement, n -> !isReplacementNode(n));
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 5 with HotSpotMetaspaceConstant

use of jdk.vm.ci.hotspot.HotSpotMetaspaceConstant in project graal by oracle.

the class ReplaceConstantNodesPhase method handleHotSpotMetaspaceConstant.

/**
 * Replace {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} with indirection.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private void handleHotSpotMetaspaceConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) node.asConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) metaspaceConstant.asResolvedJavaType();
    if (type != null) {
        if (verifyFingerprints && checkForBadFingerprint(type)) {
            throw new GraalError("Type with bad fingerprint: " + type);
        }
        assert !metaspaceConstant.isCompressed() : "No support for replacing compressed metaspace constants";
        tryToReplaceWithExisting(graph, node);
        if (anyUsagesNeedReplacement(node)) {
            replaceWithResolution(graph, stateMapper, node);
        }
    } else {
        throw new GraalError("Unsupported metaspace constant type: " + type);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Aggregations

HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)9 Value (jdk.vm.ci.meta.Value)5 PermanentBailoutException (org.graalvm.compiler.core.common.PermanentBailoutException)4 HotSpotLIRGenerator (org.graalvm.compiler.hotspot.HotSpotLIRGenerator)4 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)3 HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)2 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)2 Call (jdk.vm.ci.code.site.Call)1 ConstantReference (jdk.vm.ci.code.site.ConstantReference)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 Infopoint (jdk.vm.ci.code.site.Infopoint)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 LIRKind (org.graalvm.compiler.core.common.LIRKind)1 GraalError (org.graalvm.compiler.debug.GraalError)1 HotSpotForeignCallLinkage (org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage)1 LoadConstantIndirectlyNode (org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode)1 ResolveConstantNode (org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode)1 Variable (org.graalvm.compiler.lir.Variable)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1