Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestSerialization.java @ 18761:a665483c3881
Truffle-DSL: new node layout implementation.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Dec 2014 23:38:54 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
18760:6fa3999631d8 | 18761:a665483c3881 |
---|---|
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.dsl.test; | |
24 | |
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; | |
26 import static org.junit.Assert.*; | |
27 | |
28 import org.junit.*; | |
29 | |
30 import com.oracle.truffle.api.dsl.*; | |
31 import com.oracle.truffle.api.dsl.test.TestSerializationFactory.SerializedNodeFactory; | |
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | |
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
34 import com.oracle.truffle.api.nodes.*; | |
35 | |
36 public class TestSerialization { | |
37 | |
38 @Test | |
39 public void testUpdateRoot() { | |
40 /* Tests the unexpected polymorphic case. */ | |
41 TestRootNode<SerializedNode> node = TestHelper.createRoot(SerializedNodeFactory.getInstance()); | |
42 assertEquals(true, executeWith(node, true)); | |
43 assertEquals(21, executeWith(node, 21)); | |
44 assertEquals("s", executeWith(node, "s")); | |
45 assertEquals(3, node.getNode().invocations); | |
46 assertEquals(NodeCost.POLYMORPHIC, node.getNode().getCost()); | |
47 | |
48 @SuppressWarnings("unchecked") | |
49 TestRootNode<SerializedNode> copiedNode = (TestRootNode<SerializedNode>) node.deepCopy(); | |
50 copiedNode.adoptChildren(); | |
51 assertTrue(copiedNode != node); | |
52 assertEquals(true, executeWith(copiedNode, true)); | |
53 assertEquals(21, executeWith(copiedNode, 21)); | |
54 assertEquals("s", executeWith(copiedNode, "s")); | |
55 assertEquals(6, copiedNode.getNode().invocations); | |
56 } | |
57 | |
58 @NodeChild | |
59 abstract static class SerializedNode extends ValueNode { | |
60 | |
61 int invocations; | |
62 | |
63 @Specialization | |
64 int add(int left) { | |
65 invocations++; | |
66 return left; | |
67 } | |
68 | |
69 @Specialization | |
70 boolean add(boolean left) { | |
71 invocations++; | |
72 return left; | |
73 } | |
74 | |
75 @Specialization | |
76 String add(String left) { | |
77 invocations++; | |
78 return left; | |
79 } | |
80 | |
81 } | |
82 | |
83 } |