1 /*
2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 
25 package org.graalvm.compiler.core.test;
26 
27 import org.junit.Ignore;
28 import org.junit.Test;
29 
30 /**
31  * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase}
32  * including those that triggered bugs in this phase.
33  */
34 @Ignore
35 public class ConditionalEliminationTest7 extends ConditionalEliminationTestBase {
36 
37     @SuppressWarnings("all")
test1Snippet(int a, Object b)38     public static int test1Snippet(int a, Object b) {
39         int sum = 0;
40         for (int j = 0;; ++j) {
41             ++sum;
42             if (b instanceof String) {
43                 if (sum == 100) {
44                     break;
45                 }
46             }
47         }
48         String s = (String) b;
49         return s.length() + sum;
50     }
51 
52     @Test
test1()53     public void test1() {
54         // One loop exit is skipped.
55         testProxies("test1Snippet", 1);
56     }
57 
58     @SuppressWarnings("all")
test2Snippet(int a, Object b)59     public static int test2Snippet(int a, Object b) {
60         int sum = 0;
61         for (int j = 0;; ++j) {
62             ++sum;
63             if (b instanceof String) {
64                 break;
65             }
66         }
67         String s = (String) b;
68         return s.length() + sum;
69     }
70 
71     @Test
test2()72     public void test2() {
73         // The loop exit is the anchor => no proxy necessary.
74         testProxies("test2Snippet", 0);
75     }
76 
77     @SuppressWarnings("all")
test3Snippet(int a, Object b)78     public static int test3Snippet(int a, Object b) {
79         int sum = a;
80         outer: while (true) {
81             sum++;
82             while (sum++ != 20) {
83                 while (sum++ != 30) {
84                     while (sum++ != 40) {
85                         while (sum++ != 50) {
86                             if (b instanceof String) {
87                                 break outer;
88                             }
89                         }
90                     }
91                 }
92             }
93         }
94         String s = (String) b;
95         return s.length() + sum;
96     }
97 
98     @Test
test3()99     public void test3() {
100         // The break skips over 4 other loops.
101         testProxies("test3Snippet", 4);
102     }
103 }
104