JDK-8310127 : Crash in C1 compiled code for always throwing loop body
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 16,17,19.0.2,20.0.1
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2023-06-15
  • Updated: 2023-06-21
  • Resolved: 2023-06-15
Related Reports
Duplicate :  
Description
Originally reported against Graal https://github.com/oracle/graal/issues/6351 .

The following code segfaults in C1 compiled code (with regular tiered or stop at tiered=1) 

########
class T2 {
  void v(int p, byte o, int q) {
    int[] g = {};
    int[] y = {};
    int k = 1214167904;
    try {
      for (int z = 1; z < k; z++) g[z] = y[z + k];
    } catch (Throwable x) {
    } finally {
    }
  }

  void b() {
    for (int i = 2; ; ) v(40049, (byte) 35, i);
  }

  public static void main(String[] g) {
    new T2().b();
  }
}
########

Since this does not reproduce >=21 I am not sure if its fixed already. I could not find a similar issue, yet I dont know c1 internals so might have looked for the wrong things. Please close if its a duplicate.

Reproduce with just running ./jdk-20.0.1/bin/java   -XX:+PrintCompilation  T2

yielding

     11    1       3       java.lang.Object::<init> (1 bytes)
     11    2       3       java.lang.String::coder (15 bytes)
     14    3       3       java.lang.ArrayIndexOutOfBoundsException::<init> (6 bytes)
     14    4       3       java.lang.IndexOutOfBoundsException::<init> (6 bytes)
     14    6     n 0       java.lang.Throwable::fillInStackTrace (native)   
     14    5  s    3       java.lang.Throwable::fillInStackTrace (29 bytes)
     15    8       3       java.lang.Throwable::<init> (34 bytes)
     15    7   !   3       T2::v (57 bytes)

from jdk 21 onwards (tested 21 and 22) 
./jdk-21/bin/java   -XX:+PrintCompilation  T2
     10    1       3       java.lang.Object::<init> (1 bytes)
     11    2       3       java.lang.String::coder (15 bytes)
     13    3       3       java.lang.ArrayIndexOutOfBoundsException::<init> (6 bytes)
     14    4       3       java.lang.IndexOutOfBoundsException::<init> (6 bytes)
     14    6     n 0       java.lang.Throwable::fillInStackTrace (native)   
     14    7   !   3       T2::v (57 bytes)
     14    8       3       java.lang.Throwable::<init> (34 bytes)
     14    5  s    3       java.lang.Throwable::fillInStackTrace (29 bytes)
     35    9   !   4       T2::v (57 bytes)
     35    7   !   3       T2::v (57 bytes)   made not entrant
     36   10 %     3       T2::b @ 2 (14 bytes)
     37   11       3       T2::b (14 bytes)
     37   12 %     4       T2::b @ 2 (14 bytes)
     38   10 %     3       T2::b @ 2 (14 bytes)   made not entrant

compilations are slightly different so not sure if the issue is actually fixed or timing dependent and went away >=21.