CLR Sync Block Address

泪湿孤枕 提交于 2019-11-30 07:45:06

The sync block has more than one use. It can store the value of Object.GetHashCode() so that an object always returns the same hash code when GetHashCode() is called again. It can store the ID of the owner thread of a lock statement. It has several dedicated bits, like indicating that the finalizer for an object has been run. And it can store a handle to an allocated sync block, necessary when a thread both called GetHashCode and used lock and the info can't fit in the sync block anymore. It is very heavily micro-optimized.

Your case is the simple case, only lock was called and none of the dedicated bits are turned on. So you see the owner of the lock, 0x12 = 18 is the Thread.ManagedThreadId of the thread that owns the lock. That can come in pretty doggone handy when you ever need to troubleshoot a deadlock.

You can make the debugger display a bit easier to interpret when you right-click the window and select "4-byte Integer". The blue rectangle is the method table pointer for the object (aka "type handle"). It indicates the type of the object, Object.GetType() uses it. The red rectangle is where the object starts storing its fields. Since yours only has the exp field and its type is Int32, you can see 3 back.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!