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

C1: ShortLoopOptimizer might lift instructions before their inputs

XMLWordPrintable

    • b04
    • x86
    • generic

        A DESCRIPTION OF THE PROBLEM :
        The attached code, which is just standard Java code, causes a JVM crash.
        It can be reproduced with the code below.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached code in "TestBug" class.
        This code loops 10000 times, calling the doSomething() method each time.
        The JVM will normally crash after less than 5000 iterations.
        Most of the code needed in the doSomething() method needs to be present in order to reproduce the bug. If the if or try-catch or while is removed, the bug will not occur.
        I retained the code inside the loop in order that the loop is not empty, to avoid unnecessary optimisations.

        ACTUAL -
        JVM crashes after less than 5000 iterations.
        If I increase the value of the requiredLength argument (e.g. to 4000), then the crash occurs after less iterations.

        The content of hs_err_pid16440.log is pasted into the "Confidential Field (hs_err file)" field.

        The following was reported:

        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        # Internal Error (c1_LIRAssembler.cpp:867), pid=16440, tid=0x000011dc
        # Error: ShouldNotReachHere()
        #
        # JRE version: Java(TM) SE Runtime Environment (8.0) (build 1.8.0_361-b09)
        # Java VM: Java HotSpot(TM) Client VM (25.361-b09 mixed mode, sharing windows-x86 )
        # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
        #
        # An error report file with more information is saved as:
        # C:\<filepath>\hs_err_pid16440.log
        #
        # Compiler replay data is saved as:
        # C:\<filepath>\replay_pid16440.log
        #
        # If you would like to submit a bug report, please visit:
        # http://bugreport.java.com/bugreport/crash.jsp
        #

        ---------- BEGIN SOURCE ----------
        public class TestBug {
            private static int index = 0;

            public static void main(String[] args) {
                for (int i = 0; i < 10000; i++) {
                    doSomething(new byte[] { }, 4);
                }
            }

            private static void doSomething(byte[] source, int requiredLength) {
                System.out.println(index++);

                if (requiredLength < 0) {
                    requiredLength = 0;
                }

                boolean [] returnArray = new boolean[requiredLength];

                int index = 0;
                try {
                    for (byte b : source) {
                        if (index == returnArray.length) {
                            break;
                        }
                    }
                }
                catch (ArrayIndexOutOfBoundsException e) {
                    // ignore
                }

                while (index < returnArray.length) {
                    returnArray[index++] = false;
                }
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        If I replace the for-each loop with a standard indexed for loop, the issue does not occur.

          1. CFGAfterGenerationOfHIR.PNG
            CFGAfterGenerationOfHIR.PNG
            50 kB
          2. CFGBeforeRangeCheckElimination.PNG
            CFGBeforeRangeCheckElimination.PNG
            59 kB
          3. replay_pid3832.log
            74 kB
          4. TestBug.java
            0.9 kB
          5. x64.cfg
            42 kB
          6. x86.cfg
            22 kB

              dskantz Daniel Skantz
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              12 Start watching this issue

                Created:
                Updated:
                Resolved: