Code Review Request, 8152237 Support BigInteger.TWO
peter.levart at gmail.com
Wed Mar 23 18:01:09 UTC 2016
On 03/23/2016 04:26 AM, Xuelei Fan wrote:
> Please review the update for the supporting of BigInteger.TWO:
> 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.
I think (haven't tried, just speculate) you could achieve the same
- adding final qualifier to static BigInteger.[posConst|negConst] fields
- annotating those fields with @jdk.internal.vm.annotation.Stable annotation
This way BigInteger.valueOf(-MAX_CONSTANT <= i <= MAX_CONSTANT) when
called with a constant argument should fold into a constant when
compiled by JIT.
The same optimization could be performed for valueOf methods of
java.lang.Byte, Character, Short, Integer & Long.
@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.
static final String s = ".....";
s.charAt(0); // is folded into a constant by JIT
More information about the core-libs-dev