JDK-8086046 : escape analysis generates incorrect code as of B67
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2015-06-09
  • Updated: 2015-09-10
  • Resolved: 2015-06-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b71Fixed
Related Reports
Relates :  
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


Comments
Load bypasses arraycopy that writes to it once the ArrayCopyNode is expanded
09-06-2015

Here is the email from Robert Muir: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2015-June/018186.html Testcase pass with -Xint Testcase pass with -XX:-DoEscapeAnalysis Testcase fail with any other options.
09-06-2015