When will JVM use intrinsics

后端 未结 2 625
天涯浪人
天涯浪人 2020-11-28 10:46

Why certain code patterns when present within JVM internal classes are turned into an intrinsic function, whereas the same patterns when called from my own class are not.

相关标签:
2条回答
  • 2020-11-28 11:07

    The JVM has a list of methods, usually native ones, which is replaces with inlined machine code. This list appears in intrinsic header file in the OpenJDK though I can't find a link to it on the web.

    See from line 581 in the link @Jack provided vmSymbols.hpp

    0 讨论(0)
  • 2020-11-28 11:10

    The answer is simple: an intrinsic function is defined in this way because a faster, native way to obtain the result of the function exists and it is applied in case thanks to a specified mapping.

    That's not something related to compilation at all. Integer.bitCount is special in the sense that implementation is marked to be replaceable with a native asm instruction POPCNT. Basically this native instruction is used when using the Integer.bitCount function (if the CPU supports that instruction), when you declare your own copy of the function the normal implementation is used.

    Why JVM is able to recognize that the function can be optimized? Because it's hardcoded somewhere in the JDK, that has nothing to do with similarity to the code.

    0 讨论(0)
提交回复
热议问题