use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class ObjectTreePrinter method suppressType.
private boolean suppressType(AnalysisType type) {
AnalysisType elementalType = (AnalysisType) type.getElementalType();
String elementalTypeName = elementalType.toJavaName(true);
if (expandTypeMatcher.matches(elementalTypeName)) {
return false;
}
if (suppressTypeMatcher.matches(elementalTypeName)) {
return true;
}
if (defaultSuppressTypeMatcher.matches(elementalTypeName)) {
return true;
}
return false;
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class PointsToStats method formatSource.
private static String formatSource(TypeFlow<?> flow) {
Object source = flow.getSource();
if (source instanceof ValueNode) {
ValueNode node = (ValueNode) source;
NodeSourcePosition nodeSource = node.getNodeSourcePosition();
if (nodeSource != null) {
return formatMethod(nodeSource.getMethod()) + ":" + nodeSource.getBCI();
} else if (flow.graphRef() != null) {
return formatMethod(flow.graphRef().getMethod());
} else {
return "<unknown-source>";
}
} else if (source instanceof AnalysisType) {
return formatType((AnalysisType) source);
} else if (source instanceof AnalysisField) {
return formatField((AnalysisField) source);
} else if (source == null) {
return "<no-source>";
} else {
return source.getClass().getSimpleName();
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class Inflation method fillGenericInfo.
private void fillGenericInfo(AnalysisType type) {
SVMHost svmHost = (SVMHost) hostVM;
DynamicHub hub = svmHost.dynamicHub(type);
Class<?> javaClass = type.getJavaClass();
TypeVariable<?>[] typeParameters = javaClass.getTypeParameters();
/* The bounds are lazily initialized. Initialize them eagerly in the native image. */
Arrays.stream(typeParameters).forEach(TypeVariable::getBounds);
Type[] genericInterfaces = Arrays.stream(javaClass.getGenericInterfaces()).filter(this::filterGenericInterfaces).toArray(Type[]::new);
Type[] cachedGenericInterfaces = genericInterfacesMap.computeIfAbsent(new GenericInterfacesEncodingKey(genericInterfaces), k -> genericInterfaces);
Type genericSuperClass = javaClass.getGenericSuperclass();
hub.setGenericInfo(GenericInfo.factory(typeParameters, cachedGenericInterfaces, genericSuperClass));
AnnotatedType annotatedSuperclass = javaClass.getAnnotatedSuperclass();
AnnotatedType[] annotatedInterfaces = Arrays.stream(javaClass.getAnnotatedInterfaces()).filter(ai -> filterGenericInterfaces(ai.getType())).toArray(AnnotatedType[]::new);
AnnotatedType[] cachedAnnotatedInterfaces = annotatedInterfacesMap.computeIfAbsent(new AnnotatedInterfacesEncodingKey(annotatedInterfaces), k -> annotatedInterfaces);
hub.setAnnotatedSuperInfo(AnnotatedSuperInfo.factory(annotatedSuperclass, cachedAnnotatedInterfaces));
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class Inflation method checkType.
private void checkType(AnalysisType type) {
SVMHost svmHost = (SVMHost) hostVM;
if (type.getJavaKind() == JavaKind.Object) {
if (type.isArray() && (type.isInstantiated() || type.isInTypeCheck())) {
svmHost.dynamicHub(type).getComponentHub().setArrayHub(svmHost.dynamicHub(type));
}
try {
AnalysisType enclosingType = type.getEnclosingType();
if (enclosingType != null) {
svmHost.dynamicHub(type).setEnclosingClass(svmHost.dynamicHub(enclosingType));
}
} catch (UnsupportedFeatureException ex) {
getUnsupportedFeatures().addMessage(type.toJavaName(true), null, ex.getMessage(), null, ex);
}
fillGenericInfo(type);
fillInterfaces(type);
/*
* Support for Java annotations.
*/
svmHost.dynamicHub(type).setAnnotationsEncoding(encodeAnnotations(metaAccess, type.getAnnotations(), svmHost.dynamicHub(type).getAnnotationsEncoding()));
/*
* Support for Java enumerations.
*/
if (type.getSuperclass() != null && type.getSuperclass().equals(metaAccess.lookupJavaType(Enum.class)) && svmHost.dynamicHub(type).getEnumConstantsShared() == null) {
/*
* We want to retrieve the enum constant array that is maintained as a private
* static field in the enumeration class. We do not want a copy because that would
* mean we have the array twice in the native image: as the static field, and in the
* enumConstant field of DynamicHub. The only way to get the original value is via a
* reflective field access, and we even have to guess the field name.
*/
AnalysisField found = null;
for (AnalysisField f : type.getStaticFields()) {
if (f.getName().endsWith("$VALUES")) {
if (found != null) {
throw shouldNotReachHere("Enumeration has more than one static field with enumeration values: " + type);
}
found = f;
}
}
if (found == null) {
throw shouldNotReachHere("Enumeration does not have static field with enumeration values: " + type);
}
AnalysisField field = found;
// field.registerAsRead(null);
Enum<?>[] enumConstants = (Enum[]) SubstrateObjectConstant.asObject(getConstantReflectionProvider().readFieldValue(field, null));
assert enumConstants != null;
svmHost.dynamicHub(type).setEnumConstants(enumConstants);
}
}
}
use of com.oracle.graal.pointsto.meta.AnalysisType in project graal by oracle.
the class AnnotationTypeFeature method duringAnalysis.
@Override
public void duringAnalysis(DuringAnalysisAccess access) {
DuringAnalysisAccessImpl accessImpl = (DuringAnalysisAccessImpl) access;
AnalysisUniverse universe = accessImpl.getUniverse();
/*
* JDK implementation of repeatable annotations always instantiates an array of a requested
* annotation. We need to mark arrays of all reachable annotations as in heap.
*/
universe.getTypes().stream().filter(AnalysisType::isAnnotation).filter(AnalysisType::isInTypeCheck).map(type -> universe.lookup(type.getWrapped()).getArrayClass()).filter(annotationArray -> !annotationArray.isInstantiated()).forEach(annotationArray -> {
accessImpl.registerAsInHeap(annotationArray);
access.requireAnalysisIteration();
});
Stream<AnnotatedElement> allElements = Stream.concat(Stream.concat(universe.getFields().stream(), universe.getMethods().stream()), universe.getTypes().stream());
Stream<AnnotatedElement> newElements = allElements.filter(visitedElements::add);
newElements.forEach(this::reportAnnotation);
}
Aggregations