RFR: 8333893: Optimization for StringBuilder append boolean & null [v4]
    Shaojin Wen 
    duke at openjdk.org
       
    Wed Jun 12 13:18:16 UTC 2024
    
    
  
On Tue, 11 Jun 2024 11:35:28 GMT, Shaojin Wen <duke at openjdk.org> wrote:
>> After PR https://github.com/openjdk/jdk/pull/16245, C2 optimizes stores into primitive arrays by combining values into larger stores.
>> 
>> This PR rewrites the code of appendNull and append(boolean) methods so that these two methods can be optimized by C2.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   revert
`-XX:DisableIntrinsic=_putCharStringU` causes performance degradation. As written in the comments of StringUTF16.putChar, no bounds checks, this is similar to Unsafe.putChar
-XX:DisableIntrinsic=_putCharStringU
Benchmark                                  Mode  Cnt  Score   Error  Units
StringBuilders.toStringCharWithNull8Utf16  avgt   15  9.063 ± 0.130  ns/op
Benchmark                                  Mode  Cnt  Score   Error  Units
StringBuilders.toStringCharWithNull8Utf16  avgt   15  8.139 ± 0.018  ns/op
class StringUTF16 {
    @IntrinsicCandidate
    // intrinsic performs no bounds checks
    static void putChar(byte[] val, int index, int c) {
        assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
        index <<= 1;
        val[index++] = (byte)(c >> HI_BYTE_SHIFT);
        val[index]   = (byte)(c >> LO_BYTE_SHIFT);
    }
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19626#issuecomment-2162984481
    
    
More information about the core-libs-dev
mailing list