comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/FloatValueProfileTest.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.is;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertThat;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.experimental.theories.DataPoint;
32 import org.junit.experimental.theories.Theories;
33 import org.junit.experimental.theories.Theory;
34 import org.junit.runner.RunWith;
35
36 @RunWith(Theories.class)
37 public class FloatValueProfileTest {
38
39 @DataPoint public static final float VALUE0 = Float.MIN_VALUE;
40 @DataPoint public static final float VALUE1 = -0.0f;
41 @DataPoint public static final float VALUE2 = +0.0f;
42 @DataPoint public static final float VALUE3 = 14.5f;
43 @DataPoint public static final float VALUE4 = Float.MAX_VALUE;
44
45 private static final float FLOAT_DELTA = 0.00001f;
46
47 private FloatValueProfile.Enabled profile;
48
49 @Before
50 public void create() {
51 profile = (FloatValueProfile.Enabled) FloatValueProfile.Enabled.create();
52 }
53
54 @Test
55 public void testInitial() {
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 testProfileOneFloat(float value) {
63 float result = profile.profile(value);
64
65 assertThat(result, is(value));
66 assertEquals(profile.getCachedValue(), value, FLOAT_DELTA);
67 assertThat(profile.isUninitialized(), is(false));
68 profile.toString(); // test that it is not crashing
69 }
70
71 @SuppressWarnings("deprecation")
72 @Theory
73 public void testProfileTwoFloat(float value0, float value1) {
74 float result0 = profile.profile(value0);
75 float result1 = profile.profile(value1);
76
77 assertEquals(result0, value0, FLOAT_DELTA);
78 assertEquals(result1, value1, FLOAT_DELTA);
79
80 if (PrimitiveValueProfile.exactCompare(value0, value1)) {
81 assertEquals(profile.getCachedValue(), value0, FLOAT_DELTA);
82 assertThat(profile.isGeneric(), is(false));
83 } else {
84 assertThat(profile.isGeneric(), is(true));
85 }
86 assertThat(profile.isUninitialized(), is(false));
87 profile.toString(); // test that it is not crashing
88 }
89
90 @SuppressWarnings("deprecation")
91 @Theory
92 public void testProfileThreeFloat(float value0, float value1, float value2) {
93 float result0 = profile.profile(value0);
94 float result1 = profile.profile(value1);
95 float result2 = profile.profile(value2);
96
97 assertEquals(result0, value0, FLOAT_DELTA);
98 assertEquals(result1, value1, FLOAT_DELTA);
99 assertEquals(result2, value2, FLOAT_DELTA);
100
101 if (PrimitiveValueProfile.exactCompare(value0, value1) && PrimitiveValueProfile.exactCompare(value1, value2)) {
102 assertEquals(profile.getCachedValue(), value0, FLOAT_DELTA);
103 assertThat(profile.isGeneric(), is(false));
104 } else {
105 assertThat(profile.isGeneric(), is(true));
106 }
107 assertThat(profile.isUninitialized(), is(false));
108 profile.toString(); // test that it is not crashing
109 }
110
111 @Test
112 public void testDisabled() {
113 FloatValueProfile.Disabled p = (FloatValueProfile.Disabled) FloatValueProfile.Disabled.INSTANCE;
114 assertThat(p.profile(VALUE0), is(VALUE0));
115 assertThat(p.profile(VALUE1), is(VALUE1));
116 assertThat(p.profile(VALUE2), is(VALUE2));
117 assertThat(p.profile(VALUE3), is(VALUE3));
118 assertThat(p.profile(VALUE4), is(VALUE4));
119 p.toString(); // test that it is not crashing
120 }
121
122 }