Skip to content

Commit 66f71c5

Browse files
committed
Document preconditions for DecimalDigits methods
1 parent 5e50a58 commit 66f71c5

File tree

7 files changed

+53
-53
lines changed

7 files changed

+53
-53
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,9 @@ public AbstractStringBuilder append(int i) {
924924
int spaceNeeded = count + DecimalDigits.stringSize(i);
925925
byte[] value = ensureCapacitySameCoder(this.value, coder, spaceNeeded);
926926
if (isLatin1(coder)) {
927-
DecimalDigits.getCharsLatin1(i, spaceNeeded, value);
927+
DecimalDigits.uncheckedGetCharsLatin1(i, spaceNeeded, value);
928928
} else {
929-
DecimalDigits.getCharsUTF16(i, spaceNeeded, value);
929+
DecimalDigits.uncheckedGetCharsUTF16(i, spaceNeeded, value);
930930
}
931931
this.value = value;
932932
this.count = spaceNeeded;
@@ -951,9 +951,9 @@ public AbstractStringBuilder append(long l) {
951951
int spaceNeeded = count + DecimalDigits.stringSize(l);
952952
byte[] value = ensureCapacitySameCoder(this.value, coder, spaceNeeded);
953953
if (isLatin1(coder)) {
954-
DecimalDigits.getCharsLatin1(l, spaceNeeded, value);
954+
DecimalDigits.uncheckedGetCharsLatin1(l, spaceNeeded, value);
955955
} else {
956-
DecimalDigits.getCharsUTF16(l, spaceNeeded, value);
956+
DecimalDigits.uncheckedGetCharsUTF16(l, spaceNeeded, value);
957957
}
958958
this.value = value;
959959
this.count = spaceNeeded;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ public static String toString(int i) {
432432
int size = DecimalDigits.stringSize(i);
433433
if (COMPACT_STRINGS) {
434434
byte[] buf = new byte[size];
435-
DecimalDigits.getCharsLatin1(i, size, buf);
435+
DecimalDigits.uncheckedGetCharsLatin1(i, size, buf);
436436
return new String(buf, LATIN1);
437437
} else {
438438
byte[] buf = new byte[size * 2];
439-
DecimalDigits.getCharsUTF16(i, size, buf);
439+
DecimalDigits.uncheckedGetCharsUTF16(i, size, buf);
440440
return new String(buf, UTF16);
441441
}
442442
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ public static String toString(long i) {
462462
int size = DecimalDigits.stringSize(i);
463463
if (COMPACT_STRINGS) {
464464
byte[] buf = new byte[size];
465-
DecimalDigits.getCharsLatin1(i, size, buf);
465+
DecimalDigits.uncheckedGetCharsLatin1(i, size, buf);
466466
return new String(buf, LATIN1);
467467
} else {
468468
byte[] buf = new byte[size * 2];
469-
DecimalDigits.getCharsUTF16(i, size, buf);
469+
DecimalDigits.uncheckedGetCharsUTF16(i, size, buf);
470470
return new String(buf, UTF16);
471471
}
472472
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ static long prepend(long indexCoder, byte[] buf, char value, String prefix) {
315315
static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
316316
int index = (int)indexCoder;
317317
if (indexCoder < UTF16) {
318-
index = DecimalDigits.getCharsLatin1(value, index, buf);
318+
index = DecimalDigits.uncheckedGetCharsLatin1(value, index, buf);
319319
index -= prefix.length();
320320
prefix.getBytes(buf, index, String.LATIN1);
321321
return index;
322322
} else {
323-
index = DecimalDigits.getCharsUTF16(value, index, buf);
323+
index = DecimalDigits.uncheckedGetCharsUTF16(value, index, buf);
324324
index -= prefix.length();
325325
prefix.getBytes(buf, index, String.UTF16);
326326
return index | UTF16;
@@ -341,12 +341,12 @@ static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
341341
static long prepend(long indexCoder, byte[] buf, long value, String prefix) {
342342
int index = (int)indexCoder;
343343
if (indexCoder < UTF16) {
344-
index = DecimalDigits.getCharsLatin1(value, index, buf);
344+
index = DecimalDigits.uncheckedGetCharsLatin1(value, index, buf);
345345
index -= prefix.length();
346346
prefix.getBytes(buf, index, String.LATIN1);
347347
return index;
348348
} else {
349-
index = DecimalDigits.getCharsUTF16(value, index, buf);
349+
index = DecimalDigits.uncheckedGetCharsUTF16(value, index, buf);
350350
index -= prefix.length();
351351
prefix.getBytes(buf, index, String.UTF16);
352352
return index | UTF16;
@@ -713,11 +713,11 @@ static int prepend(int index, byte coder, byte[] buf, char value, String prefix)
713713
*/
714714
static int prepend(int index, byte coder, byte[] buf, int value, String prefix) {
715715
if (coder == String.LATIN1) {
716-
index = DecimalDigits.getCharsLatin1(value, index, buf);
716+
index = DecimalDigits.uncheckedGetCharsLatin1(value, index, buf);
717717
index -= prefix.length();
718718
prefix.getBytes(buf, index, String.LATIN1);
719719
} else {
720-
index = DecimalDigits.getCharsUTF16(value, index, buf);
720+
index = DecimalDigits.uncheckedGetCharsUTF16(value, index, buf);
721721
index -= prefix.length();
722722
prefix.getBytes(buf, index, String.UTF16);
723723
}
@@ -737,11 +737,11 @@ static int prepend(int index, byte coder, byte[] buf, int value, String prefix)
737737
*/
738738
static int prepend(int index, byte coder, byte[] buf, long value, String prefix) {
739739
if (coder == String.LATIN1) {
740-
index = DecimalDigits.getCharsLatin1(value, index, buf);
740+
index = DecimalDigits.uncheckedGetCharsLatin1(value, index, buf);
741741
index -= prefix.length();
742742
prefix.getBytes(buf, index, String.LATIN1);
743743
} else {
744-
index = DecimalDigits.getCharsUTF16(value, index, buf);
744+
index = DecimalDigits.uncheckedGetCharsUTF16(value, index, buf);
745745
index -= prefix.length();
746746
prefix.getBytes(buf, index, String.UTF16);
747747
}

src/java.base/share/classes/java/math/BigDecimal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,9 +4138,9 @@ private String layoutChars(boolean sci) {
41384138
int highInt = (int)intCompact / 100;
41394139
int highIntSize = DecimalDigits.stringSize(highInt);
41404140
byte[] buf = new byte[highIntSize + 3];
4141-
DecimalDigits.getCharsLatin1(highInt, highIntSize, buf);
4141+
DecimalDigits.uncheckedGetCharsLatin1(highInt, highIntSize, buf);
41424142
buf[highIntSize] = '.';
4143-
DecimalDigits.putPairLatin1(buf, highIntSize + 1, lowInt);
4143+
DecimalDigits.uncheckedPutPairLatin1(buf, highIntSize + 1, lowInt);
41444144
try {
41454145
return JLA.newStringNoRepl(buf, StandardCharsets.ISO_8859_1);
41464146
} catch (CharacterCodingException cce) {

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static int stringSize(long x) {
149149
* @param buf target buffer, Latin1-encoded
150150
* @return index of the most significant digit or minus sign, if present
151151
*/
152-
public static int getCharsLatin1(int i, int index, byte[] buf) {
152+
public static int uncheckedGetCharsLatin1(int i, int index, byte[] buf) {
153153
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
154154
int q;
155155
int charPos = index;
@@ -163,20 +163,20 @@ public static int getCharsLatin1(int i, int index, byte[] buf) {
163163
while (i <= -100) {
164164
q = i / 100;
165165
charPos -= 2;
166-
putPairLatin1(buf, charPos, (q * 100) - i);
166+
uncheckedPutPairLatin1(buf, charPos, (q * 100) - i);
167167
i = q;
168168
}
169169

170170
// We know there are at most two digits left at this point.
171171
if (i <= -10) {
172172
charPos -= 2;
173-
putPairLatin1(buf, charPos, -i);
173+
uncheckedPutPairLatin1(buf, charPos, -i);
174174
} else {
175-
putCharLatin1(buf, --charPos, '0' - i);
175+
uncheckedPutCharLatin1(buf, --charPos, '0' - i);
176176
}
177177

178178
if (negative) {
179-
putCharLatin1(buf, --charPos, '-');
179+
uncheckedPutCharLatin1(buf, --charPos, '-');
180180
}
181181
return charPos;
182182
}
@@ -199,7 +199,7 @@ public static int getCharsLatin1(int i, int index, byte[] buf) {
199199
* @param buf target buffer, Latin1-encoded
200200
* @return index of the most significant digit or minus sign, if present
201201
*/
202-
public static int getCharsLatin1(long i, int index, byte[] buf) {
202+
public static int uncheckedGetCharsLatin1(long i, int index, byte[] buf) {
203203
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
204204
long q;
205205
int charPos = index;
@@ -213,7 +213,7 @@ public static int getCharsLatin1(long i, int index, byte[] buf) {
213213
while (i < Integer.MIN_VALUE) {
214214
q = i / 100;
215215
charPos -= 2;
216-
putPairLatin1(buf, charPos, (int)((q * 100) - i));
216+
uncheckedPutPairLatin1(buf, charPos, (int)((q * 100) - i));
217217
i = q;
218218
}
219219

@@ -223,35 +223,35 @@ public static int getCharsLatin1(long i, int index, byte[] buf) {
223223
while (i2 <= -100) {
224224
q2 = i2 / 100;
225225
charPos -= 2;
226-
putPairLatin1(buf, charPos, (q2 * 100) - i2);
226+
uncheckedPutPairLatin1(buf, charPos, (q2 * 100) - i2);
227227
i2 = q2;
228228
}
229229

230230
// We know there are at most two digits left at this point.
231231
if (i2 <= -10) {
232232
charPos -= 2;
233-
putPairLatin1(buf, charPos, -i2);
233+
uncheckedPutPairLatin1(buf, charPos, -i2);
234234
} else {
235-
putCharLatin1(buf, --charPos, '0' - i2);
235+
uncheckedPutCharLatin1(buf, --charPos, '0' - i2);
236236
}
237237

238238
if (negative) {
239-
putCharLatin1(buf, --charPos, '-');
239+
uncheckedPutCharLatin1(buf, --charPos, '-');
240240
}
241241
return charPos;
242242
}
243243

244244

245245
/**
246-
* This is a variant of {@link DecimalDigits#getCharsLatin1(int, int, byte[])}, but for
246+
* This is a variant of {@link DecimalDigits#uncheckedGetCharsLatin1(int, int, byte[])}, but for
247247
* UTF-16 coder.
248248
*
249249
* @param i value to convert
250250
* @param index next index, after the least significant digit
251251
* @param buf target buffer, UTF16-coded.
252252
* @return index of the most significant digit or minus sign, if present
253253
*/
254-
public static int getCharsUTF16(int i, int index, byte[] buf) {
254+
public static int uncheckedGetCharsUTF16(int i, int index, byte[] buf) {
255255
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
256256
int q;
257257
int charPos = index;
@@ -265,35 +265,35 @@ public static int getCharsUTF16(int i, int index, byte[] buf) {
265265
while (i <= -100) {
266266
q = i / 100;
267267
charPos -= 2;
268-
putPairUTF16(buf, charPos, (q * 100) - i);
268+
uncheckedPutPairUTF16(buf, charPos, (q * 100) - i);
269269
i = q;
270270
}
271271

272272
// We know there are at most two digits left at this point.
273273
if (i <= -10) {
274274
charPos -= 2;
275-
putPairUTF16(buf, charPos, -i);
275+
uncheckedPutPairUTF16(buf, charPos, -i);
276276
} else {
277-
putCharUTF16(buf, --charPos, '0' - i);
277+
uncheckedPutCharUTF16(buf, --charPos, '0' - i);
278278
}
279279

280280
if (negative) {
281-
putCharUTF16(buf, --charPos, '-');
281+
uncheckedPutCharUTF16(buf, --charPos, '-');
282282
}
283283
return charPos;
284284
}
285285

286286

287287
/**
288-
* This is a variant of {@link DecimalDigits#getCharsLatin1(long, int, byte[])}, but for
288+
* This is a variant of {@link DecimalDigits#uncheckedGetCharsLatin1(long, int, byte[])}, but for
289289
* UTF-16 coder.
290290
*
291291
* @param i value to convert
292292
* @param index next index, after the least significant digit
293293
* @param buf target buffer, UTF16-coded.
294294
* @return index of the most significant digit or minus sign, if present
295295
*/
296-
public static int getCharsUTF16(long i, int index, byte[] buf) {
296+
public static int uncheckedGetCharsUTF16(long i, int index, byte[] buf) {
297297
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
298298
long q;
299299
int charPos = index;
@@ -307,7 +307,7 @@ public static int getCharsUTF16(long i, int index, byte[] buf) {
307307
while (i < Integer.MIN_VALUE) {
308308
q = i / 100;
309309
charPos -= 2;
310-
putPairUTF16(buf, charPos, (int)((q * 100) - i));
310+
uncheckedPutPairUTF16(buf, charPos, (int)((q * 100) - i));
311311
i = q;
312312
}
313313

@@ -317,26 +317,26 @@ public static int getCharsUTF16(long i, int index, byte[] buf) {
317317
while (i2 <= -100) {
318318
q2 = i2 / 100;
319319
charPos -= 2;
320-
putPairUTF16(buf, charPos, (q2 * 100) - i2);
320+
uncheckedPutPairUTF16(buf, charPos, (q2 * 100) - i2);
321321
i2 = q2;
322322
}
323323

324324
// We know there are at most two digits left at this point.
325325
if (i2 <= -10) {
326326
charPos -= 2;
327-
putPairUTF16(buf, charPos, -i2);
327+
uncheckedPutPairUTF16(buf, charPos, -i2);
328328
} else {
329-
putCharUTF16(buf, --charPos, '0' - i2);
329+
uncheckedPutCharUTF16(buf, --charPos, '0' - i2);
330330
}
331331

332332
if (negative) {
333-
putCharUTF16(buf, --charPos, '-');
333+
uncheckedPutCharUTF16(buf, --charPos, '-');
334334
}
335335
return charPos;
336336
}
337337

338338
/**
339-
* This is a variant of {@link DecimalDigits#getCharsUTF16(long, int, byte[])}, but for
339+
* This is a variant of {@link DecimalDigits#uncheckedGetCharsUTF16(long, int, byte[])}, but for
340340
* UTF-16 coder.
341341
*
342342
* @param i value to convert
@@ -406,10 +406,10 @@ public static void putPair(char[] buf, int charPos, int v) {
406406
* @param charPos insert point
407407
* @param v to convert
408408
*/
409-
public static void putPairLatin1(byte[] buf, int charPos, int v) {
409+
public static void uncheckedPutPairLatin1(byte[] buf, int charPos, int v) {
410410
int packed = DIGITS[v & 0x7f];
411-
putCharLatin1(buf, charPos, packed & 0xFF);
412-
putCharLatin1(buf, charPos + 1, packed >> 8);
411+
uncheckedPutCharLatin1(buf, charPos, packed & 0xFF);
412+
uncheckedPutCharLatin1(buf, charPos + 1, packed >> 8);
413413
}
414414

415415
/**
@@ -419,17 +419,17 @@ public static void putPairLatin1(byte[] buf, int charPos, int v) {
419419
* @param charPos insert point
420420
* @param v to convert
421421
*/
422-
public static void putPairUTF16(byte[] buf, int charPos, int v) {
422+
public static void uncheckedPutPairUTF16(byte[] buf, int charPos, int v) {
423423
int packed = DIGITS[v & 0x7f];
424-
putCharUTF16(buf, charPos, packed & 0xFF);
425-
putCharUTF16(buf, charPos + 1, packed >> 8);
424+
uncheckedPutCharUTF16(buf, charPos, packed & 0xFF);
425+
uncheckedPutCharUTF16(buf, charPos + 1, packed >> 8);
426426
}
427427

428-
private static void putCharLatin1(byte[] buf, int charPos, int c) {
428+
private static void uncheckedPutCharLatin1(byte[] buf, int charPos, int c) {
429429
UNSAFE.putByte(buf, ARRAY_BYTE_BASE_OFFSET + charPos, (byte) c);
430430
}
431431

432-
private static void putCharUTF16(byte[] buf, int charPos, int c) {
432+
private static void uncheckedPutCharUTF16(byte[] buf, int charPos, int c) {
433433
UNSAFE.putCharUnaligned(buf, ARRAY_BYTE_BASE_OFFSET + ((long) charPos << 1), (char) c);
434434
}
435435
}

test/hotspot/jtreg/compiler/patches/java.base/java/lang/Helper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public static int codePointCountSB(byte[] val, int beginIndex, int endIndex) {
120120

121121
public static int getChars(int i, int begin, int end, byte[] value) {
122122
StringUTF16.checkBoundsBeginEnd(begin, end, value);
123-
int pos = DecimalDigits.getCharsUTF16(i, end, value);
123+
int pos = DecimalDigits.uncheckedGetCharsUTF16(i, end, value);
124124
assert begin == pos;
125125
return pos;
126126
}
127127

128128
public static int getChars(long l, int begin, int end, byte[] value) {
129129
StringUTF16.checkBoundsBeginEnd(begin, end, value);
130-
int pos = DecimalDigits.getCharsUTF16(l, end, value);
130+
int pos = DecimalDigits.uncheckedGetCharsUTF16(l, end, value);
131131
assert begin == pos;
132132
return pos;
133133
}

0 commit comments

Comments
 (0)