小凡156

博客园 首页 新随笔 联系 订阅 管理

2019年11月10日 #

摘要: 如上图,红框中表示OjectMonitor的enter方法一进来就通过CAS将OjectMonitor的_owner设置为当前线程,绿框中表示设置成功的逻辑,第一个if表示重入锁的逻辑,第二个if表示第一次设置_owner成功,都意味着竞争锁成功,而我们的线程C显然是竞争失败的,会进入下图中的无线循 阅读全文
posted @ 2019-11-10 16:48 小凡156 阅读(368) 评论(0) 推荐(0) 编辑

摘要: 此时的线程C无法进入synchronized{}代码块,用jstack看应该是BLOCKED状态,如下图: 我们看看monitorenter指令对应的源码吧,位置:openjdk/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp 1 IR 阅读全文
posted @ 2019-11-10 16:28 小凡156 阅读(702) 评论(0) 推荐(0) 编辑

摘要: 1 void ATTR ObjectMonitor::exit(bool not_suspended, TRAPS) { 2 3 Thread * Self = THREAD ; 4 5 if (THREAD != _owner) { 6 7 if (THREAD->is_lock_owned((a 阅读全文
posted @ 2019-11-10 16:16 小凡156 阅读(268) 评论(0) 推荐(0) 编辑

摘要: 1 // Consider: 2 3 // If the lock is cool (cxq == null && succ == null) and we're on an MP system 4 5 // then instead of transferring a thread from th 阅读全文
posted @ 2019-11-10 16:03 小凡156 阅读(291) 评论(0) 推荐(0) 编辑

摘要: 1 // Wait/Notify/NotifyAll 2 3 // 4 5 // Note: a subset of changes to ObjectMonitor::wait() 6 7 // will need to be replicated in complete_exit above 8 阅读全文
posted @ 2019-11-10 15:43 小凡156 阅读(347) 评论(0) 推荐(0) 编辑