Search in sources :

Example 11 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class WriteBarrierSnippets method g1ArrayRangePostWriteBarrier.

@Snippet
public static void g1ArrayRangePostWriteBarrier(Address address, int length, @ConstantParameter int elementStride, @ConstantParameter Register threadRegister) {
    if (length == 0) {
        return;
    }
    Word thread = registerAsWord(threadRegister);
    Word bufferAddress = thread.readWord(g1CardQueueBufferOffset(INJECTED_VMCONFIG));
    Word indexAddress = thread.add(g1CardQueueIndexOffset(INJECTED_VMCONFIG));
    long indexValue = thread.readWord(g1CardQueueIndexOffset(INJECTED_VMCONFIG)).rawValue();
    int cardShift = cardTableShift(INJECTED_VMCONFIG);
    final long cardStart = GraalHotSpotVMConfigNode.cardTableAddress();
    long start = getPointerToFirstArrayElement(address, length, elementStride) >>> cardShift;
    long end = getPointerToLastArrayElement(address, length, elementStride) >>> cardShift;
    long count = end - start + 1;
    while (count-- > 0) {
        Word cardAddress = WordFactory.unsigned((start + cardStart) + count);
        byte cardByte = cardAddress.readByte(0, GC_CARD_LOCATION);
        // If the card is already dirty, (hence already enqueued) skip the insertion.
        if (probability(NOT_FREQUENT_PROBABILITY, cardByte != g1YoungCardValue(INJECTED_VMCONFIG))) {
            MembarNode.memoryBarrier(STORE_LOAD, GC_CARD_LOCATION);
            byte cardByteReload = cardAddress.readByte(0, GC_CARD_LOCATION);
            if (probability(NOT_FREQUENT_PROBABILITY, cardByteReload != dirtyCardValue(INJECTED_VMCONFIG))) {
                cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION);
                // initialize a new one and add the card entry.
                if (indexValue != 0) {
                    indexValue = indexValue - wordSize();
                    Word logAddress = bufferAddress.add(WordFactory.unsigned(indexValue));
                    // Log the object to be scanned as well as update
                    // the card queue's next index.
                    logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION);
                    indexAddress.writeWord(0, WordFactory.unsigned(indexValue), GC_INDEX_LOCATION);
                } else {
                    g1PostBarrierStub(G1WBPOSTCALL, cardAddress);
                }
            }
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 12 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class ArrayCopySnippets method checkcastArraycopyWithSlowPathWork.

@Snippet(allowPartialIntrinsicArgumentMismatch = true)
public static void checkcastArraycopyWithSlowPathWork(Object src, int srcPos, Object dest, int destPos, int length, @ConstantParameter Counters counters) {
    if (probability(FREQUENT_PROBABILITY, length > 0)) {
        Object nonNullSrc = PiNode.asNonNullObject(src);
        Object nonNullDest = PiNode.asNonNullObject(dest);
        KlassPointer srcKlass = loadHub(nonNullSrc);
        KlassPointer destKlass = loadHub(nonNullDest);
        if (probability(LIKELY_PROBABILITY, srcKlass == destKlass)) {
            // no storecheck required.
            counters.objectCheckcastSameTypeCounter.inc();
            counters.objectCheckcastSameTypeCopiedCounter.add(length);
            ArrayCopyCallNode.arraycopyObjectKillsAny(nonNullSrc, srcPos, nonNullDest, destPos, length);
        } else {
            KlassPointer destElemKlass = destKlass.readKlassPointer(arrayClassElementOffset(INJECTED_VMCONFIG), OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION);
            Word superCheckOffset = WordFactory.signed(destElemKlass.readInt(superCheckOffsetOffset(INJECTED_VMCONFIG), KLASS_SUPER_CHECK_OFFSET_LOCATION));
            counters.objectCheckcastDifferentTypeCounter.inc();
            counters.objectCheckcastDifferentTypeCopiedCounter.add(length);
            int copiedElements = CheckcastArrayCopyCallNode.checkcastArraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, superCheckOffset, destElemKlass, false);
            if (probability(SLOW_PATH_PROBABILITY, copiedElements != 0)) {
                /*
                     * the stub doesn't throw the ArrayStoreException, but returns the number of
                     * copied elements (xor'd with -1).
                     */
                copiedElements ^= -1;
                System.arraycopy(nonNullSrc, srcPos + copiedElements, nonNullDest, destPos + copiedElements, length - copiedElements);
            }
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 13 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class HashCodeSnippets method computeHashCode.

static int computeHashCode(final Object x) {
    Word mark = loadWordFromObject(x, markOffset(INJECTED_VMCONFIG));
    // this code is independent from biased locking (although it does not look that way)
    final Word biasedLock = mark.and(biasedLockMaskInPlace(INJECTED_VMCONFIG));
    if (probability(FAST_PATH_PROBABILITY, biasedLock.equal(WordFactory.unsigned(unlockedMask(INJECTED_VMCONFIG))))) {
        int hash = (int) mark.unsignedShiftRight(identityHashCodeShift(INJECTED_VMCONFIG)).rawValue();
        if (probability(FAST_PATH_PROBABILITY, hash != uninitializedIdentityHashCodeValue(INJECTED_VMCONFIG))) {
            return hash;
        }
    }
    return identityHashCode(IDENTITY_HASHCODE, x);
}
Also used : Word(org.graalvm.compiler.word.Word)

Example 14 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class LoadExceptionObjectSnippets method loadException.

@Snippet
public static Object loadException(@ConstantParameter Register threadRegister) {
    Word thread = registerAsWord(threadRegister);
    Object exception = readExceptionOop(thread);
    writeExceptionOop(thread, null);
    writeExceptionPc(thread, WordFactory.zero());
    return piCastToSnippetReplaceeStamp(exception);
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 15 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class Target_com_sun_security_auth_module_UnixSystem method getUnixInfo.

@Substitute
void getUnixInfo() {
    int realUid = Unistd.getuid();
    Word pwsize = WordFactory.signed(Unistd.sysconf(Unistd._SC_GETPW_R_SIZE_MAX()));
    if (pwsize.lessThan(0)) {
        // indicates no definitive bound: try different sizes
        pwsize = WordFactory.signed(1024);
    }
    CCharPointer pwbuf = LibC.malloc(pwsize);
    try {
        passwd pwent = StackValue.get(SizeOf.get(passwd.class));
        passwdPointer p = StackValue.get(SizeOf.get(passwdPointer.class));
        int result;
        do {
            if (pwbuf.isNull()) {
                throw new OutOfMemoryError("Native heap");
            }
            p.write(WordFactory.nullPointer());
            result = Pwd.getpwuid_r(realUid, pwent, pwbuf, pwsize, p);
            if (result == Errno.ERANGE()) {
                pwsize = pwsize.add(pwsize);
                pwbuf = LibC.realloc(pwbuf, pwsize);
            } else if (result < 0 && result != Errno.EINTR()) {
                throw new RuntimeException("getpwuid_r error: " + Errno.errno());
            }
        } while (result != 0);
        this.uid = pwent.pw_uid();
        this.gid = pwent.pw_gid();
        this.username = CTypeConversion.toJavaString(pwent.pw_name());
    } finally {
        LibC.free(pwbuf);
    }
    int ngroups = Unistd.getgroups(0, WordFactory.nullPointer());
    int[] groupIds = new int[ngroups];
    try (PinnedObject pinnedGroupIds = PinnedObject.create(groupIds)) {
        ngroups = Unistd.getgroups(groupIds.length, pinnedGroupIds.addressOfArrayElement(0));
    }
    this.groups = new long[ngroups];
    for (int i = 0; i < this.groups.length; i++) {
        this.groups[i] = groupIds[i];
    }
}
Also used : Word(org.graalvm.compiler.word.Word) Pwd.passwd(com.oracle.svm.core.posix.headers.Pwd.passwd) PinnedObject(org.graalvm.nativeimage.PinnedObject) Pwd.passwdPointer(com.oracle.svm.core.posix.headers.Pwd.passwdPointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Word (org.graalvm.compiler.word.Word)53 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)32 Snippet (org.graalvm.compiler.api.replacements.Snippet)22 Pointer (org.graalvm.word.Pointer)12 UnsignedWord (org.graalvm.word.UnsignedWord)7 MethodSubstitution (org.graalvm.compiler.api.replacements.MethodSubstitution)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)5 HotSpotReplacementsUtil.tlabIntArrayMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 HotSpotReplacementsUtil.loadKlassFromObject (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject)2 SignedWord (org.graalvm.word.SignedWord)2 Substitute (com.oracle.svm.core.annotate.Substitute)1 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)1 Pwd.passwd (com.oracle.svm.core.posix.headers.Pwd.passwd)1 Pwd.passwdPointer (com.oracle.svm.core.posix.headers.Pwd.passwdPointer)1 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)1 HotSpotReplacementsUtil.arrayPrototypeMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord)1 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)1 Isolate (org.graalvm.nativeimage.Isolate)1 PinnedObject (org.graalvm.nativeimage.PinnedObject)1