annotate test/compiler/6478991/NullCheckTest.java @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents 15559220ce79
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3792
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
1 /*
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
4 *
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
7 * published by the Free Software Foundation.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
8 *
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
13 * accompanied this code).
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
14 *
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
18 *
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
21 * questions.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
22 *
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
23 */
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
24
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
25 /**
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
26 * @test
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
27 * @bug 6478991
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
28 * @summary C1 NullCheckEliminator yields incorrect exceptions
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
29 *
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
30 * @run main/othervm -XX:CompileOnly=NullCheckTest.test,NullCheckTest.inlined -Xcomp NullCheckTest
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
31 */
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
32
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
33 public class NullCheckTest {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
34 static class A {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
35 int f;
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
36
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
37 public final void inlined(A a) {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
38 // This cast is intended to fail.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
39 B b = ((B) a);
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
40 }
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
41 }
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
42
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
43 static class B extends A {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
44 }
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
45
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
46
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
47 private static void test(A a1, A a2) {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
48 // Inlined call must do a null check on a1.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
49 // However, the exlipcit NullCheck instruction is eliminated and
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
50 // the null check is folded into the field load below, so the
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
51 // exception in the inlined method is thrown before the null check
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
52 // and the NullPointerException is not thrown.
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
53 a1.inlined(a2);
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
54
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
55 int x = a1.f;
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
56 }
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
57
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
58 public static void main(String[] args) {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
59 // load classes
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
60 new B();
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
61 try {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
62 test(null, new A());
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
63
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
64 throw new InternalError("FAILURE: no exception");
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
65 } catch (NullPointerException ex) {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
66 System.out.println("CORRECT: NullPointerException");
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
67 } catch (ClassCastException ex) {
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
68 System.out.println("FAILURE: ClassCastException");
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
69 throw ex;
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
70 }
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
71 }
15559220ce79 6478991: C1 NullCheckEliminator yields incorrect exceptions
never
parents:
diff changeset
72 }