use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.
the class JNIFunctionTablesFeature method beforeAnalysis.
@Override
public void beforeAnalysis(BeforeAnalysisAccess arg) {
BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) arg;
AnalysisMetaAccess metaAccess = access.getMetaAccess();
JNIFunctionTables.create();
NativeLibraries nativeLibraries = access.getNativeLibraries();
AnalysisType invokeInterface = metaAccess.lookupJavaType(JNIInvokeInterface.class);
invokeInterfaceMetadata = (StructInfo) nativeLibraries.findElementInfo(invokeInterface);
AnalysisType functionTable = metaAccess.lookupJavaType(JNINativeInterface.class);
functionTableMetadata = (StructInfo) nativeLibraries.findElementInfo(functionTable);
// Manually add functions as entry points so this is only done when JNI features are enabled
AnalysisType invokes = metaAccess.lookupJavaType(JNIInvocationInterface.class);
AnalysisType exports = metaAccess.lookupJavaType(JNIInvocationInterface.Exports.class);
AnalysisType functions = metaAccess.lookupJavaType(JNIFunctions.class);
Stream<AnalysisMethod> analysisMethods = Stream.of(invokes, functions, exports).flatMap(t -> Stream.of(t.getDeclaredMethods()));
Stream<AnalysisMethod> unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class), (AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class));
Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> {
CEntryPoint annotation = method.getAnnotation(CEntryPoint.class);
assert annotation != null : "only entry points allowed in class";
CEntryPointCallStubSupport.singleton().registerStubForMethod(method, () -> CEntryPointData.create(method));
});
ArrayList<ResolvedJavaMethod> generated = new ArrayList<>();
MetaAccessProvider wrappedMetaAccess = metaAccess.getWrapped();
ResolvedJavaType generatedMethodClass = wrappedMetaAccess.lookupJavaType(JNIFunctions.class);
ConstantPool constantPool = generatedMethodClass.getDeclaredMethods()[0].getConstantPool();
// Generate JNI field accessors
EnumSet<JavaKind> fldKinds = jniKinds.clone();
fldKinds.remove(JavaKind.Void);
for (JavaKind kind : fldKinds) {
boolean[] trueFalse = { true, false };
for (boolean isSetter : trueFalse) {
for (boolean isStatic : trueFalse) {
JNIFieldAccessorMethod method = new JNIFieldAccessorMethod(kind, isSetter, isStatic, generatedMethodClass, constantPool, wrappedMetaAccess);
AnalysisMethod analysisMethod = access.getUniverse().lookup(method);
access.getBigBang().addRootMethod(analysisMethod).registerAsEntryPoint(method.createEntryPointData());
generated.add(method);
}
}
}
// Generate JNI primitive array operations
EnumSet<JavaKind> primitiveArrayKinds = jniKinds.clone();
primitiveArrayKinds.remove(JavaKind.Void);
primitiveArrayKinds.remove(JavaKind.Object);
for (JavaKind kind : primitiveArrayKinds) {
for (Operation op : Operation.values()) {
JNIPrimitiveArrayOperationMethod method = new JNIPrimitiveArrayOperationMethod(kind, op, generatedMethodClass, constantPool, wrappedMetaAccess);
AnalysisMethod analysisMethod = access.getUniverse().lookup(method);
access.getBigBang().addRootMethod(analysisMethod).registerAsEntryPoint(method.createEntryPointData());
generated.add(method);
}
}
generatedMethods = generated.toArray(new ResolvedJavaMethod[0]);
}
use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.
the class JNIAccessFeature method addMethod.
private void addMethod(Executable method, DuringAnalysisAccessImpl access) {
JNIAccessibleClass jniClass = addClass(method.getDeclaringClass(), access);
JNIAccessibleMethodDescriptor descriptor = JNIAccessibleMethodDescriptor.of(method);
jniClass.addMethodIfAbsent(descriptor, d -> {
MetaAccessProvider wrappedMetaAccess = access.getMetaAccess().getWrapped();
JNIJavaCallWrapperMethod varargsCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VARARGS, false, wrappedMetaAccess, nativeLibraries);
JNIJavaCallWrapperMethod arrayCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.ARRAY, false, wrappedMetaAccess, nativeLibraries);
JNIJavaCallWrapperMethod valistCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VA_LIST, false, wrappedMetaAccess, nativeLibraries);
Stream<JNIJavaCallWrapperMethod> wrappers = Stream.of(varargsCallWrapper, arrayCallWrapper, valistCallWrapper);
JNIJavaCallWrapperMethod varargsNonvirtualCallWrapper = null;
JNIJavaCallWrapperMethod arrayNonvirtualCallWrapper = null;
JNIJavaCallWrapperMethod valistNonvirtualCallWrapper = null;
if (!Modifier.isStatic(method.getModifiers())) {
varargsNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VARARGS, true, wrappedMetaAccess, nativeLibraries);
arrayNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.ARRAY, true, wrappedMetaAccess, nativeLibraries);
valistNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VA_LIST, true, wrappedMetaAccess, nativeLibraries);
wrappers = Stream.concat(wrappers, Stream.of(varargsNonvirtualCallWrapper, arrayNonvirtualCallWrapper, valistNonvirtualCallWrapper));
}
JNIAccessibleMethod jniMethod = new JNIAccessibleMethod(method.getModifiers(), jniClass, varargsCallWrapper, arrayCallWrapper, valistCallWrapper, varargsNonvirtualCallWrapper, arrayNonvirtualCallWrapper, valistNonvirtualCallWrapper);
wrappers.forEach(wrapper -> {
AnalysisMethod analysisWrapper = access.getUniverse().lookup(wrapper);
access.getBigBang().addRootMethod(analysisWrapper);
// ensures C calling convention
analysisWrapper.registerAsEntryPoint(jniMethod);
});
return jniMethod;
});
}
use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.
the class AnalysisMethodCalleeWalker method walkMethodAndCallees.
/**
* Visit this method, and the methods it calls.
*/
VisitResult walkMethodAndCallees(AnalysisMethod method, AnalysisMethod caller, Invoke invoke, CallPathVisitor visitor) {
if (path.contains(method)) {
/*
* If the method is already on the path then I am in the middle of visiting it, so just
* keep walking.
*/
return VisitResult.CUT;
}
path.add(method);
try {
/* Visit the method directly. */
final VisitResult directResult = visitor.visitMethod(method, caller, invoke, path.size());
if (directResult != VisitResult.CONTINUE) {
return directResult;
}
/* Visit the callees of this method. */
final VisitResult calleeResult = walkCallees(method, visitor);
if (calleeResult != VisitResult.CONTINUE) {
return calleeResult;
}
/* Visit all the implementations of this method, ignoring if any of them says CUT. */
for (AnalysisMethod impl : method.getImplementations()) {
walkMethodAndCallees(impl, caller, invoke, visitor);
}
return VisitResult.CONTINUE;
} finally {
path.remove(method);
}
}
use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.
the class CEntryPointCallStubFeature method registerStubForMethod.
public AnalysisMethod registerStubForMethod(AnalysisMethod method, Supplier<CEntryPointData> entryPointDataSupplier) {
assert !bigbang.getUniverse().sealed();
return methodToStub.computeIfAbsent(method, m -> {
CEntryPointData entryPointData = entryPointDataSupplier.get();
CEntryPointCallStubMethod stub = CEntryPointCallStubMethod.create(method, entryPointData, bigbang.getMetaAccess());
AnalysisMethod wrapped = bigbang.getUniverse().lookup(stub);
bigbang.addRootMethod(wrapped).registerAsEntryPoint(entryPointData);
return wrapped;
});
}
use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.
the class NativeImageCodeCache method verifyDeoptEntries.
private void verifyDeoptEntries(ImageCodeInfo imageCodeInfo) {
boolean hasError = false;
List<Entry<AnalysisMethod, Set<Long>>> deoptEntries = new ArrayList<>(CompilationInfoSupport.singleton().getDeoptEntries().entrySet());
deoptEntries.sort((e1, e2) -> e1.getKey().format("%H.%n(%p)").compareTo(e2.getKey().format("%H.%n(%p)")));
for (Map.Entry<AnalysisMethod, Set<Long>> entry : deoptEntries) {
HostedMethod method = imageHeap.getUniverse().lookup(entry.getKey());
List<Long> encodedBcis = new ArrayList<>(entry.getValue());
encodedBcis.sort((v1, v2) -> Long.compare(v1, v2));
for (long encodedBci : encodedBcis) {
hasError |= verifyDeoptEntry(imageCodeInfo, method, encodedBci);
}
}
if (hasError) {
VMError.shouldNotReachHere("Verification of deoptimization entry points failed");
}
}
Aggregations