Open tianxiaogu opened 6 years ago
-Xcomp
is mapped to -Xjit:count=0
The OpenJDK definition is -Xcomp forces compilation of methods on first invocation
@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.
@andrewcraik i wonder if you or your delegate would like to take a look at this one?
@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
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
@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.
Compilation was at warm, I will attach the log. The newarray was eliminated at line 1508 by deadTreesElimination. main.log.txt
@JamesKingdon / @andrewcraik Any updates on this?
Hi Dan, nothing to the best of my knowledge.
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
The head of OpenJDK throws an exception.
Oracle JDK 9 throws an exception.
OpenJDK 8 also throws an exception.