2617N/A/*
2617N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2617N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2617N/A *
2617N/A * This code is free software; you can redistribute it and/or modify it
2617N/A * under the terms of the GNU General Public License version 2 only, as
2617N/A * published by the Free Software Foundation.
2617N/A *
2617N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2617N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2617N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2617N/A * version 2 for more details (a copy is included in the LICENSE file that
2617N/A * accompanied this code).
2617N/A *
2617N/A * You should have received a copy of the GNU General Public License version
2617N/A * 2 along with this work; if not, write to the Free Software Foundation,
2617N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2617N/A *
2617N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2617N/A * or visit www.oracle.com if you need additional information or have any
2617N/A * questions.
2617N/A *
2617N/A */
2617N/A
2617N/A/**
2617N/A * @test
2617N/A * @bug 6478991
2617N/A * @summary C1 NullCheckEliminator yields incorrect exceptions
2617N/A *
2617N/A * @run main/othervm -XX:CompileOnly=NullCheckTest.test,NullCheckTest.inlined -Xcomp NullCheckTest
2617N/A */
2617N/A
2617N/Apublic class NullCheckTest {
2617N/A static class A {
2617N/A int f;
2617N/A
2617N/A public final void inlined(A a) {
2617N/A // This cast is intended to fail.
2617N/A B b = ((B) a);
2617N/A }
2617N/A }
2617N/A
2617N/A static class B extends A {
2617N/A }
2617N/A
2617N/A
2617N/A private static void test(A a1, A a2) {
2617N/A // Inlined call must do a null check on a1.
2617N/A // However, the exlipcit NullCheck instruction is eliminated and
2617N/A // the null check is folded into the field load below, so the
2617N/A // exception in the inlined method is thrown before the null check
2617N/A // and the NullPointerException is not thrown.
2617N/A a1.inlined(a2);
2617N/A
2617N/A int x = a1.f;
2617N/A }
2617N/A
2617N/A public static void main(String[] args) {
2617N/A // load classes
2617N/A new B();
2617N/A try {
2617N/A test(null, new A());
2617N/A
2617N/A throw new InternalError("FAILURE: no exception");
2617N/A } catch (NullPointerException ex) {
2617N/A System.out.println("CORRECT: NullPointerException");
2617N/A } catch (ClassCastException ex) {
2617N/A System.out.println("FAILURE: ClassCastException");
2617N/A throw ex;
2617N/A }
2617N/A }
2617N/A}