Mercurial > hg > truffle
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest2.java @ 14641:f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Fixed polymorphic specialization nodes could still reference children in some cases.
Removed generation of getCost methods since they were very expensive to call.
Removed generation of copyPolymorphic, setNext0.
Made generated executeGeneric0 and executeAndSpecialize0 final.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 20 Mar 2014 17:50:41 +0100 |
parents | 5d1308c78ddc |
children | 5148aab962af |
rev | line source |
---|---|
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.PolymorphicTest2Factory.Node1Factory; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.nodes.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 public class PolymorphicTest2 { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 @Test |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public void testMultipleTypes() { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 /* Tests the unexpected polymorphic case. */ |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 assertEquals(21, executeWith(node, false, false)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 assertEquals(42, executeWith(node, 21, 21)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
45 assertEquals(NodeCost.POLYMORPHIC, node.getNode().getCost()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 @SuppressWarnings("unused") |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 @PolymorphicLimit(3) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 abstract static class Node1 extends BinaryNode { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 @Specialization(order = 1) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 int add(int left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 return 42; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 @Specialization(order = 2) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 int add(boolean left, boolean right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 return 21; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 @Specialization(order = 4) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 String add(boolean left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 return "(boolean,int)"; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 } |