Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/ByteValueProfileTest.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 | 114a6a77b440 |
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 ByteValueProfileTest { | |
38 | |
39 @DataPoint public static final byte VALUE0 = Byte.MIN_VALUE; | |
40 @DataPoint public static final byte VALUE1 = 0; | |
41 @DataPoint public static final byte VALUE2 = 14; | |
42 @DataPoint public static final byte VALUE3 = Byte.MAX_VALUE; | |
43 | |
44 private ByteValueProfile.Enabled profile; | |
45 | |
46 @Before | |
47 public void create() { | |
48 profile = (ByteValueProfile.Enabled) ByteValueProfile.Enabled.create(); | |
49 } | |
50 | |
51 @Test | |
52 public void testInitial() { | |
53 assertThat(profile.isGeneric(), is(false)); | |
54 assertThat(profile.isUninitialized(), is(true)); | |
55 profile.toString(); // test that it is not crashing | |
56 } | |
57 | |
58 @Theory | |
59 public void testProfileOneObject(byte value) { | |
60 byte result = profile.profile(value); | |
61 | |
62 assertThat(result, is(value)); | |
63 assertEquals(profile.getCachedValue(), value); | |
64 assertThat(profile.isUninitialized(), is(false)); | |
65 profile.toString(); // test that it is not crashing | |
66 } | |
67 | |
68 @Theory | |
69 public void testProfileTwoObject(byte value0, byte value1) { | |
70 byte result0 = profile.profile(value0); | |
71 byte result1 = profile.profile(value1); | |
72 | |
73 assertThat(result0, is(value0)); | |
74 assertThat(result1, is(value1)); | |
75 | |
76 if (value0 == value1) { | |
77 assertThat(profile.getCachedValue(), is(value0)); | |
78 assertThat(profile.isGeneric(), is(false)); | |
79 } else { | |
80 assertThat(profile.isGeneric(), is(true)); | |
81 } | |
82 assertThat(profile.isUninitialized(), is(false)); | |
83 profile.toString(); // test that it is not crashing | |
84 } | |
85 | |
86 @Theory | |
87 public void testProfileThreeObject(byte value0, byte value1, byte value2) { | |
88 byte result0 = profile.profile(value0); | |
89 byte result1 = profile.profile(value1); | |
90 byte result2 = profile.profile(value2); | |
91 | |
92 assertThat(result0, is(value0)); | |
93 assertThat(result1, is(value1)); | |
94 assertThat(result2, is(value2)); | |
95 | |
96 if (value0 == value1 && value1 == value2) { | |
97 assertThat(profile.getCachedValue(), is(value0)); | |
98 assertThat(profile.isGeneric(), is(false)); | |
99 } else { | |
100 assertThat(profile.isGeneric(), is(true)); | |
101 } | |
102 assertThat(profile.isUninitialized(), is(false)); | |
103 profile.toString(); // test that it is not crashing | |
104 } | |
105 | |
106 @Test | |
107 public void testDisabled() { | |
108 ByteValueProfile.Disabled p = (ByteValueProfile.Disabled) ByteValueProfile.Disabled.INSTANCE; | |
109 assertThat(p.profile(VALUE0), is(VALUE0)); | |
110 assertThat(p.profile(VALUE1), is(VALUE1)); | |
111 assertThat(p.profile(VALUE2), is(VALUE2)); | |
112 assertThat(p.profile(VALUE3), is(VALUE3)); | |
113 p.toString(); // test that it is not crashing | |
114 } | |
115 | |
116 } |