Skip to content

Commit 99bf89c

Browse files
committed
8228507: Archive FDBigInteger
Reviewed-by: jiangli, bpb
1 parent 85dbabe commit 99bf89c

File tree

4 files changed

+98
-84
lines changed

4 files changed

+98
-84
lines changed

make/jdk/src/classes/build/tools/classlist/HelloClasslist.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public static void main(String ... args) {
8787
String CICI = "string" + args.length + "string" + args.length;
8888
String CJ = "string" + System.currentTimeMillis();
8989
String JC = System.currentTimeMillis() + "string";
90+
String CD = "string" + (args.length/2.0);
9091
String CJC = "string" + System.currentTimeMillis() + "string";
9192
String CJCJ = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis();
9293
String CJCJC = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis() + "string";

src/hotspot/share/memory/heapShared.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static ArchivableStaticFieldInfo open_archive_subgraph_entry_fields[] = {
7979
{"java/util/ImmutableCollections$MapN", "EMPTY_MAP"},
8080
{"java/util/ImmutableCollections$SetN", "EMPTY_SET"},
8181
{"java/lang/module/Configuration", "EMPTY_CONFIGURATION"},
82+
{"jdk/internal/math/FDBigInteger", "archivedCaches"},
8283
};
8384

8485
const static int num_closed_archive_subgraph_entry_fields =

src/java.base/share/classes/jdk/internal/math/FDBigInteger.java

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package jdk.internal.math;
2626

27+
import jdk.internal.misc.VM;
28+
2729
import java.math.BigInteger;
2830
import java.util.Arrays;
2931
//@ model import org.jmlspecs.models.JMLMath;
@@ -64,83 +66,94 @@
6466
@ }
6567
@*/
6668

67-
static final int[] SMALL_5_POW = {
68-
1,
69-
5,
70-
5 * 5,
71-
5 * 5 * 5,
72-
5 * 5 * 5 * 5,
73-
5 * 5 * 5 * 5 * 5,
74-
5 * 5 * 5 * 5 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 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
104-
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
105-
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
106-
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
107-
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
108-
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
109-
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
110-
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,
111-
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,
112-
};
71+
static final long[] LONG_5_POW;
11372

11473
// Maximum size of cache of powers of 5 as FDBigIntegers.
11574
private static final int MAX_FIVE_POW = 340;
11675

11776
// Cache of big powers of 5 as FDBigIntegers.
11877
private static final FDBigInteger POW_5_CACHE[];
11978

120-
// Initialize FDBigInteger cache of powers of 5.
121-
static {
122-
POW_5_CACHE = new FDBigInteger[MAX_FIVE_POW];
123-
int i = 0;
124-
while (i < SMALL_5_POW.length) {
125-
FDBigInteger pow5 = new FDBigInteger(new int[]{SMALL_5_POW[i]}, 0);
126-
pow5.makeImmutable();
127-
POW_5_CACHE[i] = pow5;
128-
i++;
129-
}
130-
FDBigInteger prev = POW_5_CACHE[i - 1];
131-
while (i < MAX_FIVE_POW) {
132-
POW_5_CACHE[i] = prev = prev.mult(5);
133-
prev.makeImmutable();
134-
i++;
135-
}
136-
}
137-
13879
// Zero as an FDBigInteger.
139-
public static final FDBigInteger ZERO = new FDBigInteger(new int[0], 0);
80+
public static final FDBigInteger ZERO;
81+
82+
// Archive proxy
83+
private static Object[] archivedCaches;
14084

141-
// Ensure ZERO is immutable.
85+
// Initialize FDBigInteger cache of powers of 5.
14286
static {
143-
ZERO.makeImmutable();
87+
VM.initializeFromArchive(FDBigInteger.class);
88+
Object[] caches = archivedCaches;
89+
if (caches == null) {
90+
long[] long5pow = {
91+
1L,
92+
5L,
93+
5L * 5,
94+
5L * 5 * 5,
95+
5L * 5 * 5 * 5,
96+
5L * 5 * 5 * 5 * 5,
97+
5L * 5 * 5 * 5 * 5 * 5,
98+
5L * 5 * 5 * 5 * 5 * 5 * 5,
99+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5,
100+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
101+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
102+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
103+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
104+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
105+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
106+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
107+
5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 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5 * 5 * 5,
128+
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
129+
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
130+
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
131+
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
132+
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
133+
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5
134+
};
135+
FDBigInteger[] pow5cache = new FDBigInteger[MAX_FIVE_POW];
136+
int i = 0;
137+
while (i < small5pow.length) {
138+
FDBigInteger pow5 = new FDBigInteger(new int[] { small5pow[i] }, 0);
139+
pow5.makeImmutable();
140+
pow5cache[i] = pow5;
141+
i++;
142+
}
143+
FDBigInteger prev = pow5cache[i - 1];
144+
while (i < MAX_FIVE_POW) {
145+
pow5cache[i] = prev = prev.mult(5);
146+
prev.makeImmutable();
147+
i++;
148+
}
149+
FDBigInteger zero = new FDBigInteger(new int[0], 0);
150+
zero.makeImmutable();
151+
archivedCaches = caches = new Object[] {small5pow, long5pow, pow5cache, zero};
152+
}
153+
SMALL_5_POW = (int[])caches[0];
154+
LONG_5_POW = (long[])caches[1];
155+
POW_5_CACHE = (FDBigInteger[])caches[2];
156+
ZERO = (FDBigInteger)caches[3];
144157
}
145158

146159
// Constant for casting an int to a long via bitwise AND.

src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,55 +131,55 @@ public interface BinaryToASCIIConverter {
131131
* Converts a floating point value into an ASCII <code>String</code>.
132132
* @return The value converted to a <code>String</code>.
133133
*/
134-
public String toJavaFormatString();
134+
String toJavaFormatString();
135135

136136
/**
137137
* Appends a floating point value to an <code>Appendable</code>.
138138
* @param buf The <code>Appendable</code> to receive the value.
139139
*/
140-
public void appendTo(Appendable buf);
140+
void appendTo(Appendable buf);
141141

142142
/**
143143
* Retrieves the decimal exponent most closely corresponding to this value.
144144
* @return The decimal exponent.
145145
*/
146-
public int getDecimalExponent();
146+
int getDecimalExponent();
147147

148148
/**
149149
* Retrieves the value as an array of digits.
150150
* @param digits The digit array.
151151
* @return The number of valid digits copied into the array.
152152
*/
153-
public int getDigits(char[] digits);
153+
int getDigits(char[] digits);
154154

155155
/**
156156
* Indicates the sign of the value.
157157
* @return {@code value < 0.0}.
158158
*/
159-
public boolean isNegative();
159+
boolean isNegative();
160160

161161
/**
162162
* Indicates whether the value is either infinite or not a number.
163163
*
164164
* @return <code>true</code> if and only if the value is <code>NaN</code>
165165
* or infinite.
166166
*/
167-
public boolean isExceptional();
167+
boolean isExceptional();
168168

169169
/**
170170
* Indicates whether the value was rounded up during the binary to ASCII
171171
* conversion.
172172
*
173173
* @return <code>true</code> if and only if the value was rounded up.
174174
*/
175-
public boolean digitsRoundedUp();
175+
boolean digitsRoundedUp();
176176

177177
/**
178178
* Indicates whether the binary to ASCII conversion was exact.
179179
*
180180
* @return <code>true</code> if any only if the conversion was exact.
181181
*/
182-
public boolean decimalDigitsExact();
182+
boolean decimalDigitsExact();
183183
}
184184

185185
/**
@@ -321,7 +321,7 @@ public int getDecimalExponent() {
321321

322322
@Override
323323
public int getDigits(char[] digits) {
324-
System.arraycopy(this.digits,firstDigitIndex,digits,0,this.nDigits);
324+
System.arraycopy(this.digits, firstDigitIndex, digits, 0, this.nDigits);
325325
return this.nDigits;
326326
}
327327

@@ -849,7 +849,7 @@ private static int insignificantDigits(int insignificant) {
849849
* </pre>
850850
*/
851851
private static int insignificantDigitsForPow2(int p2) {
852-
if(p2>1 && p2 < insignificantDigitsNumber.length) {
852+
if (p2 > 1 && p2 < insignificantDigitsNumber.length) {
853853
return insignificantDigitsNumber[p2];
854854
}
855855
return 0;
@@ -862,7 +862,7 @@ private static int insignificantDigitsForPow2(int p2) {
862862
* for ( i = 0; insignificant >= 10L; i++ )
863863
* insignificant /= 10L;
864864
*/
865-
private static int[] insignificantDigitsNumber = {
865+
private static final int[] insignificantDigitsNumber = {
866866
0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3,
867867
4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
868868
8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11,
@@ -1873,11 +1873,11 @@ static ASCIIToBinaryConverter readJavaFormatString( String in ) throws NumberFor
18731873
} // look for and process decimal floating-point string
18741874

18751875
char[] digits = new char[ len ];
1876-
int nDigits= 0;
18771876
boolean decSeen = false;
1877+
int nDigits = 0;
18781878
int decPt = 0;
18791879
int nLeadZero = 0;
1880-
int nTrailZero= 0;
1880+
int nTrailZero = 0;
18811881

18821882
skipLeadingZerosLoop:
18831883
while (i < len) {
@@ -2137,9 +2137,9 @@ static ASCIIToBinaryConverter parseHexString(String s) {
21372137
// signed zero.
21382138
//
21392139

2140-
String significandString = null;
2141-
int signifLength = 0;
2142-
int exponentAdjust = 0;
2140+
String significandString;
2141+
int signifLength;
2142+
int exponentAdjust;
21432143
{
21442144
int leftDigits = 0; // number of meaningful digits to
21452145
// left of "decimal" point
@@ -2246,7 +2246,7 @@ static ASCIIToBinaryConverter parseHexString(String s) {
22462246

22472247
boolean round = false;
22482248
boolean sticky = false;
2249-
int nextShift = 0;
2249+
int nextShift;
22502250
long significand = 0L;
22512251
// First iteration is different, since we only copy
22522252
// from the leading significand bit; one more exponent
@@ -2525,7 +2525,6 @@ static ASCIIToBinaryConverter parseHexString(String s) {
25252525
* Returns <code>s</code> with any leading zeros removed.
25262526
*/
25272527
static String stripLeadingZeros(String s) {
2528-
// return s.replaceFirst("^0+", "");
25292528
if(!s.isEmpty() && s.charAt(0)=='0') {
25302529
for(int i=1; i<s.length(); i++) {
25312530
if(s.charAt(i)!='0') {

0 commit comments

Comments
 (0)