001/*
002 * Copyright (c) 2015, 2015, 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
027/**
028 * Collection of tests for
029 * {@link com.oracle.graal.phases.common.DominatorConditionalEliminationPhase} including those that
030 * triggered bugs in this phase.
031 */
032public class ConditionalEliminationTest7 extends ConditionalEliminationTestBase {
033
034    @SuppressWarnings("all")
035    public static int test1Snippet(int a, Object b) {
036        int sum = 0;
037        for (int j = 0;; ++j) {
038            ++sum;
039            if (b instanceof String) {
040                if (sum == 100) {
041                    break;
042                }
043            }
044        }
045        String s = (String) b;
046        return s.length() + sum;
047    }
048
049    @Test
050    public void test1() {
051        // One loop exit is skipped.
052        testProxies("test1Snippet", 1);
053    }
054
055    @SuppressWarnings("all")
056    public static int test2Snippet(int a, Object b) {
057        int sum = 0;
058        for (int j = 0;; ++j) {
059            ++sum;
060            if (b instanceof String) {
061                break;
062            }
063        }
064        String s = (String) b;
065        return s.length() + sum;
066    }
067
068    @Test
069    public void test2() {
070        // The loop exit is the anchor => no proxy necessary.
071        testProxies("test2Snippet", 0);
072    }
073
074    @SuppressWarnings("all")
075    public static int test3Snippet(int a, Object b) {
076        int sum = a;
077        outer: while (true) {
078            sum++;
079            while (sum++ != 20) {
080                while (sum++ != 30) {
081                    while (sum++ != 40) {
082                        while (sum++ != 50) {
083                            if (b instanceof String) {
084                                break outer;
085                            }
086                        }
087                    }
088                }
089            }
090        }
091        String s = (String) b;
092        return s.length() + sum;
093    }
094
095    @Test
096    public void test3() {
097        // The break skips over 4 other loops.
098        testProxies("test3Snippet", 4);
099    }
100}