001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.objectmodel;
014    
015    import org.jikesrvm.SizeConstants;
016    import org.jikesrvm.scheduler.RVMThread;
017    import org.vmmagic.unboxed.Word;
018    
019    /**
020     * Constants used to implement thin locks.
021     * A portion of a word, either in the object header
022     * or in some other location, is used to provide light weight
023     * synchronization operations. This class defines
024     * how the bits available for thin locks are allocated.
025     * Either a lock is in fat state, in which case it looks like
026     * 1Z..Z where Z..Z is the id of a heavy lock, or it is in
027     * thin state in which case it looks like 0I..IC..C where
028     * I is the thread id of the thread that owns the lock and
029     * C is the recursion count of the lock.
030     * <pre>
031     * aaaaTTTTTTTTTTbbbbb
032     * JavaHeader.NUM_THIN_LOCK_BITS = # of T's
033     * JavaHeader.THIN_LOCK_SHIFT = # of b's
034     * </pre>
035     */
036    public interface ThinLockConstants extends SizeConstants {
037    
038      // biased locking / thin locking status bits:
039      // 00 -> thin biasable, and biased if TID is non-zero
040      // 01 -> thin unbiasable
041      // 10 -> fat unbiasable
042    
043      int TL_NUM_BITS_STAT = 2;
044      int TL_NUM_BITS_TID = RVMThread.LOG_MAX_THREADS;
045      int TL_NUM_BITS_RC = JavaHeader.NUM_THIN_LOCK_BITS - TL_NUM_BITS_TID - TL_NUM_BITS_STAT;
046    
047      int TL_THREAD_ID_SHIFT = JavaHeader.THIN_LOCK_SHIFT;
048      int TL_LOCK_COUNT_SHIFT = TL_THREAD_ID_SHIFT + TL_NUM_BITS_TID;
049      int TL_STAT_SHIFT = TL_LOCK_COUNT_SHIFT + TL_NUM_BITS_RC;
050      int TL_LOCK_ID_SHIFT = JavaHeader.THIN_LOCK_SHIFT;
051      int TL_DEDICATED_U16_OFFSET = JavaHeader.THIN_LOCK_DEDICATED_U16_OFFSET;
052      int TL_DEDICATED_U16_SHIFT = JavaHeader.THIN_LOCK_DEDICATED_U16_SHIFT;
053    
054      Word TL_LOCK_COUNT_UNIT = Word.fromIntSignExtend(1 << TL_LOCK_COUNT_SHIFT);
055    
056      Word TL_LOCK_COUNT_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - TL_NUM_BITS_RC).lsh(TL_LOCK_COUNT_SHIFT);
057      Word TL_THREAD_ID_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - TL_NUM_BITS_TID).lsh(TL_THREAD_ID_SHIFT);
058      Word TL_LOCK_ID_MASK =
059          Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - (TL_NUM_BITS_RC + TL_NUM_BITS_TID)).lsh(TL_LOCK_ID_SHIFT);
060      Word TL_STAT_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - TL_NUM_BITS_TID).lsh(TL_STAT_SHIFT);
061      Word TL_UNLOCK_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - JavaHeader
062          .NUM_THIN_LOCK_BITS).lsh(JavaHeader.THIN_LOCK_SHIFT).not();
063    
064      Word TL_STAT_BIASABLE = Word.fromIntSignExtend(0).lsh(TL_STAT_SHIFT);
065      Word TL_STAT_THIN = Word.fromIntSignExtend(1).lsh(TL_STAT_SHIFT);
066      Word TL_STAT_FAT = Word.fromIntSignExtend(2).lsh(TL_STAT_SHIFT);
067    }
068