<i id='Qb5hj'><tr id='Qb5hj'><dt id='Qb5hj'><q id='Qb5hj'><span id='Qb5hj'><b id='Qb5hj'><form id='Qb5hj'><ins id='Qb5hj'></ins><ul id='Qb5hj'></ul><sub id='Qb5hj'></sub></form><legend id='Qb5hj'></legend><bdo id='Qb5hj'><pre id='Qb5hj'><center id='Qb5hj'></center></pre></bdo></b><th id='Qb5hj'></th></span></q></dt></tr></i><div id='Qb5hj'><tfoot id='Qb5hj'></tfoot><dl id='Qb5hj'><fieldset id='Qb5hj'></fieldset></dl></div>
    1. <legend id='Qb5hj'><style id='Qb5hj'><dir id='Qb5hj'><q id='Qb5hj'></q></dir></style></legend>

      <small id='Qb5hj'></small><noframes id='Qb5hj'>

    2. <tfoot id='Qb5hj'></tfoot>

      • <bdo id='Qb5hj'></bdo><ul id='Qb5hj'></ul>

        JVM 什么时候使用内部函数

        时间:2023-08-25
      1. <tfoot id='JVvJG'></tfoot>

        <i id='JVvJG'><tr id='JVvJG'><dt id='JVvJG'><q id='JVvJG'><span id='JVvJG'><b id='JVvJG'><form id='JVvJG'><ins id='JVvJG'></ins><ul id='JVvJG'></ul><sub id='JVvJG'></sub></form><legend id='JVvJG'></legend><bdo id='JVvJG'><pre id='JVvJG'><center id='JVvJG'></center></pre></bdo></b><th id='JVvJG'></th></span></q></dt></tr></i><div id='JVvJG'><tfoot id='JVvJG'></tfoot><dl id='JVvJG'><fieldset id='JVvJG'></fieldset></dl></div>

            1. <legend id='JVvJG'><style id='JVvJG'><dir id='JVvJG'><q id='JVvJG'></q></dir></style></legend>

                  <tbody id='JVvJG'></tbody>

                <small id='JVvJG'></small><noframes id='JVvJG'>

                  <bdo id='JVvJG'></bdo><ul id='JVvJG'></ul>
                  本文介绍了JVM 什么时候使用内部函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么在 JVM 内部类中存在的某些代码模式被转换为内部函数,而从我自己的类中调用的相同模式却不是.

                  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.

                  例子:

                  bitCount 函数,当从 Integer.bitCount(i) 中调用时,将变成一个内在函数.但是,当复制到我的班级然后被调用时,将需要更长的时间来执行.

                  bitCount function, when called from within Integer.bitCount(i) will be turned into an intrinsic. But when copied into my class and then called will take much longer to execute.

                  比较

                  Integer.bitCount(i) 
                  MyClass.bitCount(i) 
                  
                  
                  public static int bitCount(int i) {
                      // HD, Figure 5-2
                      i = i - ((i >>> 1) & 0x55555555);
                      i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
                      i = (i + (i >>> 4)) & 0x0f0f0f0f;
                      i = i + (i >>> 8);
                      i = i + (i >>> 16);
                      return i & 0x3f;
                  }
                  

                  推荐答案

                  答案很简单:这样定义一个内部函数是因为存在一种更快、更原生的方法来获取函数的结果,并且它适用于万一感谢指定的映射.

                  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.

                  这根本与编译无关.Integer.bitCount 的特殊之处在于实现被标记为可替换为原生 asm 指令 POPCNT.基本上,在使用 Integer.bitCount 函数(如果 CPU 支持该指令)时会使用此本机指令,当您声明自己的函数副本时,将使用正常实现.

                  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.

                  为什么JVM能够识别出可以优化的功能?因为它是硬编码的 某处 在JDK中,与代码相似度无关.

                  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.

                  这篇关于JVM 什么时候使用内部函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么每个应用程序有一个 JVM? 下一篇:是否有一种简单的方法可以在 Java 中获取特定类的所有对象实例

                  相关文章

                  <small id='6NkpR'></small><noframes id='6NkpR'>

                  <i id='6NkpR'><tr id='6NkpR'><dt id='6NkpR'><q id='6NkpR'><span id='6NkpR'><b id='6NkpR'><form id='6NkpR'><ins id='6NkpR'></ins><ul id='6NkpR'></ul><sub id='6NkpR'></sub></form><legend id='6NkpR'></legend><bdo id='6NkpR'><pre id='6NkpR'><center id='6NkpR'></center></pre></bdo></b><th id='6NkpR'></th></span></q></dt></tr></i><div id='6NkpR'><tfoot id='6NkpR'></tfoot><dl id='6NkpR'><fieldset id='6NkpR'></fieldset></dl></div>

                • <legend id='6NkpR'><style id='6NkpR'><dir id='6NkpR'><q id='6NkpR'></q></dir></style></legend>

                      <bdo id='6NkpR'></bdo><ul id='6NkpR'></ul>
                  1. <tfoot id='6NkpR'></tfoot>