NCE_01.java revision 12657:6ef01bd40ce2
1278699Sian/*
2254056Sganbold * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3254056Sganbold * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4254056Sganbold *
5278699Sian * This code is free software; you can redistribute it and/or modify it
6278699Sian * under the terms of the GNU General Public License version 2 only, as
7254056Sganbold * published by the Free Software Foundation.
8254056Sganbold *
9254056Sganbold * This code is distributed in the hope that it will be useful, but WITHOUT
10254056Sganbold * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11254056Sganbold * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12254056Sganbold * version 2 for more details (a copy is included in the LICENSE file that
13254056Sganbold * accompanied this code).
14254056Sganbold *
15254056Sganbold * You should have received a copy of the GNU General Public License version
16254056Sganbold * 2 along with this work; if not, write to the Free Software Foundation,
17254056Sganbold * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18254056Sganbold *
19254056Sganbold * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20254056Sganbold * or visit www.oracle.com if you need additional information or have any
21254056Sganbold * questions.
22254056Sganbold */
23254056Sganboldpackage org.graalvm.compiler.jtt.optimize;
24278692Sian
25254056Sganboldimport org.junit.Test;
26254056Sganbold
27278677Sianimport org.graalvm.compiler.jtt.JTTTest;
28278699Sian
29266328Sian/*
30266328Sian * Test case for null check elimination.
31278699Sian */
32266328Sianpublic class NCE_01 extends JTTTest {
33266328Sian
34278692Sian    private static class TestClass {
35266328Sian        int field1 = 22;
36278699Sian        int field2 = 23;
37278699Sian    }
38278699Sian
39278699Sian    public static TestClass object = new TestClass();
40278699Sian
41278692Sian    public static int test() {
42266328Sian        TestClass o = object;
43266328Sian        int i = o.field1;
44266328Sian        // expected null check elimination here
45278699Sian        return o.field2 + i;
46278699Sian    }
47278699Sian
48278699Sian    @Test
49266328Sian    public void run0() throws Throwable {
50266328Sian        runTest("test");
51266328Sian    }
52278692Sian
53278692Sian}
54278692Sian