<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">
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]-->Hi,
<br>
<br>
Please review the update for the supporting of BigInteger.TWO:
<br>
<br>
<a class="moz-txt-link-freetext" href="http://cr.openjdk.java.net/~xuelei/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]--></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>
</body>
</html>