001/*
002 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.compiler.test;
024
025import org.junit.*;
026
027import com.oracle.graal.compiler.test.ea.EATestBase.TestClassInt;
028
029public class ShortCircuitNodeTest extends GraalCompilerTest {
030
031    @Test
032    public void test1() {
033        // only executeActual, to avoid creating profiling information
034        executeActual(getResolvedJavaMethod("test1Snippet"), 1, 2);
035    }
036
037    public static final TestClassInt field = null;
038    public static TestClassInt field2 = null;
039
040    @SuppressWarnings("unused")
041    public static void test1Snippet(int a, int b) {
042        /*
043         * if a ShortCircuitOrNode is created for the check inside test2, then faulty handling of
044         * guards can create a cycle in the graph.
045         */
046        int v;
047        if (a == 1) {
048            if (b != 1) {
049                int i = field.x;
050            }
051            field2 = null;
052            v = 0;
053        } else {
054            v = 1;
055        }
056
057        if (test2(v, b)) {
058            int i = field.x;
059        }
060    }
061
062    public static boolean test2(int a, int b) {
063        return a != 0 || b != 1;
064    }
065}