Search in sources :

Example 6 with NoNullCheck

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

the class ThinLock method attemptToInflate.

/**
 * Promotes a light-weight lock to a heavy-weight lock.  If this returns the lock
 * that you gave it, its mutex will be locked; otherwise, its mutex will be unlocked.
 * Hence, calls to this method should always be followed by a condition lock() or
 * unlock() call.
 *
 * @param o the object to get a heavy-weight lock
 * @param lockOffset the offset of the thin lock word in the object.
 * @param l the lock to attempt to inflate
 * @return the inflated lock; either the one you gave, or another one, if the lock
 *         was inflated by some other thread.
 */
@NoNullCheck
@Unpreemptible
protected static Lock attemptToInflate(Object o, Offset lockOffset, Lock l) {
    if (false)
        VM.sysWriteln("l = ", Magic.objectAsAddress(l));
    l.mutex.lock();
    for (int cnt = 0; ; ++cnt) {
        Word bits = Magic.getWordAtOffset(o, lockOffset);
        // check to see if another thread has already created a fat lock
        if (isFat(bits)) {
            if (trace) {
                VM.sysWriteln("Thread #", RVMThread.getCurrentThreadSlot(), ": freeing lock ", Magic.objectAsAddress(l), " because we had a double-inflate");
            }
            Lock result = Lock.getLock(getLockIndex(bits));
            if (result == null || result.lockedObject != o) {
                continue;
            /* this is nasty.  this will happen when a lock
                       is deflated. */
            }
            Lock.free(l);
            l.mutex.unlock();
            return result;
        }
        if (VM.VerifyAssertions)
            VM._assert(l != null);
        if (attemptToMarkInflated(o, lockOffset, bits, l.index, cnt)) {
            l.setLockedObject(o);
            l.setOwnerId(getLockOwner(bits));
            if (l.getOwnerId() != 0) {
                l.setRecursionCount(getRecCount(bits));
            } else {
                if (VM.VerifyAssertions)
                    VM._assert(l.getRecursionCount() == 0);
            }
            return l;
        }
    // contention detected, try again
    }
}
Also used : Word(org.vmmagic.unboxed.Word) Entrypoint(org.vmmagic.pragma.Entrypoint) Unpreemptible(org.vmmagic.pragma.Unpreemptible) NoNullCheck(org.vmmagic.pragma.NoNullCheck)

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