Causing jvm crash when entering C2 compiling when using panama memaccess on macos

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Aug 18 14:13:40 UTC 2023


For the records, I'm able to reproduce on Linux also. I've filed this:

https://bugs.openjdk.org/browse/JDK-8314580

Cheers
Maurizio

On 18/08/2023 15:05, 刘希晨 wrote:
> public class CrashExample {
>      private static final VarHandlebyteHandle = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_BYTE);
>      private static final long len =100;
>      private static final byte CR = (byte)'\r';
>      private static final byte LF = (byte)'\n';
>
>      public static void main(String[] args) {
>          for(int round =0; round <1000; round++) {
>              try(Arena arena = Arena.ofConfined()) {
>                  MemorySegment memorySegment = arena.allocateArray(ValueLayout.JAVA_BYTE,len);
>                  for(int i =0; i <100000; i++) {
>                      int index = i %99;
>                      byteHandle.set(memorySegment, index,CR);
>                      byteHandle.set(memorySegment, index +1,LF);
>                      byte[] bytes =readUntil(memorySegment,CR,LF);
>                  }
>              }
>          }
>      }
>
>      private static byte[]readUntil(MemorySegment segment,byte... separators) {
>          for(long cur =0; cur <= segment.byteSize() - separators.length; cur++) {
>              if(matches(segment, cur, separators)) {
>                  return segment.asSlice(0, cur).toArray(ValueLayout.JAVA_BYTE);
>              }
>          }
>          return null;
>      }
>
>      public static boolean matches(MemorySegment m,long offset,byte[] bytes) {
>          for(int index =0; index < bytes.length; index++) {
>              if ((byte)byteHandle.get(m, offset + index) != bytes[index]) {
>                  return false;
>              }
>          }
>          return true;
>      }
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20230818/d3ede32f/attachment.htm>


More information about the panama-dev mailing list