Skip to content

Commit 913e43f

Browse files
committed
8316582: Minor startup regression in 22-b15 due JDK-8310929
Reviewed-by: liach, rriggs
1 parent 23ed890 commit 913e43f

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/java.base/share/classes/java/lang/StringLatin1.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
import java.util.stream.StreamSupport;
3535
import jdk.internal.util.ArraysSupport;
3636
import jdk.internal.util.DecimalDigits;
37-
import jdk.internal.util.ByteArrayLittleEndian;
3837
import jdk.internal.vm.annotation.IntrinsicCandidate;
39-
import jdk.internal.vm.annotation.Stable;
4038

4139
import static java.lang.String.LATIN1;
4240
import static java.lang.String.UTF16;
@@ -100,7 +98,7 @@ public static byte[] inflate(byte[] value, int off, int len) {
10098
*/
10199
static int getChars(int i, int index, byte[] buf) {
102100
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
103-
int q, r;
101+
int q;
104102
int charPos = index;
105103

106104
boolean negative = i < 0;
@@ -111,16 +109,15 @@ static int getChars(int i, int index, byte[] buf) {
111109
// Generate two digits per iteration
112110
while (i <= -100) {
113111
q = i / 100;
114-
r = (q * 100) - i;
115-
i = q;
116112
charPos -= 2;
117-
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair(r));
113+
writeDigitPair(buf, charPos, (q * 100) - i);
114+
i = q;
118115
}
119116

120117
// We know there are at most two digits left at this point.
121118
if (i < -9) {
122119
charPos -= 2;
123-
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair(-i));
120+
writeDigitPair(buf, charPos, -i);
124121
} else {
125122
buf[--charPos] = (byte)('0' - i);
126123
}
@@ -162,7 +159,7 @@ static int getChars(long i, int index, byte[] buf) {
162159
while (i <= Integer.MIN_VALUE) {
163160
q = i / 100;
164161
charPos -= 2;
165-
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair((int)((q * 100) - i)));
162+
writeDigitPair(buf, charPos, (int)((q * 100) - i));
166163
i = q;
167164
}
168165

@@ -172,14 +169,14 @@ static int getChars(long i, int index, byte[] buf) {
172169
while (i2 <= -100) {
173170
q2 = i2 / 100;
174171
charPos -= 2;
175-
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair((q2 * 100) - i2));
172+
writeDigitPair(buf, charPos, (q2 * 100) - i2);
176173
i2 = q2;
177174
}
178175

179176
// We know there are at most two digits left at this point.
180177
if (i2 < -9) {
181178
charPos -= 2;
182-
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair(-i2));
179+
writeDigitPair(buf, charPos, -i2);
183180
} else {
184181
buf[--charPos] = (byte)('0' - i2);
185182
}
@@ -190,6 +187,12 @@ static int getChars(long i, int index, byte[] buf) {
190187
return charPos;
191188
}
192189

190+
private static void writeDigitPair(byte[] buf, int charPos, int value) {
191+
short pair = DecimalDigits.digitPair(value);
192+
buf[charPos] = (byte)(pair);
193+
buf[charPos + 1] = (byte)(pair >> 8);
194+
}
195+
193196
public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) {
194197
inflate(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
195198
}

src/java.base/share/classes/jdk/internal/util/DecimalDigits.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ public final class DecimalDigits implements Digits {
5757
* </pre>
5858
*/
5959
@Stable
60-
private static final short[] DIGITS = new short[] {
61-
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830, 0x3930,
62-
0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731, 0x3831, 0x3931,
63-
0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732, 0x3832, 0x3932,
64-
0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733, 0x3833, 0x3933,
65-
0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734, 0x3834, 0x3934,
66-
0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935,
67-
0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936,
68-
0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937,
69-
0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938,
70-
0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839, 0x3939
71-
};
60+
private static final short[] DIGITS;
61+
62+
static {
63+
short[] digits = new short[10 * 10];
64+
65+
for (int i = 0; i < 10; i++) {
66+
short hi = (short) (i + '0');
67+
for (int j = 0; j < 10; j++) {
68+
short lo = (short) ((j + '0') << 8);
69+
digits[i * 10 + j] = (short) (hi | lo);
70+
}
71+
}
72+
DIGITS = digits;
73+
}
7274

7375
/**
7476
* Singleton instance of DecimalDigits.

0 commit comments

Comments
 (0)