Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/BadLongOverflowSpecializationTest.java @ 18564:966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 27 Nov 2014 11:45:13 +0100 |
parents | 2c68474cc893 |
children | eecda5abf627 |
rev | line source |
---|---|
18221
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
1 /* |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
4 * |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
8 * |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
14 * |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
18 * |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
21 * questions. |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
22 */ |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
24 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
27 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
28 import java.math.*; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
29 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
30 import org.junit.*; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
31 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.*; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.*; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.test.BadLongOverflowSpecializationTestFactory.AddNodeFactory; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
37 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
38 public class BadLongOverflowSpecializationTest { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
39 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
40 @NodeChildren({@NodeChild("left"), @NodeChild("right")}) |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
41 abstract static class BinaryNode extends ValueNode { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
42 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
43 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
44 abstract static class AddNode extends BinaryNode { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
45 @Specialization(rewriteOn = ArithmeticException.class) |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
46 int add(int left, int right) { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
47 return ExactMath.addExact(left, right); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
48 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
49 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
50 @Specialization |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
51 long addIntWithOverflow(int left, int right) { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
52 return (long) left + (long) right; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
53 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
54 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
55 @Specialization(rewriteOn = ArithmeticException.class) |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
56 Object add(long left, long right) { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
57 return ExactMath.addExact(left, right); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
58 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
59 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
60 @Specialization |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
61 BigInteger addSlow(long left, long right) { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
62 return BigInteger.valueOf(left).add(BigInteger.valueOf(right)); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
63 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
64 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
65 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
66 @Test |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
67 @Ignore |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
68 public void testAdd() { |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
69 TestRootNode<AddNode> node = createRoot(AddNodeFactory.getInstance()); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
70 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
71 long index = -1; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
72 int baseStep = 0; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
73 Object r1 = executeWith(node, index, baseStep); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
74 assertEquals(-1L, r1); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
75 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
76 long err = 5000; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
77 long errStep = 2000; |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
78 Object r2 = executeWith(node, err, errStep); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
79 |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
80 assertEquals(Long.class, r2.getClass()); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
81 assertEquals(7000L, r2); |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
82 } |
2c68474cc893
Truffle: add a test to track an ImplicitCast bug
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
83 } |