ConditionalEliminationTest7.java revision 12651:6ef01bd40ce2
1184610Salfred/* 2184610Salfred * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3184610Salfred * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4184610Salfred * 5184610Salfred * This code is free software; you can redistribute it and/or modify it 6184610Salfred * under the terms of the GNU General Public License version 2 only, as 7184610Salfred * published by the Free Software Foundation. 8184610Salfred * 9184610Salfred * This code is distributed in the hope that it will be useful, but WITHOUT 10184610Salfred * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11184610Salfred * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12184610Salfred * version 2 for more details (a copy is included in the LICENSE file that 13184610Salfred * accompanied this code). 14184610Salfred * 15184610Salfred * You should have received a copy of the GNU General Public License version 16184610Salfred * 2 along with this work; if not, write to the Free Software Foundation, 17184610Salfred * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18184610Salfred * 19184610Salfred * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20184610Salfred * or visit www.oracle.com if you need additional information or have any 21184610Salfred * questions. 22184610Salfred */ 23184610Salfredpackage org.graalvm.compiler.core.test; 24184610Salfred 25184610Salfredimport org.junit.Test; 26184610Salfred 27184610Salfred/** 28184610Salfred * Collection of tests for 29184610Salfred * {@link org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase} including those 30184610Salfred * that triggered bugs in this phase. 31184610Salfred */ 32184610Salfredpublic class ConditionalEliminationTest7 extends ConditionalEliminationTestBase { 33184610Salfred 34184610Salfred @SuppressWarnings("all") 35184610Salfred public static int test1Snippet(int a, Object b) { 36184610Salfred int sum = 0; 37184610Salfred for (int j = 0;; ++j) { 38184610Salfred ++sum; 39184610Salfred if (b instanceof String) { 40194677Sthompsa if (sum == 100) { 41194677Sthompsa break; 42194677Sthompsa } 43194677Sthompsa } 44194677Sthompsa } 45194677Sthompsa String s = (String) b; 46194677Sthompsa return s.length() + sum; 47194677Sthompsa } 48194677Sthompsa 49194677Sthompsa @Test 50194677Sthompsa public void test1() { 51194677Sthompsa // One loop exit is skipped. 52194677Sthompsa testProxies("test1Snippet", 1); 53194677Sthompsa } 54194677Sthompsa 55194677Sthompsa @SuppressWarnings("all") 56194677Sthompsa public static int test2Snippet(int a, Object b) { 57194677Sthompsa int sum = 0; 58194677Sthompsa for (int j = 0;; ++j) { 59194677Sthompsa ++sum; 60194677Sthompsa if (b instanceof String) { 61194677Sthompsa break; 62188746Sthompsa } 63184610Salfred } 64184610Salfred String s = (String) b; 65188942Sthompsa return s.length() + sum; 66188942Sthompsa } 67184610Salfred 68188942Sthompsa @Test 69184610Salfred public void test2() { 70207077Sthompsa // The loop exit is the anchor => no proxy necessary. 71184610Salfred testProxies("test2Snippet", 0); 72184610Salfred } 73227309Sed 74192502Sthompsa @SuppressWarnings("all") 75184610Salfred public static int test3Snippet(int a, Object b) { 76184610Salfred int sum = a; 77184610Salfred outer: while (true) { 78184610Salfred sum++; 79184610Salfred while (sum++ != 20) { 80184610Salfred while (sum++ != 30) { 81184610Salfred while (sum++ != 40) { 82184610Salfred while (sum++ != 50) { 83184610Salfred if (b instanceof String) { 84184610Salfred break outer; 85184610Salfred } 86184610Salfred } 87184610Salfred } 88184610Salfred } 89184610Salfred } 90184610Salfred } 91184610Salfred String s = (String) b; 92184610Salfred return s.length() + sum; 93184610Salfred } 94184610Salfred 95184610Salfred @Test 96184610Salfred public void test3() { 97184610Salfred // The break skips over 4 other loops. 98184610Salfred testProxies("test3Snippet", 4); 99184610Salfred } 100184610Salfred} 101184610Salfred