当前位置:网站首页>What happened to the JVM locking on Tencent ECS?

What happened to the JVM locking on Tencent ECS?

2022-06-24 05:41:00 User 8639654

One Why do you say this ?

summary AQS after , By the way, let's review this aspect . This paper starts from the following high frequency problems :

  • What is the memory layout of objects in memory ?
  • describe synchronized and ReentrantLock The underlying implementation of and the underlying principle of reentry .
  • Talk about AQS, Why? AQS The bottom is CAS+volatile?
  • Describe the four states of the next lock and the lock upgrade process ?
  • Object o = new Object() How many bytes does it take up in memory ?
  • Is spin lock necessarily more efficient than heavyweight lock ?
  • Whether the efficiency of opening the deflection lock will definitely be improved ?
  • What's the weight of a heavyweight lock ?
  • When is a heavyweight lock more efficient than a lightweight lock , And vice versa ?

Two What happened to locking ?

The unconscious use of locks :

//System.out.println They're all locked 
public void println(String x) {
  synchronized (this) {
    print(x);
    newLine();
  }
}
 What happens to simple locking ?

 To find out what happens after locking, you need to look at the layout in memory after the object is created ?

 An object is in new After coming out, it is mainly divided into 4 Parts of :

markword This part is actually the core of locking , It also contains some life information of the object , For example, whether GC、 After several times Young GC Still alive .
klass pointer It records the... That points to the object class The file pointer .
instance data Record the variable data in the object .
padding Use as alignment , The object is 64 Bit server version , Specifies that object memory must be able to be 8 Byte Division , If it's not divisible , Then rely on the right 

Qi Laibu . for instance :new I have an object , Memory only takes up 18 byte , But the rules have to be able to be 8 to be divisible by , therefore padding=6.

public class JOLDemo {
    private static Object  o;
    public static void main(String[] args) {
        o = new Object();
        synchronized (o){
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }
    }
}
原网站

版权声明
本文为[User 8639654]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210805190122338i.html