Search in sources :

Example 1 with HotSpotResolvedJavaType

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

the class ReplaceConstantNodesPhase method handleHotSpotObjectConstant.

/**
 * Replace an object constant with an indirect load {@link ResolveConstantNode}. Currently we
 * support only strings.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotObjectConstant} that needs
 *            resolution.
 */
private static void handleHotSpotObjectConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotObjectConstant constant = (HotSpotObjectConstant) node.asJavaConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) constant.getType();
    if (type.mirror().equals(String.class)) {
        assert !constant.isCompressed() : "No support for replacing compressed oop constants";
        FixedWithNextNode replacement = graph.add(new ResolveConstantNode(node));
        insertReplacement(graph, stateMapper, node, replacement);
        node.replaceAtUsages(replacement, n -> !(n instanceof ResolveConstantNode));
    } else {
        throw new GraalError("Unsupported object constant type: " + type);
    }
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Example 2 with HotSpotResolvedJavaType

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

the class HotSpotGraalMBean method optionsFor.

public OptionValues optionsFor(OptionValues initialValues, ResolvedJavaMethod forMethod) {
    ensureRegistered(true);
    if (forMethod instanceof HotSpotResolvedJavaMethod) {
        HotSpotResolvedObjectType type = ((HotSpotResolvedJavaMethod) forMethod).getDeclaringClass();
        if (type instanceof HotSpotResolvedJavaType) {
            Class<?> clazz = ((HotSpotResolvedJavaType) type).mirror();
            Reference<ClassLoader> addNewRef = new WeakReference<>(clazz.getClassLoader());
            if (!loaders.contains(addNewRef)) {
                EconomicSet<Reference<ClassLoader>> newLoaders = EconomicSet.create(RefEquivalence.INSTANCE, loaders);
                newLoaders.add(addNewRef);
                this.loaders = newLoaders;
            }
        }
    }
    return currentMap(initialValues, forMethod);
}
Also used : HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) WeakReference(java.lang.ref.WeakReference) Reference(java.lang.ref.Reference) WeakReference(java.lang.ref.WeakReference)

Example 3 with HotSpotResolvedJavaType

use of jdk.vm.ci.hotspot.HotSpotResolvedJavaType 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 4 with HotSpotResolvedJavaType

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

the class ReplaceConstantNodesPhase method tryToReplaceWithExisting.

/**
 * Try to find dominating node doing the resolution that can be reused.
 *
 * @param graph
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private static void tryToReplaceWithExisting(StructuredGraph graph, ConstantNode node) {
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
    EconomicMap<Block, Node> blockToExisting = EconomicMap.create();
    for (Node n : node.usages().filter(n -> isReplacementNode(n))) {
        blockToExisting.put(nodeToBlock.get(n), n);
    }
    for (Node use : node.usages().filter(n -> !isReplacementNode(n)).snapshot()) {
        boolean replaced = false;
        Block b = nodeToBlock.get(use);
        Node e = blockToExisting.get(b);
        if (e != null) {
            // the use is scheduled after it.
            for (Node n : blockToNodes.get(b)) {
                if (n.equals(use)) {
                    // Usage is before initialization, can't use it
                    break;
                }
                if (n.equals(e)) {
                    use.replaceFirstInput(node, e);
                    replaced = true;
                    break;
                }
            }
        }
        if (!replaced) {
            // Look for dominating blocks that have existing nodes
            for (Block d : blockToExisting.getKeys()) {
                if (strictlyDominates(d, b)) {
                    use.replaceFirstInput(node, blockToExisting.get(d));
                    break;
                }
            }
        }
    }
}
Also used : LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) Constant(jdk.vm.ci.meta.Constant) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) EconomicMap(org.graalvm.collections.EconomicMap) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) HotSpotConstantLoadAction(org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ReentrantNodeIterator(org.graalvm.compiler.phases.graph.ReentrantNodeIterator) NodeIteratorClosure(org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) BasePhase(org.graalvm.compiler.phases.BasePhase) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) FrameState(org.graalvm.compiler.nodes.FrameState) ConstantNode.getConstantNodes(org.graalvm.compiler.nodes.ConstantNode.getConstantNodes) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) StateSplit(org.graalvm.compiler.nodes.StateSplit) LoadMethodCountersNode.getLoadMethodCountersNodes(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode.getLoadMethodCountersNodes) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) HashSet(java.util.HashSet) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) NodeMap(org.graalvm.compiler.graph.NodeMap) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) AbstractControlFlowGraph.strictlyDominates(org.graalvm.compiler.core.common.cfg.AbstractControlFlowGraph.strictlyDominates) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Block(org.graalvm.compiler.nodes.cfg.Block) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List)

Example 5 with HotSpotResolvedJavaType

use of jdk.vm.ci.hotspot.HotSpotResolvedJavaType 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

HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)5 HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)3 GraalError (org.graalvm.compiler.debug.GraalError)3 ResolveConstantNode (org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode)3 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)3 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)2 HotSpotResolvedObjectType (jdk.vm.ci.hotspot.HotSpotResolvedObjectType)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 LoadConstantIndirectlyNode (org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 Reference (java.lang.ref.Reference)1 WeakReference (java.lang.ref.WeakReference)1 HashSet (java.util.HashSet)1 List (java.util.List)1 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 Constant (jdk.vm.ci.meta.Constant)1 ConstantReflectionProvider (jdk.vm.ci.meta.ConstantReflectionProvider)1 EconomicMap (org.graalvm.collections.EconomicMap)1 AbstractControlFlowGraph.strictlyDominates (org.graalvm.compiler.core.common.cfg.AbstractControlFlowGraph.strictlyDominates)1