<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>For the records, I'm able to reproduce on Linux also. I've filed
      this:<br>
      <br>
      <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8314580">https://bugs.openjdk.org/browse/JDK-8314580</a></p>
    <p>Cheers<br>
      Maurizio<br>
    </p>
    <div class="moz-cite-prefix">On 18/08/2023 15:05, 刘希晨 wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CABUmArTnzLdZ4=w3_fjo2_ZN-acKP61M2T-ANE28OGWjhYn0XQ@mail.gmail.com">
      <pre style="font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(207,142,109)">public class </span>CrashExample {
    <span style="color:rgb(207,142,109)">private static final </span>VarHandle <span style="color:rgb(199,125,187);font-style:italic">byteHandle </span>= MethodHandles.<span style="font-style:italic">memorySegmentViewVarHandle</span>(ValueLayout.<span style="color:rgb(199,125,187);font-style:italic">JAVA_BYTE</span>);
    <span style="color:rgb(207,142,109)">private static final long </span><span style="color:rgb(199,125,187);font-style:italic">len </span>= <span style="color:rgb(42,172,184)">100</span>;
    <span style="color:rgb(207,142,109)">private static final byte </span><span style="color:rgb(199,125,187);font-style:italic">CR </span>= (<span style="color:rgb(207,142,109)">byte</span>) <span style="color:rgb(106,171,115)">'</span><span style="color:rgb(207,142,109)">\r</span><span style="color:rgb(106,171,115)">'</span>;
    <span style="color:rgb(207,142,109)">private static final byte </span><span style="color:rgb(199,125,187);font-style:italic">LF </span>= (<span style="color:rgb(207,142,109)">byte</span>) <span style="color:rgb(106,171,115)">'</span><span style="color:rgb(207,142,109)">\n</span><span style="color:rgb(106,171,115)">'</span>;

    <span style="color:rgb(207,142,109)">public static void </span><span style="color:rgb(86,168,245)">main</span>(String[] args) {
        <span style="color:rgb(207,142,109)">for</span>(<span style="color:rgb(207,142,109)">int </span>round = <span style="color:rgb(42,172,184)">0</span>; round < <span style="color:rgb(42,172,184)">1000</span>; round++) {
            <span style="color:rgb(207,142,109)">try</span>(Arena arena = Arena.<span style="font-style:italic">ofConfined</span>()) {
                MemorySegment memorySegment = arena.allocateArray(ValueLayout.<span style="color:rgb(199,125,187);font-style:italic">JAVA_BYTE</span>, <span style="color:rgb(199,125,187);font-style:italic">len</span>);
                <span style="color:rgb(207,142,109)">for</span>(<span style="color:rgb(207,142,109)">int </span>i = <span style="color:rgb(42,172,184)">0</span>; i < <span style="color:rgb(42,172,184)">100000</span>; i++) {
                    <span style="color:rgb(207,142,109)">int </span>index = i % <span style="color:rgb(42,172,184)">99</span>;
                    <span style="color:rgb(199,125,187);font-style:italic">byteHandle</span>.set(memorySegment, index, <span style="color:rgb(199,125,187);font-style:italic">CR</span>);
                    <span style="color:rgb(199,125,187);font-style:italic">byteHandle</span>.set(memorySegment, index + <span style="color:rgb(42,172,184)">1</span>, <span style="color:rgb(199,125,187);font-style:italic">LF</span>);
                    <span style="color:rgb(207,142,109)">byte</span>[] bytes = <span style="font-style:italic">readUntil</span>(memorySegment, <span style="color:rgb(199,125,187);font-style:italic">CR</span>, <span style="color:rgb(199,125,187);font-style:italic">LF</span>);
                }
            }
        }
    }

    <span style="color:rgb(207,142,109)">private static byte</span>[] <span style="color:rgb(86,168,245)">readUntil</span>(MemorySegment segment, <span style="color:rgb(207,142,109)">byte</span>... separators) {
        <span style="color:rgb(207,142,109)">for</span>(<span style="color:rgb(207,142,109)">long </span>cur = <span style="color:rgb(42,172,184)">0</span>; cur <= segment.byteSize() - separators.<span style="color:rgb(199,125,187)">length</span>; cur++) {
            <span style="color:rgb(207,142,109)">if</span>(<span style="font-style:italic">matches</span>(segment, cur, separators)) {
                <span style="color:rgb(207,142,109)">return </span>segment.asSlice(<span style="color:rgb(42,172,184)">0</span>, cur).toArray(ValueLayout.<span style="color:rgb(199,125,187);font-style:italic">JAVA_BYTE</span>);
            }
        }
        <span style="color:rgb(207,142,109)">return null</span>;
    }

    <span style="color:rgb(207,142,109)">public static boolean </span><span style="color:rgb(86,168,245)">matches</span>(MemorySegment m, <span style="color:rgb(207,142,109)">long </span>offset, <span style="color:rgb(207,142,109)">byte</span>[] bytes) {
        <span style="color:rgb(207,142,109)">for</span>(<span style="color:rgb(207,142,109)">int </span>index = <span style="color:rgb(42,172,184)">0</span>; index < bytes.<span style="color:rgb(199,125,187)">length</span>; index++) {
            <span style="color:rgb(207,142,109)">if </span>((<span style="color:rgb(207,142,109)">byte</span>) <span style="color:rgb(199,125,187);font-style:italic">byteHandle</span>.get(m, offset + index) != bytes[index]) {
                <span style="color:rgb(207,142,109)">return false</span>;
            }
        }
        <span style="color:rgb(207,142,109)">return true</span>;
    }
}</pre>
    </blockquote>
  </body>
</html>