<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>I'll let others knowledgeable in this area to comment and provide
      inputs to this proposal. I just want to say thank you for bringing
      up this discussion to the mailing list first, providing the
      necessary context and explanation and seeking feedback, before
      creating a JBS issue or a RFR PR.</p>
    <p>-Jaikiran<br>
    </p>
    <div class="moz-cite-prefix">On 30/07/25 7:48 pm, wenshao wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:086fd3c9-30e0-4294-b674-ece0bd91051c.shaojin.wensj@alibaba-inc.com">
      
      <div class="__aliyun_email_body_block">
        <div style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun">
          <div style="clear: both;"><span>In the discussion of `8355177:
              Speed up StringBuilder::append(char[]) via
              Unsafe::copyMemory` (<a href="https://github.com/openjdk/jdk/pull/24773" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/openjdk/jdk/pull/24773</a>),
              @liach (<span>Chen Liang)</span> suggested reusing the
              StringUTF16::putCharsSB method introduced in PR #24773
              instead of the Intrinsic implementation in the
              StringUTF16::toBytes method.</span>
            <div style="clear: both;"><br>
            </div>
            <div style="clear: both;"><span>Original:</span>
              <div style="clear: both;">```java</div>
              <div style="clear: both;">    @IntrinsicCandidate</div>
              <div style="clear: both;">    public static byte[]
                toBytes(char[] value, int off, int len) {</div>
              <div style="clear: both;">        byte[] val =
                newBytesFor(len);</div>
              <div style="clear: both;">        for (int i = 0; i <
                len; i++) {</div>
              <div style="clear: both;">            putChar(val, i,
                value[off]);</div>
              <div style="clear: both;">            off++;</div>
              <div style="clear: both;">        }</div>
              <div style="clear: both;">        return val;</div>
              <div style="clear: both;">    }</div>
              <div style="clear: both;">```</div>
              <div style="clear: both;"><br>
              </div>
              <div style="clear: both;">After:</div>
              <div style="clear: both;">```java</div>
              <div style="clear: both;">    public static byte[]
                toBytes(char[] value, int off, int len) {</div>
              <div style="clear: both;">        byte[] val = (byte[])
                Unsafe.getUnsafe().allocateUninitializedArray(byte.class,
                newBytesLength(len));</div>
              <div style="clear: both;">        putCharsSB(val, 0,
                value, off, off + len);</div>
              <div style="clear: both;">        return val;</div>
              <div style="clear: both;">    }</div>
              <span>```</span></div>
            <div style="clear: both;"><br>
            </div>
            <div style="clear: both;">This replacement does not degrade
              performance. Running
              StringConstructor.newStringFromCharsMixedBegin verified
              that performance is consistent with the original on x64
              and slightly improved on aarch64.</div>
            <div style="clear: both;"><br>
            </div>
            <span>The implementation after replacing the Intrinsic
              implementation removed 100 lines of C++ code, leaving only
              Java and Unsafe code, no Intrinsic or C++ code, which
              makes the code more maintainable.</span></div>
          <div style="clear: both;"><span><br>
            </span></div>
          <div style="clear: both;"><span><span>I've submitted a draft
                PR </span><span><a href="https://github.com/openjdk/jdk/pull/26553" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/openjdk/jdk/pull/26553</a>
                , please give me some feedback.</span></span></div>
          <div style="clear: both;"><span>-</span></div>
          <div style="clear: both;"><span>Shaojin Wen</span></div>
        </div>
      </div>
    </blockquote>
  </body>
</html>