use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class UniverseBuilder method makeType.
private HostedType makeType(AnalysisType aType) {
if (aType == null) {
return null;
}
HostedType hType = hUniverse.types.get(aType);
if (hType != null) {
return hType;
}
String typeName = aType.getName();
assert !typeName.contains("/hotspot/") || typeName.contains("/jtt/hotspot/") : "HotSpot object in image " + typeName;
assert !typeName.contains("/analysis/meta/") : "Analysis meta object in image " + typeName;
assert !typeName.contains("/hosted/meta/") : "Hosted meta object in image " + typeName;
AnalysisType[] aInterfaces = aType.getInterfaces();
HostedInterface[] sInterfaces = new HostedInterface[aInterfaces.length];
for (int i = 0; i < aInterfaces.length; i++) {
sInterfaces[i] = (HostedInterface) makeType(aInterfaces[i]);
}
JavaKind kind = aType.getJavaKind();
JavaKind storageKind = aType.getStorageKind();
if (aType.getJavaKind() != JavaKind.Object) {
assert !aType.isInterface() && !aType.isInstanceClass() && !aType.isArray();
hType = new HostedPrimitiveType(hUniverse, aType, kind, storageKind);
hUniverse.kindToType.put(hType.getJavaKind(), hType);
} else if (aType.isInterface()) {
assert !aType.isInstanceClass() && !aType.isArray();
hType = new HostedInterface(hUniverse, aType, kind, storageKind, sInterfaces);
} else if (aType.isInstanceClass()) {
assert !aType.isInterface() && !aType.isArray();
HostedInstanceClass superClass = (HostedInstanceClass) makeType(aType.getSuperclass());
boolean isCloneable = aMetaAccess.lookupJavaType(Cloneable.class).isAssignableFrom(aType);
hType = new HostedInstanceClass(hUniverse, aType, kind, storageKind, superClass, sInterfaces, isCloneable);
if (superClass == null) {
hUniverse.kindToType.put(JavaKind.Object, hType);
}
} else if (aType.isArray()) {
assert !aType.isInterface() && !aType.isInstanceClass();
HostedClass superType = (HostedClass) makeType(aType.getSuperclass());
HostedType componentType = makeType(aType.getComponentType());
hType = new HostedArrayClass(hUniverse, aType, kind, storageKind, superType, sInterfaces, componentType);
int dimension = hType.getArrayDimension();
if (hType.getBaseType().getSuperclass() != null) {
makeType(hType.getBaseType().getSuperclass().getArrayClass(dimension - 1).getWrapped().getArrayClass());
}
if (hType.getBaseType().isInterface()) {
makeType(hUniverse.getObjectClass().getArrayClass(dimension - 1).getWrapped().getArrayClass());
}
for (HostedInterface interf : hType.getBaseType().getInterfaces()) {
makeType(interf.getArrayClass(dimension - 1).getWrapped().getArrayClass());
}
} else {
throw shouldNotReachHere();
}
hUniverse.types.put(aType, hType);
/*
* Set enclosing type lazily to avoid cyclic dependency between interfaces and enclosing
* types. For example, in Scala an interface can extends its inner type.
*/
if (aType.getEnclosingType() != null) {
hType.setEnclosingType(makeType(aType.getEnclosingType()));
}
return hType;
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class UniverseBuilder method collectHashCodeFieldInfo.
@SuppressWarnings("try")
private void collectHashCodeFieldInfo(BigBang bb) {
AnalysisMethod method;
try {
method = aMetaAccess.lookupJavaMethod(System.class.getMethod("identityHashCode", Object.class));
} catch (NoSuchMethodException | SecurityException e) {
throw shouldNotReachHere();
}
if (method == null) {
return;
}
DebugContext debug = bb.getDebug();
try (Indent ignore = debug.logAndIndent("check types for which identityHashCode is invoked")) {
// Check which types may be a parameter of System.identityHashCode (which is invoked by
// Object.hashCode).
TypeState thisParamState = method.getTypeFlow().getParameterTypeState(bb, 0);
assert thisParamState != null;
Iterable<AnalysisType> typesNeedHashCode = thisParamState.types();
if (typesNeedHashCode == null || thisParamState.isUnknown()) {
// This is the case if the identityHashCode parameter type is unknown. So all
// classes get the hashCode field.
// But this is only a fail-safe, because it cannot happen in the current
// implementation of the analysis pass.
debug.log("all types need a hashCode field");
for (HostedType hType : hUniverse.getTypes()) {
if (hType.isInstanceClass()) {
((HostedInstanceClass) hType).setNeedHashCodeField();
}
}
hUniverse.getObjectClass().setNeedHashCodeField();
} else {
for (AnalysisType type : typesNeedHashCode) {
debug.log("type %s is argument to identityHashCode", type);
/*
* Array types get a hash-code field by default. So we only have to deal with
* instance types here.
*/
if (type.isInstanceClass()) {
HostedInstanceClass hType = (HostedInstanceClass) hUniverse.lookup(type);
hType.setNeedHashCodeField();
}
}
}
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType 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.AnalysisType in project graal by oracle.
the class ScalaAnalysisPlugin method handleInvoke.
@Override
public boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
/* ClassTag(<type>.class) */
if (method.getDeclaringClass().getName().equals("Lscala/reflect/ClassTag$;") && method.getName().equals("apply") && args.length == 2) {
JavaConstant clazzConstant = args[1].asJavaConstant();
if (clazzConstant != null) {
AnalysisType type = (AnalysisType) b.getConstantReflection().asJavaType(clazzConstant);
for (int i = 0; i < SUPPORTED_LEVEL_OF_NESTED_ARRAYS; i++) {
type = type.getArrayClass();
type.registerAsInHeap();
}
}
}
return false;
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class UniverseBuilder method build.
/**
* This step is single threaded, i.e., all the maps are modified only by a single thread, so no
* synchronization is necessary. Accesses (the lookup methods) are multi-threaded.
*/
@SuppressWarnings("try")
public void build(DebugContext debug) {
for (AnalysisField aField : aUniverse.getFields()) {
if (aField.wrapped instanceof ComputedValueField) {
((ComputedValueField) aField.wrapped).processAnalysis(aMetaAccess);
}
}
aUniverse.seal();
try (Indent indent = debug.logAndIndent("build universe")) {
for (AnalysisType aType : aUniverse.getTypes()) {
makeType(aType);
}
for (AnalysisField aField : aUniverse.getFields()) {
makeField(aField);
}
for (AnalysisMethod aMethod : aUniverse.getMethods()) {
makeMethod(aMethod);
}
BigBang bb = staticAnalysisResultsBuilder.getBigBang();
ForkJoinTask<?> profilingInformationBuildTask = ForkJoinTask.adapt(this::buildProfilingInformation).fork();
buildSubTypes();
buildOrderedTypes();
buildTypeCheckIDs();
collectDeclaredMethods();
collectMonitorFieldInfo(bb);
collectHashCodeFieldInfo(bb);
layoutInstanceFields();
layoutStaticFields();
collectMethodImplementations();
buildVTables();
buildHubs();
setConstantFieldValues();
hUniverse.orderedMethods = new ArrayList<>(hUniverse.methods.values());
Collections.sort(hUniverse.orderedMethods);
hUniverse.orderedFields = new ArrayList<>(hUniverse.fields.values());
Collections.sort(hUniverse.orderedFields);
profilingInformationBuildTask.join();
}
}
Aggregations