<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body style="background-color: rgb(255, 255, 255); color: rgb(0, 0,
    0);" bgcolor="#FFFFFF" text="#000000">
    Ok, here's a test...<br>
    <br>
    with just the following change:<br>
    <br>
    <br>
    diff -r 9ea9fb3c0c88
    src/java.base/share/classes/java/math/BigInteger.java<br>
    --- a/src/java.base/share/classes/java/math/BigInteger.java     Wed
    Mar 23 18:24:35 2016 +0100<br>
    +++ b/src/java.base/share/classes/java/math/BigInteger.java     Wed
    Mar 23 19:55:01 2016 +0100<br>
    @@ -41,6 +41,7 @@<br>
     import jdk.internal.math.DoubleConsts;<br>
     import jdk.internal.math.FloatConsts;<br>
     import jdk.internal.HotSpotIntrinsicCandidate;<br>
    +import jdk.internal.vm.annotation.Stable;<br>
     <br>
     /**<br>
      * Immutable arbitrary-precision integers.  All operations behave
    as if<br>
    @@ -1213,8 +1214,10 @@<br>
          * Initialize static constant array when class is loaded.<br>
          */<br>
         private static final int MAX_CONSTANT = 16;<br>
    -    private static BigInteger posConst[] = new
    BigInteger[MAX_CONSTANT+1];<br>
    -    private static BigInteger negConst[] = new
    BigInteger[MAX_CONSTANT+1];<br>
    +    @Stable<br>
    +    private static final BigInteger posConst[] = new
    BigInteger[MAX_CONSTANT+1];<br>
    +    @Stable<br>
    +    private static final BigInteger negConst[] = new
    BigInteger[MAX_CONSTANT+1];<br>
     <br>
         /**<br>
          * The cache of powers of each radix.  This allows us to not
    have to<br>
    <br>
    <br>
    <br>
    The results of simple benchmark:<br>
    <br>
    /*<br>
    <br>
    Original:<br>
    <br>
    Benchmark                  Mode  Cnt  Score   Error  Units<br>
    BigIntegerBench.ONE        avgt   10  2.396 ± 0.232  ns/op<br>
    BigIntegerBench.valueOf_1  avgt   10  2.846 ± 0.233  ns/op<br>
    BigIntegerBench.valueOf_2  avgt   10  2.808 ± 0.054  ns/op<br>
    <br>
    Patched:<br>
    <br>
    Benchmark                  Mode  Cnt  Score   Error  Units<br>
    BigIntegerBench.ONE        avgt   10  2.381 ± 0.126  ns/op<br>
    BigIntegerBench.valueOf_1  avgt   10  2.347 ± 0.089  ns/op<br>
    BigIntegerBench.valueOf_2  avgt   10  2.323 ± 0.022  ns/op<br>
    <br>
    */<br>
    package jdk.test;<br>
    <br>
    import org.openjdk.jmh.annotations.*;<br>
    <br>
    import java.math.BigInteger;<br>
    import java.util.concurrent.TimeUnit;<br>
    <br>
    @BenchmarkMode(Mode.AverageTime)<br>
    @Fork(1)<br>
    @Warmup(iterations = 5)<br>
    @Measurement(iterations = 10)<br>
    @OutputTimeUnit(TimeUnit.NANOSECONDS)<br>
    public class BigIntegerBench {<br>
    <br>
        @Benchmark<br>
        public BigInteger ONE() {<br>
            return BigInteger.ONE;<br>
        }<br>
    <br>
        @Benchmark<br>
        public BigInteger valueOf_1() {<br>
            return BigInteger.valueOf(1);<br>
        }<br>
    <br>
        @Benchmark<br>
        public BigInteger valueOf_2() {<br>
            return BigInteger.valueOf(2);<br>
        }<br>
    }<br>
    <br>
    <br>
    So, no need to change the API and all uses of valueOf(-MAX_CONSTANT
    <= i <= MAX_CONSTANT) for constant 'i' will be faster a bit.<br>
    <br>
    Regards, Peter<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 03/23/2016 07:01 PM, Peter Levart
      wrote:<br>
    </div>
    <blockquote cite="mid:56F2D9E5.9050400@gmail.com" type="cite"><!--[if !IE]><DIV style="border-left: 2px solid #009900; border-right: 2px solid #009900;  padding: 0px 15px; margin: 2px 0px;"><![endif]-->
      <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
      Hi Xuelei,<br>
      <br>
      <div class="moz-cite-prefix">On 03/23/2016 04:26 AM, Xuelei Fan
        wrote:<br>
      </div>
      <blockquote cite="mid:56F20CEA.9030105@Oracle.COM" type="cite"><!--[if !IE]><DIV style="border-left: 2px solid #009900; border-right: 2px solid #009900;  padding: 0px 15px; margin: 2px 0px;"><![endif]--><!--[if !IE]><DIV style="border-left: 2px solid #009900; border-right: 2px solid #009900;  padding: 0px 15px; margin: 2px 0px;"><![endif]-->Hi,

        <br>
        <br>
        Please review the update for the supporting of BigInteger.TWO: <br>
        <br>
           <a moz-do-not-send="true" class="moz-txt-link-freetext"
          href="http://cr.openjdk.java.net/%7Exuelei/8152237/webrev/">http://cr.openjdk.java.net/~xuelei/8152237/webrev/</a>
        <br>
        <br>
        BigInteger.valueOf(2) is a common BigInteger value used in
        binary and cryptography operation calculation.  The
        BigInteger.TWO is not exported, and hence BigInteger.valueOf(2)
        is used instead in applications and JDK components.  The export
        of static BigInteger.TWO can improve performance and simplify
        existing code. <br>
        <br>
        Thanks, <br>
        Xuelei <br>
        <!--[if !IE]></DIV><![endif]--><!--[if !IE]></DIV><![endif]--></blockquote>
      <br>
      I think (haven't tried, just speculate) you could achieve the same
      performance by:<br>
      <br>
      - adding final qualifier to static BigInteger.[posConst|negConst]
      fields<br>
      - annotating those fields with @jdk.internal.vm.annotation.Stable
      annotation<br>
      <br>
      This way BigInteger.valueOf(-MAX_CONSTANT <= i <=
      MAX_CONSTANT) when called with a constant argument should fold
      into a constant when compiled by JIT.<br>
      <br>
      The same optimization could be performed for valueOf methods of
      java.lang.Byte, Character, Short, Integer & Long.<br>
      <br>
      @Stable annotation was a package-private annotation in
      java.lang.invoke, reserved for method handles infrastructure, but
      has since been made public and moved to a concealed package of
      java.base. There is already a precedent for its use outside in
      java.lang.invoke: in java.lang.String. For example:<br>
      <br>
      static final String s = ".....";<br>
      <br>
      s.charAt(0); // is folded into a constant by JIT<br>
      <br>
      <br>
      <br>
      Regards, Peter<br>
      <br>
      <!--[if !IE]></DIV><![endif]--></blockquote>
    <br>
  </body>
</html>