Search in sources :

Example 6 with MethodPointer

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

the class JNIFunctionTablesFeature method prepareCallTrampoline.

private static CFunctionPointer prepareCallTrampoline(CompilationAccessImpl access, CallVariant variant, boolean nonVirtual) {
    JNICallTrampolineMethod trampolineMethod = JNIAccessFeature.singleton().getCallTrampolineMethod(variant, nonVirtual);
    AnalysisMethod analysisTrampoline = access.getUniverse().getBigBang().getUniverse().lookup(trampolineMethod);
    HostedMethod hostedTrampoline = access.getUniverse().lookup(analysisTrampoline);
    hostedTrampoline.compilationInfo.setCustomParseFunction(trampolineMethod.createCustomParseFunction());
    hostedTrampoline.compilationInfo.setCustomCompileFunction(trampolineMethod.createCustomCompileFunction());
    return new MethodPointer(hostedTrampoline);
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) MethodPointer(com.oracle.svm.core.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) JNICallTrampolineMethod(com.oracle.svm.jni.hosted.JNICallTrampolineMethod)

Example 7 with MethodPointer

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

the class JNIFunctionTablesFeature method fillJNIFunctionsTable.

private void fillJNIFunctionsTable(CompilationAccessImpl access, CFunctionPointer[] table, CFunctionPointer defaultValue) {
    initializeFunctionPointerTable(access, table, defaultValue);
    HostedType functions = access.getMetaAccess().lookupJavaType(JNIFunctions.class);
    HostedMethod[] methods = functions.getDeclaredMethods();
    for (HostedMethod method : methods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
        int offset = field.getOffsetInfo().getProperty();
        setFunctionPointerTable(table, offset, getStubFunctionPointer(access, method));
    }
    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);
        int offset = field.getOffsetInfo().getProperty();
        setFunctionPointerTable(table, offset, new MethodPointer(hostedMethod));
    }
    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);
                int offset = field.getOffsetInfo().getProperty();
                setFunctionPointerTable(table, offset, trampoline);
            }
            StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
            int offset = field.getOffsetInfo().getProperty();
            setFunctionPointerTable(table, offset, nonvirtualTrampoline);
        }
        StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
        int offset = field.getOffsetInfo().getProperty();
        setFunctionPointerTable(table, offset, trampoline);
    }
}
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) MethodPointer(com.oracle.svm.core.meta.MethodPointer) 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 8 with MethodPointer

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

the class JNIAccessibleMethod method finishBeforeCompilation.

@Platforms(HOSTED_ONLY.class)
void finishBeforeCompilation(CompilationAccessImpl access) {
    HostedUniverse hUniverse = access.getUniverse();
    AnalysisUniverse aUniverse = access.getUniverse().getBigBang().getUniverse();
    varargsCallWrapper = new MethodPointer(hUniverse.lookup(aUniverse.lookup(varargsCallWrapperMethod)));
    arrayCallWrapper = new MethodPointer(hUniverse.lookup(aUniverse.lookup(arrayCallWrapperMethod)));
    valistCallWrapper = new MethodPointer(hUniverse.lookup(aUniverse.lookup(valistCallWrapperMethod)));
    if (!Modifier.isStatic(modifiers) && !Modifier.isAbstract(modifiers)) {
        varargsNonvirtualCallWrapper = new MethodPointer(hUniverse.lookup(aUniverse.lookup(varargsNonvirtualCallWrapperMethod)));
        arrayNonvirtualCallWrapper = new MethodPointer(hUniverse.lookup(aUniverse.lookup(arrayNonvirtualCallWrapperMethod)));
        valistNonvirtualCallWrapper = new MethodPointer(hUniverse.lookup(aUniverse.lookup(valistNonvirtualCallWrapperMethod)));
    }
    setHidingSubclasses(access.getMetaAccess(), this::anyMatchIgnoreReturnType);
}
Also used : MethodPointer(com.oracle.svm.core.meta.MethodPointer) HostedUniverse(com.oracle.svm.hosted.meta.HostedUniverse) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) Platforms(org.graalvm.nativeimage.Platforms)

Example 9 with MethodPointer

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

the class LLVMNativeImageCodeCache method linkCompiledBatches.

private void linkCompiledBatches(BatchExecutor executor, DebugContext debug, int numBatches) {
    List<String> compiledBatches = IntStream.range(0, numBatches).mapToObj(this::getBatchCompiledFilename).collect(Collectors.toList());
    nativeLink(debug, getLinkedFilename(), compiledBatches);
    LLVMTextSectionInfo textSectionInfo = objectFileReader.parseCode(getLinkedPath());
    executor.forEach(compilations.entrySet(), entry -> (debugContext) -> {
        HostedMethod method = entry.getKey();
        int offset = textSectionInfo.getOffset(SubstrateUtil.uniqueShortName(method));
        int nextFunctionStartOffset = textSectionInfo.getNextOffset(offset);
        int functionSize = nextFunctionStartOffset - offset;
        CompilationResult compilation = entry.getValue();
        compilation.setTargetCode(null, functionSize);
        method.setCodeAddressOffset(offset);
    });
    compilations.forEach((method, compilation) -> compilationsByStart.put(method.getCodeAddressOffset(), compilation));
    stackMapDumper.dumpOffsets(textSectionInfo);
    stackMapDumper.close();
    HostedMethod firstMethod = (HostedMethod) getFirstCompilation().getMethods()[0];
    buildRuntimeMetadata(new MethodPointer(firstMethod), WordFactory.signed(textSectionInfo.getCodeSize()));
}
Also used : MethodPointer(com.oracle.svm.core.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) LLVMTextSectionInfo(com.oracle.svm.core.graal.llvm.util.LLVMObjectFileReader.LLVMTextSectionInfo) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 10 with MethodPointer

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

the class MethodPointerInvalidHandlerFeature method markFunctionRelocationSite.

private void markFunctionRelocationSite(final ProgbitsSectionImpl sectionImpl, final int offset, final RelocatableBuffer.Info info) {
    assert info.getTargetObject() instanceof CFunctionPointer : "Wrong type for FunctionPointer relocation: " + info.getTargetObject().toString();
    final int functionPointerRelocationSize = 8;
    assert info.getRelocationSize() == functionPointerRelocationSize : "Function relocation: " + info.getRelocationSize() + " should be " + functionPointerRelocationSize + " bytes.";
    // References to functions are via relocations to the symbol for the function.
    MethodPointer methodPointer = (MethodPointer) info.getTargetObject();
    ResolvedJavaMethod method = methodPointer.getMethod();
    HostedMethod target = (method instanceof HostedMethod) ? (HostedMethod) method : heap.getUniverse().lookup(method);
    if (!target.isCompiled()) {
        target = metaAccess.lookupJavaMethod(InvalidMethodPointerHandler.METHOD_POINTER_NOT_COMPILED_HANDLER_METHOD);
    }
    // A reference to a method. Mark the relocation site using the symbol name.
    sectionImpl.markRelocationSite(offset, RelocationKind.getDirect(functionPointerRelocationSize), localSymbolNameForMethod(target), 0L);
}
Also used : MethodPointer(com.oracle.svm.core.meta.MethodPointer) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

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