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

escape analysis generates incorrect code as of B67

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b71
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.9.0-ea"
        Java(TM) SE Runtime Environment (build 1.9.0-ea-b67)
        Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b67, mixed mode)

        FULL OS VERSION :
        Linux beast 3.13.0-49-generic #83-Ubuntu SMP Fri Apr 10 20:11:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        Reader.read(char[]) returns wrong results. -XX:-DoEscapeAnalysis is a workaround for the bug.

        THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

        THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

        REGRESSION. Last worked in version 9

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the included test program.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        Test program will fail with an assertion error:
        Exception in thread "main" java.lang.AssertionError: expected=snhkadcv, actual=s
        at ShouldWork.main(ShouldWork.java:20)

        Expected behavior is no output at all.
        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.io.IOException;
        import java.io.Reader;
        import java.io.StringReader;
        import java.util.Random;

        public class ShouldWork {
          public static void main(String args[]) throws Exception {
            // NOTE: deterministic seed, yet fails a different way each time (compile issue)
            Random random = new Random(0L);
            for (int i = 0; i < 1000000; i++) {
              String expected = randomString(random);
              Reader reader = new StringReader(expected);
              StringBuilder sb = new StringBuilder();
              int ch = 0;
              while ((ch = readChar(random, reader)) >= 0) {
                sb.append((char) ch);
              }
              String actual = sb.toString();
              if (!expected.equals(actual)) {
                throw new AssertionError("expected=" + expected + ", actual=" + actual);
              }
            }
          }
          
          // reads a single character with read(char[])
          static int readChar(Random random, Reader input) throws IOException {
            char c[] = new char[1];
            int ret = input.read(c);
            assert ret != 0;
            return ret < 0 ? ret : c[0];
          }
          
          static String randomString(Random random) {
            int length = random.nextInt(10);
            char chars[] = new char[length];
            for (int i = 0; i < chars.length; i++) {
              chars[i] = (char) (random.nextInt(26) + 'a');
            }
            return new String(chars);
          }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
         -XX:-DoEscapeAnalysis

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  roland Roland Westrelin
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: