1
轻量级锁会自旋吗?
source link: http://www.hollischuang.com/archives/6689
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
轻量级锁会自旋吗?
2022-05-22
分类:Java
阅读(63) 评论(0)
对象加锁的入口在ObjectSynchronizer::enter(h_obj, lock, current); 这个方法中(https://github.com/openjdk/jdk/blob/9583e3657e43cc1c6f2101a64534564db2a9bd84/src/hotspot/share/runtime/synchronizer.cpp#L348 )。
enter方法代码如下:
大概过程就是,如果是轻量级锁,则进行CAS(cas_set_mark(markWord::from_pointer(lock), mark)),否则,直接膨胀(inflate()),这个膨胀的过程中没有自旋的操作。
(全文完) 扫描二维码,关注作者微信公众号
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK