Thu, 24 Apr 2008 14:02:13 -0700
6646019: array subscript expressions become top() with -d64
Summary: stop compilation after negative array allocation
Reviewed-by: never, jrose
src/share/vm/opto/parse2.cpp | file | annotate | diff | comparison | revisions | |
test/compiler/6646019/Test.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/opto/parse2.cpp Thu Apr 24 11:13:03 2008 -0700 1.2 +++ b/src/share/vm/opto/parse2.cpp Thu Apr 24 14:02:13 2008 -0700 1.3 @@ -105,10 +105,19 @@ 1.4 if (GenerateRangeChecks && need_range_check) { 1.5 // Range is constant in array-oop, so we can use the original state of mem 1.6 Node* len = load_array_length(ary); 1.7 - // Test length vs index (standard trick using unsigned compare) 1.8 - Node* chk = _gvn.transform( new (C, 3) CmpUNode(idx, len) ); 1.9 - BoolTest::mask btest = BoolTest::lt; 1.10 - Node* tst = _gvn.transform( new (C, 2) BoolNode(chk, btest) ); 1.11 + Node* tst; 1.12 + if (sizetype->_hi <= 0) { 1.13 + // If the greatest array bound is negative, we can conclude that we're 1.14 + // compiling unreachable code, but the unsigned compare trick used below 1.15 + // only works with non-negative lengths. Instead, hack "tst" to be zero so 1.16 + // the uncommon_trap path will always be taken. 1.17 + tst = _gvn.intcon(0); 1.18 + } else { 1.19 + // Test length vs index (standard trick using unsigned compare) 1.20 + Node* chk = _gvn.transform( new (C, 3) CmpUNode(idx, len) ); 1.21 + BoolTest::mask btest = BoolTest::lt; 1.22 + tst = _gvn.transform( new (C, 2) BoolNode(chk, btest) ); 1.23 + } 1.24 // Branch to failure if out of bounds 1.25 { BuildCutout unless(this, tst, PROB_MAX); 1.26 if (C->allow_range_check_smearing()) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/6646019/Test.java Thu Apr 24 14:02:13 2008 -0700 2.3 @@ -0,0 +1,51 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2.6 + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 2.7 + * 2.8 + * 2.9 + * 2.10 + * 2.11 + * 2.12 + * 2.13 + * 2.14 + * 2.15 + * 2.16 + * 2.17 + * 2.18 + * 2.19 + * 2.20 + * 2.21 + * 2.22 + * 2.23 + * 2.24 + * 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6646019 2.30 + * @summary array subscript expressions become top() with -d64 2.31 + * @run main/othervm -Xcomp -XX:CompileOnly=Test.test Test 2.32 +*/ 2.33 + 2.34 + 2.35 +public class Test { 2.36 + final static int i = 2076285318; 2.37 + long l = 2; 2.38 + short s; 2.39 + 2.40 + public static void main(String[] args) { 2.41 + Test t = new Test(); 2.42 + try { t.test(); } 2.43 + catch (Throwable e) { 2.44 + if (t.l != 5) { 2.45 + System.out.println("Fails: " + t.l + " != 5"); 2.46 + } 2.47 + } 2.48 + } 2.49 + 2.50 + private void test() { 2.51 + l = 5; 2.52 + l = (new short[(byte)-2])[(byte)(l = i)]; 2.53 + } 2.54 +}