I was playing around with JMH, and under different load Math.max(int, int)
from same JVM (OpenJDK 13) compiled to two different implementations (both were emitted by C2):
call handling code (stack and base pointers setting/restoration, etc.) omitted
0x00007f8ce456cd8c: cmp %edx,%esi
0x00007f8ce456cd8e: mov %esi,%eax
0x00007f8ce456cd90: cmovl %edx,%eax ;*ireturn {reexecute=0 rethrow=0 return_oop=0}
; - java.lang.Math::max@10 (line 1441)
some call handling code present due to nature of jumps
0x00007fdda859270c: cmp %edx,%esi
0x00007fdda859270e: jl 0x00007fdda8592722 ;*if_icmplt {reexecute=0 rethrow=0 return_oop=0}
; - java.lang.Math::max@2 (line 1441)
0x00007fdda8592710: mov %esi,%eax ;*ireturn {reexecute=0 rethrow=0 return_oop=0}
; - java.lang.Math::max@10 (line 1441)
0x00007fdda8592712: add $0x10,%rsp
0x00007fdda8592716: pop %rbp
0x00007fdda8592717: mov 0x108(%r15),%r10
0x00007fdda859271e: test %eax,(%r10) ; {poll_return}
0x00007fdda8592721: retq
0x00007fdda8592722: mov %edx,%eax
0x00007fdda8592724: jmp 0x00007fdda8592712
I used -XX:+UnlockDiagnosticVMOptions -XX:+PrintIntrinsics
as well, and Math.max
is printed out.
I was sure that intrinsic means static (i.e. it's always the same) C++ implementation for specific method from JRE, however, given the output above I'm confused. I know that intrinsics can be described as "optimization technique that provides custom, more performant implementation for standard methods", but what exactly is intrinsic (let's restrict domain by HotSpot JVM only)? Is it static code that is compiled with JVM and shouldn't differ on same architecture? Is it some kind of IR that replaces original one? Is it optimized bytecode, that again replaces whatever is source code compiled to? Is it any of the above depending on particular method?