RFR: 8333893: Optimization for StringBuilder append boolean & null [v4]
Shaojin Wen
duke at openjdk.org
Thu Jul 25 01:17:38 UTC 2024
On Wed, 26 Jun 2024 14:39:57 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>>> I filed:
>>>
>>> [JDK-8335113](https://bugs.openjdk.org/browse/JDK-8335113): C2 MergeStores: allow merging of putChar and other larger stores on smaller array elements
>>
>> Great! Should we hold off on this optimization and see if we can avoid the need for `Unsafe` here - or go ahead integrating this PR and leave it to JDK-8335113 to revert any no-longer-needed changes made here?
>
> @cl4es I would wait, to be honest. I'm currently quite busy, but I hope I can do something here in the next 2-3 weeks.
@eme64 Unsafe.putByte MergeStore of master branch doesn't work
import sun.misc.Unsafe;
public class PutBytesTest {
static final Unsafe UNSAFE = JDKUtils.UNSAFE;
// MergeStore not work
static void putCharsAt(byte[] val, int index, int c1, int c2, int c3, int c4) {
putByte(val, index , (byte)(c1));
putByte(val, index + 1, (byte)(c2));
putByte(val, index + 2, (byte)(c3));
putByte(val, index + 3, (byte)(c4));
}
// MergeStore work
static void putCharsAtArrayStore(byte[] val, int index, int c1, int c2, int c3, int c4) {
val[index] = (byte) c1;
val[index + 1] = (byte) c2;
val[index + 2] = (byte) c3;
val[index + 3] = (byte) c4;
}
static void putByte(byte[] bytes, int index, byte c) {
UNSAFE.putByte(bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET + index, c);
}
static void putNull(byte[] bytes, int index) {
putCharsAt(bytes, index, 'n', 'u', 'l', 'l');
}
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
testNull();
}
System.out.println("done");
}
private static void testNull() {
byte[] bytes = new byte[4096];
for (int i = 0; i < 1000; i++) {
int index = 0;
for (int j = 0; j < 1024; j++) {
putNull(bytes, index);
index += 4;
}
}
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19626#issuecomment-2249171446
More information about the hotspot-compiler-dev
mailing list