Thu, 16 Jul 2009 16:29:55 -0700
6851282: JIT miscompilation results in null entry in array when using CompressedOops
Summary: Get type for new Phi from non dead path.
Reviewed-by: never
src/share/vm/opto/cfgnode.cpp | file | annotate | diff | comparison | revisions | |
test/compiler/6851282/Test.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/opto/cfgnode.cpp Thu Jul 16 14:10:42 2009 -0700 1.2 +++ b/src/share/vm/opto/cfgnode.cpp Thu Jul 16 16:29:55 2009 -0700 1.3 @@ -1796,8 +1796,12 @@ 1.4 for (uint i=1; i<req(); ++i) {// For all paths in 1.5 Node *ii = in(i); 1.6 if (ii->is_DecodeN() && ii->bottom_type() == bottom_type()) { 1.7 - has_decodeN = true; 1.8 - in_decodeN = ii->in(1); 1.9 + // Note: in_decodeN is used only to define the type of new phi. 1.10 + // Find a non dead path otherwise phi type will be wrong. 1.11 + if (ii->in(1)->bottom_type() != Type::TOP) { 1.12 + has_decodeN = true; 1.13 + in_decodeN = ii->in(1); 1.14 + } 1.15 } else if (!ii->is_Phi()) { 1.16 may_push = false; 1.17 } 1.18 @@ -1805,7 +1809,6 @@ 1.19 1.20 if (has_decodeN && may_push) { 1.21 PhaseIterGVN *igvn = phase->is_IterGVN(); 1.22 - // Note: in_decodeN is used only to define the type of new phi here. 1.23 PhiNode *new_phi = PhiNode::make_blank(in(0), in_decodeN); 1.24 uint orig_cnt = req(); 1.25 for (uint i=1; i<req(); ++i) {// For all paths in
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/6851282/Test.java Thu Jul 16 16:29:55 2009 -0700 2.3 @@ -0,0 +1,124 @@ 2.4 +/* 2.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + * 2.26 + */ 2.27 + 2.28 +/** 2.29 + * @test 2.30 + * @bug 6851282 2.31 + * @summary JIT miscompilation results in null entry in array when using CompressedOops 2.32 + * 2.33 + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops Test 2.34 + */ 2.35 + 2.36 +import java.util.ArrayList; 2.37 +import java.util.List; 2.38 + 2.39 +public class Test { 2.40 + void foo(A a, A[] as) { 2.41 + for (A a1 : as) { 2.42 + B[] filtered = a.c(a1); 2.43 + for (B b : filtered) { 2.44 + if (b == null) { 2.45 + System.out.println("bug: b == null"); 2.46 + System.exit(97); 2.47 + } 2.48 + } 2.49 + } 2.50 + } 2.51 + 2.52 + public static void main(String[] args) { 2.53 + List<A> as = new ArrayList<A>(); 2.54 + for (int i = 0; i < 5000; i++) { 2.55 + List<B> bs = new ArrayList<B>(); 2.56 + for (int j = i; j < i + 1000; j++) 2.57 + bs.add(new B(j)); 2.58 + as.add(new A(bs.toArray(new B[0]))); 2.59 + } 2.60 + new Test().foo(as.get(0), as.subList(1, as.size()).toArray(new A[0])); 2.61 + } 2.62 +} 2.63 + 2.64 +class A { 2.65 + final B[] bs; 2.66 + 2.67 + public A(B[] bs) { 2.68 + this.bs = bs; 2.69 + } 2.70 + 2.71 + final B[] c(final A a) { 2.72 + return new BoxedArray<B>(bs).filter(new Function<B, Boolean>() { 2.73 + public Boolean apply(B arg) { 2.74 + for (B b : a.bs) { 2.75 + if (b.d == arg.d) 2.76 + return true; 2.77 + } 2.78 + return false; 2.79 + } 2.80 + }); 2.81 + } 2.82 +} 2.83 + 2.84 +class BoxedArray<T> { 2.85 + 2.86 + private final T[] array; 2.87 + 2.88 + BoxedArray(T[] array) { 2.89 + this.array = array; 2.90 + } 2.91 + 2.92 + public T[] filter(Function<T, Boolean> function) { 2.93 + boolean[] include = new boolean[array.length]; 2.94 + int len = 0; 2.95 + int i = 0; 2.96 + while (i < array.length) { 2.97 + if (function.apply(array[i])) { 2.98 + include[i] = true; 2.99 + len += 1; 2.100 + } 2.101 + i += 1; 2.102 + } 2.103 + T[] result = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), len); 2.104 + len = 0; 2.105 + i = 0; 2.106 + while (len < result.length) { 2.107 + if (include[i]) { 2.108 + result[len] = array[i]; 2.109 + len += 1; 2.110 + } 2.111 + i += 1; 2.112 + } 2.113 + return result; 2.114 + } 2.115 +} 2.116 + 2.117 +interface Function<T, R> { 2.118 + R apply(T arg); 2.119 +} 2.120 + 2.121 +class B { 2.122 + final int d; 2.123 + public B(int d) { 2.124 + this.d = d; 2.125 + } 2.126 +} 2.127 +