ConditionalEliminationTest7.java revision 12968:4d8a004e5c6d
1/* 2 * Copyright (c) 2015, 2015, 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 */ 23package org.graalvm.compiler.core.test; 24 25import org.junit.Ignore; 26import org.junit.Test; 27 28/** 29 * Collection of tests for 30 * {@link org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase} including those 31 * that triggered bugs in this phase. 32 */ 33@Ignore 34public class ConditionalEliminationTest7 extends ConditionalEliminationTestBase { 35 36 @SuppressWarnings("all") 37 public static int test1Snippet(int a, Object b) { 38 int sum = 0; 39 for (int j = 0;; ++j) { 40 ++sum; 41 if (b instanceof String) { 42 if (sum == 100) { 43 break; 44 } 45 } 46 } 47 String s = (String) b; 48 return s.length() + sum; 49 } 50 51 @Test 52 public void test1() { 53 // One loop exit is skipped. 54 testProxies("test1Snippet", 1); 55 } 56 57 @SuppressWarnings("all") 58 public static int test2Snippet(int a, Object b) { 59 int sum = 0; 60 for (int j = 0;; ++j) { 61 ++sum; 62 if (b instanceof String) { 63 break; 64 } 65 } 66 String s = (String) b; 67 return s.length() + sum; 68 } 69 70 @Test 71 public void test2() { 72 // The loop exit is the anchor => no proxy necessary. 73 testProxies("test2Snippet", 0); 74 } 75 76 @SuppressWarnings("all") 77 public static int test3Snippet(int a, Object b) { 78 int sum = a; 79 outer: while (true) { 80 sum++; 81 while (sum++ != 20) { 82 while (sum++ != 30) { 83 while (sum++ != 40) { 84 while (sum++ != 50) { 85 if (b instanceof String) { 86 break outer; 87 } 88 } 89 } 90 } 91 } 92 } 93 String s = (String) b; 94 return s.length() + sum; 95 } 96 97 @Test 98 public void test3() { 99 // The break skips over 4 other loops. 100 testProxies("test3Snippet", 4); 101 } 102} 103