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     * <p>
022     * A portion of a word, either in the object header
023     * or in some other location, is used to provide light weight
024     * synchronization operations. This class defines
025     * how the bits available for thin locks are allocated.
026     * Either a lock is in fat state, in which case it looks like
027     * 1Z..Z where Z..Z is the id of a heavy lock, or it is in
028     * thin state in which case it looks like 0I..IC..C where
029     * I is the thread id of the thread that owns the lock and
030     * C is the recursion count of the lock.
031     * <pre>
032     * aaaaTTTTTTTTTTbbbbb
033     * JavaHeader.NUM_THIN_LOCK_BITS = # of T's
034     * JavaHeader.THIN_LOCK_SHIFT = # of b's
035     * </pre>
036     */
037    public interface ThinLockConstants extends SizeConstants {
038    
039      // biased locking / thin locking status bits:
040      // 00 -> thin biasable, and biased if TID is non-zero
041      // 01 -> thin unbiasable
042      // 10 -> fat unbiasable
043    
044      int TL_NUM_BITS_STAT = 2;
045      int TL_NUM_BITS_TID = RVMThread.LOG_MAX_THREADS;
046      int TL_NUM_BITS_RC = JavaHeader.NUM_THIN_LOCK_BITS - TL_NUM_BITS_TID - TL_NUM_BITS_STAT;
047    
048      int TL_THREAD_ID_SHIFT = JavaHeader.THIN_LOCK_SHIFT;
049      int TL_LOCK_COUNT_SHIFT = TL_THREAD_ID_SHIFT + TL_NUM_BITS_TID;
050      int TL_STAT_SHIFT = TL_LOCK_COUNT_SHIFT + TL_NUM_BITS_RC;
051      int TL_LOCK_ID_SHIFT = JavaHeader.THIN_LOCK_SHIFT;
052      int TL_DEDICATED_U16_OFFSET = JavaHeader.THIN_LOCK_DEDICATED_U16_OFFSET;
053      int TL_DEDICATED_U16_SHIFT = JavaHeader.THIN_LOCK_DEDICATED_U16_SHIFT;
054    
055      Word TL_LOCK_COUNT_UNIT = Word.fromIntSignExtend(1 << TL_LOCK_COUNT_SHIFT);
056    
057      Word TL_LOCK_COUNT_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - TL_NUM_BITS_RC).lsh(TL_LOCK_COUNT_SHIFT);
058      Word TL_THREAD_ID_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - TL_NUM_BITS_TID).lsh(TL_THREAD_ID_SHIFT);
059      Word TL_LOCK_ID_MASK =
060          Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - (TL_NUM_BITS_RC + TL_NUM_BITS_TID)).lsh(TL_LOCK_ID_SHIFT);
061      Word TL_STAT_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - TL_NUM_BITS_TID).lsh(TL_STAT_SHIFT);
062      Word TL_UNLOCK_MASK = Word.fromIntSignExtend(-1).rshl(BITS_IN_ADDRESS - JavaHeader
063          .NUM_THIN_LOCK_BITS).lsh(JavaHeader.THIN_LOCK_SHIFT).not();
064    
065      Word TL_STAT_BIASABLE = Word.fromIntSignExtend(0).lsh(TL_STAT_SHIFT);
066      Word TL_STAT_THIN = Word.fromIntSignExtend(1).lsh(TL_STAT_SHIFT);
067      Word TL_STAT_FAT = Word.fromIntSignExtend(2).lsh(TL_STAT_SHIFT);
068    }
069