Exemple #1
0
 @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));
         return;
       } else {
         RVMThread.raiseIllegalMonitorStateException(
             "biased unlocking: we don't own this object", o);
       }
     } else if (stat.EQ(TL_STAT_THIN)) {
       Magic.sync();
       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);
         }
         if (Synchronization.tryCompareAndSwap(o, lockOffset, old, changed)) {
           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;
     }
   }
 }
Exemple #2
0
 /**
  * Prepare for a new collection increment. For the mark-sweep collector we must flip the state of
  * the mark bit between collections.
  */
 public void prepare(boolean fullHeap) {
   if (fullHeap) {
     if (VM.VERIFY_ASSERTIONS) {
       VM.assertions._assert(treadmill.fromSpaceEmpty());
     }
     markState = MARK_BIT.minus(markState);
   }
   treadmill.flip(fullHeap);
   inNurseryGC = !fullHeap;
 }
Exemple #3
0
 @Inline
 @NoNullCheck
 @Unpreemptible
 public static void inlineUnlockHelper(Object o, Offset lockOffset) {
   Word old = Magic.prepareWord(o, lockOffset); // FIXME: bad for PPC?
   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));
       return;
     }
   } else if (old.xor(tid).rshl(TL_LOCK_COUNT_SHIFT).EQ(TL_STAT_THIN.rshl(TL_LOCK_COUNT_SHIFT))) {
     Magic.sync();
     if (Magic.attemptWord(o, lockOffset, old, old.and(TL_UNLOCK_MASK).or(TL_STAT_THIN))) {
       return;
     }
   }
   unlock(o, lockOffset);
 }