Search in sources :

Example 1 with NoNullCheck

use of org.vmmagic.pragma.NoNullCheck in project JikesRVM by JikesRVM.

the class ThinLock method inlineLock.

@Inline
@NoNullCheck
@Unpreemptible
@Entrypoint
public static void inlineLock(Object o, Offset lockOffset) {
    // FIXME: bad for PPC?
    Word old = Magic.prepareWord(o, lockOffset);
    Word id = old.and(TL_THREAD_ID_MASK.or(TL_STAT_MASK));
    Word tid = Word.fromIntSignExtend(RVMThread.getCurrentThread().getLockingId());
    if (id.EQ(tid)) {
        Word changed = old.plus(TL_LOCK_COUNT_UNIT);
        if (!changed.and(TL_LOCK_COUNT_MASK).isZero()) {
            setDedicatedU16(o, lockOffset, changed);
            Magic.combinedLoadBarrier();
            return;
        }
    } else if (id.EQ(TL_STAT_THIN)) {
        // lock is thin and not held by anyone
        if (Magic.attemptWord(o, lockOffset, old, old.or(tid))) {
            if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                Magic.fence();
            return;
        }
    }
    lock(o, lockOffset);
}
Also used : Word(org.vmmagic.unboxed.Word) Unpreemptible(org.vmmagic.pragma.Unpreemptible) Entrypoint(org.vmmagic.pragma.Entrypoint) NoNullCheck(org.vmmagic.pragma.NoNullCheck) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Example 2 with NoNullCheck

use of org.vmmagic.pragma.NoNullCheck in project JikesRVM by JikesRVM.

the class ThinLock method holdsLock.

@Uninterruptible
@NoNullCheck
public static boolean holdsLock(Object o, Offset lockOffset, RVMThread thread) {
    for (int cnt = 0; ; ++cnt) {
        int tid = thread.getLockingId();
        Word bits = Magic.getWordAtOffset(o, lockOffset);
        if (bits.and(TL_STAT_MASK).EQ(TL_STAT_BIASABLE)) {
            // if locked, then it is locked with a thin lock
            return bits.and(TL_THREAD_ID_MASK).toInt() == tid && !bits.and(TL_LOCK_COUNT_MASK).isZero();
        } else if (bits.and(TL_STAT_MASK).EQ(TL_STAT_THIN)) {
            return bits.and(TL_THREAD_ID_MASK).toInt() == tid;
        } else {
            if (VM.VerifyAssertions)
                VM._assert(bits.and(TL_STAT_MASK).EQ(TL_STAT_FAT));
            // if locked, then it is locked with a fat lock
            Lock l = Lock.getLock(getLockIndex(bits));
            if (l != null) {
                l.mutex.lock();
                boolean result = (l.getOwnerId() == tid && l.getLockedObject() == o);
                l.mutex.unlock();
                return result;
            }
        }
        RVMThread.yieldNoHandshake();
    }
}
Also used : Word(org.vmmagic.unboxed.Word) Entrypoint(org.vmmagic.pragma.Entrypoint) Uninterruptible(org.vmmagic.pragma.Uninterruptible) NoNullCheck(org.vmmagic.pragma.NoNullCheck)

Example 3 with NoNullCheck

use of org.vmmagic.pragma.NoNullCheck in project JikesRVM by JikesRVM.

the class ThinLock method lock.

@NoInline
@NoNullCheck
@Unpreemptible
public static void lock(Object o, Offset lockOffset) {
    if (STATS)
        fastLocks++;
    Word threadId = Word.fromIntZeroExtend(RVMThread.getCurrentThread().getLockingId());
    for (int cnt = 0; ; cnt++) {
        Word old = Magic.getWordAtOffset(o, lockOffset);
        Word stat = old.and(TL_STAT_MASK);
        boolean tryToInflate = false;
        if (stat.EQ(TL_STAT_BIASABLE)) {
            Word id = old.and(TL_THREAD_ID_MASK);
            if (id.isZero()) {
                if (ENABLE_BIASED_LOCKING) {
                    // lock is unbiased, bias it in our favor and grab it
                    if (Synchronization.tryCompareAndSwap(o, lockOffset, old, old.or(threadId).plus(TL_LOCK_COUNT_UNIT))) {
                        if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                            Magic.fence();
                        return;
                    }
                } else {
                    // a thin lock
                    if (Synchronization.tryCompareAndSwap(o, lockOffset, old, old.or(threadId).or(TL_STAT_THIN))) {
                        if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                            Magic.fence();
                        return;
                    }
                }
            } else if (id.EQ(threadId)) {
                // lock is biased in our favor
                Word changed = old.plus(TL_LOCK_COUNT_UNIT);
                if (!changed.and(TL_LOCK_COUNT_MASK).isZero()) {
                    setDedicatedU16(o, lockOffset, changed);
                    Magic.combinedLoadBarrier();
                    return;
                } else {
                    tryToInflate = true;
                }
            } else {
                if (casFromBiased(o, lockOffset, old, biasBitsToThinBits(old), cnt)) {
                    // don't spin, since it's thin now
                    continue;
                }
            }
        } else if (stat.EQ(TL_STAT_THIN)) {
            Word id = old.and(TL_THREAD_ID_MASK);
            if (id.isZero()) {
                if (Synchronization.tryCompareAndSwap(o, lockOffset, old, old.or(threadId))) {
                    if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                        Magic.fence();
                    return;
                }
            } else if (id.EQ(threadId)) {
                Word changed = old.plus(TL_LOCK_COUNT_UNIT);
                if (changed.and(TL_LOCK_COUNT_MASK).isZero()) {
                    tryToInflate = true;
                } else if (Synchronization.tryCompareAndSwap(o, lockOffset, old, changed)) {
                    if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                        Magic.fence();
                    return;
                }
            } else if (cnt > retryLimit) {
                tryToInflate = true;
            }
        } else {
            if (VM.VerifyAssertions)
                VM._assert(stat.EQ(TL_STAT_FAT));
            // lock is fat.  contend on it.
            if (Lock.getLock(getLockIndex(old)).lockHeavy(o)) {
                return;
            }
        }
        if (tryToInflate) {
            if (STATS)
                slowLocks++;
            // Right Thing if the lock is biased to someone else.
            if (inflateAndLock(o, lockOffset)) {
                return;
            }
        } else {
            Magic.combinedLoadBarrier();
            RVMThread.yieldNoHandshake();
        }
    }
}
Also used : Word(org.vmmagic.unboxed.Word) Entrypoint(org.vmmagic.pragma.Entrypoint) Unpreemptible(org.vmmagic.pragma.Unpreemptible) NoNullCheck(org.vmmagic.pragma.NoNullCheck) NoInline(org.vmmagic.pragma.NoInline)

Example 4 with NoNullCheck

use of org.vmmagic.pragma.NoNullCheck in project JikesRVM by JikesRVM.

the class ThinLock method unlock.

@NoInline
@NoNullCheck
@Unpreemptible
public static void unlock(Object o, Offset lockOffset) {
    Word threadId = Word.fromIntZeroExtend(RVMThread.getCurrentThread().getLockingId());
    for (int cnt = 0; ; cnt++) {
        Word old = Magic.getWordAtOffset(o, lockOffset);
        Word stat = old.and(TL_STAT_MASK);
        if (stat.EQ(TL_STAT_BIASABLE)) {
            Word id = old.and(TL_THREAD_ID_MASK);
            if (id.EQ(threadId)) {
                if (old.and(TL_LOCK_COUNT_MASK).isZero()) {
                    RVMThread.raiseIllegalMonitorStateException("biased unlocking: we own this object but the count is already zero", o);
                }
                setDedicatedU16(o, lockOffset, old.minus(TL_LOCK_COUNT_UNIT));
                Magic.fence();
                return;
            } else {
                RVMThread.raiseIllegalMonitorStateException("biased unlocking: we don't own this object", o);
            }
        } else if (stat.EQ(TL_STAT_THIN)) {
            Word id = old.and(TL_THREAD_ID_MASK);
            if (id.EQ(threadId)) {
                Word changed;
                if (old.and(TL_LOCK_COUNT_MASK).isZero()) {
                    changed = old.and(TL_UNLOCK_MASK).or(TL_STAT_THIN);
                } else {
                    changed = old.minus(TL_LOCK_COUNT_UNIT);
                }
                Magic.combinedLoadBarrier();
                if (Synchronization.tryCompareAndSwap(o, lockOffset, old, changed)) {
                    if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                        Magic.fence();
                    return;
                }
            } else {
                if (false) {
                    VM.sysWriteln("threadId = ", threadId);
                    VM.sysWriteln("id = ", id);
                }
                RVMThread.raiseIllegalMonitorStateException("thin unlocking: we don't own this object", o);
            }
        } else {
            if (VM.VerifyAssertions)
                VM._assert(stat.EQ(TL_STAT_FAT));
            // fat unlock
            Lock.getLock(getLockIndex(old)).unlockHeavy(o);
            return;
        }
    }
}
Also used : Word(org.vmmagic.unboxed.Word) Entrypoint(org.vmmagic.pragma.Entrypoint) Unpreemptible(org.vmmagic.pragma.Unpreemptible) NoNullCheck(org.vmmagic.pragma.NoNullCheck) NoInline(org.vmmagic.pragma.NoInline)

Example 5 with NoNullCheck

use of org.vmmagic.pragma.NoNullCheck in project JikesRVM by JikesRVM.

the class ThinLock method inlineUnlock.

@Inline
@NoNullCheck
@Unpreemptible
@Entrypoint
public static void inlineUnlock(Object o, Offset lockOffset) {
    // FIXME: bad for PPC?
    Word old = Magic.prepareWord(o, lockOffset);
    Word id = old.and(TL_THREAD_ID_MASK.or(TL_STAT_MASK));
    Word tid = Word.fromIntSignExtend(RVMThread.getCurrentThread().getLockingId());
    if (id.EQ(tid)) {
        if (!old.and(TL_LOCK_COUNT_MASK).isZero()) {
            setDedicatedU16(o, lockOffset, old.minus(TL_LOCK_COUNT_UNIT));
            Magic.fence();
            return;
        }
    } else if (old.xor(tid).rshl(TL_LOCK_COUNT_SHIFT).EQ(TL_STAT_THIN.rshl(TL_LOCK_COUNT_SHIFT))) {
        Magic.combinedLoadBarrier();
        if (Magic.attemptWord(o, lockOffset, old, old.and(TL_UNLOCK_MASK).or(TL_STAT_THIN))) {
            if (!VM.MagicAttemptImpliesStoreLoadBarrier)
                Magic.fence();
            return;
        }
    }
    unlock(o, lockOffset);
}
Also used : Word(org.vmmagic.unboxed.Word) Unpreemptible(org.vmmagic.pragma.Unpreemptible) Entrypoint(org.vmmagic.pragma.Entrypoint) NoNullCheck(org.vmmagic.pragma.NoNullCheck) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Aggregations

Entrypoint (org.vmmagic.pragma.Entrypoint)6 NoNullCheck (org.vmmagic.pragma.NoNullCheck)6 Word (org.vmmagic.unboxed.Word)6 Unpreemptible (org.vmmagic.pragma.Unpreemptible)5 NoInline (org.vmmagic.pragma.NoInline)4 Inline (org.vmmagic.pragma.Inline)2 Uninterruptible (org.vmmagic.pragma.Uninterruptible)1