Search in sources :

Example 66 with JavaKind

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

the class UniverseBuilder method buildHubs.

private void buildHubs() {
    ReferenceMapEncoder referenceMapEncoder = new ReferenceMapEncoder();
    Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
    for (HostedType type : hUniverse.orderedTypes) {
        ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
        referenceMaps.put(type, referenceMap);
        referenceMapEncoder.add(referenceMap);
    }
    ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll(null));
    ObjectLayout ol = ConfigurationValues.getObjectLayout();
    for (HostedType type : hUniverse.orderedTypes) {
        int layoutHelper;
        int monitorOffset = 0;
        int hashCodeOffset = 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 kind = hybridLayout.getArrayElementKind();
                layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(kind), ol.getAlignment());
            } else {
                layoutHelper = LayoutEncoding.forInstance(ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
            }
            monitorOffset = instanceClass.getMonitorFieldOffset();
            hashCodeOffset = instanceClass.getHashCodeFieldOffset();
        } else if (type.isArray()) {
            JavaKind kind = type.getComponentType().getStorageKind();
            layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, ol.getArrayBaseOffset(kind), ol.getArrayIndexShift(kind), ol.getAlignment());
            hashCodeOffset = ol.getArrayHashCodeOffset();
        } else if (type.isInterface()) {
            layoutHelper = LayoutEncoding.forInterface();
        } else if (type.isPrimitive()) {
            layoutHelper = LayoutEncoding.forPrimitive();
        } else {
            throw 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] = MethodPointer.factory(type.vtable[idx]);
        }
        // pointer maps in Dynamic Hub
        ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
        assert referenceMap != null;
        long referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
        DynamicHub hub = type.getHub();
        hub.setData(layoutHelper, type.getTypeID(), monitorOffset, hashCodeOffset, type.getAssignableFromMatches(), type.instanceOfBits, vtable, referenceMapIndex, type.isInstantiated());
    }
}
Also used : HashMap(java.util.HashMap) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) ReferenceMapEncoder(com.oracle.svm.core.heap.ReferenceMapEncoder) HybridLayout(com.oracle.svm.hosted.config.HybridLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub) DynamicHubSupport(com.oracle.svm.core.hub.DynamicHubSupport) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 67 with JavaKind

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

the class BytecodeParser method genConditionalForIf.

private void genConditionalForIf(BciBlock trueBlock, LogicNode condition, int oldBci, int trueBlockInt, int falseBlockInt, boolean genReturn) {
    ConstantNode trueValue = graph.unique(ConstantNode.forInt(trueBlockInt));
    ConstantNode falseValue = graph.unique(ConstantNode.forInt(falseBlockInt));
    ValueNode conditionalNode = ConditionalNode.create(condition, trueValue, falseValue, NodeView.DEFAULT);
    if (conditionalNode.graph() == null) {
        conditionalNode = graph.addOrUniqueWithInputs(conditionalNode);
    }
    if (genReturn) {
        JavaKind returnKind = method.getSignature().getReturnKind().getStackKind();
        this.genReturn(conditionalNode, returnKind);
    } else {
        frameState.push(JavaKind.Int, conditionalNode);
        appendGoto(trueBlock.getSuccessor(0));
        stream.setBCI(oldBci);
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 68 with JavaKind

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

the class BytecodeParser method appendInvoke.

protected Invoke appendInvoke(InvokeKind initialInvokeKind, ResolvedJavaMethod initialTargetMethod, ValueNode[] args) {
    ResolvedJavaMethod targetMethod = initialTargetMethod;
    InvokeKind invokeKind = initialInvokeKind;
    if (initialInvokeKind.isIndirect()) {
        ResolvedJavaType contextType = this.frameState.getMethod().getDeclaringClass();
        ResolvedJavaMethod specialCallTarget = MethodCallTargetNode.findSpecialCallTarget(initialInvokeKind, args[0], initialTargetMethod, contextType);
        if (specialCallTarget != null) {
            invokeKind = InvokeKind.Special;
            targetMethod = specialCallTarget;
        }
    }
    JavaKind resultType = targetMethod.getSignature().getReturnKind();
    if (!parsingIntrinsic() && DeoptALot.getValue(options)) {
        append(new DeoptimizeNode(DeoptimizationAction.None, RuntimeConstraint));
        frameState.pushReturn(resultType, ConstantNode.defaultForKind(resultType, graph));
        return null;
    }
    JavaType returnType = targetMethod.getSignature().getReturnType(method.getDeclaringClass());
    if (graphBuilderConfig.eagerResolving() || parsingIntrinsic()) {
        returnType = returnType.resolve(targetMethod.getDeclaringClass());
    }
    if (invokeKind.hasReceiver()) {
        args[0] = emitExplicitExceptions(args[0]);
    }
    if (initialInvokeKind == InvokeKind.Special && !targetMethod.isConstructor()) {
        emitCheckForInvokeSuperSpecial(args);
    }
    InlineInfo inlineInfo = null;
    try {
        currentInvoke = new CurrentInvoke(args, invokeKind, returnType);
        if (tryNodePluginForInvocation(args, targetMethod)) {
            if (TraceParserPlugins.getValue(options)) {
                traceWithContext("used node plugin for %s", targetMethod.format("%h.%n(%p)"));
            }
            return null;
        }
        if (invokeKind.hasReceiver() && args[0].isNullConstant()) {
            append(new DeoptimizeNode(InvalidateRecompile, NullCheckException));
            return null;
        }
        if (!invokeKind.isIndirect() || (UseGuardedIntrinsics.getValue(options) && !GeneratePIC.getValue(options))) {
            if (tryInvocationPlugin(invokeKind, args, targetMethod, resultType, returnType)) {
                if (TraceParserPlugins.getValue(options)) {
                    traceWithContext("used invocation plugin for %s", targetMethod.format("%h.%n(%p)"));
                }
                return null;
            }
        }
        if (invokeKind.isDirect()) {
            inlineInfo = tryInline(args, targetMethod);
            if (inlineInfo == SUCCESSFULLY_INLINED) {
                return null;
            }
        }
    } finally {
        currentInvoke = null;
    }
    int invokeBci = bci();
    JavaTypeProfile profile = getProfileForInvoke(invokeKind);
    ExceptionEdgeAction edgeAction = getActionForInvokeExceptionEdge(inlineInfo);
    boolean partialIntrinsicExit = false;
    if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
        partialIntrinsicExit = true;
        ResolvedJavaMethod originalMethod = intrinsicContext.getOriginalMethod();
        BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor();
        if (intrinsicCallSiteParser != null) {
            // When exiting a partial intrinsic, the invoke to the original
            // must use the same context as the call to the intrinsic.
            invokeBci = intrinsicCallSiteParser.bci();
            profile = intrinsicCallSiteParser.getProfileForInvoke(invokeKind);
            edgeAction = intrinsicCallSiteParser.getActionForInvokeExceptionEdge(inlineInfo);
        } else {
            // so the bci must be set to unknown, so that the inliner patches it later.
            assert intrinsicContext.isPostParseInlined();
            invokeBci = BytecodeFrame.UNKNOWN_BCI;
            profile = null;
            edgeAction = graph.method().getAnnotation(Snippet.class) == null ? ExceptionEdgeAction.INCLUDE_AND_HANDLE : ExceptionEdgeAction.OMIT;
        }
        if (originalMethod.isStatic()) {
            invokeKind = InvokeKind.Static;
        } else {
            // The original call to the intrinsic must have been devirtualized
            // otherwise we wouldn't be here.
            invokeKind = InvokeKind.Special;
        }
        Signature sig = originalMethod.getSignature();
        returnType = sig.getReturnType(method.getDeclaringClass());
        resultType = sig.getReturnKind();
        assert intrinsicContext.allowPartialIntrinsicArgumentMismatch() || checkPartialIntrinsicExit(intrinsicCallSiteParser == null ? null : intrinsicCallSiteParser.currentInvoke.args, args);
        targetMethod = originalMethod;
    }
    Invoke invoke = createNonInlinedInvoke(edgeAction, invokeBci, args, targetMethod, invokeKind, resultType, returnType, profile);
    if (partialIntrinsicExit) {
        // This invoke must never be later inlined as it might select the intrinsic graph.
        // Until there is a mechanism to guarantee that any late inlining will not select
        // the intrinsic graph, prevent this invoke from being inlined.
        invoke.setUseForInlining(false);
    }
    return invoke;
}
Also used : InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) Snippet(org.graalvm.compiler.api.replacements.Snippet) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ResolveClassBeforeStaticInvoke(org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke) Invoke(org.graalvm.compiler.nodes.Invoke) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile) Signature(jdk.vm.ci.meta.Signature) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 69 with JavaKind

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

the class ArrayCopyCallNode method updateAlignedDisjoint.

public void updateAlignedDisjoint() {
    JavaKind componentKind = elementKind;
    if (srcPos == destPos) {
        // Can treat as disjoint
        disjoint = true;
    }
    PrimitiveConstant constantSrc = (PrimitiveConstant) srcPos.stamp(NodeView.DEFAULT).asConstant();
    PrimitiveConstant constantDst = (PrimitiveConstant) destPos.stamp(NodeView.DEFAULT).asConstant();
    if (constantSrc != null && constantDst != null) {
        if (!aligned) {
            aligned = isHeapWordAligned(constantSrc, componentKind) && isHeapWordAligned(constantDst, componentKind);
        }
        if (constantSrc.asInt() >= constantDst.asInt()) {
            // low to high copy so treat as disjoint
            disjoint = true;
        }
    }
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 70 with JavaKind

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

the class FrameStateBuilder method initializeForMethodStart.

public void initializeForMethodStart(Assumptions assumptions, boolean eagerResolve, Plugins plugins) {
    int javaIndex = 0;
    int index = 0;
    ResolvedJavaMethod method = getMethod();
    ResolvedJavaType originalType = method.getDeclaringClass();
    if (!method.isStatic()) {
        // add the receiver
        FloatingNode receiver = null;
        StampPair receiverStamp = null;
        if (plugins != null) {
            receiverStamp = plugins.getOverridingStamp(tool, originalType, true);
        }
        if (receiverStamp == null) {
            receiverStamp = StampFactory.forDeclaredType(assumptions, originalType, true);
        }
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                receiver = plugin.interceptParameter(tool, index, receiverStamp);
                if (receiver != null) {
                    break;
                }
            }
        }
        if (receiver == null) {
            receiver = new ParameterNode(javaIndex, receiverStamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(receiver);
        javaIndex = 1;
        index = 1;
    }
    Signature sig = method.getSignature();
    int max = sig.getParameterCount(false);
    ResolvedJavaType accessingClass = originalType;
    for (int i = 0; i < max; i++) {
        JavaType type = sig.getParameterType(i, accessingClass);
        if (eagerResolve) {
            type = type.resolve(accessingClass);
        }
        JavaKind kind = type.getJavaKind();
        StampPair stamp = null;
        if (plugins != null) {
            stamp = plugins.getOverridingStamp(tool, type, false);
        }
        if (stamp == null) {
            stamp = StampFactory.forDeclaredType(assumptions, type, false);
        }
        FloatingNode param = null;
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                param = plugin.interceptParameter(tool, index, stamp);
                if (param != null) {
                    break;
                }
            }
        }
        if (param == null) {
            param = new ParameterNode(index, stamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(param);
        javaIndex++;
        if (kind.needsTwoSlots()) {
            locals[javaIndex] = TWO_SLOT_MARKER;
            javaIndex++;
        }
        index++;
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)90 ValueNode (org.graalvm.compiler.nodes.ValueNode)44 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)24 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)16 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)12 JavaType (jdk.vm.ci.meta.JavaType)11 Stamp (org.graalvm.compiler.core.common.type.Stamp)10 LocationIdentity (org.graalvm.word.LocationIdentity)10 ArrayList (java.util.ArrayList)9 JavaConstant (jdk.vm.ci.meta.JavaConstant)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FrameState (org.graalvm.compiler.nodes.FrameState)8 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)8 Signature (jdk.vm.ci.meta.Signature)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6