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