annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IdentityValueProfileTest.java @ 21155:754f2b20d8bc graal-0.7

Skip invokes with a placeholder framestate in MethodCallTargetNode.simplify
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Wed, 29 Apr 2015 17:28:50 +0200
parents 1e542561783e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17039
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.test.utilities;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import static org.hamcrest.CoreMatchers.*;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import static org.junit.Assert.*;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28 import org.junit.*;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import org.junit.experimental.theories.*;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import org.junit.runner.*;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import com.oracle.truffle.api.utilities.*;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 @RunWith(Theories.class)
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 public class IdentityValueProfileTest {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 @DataPoint public static final String O1 = new String();
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 @DataPoint public static final String O2 = O1;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 @DataPoint public static final Object O3 = new Object();
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 @DataPoint public static final Integer O4 = new Integer(1);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 @DataPoint public static final Integer O5 = null;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 private IdentityValueProfile profile;
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 @Before
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 public void create() {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 profile = (IdentityValueProfile) ValueProfile.createIdentityProfile();
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 @Test
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 public void testInitial() {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 assertThat(profile.isGeneric(), is(false));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 assertThat(profile.isUninitialized(), is(true));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 profile.toString(); // test that it is not crashing
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 @Theory
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 public void testProfileOne(Object value) {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 Object result = profile.profile(value);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 assertThat(result, is(value));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 assertEquals(profile.getCachedValue(), value);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 assertThat(profile.isUninitialized(), is(false));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 profile.toString(); // test that it is not crashing
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 @Theory
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 public void testProfileTwo(Object value0, Object value1) {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 Object result0 = profile.profile(value0);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 Object result1 = profile.profile(value1);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 assertThat(result0, is(value0));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 assertThat(result1, is(value1));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 if (value0 == value1) {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 assertThat(profile.getCachedValue(), is(value0));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 assertThat(profile.isGeneric(), is(false));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 } else {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 assertThat(profile.isGeneric(), is(true));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 assertThat(profile.isUninitialized(), is(false));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 profile.toString(); // test that it is not crashing
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 @Theory
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 public void testProfileThree(Object value0, Object value1, Object value2) {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 Object result0 = profile.profile(value0);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 Object result1 = profile.profile(value1);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 Object result2 = profile.profile(value2);
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 assertThat(result0, is(value0));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 assertThat(result1, is(value1));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 assertThat(result2, is(value2));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 if (value0 == value1 && value1 == value2) {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 assertThat(profile.getCachedValue(), is(value0));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 assertThat(profile.isGeneric(), is(false));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 } else {
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 assertThat(profile.isGeneric(), is(true));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 assertThat(profile.isUninitialized(), is(false));
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 profile.toString(); // test that it is not crashing
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 }
1e542561783e Truffle: new value profiles prototype.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 }