Search in sources :

Example 1 with LoadConstantIndirectlyNode

use of org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode 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)

Aggregations

HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)1 HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 LoadConstantIndirectlyNode (org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode)1 ResolveConstantNode (org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1