comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/PrimitiveValueProfileTest.java @ 21951:9c8c0937da41

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