中<code root>/dalvik/vm/Sync.cpp
,有一个struct Monitor
:
struct Monitor {
Thread* owner; /* which thread currently owns the lock? */
int lockCount; /* owner's recursive lock depth */
Object* obj; /* what object are we part of [debug only] */
Thread* waitSet; /* threads currently waiting on this monitor */
pthread_mutex_t lock;
Monitor* next;
/*
* Who last acquired this monitor, when lock sampling is enabled.
* Even when enabled, ownerMethod may be NULL.
*/
const Method* ownerMethod;
u4 ownerPc;
};
我不明白为什么Monitor
要按 8 个字节对齐。我认为它应该对齐 4 个字节,因为其中的所有成员(即指针int
& pthread_mutex_t
)的长度都是 4 个字节。