Skip to content

Running the Java program under an OpenJ9 (JDK27) fastdebug build with -Xjit:count=0,optLevel=scorching, The results will be inconsistent #23277

@JinzeSi

Description

@JinzeSi

Environment:

  • java -Xshareclasses:none -version
    openjdk version "27-internal" 2026-09-15
    OpenJDK Runtime Environment (build 27-internal-adhoc.sjz.jdk27u-j9)
    Eclipse OpenJ9 VM (build 27-internal-adhoc.sjz.jdk27u-j9-master-f5a91e34d2, JRE 27 Linux amd64-64-Bit Compressed References 20260119_000000 (JIT enabled, AOT enabled)
    OpenJ9 - f5a91e3
    OMR - ccb25976d
    JCL - 67c6256a511 based on jdk-27+5)

  • commit: 67c6256a5110026e07e3e4e42511dfbac1eeb5f2

  • OS: Linux 5.8.0-63-generic, x86_64

  • CPU: amd64, 48 logical CPUs

  • Build GCC: 9.4

Key :

- Options:  -Xjit:count=0,optLevel=scorching  & other(-Xint or Default)

Steps to reproduce

  1. Compile the Java
    <jdk>/bin/javac  -sourcepath {$FuzzerUtils_pwd}  Test.java
    
  2. Run with OpenJ9 fastdebug build: - diff run 1:
     <jdk>/bin/java  -Xshareclasses:none  Test
    
    • diff run2 :
     <jdk>/bin/java -Xjit:count=0,optLevel=scorching -Xshareclasses:none  Test
    

Result

With -Xshareclasses:none Test, the result is:

vMeth_check_sum: 27164795110628

With -Xjit:count=0,optLevel=scorching -Xshareclasses:none Test, the result is:

vMeth_check_sum: 27164784952448

Source code

import java.util.Arrays;

class Cls1 {
    public static final int N = 128;
    public static long instanceCount = -7L;
}


public class Test {
    public static final int N = 128;
    public static long instanceCount = -6L;
    public static int iFld = 105;
    public static double dFld = 0.128051;
    public static float fFld = 0.454F;
    public static long lMeth_check_sum = 0;
    public static long vMeth_check_sum = 0;
    public static void vMeth(java.lang.String str, char c, char c1) {
        long meth_res = 0;
        double d = 15.26925;
        Object O4 = new Object();
        int iArr[] = new int[Test.N];
        FuzzerUtils.init(iArr, -7);
        iArr[(Test.iFld >>> 1) % Test.N] += Test.iFld;
        for (d = ((double) (5)); d < 125; d++) {
            synchronized(O4) {
                iArr[((int) (d))] = ((int) (7721688498509462086L));
            }
        }
        Test.vMeth_check_sum += FuzzerUtils.checkSum(iArr);
    }
    public static long lMeth(long l) {       
        long meth_res = 0;
        int i = 124;
        float f3 = 6.152F;
        for (i = ((int) (101)); i > 5; i--) {
            Test.dFld *= ((double) ((l++) + Cls.iMeth(f3, i)));
            f3 += ((float) (i));
        }
        Test.lMeth_check_sum += meth_res;
        return ((long) (meth_res));
    }
    public void mainTest(java.lang.String[] strArr1) {
        byte by = 117;
        long l2 = -8L;
        Test.iFld += ((int) (by + (Test.lMeth(l2) - Test.iFld)));
        FuzzerUtils.out.println("vMeth_check_sum: " + Test.vMeth_check_sum);
    }
    public static void main(java.lang.String[] strArr) {
       
        Test _instance = new Test();
        _instance.mainTest(strArr);
       
    }
}// DEBUG  static objects = {}

class Cls extends Test {
    public static final int N = 128;
    public static long instanceCount = -5497L;
    public static char cFld = 17356;
    public static volatile java.lang.String strFld = "two";
    public static volatile byte byFld = -60;
    public static long iMeth_check_sum = 0;
    public static int iMeth(float f, int i2) {
        long meth_res = 0;
        int i3 = 60;
        int i4 = 8;
        int i5 = 95;
        for (i3 = ((int) (2)); i3 < 10; i3 += 2) {
            for (i5 = ((int) (27)); i5 > 1; --i5) {
                Cls.cFld = ((char) ((-i3) + Cls.instanceCount));
                Test.iFld += i4;
                Test.vMeth(Cls.strFld, ((char) (Cls.cFld)), ((char) (24418)));
            }
            Cls.instanceCount = ((long) (i2));
        }
        return ((int) (meth_res));
    }
}

FuzzerUtils.java


import java.util.concurrent.atomic.AtomicLong;
import java.io.PrintStream;
import java.util.Random;



public class FuzzerUtils {

    public static PrintStream out = System.out;
    public static PrintStream err = System.err;
    public static Random random = new Random(1);
    public static long seed = 1L;
    public static int UnknownZero = 0;

    // Init seed
    public static void seed(long seed){
        random = new Random(seed);
        FuzzerUtils.seed = seed;
    }

    public static int nextInt(){
        return random.nextInt();
    }
    public static long nextLong(){
        return random.nextLong();
    }
    public static float nextFloat(){
        return random.nextFloat();
    }
    public static double nextDouble(){
        return random.nextDouble();
    }
    public static boolean nextBoolean(){
        return random.nextBoolean();
    }
    public static byte nextByte(){
        return (byte)random.nextInt();
    }
    public static short nextShort(){
        return (short)random.nextInt();
    }
    public static char nextChar(){
        return (char)random.nextInt();
    }

    // Array initialization

    // boolean -----------------------------------------------
    public static void init(boolean[] a, boolean seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (j % 2 == 0) ? seed : (j % 3 == 0);
        }
    }

    public static void init(boolean[][] a, boolean seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Boolean -----------------------------------------------
    public static void init(Boolean[] a, Boolean seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Boolean.valueOf((j % 2 == 0) ? seed : (j % 3 == 0));
        }
    }

    public static void init(Boolean[][] a, Boolean seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // long --------------------------------------------------
    public static void init(long[] a, long seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (j % 2 == 0) ? seed + j : seed - j;
        }
    }

    public static void init(long[][] a, long seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Long --------------------------------------------------
    public static void init(Long[] a, Long seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Long.valueOf((long)((j % 2 == 0) ? seed + j : seed - j));
        }
    }

    public static void init(Long[][] a, Long seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // int --------------------------------------------------
    public static void init(int[] a, int seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (j % 2 == 0) ? seed + j : seed - j;
        }
    }

    public static void init(int[][] a, int seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Integer --------------------------------------------------
    public static void init(Integer[] a, Integer seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Integer.valueOf((j % 2 == 0) ? seed + j : seed - j);
        }
    }

    public static void init(Integer[][] a, Integer seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // short --------------------------------------------------
    public static void init(short[] a, short seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (short) ((j % 2 == 0) ? seed + j : seed - j);
        }
    }

    public static void init(short[][] a, short seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Short --------------------------------------------------
    public static void init(Short[] a, Short seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Short.valueOf((short) ((j % 2 == 0) ? seed + j : seed - j));
        }
    }

    public static void init(Short[][] a, Short seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // char --------------------------------------------------
    public static void init(char[] a, char seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (char) ((j % 2 == 0) ? seed + j : seed - j);
        }
    }

    public static void init(char[][] a, char seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Character --------------------------------------------------
    public static void init(Character[] a, Character seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Character.valueOf((char) ((j % 2 == 0) ? seed + j : seed - j));
        }
    }

    public static void init(Character[][] a, Character seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // byte --------------------------------------------------
    public static void init(byte[] a, byte seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (byte) ((j % 2 == 0) ? seed + j : seed - j);
        }
    }

    public static void init(byte[][] a, byte seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Byte --------------------------------------------------
    public static void init(Byte[] a, Byte seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Byte.valueOf((byte) ((j % 2 == 0) ? seed + j : seed - j));
        }
    }

    public static void init(Byte[][] a, Byte seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // double --------------------------------------------------
    public static void init(double[] a, double seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (j % 2 == 0) ? seed + j : seed - j;
        }
    }

    public static void init(double[][] a, double seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Double --------------------------------------------------
    public static void init(Double[] a, Double seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Double.valueOf((j % 2 == 0) ? seed + j : seed - j);
        }
    }

    public static void init(Double[][] a, Double seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // float --------------------------------------------------
    public static void init(float[] a, float seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = (j % 2 == 0) ? seed + j : seed - j;
        }
    }

    public static void init(float[][] a, float seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Float --------------------------------------------------
    public static void init(Float[] a, Float seed) {
        for (int j = 0; j < a.length; j++) {
            a[j] = Float.valueOf((j % 2 == 0) ? seed + j : seed - j);
        }
    }

    public static void init(Float[][] a, Float seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    // Object -------------------------------------------------
    public static void init(Object[][] a, Object seed) {
        for (int j = 0; j < a.length; j++) {
            init(a[j], seed);
        }
    }

    public static void init(Object[] a, Object seed) {
        for (int j = 0; j < a.length; j++)
            try {
                a[j] = seed.getClass().getDeclaredConstructor().newInstance();
            } catch (Exception ex) {
                a[j] = seed;
            }
    }

    // Calculate array checksum

    // boolean -----------------------------------------------
    public static long checkSum(boolean[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (a[j] ? j + 1 : 0);
        }
        return sum;
    }

    public static long checkSum(boolean[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // long --------------------------------------------------
    public static long checkSum(long[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static long checkSum(long[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // int --------------------------------------------------
    public static long checkSum(int[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static long checkSum(int[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // short --------------------------------------------------
    public static long checkSum(short[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (short) (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static long checkSum(short[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // char --------------------------------------------------
    public static long checkSum(char[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (char) (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static long checkSum(char[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // byte --------------------------------------------------
    public static long checkSum(byte[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (byte) (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static long checkSum(byte[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // double --------------------------------------------------
    public static double checkSum(double[] a) {
        double sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static double checkSum(double[][] a) {
        double sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // float --------------------------------------------------
    public static double checkSum(float[] a) {
        double sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += (a[j] / (j + 1) + a[j] % (j + 1));
        }
        return sum;
    }

    public static double checkSum(float[][] a) {
        double sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    // Object --------------------------------------------------
    public static long checkSum(Object[][] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]);
        }
        return sum;
    }

    public static long checkSum(Object[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++) {
            sum += checkSum(a[j]) * Math.pow(2, j);
        }
        return sum;
    }

    public static long checkSum(Object a) {
        if (a == null)
            return 0L;
        return (long) a.getClass().getCanonicalName().length();
    }

    // Array creation ------------------------------------------
    public static byte[] byte1array(int sz, byte seed) {
        byte[] ret = new byte[sz];
        init(ret, seed);
        return ret;
    }

    public static byte[][] byte2array(int sz, byte seed) {
        byte[][] ret = new byte[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Byte[] Byte1array(int sz, Byte seed) {
        Byte[] ret = new Byte[sz];
        init(ret, seed);
        return ret;
    }

    public static Byte[][] Byte2array(int sz, Byte seed) {
        Byte[][] ret = new Byte[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static short[] short1array(int sz, short seed) {
        short[] ret = new short[sz];
        init(ret, seed);
        return ret;
    }

    public static short[][] short2array(int sz, short seed) {
        short[][] ret = new short[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Short[] Short1array(int sz, Short seed) {
        Short[] ret = new Short[sz];
        init(ret, seed);
        return ret;
    }

    public static Short[][] Short2array(int sz, Short seed) {
        Short[][] ret = new Short[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static int[] int1array(int sz, int seed) {
        int[] ret = new int[sz];
        init(ret, seed);
        return ret;
    }

    public static int[][] int2array(int sz, int seed) {
        int[][] ret = new int[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Integer[] Integer1array(int sz, Integer seed) {
        Integer[] ret = new Integer[sz];
        init(ret, seed);
        return ret;
    }

    public static Integer[][] Integer2array(int sz, Integer seed) {
        Integer[][] ret = new Integer[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static long[] long1array(int sz, long seed) {
        long[] ret = new long[sz];
        init(ret, seed);
        return ret;
    }

    public static long[][] long2array(int sz, long seed) {
        long[][] ret = new long[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Long[] Long1array(int sz, Long seed) {
        Long[] ret = new Long[sz];
        init(ret, seed);
        return ret;
    }

    public static Long[][] Long2array(int sz, Long seed) {
        Long[][] ret = new Long[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static float[] float1array(int sz, float seed) {
        float[] ret = new float[sz];
        init(ret, seed);
        return ret;
    }

    public static float[][] float2array(int sz, float seed) {
        float[][] ret = new float[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Float[] Float1array(int sz, Float seed) {
        Float[] ret = new Float[sz];
        init(ret, seed);
        return ret;
    }

    public static Float[][] Float2array(int sz, Float seed) {
        Float[][] ret = new Float[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static double[] double1array(int sz, double seed) {
        double[] ret = new double[sz];
        init(ret, seed);
        return ret;
    }

    public static double[][] double2array(int sz, double seed) {
        double[][] ret = new double[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Double[] Double1array(int sz, Double seed) {
        Double[] ret = new Double[sz];
        init(ret, seed);
        return ret;
    }

    public static Double[][] Double2array(int sz, Double seed) {
        Double[][] ret = new Double[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static char[] char1array(int sz, char seed) {
        char[] ret = new char[sz];
        init(ret, seed);
        return ret;
    }

    public static char[][] char2array(int sz, char seed) {
        char[][] ret = new char[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Character[] Character1array(int sz, Character seed) {
        Character[] ret = new Character[sz];
        init(ret, seed);
        return ret;
    }

    public static Character[][] Character2array(int sz, Character seed) {
        Character[][] ret = new Character[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Object[] Object1array(int sz, Object seed) {
        Object[] ret = new Object[sz];
        init(ret, seed);
        return ret;
    }

    public static Object[][] Object2array(int sz, Object seed) {
        Object[][] ret = new Object[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static boolean[] boolean1array(int sz, boolean seed) {
        boolean[] ret = new boolean[sz];
        init(ret, seed);
        return ret;
    }

    public static boolean[][] boolean2array(int sz, boolean seed) {
        boolean[][] ret = new boolean[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static Boolean[] Boolean1array(int sz, Boolean seed) {
        Boolean[] ret = new Boolean[sz];
        init(ret, seed);
        return ret;
    }

    public static Boolean[][] Boolean2array(int sz, Boolean seed) {
        Boolean[][] ret = new Boolean[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static String[] String1array(int sz, String seed) {
        String[] ret = new String[sz];
        init(ret, seed);
        return ret;
    }

    public static String[][] String2array(int sz, String seed) {
        String[][] ret = new String[sz][sz];
        init(ret, seed);
        return ret;
    }

    public static AtomicLong runningThreads = new AtomicLong(0);

    public static synchronized void runThread(Runnable r) {
        final Thread t = new Thread(r);
        t.start();
        runningThreads.incrementAndGet();
        Thread t1 = new Thread(new Runnable() {
            public void run() {
                try {
                    t.join();
                    runningThreads.decrementAndGet();
                } catch (InterruptedException e) {
                }
            }
        });
        t1.start();
    }

    public static void joinThreads() {
        while (runningThreads.get() > 0) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
    }
}


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions