comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/PrimitiveValueProfileTest.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 truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/utilities/PrimitiveValueProfileTest.java@b39b603e2a1e
children 4ba1aa33fda4
comparison
equal deleted inserted replaced
22500:fbe1eb7b4172 22501:a63bda98cfdb
1 /*
2 * Copyright (c) 2014, 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.assertFalse;
28 import static org.junit.Assert.assertSame;
29 import static org.junit.Assert.assertThat;
30 import static org.junit.Assert.assertTrue;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.experimental.theories.DataPoint;
35 import org.junit.experimental.theories.Theories;
36 import org.junit.experimental.theories.Theory;
37 import org.junit.runner.RunWith;
38
39 @SuppressWarnings("deprecation")
40 @RunWith(Theories.class)
41 public class PrimitiveValueProfileTest {
42
43 @DataPoint public static final String O1 = new String();
44 @DataPoint public static final String O2 = O1;
45 @DataPoint public static final Object O3 = new Object();
46 @DataPoint public static final Object O4 = null;
47
48 @DataPoint public static final byte B1 = Byte.MIN_VALUE;
49 @DataPoint public static final byte B2 = 0;
50 @DataPoint public static final byte B3 = 14;
51 @DataPoint public static final byte B4 = Byte.MAX_VALUE;
52
53 @DataPoint public static final short S1 = Short.MIN_VALUE;
54 @DataPoint public static final short S2 = 0;
55 @DataPoint public static final short S3 = 14;
56 @DataPoint public static final short S4 = Short.MAX_VALUE;
57
58 @DataPoint public static final int I1 = Integer.MIN_VALUE;
59 @DataPoint public static final int I2 = 0;
60 @DataPoint public static final int I3 = 14;
61 @DataPoint public static final int I4 = Integer.MAX_VALUE;
62
63 @DataPoint public static final long L1 = Long.MIN_VALUE;
64 @DataPoint public static final long L2 = 0;
65 @DataPoint public static final long L3 = 14;
66 @DataPoint public static final long L4 = Long.MAX_VALUE;
67
68 @DataPoint public static final float F1 = Float.MIN_VALUE;
69 @DataPoint public static final float F2 = -0.0f;
70 @DataPoint public static final float F3 = +0.0f;
71 @DataPoint public static final float F4 = 14.5f;
72 @DataPoint public static final float F5 = Float.MAX_VALUE;
73
74 @DataPoint public static final double D1 = Double.MIN_VALUE;
75 @DataPoint public static final double D2 = -0.0;
76 @DataPoint public static final double D3 = +0.0;
77 @DataPoint public static final double D4 = 14.5;
78 @DataPoint public static final double D5 = Double.MAX_VALUE;
79
80 @DataPoint public static final boolean T1 = false;
81 @DataPoint public static final boolean T2 = true;
82
83 @DataPoint public static final char C1 = Character.MIN_VALUE;
84 @DataPoint public static final char C2 = 0;
85 @DataPoint public static final char C3 = 14;
86 @DataPoint public static final char C4 = Character.MAX_VALUE;
87
88 private static final float FLOAT_DELTA = 0.00001f;
89 private static final double DOUBLE_DELTA = 0.00001;
90
91 private PrimitiveValueProfile.Enabled profile;
92
93 @Before
94 public void create() {
95 profile = (PrimitiveValueProfile.Enabled) PrimitiveValueProfile.Enabled.create();
96 }
97
98 @Test
99 public void testInitial() {
100 assertThat(profile.isGeneric(), is(false));
101 assertThat(profile.isUninitialized(), is(true));
102 profile.toString(); // test that it is not crashing
103 }
104
105 @Theory
106 public void testProfileOneObject(Object value) {
107 Object result = profile.profile(value);
108
109 assertThat(result, is(value));
110 assertEquals(profile.getCachedValue(), value);
111 assertThat(profile.isUninitialized(), is(false));
112 profile.toString(); // test that it is not crashing
113 }
114
115 @Theory
116 public void testProfileTwoObject(Object value0, Object value1) {
117 Object result0 = profile.profile(value0);
118 Object result1 = profile.profile(value1);
119
120 assertThat(result0, is(value0));
121 assertThat(result1, is(value1));
122
123 if (value0 == value1) {
124 assertThat(profile.getCachedValue(), is(value0));
125 assertThat(profile.isGeneric(), is(false));
126 } else {
127 assertThat(profile.isGeneric(), is(true));
128 }
129 assertThat(profile.isUninitialized(), is(false));
130 profile.toString(); // test that it is not crashing
131 }
132
133 @Theory
134 public void testProfileThreeObject(Object value0, Object value1, Object value2) {
135 Object result0 = profile.profile(value0);
136 Object result1 = profile.profile(value1);
137 Object result2 = profile.profile(value2);
138
139 assertThat(result0, is(value0));
140 assertThat(result1, is(value1));
141 assertThat(result2, is(value2));
142
143 if (value0 == value1 && value1 == value2) {
144 assertThat(profile.getCachedValue(), is(value0));
145 assertThat(profile.isGeneric(), is(false));
146 } else {
147 assertThat(profile.isGeneric(), is(true));
148 }
149 assertThat(profile.isUninitialized(), is(false));
150 profile.toString(); // test that it is not crashing
151 }
152
153 @Theory
154 public void testProfileOneByte(byte value) {
155 byte result = profile.profile(value);
156
157 assertThat(result, is(value));
158 assertEquals(profile.getCachedValue(), value);
159 assertThat(profile.isUninitialized(), is(false));
160 profile.toString(); // test that it is not crashing
161 }
162
163 @Theory
164 public void testProfileTwoByte(byte value0, byte value1) {
165 byte result0 = profile.profile(value0);
166 byte result1 = profile.profile(value1);
167
168 assertEquals(result0, value0);
169 assertEquals(result1, value1);
170
171 if (value0 == value1) {
172 assertTrue(profile.getCachedValue() instanceof Byte);
173 assertEquals((byte) profile.getCachedValue(), value0);
174 assertThat(profile.isGeneric(), is(false));
175 } else {
176 assertThat(profile.isGeneric(), is(true));
177 }
178 assertThat(profile.isUninitialized(), is(false));
179 profile.toString(); // test that it is not crashing
180 }
181
182 @Theory
183 public void testProfileThreeByte(byte value0, byte value1, byte value2) {
184 byte result0 = profile.profile(value0);
185 byte result1 = profile.profile(value1);
186 byte result2 = profile.profile(value2);
187
188 assertEquals(result0, value0);
189 assertEquals(result1, value1);
190 assertEquals(result2, value2);
191
192 if (value0 == value1 && value1 == value2) {
193 assertTrue(profile.getCachedValue() instanceof Byte);
194 assertEquals((byte) profile.getCachedValue(), value0);
195 assertThat(profile.isGeneric(), is(false));
196 } else {
197 assertThat(profile.isGeneric(), is(true));
198 }
199 assertThat(profile.isUninitialized(), is(false));
200 profile.toString(); // test that it is not crashing
201 }
202
203 @Theory
204 public void testProfileOneShort(short value) {
205 short result = profile.profile(value);
206
207 assertThat(result, is(value));
208 assertEquals(profile.getCachedValue(), value);
209 assertThat(profile.isUninitialized(), is(false));
210 profile.toString(); // test that it is not crashing
211 }
212
213 @Theory
214 public void testProfileTwoShort(short value0, short value1) {
215 short result0 = profile.profile(value0);
216 short result1 = profile.profile(value1);
217
218 assertEquals(result0, value0);
219 assertEquals(result1, value1);
220
221 if (value0 == value1) {
222 assertTrue(profile.getCachedValue() instanceof Short);
223 assertEquals((short) profile.getCachedValue(), value0);
224 assertThat(profile.isGeneric(), is(false));
225 } else {
226 assertThat(profile.isGeneric(), is(true));
227 }
228 assertThat(profile.isUninitialized(), is(false));
229 profile.toString(); // test that it is not crashing
230 }
231
232 @Theory
233 public void testProfileThreeShort(short value0, short value1, short value2) {
234 short result0 = profile.profile(value0);
235 short result1 = profile.profile(value1);
236 short result2 = profile.profile(value2);
237
238 assertEquals(result0, value0);
239 assertEquals(result1, value1);
240 assertEquals(result2, value2);
241
242 if (value0 == value1 && value1 == value2) {
243 assertTrue(profile.getCachedValue() instanceof Short);
244 assertEquals((short) profile.getCachedValue(), value0);
245 assertThat(profile.isGeneric(), is(false));
246 } else {
247 assertThat(profile.isGeneric(), is(true));
248 }
249 assertThat(profile.isUninitialized(), is(false));
250 profile.toString(); // test that it is not crashing
251 }
252
253 @Theory
254 public void testProfileOneInteger(int value) {
255 int result = profile.profile(value);
256
257 assertThat(result, is(value));
258 assertEquals(profile.getCachedValue(), value);
259 assertThat(profile.isUninitialized(), is(false));
260 profile.toString(); // test that it is not crashing
261 }
262
263 @Theory
264 public void testProfileTwoInteger(int value0, int value1) {
265 int result0 = profile.profile(value0);
266 int result1 = profile.profile(value1);
267
268 assertEquals(result0, value0);
269 assertEquals(result1, value1);
270
271 if (value0 == value1) {
272 assertTrue(profile.getCachedValue() instanceof Integer);
273 assertEquals((int) profile.getCachedValue(), value0);
274 assertThat(profile.isGeneric(), is(false));
275 } else {
276 assertThat(profile.isGeneric(), is(true));
277 }
278 assertThat(profile.isUninitialized(), is(false));
279 profile.toString(); // test that it is not crashing
280 }
281
282 @Theory
283 public void testProfileThreeInteger(int value0, int value1, int value2) {
284 int result0 = profile.profile(value0);
285 int result1 = profile.profile(value1);
286 int result2 = profile.profile(value2);
287
288 assertEquals(result0, value0);
289 assertEquals(result1, value1);
290 assertEquals(result2, value2);
291
292 if (value0 == value1 && value1 == value2) {
293 assertTrue(profile.getCachedValue() instanceof Integer);
294 assertEquals((int) profile.getCachedValue(), value0);
295 assertThat(profile.isGeneric(), is(false));
296 } else {
297 assertThat(profile.isGeneric(), is(true));
298 }
299 assertThat(profile.isUninitialized(), is(false));
300 profile.toString(); // test that it is not crashing
301 }
302
303 @Theory
304 public void testProfileOneLong(long value) {
305 long result = profile.profile(value);
306
307 assertThat(result, is(value));
308 assertEquals(profile.getCachedValue(), value);
309 assertThat(profile.isUninitialized(), is(false));
310 profile.toString(); // test that it is not crashing
311 }
312
313 @Theory
314 public void testProfileTwoLong(long value0, long value1) {
315 long result0 = profile.profile(value0);
316 long result1 = profile.profile(value1);
317
318 assertEquals(result0, value0);
319 assertEquals(result1, value1);
320
321 if (value0 == value1) {
322 assertTrue(profile.getCachedValue() instanceof Long);
323 assertEquals((long) profile.getCachedValue(), value0);
324 assertThat(profile.isGeneric(), is(false));
325 } else {
326 assertThat(profile.isGeneric(), is(true));
327 }
328 assertThat(profile.isUninitialized(), is(false));
329 profile.toString(); // test that it is not crashing
330 }
331
332 @Theory
333 public void testProfileThreeLong(long value0, long value1, long value2) {
334 long result0 = profile.profile(value0);
335 long result1 = profile.profile(value1);
336 long result2 = profile.profile(value2);
337
338 assertEquals(result0, value0);
339 assertEquals(result1, value1);
340 assertEquals(result2, value2);
341
342 if (value0 == value1 && value1 == value2) {
343 assertTrue(profile.getCachedValue() instanceof Long);
344 assertEquals((long) profile.getCachedValue(), value0);
345 assertThat(profile.isGeneric(), is(false));
346 } else {
347 assertThat(profile.isGeneric(), is(true));
348 }
349 assertThat(profile.isUninitialized(), is(false));
350 profile.toString(); // test that it is not crashing
351 }
352
353 @Theory
354 public void testProfileOneFloat(float value) {
355 float result = profile.profile(value);
356
357 assertThat(result, is(value));
358 assertEquals(profile.getCachedValue(), value);
359 assertThat(profile.isUninitialized(), is(false));
360 profile.toString(); // test that it is not crashing
361 }
362
363 @Theory
364 public void testProfileTwoFloat(float value0, float value1) {
365 float result0 = profile.profile(value0);
366 float result1 = profile.profile(value1);
367
368 assertEquals(result0, value0, FLOAT_DELTA);
369 assertEquals(result1, value1, FLOAT_DELTA);
370
371 if (PrimitiveValueProfile.exactCompare(value0, value1)) {
372 assertTrue(profile.getCachedValue() instanceof Float);
373 assertEquals((float) profile.getCachedValue(), value0, FLOAT_DELTA);
374 assertThat(profile.isGeneric(), is(false));
375 } else {
376 assertThat(profile.isGeneric(), is(true));
377 }
378 assertThat(profile.isUninitialized(), is(false));
379 profile.toString(); // test that it is not crashing
380 }
381
382 @Theory
383 public void testProfileThreeFloat(float value0, float value1, float value2) {
384 float result0 = profile.profile(value0);
385 float result1 = profile.profile(value1);
386 float result2 = profile.profile(value2);
387
388 assertEquals(result0, value0, FLOAT_DELTA);
389 assertEquals(result1, value1, FLOAT_DELTA);
390 assertEquals(result2, value2, FLOAT_DELTA);
391
392 if (PrimitiveValueProfile.exactCompare(value0, value1) && PrimitiveValueProfile.exactCompare(value1, value2)) {
393 assertTrue(profile.getCachedValue() instanceof Float);
394 assertEquals((float) profile.getCachedValue(), value0, FLOAT_DELTA);
395 assertThat(profile.isGeneric(), is(false));
396 } else {
397 assertThat(profile.isGeneric(), is(true));
398 }
399 assertThat(profile.isUninitialized(), is(false));
400 profile.toString(); // test that it is not crashing
401 }
402
403 @Theory
404 public void testProfileOneDouble(double value) {
405 double result = profile.profile(value);
406
407 assertThat(result, is(value));
408 assertEquals(profile.getCachedValue(), value);
409 assertThat(profile.isUninitialized(), is(false));
410 profile.toString(); // test that it is not crashing
411 }
412
413 @Theory
414 public void testProfileTwoDouble(double value0, double value1) {
415 double result0 = profile.profile(value0);
416 double result1 = profile.profile(value1);
417
418 assertEquals(result0, value0, DOUBLE_DELTA);
419 assertEquals(result1, value1, DOUBLE_DELTA);
420
421 if (PrimitiveValueProfile.exactCompare(value0, value1)) {
422 assertTrue(profile.getCachedValue() instanceof Double);
423 assertEquals((double) profile.getCachedValue(), value0, DOUBLE_DELTA);
424 assertThat(profile.isGeneric(), is(false));
425 } else {
426 assertThat(profile.isGeneric(), is(true));
427 }
428 assertThat(profile.isUninitialized(), is(false));
429 profile.toString(); // test that it is not crashing
430 }
431
432 @Theory
433 public void testProfileThreeDouble(double value0, double value1, double value2) {
434 double result0 = profile.profile(value0);
435 double result1 = profile.profile(value1);
436 double result2 = profile.profile(value2);
437
438 assertEquals(result0, value0, DOUBLE_DELTA);
439 assertEquals(result1, value1, DOUBLE_DELTA);
440 assertEquals(result2, value2, DOUBLE_DELTA);
441
442 if (PrimitiveValueProfile.exactCompare(value0, value1) && PrimitiveValueProfile.exactCompare(value1, value2)) {
443 assertTrue(profile.getCachedValue() instanceof Double);
444 assertEquals((double) profile.getCachedValue(), value0, DOUBLE_DELTA);
445 assertThat(profile.isGeneric(), is(false));
446 } else {
447 assertThat(profile.isGeneric(), is(true));
448 }
449 assertThat(profile.isUninitialized(), is(false));
450 profile.toString(); // test that it is not crashing
451 }
452
453 @Theory
454 public void testProfileOneBoolean(boolean value) {
455 boolean result = profile.profile(value);
456
457 assertThat(result, is(value));
458 assertEquals(profile.getCachedValue(), value);
459 assertThat(profile.isUninitialized(), is(false));
460 profile.toString(); // test that it is not crashing
461 }
462
463 @Theory
464 public void testProfileTwoBoolean(boolean value0, boolean value1) {
465 boolean result0 = profile.profile(value0);
466 boolean result1 = profile.profile(value1);
467
468 assertEquals(result0, value0);
469 assertEquals(result1, value1);
470
471 if (value0 == value1) {
472 assertTrue(profile.getCachedValue() instanceof Boolean);
473 assertEquals((boolean) profile.getCachedValue(), value0);
474 assertThat(profile.isGeneric(), is(false));
475 } else {
476 assertThat(profile.isGeneric(), is(true));
477 }
478 assertThat(profile.isUninitialized(), is(false));
479 profile.toString(); // test that it is not crashing
480 }
481
482 @Theory
483 public void testProfileThreeBoolean(boolean value0, boolean value1, boolean value2) {
484 boolean result0 = profile.profile(value0);
485 boolean result1 = profile.profile(value1);
486 boolean result2 = profile.profile(value2);
487
488 assertEquals(result0, value0);
489 assertEquals(result1, value1);
490 assertEquals(result2, value2);
491
492 if (value0 == value1 && value1 == value2) {
493 assertTrue(profile.getCachedValue() instanceof Boolean);
494 assertEquals((boolean) profile.getCachedValue(), value0);
495 assertThat(profile.isGeneric(), is(false));
496 } else {
497 assertThat(profile.isGeneric(), is(true));
498 }
499 assertThat(profile.isUninitialized(), is(false));
500 profile.toString(); // test that it is not crashing
501 }
502
503 @Theory
504 public void testProfileOneChar(char value) {
505 char result = profile.profile(value);
506
507 assertThat(result, is(value));
508 assertEquals(profile.getCachedValue(), value);
509 assertThat(profile.isUninitialized(), is(false));
510 profile.toString(); // test that it is not crashing
511 }
512
513 @Theory
514 public void testProfileTwoChar(char value0, char value1) {
515 char result0 = profile.profile(value0);
516 char result1 = profile.profile(value1);
517
518 assertEquals(result0, value0);
519 assertEquals(result1, value1);
520
521 if (value0 == value1) {
522 assertTrue(profile.getCachedValue() instanceof Character);
523 assertEquals((char) profile.getCachedValue(), value0);
524 assertThat(profile.isGeneric(), is(false));
525 } else {
526 assertThat(profile.isGeneric(), is(true));
527 }
528 assertThat(profile.isUninitialized(), is(false));
529 profile.toString(); // test that it is not crashing
530 }
531
532 @Theory
533 public void testProfileThreeChar(char value0, char value1, char value2) {
534 char result0 = profile.profile(value0);
535 char result1 = profile.profile(value1);
536 char result2 = profile.profile(value2);
537
538 assertEquals(result0, value0);
539 assertEquals(result1, value1);
540 assertEquals(result2, value2);
541
542 if (value0 == value1 && value1 == value2) {
543 assertTrue(profile.getCachedValue() instanceof Character);
544 assertEquals((char) profile.getCachedValue(), value0);
545 assertThat(profile.isGeneric(), is(false));
546 } else {
547 assertThat(profile.isGeneric(), is(true));
548 }
549 assertThat(profile.isUninitialized(), is(false));
550 profile.toString(); // test that it is not crashing
551 }
552
553 @Theory
554 public void testWithBoxedBoxedByte(byte value) {
555 Object result0 = profile.profile((Object) value);
556 Object result1 = profile.profile((Object) value);
557
558 assertTrue(result0 instanceof Byte);
559 assertEquals((byte) result0, value);
560 assertTrue(result1 instanceof Byte);
561 assertEquals((byte) result1, value);
562 assertFalse(profile.isUninitialized());
563 assertFalse(profile.isGeneric());
564 }
565
566 @Theory
567 public void testWithUnboxedBoxedByte(byte value) {
568 byte result0 = profile.profile(value);
569 Object result1 = profile.profile((Object) value);
570
571 assertEquals(result0, value);
572 assertTrue(result1 instanceof Byte);
573 assertEquals((byte) result1, value);
574 assertFalse(profile.isUninitialized());
575 assertFalse(profile.isGeneric());
576 }
577
578 @Theory
579 public void testWithBoxedUnboxedByte(byte value) {
580 Object result0 = profile.profile((Object) value);
581 byte result1 = profile.profile(value);
582
583 assertTrue(result0 instanceof Byte);
584 assertEquals((byte) result0, value);
585 assertEquals(result1, value);
586 assertFalse(profile.isUninitialized());
587 assertFalse(profile.isGeneric());
588 }
589
590 @Theory
591 public void testWithBoxedBoxedShort(short value) {
592 Object result0 = profile.profile((Object) value);
593 Object result1 = profile.profile((Object) value);
594
595 assertTrue(result0 instanceof Short);
596 assertEquals((short) result0, value);
597 assertTrue(result1 instanceof Short);
598 assertEquals((short) result1, value);
599 assertFalse(profile.isUninitialized());
600 assertFalse(profile.isGeneric());
601 }
602
603 @Theory
604 public void testWithUnboxedBoxedShort(short value) {
605 short result0 = profile.profile(value);
606 Object result1 = profile.profile((Object) value);
607
608 assertEquals(result0, value);
609 assertTrue(result1 instanceof Short);
610 assertEquals((short) result1, value);
611 assertFalse(profile.isUninitialized());
612 assertFalse(profile.isGeneric());
613 }
614
615 @Theory
616 public void testWithBoxedUnboxedShort(short value) {
617 Object result0 = profile.profile((Object) value);
618 short result1 = profile.profile(value);
619
620 assertTrue(result0 instanceof Short);
621 assertEquals((short) result0, value);
622 assertEquals(result1, value);
623 assertFalse(profile.isUninitialized());
624 assertFalse(profile.isGeneric());
625 }
626
627 @Theory
628 public void testWithBoxedBoxedInt(int value) {
629 Object result0 = profile.profile((Object) value);
630 Object result1 = profile.profile((Object) value);
631
632 assertTrue(result0 instanceof Integer);
633 assertEquals((int) result0, value);
634 assertTrue(result1 instanceof Integer);
635 assertEquals((int) result1, value);
636 assertFalse(profile.isUninitialized());
637 assertFalse(profile.isGeneric());
638 }
639
640 @Theory
641 public void testWithUnboxedBoxedInt(int value) {
642 int result0 = profile.profile(value);
643 Object result1 = profile.profile((Object) value);
644
645 assertEquals(result0, value);
646 assertTrue(result1 instanceof Integer);
647 assertEquals((int) result1, value);
648 assertFalse(profile.isUninitialized());
649 assertFalse(profile.isGeneric());
650 }
651
652 @Theory
653 public void testWithBoxedUnboxedInt(int value) {
654 Object result0 = profile.profile((Object) value);
655 int result1 = profile.profile(value);
656
657 assertTrue(result0 instanceof Integer);
658 assertEquals((int) result0, value);
659 assertEquals(result1, value);
660 assertFalse(profile.isUninitialized());
661 assertFalse(profile.isGeneric());
662 }
663
664 @Theory
665 public void testWithBoxedBoxedLong(long value) {
666 Object result0 = profile.profile((Object) value);
667 Object result1 = profile.profile((Object) value);
668
669 assertTrue(result0 instanceof Long);
670 assertEquals((long) result0, value);
671 assertTrue(result1 instanceof Long);
672 assertEquals((long) result1, value);
673 assertFalse(profile.isUninitialized());
674 assertFalse(profile.isGeneric());
675 }
676
677 @Theory
678 public void testWithUnboxedBoxedLong(long value) {
679 long result0 = profile.profile(value);
680 Object result1 = profile.profile((Object) value);
681
682 assertEquals(result0, value);
683 assertTrue(result1 instanceof Long);
684 assertEquals((long) result1, value);
685 assertFalse(profile.isUninitialized());
686 assertFalse(profile.isGeneric());
687 }
688
689 @Theory
690 public void testWithBoxedUnboxedLong(long value) {
691 Object result0 = profile.profile((Object) value);
692 long result1 = profile.profile(value);
693
694 assertTrue(result0 instanceof Long);
695 assertEquals((long) result0, value);
696 assertEquals(result1, value);
697 assertFalse(profile.isUninitialized());
698 assertFalse(profile.isGeneric());
699 }
700
701 @Theory
702 public void testWithBoxedBoxedFloat(float value) {
703 Object result0 = profile.profile((Object) value);
704 Object result1 = profile.profile((Object) value);
705
706 assertTrue(result0 instanceof Float);
707 assertTrue(PrimitiveValueProfile.exactCompare((float) result0, value));
708 assertTrue(result1 instanceof Float);
709 assertTrue(PrimitiveValueProfile.exactCompare((float) result1, value));
710 assertFalse(profile.isUninitialized());
711 assertFalse(profile.isGeneric());
712 }
713
714 @Theory
715 public void testWithUnboxedBoxedFloat(float value) {
716 float result0 = profile.profile(value);
717 Object result1 = profile.profile((Object) value);
718
719 assertTrue(PrimitiveValueProfile.exactCompare(result0, value));
720 assertTrue(result1 instanceof Float);
721 assertTrue(PrimitiveValueProfile.exactCompare((float) result1, value));
722 assertFalse(profile.isUninitialized());
723 assertFalse(profile.isGeneric());
724 }
725
726 @Theory
727 public void testWithBoxedUnboxedFloat(float value) {
728 Object result0 = profile.profile((Object) value);
729 float result1 = profile.profile(value);
730
731 assertTrue(result0 instanceof Float);
732 assertTrue(PrimitiveValueProfile.exactCompare((float) result0, value));
733 assertTrue(PrimitiveValueProfile.exactCompare(result1, value));
734 assertFalse(profile.isUninitialized());
735 assertFalse(profile.isGeneric());
736 }
737
738 @Theory
739 public void testWithBoxedBoxedDouble(double value) {
740 Object result0 = profile.profile((Object) value);
741 Object result1 = profile.profile((Object) value);
742
743 assertTrue(result0 instanceof Double);
744 assertTrue(PrimitiveValueProfile.exactCompare((double) result0, value));
745 assertTrue(result1 instanceof Double);
746 assertTrue(PrimitiveValueProfile.exactCompare((double) result1, value));
747 assertFalse(profile.isUninitialized());
748 assertFalse(profile.isGeneric());
749 }
750
751 @Theory
752 public void testWithUnboxedBoxedDouble(double value) {
753 double result0 = profile.profile(value);
754 Object result1 = profile.profile((Object) value);
755
756 assertTrue(PrimitiveValueProfile.exactCompare(result0, value));
757 assertTrue(result1 instanceof Double);
758 assertTrue(PrimitiveValueProfile.exactCompare((double) result1, value));
759 assertFalse(profile.isUninitialized());
760 assertFalse(profile.isGeneric());
761 }
762
763 @Theory
764 public void testWithBoxedUnboxedDouble(double value) {
765 Object result0 = profile.profile((Object) value);
766 double result1 = profile.profile(value);
767
768 assertTrue(result0 instanceof Double);
769 assertTrue(PrimitiveValueProfile.exactCompare((double) result0, value));
770 assertTrue(PrimitiveValueProfile.exactCompare(result1, value));
771 assertFalse(profile.isUninitialized());
772 assertFalse(profile.isGeneric());
773 }
774
775 @Theory
776 public void testWithBoxedBoxedBoolean(boolean value) {
777 Object result0 = profile.profile((Object) value);
778 Object result1 = profile.profile((Object) value);
779
780 assertTrue(result0 instanceof Boolean);
781 assertEquals((boolean) result0, value);
782 assertTrue(result1 instanceof Boolean);
783 assertEquals((boolean) result1, value);
784 assertFalse(profile.isUninitialized());
785 assertFalse(profile.isGeneric());
786 }
787
788 @Theory
789 public void testWithUnboxedBoxedBoolean(boolean value) {
790 boolean result0 = profile.profile(value);
791 Object result1 = profile.profile((Object) value);
792
793 assertEquals(result0, value);
794 assertTrue(result1 instanceof Boolean);
795 assertEquals((boolean) result1, value);
796 assertFalse(profile.isUninitialized());
797 assertFalse(profile.isGeneric());
798 }
799
800 @Theory
801 public void testWithBoxedUnboxedBoolean(boolean value) {
802 Object result0 = profile.profile((Object) value);
803 boolean result1 = profile.profile(value);
804
805 assertTrue(result0 instanceof Boolean);
806 assertEquals((boolean) result0, value);
807 assertEquals(result1, value);
808 assertFalse(profile.isUninitialized());
809 assertFalse(profile.isGeneric());
810 }
811
812 @Theory
813 public void testWithBoxedBoxedChar(char value) {
814 Object result0 = profile.profile((Object) value);
815 Object result1 = profile.profile((Object) value);
816
817 assertTrue(result0 instanceof Character);
818 assertEquals((char) result0, value);
819 assertTrue(result1 instanceof Character);
820 assertEquals((char) result1, value);
821 assertFalse(profile.isUninitialized());
822 assertFalse(profile.isGeneric());
823 }
824
825 @Theory
826 public void testWithUnboxedBoxedChar(char value) {
827 char result0 = profile.profile(value);
828 Object result1 = profile.profile((Object) value);
829
830 assertEquals(result0, value);
831 assertTrue(result1 instanceof Character);
832 assertEquals((char) result1, value);
833 assertFalse(profile.isUninitialized());
834 assertFalse(profile.isGeneric());
835 }
836
837 @Theory
838 public void testWithBoxedUnboxedCharacter(char value) {
839 Object result0 = profile.profile((Object) value);
840 char result1 = profile.profile(value);
841
842 assertTrue(result0 instanceof Character);
843 assertEquals((char) result0, value);
844 assertEquals(result1, value);
845 assertFalse(profile.isUninitialized());
846 assertFalse(profile.isGeneric());
847 }
848
849 @Theory
850 public void testWithByteThenObject(byte value0, Object value1) {
851 byte result0 = profile.profile(value0);
852 Object result1 = profile.profile(value1);
853
854 assertEquals(result0, value0);
855 assertSame(result1, value1);
856 assertFalse(profile.isUninitialized());
857 assertTrue(profile.isGeneric());
858 }
859
860 @Theory
861 public void testWithShortThenObject(short value0, Object value1) {
862 short result0 = profile.profile(value0);
863 Object result1 = profile.profile(value1);
864
865 assertEquals(result0, value0);
866 assertSame(result1, value1);
867 assertFalse(profile.isUninitialized());
868 assertTrue(profile.isGeneric());
869 }
870
871 @Theory
872 public void testWithIntThenObject(int value0, Object value1) {
873 int result0 = profile.profile(value0);
874 Object result1 = profile.profile(value1);
875
876 assertEquals(result0, value0);
877 assertSame(result1, value1);
878 assertFalse(profile.isUninitialized());
879 assertTrue(profile.isGeneric());
880 }
881
882 @Theory
883 public void testWithLongThenObject(long value0, Object value1) {
884 long result0 = profile.profile(value0);
885 Object result1 = profile.profile(value1);
886
887 assertEquals(result0, value0);
888 assertSame(result1, value1);
889 assertFalse(profile.isUninitialized());
890 assertTrue(profile.isGeneric());
891 }
892
893 @Theory
894 public void testWithFloatThenObject(float value0, Object value1) {
895 float result0 = profile.profile(value0);
896 Object result1 = profile.profile(value1);
897
898 assertTrue(PrimitiveValueProfile.exactCompare(result0, value0));
899 assertSame(result1, value1);
900 assertFalse(profile.isUninitialized());
901 assertTrue(profile.isGeneric());
902 }
903
904 @Theory
905 public void testWithDoubleThenObject(double value0, Object value1) {
906 double result0 = profile.profile(value0);
907 Object result1 = profile.profile(value1);
908
909 assertTrue(PrimitiveValueProfile.exactCompare(result0, value0));
910 assertSame(result1, value1);
911 assertFalse(profile.isUninitialized());
912 assertTrue(profile.isGeneric());
913 }
914
915 @Theory
916 public void testWithBooleanThenObject(boolean value0, Object value1) {
917 boolean result0 = profile.profile(value0);
918 Object result1 = profile.profile(value1);
919
920 assertEquals(result0, value0);
921 assertSame(result1, value1);
922 assertFalse(profile.isUninitialized());
923 assertTrue(profile.isGeneric());
924 }
925
926 @Theory
927 public void testWithCharThenObject(char value0, Object value1) {
928 char result0 = profile.profile(value0);
929 Object result1 = profile.profile(value1);
930
931 assertEquals(result0, value0);
932 assertSame(result1, value1);
933 assertFalse(profile.isUninitialized());
934 assertTrue(profile.isGeneric());
935 }
936
937 @Test
938 public void testNegativeZeroFloat() {
939 profile.profile(-0.0f);
940 profile.profile(+0.0f);
941 assertThat(profile.isGeneric(), is(true));
942 }
943
944 @Test
945 public void testNegativeZeroDouble() {
946 profile.profile(-0.0);
947 profile.profile(+0.0);
948 assertThat(profile.isGeneric(), is(true));
949 }
950
951 @Test
952 public void testDisabled() {
953 PrimitiveValueProfile.Disabled p = (PrimitiveValueProfile.Disabled) PrimitiveValueProfile.Disabled.INSTANCE;
954 assertThat(p.profile(O1), is(O1));
955 assertThat(p.profile(B1), is(B1));
956 assertThat(p.profile(S1), is(S1));
957 assertThat(p.profile(I1), is(I1));
958 assertThat(p.profile(L1), is(L1));
959 assertThat(p.profile(F1), is(F1));
960 assertThat(p.profile(D1), is(D1));
961 assertThat(p.profile(T1), is(T1));
962 assertThat(p.profile(C1), is(C1));
963 p.toString(); // test that it is not crashing
964 }
965
966 }