46762
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 2017, 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 org.graalvm.graphio;
|
|
24 |
|
|
25 |
import java.io.IOException;
|
|
26 |
import java.nio.channels.WritableByteChannel;
|
|
27 |
import java.util.Collection;
|
|
28 |
import java.util.Map;
|
|
29 |
|
|
30 |
final class ProtocolImpl<Graph, Node, NodeClass, Port, Block, ResolvedJavaMethod, ResolvedJavaField, Signature, NodeSourcePosition>
|
|
31 |
extends GraphProtocol<Graph, Node, NodeClass, Port, Block, ResolvedJavaMethod, ResolvedJavaField, Signature, NodeSourcePosition> {
|
|
32 |
private final GraphStructure<Graph, Node, NodeClass, Port> structure;
|
|
33 |
private final GraphTypes types;
|
|
34 |
private final GraphBlocks<Graph, Block, Node> blocks;
|
|
35 |
private final GraphElements<ResolvedJavaMethod, ResolvedJavaField, Signature, NodeSourcePosition> elements;
|
|
36 |
|
|
37 |
ProtocolImpl(GraphStructure<Graph, Node, NodeClass, Port> structure, GraphTypes enums, GraphBlocks<Graph, Block, Node> blocks,
|
|
38 |
GraphElements<ResolvedJavaMethod, ResolvedJavaField, Signature, NodeSourcePosition> elements, WritableByteChannel channel) throws IOException {
|
|
39 |
super(channel);
|
|
40 |
this.structure = structure;
|
|
41 |
this.types = enums;
|
|
42 |
this.blocks = blocks;
|
|
43 |
this.elements = elements;
|
|
44 |
}
|
|
45 |
|
|
46 |
@Override
|
|
47 |
protected Graph findGraph(Graph current, Object obj) {
|
|
48 |
return structure.graph(current, obj);
|
|
49 |
}
|
|
50 |
|
|
51 |
@Override
|
|
52 |
protected NodeClass findNodeClass(Object obj) {
|
|
53 |
return structure.nodeClass(obj);
|
|
54 |
}
|
|
55 |
|
|
56 |
@Override
|
|
57 |
protected String findNameTemplate(NodeClass clazz) {
|
|
58 |
return structure.nameTemplate(clazz);
|
|
59 |
}
|
|
60 |
|
|
61 |
@Override
|
|
62 |
protected int findNodeId(Node n) {
|
|
63 |
return structure.nodeId(n);
|
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
|
67 |
protected boolean hasPredecessor(Node node) {
|
|
68 |
return structure.nodeHasPredecessor(node);
|
|
69 |
}
|
|
70 |
|
|
71 |
@Override
|
|
72 |
protected int findNodesCount(Graph info) {
|
|
73 |
return structure.nodesCount(info);
|
|
74 |
}
|
|
75 |
|
|
76 |
@Override
|
|
77 |
protected Iterable<? extends Node> findNodes(Graph info) {
|
|
78 |
return structure.nodes(info);
|
|
79 |
}
|
|
80 |
|
|
81 |
@Override
|
|
82 |
protected void findNodeProperties(Node node, Map<String, Object> props, Graph info) {
|
|
83 |
structure.nodeProperties(info, node, props);
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
protected Port findClassEdges(NodeClass nodeClass, boolean dumpInputs) {
|
|
88 |
if (dumpInputs) {
|
|
89 |
return structure.portInputs(nodeClass);
|
|
90 |
} else {
|
|
91 |
return structure.portOutputs(nodeClass);
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
@Override
|
|
96 |
protected int findSize(Port edges) {
|
|
97 |
return structure.portSize(edges);
|
|
98 |
}
|
|
99 |
|
|
100 |
@Override
|
|
101 |
protected boolean isDirect(Port edges, int i) {
|
|
102 |
return structure.edgeDirect(edges, i);
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
|
106 |
protected String findName(Port edges, int i) {
|
|
107 |
return structure.edgeName(edges, i);
|
|
108 |
}
|
|
109 |
|
|
110 |
@Override
|
|
111 |
protected Object findType(Port edges, int i) {
|
|
112 |
return structure.edgeType(edges, i);
|
|
113 |
}
|
|
114 |
|
|
115 |
@Override
|
|
116 |
protected Collection<? extends Node> findNodes(Graph graph, Node node, Port port, int i) {
|
|
117 |
return structure.edgeNodes(graph, node, port, i);
|
|
118 |
}
|
|
119 |
|
|
120 |
@Override
|
|
121 |
protected Object findJavaClass(NodeClass clazz) {
|
|
122 |
return structure.nodeClassType(clazz);
|
|
123 |
}
|
|
124 |
|
|
125 |
@Override
|
|
126 |
protected Object findEnumClass(Object enumValue) {
|
|
127 |
return types.enumClass(enumValue);
|
|
128 |
}
|
|
129 |
|
|
130 |
@Override
|
|
131 |
protected int findEnumOrdinal(Object obj) {
|
|
132 |
return types.enumOrdinal(obj);
|
|
133 |
}
|
|
134 |
|
|
135 |
@Override
|
|
136 |
protected String[] findEnumTypeValues(Object clazz) {
|
|
137 |
return types.enumTypeValues(clazz);
|
|
138 |
}
|
|
139 |
|
|
140 |
@Override
|
|
141 |
protected String findJavaTypeName(Object obj) {
|
|
142 |
return types.typeName(obj);
|
|
143 |
}
|
|
144 |
|
|
145 |
@Override
|
|
146 |
protected Collection<? extends Node> findBlockNodes(Graph info, Block block) {
|
|
147 |
return blocks.blockNodes(info, block);
|
|
148 |
}
|
|
149 |
|
|
150 |
@Override
|
|
151 |
protected int findBlockId(Block block) {
|
|
152 |
return blocks.blockId(block);
|
|
153 |
}
|
|
154 |
|
|
155 |
@Override
|
|
156 |
protected Collection<? extends Block> findBlocks(Graph graph) {
|
|
157 |
return blocks.blocks(graph);
|
|
158 |
}
|
|
159 |
|
|
160 |
@Override
|
|
161 |
protected Collection<? extends Block> findBlockSuccessors(Block block) {
|
|
162 |
return blocks.blockSuccessors(block);
|
|
163 |
}
|
|
164 |
|
|
165 |
@Override
|
|
166 |
protected ResolvedJavaMethod findMethod(Object obj) {
|
|
167 |
return elements == null ? null : elements.method(obj);
|
|
168 |
}
|
|
169 |
|
|
170 |
@Override
|
|
171 |
protected byte[] findMethodCode(ResolvedJavaMethod method) {
|
|
172 |
return elements.methodCode(method);
|
|
173 |
}
|
|
174 |
|
|
175 |
@Override
|
|
176 |
protected int findMethodModifiers(ResolvedJavaMethod method) {
|
|
177 |
return elements.methodModifiers(method);
|
|
178 |
}
|
|
179 |
|
|
180 |
@Override
|
|
181 |
protected Signature findMethodSignature(ResolvedJavaMethod method) {
|
|
182 |
return elements.methodSignature(method);
|
|
183 |
}
|
|
184 |
|
|
185 |
@Override
|
|
186 |
protected String findMethodName(ResolvedJavaMethod method) {
|
|
187 |
return elements.methodName(method);
|
|
188 |
}
|
|
189 |
|
|
190 |
@Override
|
|
191 |
protected Object findMethodDeclaringClass(ResolvedJavaMethod method) {
|
|
192 |
return elements.methodDeclaringClass(method);
|
|
193 |
}
|
|
194 |
|
|
195 |
@Override
|
|
196 |
protected int findFieldModifiers(ResolvedJavaField field) {
|
|
197 |
return elements.fieldModifiers(field);
|
|
198 |
}
|
|
199 |
|
|
200 |
@Override
|
|
201 |
protected String findFieldTypeName(ResolvedJavaField field) {
|
|
202 |
return elements.fieldTypeName(field);
|
|
203 |
}
|
|
204 |
|
|
205 |
@Override
|
|
206 |
protected String findFieldName(ResolvedJavaField field) {
|
|
207 |
return elements.fieldName(field);
|
|
208 |
}
|
|
209 |
|
|
210 |
@Override
|
|
211 |
protected Object findFieldDeclaringClass(ResolvedJavaField field) {
|
|
212 |
return elements.fieldDeclaringClass(field);
|
|
213 |
}
|
|
214 |
|
|
215 |
@Override
|
|
216 |
protected ResolvedJavaField findJavaField(Object object) {
|
|
217 |
return elements == null ? null : elements.field(object);
|
|
218 |
}
|
|
219 |
|
|
220 |
@Override
|
|
221 |
protected Signature findSignature(Object object) {
|
|
222 |
return elements == null ? null : elements.signature(object);
|
|
223 |
}
|
|
224 |
|
|
225 |
@Override
|
|
226 |
protected int findSignatureParameterCount(Signature signature) {
|
|
227 |
return elements.signatureParameterCount(signature);
|
|
228 |
}
|
|
229 |
|
|
230 |
@Override
|
|
231 |
protected String findSignatureParameterTypeName(Signature signature, int index) {
|
|
232 |
return elements.signatureParameterTypeName(signature, index);
|
|
233 |
}
|
|
234 |
|
|
235 |
@Override
|
|
236 |
protected String findSignatureReturnTypeName(Signature signature) {
|
|
237 |
return elements.signatureReturnTypeName(signature);
|
|
238 |
}
|
|
239 |
|
|
240 |
@Override
|
|
241 |
protected NodeSourcePosition findNodeSourcePosition(Object object) {
|
|
242 |
return elements == null ? null : elements.nodeSourcePosition(object);
|
|
243 |
}
|
|
244 |
|
|
245 |
@Override
|
|
246 |
protected ResolvedJavaMethod findNodeSourcePositionMethod(NodeSourcePosition pos) {
|
|
247 |
return elements.nodeSourcePositionMethod(pos);
|
|
248 |
}
|
|
249 |
|
|
250 |
@Override
|
|
251 |
protected NodeSourcePosition findNodeSourcePositionCaller(NodeSourcePosition pos) {
|
|
252 |
return elements.nodeSourcePositionCaller(pos);
|
|
253 |
}
|
|
254 |
|
|
255 |
@Override
|
|
256 |
protected int findNodeSourcePositionBCI(NodeSourcePosition pos) {
|
|
257 |
return elements.nodeSourcePositionBCI(pos);
|
|
258 |
}
|
|
259 |
|
|
260 |
@Override
|
|
261 |
protected StackTraceElement findMethodStackTraceElement(ResolvedJavaMethod method, int bci, NodeSourcePosition pos) {
|
|
262 |
return elements.methodStackTraceElement(method, bci, pos);
|
|
263 |
}
|
|
264 |
|
|
265 |
@Override
|
|
266 |
protected void findExtraNodes(Node node, Collection<? super Node> extraNodes) {
|
|
267 |
}
|
|
268 |
|
|
269 |
@Override
|
|
270 |
protected String formatTitle(Graph graph, int id, String format, Object... args) {
|
|
271 |
return String.format(format, args) + " [" + id + "]";
|
|
272 |
}
|
|
273 |
}
|