Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e7aca75
move getChars to DecimalDigits & deduplicate
wenshao Oct 19, 2024
2b7baad
add comments
wenshao Oct 20, 2024
7fbb399
remove unused code
wenshao Oct 20, 2024
fb6c741
remove JLA
wenshao Oct 20, 2024
fffa528
fix import
wenshao Oct 20, 2024
060893f
remove digitPair
wenshao Oct 20, 2024
4aa84d5
unsafe putByte
wenshao Oct 20, 2024
0484684
fix Helper
wenshao Oct 20, 2024
6324cf4
fix Helper
wenshao Oct 20, 2024
65dbe67
fix Helper
wenshao Oct 20, 2024
73b3200
Merge remote-tracking branch 'upstream/master' into int_get_chars_ded…
wenshao Nov 5, 2024
e97138d
remove comments, from @liach
wenshao Nov 6, 2024
cf947f6
add benchmark
wenshao Nov 10, 2024
cd9ba30
fix unsafe address overflow
wenshao Nov 11, 2024
ee05a6f
Merge remote-tracking branch 'upstream/master' into int_get_chars_ded…
wenshao Dec 6, 2024
efa6e6b
Merge remote-tracking branch 'upstream/master' into int_get_chars_ded…
wenshao Dec 8, 2024
a05c2f5
Merge remote-tracking branch 'upstream/master' into int_get_chars_ded…
wenshao Dec 9, 2024
72ff93f
form @cl4es
wenshao Dec 10, 2024
8122c1b
Merge remote-tracking branch 'upstream/master' into int_get_chars_ded…
wenshao Dec 11, 2024
1449959
fix comment, from @rgiulietti
wenshao Jan 17, 2025
3e23ab6
fix comment
wenshao Jan 18, 2025
7df0c8b
Coding style consistency, from rgiulietti
wenshao Jan 18, 2025
803a88a
fix benchmark, from rgiulietti
wenshao Jan 18, 2025
d3d9631
Coding style consistency, from rgiulietti
wenshao Jan 18, 2025
c8e4fe1
from rgiulietti
wenshao Jan 18, 2025
34bd9d4
bug fix
wenshao Jan 18, 2025
7eb89c9
use putCharUnaligned
wenshao Jan 19, 2025
960e279
fix comments
wenshao Jan 20, 2025
be1f88a
Merge remote-tracking branch 'upstream/master' into int_get_chars_ded…
wenshao Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,9 @@ public AbstractStringBuilder append(int i) {
int spaceNeeded = count + DecimalDigits.stringSize(i);
ensureCapacityInternal(spaceNeeded);
if (isLatin1()) {
StringLatin1.getChars(i, spaceNeeded, value);
DecimalDigits.getCharsLatin1(i, spaceNeeded, value);
} else {
StringUTF16.getChars(i, count, spaceNeeded, value);
DecimalDigits.getCharsUTF16(i, spaceNeeded, value);
}
this.count = spaceNeeded;
return this;
Expand All @@ -855,9 +855,9 @@ public AbstractStringBuilder append(long l) {
int spaceNeeded = count + DecimalDigits.stringSize(l);
ensureCapacityInternal(spaceNeeded);
if (isLatin1()) {
StringLatin1.getChars(l, spaceNeeded, value);
DecimalDigits.getCharsLatin1(l, spaceNeeded, value);
} else {
StringUTF16.getChars(l, count, spaceNeeded, value);
DecimalDigits.getCharsUTF16(l, spaceNeeded, value);
}
this.count = spaceNeeded;
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ public static String toString(int i) {
int size = DecimalDigits.stringSize(i);
if (COMPACT_STRINGS) {
byte[] buf = new byte[size];
StringLatin1.getChars(i, size, buf);
DecimalDigits.getCharsLatin1(i, size, buf);
return new String(buf, LATIN1);
} else {
byte[] buf = new byte[size * 2];
StringUTF16.getChars(i, size, buf);
DecimalDigits.getCharsUTF16(i, size, buf);
return new String(buf, UTF16);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Long.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ public static String toString(long i) {
int size = DecimalDigits.stringSize(i);
if (COMPACT_STRINGS) {
byte[] buf = new byte[size];
StringLatin1.getChars(i, size, buf);
DecimalDigits.getCharsLatin1(i, size, buf);
return new String(buf, LATIN1);
} else {
byte[] buf = new byte[size * 2];
StringUTF16.getChars(i, size, buf);
DecimalDigits.getCharsUTF16(i, size, buf);
return new String(buf, UTF16);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/java.base/share/classes/java/lang/StringConcatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ static long prepend(long indexCoder, byte[] buf, char value, String prefix) {
static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
int index = (int)indexCoder;
if (indexCoder < UTF16) {
index = StringLatin1.getChars(value, index, buf);
index = DecimalDigits.getCharsLatin1(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
index = StringUTF16.getChars(value, index, buf);
index = DecimalDigits.getCharsUTF16(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
Expand All @@ -324,12 +324,12 @@ static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
static long prepend(long indexCoder, byte[] buf, long value, String prefix) {
int index = (int)indexCoder;
if (indexCoder < UTF16) {
index = StringLatin1.getChars(value, index, buf);
index = DecimalDigits.getCharsLatin1(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
index = StringUTF16.getChars(value, index, buf);
index = DecimalDigits.getCharsUTF16(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
Expand Down Expand Up @@ -682,11 +682,11 @@ static int prepend(int index, byte coder, byte[] buf, char value, String prefix)
*/
static int prepend(int index, byte coder, byte[] buf, int value, String prefix) {
if (coder == String.LATIN1) {
index = StringLatin1.getChars(value, index, buf);
index = DecimalDigits.getCharsLatin1(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
} else {
index = StringUTF16.getChars(value, index, buf);
index = DecimalDigits.getCharsUTF16(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
}
Expand All @@ -706,11 +706,11 @@ static int prepend(int index, byte coder, byte[] buf, int value, String prefix)
*/
static int prepend(int index, byte coder, byte[] buf, long value, String prefix) {
if (coder == String.LATIN1) {
index = StringLatin1.getChars(value, index, buf);
index = DecimalDigits.getCharsLatin1(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
} else {
index = StringUTF16.getChars(value, index, buf);
index = DecimalDigits.getCharsUTF16(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
}
Expand Down
115 changes: 0 additions & 115 deletions src/java.base/share/classes/java/lang/StringLatin1.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.stream.StreamSupport;
import jdk.internal.misc.Unsafe;
import jdk.internal.util.ArraysSupport;
import jdk.internal.util.DecimalDigits;
import jdk.internal.vm.annotation.IntrinsicCandidate;

import static java.lang.String.LATIN1;
Expand Down Expand Up @@ -86,120 +85,6 @@ public static byte[] inflate(byte[] value, int off, int len) {
return ret;
}

/**
* Places characters representing the integer i into the
* character array buf. The characters are placed into
* the buffer backwards starting with the least significant
* digit at the specified index (exclusive), and working
* backwards from there.
*
* @implNote This method converts positive inputs into negative
* values, to cover the Integer.MIN_VALUE case. Converting otherwise
* (negative to positive) will expose -Integer.MIN_VALUE that overflows
* integer.
*
* @param i value to convert
* @param index next index, after the least significant digit
* @param buf target buffer, Latin1-encoded
* @return index of the most significant digit or minus sign, if present
*/
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;
int charPos = index;

boolean negative = i < 0;
if (!negative) {
i = -i;
}

// Generate two digits per iteration
while (i <= -100) {
q = i / 100;
charPos -= 2;
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;
writeDigitPair(buf, charPos, -i);
} else {
buf[--charPos] = (byte)('0' - i);
}

if (negative) {
buf[--charPos] = (byte)'-';
}
return charPos;
}

/**
* Places characters representing the long i into the
* character array buf. The characters are placed into
* the buffer backwards starting with the least significant
* digit at the specified index (exclusive), and working
* backwards from there.
*
* @implNote This method converts positive inputs into negative
* values, to cover the Long.MIN_VALUE case. Converting otherwise
* (negative to positive) will expose -Long.MIN_VALUE that overflows
* long.
*
* @param i value to convert
* @param index next index, after the least significant digit
* @param buf target buffer, Latin1-encoded
* @return index of the most significant digit or minus sign, if present
*/
static int getChars(long i, int index, byte[] buf) {
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
long q;
int charPos = index;

boolean negative = (i < 0);
if (!negative) {
i = -i;
}

// Get 2 digits/iteration using longs until quotient fits into an int
while (i <= Integer.MIN_VALUE) {
q = i / 100;
charPos -= 2;
writeDigitPair(buf, charPos, (int)((q * 100) - i));
i = q;
}

// Get 2 digits/iteration using ints
int q2;
int i2 = (int)i;
while (i2 <= -100) {
q2 = i2 / 100;
charPos -= 2;
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;
writeDigitPair(buf, charPos, -i2);
} else {
buf[--charPos] = (byte)('0' - i2);
}

if (negative) {
buf[--charPos] = (byte)'-';
}
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);
}
Expand Down
118 changes: 0 additions & 118 deletions src/java.base/share/classes/java/lang/StringUTF16.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import jdk.internal.misc.Unsafe;
import jdk.internal.util.ArraysSupport;
import jdk.internal.util.DecimalDigits;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.IntrinsicCandidate;

Expand Down Expand Up @@ -1513,20 +1512,6 @@ public static int codePointCountSB(byte[] val, int beginIndex, int endIndex) {
return codePointCount(val, beginIndex, endIndex, true /* checked */);
}

public static int getChars(int i, int begin, int end, byte[] value) {
checkBoundsBeginEnd(begin, end, value);
int pos = getChars(i, end, value);
assert begin == pos;
return pos;
}

public static int getChars(long l, int begin, int end, byte[] value) {
checkBoundsBeginEnd(begin, end, value);
int pos = getChars(l, end, value);
assert begin == pos;
return pos;
}

public static boolean contentEquals(byte[] v1, byte[] v2, int len) {
checkBoundsOffCount(0, len, v2);
for (int i = 0; i < len; i++) {
Expand Down Expand Up @@ -1662,109 +1647,6 @@ public static int lastIndexOfLatin1(byte[] src, int srcCount,

static final int MAX_LENGTH = Integer.MAX_VALUE >> 1;

// Used by trusted callers. Assumes all necessary bounds checks have
// been done by the caller.

/**
* This is a variant of {@link StringLatin1#getChars(int, int, byte[])}, but for
* UTF-16 coder.
*
* @param i value to convert
* @param index next index, after the least significant digit
* @param buf target buffer, UTF16-coded.
* @return index of the most significant digit or minus sign, if present
*/
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 charPos = index;

boolean negative = (i < 0);
if (!negative) {
i = -i;
}

// Get 2 digits/iteration using ints
while (i <= -100) {
q = i / 100;
r = (q * 100) - i;
i = q;
charPos -= 2;
putPair(buf, charPos, r);
}

// We know there are at most two digits left at this point.
if (i < -9) {
charPos -= 2;
putPair(buf, charPos, -i);
} else {
putChar(buf, --charPos, '0' - i);
}

if (negative) {
putChar(buf, --charPos, '-');
}
return charPos;
}

/**
* This is a variant of {@link StringLatin1#getChars(long, int, byte[])}, but for
* UTF-16 coder.
*
* @param i value to convert
* @param index next index, after the least significant digit
* @param buf target buffer, UTF16-coded.
* @return index of the most significant digit or minus sign, if present
*/
static int getChars(long i, int index, byte[] buf) {
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
long q;
int charPos = index;

boolean negative = (i < 0);
if (!negative) {
i = -i;
}

// Get 2 digits/iteration using longs until quotient fits into an int
while (i <= Integer.MIN_VALUE) {
q = i / 100;
charPos -= 2;
putPair(buf, charPos, (int)((q * 100) - i));
i = q;
}

// Get 2 digits/iteration using ints
int q2;
int i2 = (int)i;
while (i2 <= -100) {
q2 = i2 / 100;
charPos -= 2;
putPair(buf, charPos, (q2 * 100) - i2);
i2 = q2;
}

// We know there are at most two digits left at this point.
if (i2 < -9) {
charPos -= 2;
putPair(buf, charPos, -i2);
} else {
putChar(buf, --charPos, '0' - i2);
}

if (negative) {
putChar(buf, --charPos, '-');
}
return charPos;
}

private static void putPair(byte[] buf, int charPos, int v) {
int packed = (int) DecimalDigits.digitPair(v);
putChar(buf, charPos, packed & 0xFF);
putChar(buf, charPos + 1, packed >> 8);
}
// End of trusted methods.

public static void checkIndex(int off, byte[] val) {
String.checkIndex(off, length(val));
}
Expand Down
8 changes: 0 additions & 8 deletions src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -2179,14 +2179,6 @@ public byte stringCoder(String str) {
return str.coder();
}

public int getCharsLatin1(long i, int index, byte[] buf) {
return StringLatin1.getChars(i, index, buf);
}

public int getCharsUTF16(long i, int index, byte[] buf) {
return StringUTF16.getChars(i, index, buf);
}

public String join(String prefix, String suffix, String delimiter, String[] elements, int size) {
return String.join(prefix, suffix, delimiter, elements, size);
}
Expand Down
Loading