Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/EqualityValueProfileTest.java @ 22501:a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
author | Christian Humer <christian.humer@oracle.com> |
---|---|
date | Wed, 16 Dec 2015 16:38:13 +0100 |
parents | |
children | 4ba1aa33fda4 |
comparison
equal
deleted
inserted
replaced
22500:fbe1eb7b4172 | 22501:a63bda98cfdb |
---|---|
1 /* | |
2 * Copyright (c) 2015, 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 package com.oracle.truffle.api.profiles; | |
24 | |
25 import static org.hamcrest.CoreMatchers.equalTo; | |
26 import static org.hamcrest.CoreMatchers.is; | |
27 import static org.junit.Assert.assertEquals; | |
28 import static org.junit.Assert.assertThat; | |
29 | |
30 import org.junit.Before; | |
31 import org.junit.Test; | |
32 import org.junit.experimental.theories.DataPoint; | |
33 import org.junit.experimental.theories.Theories; | |
34 import org.junit.experimental.theories.Theory; | |
35 import org.junit.runner.RunWith; | |
36 | |
37 @RunWith(Theories.class) | |
38 public class EqualityValueProfileTest { | |
39 | |
40 @DataPoint public static final String O1 = new String(); | |
41 @DataPoint public static final String O2 = O1; | |
42 @DataPoint public static final Object O3 = new Object(); | |
43 @DataPoint public static final Integer O4 = new Integer(1); | |
44 @DataPoint public static final Integer O5 = new Integer(1); | |
45 @DataPoint public static final Integer O6 = null; | |
46 | |
47 private ValueProfile.Equality profile; | |
48 | |
49 @Before | |
50 public void create() { | |
51 profile = (ValueProfile.Equality) ValueProfile.Equality.create(); | |
52 } | |
53 | |
54 @Test | |
55 public void testInitial() throws Exception { | |
56 assertThat(profile.isGeneric(), is(false)); | |
57 assertThat(profile.isUninitialized(), is(true)); | |
58 profile.toString(); // test that it is not crashing | |
59 } | |
60 | |
61 @Theory | |
62 public void testProfileOne(Object value) throws Exception { | |
63 Object result = profile.profile(value); | |
64 assertThat(result, is(equalTo(value))); | |
65 if (value == null) { | |
66 assertThat(profile.isUninitialized(), is(false)); | |
67 assertThat(profile.isGeneric(), is(true)); | |
68 } else { | |
69 assertEquals(profile.getCachedValue(), value); | |
70 assertThat(profile.isUninitialized(), is(false)); | |
71 assertThat(profile.isGeneric(), is(false)); | |
72 } | |
73 profile.toString(); // test that it is not crashing | |
74 } | |
75 | |
76 @Theory | |
77 public void testProfileTwo(Object value0, Object value1) throws Exception { | |
78 Object result0 = profile.profile(value0); | |
79 Object result1 = profile.profile(value1); | |
80 | |
81 assertThat(result0, is(equalTo(value0))); | |
82 assertThat(result1, is(equalTo(value1))); | |
83 | |
84 if (value0 != null && value0.equals(value1)) { | |
85 assertThat(profile.getCachedValue(), is(equalTo(value0))); | |
86 assertThat(profile.isGeneric(), is(false)); | |
87 } else { | |
88 assertThat(profile.isGeneric(), is(true)); | |
89 } | |
90 assertThat(profile.isUninitialized(), is(false)); | |
91 profile.toString(); // test that it is not crashing | |
92 } | |
93 | |
94 @Theory | |
95 public void testProfileThree(Object value0, Object value1, Object value2) throws Exception { | |
96 Object result0 = profile.profile(value0); | |
97 Object result1 = profile.profile(value1); | |
98 Object result2 = profile.profile(value2); | |
99 | |
100 assertThat(result0, is(equalTo(value0))); | |
101 assertThat(result1, is(equalTo(value1))); | |
102 assertThat(result2, is(equalTo(value2))); | |
103 | |
104 if (value0 != null && value0.equals(value1) && value1 != null && value1.equals(value2)) { | |
105 assertThat(profile.getCachedValue(), is(equalTo(value0))); | |
106 assertThat(profile.isGeneric(), is(false)); | |
107 } else { | |
108 assertThat(profile.isGeneric(), is(true)); | |
109 } | |
110 assertThat(profile.isUninitialized(), is(false)); | |
111 profile.toString(); // test that it is not crashing | |
112 } | |
113 | |
114 } |