Atomic Operations and Syncronization
This implementation is based on "Thin Locks: Featherweight Syncronization for Java" developed at IBM T.J. Watson Research Centre.
Object Layout
All objects contain the following header layout:
--- Locking Structure (24 bits) --- Metadata Token (16 bit integer)
Thin Locks
--- 0 (1 bit) --- Thread Identifier (15 bits) - Index in table which maps Thread Ids to Thread Pointers --- Count (8 bits) - Number of locks minus 1
Locking
- Lock Interrupts
- Old Value = 0x000
- Count = 0
- New Value = Old Value OR (Thread Identifier << 16)
- Compare and swap (Old Value, New Value) ==> Lock Word
- If equal jump to end
- Owned = (Thread Identifier << 16)
- Owned > 255 need fat lock
- (|Lock Word| XOR |Thread Index|) << 8
- Less Than 255
- Add 255 to |New Value|
- Store in |Lock Word|
- Unlock Interrupts
Fat Locks
--- 1 (1 bit) --- Lock Index (23 bits) - Index in table which maps Fat Locks to Fat Lock Structures.