Definition: Intrinsic
Intrinsic methods in Java are ones that have a native implementation by default in the JDK. They will have a Java version but most of the time it will get inlined and and the intrinsic implementation will be called instead.
Note that what methods are made intrinsic may depend on the platform.
Examples of Intrinsic methods include Math functions (sin, cos, min, max). The full list is here.
Example
Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String... args) { | |
int[] data = new int[100_000]; | |
Random random = new Random(); | |
for (int i = 0; i< 100_000; i++) { | |
data[i] = random.nextInt(); | |
} | |
int max = Integer.MIN_VALUE; | |
for (int x : data) { | |
max = Math.max(max, x); | |
} | |
System.out.println(max); | |
} |
-XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
In the output we see the following:
@ 97 java.lang.Math::max (11 bytes) (intrinsic)
Woohoo! It got inlined with the intrinsic code.
No comments:
Post a Comment