Deep understanding of jvm--lightweight locks and bias locks

Source: Internet
Author: User
Tags array length
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.