1 lock bias. When an object lock is requested out of the box, if the lock is acquired, the object lock enters bias mode, and when the thread requests the lock on the object again, no further synchronization is required.
You can turn on the bias lock by turning on the parameter-xx:+usebasedlock in the Java Virtual machine
The applicable environment is: The lock competition is not very intense. If the lock is in a very competitive environment, it is likely that the next time the current lock is not the same thread, the bias lock is invalid
2 Light weight lock. If the bias fails, the virtual machine does not immediately suspend the thread. The virtual opportunity simply takes the object's head as a pointer, pointing to the inside of the stack holding the lock, to determine whether a thread holds the object lock.
If the thread obtains a lightweight lock success, it can go inside the thread smoothly.
3 spin lock. If a lightweight lock fails, the thread is not immediately suspended, and the virtual machine makes a final effort: spin lock. Since other threads have acquired the lock, we do not know when the lock will be released, and if it is simply rude to suspend the current thread directly, it may outweigh the costs and increase the resource consumption. At this time the virtual opportunity assumes that in the near future we can get locks. The system causes the current thread to make several empty loops, and after several loops, if the lock is acquired, it enters the critical section or hangs the thread.
4 lock removal. When a virtual machine is JIT-compiled, it scans the context to remove locks that cannot compete with resources
Lock optimization for Java virtual machines