use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class JavaLangSubstitutions method identityHashCode.
@Substitute
private static int identityHashCode(Object obj) {
if (obj == null) {
return 0;
}
DynamicHub hub = KnownIntrinsics.readHub(obj);
int hashCodeOffset = hub.getHashCodeOffset();
if (hashCodeOffset == 0) {
throw VMError.shouldNotReachHere("identityHashCode called on illegal object");
}
UnsignedWord hashCodeOffsetWord = WordFactory.unsigned(hashCodeOffset);
int hashCode = ObjectAccess.readInt(obj, hashCodeOffsetWord);
if (hashCode != 0) {
return hashCode;
}
/* On the first invocation for an object create a new hash code. */
hashCode = IdentityHashCodeSupport.generateHashCode();
if (!UnsafeAccess.UNSAFE.compareAndSwapInt(obj, hashCodeOffset, 0, hashCode)) {
/* We lost the race, so there now must be a hash code installed from another thread. */
hashCode = ObjectAccess.readInt(obj, hashCodeOffsetWord);
}
VMError.guarantee(hashCode != 0, "Missing identity hash code");
return hashCode;
}
use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class SVMHost method createHub.
private DynamicHub createHub(AnalysisType type) {
DynamicHub superHub = null;
if ((type.isInstanceClass() && type.getSuperclass() != null) || type.isArray()) {
superHub = dynamicHub(type.getSuperclass());
}
DynamicHub componentHub = null;
if (type.isArray()) {
componentHub = dynamicHub(type.getComponentType());
}
boolean isStatic = Modifier.isStatic(type.getJavaClass().getModifiers());
boolean isSynthetic = type.getJavaClass().isSynthetic();
return new DynamicHub(type.toClassName(), type.isLocal(), superHub, componentHub, type.getSourceFileName(), isStatic, isSynthetic);
}
use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class AnalysisConstantReflectionProvider method asJavaClass.
@Override
public JavaConstant asJavaClass(ResolvedJavaType type) {
DynamicHub dynamicHub = hostVM.dynamicHub(type);
registerHub(hostVM, dynamicHub);
return SubstrateObjectConstant.forObject(dynamicHub);
}
use of com.oracle.svm.core.hub.DynamicHub 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.core.hub.DynamicHub in project graal by oracle.
the class AllocationSnippets method formatArraySnippet.
@Snippet
public static Object formatArraySnippet(Word memory, DynamicHub hub, int length, boolean rememberedSet, boolean unaligned) {
DynamicHub hubNonNull = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
int layoutEncoding = hubNonNull.getLayoutEncoding();
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
emitPrefetchAllocate(memory, true);
return formatArrayImpl(memory, hubNonNull, length, layoutEncoding, size, true, rememberedSet, unaligned);
}
Aggregations