Thursday, 2 June 2011

Plan for inline caching on x86_32

HotSpot passes the first two int/reference args in registers. For non-static methods this means this argument is always available in a register for inline cache check. The number of memory accesses is 1.

Jato passes this argument on stack. So obtaining this->class will require 2 memory accesses. We could use this pointer available at call-site in a register.

The call site code generated looks like this

/* edi contains this pointer */
mov %(edi), %ecx /* This works as null check and also passes this->class to #fn */
mov #imm, %eax
call #fn


The #imm and #fn fields depends on the state of the inline cache.

Clean state

#imm = vm_method *
#fn = inline_cache_setup

Monomorphic state

#imm = expected class
#fn = verified entry point of the method

Megamorphic state

#imm = vtable index of the virtual method
#fn = vtable lookup routine

The inline cache check can be

cmp %eax, %ecx
jne inline_cache_miss_handler


inline_cache_setup implements the transition from clean to monomorphic. inline_cache_miss_handler implements the transition from monomorphic to megamorphic.

Both routines along with the vtable lookup routine can use this->class passed in ecx for vtable lookup.

No comments:

Post a Comment