Lightweight locks
The JDK1.6 appeared. It is not a substitute for a heavyweight lock, which is meant to reduce the performance consumption of traditional heavyweight locks using operating system mutexes without multiple threading competition. Hotspot the Run-time data of the virtual machine Object Header object itself
such as: hash (hashcode), GC generational age (generational GC), this part of the data in the 32-bit and 64-bit virtual machines are 32bit and 64bit, referred to as "Mark Word", if the object is an array type, The virtual machine stores the object header in 3 word (word width), and the object header is stored in 2Word if the object is a non array type. The first part of the object header information is the key to implement lightweight locks and bias locks. To store a pointer to a method area object type data
A pointer to the method area object type data, or, if it is an array object, an extra portion to store the array length.
Object header information is an additional storage cost that is independent of the data defined by the object itself. Markword is designed as an unfixed data structure to store as much information as possible in a very small space. It will reuse its own storage space based on the state of the object. For example, in a 32-bit hotspot virtual machine where the object is not locked, 25bit in 32bit space of Mark Word is used to store the object hash (hashcode), 4bit is used to store the age of the object, 2bit is used to store the lock flag bit, and 1bit is fixed to 0. Storage content lock states for objects in other states include lightweight locks, heavyweight locks, GC tags, biased
Mark Word's default storage structure for 32-bit JVMs is as follows: Under the 64-bit JVM, Mark Word is 64bit in size and the storage structure is as follows:
To be continued.