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()) {