RFR: 8333893: Optimization for StringBuilder append boolean & null [v4]
Shaojin Wen
duke at openjdk.org
Thu Jun 20 14:35:14 UTC 2024
On Thu, 20 Jun 2024 10:54:49 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> I'm not opposed to accepting this patch as-is, but I think we should do so with an eye towards reverting if we figure out a way to improve the `putChar` intrinsic so that it doesn't block merge store optimization. What do you think @eme64?
>>
>> As the need for the changes in [b5ad8e7](https://github.com/openjdk/jdk/pull/19626/commits/b5ad8e70928c547d134d0e4a532441cad9a7e4a2) showed added code complexity (like here) can be detrimental to performance, and if the `putChar` can be improved we might see benefits in more places.
>
> @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;
}
}
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19626#issuecomment-2180862537
More information about the core-libs-dev
mailing list