= Benchmark @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(3) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Benchmark) @CompilerControl(CompilerControl.Mode.DONT_INLINE) public class IsPrimitive { private static final Class BYTE_CLASS = byte.class; private static final Class OBJECT_CLASS = Object.class; Class byteClass = byte.class; Class objectClass = Object.class; @Benchmark public boolean object_inline() { return Object.class.isPrimitive(); } @Benchmark public boolean object_staticFinal() { return OBJECT_CLASS.isPrimitive(); } @Benchmark public boolean object_instance() { return objectClass.isPrimitive(); } @Benchmark public boolean byte_inline() { return byte.class.isPrimitive(); } @Benchmark public boolean byte_staticFinal() { return BYTE_CLASS.isPrimitive(); } @Benchmark public boolean byte_instance() { return byteClass.isPrimitive(); } } == C1/release Benchmark Mode Cnt Score Error Units # Baseline IsPrimitive.byte_inline avgt 15 13.831 ± 0.231 ns/op IsPrimitive.byte_instance avgt 15 14.322 ± 0.015 ns/op IsPrimitive.byte_staticFinal avgt 15 13.762 ± 0.071 ns/op IsPrimitive.object_inline avgt 15 13.834 ± 0.181 ns/op IsPrimitive.object_instance avgt 15 14.171 ± 0.043 ns/op IsPrimitive.object_staticFinal avgt 15 13.764 ± 0.044 ns/op # Patched IsPrimitive.byte_inline avgt 15 3.545 ± 0.010 ns/op IsPrimitive.byte_instance avgt 15 3.766 ± 0.018 ns/op IsPrimitive.byte_staticFinal avgt 15 3.544 ± 0.012 ns/op IsPrimitive.object_inline avgt 15 3.540 ± 0.005 ns/op IsPrimitive.object_instance avgt 15 3.754 ± 0.006 ns/op IsPrimitive.object_staticFinal avgt 15 3.544 ± 0.007 ns/op Instead of going through JNI to Class::isPrimitive, we now successfully fold: byte_inline, byte_staticFinal: [Verified Entry Point] 2.42% 2.50% 0x00007f83b9067da0: mov %eax,-0x14000(%rsp) 3.84% 4.40% 0x00007f83b9067da7: push %rbp 2.39% 2.22% 0x00007f83b9067da8: sub $0x30,%rsp 4.31% 5.66% 0x00007f83b9067dac: mov $0x1,%eax ; <---- folded 0.28% 0.26% 0x00007f83b9067db1: add $0x30,%rsp 2.47% 2.24% 0x00007f83b9067db5: pop %rbp 0.66% 0.94% 0x00007f83b9067db6: test %eax,0x199b6244(%rip) 3.63% 4.36% 0x00007f83b9067dbc: retq object_inline, object_staticFinal: [Verified Entry Point] 3.21% 2.78% 0x00007fdf40e53ea0: mov %eax,-0x14000(%rsp) 3.86% 4.53% 0x00007fdf40e53ea7: push %rbp 2.64% 2.45% 0x00007fdf40e53ea8: sub $0x30,%rsp 4.27% 5.48% 0x00007fdf40e53eac: mov $0x0,%eax ; <---- folded 0.27% 0.42% 0x00007fdf40e53eb1: add $0x30,%rsp 2.71% 2.23% 0x00007fdf40e53eb5: pop %rbp 0.85% 0.60% 0x00007fdf40e53eb6: test %eax,0x19a3e144(%rip) 3.24% 3.79% 0x00007fdf40e53ebc: retq Also, we improve the cases where folding is not possible. But, we do the simple comparison, sparing the JNI overhead. byte_instance, object_instance: [Verified Entry Point] 1.94% 1.80% 0x00007f88b9238620: mov %eax,-0x14000(%rsp) 4.84% 6.07% 0x00007f88b9238627: push %rbp 2.13% 2.11% 0x00007f88b9238628: sub $0x30,%rsp 4.51% 5.42% 0x00007f88b923862c: mov 0x10(%rsi),%eax 0x00007f88b923862f: shl $0x3,%rax 1.60% 3.15% 0x00007f88b9238633: mov 0x48(%rax),%rax 2.29% 2.19% 0x00007f88b9238637: cmp $0x0,%eax ; <--- inlined check 5.42% 4.93% 0x00007f88b923863a: mov $0x0,%eax ; <--- not primitive 0x00007f88b923863f: jne 0x00007f88b923864a 0x00007f88b9238645: mov $0x1,%eax ; <--- primitive 4.54% 4.63% 0x00007f88b923864a: add $0x30,%rsp 0x00007f88b923864e: pop %rbp 1.38% 1.45% 0x00007f88b923864f: test %eax,0x19ad49ab(%rip) 0x00007f88b9238655: retq == C1/fastdebug NOT A SERIOUS COMPARISON, but interesting nevertheless: avoiding going to native improves performance, as expected. Benchmark Mode Cnt Score Error Units # Baseline IsPrimitive.byte_inline avgt 15 36.739 ± 2.635 ns/op IsPrimitive.byte_instance avgt 15 37.172 ± 3.161 ns/op IsPrimitive.byte_staticFinal avgt 15 36.529 ± 3.423 ns/op IsPrimitive.object_inline avgt 15 33.667 ± 1.806 ns/op IsPrimitive.object_instance avgt 15 34.193 ± 1.693 ns/op IsPrimitive.object_staticFinal avgt 15 35.198 ± 7.958 ns/op # Patched IsPrimitive.byte_inline avgt 15 3.888 ± 0.207 ns/op IsPrimitive.byte_instance avgt 15 4.331 ± 0.144 ns/op IsPrimitive.byte_staticFinal avgt 15 3.842 ± 0.076 ns/op IsPrimitive.object_inline avgt 15 3.828 ± 0.013 ns/op IsPrimitive.object_instance avgt 15 4.338 ± 0.074 ns/op IsPrimitive.object_staticFinal avgt 15 3.859 ± 0.172 ns/op