Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8357782

JVM JIT Causes Static Initialization Order Issue

XMLWordPrintable

    • b03

        ADDITIONAL SYSTEM INFORMATION :
        $ <JAVA_HOME>/bin/java -version
        openjdk version "25-internal" 2025-09-16
        OpenJDK Runtime Environment (fastdebug build 25-internal-adhoc.user.jdk-mainline)
        OpenJDK 64-Bit Server VM (fastdebug build 25-internal-adhoc.user.jdk-mainline, mixed mode)

        A DESCRIPTION OF THE PROBLEM :
        We encountered an inconsistency when running the following testcase on the JVM. The code below is the minimized version that can reproduce the issue. When we execute the code directly (with JIT disabled), the output is Helloover. However, when we run it with the -Xcomp option to force JIT compilation, the output becomes nullover. Based on the logic in the code, this may be related to the execution order of static blocks. This seems to be a JIT-related issue.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac Test.java
        java Test
        java -Xcomp Test

        ACTUAL -
        nullover


        ---------- BEGIN SOURCE ----------
        class Test {
            public static void main(String[] strArr) {
                Cr.Ci.main(new String[] {});
                System.out.println("over");
            }
        }

        class Cr {
            class Ci {
                static String field;

                static void main(String[] args) {
                    String v0 = field;
                    new Ci_sta(field);
                }
            }

            static class Ci_sta {
                static {
                    Ci.field = "Hello";
                }

                Ci_sta(String arg1) {
                    System.out.print(arg1);
                }
            }
        }

        ---------- END SOURCE ----------

        FREQUENCY : always


              mhaessig Manuel Hässig
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: