Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The nightly build (jdk-9+181-20 on January 22 2018) has different behaviors on Xcomp and default mode. #997

Open
tianxiaogu opened this issue Jan 22, 2018 · 9 comments

Comments

@tianxiaogu
Copy link

tianxiaogu commented Jan 22, 2018

The nightly build (jdk-9+181-20 on January 22 2018 Linux x64) has different behaviors on Xcomp and default mode.

C0.class

Default:
A NegativeArraySizeException is thrown

Xcomp:
exit normally with 0

$ ./jdk-9+181/bin/java -Xcomp C0
$ echo $?
0
$ ./jdk-9+181/bin/java C0
Exception in thread "main" java.lang.NegativeArraySizeException
	at C0.main(Unknown Source)
$ ./jdk-9+181/bin/java --version
openjdk 9-internal
OpenJDK Runtime Environment (build 9-internal+0-adhoc.jenkins.openjdk)
Eclipse OpenJ9 VM (build 2.9, JRE 9 Linux amd64-64 Compressed References 20180122_95 (JIT enabled, AOT enabled)
OpenJ9   - d38352e
OMR      - cfd2f17
OpenJDK  - be5903d based on jdk-9+181)

The head of OpenJDK throws an exception.

$ ./openjdk/jdk/build/linux-x86_64-normal-server-release/jdk/bin/java -Xcomp C0
Exception in thread "main" java.lang.NegativeArraySizeException
	at C0.main(Unknown Source)
$ ./openjdk/jdk/build/linux-x86_64-normal-server-release/jdk/bin/java -version
openjdk version "10-internal" 2018-03-20
OpenJDK Runtime Environment (build 10-internal+0-adhoc.t.jdk)
OpenJDK 64-Bit Server VM (build 10-internal+0-adhoc.t.jdk, mixed mode)

Oracle JDK 9 throws an exception.

$ ./jdk-9.0.4/bin/java -Xcomp C0
Exception in thread "main" java.lang.NegativeArraySizeException
	at C0.main(Unknown Source)
$ ./jdk-9.0.4/bin/java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

OpenJDK 8 also throws an exception.

$ java C0
Exception in thread "main" java.lang.NegativeArraySizeException
	at C0.main(Unknown Source)
$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
@pshipton
Copy link
Contributor

pshipton commented Jan 22, 2018

-Xcomp is mapped to -Xjit:count=0

The OpenJDK definition is -Xcomp forces compilation of methods on first invocation

@tianxiaogu
Copy link
Author

@pshipton Thanks for your reply. I am not sure whether this is a bug or not. I have attached the program C0.class (via Google Drive) now.

BTW, C0.class is generated by a fuzzing tool I created. So I cannot provide its source code.

@mstoodle
Copy link
Contributor

@andrewcraik i wonder if you or your delegate would like to take a look at this one?

@tianxiaogu
Copy link
Author

tianxiaogu commented Jan 27, 2018

@andrewcraik Sorry, this may not be an issue. It seems that the optimization of OpenJ9 removes the unused allocation, while HotSpot does not.

The JVM specification specifies that anewarray and newarray should throw a NegativeSizeException if the size is negative. Removing unused array allocation may break the specification of JVM.

https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.anewarray

@JamesKingdon
Copy link
Contributor

Thanks for the interesting test case @tianxiaogu This may need some thought.

Trivial cases have the expected behaviour, e.g.

      short s = -1;
      double[] da = new double[s];

gives the expected Exception in thread "main" java.lang.NegativeArraySizeException
However, a conversion chain on the size prevents the JIT from realizing that an exception will always be thrown, and then the allocation of the unused array gets optimized away:

public class NegArrayRepro
{
   public static void main(String[] args)
   {
      float a = -1.0f;
      int i = (int) a;
      short s = (short) i;
      double[] da = new double[s];
      
      System.out.println("done, with s "+s);
   }
}

results in

java -Xcomp NegArrayRepro 
done, with s -1

@andrewcraik
Copy link
Contributor

@JamesKingdon interesting - the main issue will likely be that we can't tell that the float is negative. A compile log will be necessary. It would be good to confirm the opt level this failed at and, if it is a cold compile, see what happens in the warm compile. Regardless, there is a bug to be fixed here.

@JamesKingdon
Copy link
Contributor

Compilation was at warm, I will attach the log. The newarray was eliminated at line 1508 by deadTreesElimination.
main.log.txt

@DanHeidinga DanHeidinga added this to User Raised issues in Issue tracking Feb 14, 2018
@DanHeidinga
Copy link
Member

@JamesKingdon / @andrewcraik Any updates on this?

@JamesKingdon
Copy link
Contributor

Hi Dan, nothing to the best of my knowledge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Issue tracking
User Raised issues
Development

No branches or pull requests

6 participants