Search in sources :

Example 61 with JavaKind

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

the class TruffleGraphBuilderPlugins method registerUnsafeLoadStorePlugins.

public static void registerUnsafeLoadStorePlugins(Registration r, boolean canDelayIntrinsification, JavaConstant anyConstant, JavaKind... kinds) {
    for (JavaKind kind : kinds) {
        String kindName = kind.getJavaName();
        kindName = toUpperCase(kindName.charAt(0)) + kindName.substring(1);
        String getName = "unsafeGet" + kindName;
        String putName = "unsafePut" + kindName;
        r.register4(getName, Object.class, long.class, boolean.class, Object.class, new CustomizedUnsafeLoadPlugin(kind, canDelayIntrinsification));
        r.register4(putName, Object.class, long.class, kind == JavaKind.Object ? Object.class : kind.toJavaClass(), Object.class, new CustomizedUnsafeStorePlugin(kind, anyConstant, canDelayIntrinsification));
    }
}
Also used : JavaKind(jdk.vm.ci.meta.JavaKind)

Example 62 with JavaKind

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

the class NewFrameNode method asJavaKind.

private static JavaKind asJavaKind(JavaConstant frameSlotTag) {
    int tagValue = frameSlotTag.asInt();
    JavaKind rawKind = TruffleCompilerRuntime.getRuntime().getJavaKindForFrameSlotKind(tagValue);
    switch(rawKind) {
        case Boolean:
        case Byte:
        case Int:
            return JavaKind.Int;
        case Double:
        case Float:
            return rawKind;
        case Long:
        case Object:
        case Illegal:
            return JavaKind.Long;
    }
    throw new IllegalStateException("Unexpected frame slot kind tag: " + tagValue);
}
Also used : JavaKind(jdk.vm.ci.meta.JavaKind)

Example 63 with JavaKind

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

the class CEntryPointCallStubMethod method generateExceptionHandler.

private void generateExceptionHandler(HostedProviders providers, SubstrateGraphKit kit, ExceptionObjectNode exception, JavaKind returnKind) {
    if (entryPointData.getExceptionHandler() == CEntryPointOptions.FatalExceptionHandler.class) {
        kit.append(new CEntryPointLeaveNode(LeaveAction.ExceptionAbort, exception));
        kit.append(new DeadEndNode());
    } else {
        ResolvedJavaType throwable = providers.getMetaAccess().lookupJavaType(Throwable.class);
        ResolvedJavaType handler = providers.getMetaAccess().lookupJavaType(entryPointData.getExceptionHandler());
        ResolvedJavaMethod[] handlerMethods = handler.getDeclaredMethods();
        UserError.guarantee(handlerMethods.length == 1 && handlerMethods[0].isStatic(), "Exception handler class must declare exactly one static method: " + targetMethod.format("%H.%n(%p)") + " -> " + handler.toJavaName());
        JavaType[] handlerParameterTypes = handlerMethods[0].toParameterTypes();
        UserError.guarantee(handlerParameterTypes.length == 1 && ((ResolvedJavaType) handlerParameterTypes[0]).isAssignableFrom(throwable), "Exception handler method must have exactly one parameter of type Throwable: " + targetMethod.format("%H.%n(%p)") + " -> " + handlerMethods[0].format("%H.%n(%p)"));
        int handlerExceptionBci = kit.bci();
        InvokeWithExceptionNode handlerInvoke = kit.startInvokeWithException(handlerMethods[0], InvokeKind.Static, kit.getFrameState(), kit.bci(), handlerExceptionBci, exception);
        kit.noExceptionPart();
        ValueNode returnValue = handlerInvoke;
        if (handlerInvoke.getStackKind() != returnKind) {
            JavaKind fromKind = handlerInvoke.getStackKind();
            if (fromKind == JavaKind.Float && returnKind == JavaKind.Double) {
                returnValue = kit.unique(new FloatConvertNode(FloatConvert.F2D, returnValue));
            } else if (fromKind.isUnsigned() && returnKind.isNumericInteger() && returnKind.getBitCount() > fromKind.getBitCount()) {
                returnValue = kit.unique(new ZeroExtendNode(returnValue, returnKind.getBitCount()));
            } else if (fromKind.isNumericInteger() && returnKind.isNumericInteger() && returnKind.getBitCount() > fromKind.getBitCount()) {
                returnValue = kit.unique(new SignExtendNode(returnValue, returnKind.getBitCount()));
            } else {
                throw UserError.abort("Exception handler method return type must be assignable to entry point method return type: " + targetMethod.format("%H.%n(%p)") + " -> " + handlerMethods[0].format("%H.%n(%p)"));
            }
        }
        kit.createReturn(returnValue, returnValue.getStackKind());
        // fail-safe for exceptions in exception handler
        kit.exceptionPart();
        kit.append(new CEntryPointLeaveNode(LeaveAction.ExceptionAbort, kit.exceptionObject()));
        kit.append(new DeadEndNode());
        kit.endInvokeWithException();
    }
}
Also used : CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DeadEndNode(com.oracle.svm.core.graal.nodes.DeadEndNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 64 with JavaKind

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

the class CEntryPointCallStubMethod method adaptReturnValue.

private ValueNode adaptReturnValue(ResolvedJavaMethod method, HostedProviders providers, Purpose purpose, UniverseMetaAccess metaAccess, NativeLibraries nativeLibraries, HostedGraphKit kit, ValueNode invokeValue) {
    ValueNode returnValue = invokeValue;
    if (returnValue.getStackKind().isPrimitive()) {
        return returnValue;
    }
    JavaType returnType = method.getSignature().getReturnType(null);
    ElementInfo typeInfo = nativeLibraries.findElementInfo(returnType);
    if (typeInfo instanceof EnumInfo) {
        UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumValueInfo.class::isInstance), "Enum class " + returnType.toJavaName() + " needs a method that is annotated with @" + CEnumValue.class + " because it is used as the return type of an entry point method: " + targetMethod.format("%H.%n(%p)"));
        IsNullNode isNull = kit.unique(new IsNullNode(returnValue));
        kit.startIf(isNull, BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY);
        kit.thenPart();
        ResolvedJavaType enumExceptionType = metaAccess.lookupJavaType(RuntimeException.class);
        NewInstanceNode enumException = kit.append(new NewInstanceNode(enumExceptionType, true));
        Iterator<ResolvedJavaMethod> enumExceptionCtor = Arrays.stream(enumExceptionType.getDeclaredConstructors()).filter(c -> c.getSignature().getParameterCount(false) == 1 && c.getSignature().getParameterType(0, null).equals(metaAccess.lookupJavaType(String.class))).iterator();
        ConstantNode enumExceptionMessage = kit.createConstant(kit.getConstantReflection().forString("null return value cannot be converted to a C enum value"), JavaKind.Object);
        kit.createJavaCallWithExceptionAndUnwind(InvokeKind.Special, enumExceptionCtor.next(), enumException, enumExceptionMessage);
        assert !enumExceptionCtor.hasNext();
        kit.append(new CEntryPointLeaveNode(LeaveAction.ExceptionAbort, enumException));
        kit.append(new DeadEndNode());
        kit.endIf();
        // Always return enum values as a signed word because it should never be a problem if
        // the caller expects a narrower integer type and the various checks already handle
        // replacements with word types
        CInterfaceEnumTool tool = new CInterfaceEnumTool(providers.getMetaAccess(), providers.getSnippetReflection());
        JavaKind cEnumReturnType = providers.getWordTypes().getWordKind();
        assert !cEnumReturnType.isUnsigned() : "requires correct representation of signed values";
        returnValue = tool.createEnumValueInvoke(kit, (EnumInfo) typeInfo, cEnumReturnType, returnValue);
    } else if (purpose != Purpose.ANALYSIS) {
        // for analysis test cases: abort only during compilation
        throw UserError.abort("Entry point method return types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + targetMethod.format("%H.%n(%p)"));
    }
    return returnValue;
}
Also used : Isolate(org.graalvm.nativeimage.Isolate) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphProvider(com.oracle.graal.pointsto.infrastructure.GraphProvider) NativeBootImage(com.oracle.svm.hosted.image.NativeBootImage) Constant(jdk.vm.ci.meta.Constant) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) CInterfaceEnumTool(com.oracle.svm.hosted.phases.CInterfaceEnumTool) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) JavaKind(jdk.vm.ci.meta.JavaKind) IsolateThread(org.graalvm.nativeimage.IsolateThread) UserError(com.oracle.svm.core.util.UserError) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointPrologueBailoutNode(com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode) CEntryPointSetup(com.oracle.svm.core.c.function.CEntryPointSetup) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) ConstantPool(jdk.vm.ci.meta.ConstantPool) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) VMError(com.oracle.svm.core.util.VMError) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) FrameState(org.graalvm.compiler.nodes.FrameState) Type(java.lang.reflect.Type) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) NoPrologue(com.oracle.svm.core.c.function.CEntryPointOptions.NoPrologue) NoEpilogue(com.oracle.svm.core.c.function.CEntryPointOptions.NoEpilogue) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) CEnum(org.graalvm.nativeimage.c.constant.CEnum) HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Signature(jdk.vm.ci.meta.Signature) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) CEntryPointCallStubs(com.oracle.svm.core.code.CEntryPointCallStubs) EnumLookupInfo(com.oracle.svm.hosted.c.info.EnumLookupInfo) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Iterator(java.util.Iterator) CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) ExceptionHandler(jdk.vm.ci.meta.ExceptionHandler) ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) SubstrateGraphKit(com.oracle.svm.core.graal.replacements.SubstrateGraphKit) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) LineNumberTable(jdk.vm.ci.meta.LineNumberTable) LocalVariableTable(jdk.vm.ci.meta.LocalVariableTable) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DeadEndNode(com.oracle.svm.core.graal.nodes.DeadEndNode) LeaveAction(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode.LeaveAction) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) CEnum(org.graalvm.nativeimage.c.constant.CEnum) ValueNode(org.graalvm.compiler.nodes.ValueNode) CInterfaceEnumTool(com.oracle.svm.hosted.phases.CInterfaceEnumTool) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DeadEndNode(com.oracle.svm.core.graal.nodes.DeadEndNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 65 with JavaKind

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

the class NativeImageHeap method choosePartition.

/**
 * Choose a partition of the native image heap for the given object.
 */
private HeapPartition choosePartition(final Object candidate, final boolean immutableArg) {
    final HostedType type = getMetaAccess().lookupJavaType(candidate.getClass());
    assert type.getWrapped().isInstantiated() : type;
    boolean written = false;
    boolean references = false;
    boolean immutable = immutableArg;
    if (type.isInstanceClass()) {
        final HostedInstanceClass clazz = (HostedInstanceClass) type;
        if (HybridLayout.isHybrid(clazz)) {
            final HybridLayout<?> hybridLayout = new HybridLayout<>(clazz, layout);
            final HostedField arrayField = hybridLayout.getArrayField();
            written |= arrayField.isWritten();
            final JavaKind arrayKind = hybridLayout.getArrayElementKind();
            references |= arrayKind.isObject();
        }
        // Aggregate over all the fields of the instance.
        for (HostedField field : clazz.getInstanceFields(true)) {
            /*
                 * Any field that is written says the instance is written. Except that if the field
                 * is final, it will only be written during initialization during native image
                 * construction, but will not be written in the running image.
                 */
            written |= field.isWritten() && !field.isFinal();
            references |= field.getType().getStorageKind().isObject();
        }
        // If the type has a monitor field, it has a reference field that is written.
        if (clazz.getMonitorFieldOffset() != 0) {
            written = true;
            references = true;
            immutable = false;
        }
    } else if (type.isArray()) {
        HostedArrayClass clazz = (HostedArrayClass) type;
        // TODO: How to know if any of the array elements are written?
        written = true;
        JavaKind kind = clazz.getComponentType().getJavaKind();
        references = kind.isObject();
    } else {
        throw shouldNotReachHere();
    }
    if (SubstrateOptions.UseOnlyWritableBootImageHeap.getValue()) {
        assert !spawnIsolates();
        // Emergency use only! Alarms will sound!
        return writableReference;
    }
    if (!written || immutable) {
        return references ? readOnlyReference : readOnlyPrimitive;
    } else {
        return references ? writableReference : writablePrimitive;
    }
}
Also used : HostedType(com.oracle.svm.hosted.meta.HostedType) HostedArrayClass(com.oracle.svm.hosted.meta.HostedArrayClass) HostedField(com.oracle.svm.hosted.meta.HostedField) HybridLayout(com.oracle.svm.hosted.config.HybridLayout) HostedInstanceClass(com.oracle.svm.hosted.meta.HostedInstanceClass) 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