Search in sources :

Example 6 with WordBase

use of org.graalvm.word.WordBase 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;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ArrayList(java.util.ArrayList) WordBase(org.graalvm.word.WordBase)

Example 7 with WordBase

use of org.graalvm.word.WordBase in project graal by oracle.

the class AllocationSnippets method doCloneSnippet.

/**
 * The actual implementation of {@link Object#clone}.
 */
@Snippet
private static Object doCloneSnippet(Object thisObj, AllocationCounter counter) throws CloneNotSupportedException {
    if (!(thisObj instanceof Cloneable)) {
        throw CLONE_NOT_SUPPORTED_EXCEPTION;
    }
    DynamicHub hub = KnownIntrinsics.readHub(thisObj);
    int layoutEncoding = hub.getLayoutEncoding();
    UnsignedWord size = LayoutEncoding.getSizeFromObject(thisObj);
    profileAllocation(size, counter);
    /*
         * The size of the clone is the same as the size of the original object. On the fast path we
         * try to allocate aligned memory, i.e., a block inside an aligned chunks, for the clone and
         * don't need to distinguish instance objects from arrays. If we fail, i.e., the returned
         * memory is null, then either the instance object or small array didn't fit in the
         * available space or it is a large array. In either case we go on the slow path.
         */
    Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.regularTLAB.getAddress(), size);
    Object thatObject = null;
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
        WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, false, false);
        memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
        /*
             * For arrays the length initialization is handled by doCloneUninterruptibly since the
             * array length offset is the same as the first field offset.
             */
        thatObject = memory.toObjectNonNull();
    } else {
        if (LayoutEncoding.isArray(layoutEncoding)) {
            int length = KnownIntrinsics.readArrayLength(thisObj);
            thatObject = callSlowNewArray(SLOW_NEW_ARRAY, hub.asClass(), length);
        } else {
            thatObject = callSlowNewInstance(SLOW_NEW_INSTANCE, hub.asClass());
        }
    }
    if (LayoutEncoding.isArray(layoutEncoding)) {
        int length = KnownIntrinsics.readArrayLength(thisObj);
        thatObject = PiArrayNode.piArrayCastToSnippetReplaceeStamp(thatObject, length);
    } else {
        thatObject = PiNode.piCastToSnippetReplaceeStamp(thatObject);
    }
    UnsignedWord firstFieldOffset = WordFactory.signed(ConfigurationValues.getObjectLayout().getFirstFieldOffset());
    return doCloneUninterruptibly(thisObj, thatObject, firstFieldOffset, size);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) WordBase(org.graalvm.word.WordBase) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 8 with WordBase

use of org.graalvm.word.WordBase in project graal by oracle.

the class AllocationSnippets method formatArrayImpl.

@Uninterruptible(reason = "Manipulates Objects via Pointers", callerMustBe = true)
private static Object formatArrayImpl(Pointer memory, DynamicHub hub, int length, int layoutEncoding, UnsignedWord size, boolean fillContents, boolean rememberedSet, boolean unaligned) {
    WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, rememberedSet, unaligned);
    memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
    memory.writeInt(ConfigurationValues.getObjectLayout().getArrayLengthOffset(), length, LocationIdentity.INIT_LOCATION);
    if (fillContents) {
        UnsignedWord offset = LayoutEncoding.getArrayBaseOffset(layoutEncoding);
        if ((!isWordAligned(offset)) && offset.belowThan(size)) {
            /*
                 * The first array element offset can be 4-byte aligned. Write an int in this case
                 * to zero any bytes before the Word writes below.
                 */
            memory.writeInt(offset, 0, LocationIdentity.INIT_LOCATION);
            offset = offset.add(4);
        }
        /* Assert that offset is now Word aligned, or past the end of the elements. */
        assert isWordAligned(offset) : "offset should be Word aligned";
        while (offset.belowThan(size)) {
            memory.writeWord(offset, WordFactory.zero(), LocationIdentity.INIT_LOCATION);
            offset = offset.add(ConfigurationValues.getTarget().wordSize);
        }
    }
    return memory.toObjectNonNull();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) WordBase(org.graalvm.word.WordBase) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 9 with WordBase

use of org.graalvm.word.WordBase in project graal by oracle.

the class NativeClosure method invokeClosureBufferRet.

@CEntryPoint
@CEntryPointOptions(prologue = EnterClosureDataIsolatePrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void invokeClosureBufferRet(@SuppressWarnings("unused") ffi_cif cif, Pointer ret, WordPointer args, ClosureData user) {
    CIntPointer errnoMirror = ErrnoMirror.getErrnoMirrorLocation();
    errnoMirror.write(Errno.errno());
    try {
        NativeClosure closure = lookup(user);
        ByteBuffer retBuffer = closure.createRetBuffer(ret);
        Target_com_oracle_truffle_nfi_impl_LibFFIClosure_RetPatches patches = (Target_com_oracle_truffle_nfi_impl_LibFFIClosure_RetPatches) closure.call(args, retBuffer);
        if (patches != null) {
            for (int i = 0; i < patches.count; i++) {
                Target_com_oracle_truffle_nfi_impl_NativeArgumentBuffer_TypeTag tag = getTag(patches.patches[i]);
                int offset = getOffset(patches.patches[i]);
                Object obj = patches.objects[i];
                if (tag == Target_com_oracle_truffle_nfi_impl_NativeArgumentBuffer_TypeTag.OBJECT) {
                    WordBase handle = ImageSingletons.lookup(TruffleNFISupport.class).createGlobalHandle(obj);
                    ret.writeWord(offset, handle);
                } else if (tag == Target_com_oracle_truffle_nfi_impl_NativeArgumentBuffer_TypeTag.STRING) {
                    ret.writeWord(offset, serializeStringRet(obj));
                } else {
                // nothing to do
                }
            }
        }
    } finally {
        Errno.set_errno(errnoMirror.read());
    }
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordBase(org.graalvm.word.WordBase) PinnedObject(org.graalvm.nativeimage.PinnedObject) ByteBuffer(java.nio.ByteBuffer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Aggregations

WordBase (org.graalvm.word.WordBase)9 UnsignedWord (org.graalvm.word.UnsignedWord)4 Snippet (org.graalvm.compiler.api.replacements.Snippet)2 Pointer (org.graalvm.word.Pointer)2 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 CompressEncoding (org.graalvm.compiler.core.common.CompressEncoding)1 Word (org.graalvm.compiler.word.Word)1 PinnedObject (org.graalvm.nativeimage.PinnedObject)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1 RelocatedPointer (org.graalvm.nativeimage.c.function.RelocatedPointer)1 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)1