Open
Description
Type Test(object o) => o.GetType();
Current codegen:
; Method Test(System.Object):System.Type:this (FullOpts)
sub rsp, 40
mov rcx, rdx
call System.Object:GetType():System.Type:this
nop
add rsp, 40
ret
; Total bytes of code: 18
This calls directly into the internal vm helper, although, JIT special cases Object.GetType
into GT_INTRINSIC
even today to fold some type comparisons. We can slightly help jit here to generate an inlined access to Type object. Basically, it's:
nuint handle = RuntimeHelpers.GetMethodTable(o)->WriteableData->ExposedClassObject;
if (handle & 1)
return (Type)(handle -1); // direct frozen RuntimeType object
else
return <fallback to internal call>