Determining whether a particular JDK Method typically has an intrinsic implementation
Asked Answered
C

2

12

Short of the reading the OpenJDK source code (which I'm not averse to) is there a reasonably comprehensive (or 'official') list of intrinsic operations within the Hotspot JVM (say for Intel)?

For example, what's the quickest way to determine whether Math.abs() will generally be converted directly to a few native instructions wherever it is used?

Coextend answered 18/4, 2015 at 19:1 Comment(1)
Since it depends on the JVM implementations, you'll probably have to dive source code...Unobtrusive
C
14

The relevant part of the OpenJDK source code states:

http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/classfile/vmSymbols.hpp#l581

"Here are all the intrinsics known to the runtime and the CI."

So I suppose that's comprehensive enough!

Coextend answered 18/4, 2015 at 19:19 Comment(1)
Here's the equivalent for JDK 9 hg.openjdk.java.net/jdk9/jdk9/hotspot/file/tip/src/share/vm/…Coextend
C
7

Java 9 adds the @HotSpotIntrinsicCandidate annotation, which was renamed to just @IntrinsicCandidate in JDK 16. Methods annotated with that annotation will have an intrinsic defined for them on at least one platform (and this is even checked during class loading).

Unfortunately this annotation does not show up in the online javadoc, but I can still see it using my IDE (Eclipse), and I assume that other IDEs provide a similar mechanism, so that is a fast way to check:

Picture of eclipse javadoc window

Casern answered 2/10, 2017 at 17:7 Comment(1)
One small (and probably obvious) correction: Methods annotated "@IntrinsicCandidate" may be intrinsified … or not. It depends on the JVM for a particular platform. That's one reason for the pure Java implementations of most such methods; not only do they simplify bootstrapping the JVM on a new platform, but, afterward, they allow piecemeal intrinsification from one release to the next, according to perceived need, utility, and the relevant JVM developers' enthusiasm-to-time ratios. Not all JVMs receive the same love as, say, the x64 ports.Tyika

© 2022 - 2024 — McMap. All rights reserved.