Search in sources :

Example 1 with DynamicHub

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;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 2 with DynamicHub

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);
}
Also used : DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 3 with DynamicHub

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);
}
Also used : DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 4 with 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));
}
Also used : HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) DynamicHub(com.oracle.svm.core.hub.DynamicHub) HashMap(java.util.HashMap) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SVMHost(com.oracle.svm.hosted.SVMHost) MethodTypeFlow(com.oracle.graal.pointsto.flow.MethodTypeFlow) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectScanner(com.oracle.graal.pointsto.ObjectScanner) Map(java.util.Map) BigBang(com.oracle.graal.pointsto.BigBang) MethodTypeFlowBuilder(com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder) TypeNotFoundError(com.oracle.graal.pointsto.util.AnalysisError.TypeNotFoundError) GenericInfo(com.oracle.svm.core.hub.GenericInfo) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) UnknownPrimitiveField(com.oracle.svm.core.annotate.UnknownPrimitiveField) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) OptionValues(org.graalvm.compiler.options.OptionValues) JVMCIError(jdk.vm.ci.common.JVMCIError) SVMMethodTypeFlowBuilder(com.oracle.svm.hosted.analysis.flow.SVMMethodTypeFlowBuilder) TypeVariable(java.lang.reflect.TypeVariable) AnnotatedType(java.lang.reflect.AnnotatedType) Set(java.util.Set) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) JavaConstant(jdk.vm.ci.meta.JavaConstant) List(java.util.List) Type(java.lang.reflect.Type) ForkJoinPool(java.util.concurrent.ForkJoinPool) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) TypeFlow(com.oracle.graal.pointsto.flow.TypeFlow) UnknownObjectField(com.oracle.svm.core.annotate.UnknownObjectField) AnnotatedSuperInfo(com.oracle.svm.core.hub.AnnotatedSuperInfo) JVMCIError.shouldNotReachHere(jdk.vm.ci.common.JVMCIError.shouldNotReachHere) Pattern(java.util.regex.Pattern) HostVM(com.oracle.graal.pointsto.api.HostVM) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) WordBase(org.graalvm.word.WordBase) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnnotatedType(java.lang.reflect.AnnotatedType) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) Type(java.lang.reflect.Type) AnnotatedType(java.lang.reflect.AnnotatedType) TypeVariable(java.lang.reflect.TypeVariable) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 5 with DynamicHub

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);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Aggregations

DynamicHub (com.oracle.svm.core.hub.DynamicHub)28 UnsignedWord (org.graalvm.word.UnsignedWord)11 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)5 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 SVMHost (com.oracle.svm.hosted.SVMHost)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Snippet (org.graalvm.compiler.api.replacements.Snippet)3 Pointer (org.graalvm.word.Pointer)3 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)2 SubstrateType (com.oracle.svm.graal.meta.SubstrateType)2 HostedField (com.oracle.svm.hosted.meta.HostedField)2 HostedType (com.oracle.svm.hosted.meta.HostedType)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 BigBang (com.oracle.graal.pointsto.BigBang)1 ObjectScanner (com.oracle.graal.pointsto.ObjectScanner)1