3 ms·
> But did you know there is also a secret second implementation? String.compareTo is one of a few methods that is important enough to also get a special hand-ro
by exikyut 9y ago
> But did you know there is also a secret second implementation? String.compareTo is one of a few methods that is important enough to also get a special hand-rolled assembly version.
oooooh.
Is there a list somewhere of all the functions that have had such special treatment?
- kaeluka 9y agoThe feature is called "intrinsics", this claims to be a list: https://gist.github.com/apangin/7a9b7062a4bd0cd41fcc https://gist.github.com/apangin/7a9b7062a4bd0cd41fcc
- djsumdog 9y agoInteresting. So do all those functions have assembly implementations or do some of them have c implementations? I'm assuming the list of functions also changes depending on the architecture?
- BeeOnRope 9y agoThey are implemented in different ways, depending on the instrinsic. Many are implemented in the in-memory intermediate SSA (?) representation the JVM uses for its JIT, so they essentially get compiled down to assembly at the same time as the surrounding bytecode. Some are implemented as jumps to various native methods, which in turn might be implemented in C++ or assembly. Most intrinsics are available on most platforms: only some of the hand-coded assembly versions are less likely to have wide support.
- nicoulaj 9y agoThe intrinsics for the HotSpot JVM are declared here: http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/5ab7a67bc155/src/share/vm/classfile/vmSymbols.hpp#l679 http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/5ab7a67b... (look for "java_lang_Math" for instance)
- rplnt 9y agoAre you telling us it's not a secret then?
- sudhirj 9y agoDon’t know if this is sarcasm, but no, doubtful it’s a secret. Or might depend on the JVM license. OpenJDK obviously has no secrets. But otherwise, assembly overrides for hot paths in execution targets that support them aren’t actually a big secret, just that they’re rarely visible. Think Go has a lot of processed architecture specific assembly for some functions, especially crypto iirc.
- rplnt 9y agoYeah, it was a sarcasm. The article (quoted in parent comment) called it a secret implementation.