On Thu, 20 Jun 2024 14:32:25 GMT, Shaojin Wen <d...@openjdk.org> wrote:
>> @cl4es @wenshao I think we should probably work on `putChar`, or at least >> figure out what blocks `MergeStore` for `putChar`. Can someone produce a >> simple stand-alone `.java` file that uses `putChar`, so that I can >> investigate why `MergeStore` does not work for it? >> >> Otherwise, I agree with @cl4es : the code here may be ok for now, but we >> would have to revert it again later, should `MergeStore` eventually do the >> trick. > > @eme64 > > simple stand-alone java > > import jdk.internal.misc.Unsafe; > > public class PutCharTest { > static final Unsafe UNSAFE = Unsafe.getUnsafe(); > > static void putCharsAt(byte[] val, int index, int c1, int c2, int c3, int > c4) { > putChar(val, index , (char)(c1)); > putChar(val, index + 1, (char)(c2)); > putChar(val, index + 2, (char)(c3)); > putChar(val, index + 3, (char)(c4)); > } > > static void putChar(byte[] bytes, int index, int c) { > UNSAFE.putChar(bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET + (index << 1), > (char)(c)); > } > > static void putChar0(byte[] bytes, int index, int c) { > UNSAFE.putByte(bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET + (index << 1), > (byte)(c)); > UNSAFE.putByte(bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET + (index << 1) + > 1, (byte)(c << 8)); > } > > 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[8192]; > > for (int i = 0; i < 1000; i++) { > int index = 0; > for (int j = 0; j < 1024; j++) { > putNull(bytes, index); > index += 4; > } > } > } > } @wenshao @cl4es I think this use-case is quite a valid one, and deserves an extension. 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 ------------- PR Comment: https://git.openjdk.org/jdk/pull/19626#issuecomment-2189523984