8228507: Archive FDBigInteger

Reviewed-by: jiangli, bpb
This commit is contained in:
Claes Redestad 2019-08-27 22:26:42 +02:00
parent 85dbabe345
commit 99bf89c581
4 changed files with 98 additions and 84 deletions

View File

@ -87,6 +87,7 @@ public class HelloClasslist {
String CICI = "string" + args.length + "string" + args.length; String CICI = "string" + args.length + "string" + args.length;
String CJ = "string" + System.currentTimeMillis(); String CJ = "string" + System.currentTimeMillis();
String JC = System.currentTimeMillis() + "string"; String JC = System.currentTimeMillis() + "string";
String CD = "string" + (args.length/2.0);
String CJC = "string" + System.currentTimeMillis() + "string"; String CJC = "string" + System.currentTimeMillis() + "string";
String CJCJ = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis(); String CJCJ = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis();
String CJCJC = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis() + "string"; String CJCJC = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis() + "string";

View File

@ -79,6 +79,7 @@ static ArchivableStaticFieldInfo open_archive_subgraph_entry_fields[] = {
{"java/util/ImmutableCollections$MapN", "EMPTY_MAP"}, {"java/util/ImmutableCollections$MapN", "EMPTY_MAP"},
{"java/util/ImmutableCollections$SetN", "EMPTY_SET"}, {"java/util/ImmutableCollections$SetN", "EMPTY_SET"},
{"java/lang/module/Configuration", "EMPTY_CONFIGURATION"}, {"java/lang/module/Configuration", "EMPTY_CONFIGURATION"},
{"jdk/internal/math/FDBigInteger", "archivedCaches"},
}; };
const static int num_closed_archive_subgraph_entry_fields = const static int num_closed_archive_subgraph_entry_fields =

View File

@ -24,6 +24,8 @@
*/ */
package jdk.internal.math; package jdk.internal.math;
import jdk.internal.misc.VM;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Arrays; import java.util.Arrays;
//@ model import org.jmlspecs.models.JMLMath; //@ model import org.jmlspecs.models.JMLMath;
@ -64,52 +66,9 @@ public /*@ spec_bigint_math @*/ class FDBigInteger {
@ } @ }
@*/ @*/
static final int[] S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 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
};
// Maximum size of cache of powers of 5 as FDBigIntegers. // Maximum size of cache of powers of 5 as FDBigIntegers.
private static final int MAX_FIVE_POW = 340; private static final int MAX_FIVE_POW = 340;
@ -117,30 +76,84 @@ public /*@ spec_bigint_math @*/ class FDBigInteger {
// Cache of big powers of 5 as FDBigIntegers. // Cache of big powers of 5 as FDBigIntegers.
private static final FDBigInteger POW_5_CACHE[]; private static final FDBigInteger POW_5_CACHE[];
// Zero as an FDBigInteger.
public static final FDBigInteger ZERO;
// Archive proxy
private static Object[] archivedCaches;
// Initialize FDBigInteger cache of powers of 5. // Initialize FDBigInteger cache of powers of 5.
static { static {
POW_5_CACHE = new FDBigInteger[MAX_FIVE_POW]; VM.initializeFromArchive(FDBigInteger.class);
int i = 0; Object[] caches = archivedCaches;
while (i < SMALL_5_POW.length) { if (caches == null) {
FDBigInteger pow5 = new FDBigInteger(new int[]{SMALL_5_POW[i]}, 0); long[] long5pow = {
pow5.makeImmutable(); 1L,
POW_5_CACHE[i] = pow5; 5L,
i++; 5L * 5,
5L * 5 * 5,
5L * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
5L * 5 * 5 * 5 * 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
int i = 0;
while (i < small5pow.length) {
FDBigInteger pow5 = new FDBigInteger(new int[] { small5pow[i] }, 0);
pow5.makeImmutable();
pow5cache[i] = pow5;
i++;
}
FDBigInteger prev = pow5cache[i - 1];
while (i < MAX_FIVE_POW) {
pow5cache[i] = prev = prev.mult(5);
prev.makeImmutable();
i++;
}
FDBigInteger zero = new FDBigInteger(new int[0], 0);
zero.makeImmutable();
archivedCaches = caches = new Object[] {small5pow, long5pow, pow5cache, zero};
} }
FDBigInteger prev = POW_5_CACHE[i - 1]; SMALL_5_POW = (int[])caches[0];
while (i < MAX_FIVE_POW) { LONG_5_POW = (long[])caches[1];
POW_5_CACHE[i] = prev = prev.mult(5); POW_5_CACHE = (FDBigInteger[])caches[2];
prev.makeImmutable(); ZERO = (FDBigInteger)caches[3];
i++;
}
}
// Zero as an FDBigInteger.
public static final FDBigInteger ZERO = new FDBigInteger(new int[0], 0);
// Ensure ZERO is immutable.
static {
ZERO.makeImmutable();
} }
// Constant for casting an int to a long via bitwise AND. // Constant for casting an int to a long via bitwise AND.

View File

@ -131,32 +131,32 @@ public class FloatingDecimal{
* Converts a floating point value into an ASCII <code>String</code>. * Converts a floating point value into an ASCII <code>String</code>.
* @return The value converted to a <code>String</code>. * @return The value converted to a <code>String</code>.
*/ */
public String toJavaFormatString(); String toJavaFormatString();
/** /**
* Appends a floating point value to an <code>Appendable</code>. * Appends a floating point value to an <code>Appendable</code>.
* @param buf The <code>Appendable</code> to receive the value. * @param buf The <code>Appendable</code> to receive the value.
*/ */
public void appendTo(Appendable buf); void appendTo(Appendable buf);
/** /**
* Retrieves the decimal exponent most closely corresponding to this value. * Retrieves the decimal exponent most closely corresponding to this value.
* @return The decimal exponent. * @return The decimal exponent.
*/ */
public int getDecimalExponent(); int getDecimalExponent();
/** /**
* Retrieves the value as an array of digits. * Retrieves the value as an array of digits.
* @param digits The digit array. * @param digits The digit array.
* @return The number of valid digits copied into the array. * @return The number of valid digits copied into the array.
*/ */
public int getDigits(char[] digits); int getDigits(char[] digits);
/** /**
* Indicates the sign of the value. * Indicates the sign of the value.
* @return {@code value < 0.0}. * @return {@code value < 0.0}.
*/ */
public boolean isNegative(); boolean isNegative();
/** /**
* Indicates whether the value is either infinite or not a number. * Indicates whether the value is either infinite or not a number.
@ -164,7 +164,7 @@ public class FloatingDecimal{
* @return <code>true</code> if and only if the value is <code>NaN</code> * @return <code>true</code> if and only if the value is <code>NaN</code>
* or infinite. * or infinite.
*/ */
public boolean isExceptional(); boolean isExceptional();
/** /**
* Indicates whether the value was rounded up during the binary to ASCII * Indicates whether the value was rounded up during the binary to ASCII
@ -172,14 +172,14 @@ public class FloatingDecimal{
* *
* @return <code>true</code> if and only if the value was rounded up. * @return <code>true</code> if and only if the value was rounded up.
*/ */
public boolean digitsRoundedUp(); boolean digitsRoundedUp();
/** /**
* Indicates whether the binary to ASCII conversion was exact. * Indicates whether the binary to ASCII conversion was exact.
* *
* @return <code>true</code> if any only if the conversion was exact. * @return <code>true</code> if any only if the conversion was exact.
*/ */
public boolean decimalDigitsExact(); boolean decimalDigitsExact();
} }
/** /**
@ -321,7 +321,7 @@ public class FloatingDecimal{
@Override @Override
public int getDigits(char[] digits) { public int getDigits(char[] digits) {
System.arraycopy(this.digits,firstDigitIndex,digits,0,this.nDigits); System.arraycopy(this.digits, firstDigitIndex, digits, 0, this.nDigits);
return this.nDigits; return this.nDigits;
} }
@ -849,7 +849,7 @@ public class FloatingDecimal{
* </pre> * </pre>
*/ */
private static int insignificantDigitsForPow2(int p2) { private static int insignificantDigitsForPow2(int p2) {
if(p2>1 && p2 < insignificantDigitsNumber.length) { if (p2 > 1 && p2 < insignificantDigitsNumber.length) {
return insignificantDigitsNumber[p2]; return insignificantDigitsNumber[p2];
} }
return 0; return 0;
@ -862,7 +862,7 @@ public class FloatingDecimal{
* for ( i = 0; insignificant >= 10L; i++ ) * for ( i = 0; insignificant >= 10L; i++ )
* insignificant /= 10L; * insignificant /= 10L;
*/ */
private static int[] insignificantDigitsNumber = { private static final int[] insignificantDigitsNumber = {
0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3,
4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11,
@ -1873,11 +1873,11 @@ public class FloatingDecimal{
} // look for and process decimal floating-point string } // look for and process decimal floating-point string
char[] digits = new char[ len ]; char[] digits = new char[ len ];
int nDigits= 0;
boolean decSeen = false; boolean decSeen = false;
int nDigits = 0;
int decPt = 0; int decPt = 0;
int nLeadZero = 0; int nLeadZero = 0;
int nTrailZero= 0; int nTrailZero = 0;
skipLeadingZerosLoop: skipLeadingZerosLoop:
while (i < len) { while (i < len) {
@ -2137,9 +2137,9 @@ public class FloatingDecimal{
// signed zero. // signed zero.
// //
String significandString = null; String significandString;
int signifLength = 0; int signifLength;
int exponentAdjust = 0; int exponentAdjust;
{ {
int leftDigits = 0; // number of meaningful digits to int leftDigits = 0; // number of meaningful digits to
// left of "decimal" point // left of "decimal" point
@ -2246,7 +2246,7 @@ public class FloatingDecimal{
boolean round = false; boolean round = false;
boolean sticky = false; boolean sticky = false;
int nextShift = 0; int nextShift;
long significand = 0L; long significand = 0L;
// First iteration is different, since we only copy // First iteration is different, since we only copy
// from the leading significand bit; one more exponent // from the leading significand bit; one more exponent
@ -2525,7 +2525,6 @@ public class FloatingDecimal{
* Returns <code>s</code> with any leading zeros removed. * Returns <code>s</code> with any leading zeros removed.
*/ */
static String stripLeadingZeros(String s) { static String stripLeadingZeros(String s) {
// return s.replaceFirst("^0+", "");
if(!s.isEmpty() && s.charAt(0)=='0') { if(!s.isEmpty() && s.charAt(0)=='0') {
for(int i=1; i<s.length(); i++) { for(int i=1; i<s.length(); i++) {
if(s.charAt(i)!='0') { if(s.charAt(i)!='0') {