Search in sources :

Example 11 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class JNIFunctionTablesFeature method buildFunctionsInitializer.

private JNIStructFunctionsInitializer<JNINativeInterface> buildFunctionsInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
    Class<JNIFunctions> clazz = JNIFunctions.class;
    HostedType functions = access.getMetaAccess().lookupJavaType(clazz);
    HostedMethod[] methods = functions.getDeclaredMethods();
    int index = 0;
    int count = methods.length + generatedMethods.length;
    // Call, CallStatic, CallNonvirtual: for each return value kind: array, va_list, varargs
    // NewObject: array, va_list, varargs
    count += (jniKinds.size() * 3 + 1) * 3;
    int[] offsets = new int[count];
    CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
    for (HostedMethod method : methods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = getStubFunctionPointer(access, method);
        index++;
    }
    for (ResolvedJavaMethod accessor : generatedMethods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName());
        AnalysisUniverse analysisUniverse = access.getUniverse().getBigBang().getUniverse();
        AnalysisMethod analysisMethod = analysisUniverse.lookup(accessor);
        HostedMethod hostedMethod = access.getUniverse().lookup(analysisMethod);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = MethodPointer.factory(hostedMethod);
        index++;
    }
    for (CallVariant variant : CallVariant.values()) {
        CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
        String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");
        CFunctionPointer nonvirtualTrampoline = prepareCallTrampoline(access, variant, true);
        for (JavaKind kind : jniKinds) {
            String[] prefixes = { "Call", "CallStatic" };
            for (String prefix : prefixes) {
                StructFieldInfo field = findFieldFor(functionTableMetadata, prefix + kind.name() + "Method" + suffix);
                offsets[index] = field.getOffsetInfo().getProperty();
                pointers[index] = trampoline;
                index++;
            }
            StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
            offsets[index] = field.getOffsetInfo().getProperty();
            pointers[index] = nonvirtualTrampoline;
            index++;
        }
        StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = trampoline;
        index++;
    }
    VMError.guarantee(index == offsets.length && index == pointers.length);
    return new JNIStructFunctionsInitializer<>(JNINativeInterface.class, offsets, pointers, unimplemented);
}
Also used : CallVariant(com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) HostedType(com.oracle.svm.hosted.meta.HostedType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 12 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class NativeImageCodeCache method layoutMethods.

@SuppressWarnings("try")
public void layoutMethods(DebugContext debug) {
    try (Indent indent = debug.logAndIndent("layout methods")) {
        // Assign a location to all methods.
        assert codeCacheSize == 0;
        HostedMethod firstMethod = null;
        for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
            HostedMethod method = entry.getKey();
            if (firstMethod == null) {
                firstMethod = method;
            }
            CompilationResult compilation = entry.getValue();
            compilationsByStart.put(codeCacheSize, compilation);
            method.setCodeAddressOffset(codeCacheSize);
            codeCacheSize = ObjectLayout.roundUp(codeCacheSize + compilation.getTargetCodeSize(), CODE_ALIGNMENT);
        }
        // Build run-time metadata.
        FrameInfoCustomization frameInfoCustomization = new FrameInfoCustomization();
        CodeInfoEncoder codeInfoEncoder = new CodeInfoEncoder(frameInfoCustomization, null);
        for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
            final HostedMethod method = entry.getKey();
            final CompilationResult compilation = entry.getValue();
            codeInfoEncoder.addMethod(method, compilation, method.getCodeAddressOffset());
        }
        if (NativeImageOptions.PrintMethodHistogram.getValue()) {
            System.out.println("encoded deopt entry points                 ; " + frameInfoCustomization.numDeoptEntryPoints);
            System.out.println("encoded during call entry points           ; " + frameInfoCustomization.numDuringCallEntryPoints);
        }
        ImageCodeInfo imageCodeInfo = CodeInfoTable.getImageCodeCache();
        codeInfoEncoder.encodeAll();
        codeInfoEncoder.install(imageCodeInfo);
        imageCodeInfo.setData(MethodPointer.factory(firstMethod), WordFactory.unsigned(codeCacheSize));
        if (CodeInfoEncoder.Options.CodeInfoEncoderCounters.getValue()) {
            for (Counter counter : ImageSingletons.lookup(CodeInfoEncoder.Counters.class).group.getCounters()) {
                System.out.println(counter.getName() + " ; " + counter.getValue());
            }
        }
        if (Options.VerifyDeoptimizationEntryPoints.getValue()) {
            /*
                 * Missing deoptimization entry points lead to hard-to-debug transient failures, so
                 * we want the verification on all the time and not just when assertions are on.
                 */
            verifyDeoptEntries(imageCodeInfo);
        }
        assert verifyMethods(codeInfoEncoder);
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) CodeInfoEncoder(com.oracle.svm.core.code.CodeInfoEncoder) Counter(com.oracle.svm.core.util.Counter) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CompilationResult(org.graalvm.compiler.code.CompilationResult) ImageCodeInfo(com.oracle.svm.core.code.ImageCodeInfo)

Example 13 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class NativeImageHeap method addNonDataRelocation.

/**
 * Adds a relocation for a code pointer or other non-data pointers.
 */
private void addNonDataRelocation(RelocatableBuffer buffer, int index, RelocatedPointer pointer) {
    mustBeAligned(index);
    assert pointer instanceof CFunctionPointer : "unknown relocated pointer " + pointer;
    assert pointer instanceof MethodPointer : "cannot create relocation for unknown FunctionPointer " + pointer;
    HostedMethod method = ((MethodPointer) pointer).getMethod();
    if (method.isCodeAddressOffsetValid()) {
        // Only compiled methods inserted in vtables require relocation.
        buffer.addDirectRelocationWithoutAddend(index, objectSize(), pointer);
    }
}
Also used : MethodPointer(com.oracle.svm.hosted.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer)

Example 14 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class DevirtualizeCallsPhase method run.

@Override
protected void run(StructuredGraph graph) {
    for (Invoke invoke : graph.getInvokes()) {
        if (invoke.callTarget() instanceof SubstrateMethodCallTargetNode) {
            SubstrateMethodCallTargetNode callTarget = (SubstrateMethodCallTargetNode) invoke.callTarget();
            JavaMethodProfile methodProfile = callTarget.getMethodProfile();
            if (methodProfile != null) {
                if (methodProfile.getMethods().length == 0) {
                    unreachableInvoke(graph, invoke, callTarget);
                } else if (methodProfile.getMethods().length == 1) {
                    if (callTarget.invokeKind().isIndirect()) {
                        singleCallee((HostedMethod) methodProfile.getMethods()[0].getMethod(), graph, invoke, callTarget);
                    }
                }
            }
        }
    }
}
Also used : HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) SubstrateMethodCallTargetNode(com.oracle.svm.hosted.nodes.SubstrateMethodCallTargetNode) JavaMethodProfile(jdk.vm.ci.meta.JavaMethodProfile) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 15 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class CompileQueue method inlineTrivialMethods.

@SuppressWarnings("try")
private void inlineTrivialMethods(DebugContext debug) throws InterruptedException {
    for (HostedMethod method : universe.getMethods()) {
        try (DebugContext.Scope s = debug.scope("InlineTrivial", method.compilationInfo.getGraph(), method, this)) {
            if (method.compilationInfo.getGraph() != null) {
                checkTrivial(method);
            }
        } catch (Throwable e) {
            throw debug.handle(e);
        }
    }
    int round = 0;
    do {
        inliningProgress = false;
        round++;
        try (Indent ignored = debug.logAndIndent("==== Trivial Inlining  round %d\n", round)) {
            executor.init();
            universe.getMethods().stream().filter(method -> method.compilationInfo.getGraph() != null).forEach(method -> executor.execute(new TrivialInlineTask(method)));
            universe.getMethods().stream().map(method -> method.compilationInfo.getDeoptTargetMethod()).filter(Objects::nonNull).forEach(deoptTargetMethod -> executor.execute(new TrivialInlineTask(deoptTargetMethod)));
            executor.start();
            executor.complete();
            executor.shutdown();
        }
    } while (inliningProgress);
}
Also used : HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Arrays(java.util.Arrays) SubstrateOptions(com.oracle.svm.core.SubstrateOptions) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) CompletionExecutor(com.oracle.graal.pointsto.util.CompletionExecutor) GraalCompiler(org.graalvm.compiler.core.GraalCompiler) NativeImageOptions(com.oracle.svm.hosted.NativeImageOptions) Map(java.util.Map) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) Specialize(com.oracle.svm.core.annotate.Specialize) Fold(org.graalvm.compiler.api.replacements.Fold) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) CompilationResultBuilderFactory(org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory) DeoptTest(com.oracle.svm.core.annotate.DeoptTest) FrameState(org.graalvm.compiler.nodes.FrameState) Purpose(com.oracle.graal.pointsto.infrastructure.GraphProvider.Purpose) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase) InterruptImageBuilding(com.oracle.svm.core.util.InterruptImageBuilding) LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) LinearScanPhase(org.graalvm.compiler.lir.alloc.lsra.LinearScanPhase) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) GraalOptions(org.graalvm.compiler.core.common.GraalOptions) StateSplit(org.graalvm.compiler.nodes.StateSplit) RestrictHeapAccess(com.oracle.svm.core.annotate.RestrictHeapAccess) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Description(org.graalvm.compiler.debug.DebugContext.Description) Backend(org.graalvm.compiler.core.target.Backend) OptimisticOptimizations(org.graalvm.compiler.phases.OptimisticOptimizations) GraalConfiguration(com.oracle.svm.core.graal.GraalConfiguration) ArrayList(java.util.ArrayList) FrameContext(org.graalvm.compiler.lir.asm.FrameContext) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) CompilationResult(org.graalvm.compiler.code.CompilationResult) Verbosity(org.graalvm.compiler.core.common.CompilationIdentifier.Verbosity) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) GraphOrder(org.graalvm.compiler.phases.util.GraphOrder) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) DevirtualizeCallsPhase(com.oracle.svm.hosted.phases.DevirtualizeCallsPhase) DebugContextRunnable(com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable) Suites(org.graalvm.compiler.phases.tiers.Suites) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) AlwaysInlineAllCallees(com.oracle.svm.core.annotate.AlwaysInlineAllCallees) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) TreeMap(java.util.TreeMap) ForkJoinPool(java.util.concurrent.ForkJoinPool) Indent(org.graalvm.compiler.debug.Indent) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) Providers(org.graalvm.compiler.phases.util.Providers) EarlyReadEliminationPhase(org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) Constant(jdk.vm.ci.meta.Constant) FeatureHandler(com.oracle.svm.hosted.FeatureHandler) NodeIntrinsic(org.graalvm.compiler.graph.Node.NodeIntrinsic) HostedUniverse(com.oracle.svm.hosted.meta.HostedUniverse) CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) EconomicMap(org.graalvm.collections.EconomicMap) ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) Infopoint(jdk.vm.ci.code.site.Infopoint) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) DebugInfo(jdk.vm.ci.code.DebugInfo) DeletedMethod(com.oracle.svm.hosted.substitute.DeletedMethod) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RedundantMoveElimination(org.graalvm.compiler.lir.RedundantMoveElimination) VMError(com.oracle.svm.core.util.VMError) Objects(java.util.Objects) Bytecode(org.graalvm.compiler.bytecode.Bytecode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) FrameInfoEncoder(com.oracle.svm.core.code.FrameInfoEncoder) Modifier(java.lang.reflect.Modifier) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) GraalError(org.graalvm.compiler.debug.GraalError) FixReadsPhase(org.graalvm.compiler.phases.common.FixReadsPhase) DataSection(org.graalvm.compiler.code.DataSection) StartNode(org.graalvm.compiler.nodes.StartNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) InliningUtil(org.graalvm.compiler.phases.common.inlining.InliningUtil) HostedGraphBuilderPhase(com.oracle.svm.hosted.phases.HostedGraphBuilderPhase) Assembler(org.graalvm.compiler.asm.Assembler) SubstrateIntrinsicGraphBuilder(com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) NativeImageGenerator(com.oracle.svm.hosted.NativeImageGenerator) NeverInlineTrivial(com.oracle.svm.core.annotate.NeverInlineTrivial) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) BytecodeExceptionMode(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode) ImageSingletons(org.graalvm.nativeimage.ImageSingletons) Timer(com.oracle.graal.pointsto.util.Timer) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) DeoptTester(com.oracle.svm.core.deopt.DeoptTester) InfopointReason(jdk.vm.ci.code.site.InfopointReason) Invoke(org.graalvm.compiler.nodes.Invoke) Call(jdk.vm.ci.code.site.Call) Node(org.graalvm.compiler.graph.Node) Comparator(java.util.Comparator) Collections(java.util.Collections) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Indent(org.graalvm.compiler.debug.Indent) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint)

Aggregations

HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)32 DebugContext (org.graalvm.compiler.debug.DebugContext)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 CompilationResult (org.graalvm.compiler.code.CompilationResult)8 Invoke (org.graalvm.compiler.nodes.Invoke)8 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)7 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)7 Infopoint (jdk.vm.ci.code.site.Infopoint)7 Indent (org.graalvm.compiler.debug.Indent)6 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)5 HostedOptionValues (com.oracle.svm.core.option.HostedOptionValues)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Call (jdk.vm.ci.code.site.Call)5 GraalError (org.graalvm.compiler.debug.GraalError)5 OptionValues (org.graalvm.compiler.options.OptionValues)5 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)4 SubstrateIntrinsicGraphBuilder (com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder)4 Timer (com.oracle.graal.pointsto.util.Timer)4