8316582: Minor startup regression in 22-b15 due JDK-8310929

Reviewed-by: liach, rriggs
This commit is contained in:
Claes Redestad 2023-09-21 09:36:28 +00:00
parent 23ed890f3f
commit 913e43fea9
2 changed files with 27 additions and 22 deletions
src/java.base/share/classes
java/lang
jdk/internal/util

@ -34,9 +34,7 @@ import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import jdk.internal.util.ArraysSupport;
import jdk.internal.util.DecimalDigits;
import jdk.internal.util.ByteArrayLittleEndian;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.vm.annotation.Stable;
import static java.lang.String.LATIN1;
import static java.lang.String.UTF16;
@ -100,7 +98,7 @@ final class StringLatin1 {
*/
static int getChars(int i, int index, byte[] buf) {
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
int q, r;
int q;
int charPos = index;
boolean negative = i < 0;
@ -111,16 +109,15 @@ final class StringLatin1 {
// Generate two digits per iteration
while (i <= -100) {
q = i / 100;
r = (q * 100) - i;
i = q;
charPos -= 2;
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair(r));
writeDigitPair(buf, charPos, (q * 100) - i);
i = q;
}
// We know there are at most two digits left at this point.
if (i < -9) {
charPos -= 2;
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair(-i));
writeDigitPair(buf, charPos, -i);
} else {
buf[--charPos] = (byte)('0' - i);
}
@ -162,7 +159,7 @@ final class StringLatin1 {
while (i <= Integer.MIN_VALUE) {
q = i / 100;
charPos -= 2;
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair((int)((q * 100) - i)));
writeDigitPair(buf, charPos, (int)((q * 100) - i));
i = q;
}
@ -172,14 +169,14 @@ final class StringLatin1 {
while (i2 <= -100) {
q2 = i2 / 100;
charPos -= 2;
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair((q2 * 100) - i2));
writeDigitPair(buf, charPos, (q2 * 100) - i2);
i2 = q2;
}
// We know there are at most two digits left at this point.
if (i2 < -9) {
charPos -= 2;
ByteArrayLittleEndian.setShort(buf, charPos, DecimalDigits.digitPair(-i2));
writeDigitPair(buf, charPos, -i2);
} else {
buf[--charPos] = (byte)('0' - i2);
}
@ -190,6 +187,12 @@ final class StringLatin1 {
return charPos;
}
private static void writeDigitPair(byte[] buf, int charPos, int value) {
short pair = DecimalDigits.digitPair(value);
buf[charPos] = (byte)(pair);
buf[charPos + 1] = (byte)(pair >> 8);
}
public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) {
inflate(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
}

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