43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.replacements.test;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0;
|
|
28 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0;
|
|
29 |
|
|
30 |
import java.lang.reflect.Method;
|
|
31 |
|
|
32 |
import org.junit.Assert;
|
|
33 |
import org.junit.Test;
|
|
34 |
|
|
35 |
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
|
36 |
import org.graalvm.compiler.graph.Edges;
|
|
37 |
import org.graalvm.compiler.graph.Node;
|
|
38 |
import org.graalvm.compiler.graph.NodeClass;
|
|
39 |
import org.graalvm.compiler.graph.NodeInputList;
|
|
40 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
41 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
42 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
43 |
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
|
44 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
45 |
import org.graalvm.compiler.nodes.calc.FloatingNode;
|
|
46 |
import org.graalvm.compiler.nodes.java.InstanceOfNode;
|
46640
|
47 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
48 |
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
|
49 |
import org.graalvm.compiler.phases.common.inlining.policy.InlineMethodSubstitutionsPolicy;
|
|
50 |
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
|
51 |
|
|
52 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
53 |
|
|
54 |
public class EdgesTest extends GraalCompilerTest {
|
|
55 |
|
|
56 |
@NodeInfo(cycles = CYCLES_0, size = SIZE_0)
|
|
57 |
static final class TestNode extends Node {
|
|
58 |
public static final NodeClass<TestNode> TYPE = NodeClass.create(TestNode.class);
|
|
59 |
@Input NodeInputList<ValueNode> itail;
|
|
60 |
@Input ConstantNode i1;
|
|
61 |
@Input FloatingNode i2;
|
|
62 |
|
|
63 |
protected TestNode() {
|
|
64 |
super(TYPE);
|
|
65 |
}
|
|
66 |
|
|
67 |
}
|
|
68 |
|
46640
|
69 |
protected StructuredGraph createGraph() {
|
|
70 |
OptionValues options = getInitialOptions();
|
|
71 |
return new StructuredGraph.Builder(options, getDebugContext(options)).build();
|
|
72 |
}
|
|
73 |
|
|
74 |
StructuredGraph graph = createGraph();
|
43972
|
75 |
TestNode node;
|
|
76 |
ConstantNode i1;
|
|
77 |
ConstantNode i2;
|
|
78 |
ConstantNode i3;
|
|
79 |
ConstantNode i4;
|
|
80 |
Edges inputs;
|
|
81 |
|
|
82 |
public EdgesTest() {
|
|
83 |
node = new TestNode();
|
|
84 |
i1 = ConstantNode.forInt(1, graph);
|
|
85 |
i2 = ConstantNode.forDouble(1.0d, graph);
|
|
86 |
i3 = ConstantNode.forInt(4, graph);
|
|
87 |
i4 = ConstantNode.forInt(14, graph);
|
|
88 |
node.itail = new NodeInputList<>(node, new ValueNode[]{i3, i4});
|
|
89 |
node.i1 = i1;
|
|
90 |
node.i2 = i2;
|
|
91 |
graph.add(node);
|
|
92 |
inputs = node.getNodeClass().getInputEdges();
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Checks that there are no checkcasts in the compiled version of
|
|
97 |
* {@link Edges#getNode(Node, long[], int)}.
|
|
98 |
*/
|
|
99 |
@Test
|
|
100 |
public void test0() {
|
|
101 |
testMethod(getMethod("getNode", Node.class, long[].class, int.class), null, node, inputs.getOffsets(), 0);
|
|
102 |
}
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Checks that there are no checkcasts in the compiled version of
|
|
106 |
* {@link Edges#getNodeList(Node, long[], int)}.
|
|
107 |
*/
|
|
108 |
@Test
|
|
109 |
public void test1() {
|
|
110 |
testMethod(getMethod("getNodeList", Node.class, long[].class, int.class), null, node, inputs.getOffsets(), 2);
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Checks that there are no checkcasts in the compiled version of
|
|
115 |
* {@link Edges#setNode(Node, int, Node)}.
|
|
116 |
*/
|
|
117 |
@Test
|
|
118 |
public void test2() {
|
|
119 |
testMethod(getMethod("setNode", Node.class, int.class, Node.class), inputs, node, 1, i2);
|
|
120 |
}
|
|
121 |
|
|
122 |
private void testMethod(Method method, Object receiver, Object... args) {
|
|
123 |
try {
|
|
124 |
// Invoke the method to ensure it has a type profile
|
|
125 |
for (int i = 0; i < 5000; i++) {
|
|
126 |
method.invoke(receiver, args);
|
|
127 |
}
|
|
128 |
} catch (Exception e) {
|
|
129 |
throw new RuntimeException(e);
|
|
130 |
}
|
|
131 |
|
|
132 |
ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
|
|
133 |
StructuredGraph g = parseProfiled(javaMethod, AllowAssumptions.NO);
|
|
134 |
HighTierContext context = getDefaultHighTierContext();
|
58877
|
135 |
new InliningPhase(new InlineMethodSubstitutionsPolicy(), createCanonicalizerPhase()).apply(g, context);
|
|
136 |
this.createCanonicalizerPhase().apply(g, context);
|
43972
|
137 |
Assert.assertTrue(g.getNodes().filter(InstanceOfNode.class).isEmpty());
|
|
138 |
}
|
|
139 |
|
|
140 |
private static Method getMethod(final String name, Class<?>... parameters) {
|
|
141 |
try {
|
|
142 |
return Edges.class.getDeclaredMethod(name, parameters);
|
|
143 |
} catch (NoSuchMethodException | SecurityException e) {
|
|
144 |
throw new RuntimeException(e);
|
|
145 |
}
|
|
146 |
}
|
|
147 |
}
|