Tue, 05 Jul 2011 16:07:54 -0700
6478991: C1 NullCheckEliminator yields incorrect exceptions
Reviewed-by: twisti, iveresov
src/share/vm/c1/c1_Optimizer.cpp | file | annotate | diff | comparison | revisions | |
test/compiler/6478991/NullCheckTest.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/c1/c1_Optimizer.cpp Fri Jul 01 10:37:37 2011 -0700 1.2 +++ b/src/share/vm/c1/c1_Optimizer.cpp Tue Jul 05 16:07:54 2011 -0700 1.3 @@ -642,7 +642,7 @@ 1.4 void NullCheckVisitor::do_NewTypeArray (NewTypeArray* x) { nce()->handle_NewArray(x); } 1.5 void NullCheckVisitor::do_NewObjectArray (NewObjectArray* x) { nce()->handle_NewArray(x); } 1.6 void NullCheckVisitor::do_NewMultiArray (NewMultiArray* x) { nce()->handle_NewArray(x); } 1.7 -void NullCheckVisitor::do_CheckCast (CheckCast* x) {} 1.8 +void NullCheckVisitor::do_CheckCast (CheckCast* x) { nce()->clear_last_explicit_null_check(); } 1.9 void NullCheckVisitor::do_InstanceOf (InstanceOf* x) {} 1.10 void NullCheckVisitor::do_MonitorEnter (MonitorEnter* x) { nce()->handle_AccessMonitor(x); } 1.11 void NullCheckVisitor::do_MonitorExit (MonitorExit* x) { nce()->handle_AccessMonitor(x); }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/6478991/NullCheckTest.java Tue Jul 05 16:07:54 2011 -0700 2.3 @@ -0,0 +1,72 @@ 2.4 +/* 2.5 + * Copyright (c) 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + * 2.26 + */ 2.27 + 2.28 +/** 2.29 + * @test 2.30 + * @bug 6478991 2.31 + * @summary C1 NullCheckEliminator yields incorrect exceptions 2.32 + * 2.33 + * @run main/othervm -XX:CompileOnly=NullCheckTest.test,NullCheckTest.inlined -Xcomp NullCheckTest 2.34 + */ 2.35 + 2.36 +public class NullCheckTest { 2.37 + static class A { 2.38 + int f; 2.39 + 2.40 + public final void inlined(A a) { 2.41 + // This cast is intended to fail. 2.42 + B b = ((B) a); 2.43 + } 2.44 + } 2.45 + 2.46 + static class B extends A { 2.47 + } 2.48 + 2.49 + 2.50 + private static void test(A a1, A a2) { 2.51 + // Inlined call must do a null check on a1. 2.52 + // However, the exlipcit NullCheck instruction is eliminated and 2.53 + // the null check is folded into the field load below, so the 2.54 + // exception in the inlined method is thrown before the null check 2.55 + // and the NullPointerException is not thrown. 2.56 + a1.inlined(a2); 2.57 + 2.58 + int x = a1.f; 2.59 + } 2.60 + 2.61 + public static void main(String[] args) { 2.62 + // load classes 2.63 + new B(); 2.64 + try { 2.65 + test(null, new A()); 2.66 + 2.67 + throw new InternalError("FAILURE: no exception"); 2.68 + } catch (NullPointerException ex) { 2.69 + System.out.println("CORRECT: NullPointerException"); 2.70 + } catch (ClassCastException ex) { 2.71 + System.out.println("FAILURE: ClassCastException"); 2.72 + throw ex; 2.73 + } 2.74 + } 2.75 +}