Skip to content

Bad speculation in JIT_MonExit_Portable #34800

Description

@benaadams

There is a high misprediction rate for the common path in JIT_MonExit_Portable

image

With the common path action == AwareLock::LeaveHelperAction_None not being arranged as the common path in asm.

action = obj->LeaveObjMonitorHelper(GetThread());
if (action == AwareLock::LeaveHelperAction_None)
{
return;
}

image

I've tried rearranging this in the C++; however it seems quite resistant to ordering change; perhaps PGO is incorrectly enforcing the order here?

Aside: I assume it needs to be a cmpxchg rather than just a volatile write because it may have changed from a lock to a lock+hashcode or perhaps signaling? Would there be any scope to having a lock object type that doesn't allow a hashcode or signaling, so it could just be a volatile write to unlock a non-recursive non-signaled lock? (as JIT_MonExit_Portable is quite expensive in the code I'm looking at as 3rd highest cost method)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions