A simple optimization proposal (original) (raw)

Krystal Mok rednaxelafx at gmail.com
Thu Feb 13 00🔞59 PST 2014


Hi John,

Nice to hear from you!

I ran a couple of tests on the patch, one of them is:

public class ArrayRangeCheck { private static Object foo(Object[] a, int x) throws Exception { if (a.length == 0) throw new Exception(); return a[x & (a.length - 1)]; }

public static void main(String[] args) throws Exception { Object[] a = new Object[8]; foo(a, 6); foo(a, 6); System.in.read(); } }

Ran with:

$ java -XX:CompileCommand="compileonly ArrayRangeCheck foo" -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:CompileThreshold=1 -XX:PrintIdealGraphLevel=4 -XX:PrintIdealGraphFile=ideal.xml -XX:+PrintCompilation -XX:+PrintAssembly ArrayRangeCheck

And confirmed that in this case the range check is indeed elided: there's only one a.length != 0 check dominating the actual element load, and the else branch goes to the exception throwing code.

Thanks, Kris

On Wed, Feb 12, 2014 at 9:47 PM, John Rose <john.r.rose at oracle.com> wrote:

One point behind the bug report is to give a little reward to Java coders who write dominating tests that exclude a.length==0, as:

if (a.length == 0) goAway(); else return a[i & a.length-1]; Kris, can your patch do this? The logic in IfNode can probably elide the duplicate dominating test, if the right normalizations occur. �� – John On Feb 12, 2014, at 6:05 PM, Martin Grajcar <maaartinus at gmail.com> wrote: That's what I've meant with goAway. My point was the jump using already computed flags -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20140213/9def06c7/attachment.html



More information about the hotspot-compiler-dev mailing list