001/*
002 * Copyright (c) 2012, 2012, 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 */
023// Checkstyle: stop
024package com.oracle.graal.jtt.loop;
025
026import org.junit.*;
027
028import com.oracle.graal.jtt.*;
029
030/*
031 * Test around an object that escapes directly from inside a loop (no virtual phi on the loop)
032 */
033public class LoopEscape extends JTTTest {
034
035    public static L ll = new L(0, 1, 2);
036
037    private static class L {
038
039        public int a;
040        public int b;
041        public int c;
042
043        public L(int a, int b, int c) {
044            this.a = a;
045            this.b = b;
046            this.c = c;
047        }
048    }
049
050    public static int test0(int count) {
051        L l = new L(5, 5, 5);
052        for (int i = 0; i < count; i++) {
053            l.a++;
054            l.b--;
055            l.c = 4;
056        }
057
058        return l.a + l.b * 10 + l.c * 100;
059    }
060
061    public static int test1(int count) {
062        L l = new L(5, 5, 5);
063        for (int i = 0; i < count; i++) {
064            if (l.a % 2 == 0) {
065                l.a++;
066                l.b--;
067                l.c = 4;
068            } else {
069                l.a++;
070            }
071        }
072
073        return l.a + l.b * 10 + l.c * 100;
074    }
075
076    @Test
077    public void run10() throws Throwable {
078        runTest("test1", 0);
079    }
080
081    @Test
082    public void run11() throws Throwable {
083        runTest("test1", 1);
084    }
085
086    @Test
087    public void run12() throws Throwable {
088        runTest("test1", 2);
089    }
090
091    @Test
092    public void run00() throws Throwable {
093        runTest("test0", 0);
094    }
095
096    @Test
097    public void run01() throws Throwable {
098        runTest("test0", 1);
099    }
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}