Skip to content

Commit e122f4d

Browse files
committed
8368024: Remove StringConcatFactory#generateMHInlineCopy
Reviewed-by: redestad
1 parent 2990814 commit e122f4d

File tree

5 files changed

+3
-782
lines changed

5 files changed

+3
-782
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,7 @@ static String join(String prefix, String suffix, String delimiter, String[] elem
37103710
if (len < 0L || (len <<= coder) != (int) len) {
37113711
throw new OutOfMemoryError("Requested string length exceeds VM limit");
37123712
}
3713-
byte[] value = StringConcatHelper.newArray(len);
3713+
byte[] value = StringConcatHelper.newArray((int) len);
37143714

37153715
int off = 0;
37163716
prefix.getBytes(value, off, coder); off += prefix.length();

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

Lines changed: 2 additions & 304 deletions
Original file line numberDiff line numberDiff line change
@@ -141,262 +141,6 @@ private StringConcatHelper() {
141141
// no instantiation
142142
}
143143

144-
/**
145-
* Return the coder for the character.
146-
* @param value character
147-
* @return coder
148-
*/
149-
static long coder(char value) {
150-
return StringLatin1.canEncode(value) ? LATIN1 : UTF16;
151-
}
152-
153-
/**
154-
* Check for overflow, throw exception on overflow.
155-
*
156-
* @param lengthCoder String length with coder packed into higher bits
157-
* the upper word.
158-
* @return the given parameter value, if valid
159-
*/
160-
private static long checkOverflow(long lengthCoder) {
161-
if ((int)lengthCoder >= 0) {
162-
return lengthCoder;
163-
}
164-
throw new OutOfMemoryError("Overflow: String length out of range");
165-
}
166-
167-
/**
168-
* Mix value length and coder into current length and coder.
169-
* @param lengthCoder String length with coder packed into higher bits
170-
* the upper word.
171-
* @param value value to mix in
172-
* @return new length and coder
173-
*/
174-
static long mix(long lengthCoder, boolean value) {
175-
return checkOverflow(lengthCoder + (value ? 4 : 5));
176-
}
177-
178-
/**
179-
* Mix value length and coder into current length and coder.
180-
* @param lengthCoder String length with coder packed into higher bits
181-
* the upper word.
182-
* @param value value to mix in
183-
* @return new length and coder
184-
*/
185-
static long mix(long lengthCoder, char value) {
186-
return checkOverflow(lengthCoder + 1) | coder(value);
187-
}
188-
189-
/**
190-
* Mix value length and coder into current length and coder.
191-
* @param lengthCoder String length with coder packed into higher bits
192-
* the upper word.
193-
* @param value value to mix in
194-
* @return new length and coder
195-
*/
196-
static long mix(long lengthCoder, int value) {
197-
return checkOverflow(lengthCoder + DecimalDigits.stringSize(value));
198-
}
199-
200-
/**
201-
* Mix value length and coder into current length and coder.
202-
* @param lengthCoder String length with coder packed into higher bits
203-
* the upper word.
204-
* @param value value to mix in
205-
* @return new length and coder
206-
*/
207-
static long mix(long lengthCoder, long value) {
208-
return checkOverflow(lengthCoder + DecimalDigits.stringSize(value));
209-
}
210-
211-
/**
212-
* Mix value length and coder into current length and coder.
213-
* @param lengthCoder String length with coder packed into higher bits
214-
* the upper word.
215-
* @param value value to mix in
216-
* @return new length and coder
217-
*/
218-
static long mix(long lengthCoder, String value) {
219-
lengthCoder += value.length();
220-
if (!value.isLatin1()) {
221-
lengthCoder |= UTF16;
222-
}
223-
return checkOverflow(lengthCoder);
224-
}
225-
226-
/**
227-
* Prepends constant and the stringly representation of value into buffer,
228-
* given the coder and final index. Index is measured in chars, not in bytes!
229-
*
230-
* @param indexCoder final char index in the buffer, along with coder packed
231-
* into higher bits.
232-
* @param buf buffer to append to
233-
* @param value boolean value to encode
234-
* @param prefix a constant to prepend before value
235-
* @return updated index (coder value retained)
236-
*/
237-
static long prepend(long indexCoder, byte[] buf, boolean value, String prefix) {
238-
int index = (int)indexCoder;
239-
if (indexCoder < UTF16) {
240-
if (value) {
241-
index -= 4;
242-
buf[index] = 't';
243-
buf[index + 1] = 'r';
244-
buf[index + 2] = 'u';
245-
buf[index + 3] = 'e';
246-
} else {
247-
index -= 5;
248-
buf[index] = 'f';
249-
buf[index + 1] = 'a';
250-
buf[index + 2] = 'l';
251-
buf[index + 3] = 's';
252-
buf[index + 4] = 'e';
253-
}
254-
index -= prefix.length();
255-
prefix.getBytes(buf, index, String.LATIN1);
256-
return index;
257-
} else {
258-
if (value) {
259-
index -= 4;
260-
StringUTF16.putChar(buf, index, 't');
261-
StringUTF16.putChar(buf, index + 1, 'r');
262-
StringUTF16.putChar(buf, index + 2, 'u');
263-
StringUTF16.putChar(buf, index + 3, 'e');
264-
} else {
265-
index -= 5;
266-
StringUTF16.putChar(buf, index, 'f');
267-
StringUTF16.putChar(buf, index + 1, 'a');
268-
StringUTF16.putChar(buf, index + 2, 'l');
269-
StringUTF16.putChar(buf, index + 3, 's');
270-
StringUTF16.putChar(buf, index + 4, 'e');
271-
}
272-
index -= prefix.length();
273-
prefix.getBytes(buf, index, String.UTF16);
274-
return index | UTF16;
275-
}
276-
}
277-
278-
/**
279-
* Prepends constant and the stringly representation of value into buffer,
280-
* given the coder and final index. Index is measured in chars, not in bytes!
281-
*
282-
* @param indexCoder final char index in the buffer, along with coder packed
283-
* into higher bits.
284-
* @param buf buffer to append to
285-
* @param value char value to encode
286-
* @param prefix a constant to prepend before value
287-
* @return updated index (coder value retained)
288-
*/
289-
static long prepend(long indexCoder, byte[] buf, char value, String prefix) {
290-
int index = (int)indexCoder;
291-
if (indexCoder < UTF16) {
292-
buf[--index] = (byte) (value & 0xFF);
293-
index -= prefix.length();
294-
prefix.getBytes(buf, index, String.LATIN1);
295-
return index;
296-
} else {
297-
StringUTF16.putChar(buf, --index, value);
298-
index -= prefix.length();
299-
prefix.getBytes(buf, index, String.UTF16);
300-
return index | UTF16;
301-
}
302-
}
303-
304-
/**
305-
* Prepends constant and the stringly representation of value into buffer,
306-
* given the coder and final index. Index is measured in chars, not in bytes!
307-
*
308-
* @param indexCoder final char index in the buffer, along with coder packed
309-
* into higher bits.
310-
* @param buf buffer to append to
311-
* @param value int value to encode
312-
* @param prefix a constant to prepend before value
313-
* @return updated index (coder value retained)
314-
*/
315-
static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
316-
int index = (int)indexCoder;
317-
if (indexCoder < UTF16) {
318-
index = DecimalDigits.uncheckedGetCharsLatin1(value, index, buf);
319-
index -= prefix.length();
320-
prefix.getBytes(buf, index, String.LATIN1);
321-
return index;
322-
} else {
323-
index = DecimalDigits.uncheckedGetCharsUTF16(value, index, buf);
324-
index -= prefix.length();
325-
prefix.getBytes(buf, index, String.UTF16);
326-
return index | UTF16;
327-
}
328-
}
329-
330-
/**
331-
* Prepends constant and the stringly representation of value into buffer,
332-
* given the coder and final index. Index is measured in chars, not in bytes!
333-
*
334-
* @param indexCoder final char index in the buffer, along with coder packed
335-
* into higher bits.
336-
* @param buf buffer to append to
337-
* @param value long value to encode
338-
* @param prefix a constant to prepend before value
339-
* @return updated index (coder value retained)
340-
*/
341-
static long prepend(long indexCoder, byte[] buf, long value, String prefix) {
342-
int index = (int)indexCoder;
343-
if (indexCoder < UTF16) {
344-
index = DecimalDigits.uncheckedGetCharsLatin1(value, index, buf);
345-
index -= prefix.length();
346-
prefix.getBytes(buf, index, String.LATIN1);
347-
return index;
348-
} else {
349-
index = DecimalDigits.uncheckedGetCharsUTF16(value, index, buf);
350-
index -= prefix.length();
351-
prefix.getBytes(buf, index, String.UTF16);
352-
return index | UTF16;
353-
}
354-
}
355-
356-
/**
357-
* Prepends constant and the stringly representation of value into buffer,
358-
* given the coder and final index. Index is measured in chars, not in bytes!
359-
*
360-
* @param indexCoder final char index in the buffer, along with coder packed
361-
* into higher bits.
362-
* @param buf buffer to append to
363-
* @param value boolean value to encode
364-
* @param prefix a constant to prepend before value
365-
* @return updated index (coder value retained)
366-
*/
367-
static long prepend(long indexCoder, byte[] buf, String value, String prefix) {
368-
int index = ((int)indexCoder) - value.length();
369-
if (indexCoder < UTF16) {
370-
value.getBytes(buf, index, String.LATIN1);
371-
index -= prefix.length();
372-
prefix.getBytes(buf, index, String.LATIN1);
373-
return index;
374-
} else {
375-
value.getBytes(buf, index, String.UTF16);
376-
index -= prefix.length();
377-
prefix.getBytes(buf, index, String.UTF16);
378-
return index | UTF16;
379-
}
380-
}
381-
382-
/**
383-
* Instantiates the String with given buffer and coder
384-
* @param buf buffer to use
385-
* @param indexCoder remaining index (should be zero) and coder
386-
* @return String resulting string
387-
*/
388-
static String newString(byte[] buf, long indexCoder) {
389-
// Use the private, non-copying constructor (unsafe!)
390-
if (indexCoder == LATIN1) {
391-
return new String(buf, String.LATIN1);
392-
} else if (indexCoder == UTF16) {
393-
return new String(buf, String.UTF16);
394-
} else {
395-
throw new InternalError("Storage is not completely initialized, " +
396-
(int)indexCoder + " bytes left");
397-
}
398-
}
399-
400144
/**
401145
* Perform a simple concatenation between two objects. Added for startup
402146
* performance, but also demonstrates the code that would be emitted by
@@ -466,10 +210,6 @@ static String stringOf(Object value) {
466210
return (value == null || (s = value.toString()) == null) ? "null" : s;
467211
}
468212

469-
private static final long LATIN1 = (long)String.LATIN1 << 32;
470-
471-
private static final long UTF16 = (long)String.UTF16 << 32;
472-
473213
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
474214

475215
static String stringOf(float value) {
@@ -530,41 +270,6 @@ static int stringSize(int length, String value) {
530270
return checkOverflow(length + value.length());
531271
}
532272

533-
/**
534-
* Allocates an uninitialized byte array based on the length and coder
535-
* information, then prepends the given suffix string at the end of the
536-
* byte array before returning it. The calling code must adjust the
537-
* indexCoder so that it's taken the coder of the suffix into account, but
538-
* subtracted the length of the suffix.
539-
*
540-
* @param suffix
541-
* @param indexCoder
542-
* @return the newly allocated byte array
543-
*/
544-
@ForceInline
545-
static byte[] newArrayWithSuffix(String suffix, long indexCoder) {
546-
byte[] buf = newArray(indexCoder + suffix.length());
547-
if (indexCoder < UTF16) {
548-
suffix.getBytes(buf, (int)indexCoder, String.LATIN1);
549-
} else {
550-
suffix.getBytes(buf, (int)indexCoder, String.UTF16);
551-
}
552-
return buf;
553-
}
554-
555-
/**
556-
* Allocates an uninitialized byte array based on the length and coder information
557-
* in indexCoder
558-
* @param indexCoder
559-
* @return the newly allocated byte array
560-
*/
561-
@ForceInline
562-
static byte[] newArray(long indexCoder) {
563-
byte coder = (byte)(indexCoder >> 32);
564-
int index = ((int)indexCoder) << coder;
565-
return newArray(index);
566-
}
567-
568273
/**
569274
* Allocates an uninitialized byte array based on the length
570275
* @param length
@@ -578,14 +283,6 @@ static byte[] newArray(int length) {
578283
return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, length);
579284
}
580285

581-
/**
582-
* Provides the initial coder for the String.
583-
* @return initial coder, adjusted into the upper half
584-
*/
585-
static long initialCoder() {
586-
return String.COMPACT_STRINGS ? LATIN1 : UTF16;
587-
}
588-
589286
static MethodHandle lookupStatic(String name, MethodType methodType) {
590287
try {
591288
return MethodHandles.lookup()
@@ -603,7 +300,8 @@ static MethodHandle lookupStatic(String name, MethodType methodType) {
603300
* subtracted the length of the suffix.
604301
*
605302
* @param suffix
606-
* @param indexCoder
303+
* @param index final char index in the buffer
304+
* @param coder coder of the buffer
607305
* @return the newly allocated byte array
608306
*/
609307
@ForceInline

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,18 +2185,6 @@ public MethodHandle stringConcatHelper(String name, MethodType methodType) {
21852185
return StringConcatHelper.lookupStatic(name, methodType);
21862186
}
21872187

2188-
public long stringConcatInitialCoder() {
2189-
return StringConcatHelper.initialCoder();
2190-
}
2191-
2192-
public long stringConcatMix(long lengthCoder, String constant) {
2193-
return StringConcatHelper.mix(lengthCoder, constant);
2194-
}
2195-
2196-
public long stringConcatMix(long lengthCoder, char value) {
2197-
return StringConcatHelper.mix(lengthCoder, value);
2198-
}
2199-
22002188
public Object uncheckedStringConcat1(String[] constants) {
22012189
return new StringConcatHelper.Concat1(constants);
22022190
}

0 commit comments

Comments
 (0)