Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestSerialization.java @ 22157:dc83cc1f94f2
Using fully qualified imports
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 11:33:22 +0200 |
parents | 9c8c0937da41 |
children | 14e6dfb1ef05 |
rev | line source |
---|---|
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
25 import com.oracle.truffle.api.dsl.NodeChild; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
26 import com.oracle.truffle.api.dsl.Specialization; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
27 import static com.oracle.truffle.api.dsl.test.TestHelper.executeWith; |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.dsl.test.TestSerializationFactory.SerializedNodeFactory; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
31 import com.oracle.truffle.api.nodes.NodeCost; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
32 import static org.junit.Assert.assertEquals; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
33 import static org.junit.Assert.assertTrue; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
34 import org.junit.Test; |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 public class TestSerialization { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 @Test |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public void testUpdateRoot() { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 /* Tests the unexpected polymorphic case. */ |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 TestRootNode<SerializedNode> node = TestHelper.createRoot(SerializedNodeFactory.getInstance()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 assertEquals(true, executeWith(node, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 assertEquals(21, executeWith(node, 21)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 assertEquals("s", executeWith(node, "s")); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 assertEquals(3, node.getNode().invocations); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 assertEquals(NodeCost.POLYMORPHIC, node.getNode().getCost()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 @SuppressWarnings("unchecked") |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 TestRootNode<SerializedNode> copiedNode = (TestRootNode<SerializedNode>) node.deepCopy(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 copiedNode.adoptChildren(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 assertTrue(copiedNode != node); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 assertEquals(true, executeWith(copiedNode, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 assertEquals(21, executeWith(copiedNode, 21)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 assertEquals("s", executeWith(copiedNode, "s")); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 assertEquals(6, copiedNode.getNode().invocations); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 @NodeChild |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 abstract static class SerializedNode extends ValueNode { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 int invocations; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 @Specialization |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 int add(int left) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 invocations++; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 return left; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 @Specialization |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 boolean add(boolean left) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 invocations++; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 return left; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 @Specialization |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 String add(String left) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 invocations++; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 return left; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 } |