author | rriggs |
Wed, 28 Nov 2018 15:53:49 -0500 | |
changeset 52724 | 0bdbf854472f |
parent 52326 | 77018c2b97df |
child 54550 | 5fa7fbddfe9d |
permissions | -rw-r--r-- |
35388 | 1 |
/* |
44642
331e669007f7
8158168: Missing bounds checks for some String intrinsics
dlong
parents:
40810
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
35388 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
48373
f9152f462cbc
8193758: Update copyright headers of files in src tree that are missing Classpath exception
alanb
parents:
47216
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f9152f462cbc
8193758: Update copyright headers of files in src tree that are missing Classpath exception
alanb
parents:
47216
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f9152f462cbc
8193758: Update copyright headers of files in src tree that are missing Classpath exception
alanb
parents:
47216
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
35388 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
/** |
|
29 |
* Helper for string concatenation. These methods are mostly looked up with private lookups |
|
30 |
* from {@link java.lang.invoke.StringConcatFactory}, and used in {@link java.lang.invoke.MethodHandle} |
|
31 |
* combinators there. |
|
32 |
*/ |
|
33 |
final class StringConcatHelper { |
|
34 |
||
35 |
private StringConcatHelper() { |
|
36 |
// no instantiation |
|
37 |
} |
|
38 |
||
39 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
40 |
* Check for overflow, throw exception on overflow. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
41 |
* @param lengthCoder String length and coder |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
42 |
* @return lengthCoder |
35388 | 43 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
44 |
private static long checkOverflow(long lengthCoder) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
45 |
if ((int)lengthCoder >= 0) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
46 |
return lengthCoder; |
35388 | 47 |
} |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
48 |
throw new OutOfMemoryError("Overflow: String length out of range"); |
35388 | 49 |
} |
50 |
||
51 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
52 |
* Mix value length and coder into current length and coder. |
35388 | 53 |
* @param current current length |
54 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
55 |
* @return new length and coder |
35388 | 56 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
57 |
static long mix(long current, boolean value) { |
35388 | 58 |
return checkOverflow(current + (value ? 4 : 5)); |
59 |
} |
|
60 |
||
61 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
62 |
* Mix value length and coder into current length and coder. |
35388 | 63 |
* @param current current length |
64 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
65 |
* @return new length and coder |
35388 | 66 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
67 |
static long mix(long current, byte value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
68 |
return mix(current, (int)value); |
35388 | 69 |
} |
70 |
||
71 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
72 |
* Mix value length and coder into current length and coder. |
35388 | 73 |
* @param current current length |
74 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
75 |
* @return new length and coder |
35388 | 76 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
77 |
static long mix(long current, char value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
78 |
return checkOverflow(current + 1) | (StringLatin1.canEncode(value) ? 0 : UTF16); |
35388 | 79 |
} |
80 |
||
81 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
82 |
* Mix value length and coder into current length and coder. |
35388 | 83 |
* @param current current length |
84 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
85 |
* @return new length and coder |
35388 | 86 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
87 |
static long mix(long current, short value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
88 |
return mix(current, (int)value); |
35388 | 89 |
} |
90 |
||
91 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
92 |
* Mix value length and coder into current length and coder. |
35388 | 93 |
* @param current current length |
94 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
95 |
* @return new length and coder |
35388 | 96 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
97 |
static long mix(long current, int value) { |
35388 | 98 |
return checkOverflow(current + Integer.stringSize(value)); |
99 |
} |
|
100 |
||
101 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
102 |
* Mix value length and coder into current length and coder. |
35388 | 103 |
* @param current current length |
104 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
105 |
* @return new length and coder |
35388 | 106 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
107 |
static long mix(long current, long value) { |
35388 | 108 |
return checkOverflow(current + Long.stringSize(value)); |
109 |
} |
|
110 |
||
111 |
/** |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
112 |
* Mix value length and coder into current length and coder. |
35388 | 113 |
* @param current current length |
114 |
* @param value value to mix in |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
115 |
* @return new length and coder |
35388 | 116 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
117 |
static long mix(long current, String value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
118 |
current += value.length(); |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
119 |
if (value.coder() == String.UTF16) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
120 |
current |= UTF16; |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
121 |
} |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
122 |
return checkOverflow(current); |
35388 | 123 |
} |
124 |
||
125 |
/** |
|
126 |
* Prepends the stringly representation of boolean value into buffer, |
|
127 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
128 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
129 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
130 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
131 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
132 |
* @param value boolean value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
133 |
* @return updated index (coder value retained) |
35388 | 134 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
135 |
static long prepend(long indexCoder, byte[] buf, boolean value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
136 |
int index = (int)indexCoder; |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
137 |
if (indexCoder < UTF16) { |
35388 | 138 |
if (value) { |
139 |
buf[--index] = 'e'; |
|
140 |
buf[--index] = 'u'; |
|
141 |
buf[--index] = 'r'; |
|
142 |
buf[--index] = 't'; |
|
143 |
} else { |
|
144 |
buf[--index] = 'e'; |
|
145 |
buf[--index] = 's'; |
|
146 |
buf[--index] = 'l'; |
|
147 |
buf[--index] = 'a'; |
|
148 |
buf[--index] = 'f'; |
|
149 |
} |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
150 |
return index; |
35388 | 151 |
} else { |
152 |
if (value) { |
|
153 |
StringUTF16.putChar(buf, --index, 'e'); |
|
154 |
StringUTF16.putChar(buf, --index, 'u'); |
|
155 |
StringUTF16.putChar(buf, --index, 'r'); |
|
156 |
StringUTF16.putChar(buf, --index, 't'); |
|
157 |
} else { |
|
158 |
StringUTF16.putChar(buf, --index, 'e'); |
|
159 |
StringUTF16.putChar(buf, --index, 's'); |
|
160 |
StringUTF16.putChar(buf, --index, 'l'); |
|
161 |
StringUTF16.putChar(buf, --index, 'a'); |
|
162 |
StringUTF16.putChar(buf, --index, 'f'); |
|
163 |
} |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
164 |
return index | UTF16; |
35388 | 165 |
} |
166 |
} |
|
167 |
||
168 |
/** |
|
169 |
* Prepends the stringly representation of byte value into buffer, |
|
170 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
171 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
172 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
173 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
174 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
175 |
* @param value byte value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
176 |
* @return updated index (coder value retained) |
35388 | 177 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
178 |
static long prepend(long indexCoder, byte[] buf, byte value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
179 |
return prepend(indexCoder, buf, (int)value); |
35388 | 180 |
} |
181 |
||
182 |
/** |
|
183 |
* Prepends the stringly representation of char value into buffer, |
|
184 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
185 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
186 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
187 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
188 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
189 |
* @param value char value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
190 |
* @return updated index (coder value retained) |
35388 | 191 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
192 |
static long prepend(long indexCoder, byte[] buf, char value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
193 |
if (indexCoder < UTF16) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
194 |
buf[(int)(--indexCoder)] = (byte) (value & 0xFF); |
35388 | 195 |
} else { |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
196 |
StringUTF16.putChar(buf, (int)(--indexCoder), value); |
35388 | 197 |
} |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
198 |
return indexCoder; |
35388 | 199 |
} |
200 |
||
201 |
/** |
|
202 |
* Prepends the stringly representation of short value into buffer, |
|
203 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
204 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
205 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
206 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
207 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
208 |
* @param value short value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
209 |
* @return updated index (coder value retained) |
35388 | 210 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
211 |
static long prepend(long indexCoder, byte[] buf, short value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
212 |
return prepend(indexCoder, buf, (int)value); |
35388 | 213 |
} |
214 |
||
215 |
/** |
|
216 |
* Prepends the stringly representation of integer value into buffer, |
|
217 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
218 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
219 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
220 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
221 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
222 |
* @param value integer value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
223 |
* @return updated index (coder value retained) |
35388 | 224 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
225 |
static long prepend(long indexCoder, byte[] buf, int value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
226 |
if (indexCoder < UTF16) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
227 |
return Integer.getChars(value, (int)indexCoder, buf); |
35388 | 228 |
} else { |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
229 |
return StringUTF16.getChars(value, (int)indexCoder, buf) | UTF16; |
35388 | 230 |
} |
231 |
} |
|
232 |
||
233 |
/** |
|
234 |
* Prepends the stringly representation of long value into buffer, |
|
235 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
236 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
237 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
238 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
239 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
240 |
* @param value long value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
241 |
* @return updated index (coder value retained) |
35388 | 242 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
243 |
static long prepend(long indexCoder, byte[] buf, long value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
244 |
if (indexCoder < UTF16) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
245 |
return Long.getChars(value, (int)indexCoder, buf); |
35388 | 246 |
} else { |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
247 |
return StringUTF16.getChars(value, (int)indexCoder, buf) | UTF16; |
35388 | 248 |
} |
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
* Prepends the stringly representation of String value into buffer, |
|
253 |
* given the coder and final index. Index is measured in chars, not in bytes! |
|
254 |
* |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
255 |
* @param indexCoder final char index in the buffer, along with coder packed |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
256 |
* into higher bits. |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
257 |
* @param buf buffer to append to |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
258 |
* @param value String value to encode |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
259 |
* @return updated index (coder value retained) |
35388 | 260 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
261 |
static long prepend(long indexCoder, byte[] buf, String value) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
262 |
indexCoder -= value.length(); |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
263 |
if (indexCoder < UTF16) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
264 |
value.getBytes(buf, (int)indexCoder, String.LATIN1); |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
265 |
} else { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
266 |
value.getBytes(buf, (int)indexCoder, String.UTF16); |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
267 |
} |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
268 |
return indexCoder; |
35388 | 269 |
} |
270 |
||
271 |
/** |
|
272 |
* Instantiates the String with given buffer and coder |
|
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
273 |
* @param buf buffer to use |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
274 |
* @param indexCoder remaining index (should be zero) and coder |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
275 |
* @return String resulting string |
35388 | 276 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
277 |
static String newString(byte[] buf, long indexCoder) { |
35388 | 278 |
// Use the private, non-copying constructor (unsafe!) |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
279 |
if (indexCoder == LATIN1) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
280 |
return new String(buf, String.LATIN1); |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
281 |
} else if (indexCoder == UTF16) { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
282 |
return new String(buf, String.UTF16); |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
283 |
} else { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
284 |
throw new InternalError("Storage is not completely initialized, " + (int)indexCoder + " bytes left"); |
40810
b88d5910ea1e
8165492: Reduce number of lambda forms generated by MethodHandleInlineCopyStrategy
redestad
parents:
35700
diff
changeset
|
285 |
} |
35388 | 286 |
} |
287 |
||
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
288 |
private static final long LATIN1 = (long)String.LATIN1 << 32; |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
289 |
|
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
290 |
private static final long UTF16 = (long)String.UTF16 << 32; |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
291 |
|
35700
b933119b8f84
8148869: StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings
shade
parents:
35388
diff
changeset
|
292 |
/** |
b933119b8f84
8148869: StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings
shade
parents:
35388
diff
changeset
|
293 |
* Provides the initial coder for the String. |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
294 |
* @return initial coder, adjusted into the upper half |
35700
b933119b8f84
8148869: StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings
shade
parents:
35388
diff
changeset
|
295 |
*/ |
52326
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
296 |
static long initialCoder() { |
77018c2b97df
8213035: Pack MethodHandleInlineStrategy coder and length into a long
redestad
parents:
52177
diff
changeset
|
297 |
return String.COMPACT_STRINGS ? LATIN1 : UTF16; |
35700
b933119b8f84
8148869: StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings
shade
parents:
35388
diff
changeset
|
298 |
} |
b933119b8f84
8148869: StringConcatFactory MH_INLINE_SIZED_EXACT strategy does not work with -XX:-CompactStrings
shade
parents:
35388
diff
changeset
|
299 |
|
35388 | 300 |
} |