Search in sources :

Example 11 with MethodPointer

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

the class CompileQueue method ensureCalleesCompiled.

protected void ensureCalleesCompiled(HostedMethod method, CompileReason reason, CompilationResult result) {
    for (Infopoint infopoint : result.getInfopoints()) {
        if (infopoint instanceof Call) {
            Call call = (Call) infopoint;
            HostedMethod callTarget = (HostedMethod) call.target;
            if (call.direct) {
                ensureCompiled(callTarget, new DirectCallReason(method, reason));
            } else if (callTarget != null && callTarget.getImplementations() != null) {
                for (HostedMethod impl : callTarget.getImplementations()) {
                    ensureCompiled(impl, new VirtualCallReason(method, callTarget, reason));
                }
            }
        }
    }
    for (DataPatch dataPatch : result.getDataPatches()) {
        Reference reference = dataPatch.reference;
        if (reference instanceof ConstantReference) {
            VMConstant constant = ((ConstantReference) reference).getConstant();
            if (constant instanceof SubstrateMethodPointerConstant) {
                MethodPointer pointer = ((SubstrateMethodPointerConstant) constant).pointer();
                final ResolvedJavaMethod method1 = pointer.getMethod();
                HostedMethod hMethod = (HostedMethod) method1;
                ensureCompiled(hMethod, new MethodPointerConstantReason(method, hMethod, reason));
            }
        }
    }
}
Also used : Call(jdk.vm.ci.code.site.Call) ConstantReference(jdk.vm.ci.code.site.ConstantReference) ConstantReference(jdk.vm.ci.code.site.ConstantReference) Reference(jdk.vm.ci.code.site.Reference) SubstrateMethodPointerConstant(com.oracle.svm.core.meta.SubstrateMethodPointerConstant) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint) DataPatch(jdk.vm.ci.code.site.DataPatch) MethodPointer(com.oracle.svm.core.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) VMConstant(jdk.vm.ci.meta.VMConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 12 with MethodPointer

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

the class CompileQueue method replaceAnalysisObjects.

public static Object replaceAnalysisObjects(Object obj, Node node, IdentityHashMap<Object, Object> replacements, HostedUniverse hUniverse) {
    if (obj == null) {
        return obj;
    }
    Object existingReplacement = replacements.get(obj);
    if (existingReplacement != null) {
        return existingReplacement;
    }
    Object newReplacement;
    if (obj instanceof Node) {
        throw VMError.shouldNotReachHere("Must not replace a Graal graph nodes, only data objects referenced from a node");
    } else if (obj instanceof AnalysisType) {
        newReplacement = hUniverse.lookup((AnalysisType) obj);
    } else if (obj instanceof AnalysisMethod) {
        newReplacement = hUniverse.lookup((AnalysisMethod) obj);
    } else if (obj instanceof AnalysisField) {
        newReplacement = hUniverse.lookup((AnalysisField) obj);
    } else if (obj.getClass() == ObjectStamp.class) {
        ObjectStamp stamp = (ObjectStamp) obj;
        if (stamp.type() == null) {
            /* No actual type referenced, so we can keep the original object. */
            newReplacement = obj;
        } else {
            /*
                 * ObjectStamp references a type indirectly, so we need to provide a new stamp with
                 * a modified type.
                 */
            newReplacement = new ObjectStamp((ResolvedJavaType) replaceAnalysisObjects(stamp.type(), node, replacements, hUniverse), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), stamp.isAlwaysArray());
        }
    } else if (obj.getClass() == SubstrateNarrowOopStamp.class) {
        SubstrateNarrowOopStamp stamp = (SubstrateNarrowOopStamp) obj;
        if (stamp.type() == null) {
            newReplacement = obj;
        } else {
            newReplacement = new SubstrateNarrowOopStamp((ResolvedJavaType) replaceAnalysisObjects(stamp.type(), node, replacements, hUniverse), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), stamp.isAlwaysArray(), stamp.getEncoding());
        }
    } else if (obj.getClass() == PiNode.PlaceholderStamp.class) {
        assert ((PiNode.PlaceholderStamp) obj).type() == null : "PlaceholderStamp never references a type";
        newReplacement = obj;
    } else if (obj instanceof AbstractObjectStamp) {
        throw VMError.shouldNotReachHere("missing replacement of a subclass of AbstractObjectStamp: " + obj.getClass().getTypeName());
    } else if (obj.getClass() == StampPair.class) {
        StampPair pair = (StampPair) obj;
        Stamp trustedStamp = (Stamp) replaceAnalysisObjects(pair.getTrustedStamp(), node, replacements, hUniverse);
        Stamp uncheckedStamp = (Stamp) replaceAnalysisObjects(pair.getUncheckedStamp(), node, replacements, hUniverse);
        if (trustedStamp != pair.getTrustedStamp() || uncheckedStamp != pair.getUncheckedStamp()) {
            newReplacement = StampPair.create(trustedStamp, uncheckedStamp);
        } else {
            newReplacement = pair;
        }
    } else if (obj.getClass() == ResolvedJavaMethodBytecode.class) {
        ResolvedJavaMethodBytecode bc = (ResolvedJavaMethodBytecode) obj;
        newReplacement = new ResolvedJavaMethodBytecode(hUniverse.lookup(bc.getMethod()), bc.getOrigin());
    } else if (obj instanceof Object[]) {
        Object[] originalArray = (Object[]) obj;
        Object[] copyArray = null;
        for (int i = 0; i < originalArray.length; i++) {
            Object original = originalArray[i];
            Object replaced = replaceAnalysisObjects(original, node, replacements, hUniverse);
            if (replaced != original) {
                if (copyArray == null) {
                    copyArray = Arrays.copyOf(originalArray, originalArray.length);
                }
                copyArray[i] = replaced;
            }
        }
        newReplacement = copyArray != null ? copyArray : originalArray;
    } else if (obj.getClass() == NodeSourcePosition.class) {
        NodeSourcePosition nsp = (NodeSourcePosition) obj;
        NodeSourcePosition replacedCaller = (NodeSourcePosition) replaceAnalysisObjects(nsp.getCaller(), node, replacements, hUniverse);
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(nsp.getMethod(), node, replacements, hUniverse);
        newReplacement = new NodeSourcePosition(nsp.getSourceLanguage(), replacedCaller, replacedMethod, nsp.getBCI(), nsp.getMarker());
    } else if (obj.getClass() == BytecodePosition.class) {
        BytecodePosition nsp = (BytecodePosition) obj;
        BytecodePosition replacedCaller = (BytecodePosition) replaceAnalysisObjects(nsp.getCaller(), node, replacements, hUniverse);
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(nsp.getMethod(), node, replacements, hUniverse);
        newReplacement = new BytecodePosition(replacedCaller, replacedMethod, nsp.getBCI());
    } else if (obj.getClass() == SubstrateMethodPointerConstant.class) {
        SubstrateMethodPointerConstant methodPointerConstant = (SubstrateMethodPointerConstant) obj;
        MethodPointer methodPointer = methodPointerConstant.pointer();
        ResolvedJavaMethod method = methodPointer.getMethod();
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(method, node, replacements, hUniverse);
        newReplacement = new SubstrateMethodPointerConstant(new MethodPointer(replacedMethod));
    } else {
        /* Check that we do not have a class or package name that relates to the analysis. */
        assert !obj.getClass().getName().toLowerCase().contains("analysis") : "Object " + obj + " of " + obj.getClass() + " in node " + node;
        assert !obj.getClass().getName().toLowerCase().contains("pointsto") : "Object " + obj + " of " + obj.getClass() + " in node " + node;
        newReplacement = obj;
    }
    replacements.put(obj, newReplacement);
    return newReplacement;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) SubstrateNarrowOopStamp(com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) BytecodePosition(jdk.vm.ci.code.BytecodePosition) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) SubstrateMethodPointerConstant(com.oracle.svm.core.meta.SubstrateMethodPointerConstant) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) PiNode(org.graalvm.compiler.nodes.PiNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) MethodPointer(com.oracle.svm.core.meta.MethodPointer) StampPair(org.graalvm.compiler.core.common.type.StampPair) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) SubstrateNarrowOopStamp(com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 13 with MethodPointer

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

the class InvalidVTableEntryFeature method buildHubs.

private void buildHubs() {
    InstanceReferenceMapEncoder referenceMapEncoder = new InstanceReferenceMapEncoder();
    Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
    for (HostedType type : hUniverse.getTypes()) {
        ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
        assert ((SubstrateReferenceMap) referenceMap).hasNoDerivedOffsets();
        referenceMaps.put(type, referenceMap);
        referenceMapEncoder.add(referenceMap);
    }
    ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll());
    ObjectLayout ol = ConfigurationValues.getObjectLayout();
    for (HostedType type : hUniverse.getTypes()) {
        hUniverse.bb.getHeartbeatCallback().run();
        int layoutHelper;
        int monitorOffset = 0;
        if (type.isInstanceClass()) {
            HostedInstanceClass instanceClass = (HostedInstanceClass) type;
            if (instanceClass.isAbstract()) {
                layoutHelper = LayoutEncoding.forAbstract();
            } else if (HybridLayout.isHybrid(type)) {
                HybridLayout<?> hybridLayout = new HybridLayout<>(instanceClass, ol);
                JavaKind storageKind = hybridLayout.getArrayElementStorageKind();
                boolean isObject = (storageKind == JavaKind.Object);
                layoutHelper = LayoutEncoding.forArray(type, isObject, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(storageKind));
            } else if (instanceClass.getJavaClass().equals(StoredContinuation.class)) {
                layoutHelper = LayoutEncoding.forStoredContinuation();
            } else {
                layoutHelper = LayoutEncoding.forInstance(type, ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
            }
            monitorOffset = instanceClass.getMonitorFieldOffset();
        } else if (type.isArray()) {
            JavaKind storageKind = type.getComponentType().getStorageKind();
            boolean isObject = (storageKind == JavaKind.Object);
            layoutHelper = LayoutEncoding.forArray(type, isObject, ol.getArrayBaseOffset(storageKind), ol.getArrayIndexShift(storageKind));
        } else if (type.isInterface()) {
            layoutHelper = LayoutEncoding.forInterface();
        } else if (type.isPrimitive()) {
            layoutHelper = LayoutEncoding.forPrimitive();
        } else {
            throw VMError.shouldNotReachHere();
        }
        /*
             * The vtable entry values are available only after the code cache layout is fixed, so
             * leave them 0.
             */
        CFunctionPointer[] vtable = new CFunctionPointer[type.vtable.length];
        for (int idx = 0; idx < type.vtable.length; idx++) {
            /*
                 * We install a CodePointer in the vtable; when generating relocation info, we will
                 * know these point into .text
                 */
            vtable[idx] = new MethodPointer(type.vtable[idx]);
        }
        // pointer maps in Dynamic Hub
        ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
        assert referenceMap != null;
        assert ((SubstrateReferenceMap) referenceMap).hasNoDerivedOffsets();
        long referenceMapIndex;
        if (referenceMap == SubstrateReferenceMap.STORED_CONTINUATION_REFERENCE_MAP) {
            referenceMapIndex = ReferenceMapIndex.STORED_CONTINUATION;
        } else {
            referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
        }
        DynamicHub hub = type.getHub();
        hub.setData(layoutHelper, type.getTypeID(), monitorOffset, type.getTypeCheckStart(), type.getTypeCheckRange(), type.getTypeCheckSlot(), type.getTypeCheckSlots(), vtable, referenceMapIndex, type.isInstantiated());
    }
}
Also used : HashMap(java.util.HashMap) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) MethodPointer(com.oracle.svm.core.meta.MethodPointer) ReferenceMapEncoder(com.oracle.svm.core.heap.ReferenceMapEncoder) InstanceReferenceMapEncoder(com.oracle.svm.core.heap.InstanceReferenceMapEncoder) HybridLayout(com.oracle.svm.hosted.config.HybridLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateReferenceMap(com.oracle.svm.core.heap.SubstrateReferenceMap) InstanceReferenceMapEncoder(com.oracle.svm.core.heap.InstanceReferenceMapEncoder) DynamicHubSupport(com.oracle.svm.core.hub.DynamicHubSupport) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

MethodPointer (com.oracle.svm.core.meta.MethodPointer)13 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)6 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)6 CFunctionPointer (org.graalvm.nativeimage.c.function.CFunctionPointer)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)2 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)2 SubstrateMethodPointerConstant (com.oracle.svm.core.meta.SubstrateMethodPointerConstant)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 ClassInitializationInfo (com.oracle.svm.core.classinitialization.ClassInitializationInfo)1 IsolateLeaveStub (com.oracle.svm.core.code.IsolateLeaveStub)1 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)1 DeoptimizationSupport (com.oracle.svm.core.deopt.DeoptimizationSupport)1 LLVMTextSectionInfo (com.oracle.svm.core.graal.llvm.util.LLVMObjectFileReader.LLVMTextSectionInfo)1 DeoptEntryNode (com.oracle.svm.core.graal.nodes.DeoptEntryNode)1