use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class Inflation method handleUnknownObjectField.
/**
* Register a field as containing unknown object(s), i.e., is usually written only in hosted
* code. It can have multiple declared types provided via annotation.
*/
private void handleUnknownObjectField(AnalysisField aField, AnalysisType... declaredTypes) {
assert aField.getJavaKind() == JavaKind.Object;
aField.registerAsWritten(null);
/* Link the field with all declared types. */
for (AnalysisType fieldDeclaredType : declaredTypes) {
TypeFlow<?> fieldDeclaredTypeFlow = fieldDeclaredType.getTypeFlow(this, true);
if (aField.isStatic()) {
fieldDeclaredTypeFlow.addUse(this, aField.getStaticFieldFlow());
} else {
fieldDeclaredTypeFlow.addUse(this, aField.getInitialInstanceFieldFlow());
if (fieldDeclaredType.isArray()) {
AnalysisType fieldComponentType = fieldDeclaredType.getComponentType();
aField.getInitialInstanceFieldFlow().addUse(this, aField.getInstanceFieldFlow());
// object field is not empty?
if (!fieldComponentType.isPrimitive()) {
/*
* Write the component type abstract object into the field array elements
* type flow, i.e., the array elements type flow of the abstract object of
* the field declared type.
*
* This is required so that the index loads from this array return all the
* possible objects that can be stored in the array.
*/
TypeFlow<?> elementsFlow = fieldDeclaredType.getContextInsensitiveAnalysisObject().getArrayElementsFlow(this, true);
fieldComponentType.getTypeFlow(this, false).addUse(this, elementsFlow);
/*
* In the current implementation it is not necessary to do it it recursively
* for multidimensional arrays since we don't model individual array
* elements, so from the point of view of the static analysis the field's
* array elements value is non null (in the case of a n-dimensional array
* that value is another array, n-1 dimensional).
*/
}
}
}
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class Inflation method fillInterfaces.
/**
* Fill array returned by Class.getInterfaces().
*/
private void fillInterfaces(AnalysisType type) {
SVMHost svmHost = (SVMHost) hostVM;
DynamicHub hub = svmHost.dynamicHub(type);
AnalysisType[] aInterfaces = type.getInterfaces();
if (aInterfaces.length == 0) {
hub.setInterfacesEncoding(null);
} else if (aInterfaces.length == 1) {
hub.setInterfacesEncoding(svmHost.dynamicHub(aInterfaces[0]));
} else {
/*
* Many interfaces arrays are the same, e.g., all arrays implement the same two
* interfaces. We want to avoid duplicate arrays with the same content in the native
* image heap.
*/
hub.setInterfacesEncoding(interfacesEncodings.computeIfAbsent(new InterfacesEncodingKey(aInterfaces), k -> k.createHubs()));
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class Inflation method extractAnnotationTypes.
private List<AnalysisType> extractAnnotationTypes(AnalysisField field, UnknownObjectField unknownObjectField) {
List<Class<?>> annotationTypes = new ArrayList<>(Arrays.asList(unknownObjectField.types()));
for (String annotationTypeName : unknownObjectField.fullyQualifiedTypes()) {
try {
Class<?> annotationType = Class.forName(annotationTypeName);
annotationTypes.add(annotationType);
} catch (ClassNotFoundException e) {
throw shouldNotReachHere("Annotation type not found " + annotationTypeName);
}
}
List<AnalysisType> aAnnotationTypes = new ArrayList<>();
AnalysisType declaredType = field.getType();
for (Class<?> annotationType : annotationTypes) {
AnalysisType aAnnotationType = metaAccess.lookupJavaType(annotationType);
assert !WordBase.class.isAssignableFrom(annotationType) : "Annotation type must not be a subtype of WordBase: field: " + field + " | declared type: " + declaredType + " | annotation type: " + annotationType;
assert declaredType.isAssignableFrom(aAnnotationType) : "Annotation type must be a subtype of the declared type: field: " + field + " | declared type: " + declaredType + " | annotation type: " + annotationType;
assert aAnnotationType.isArray() || (aAnnotationType.isInstanceClass() && !Modifier.isAbstract(aAnnotationType.getModifiers())) : "Annotation type failure: field: " + field + " | annotation type " + aAnnotationType;
aAnnotationTypes.add(aAnnotationType);
}
return aAnnotationTypes;
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class GraalSupport method registerStatistics.
private static <S> void registerStatistics(Map<Class<?>, S> cache, Class<?> phaseClass, Class<S> statisticsClass, Function<Class<?>, S> lookup, DuringAnalysisAccessImpl access) {
AnalysisType statisticsType = access.getMetaAccess().lookupJavaType(statisticsClass);
if (!statisticsType.isInstantiated()) {
/*
* There is no allocation of statistics objects at runtime, thus their type must be
* correctly registered as in heap.
*/
statisticsType.registerAsInHeap();
access.requireAnalysisIteration();
}
for (Class<?> phaseSubClass : access.findSubclasses(phaseClass)) {
if (Modifier.isAbstract(phaseSubClass.getModifiers()) || phaseSubClass.getName().contains(".hosted.") || phaseSubClass.getName().contains(".hotspot.")) {
/* Class is abstract or SVM hosted. */
continue;
}
AnalysisType phaseSubClassType = access.getMetaAccess().lookupJavaType(phaseSubClass);
if (!phaseSubClassType.isInstantiated()) {
/* The sub class is not instantiated, it doesn't need a statistics object. */
continue;
}
if (cache.containsKey(phaseSubClass)) {
/* The statistics object for the sub class was already registered. */
continue;
}
cache.put(phaseSubClass, lookup.apply(phaseSubClass));
access.requireAnalysisIteration();
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class GraalObjectReplacer method updateSubstrateDataAfterCompilation.
/**
* Updates all relevant data from universe building. Object replacement is done during analysis.
* Therefore all substrate VM related data has to be updated after building the substrate
* universe.
*/
@SuppressWarnings("try")
public void updateSubstrateDataAfterCompilation(HostedUniverse hUniverse) {
for (Map.Entry<AnalysisType, SubstrateType> entry : types.entrySet()) {
AnalysisType aType = entry.getKey();
SubstrateType sType = entry.getValue();
if (!hUniverse.contains(aType)) {
continue;
}
HostedType hType = hUniverse.lookup(aType);
DynamicHub uniqueImplementation = null;
if (hType.getUniqueConcreteImplementation() != null) {
uniqueImplementation = hType.getUniqueConcreteImplementation().getHub();
}
sType.setTypeCheckData(hType.getInstanceOfFromTypeID(), hType.getInstanceOfNumTypeIDs(), uniqueImplementation);
SubstrateField[] originalFields = sType.getInstanceFields(false);
if (originalFields != null) {
/*
* What we do here is just a reordering of the instance fields array. The fields
* array already contains all the fields, but in the order of the AnalysisType. As
* the UniverseBuilder reorders the fields, we re-construct the fields array in the
* order of the HostedType. The correct order is essential for materialization
* during deoptimization.
*/
SubstrateField[] newFields = createFields(hType);
sType.setInstanceFields(newFields);
}
}
for (Map.Entry<AnalysisField, SubstrateField> entry : fields.entrySet()) {
AnalysisField aField = entry.getKey();
SubstrateField sField = entry.getValue();
HostedField hField = hUniverse.lookup(aField);
sField.setSubstrateData(hField.getLocation(), hField.isAccessed(), hField.isWritten(), hField.getConstantValue());
}
}
Aggregations