001/*
002 * Copyright (c) 2015, 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 */
023package com.oracle.graal.compiler.test.ea;
024
025import jdk.internal.jvmci.code.*;
026
027import org.junit.*;
028
029import com.oracle.graal.api.directives.*;
030import com.oracle.graal.compiler.test.*;
031
032public class PEAAssertionsTest extends GraalCompilerTest {
033
034    public static Object field;
035
036    public static void snippet1(int i) {
037        Integer object = new Integer(i);
038        GraalDirectives.ensureVirtualized(object);
039    }
040
041    @Test
042    public void test1() {
043        test("snippet1", 1);
044    }
045
046    public static void snippet2(int i) {
047        Integer object = new Integer(i);
048        GraalDirectives.ensureVirtualized(object);
049        field = object; // assert here
050    }
051
052    @Test(expected = SourceStackTrace.class)
053    public void test2() {
054        test("snippet2", 1);
055    }
056
057    public static void snippet3(int i) {
058        Integer object = new Integer(i);
059        field = object;
060        GraalDirectives.ensureVirtualized(object); // assert here
061    }
062
063    @Test(expected = SourceStackTrace.class)
064    public void test3() {
065        test("snippet3", 1);
066    }
067
068    public static void snippetHere1(int i) {
069        Integer object = new Integer(i);
070        GraalDirectives.ensureVirtualizedHere(object);
071    }
072
073    @Test
074    public void testHere1() {
075        test("snippetHere1", 1);
076    }
077
078    public static void snippetHere2(int i) {
079        Integer object = new Integer(i);
080        GraalDirectives.ensureVirtualizedHere(object);
081        field = object;
082    }
083
084    @Test
085    public void testHere2() {
086        test("snippetHere2", 1);
087    }
088
089    public static void snippetHere3(int i) {
090        Integer object = new Integer(i);
091        field = object;
092        GraalDirectives.ensureVirtualizedHere(object); // assert here
093    }
094
095    @Test(expected = SourceStackTrace.class)
096    public void testHere3() {
097        test("snippetHere3", 1);
098    }
099
100    public static void snippetBoxing1(int i) {
101        Integer object = i;
102        GraalDirectives.ensureVirtualizedHere(object); // assert here
103    }
104
105    @Test(expected = SourceStackTrace.class)
106    public void testBoxing1() {
107        test("snippetBoxing1", 1);
108    }
109
110    public static void snippetBoxing2(int i) {
111        Integer object = i;
112        GraalDirectives.ensureVirtualized(object); // assert here
113        field = object;
114    }
115
116    @Test(expected = SourceStackTrace.class)
117    public void testBoxing2() {
118        test("snippetBoxing2", 1);
119    }
120
121    public static void snippetControlFlow1(boolean b, int i) {
122        Integer object = new Integer(i);
123        if (b) {
124            GraalDirectives.ensureVirtualized(object);
125        }
126        field = object;
127    }
128
129    @Test
130    public void testControlFlow1() {
131        test("snippetControlFlow1", true, 1);
132    }
133
134    public static void snippetControlFlow2(boolean b, int i) {
135        Integer object = new Integer(i);
136        if (b) {
137            GraalDirectives.ensureVirtualized(object);
138        } else {
139            GraalDirectives.ensureVirtualized(object);
140        }
141        field = object; // assert here
142    }
143
144    @Test(expected = SourceStackTrace.class)
145    public void testControlFlow2() {
146        test("snippetControlFlow2", true, 1);
147    }
148
149    public static void snippetControlFlow3(boolean b, int i) {
150        Integer object = new Integer(i);
151        GraalDirectives.ensureVirtualized(object);
152        if (b) {
153            field = 1;
154        } else {
155            field = 2;
156        }
157        field = object; // assert here
158    }
159
160    @Test(expected = SourceStackTrace.class)
161    public void testControlFlow3() {
162        test("snippetControlFlow3", true, 1);
163    }
164
165    public static void snippetControlFlow4(boolean b, int i) {
166        Integer object = new Integer(i);
167        if (b) {
168            field = object;
169        } else {
170            field = 2;
171        }
172        GraalDirectives.ensureVirtualized(object); // assert here
173    }
174
175    @Test(expected = SourceStackTrace.class)
176    public void testControlFlow4() {
177        test("snippetControlFlow4", true, 1);
178    }
179
180    public static void snippetControlFlow5(boolean b, int i) {
181        Integer object = new Integer(i);
182        if (b) {
183            field = object;
184        } else {
185            field = 2;
186        }
187        GraalDirectives.ensureVirtualizedHere(object); // assert here
188    }
189
190    @Test(expected = SourceStackTrace.class)
191    public void testControlFlow5() {
192        test("snippetControlFlow5", true, 1);
193    }
194
195    public static final class TestClass {
196        Object a;
197        Object b;
198    }
199
200    public static void snippetIndirect1(boolean b, int i) {
201        Integer object = new Integer(i);
202        TestClass t = new TestClass();
203        t.a = object;
204        GraalDirectives.ensureVirtualized(object);
205
206        if (b) {
207            field = t; // assert here
208        } else {
209            field = 2;
210        }
211    }
212
213    @Test(expected = SourceStackTrace.class)
214    public void testIndirect1() {
215        test("snippetIndirect1", true, 1);
216    }
217
218    public static void snippetIndirect2(boolean b, int i) {
219        Integer object = new Integer(i);
220        TestClass t = new TestClass();
221        t.a = object;
222        GraalDirectives.ensureVirtualized(t);
223
224        if (b) {
225            field = object;
226        } else {
227            field = 2;
228        }
229    }
230
231    @Test
232    public void testIndirect2() {
233        test("snippetIndirect2", true, 1);
234    }
235}