use of com.oracle.svm.hosted.SVMHost 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.svm.hosted.SVMHost 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.svm.hosted.SVMHost in project graal by oracle.
the class Inflation method scanHub.
private void scanHub(ObjectScanner objectScanner, AnalysisType type) {
SVMHost svmHost = (SVMHost) hostVM;
JavaConstant hubConstant = SubstrateObjectConstant.forObject(svmHost.dynamicHub(type));
objectScanner.scanConstant(hubConstant, "Hub");
}
use of com.oracle.svm.hosted.SVMHost 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.svm.hosted.SVMHost in project graal by oracle.
the class GraalObjectReplacer method createType.
public SubstrateType createType(JavaType original) {
if (original == null) {
return null;
}
AnalysisType aType;
if (original instanceof AnalysisType) {
aType = (AnalysisType) original;
} else {
aType = ((HostedType) original).getWrapped();
}
SubstrateType sType = types.get(aType);
if (sType == null) {
assert !(original instanceof HostedType) : "too late to create new type";
DynamicHub hub = ((SVMHost) aUniverse.hostVM()).dynamicHub(aType);
sType = new SubstrateType(aType.getJavaKind(), hub);
types.put(aType, sType);
hub.setMetaType(sType);
sType.setInstanceFields(createFields(aType));
createType(aType.getSuperclass());
createType(aType.getComponentType());
for (AnalysisType aInterface : aType.getInterfaces()) {
createType(aInterface);
}
}
return sType;
}
Aggregations