RFR: 8333893: Optimization for StringBuilder append boolean & null [v4]
Claes Redestad
redestad at openjdk.org
Wed Jun 26 19:18:12 UTC 2024
On Thu, 20 Jun 2024 14:32:25 GMT, Shaojin Wen <duke at 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;
> }
> }
> }
> }
As long as @wenshao is OK with that I'm happy to let this wait. I'll have limited availability myself in the coming weeks.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19626#issuecomment-2192459124
More information about the core-libs-dev
mailing list