1 /* 2 * Copyright (c) 2012, 2012, 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 // Checkstyle: stop 24 package org.graalvm.compiler.jtt.loop; 25 26 import org.junit.Test; 27 28 import org.graalvm.compiler.jtt.JTTTest; 29 30 /* 31 * Test around an object that escapes directly from inside a loop (no virtual phi on the loop) 32 */ 33 public class LoopEscape extends JTTTest { 34 35 public static L ll = new L(0, 1, 2); 36 37 private static class L { 38 39 public int a; 40 public int b; 41 public int c; 42 43 public L(int a, int b, int c) { 44 this.a = a; 45 this.b = b; 46 this.c = c; 47 } 48 } 49 50 public static int test0(int count) { 51 L l = new L(5, 5, 5); 52 for (int i = 0; i < count; i++) { 53 l.a++; 54 l.b--; 55 l.c = 4; 56 } 57 58 return l.a + l.b * 10 + l.c * 100; 59 } 60 61 public static int test1(int count) { 62 L l = new L(5, 5, 5); 63 for (int i = 0; i < count; i++) { 64 if (l.a % 2 == 0) { 65 l.a++; 66 l.b--; 67 l.c = 4; 68 } else { 69 l.a++; 70 } 71 } 72 73 return l.a + l.b * 10 + l.c * 100; 74 } 75 76 @Test 77 public void run10() throws Throwable { 78 runTest("test1", 0); 79 } 80 81 @Test 82 public void run11() throws Throwable { 83 runTest("test1", 1); 84 } 85 86 @Test 87 public void run12() throws Throwable { 88 runTest("test1", 2); 89 } 90 91 @Test 92 public void run00() throws Throwable { 93 runTest("test0", 0); 94 } 95 96 @Test 97 public void run01() throws Throwable { 98 runTest("test0", 1); 99 } 100 101 @Test 102 public void run02() throws Throwable { 103 runTest("test0", 2); 104 } 105 106 @Test 107 public void run05() throws Throwable { 108 runTest("test0", 5); 109 } 110 }