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);
}
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);
}
}
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);
}
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()));
}
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);
}
Aggregations