File: | jdk/src/hotspot/share/opto/idealGraphPrinter.cpp |
Warning: | line 557, column 29 Value stored to 'typeKlass' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (c) 2007, 2021, 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 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "memory/resourceArea.hpp" |
27 | #include "opto/chaitin.hpp" |
28 | #include "opto/idealGraphPrinter.hpp" |
29 | #include "opto/machnode.hpp" |
30 | #include "opto/parse.hpp" |
31 | #include "runtime/threadCritical.hpp" |
32 | #include "runtime/threadSMR.hpp" |
33 | #include "utilities/stringUtils.hpp" |
34 | |
35 | #ifndef PRODUCT |
36 | |
37 | // Constants |
38 | // Keep consistent with Java constants |
39 | const char *IdealGraphPrinter::INDENT = " "; |
40 | const char *IdealGraphPrinter::TOP_ELEMENT = "graphDocument"; |
41 | const char *IdealGraphPrinter::GROUP_ELEMENT = "group"; |
42 | const char *IdealGraphPrinter::GRAPH_ELEMENT = "graph"; |
43 | const char *IdealGraphPrinter::PROPERTIES_ELEMENT = "properties"; |
44 | const char *IdealGraphPrinter::EDGES_ELEMENT = "edges"; |
45 | const char *IdealGraphPrinter::PROPERTY_ELEMENT = "p"; |
46 | const char *IdealGraphPrinter::EDGE_ELEMENT = "edge"; |
47 | const char *IdealGraphPrinter::NODE_ELEMENT = "node"; |
48 | const char *IdealGraphPrinter::NODES_ELEMENT = "nodes"; |
49 | const char *IdealGraphPrinter::REMOVE_EDGE_ELEMENT = "removeEdge"; |
50 | const char *IdealGraphPrinter::REMOVE_NODE_ELEMENT = "removeNode"; |
51 | const char *IdealGraphPrinter::COMPILATION_ID_PROPERTY = "compilationId"; |
52 | const char *IdealGraphPrinter::COMPILATION_OSR_PROPERTY = "osr"; |
53 | const char *IdealGraphPrinter::METHOD_NAME_PROPERTY = "name"; |
54 | const char *IdealGraphPrinter::METHOD_IS_PUBLIC_PROPERTY = "public"; |
55 | const char *IdealGraphPrinter::METHOD_IS_STATIC_PROPERTY = "static"; |
56 | const char *IdealGraphPrinter::TRUE_VALUE = "true"; |
57 | const char *IdealGraphPrinter::NODE_NAME_PROPERTY = "name"; |
58 | const char *IdealGraphPrinter::EDGE_NAME_PROPERTY = "name"; |
59 | const char *IdealGraphPrinter::NODE_ID_PROPERTY = "id"; |
60 | const char *IdealGraphPrinter::FROM_PROPERTY = "from"; |
61 | const char *IdealGraphPrinter::TO_PROPERTY = "to"; |
62 | const char *IdealGraphPrinter::PROPERTY_NAME_PROPERTY = "name"; |
63 | const char *IdealGraphPrinter::GRAPH_NAME_PROPERTY = "name"; |
64 | const char *IdealGraphPrinter::INDEX_PROPERTY = "index"; |
65 | const char *IdealGraphPrinter::METHOD_ELEMENT = "method"; |
66 | const char *IdealGraphPrinter::INLINE_ELEMENT = "inlined"; |
67 | const char *IdealGraphPrinter::BYTECODES_ELEMENT = "bytecodes"; |
68 | const char *IdealGraphPrinter::METHOD_BCI_PROPERTY = "bci"; |
69 | const char *IdealGraphPrinter::METHOD_SHORT_NAME_PROPERTY = "shortName"; |
70 | const char *IdealGraphPrinter::CONTROL_FLOW_ELEMENT = "controlFlow"; |
71 | const char *IdealGraphPrinter::BLOCK_NAME_PROPERTY = "name"; |
72 | const char *IdealGraphPrinter::BLOCK_DOMINATOR_PROPERTY = "dom"; |
73 | const char *IdealGraphPrinter::BLOCK_ELEMENT = "block"; |
74 | const char *IdealGraphPrinter::SUCCESSORS_ELEMENT = "successors"; |
75 | const char *IdealGraphPrinter::SUCCESSOR_ELEMENT = "successor"; |
76 | const char *IdealGraphPrinter::ASSEMBLY_ELEMENT = "assembly"; |
77 | |
78 | int IdealGraphPrinter::_file_count = 0; |
79 | |
80 | IdealGraphPrinter *IdealGraphPrinter::printer() { |
81 | JavaThread *thread = JavaThread::current(); |
82 | if (!thread->is_Compiler_thread()) return NULL__null; |
83 | |
84 | CompilerThread *compiler_thread = (CompilerThread *)thread; |
85 | if (compiler_thread->ideal_graph_printer() == NULL__null) { |
86 | IdealGraphPrinter *printer = new IdealGraphPrinter(); |
87 | compiler_thread->set_ideal_graph_printer(printer); |
88 | } |
89 | |
90 | return compiler_thread->ideal_graph_printer(); |
91 | } |
92 | |
93 | void IdealGraphPrinter::clean_up() { |
94 | for (JavaThreadIteratorWithHandle jtiwh; JavaThread* p = jtiwh.next(); ) { |
95 | if (p->is_Compiler_thread()) { |
96 | CompilerThread* c = (CompilerThread*)p; |
97 | IdealGraphPrinter* printer = c->ideal_graph_printer(); |
98 | if (printer) { |
99 | delete printer; |
100 | } |
101 | c->set_ideal_graph_printer(NULL__null); |
102 | } |
103 | } |
104 | IdealGraphPrinter* debug_file_printer = Compile::debug_file_printer(); |
105 | if (debug_file_printer != NULL__null) { |
106 | delete debug_file_printer; |
107 | } |
108 | IdealGraphPrinter* debug_network_printer = Compile::debug_network_printer(); |
109 | if (debug_network_printer != NULL__null) { |
110 | delete debug_network_printer; |
111 | } |
112 | } |
113 | |
114 | // Either print methods to file specified with PrintIdealGraphFile or otherwise over the network to the IGV |
115 | IdealGraphPrinter::IdealGraphPrinter() { |
116 | init(PrintIdealGraphFile, true, false); |
117 | } |
118 | |
119 | // Either print methods to the specified file 'file_name' or if NULL over the network to the IGV. If 'append' |
120 | // is set, the next phase is directly appended to the specified file 'file_name'. This is useful when doing |
121 | // replay compilation with a tool like rr that cannot alter the current program state but only the file. |
122 | IdealGraphPrinter::IdealGraphPrinter(Compile* compile, const char* file_name, bool append) { |
123 | assert(!append || (append && file_name != NULL), "can only use append flag when printing to file")do { if (!(!append || (append && file_name != __null) )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 123, "assert(" "!append || (append && file_name != __null)" ") failed", "can only use append flag when printing to file" ); ::breakpoint(); } } while (0); |
124 | init(file_name, false, append); |
125 | C = compile; |
126 | if (append) { |
127 | // When directly appending the next graph, we only need to set _current_method and not set up a new method |
128 | _current_method = C->method(); |
129 | } else { |
130 | begin_method(); |
131 | } |
132 | } |
133 | |
134 | void IdealGraphPrinter::init(const char* file_name, bool use_multiple_files, bool append) { |
135 | // By default dump both ins and outs since dead or unreachable code |
136 | // needs to appear in the graph. There are also some special cases |
137 | // in the mach where kill projections have no users but should |
138 | // appear in the dump. |
139 | _traverse_outs = true; |
140 | _should_send_method = true; |
141 | _output = NULL__null; |
142 | buffer[0] = 0; |
143 | _depth = 0; |
144 | _current_method = NULL__null; |
145 | _network_stream = NULL__null; |
146 | |
147 | if (file_name != NULL__null) { |
148 | init_file_stream(file_name, use_multiple_files, append); |
149 | } else { |
150 | init_network_stream(); |
151 | } |
152 | _xml = new (ResourceObj::C_HEAP, mtCompiler) xmlStream(_output); |
153 | if (!append) { |
154 | head(TOP_ELEMENT); |
155 | } |
156 | } |
157 | |
158 | // Destructor, close file or network stream |
159 | IdealGraphPrinter::~IdealGraphPrinter() { |
160 | tail(TOP_ELEMENT); |
161 | |
162 | // tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds()); |
163 | // tty->print_cr("Output time: %d", (int)_output_time.milliseconds()); |
164 | // tty->print_cr("Build blocks time: %d", (int)_build_blocks_time.milliseconds()); |
165 | |
166 | if(_xml) { |
167 | delete _xml; |
168 | _xml = NULL__null; |
169 | } |
170 | |
171 | if (_network_stream) { |
172 | delete _network_stream; |
173 | if (_network_stream == _output) { |
174 | _output = NULL__null; |
175 | } |
176 | _network_stream = NULL__null; |
177 | } |
178 | |
179 | if (_output) { |
180 | delete _output; |
181 | _output = NULL__null; |
182 | } |
183 | } |
184 | |
185 | void IdealGraphPrinter::begin_elem(const char *s) { |
186 | _xml->begin_elem("%s", s); |
187 | } |
188 | |
189 | void IdealGraphPrinter::end_elem() { |
190 | _xml->end_elem(); |
191 | } |
192 | |
193 | void IdealGraphPrinter::begin_head(const char *s) { |
194 | _xml->begin_head("%s", s); |
195 | } |
196 | |
197 | void IdealGraphPrinter::end_head() { |
198 | _xml->end_head(); |
199 | } |
200 | |
201 | void IdealGraphPrinter::print_attr(const char *name, intptr_t val) { |
202 | stringStream stream; |
203 | stream.print(INTX_FORMAT"%" "l" "d", val); |
204 | print_attr(name, stream.as_string()); |
205 | } |
206 | |
207 | void IdealGraphPrinter::print_attr(const char *name, const char *val) { |
208 | _xml->print(" %s='", name); |
209 | text(val); |
210 | _xml->print("'"); |
211 | } |
212 | |
213 | void IdealGraphPrinter::head(const char *name) { |
214 | _xml->head("%s", name); |
215 | } |
216 | |
217 | void IdealGraphPrinter::tail(const char *name) { |
218 | _xml->tail(name); |
219 | } |
220 | |
221 | void IdealGraphPrinter::text(const char *s) { |
222 | _xml->text("%s", s); |
223 | } |
224 | |
225 | void IdealGraphPrinter::print_prop(const char *name, int val) { |
226 | stringStream stream; |
227 | stream.print("%d", val); |
228 | print_prop(name, stream.as_string()); |
229 | } |
230 | |
231 | void IdealGraphPrinter::print_prop(const char *name, const char *val) { |
232 | begin_head(PROPERTY_ELEMENT); |
233 | print_attr(PROPERTY_NAME_PROPERTY, name); |
234 | end_head(); |
235 | text(val); |
236 | tail(PROPERTY_ELEMENT); |
237 | } |
238 | |
239 | void IdealGraphPrinter::print_method(ciMethod *method, int bci, InlineTree *tree) { |
240 | begin_head(METHOD_ELEMENT); |
241 | |
242 | stringStream str; |
243 | method->print_name(&str); |
244 | |
245 | stringStream shortStr; |
246 | method->print_short_name(&shortStr); |
247 | |
248 | print_attr(METHOD_NAME_PROPERTY, str.as_string()); |
249 | print_attr(METHOD_SHORT_NAME_PROPERTY, shortStr.as_string()); |
250 | print_attr(METHOD_BCI_PROPERTY, bci); |
251 | |
252 | end_head(); |
253 | |
254 | head(BYTECODES_ELEMENT); |
255 | _xml->print_cr("<![CDATA["); |
256 | method->print_codes_on(_xml); |
257 | _xml->print_cr("]]>"); |
258 | tail(BYTECODES_ELEMENT); |
259 | |
260 | if (tree != NULL__null && tree->subtrees().length() > 0) { |
261 | head(INLINE_ELEMENT); |
262 | GrowableArray<InlineTree *> subtrees = tree->subtrees(); |
263 | for (int i = 0; i < subtrees.length(); i++) { |
264 | print_inline_tree(subtrees.at(i)); |
265 | } |
266 | tail(INLINE_ELEMENT); |
267 | } |
268 | |
269 | tail(METHOD_ELEMENT); |
270 | _xml->flush(); |
271 | } |
272 | |
273 | void IdealGraphPrinter::print_inline_tree(InlineTree *tree) { |
274 | if (tree != NULL__null) { |
275 | print_method(tree->method(), tree->caller_bci(), tree); |
276 | } |
277 | } |
278 | |
279 | void IdealGraphPrinter::print_inlining() { |
280 | |
281 | // Print inline tree |
282 | if (_should_send_method) { |
283 | InlineTree *inlineTree = C->ilt(); |
284 | if (inlineTree != NULL__null) { |
285 | print_inline_tree(inlineTree); |
286 | } else { |
287 | // print this method only |
288 | } |
289 | } |
290 | } |
291 | |
292 | // Has to be called whenever a method is compiled |
293 | void IdealGraphPrinter::begin_method() { |
294 | |
295 | ciMethod *method = C->method(); |
296 | assert(_output, "output stream must exist!")do { if (!(_output)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 296, "assert(" "_output" ") failed", "output stream must exist!" ); ::breakpoint(); } } while (0); |
297 | assert(method, "null methods are not allowed!")do { if (!(method)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 297, "assert(" "method" ") failed", "null methods are not allowed!" ); ::breakpoint(); } } while (0); |
298 | assert(!_current_method, "current method must be null!")do { if (!(!_current_method)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 298, "assert(" "!_current_method" ") failed", "current method must be null!" ); ::breakpoint(); } } while (0); |
299 | |
300 | head(GROUP_ELEMENT); |
301 | |
302 | head(PROPERTIES_ELEMENT); |
303 | |
304 | // Print properties |
305 | // Add method name |
306 | stringStream strStream; |
307 | method->print_name(&strStream); |
308 | print_prop(METHOD_NAME_PROPERTY, strStream.as_string()); |
309 | |
310 | if (method->flags().is_public()) { |
311 | print_prop(METHOD_IS_PUBLIC_PROPERTY, TRUE_VALUE); |
312 | } |
313 | |
314 | if (method->flags().is_static()) { |
315 | print_prop(METHOD_IS_STATIC_PROPERTY, TRUE_VALUE); |
316 | } |
317 | |
318 | if (C->is_osr_compilation()) { |
319 | print_prop(COMPILATION_OSR_PROPERTY, TRUE_VALUE); |
320 | } |
321 | |
322 | print_prop(COMPILATION_ID_PROPERTY, C->compile_id()); |
323 | |
324 | tail(PROPERTIES_ELEMENT); |
325 | |
326 | _should_send_method = true; |
327 | this->_current_method = method; |
328 | |
329 | _xml->flush(); |
330 | } |
331 | |
332 | // Has to be called whenever a method has finished compilation |
333 | void IdealGraphPrinter::end_method() { |
334 | tail(GROUP_ELEMENT); |
335 | _current_method = NULL__null; |
336 | _xml->flush(); |
337 | } |
338 | |
339 | bool IdealGraphPrinter::traverse_outs() { |
340 | return _traverse_outs; |
341 | } |
342 | |
343 | void IdealGraphPrinter::set_traverse_outs(bool b) { |
344 | _traverse_outs = b; |
345 | } |
346 | |
347 | void IdealGraphPrinter::visit_node(Node *n, bool edges, VectorSet* temp_set) { |
348 | |
349 | if (edges) { |
350 | |
351 | for (uint i = 0; i < n->len(); i++) { |
352 | if (n->in(i)) { |
353 | Node *source = n->in(i); |
354 | begin_elem(EDGE_ELEMENT); |
355 | print_attr(FROM_PROPERTY, source->_igv_idx); |
356 | print_attr(TO_PROPERTY, n->_igv_idx); |
357 | print_attr(INDEX_PROPERTY, i); |
358 | end_elem(); |
359 | } |
360 | } |
361 | |
362 | } else { |
363 | |
364 | // Output node |
365 | begin_head(NODE_ELEMENT); |
366 | print_attr(NODE_ID_PROPERTY, n->_igv_idx); |
367 | end_head(); |
368 | |
369 | head(PROPERTIES_ELEMENT); |
370 | |
371 | Node *node = n; |
372 | #ifndef PRODUCT |
373 | Compile::current()->_in_dump_cnt++; |
374 | print_prop(NODE_NAME_PROPERTY, (const char *)node->Name()); |
375 | const Type *t = node->bottom_type(); |
376 | print_prop("type", t->msg()); |
377 | print_prop("idx", node->_idx); |
378 | #ifdef ASSERT1 |
379 | print_prop("debug_idx", node->_debug_idx); |
380 | #endif |
381 | |
382 | if (C->cfg() != NULL__null) { |
383 | Block* block = C->cfg()->get_block_for_node(node); |
384 | if (block == NULL__null) { |
385 | print_prop("block", C->cfg()->get_block(0)->_pre_order); |
386 | } else { |
387 | print_prop("block", block->_pre_order); |
388 | // Print estimated execution frequency, normalized within a [0,1] range. |
389 | buffer[0] = 0; |
390 | stringStream freq(buffer, sizeof(buffer) - 1); |
391 | // Higher precision has no practical effect in visualizations. |
392 | freq.print("%.8f", block->_freq / _max_freq); |
393 | assert(freq.size() < sizeof(buffer), "size in range")do { if (!(freq.size() < sizeof(buffer))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 393, "assert(" "freq.size() < sizeof(buffer)" ") failed" , "size in range"); ::breakpoint(); } } while (0); |
394 | // Enforce dots as decimal separators, as required by IGV. |
395 | StringUtils::replace_no_expand(buffer, ",", "."); |
396 | print_prop("frequency", buffer); |
397 | } |
398 | } |
399 | |
400 | switch (t->category()) { |
401 | case Type::Category::Data: |
402 | print_prop("category", "data"); |
403 | break; |
404 | case Type::Category::Memory: |
405 | print_prop("category", "memory"); |
406 | break; |
407 | case Type::Category::Mixed: |
408 | print_prop("category", "mixed"); |
409 | break; |
410 | case Type::Category::Control: |
411 | print_prop("category", "control"); |
412 | break; |
413 | case Type::Category::Other: |
414 | print_prop("category", "other"); |
415 | break; |
416 | case Type::Category::Undef: |
417 | print_prop("category", "undef"); |
418 | break; |
419 | } |
420 | |
421 | Node_Notes* nn = C->node_notes_at(node->_idx); |
422 | if (nn != NULL__null && !nn->is_clear() && nn->jvms() != NULL__null) { |
423 | buffer[0] = 0; |
424 | stringStream ss(buffer, sizeof(buffer) - 1); |
425 | nn->jvms()->dump_spec(&ss); |
426 | print_prop("jvms", buffer); |
427 | } |
428 | |
429 | const jushort flags = node->flags(); |
430 | if (flags & Node::Flag_is_Copy) { |
431 | print_prop("is_copy", "true"); |
432 | } |
433 | if (flags & Node::Flag_rematerialize) { |
434 | print_prop("rematerialize", "true"); |
435 | } |
436 | if (flags & Node::Flag_needs_anti_dependence_check) { |
437 | print_prop("needs_anti_dependence_check", "true"); |
438 | } |
439 | if (flags & Node::Flag_is_macro) { |
440 | print_prop("is_macro", "true"); |
441 | } |
442 | if (flags & Node::Flag_is_Con) { |
443 | print_prop("is_con", "true"); |
444 | } |
445 | if (flags & Node::Flag_is_cisc_alternate) { |
446 | print_prop("is_cisc_alternate", "true"); |
447 | } |
448 | if (flags & Node::Flag_is_dead_loop_safe) { |
449 | print_prop("is_dead_loop_safe", "true"); |
450 | } |
451 | if (flags & Node::Flag_may_be_short_branch) { |
452 | print_prop("may_be_short_branch", "true"); |
453 | } |
454 | if (flags & Node::Flag_has_call) { |
455 | print_prop("has_call", "true"); |
456 | } |
457 | |
458 | if (C->matcher() != NULL__null) { |
459 | if (C->matcher()->is_shared(node)) { |
460 | print_prop("is_shared", "true"); |
461 | } else { |
462 | print_prop("is_shared", "false"); |
463 | } |
464 | if (C->matcher()->is_dontcare(node)) { |
465 | print_prop("is_dontcare", "true"); |
466 | } else { |
467 | print_prop("is_dontcare", "false"); |
468 | } |
469 | Node* old = C->matcher()->find_old_node(node); |
470 | if (old != NULL__null) { |
471 | print_prop("old_node_idx", old->_idx); |
472 | } |
473 | } |
474 | |
475 | if (node->is_Proj()) { |
476 | print_prop("con", (int)node->as_Proj()->_con); |
477 | } |
478 | |
479 | if (node->is_Mach()) { |
480 | print_prop("idealOpcode", (const char *)NodeClassNames[node->as_Mach()->ideal_Opcode()]); |
481 | } |
482 | |
483 | buffer[0] = 0; |
484 | stringStream s2(buffer, sizeof(buffer) - 1); |
485 | |
486 | node->dump_spec(&s2); |
487 | if (t != NULL__null && (t->isa_instptr() || t->isa_klassptr())) { |
488 | const TypeInstPtr *toop = t->isa_instptr(); |
489 | const TypeKlassPtr *tkls = t->isa_klassptr(); |
490 | ciKlass* klass = toop ? toop->klass() : (tkls ? tkls->klass() : NULL__null ); |
491 | if( klass && klass->is_loaded() && klass->is_interface() ) { |
492 | s2.print(" Interface:"); |
493 | } else if( toop ) { |
494 | s2.print(" Oop:"); |
495 | } else if( tkls ) { |
496 | s2.print(" Klass:"); |
497 | } |
498 | t->dump_on(&s2); |
499 | } else if( t == Type::MEMORY ) { |
500 | s2.print(" Memory:"); |
501 | MemNode::dump_adr_type(node, node->adr_type(), &s2); |
502 | } |
503 | |
504 | assert(s2.size() < sizeof(buffer), "size in range")do { if (!(s2.size() < sizeof(buffer))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 504, "assert(" "s2.size() < sizeof(buffer)" ") failed", "size in range" ); ::breakpoint(); } } while (0); |
505 | print_prop("dump_spec", buffer); |
506 | |
507 | if (node->is_block_proj()) { |
508 | print_prop("is_block_proj", "true"); |
509 | } |
510 | |
511 | if (node->is_block_start()) { |
512 | print_prop("is_block_start", "true"); |
513 | } |
514 | |
515 | const char *short_name = "short_name"; |
516 | if (strcmp(node->Name(), "Parm") == 0 && node->as_Proj()->_con >= TypeFunc::Parms) { |
517 | int index = node->as_Proj()->_con - TypeFunc::Parms; |
518 | if (index >= 10) { |
519 | print_prop(short_name, "PA"); |
520 | } else { |
521 | sprintf(buffer, "P%d", index); |
522 | print_prop(short_name, buffer); |
523 | } |
524 | } else if (strcmp(node->Name(), "IfTrue") == 0) { |
525 | print_prop(short_name, "T"); |
526 | } else if (strcmp(node->Name(), "IfFalse") == 0) { |
527 | print_prop(short_name, "F"); |
528 | } else if ((node->is_Con() && node->is_Type()) || node->is_Proj()) { |
529 | |
530 | if (t->base() == Type::Int && t->is_int()->is_con()) { |
531 | const TypeInt *typeInt = t->is_int(); |
532 | assert(typeInt->is_con(), "must be constant")do { if (!(typeInt->is_con())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 532, "assert(" "typeInt->is_con()" ") failed", "must be constant" ); ::breakpoint(); } } while (0); |
533 | jint value = typeInt->get_con(); |
534 | |
535 | // max. 2 chars allowed |
536 | if (value >= -9 && value <= 99) { |
537 | sprintf(buffer, "%d", value); |
538 | print_prop(short_name, buffer); |
539 | } else { |
540 | print_prop(short_name, "I"); |
541 | } |
542 | } else if (t == Type::TOP) { |
543 | print_prop(short_name, "^"); |
544 | } else if (t->base() == Type::Long && t->is_long()->is_con()) { |
545 | const TypeLong *typeLong = t->is_long(); |
546 | assert(typeLong->is_con(), "must be constant")do { if (!(typeLong->is_con())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 546, "assert(" "typeLong->is_con()" ") failed", "must be constant" ); ::breakpoint(); } } while (0); |
547 | jlong value = typeLong->get_con(); |
548 | |
549 | // max. 2 chars allowed |
550 | if (value >= -9 && value <= 99) { |
551 | sprintf(buffer, JLONG_FORMAT"%" "l" "d", value); |
552 | print_prop(short_name, buffer); |
553 | } else { |
554 | print_prop(short_name, "L"); |
555 | } |
556 | } else if (t->base() == Type::KlassPtr || t->base() == Type::InstKlassPtr || t->base() == Type::AryKlassPtr) { |
557 | const TypeKlassPtr *typeKlass = t->is_klassptr(); |
Value stored to 'typeKlass' during its initialization is never read | |
558 | print_prop(short_name, "CP"); |
559 | } else if (t->base() == Type::Control) { |
560 | print_prop(short_name, "C"); |
561 | } else if (t->base() == Type::Memory) { |
562 | print_prop(short_name, "M"); |
563 | } else if (t->base() == Type::Abio) { |
564 | print_prop(short_name, "IO"); |
565 | } else if (t->base() == Type::Return_Address) { |
566 | print_prop(short_name, "RA"); |
567 | } else if (t->base() == Type::AnyPtr) { |
568 | print_prop(short_name, "P"); |
569 | } else if (t->base() == Type::RawPtr) { |
570 | print_prop(short_name, "RP"); |
571 | } else if (t->base() == Type::AryPtr) { |
572 | print_prop(short_name, "AP"); |
573 | } |
574 | } |
575 | |
576 | JVMState* caller = NULL__null; |
577 | if (node->is_SafePoint()) { |
578 | caller = node->as_SafePoint()->jvms(); |
579 | } else { |
580 | Node_Notes* notes = C->node_notes_at(node->_idx); |
581 | if (notes != NULL__null) { |
582 | caller = notes->jvms(); |
583 | } |
584 | } |
585 | |
586 | if (caller != NULL__null) { |
587 | stringStream bciStream; |
588 | ciMethod* last = NULL__null; |
589 | int last_bci; |
590 | while(caller) { |
591 | if (caller->has_method()) { |
592 | last = caller->method(); |
593 | last_bci = caller->bci(); |
594 | } |
595 | bciStream.print("%d ", caller->bci()); |
596 | caller = caller->caller(); |
597 | } |
598 | print_prop("bci", bciStream.as_string()); |
599 | if (last != NULL__null && last->has_linenumber_table() && last_bci >= 0) { |
600 | print_prop("line", last->line_number_from_bci(last_bci)); |
601 | } |
602 | } |
603 | |
604 | #ifdef ASSERT1 |
605 | if (node->debug_orig() != NULL__null) { |
606 | stringStream dorigStream; |
607 | node->dump_orig(&dorigStream, false); |
608 | print_prop("debug_orig", dorigStream.as_string()); |
609 | } |
610 | #endif |
611 | |
612 | if (_chaitin && _chaitin != (PhaseChaitin *)((intptr_t)0xdeadbeef)) { |
613 | buffer[0] = 0; |
614 | _chaitin->dump_register(node, buffer); |
615 | print_prop("reg", buffer); |
616 | uint lrg_id = 0; |
617 | if (node->_idx < _chaitin->_lrg_map.size()) { |
618 | lrg_id = _chaitin->_lrg_map.live_range_id(node); |
619 | } |
620 | print_prop("lrg", lrg_id); |
621 | } |
622 | |
623 | Compile::current()->_in_dump_cnt--; |
624 | #endif |
625 | |
626 | tail(PROPERTIES_ELEMENT); |
627 | tail(NODE_ELEMENT); |
628 | } |
629 | } |
630 | |
631 | void IdealGraphPrinter::walk_nodes(Node *start, bool edges, VectorSet* temp_set) { |
632 | |
633 | |
634 | VectorSet visited; |
635 | GrowableArray<Node *> nodeStack(Thread::current()->resource_area(), 0, 0, NULL__null); |
636 | nodeStack.push(start); |
637 | visited.test_set(start->_idx); |
638 | if (C->cfg() != NULL__null) { |
639 | // once we have a CFG there are some nodes that aren't really |
640 | // reachable but are in the CFG so add them here. |
641 | for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) { |
642 | Block* block = C->cfg()->get_block(i); |
643 | for (uint s = 0; s < block->number_of_nodes(); s++) { |
644 | nodeStack.push(block->get_node(s)); |
645 | } |
646 | } |
647 | } |
648 | |
649 | while(nodeStack.length() > 0) { |
650 | |
651 | Node *n = nodeStack.pop(); |
652 | visit_node(n, edges, temp_set); |
653 | |
654 | if (_traverse_outs) { |
655 | for (DUIterator i = n->outs(); n->has_out(i); i++) { |
656 | Node* p = n->out(i); |
657 | if (!visited.test_set(p->_idx)) { |
658 | nodeStack.push(p); |
659 | } |
660 | } |
661 | } |
662 | |
663 | for ( uint i = 0; i < n->len(); i++ ) { |
664 | if ( n->in(i) ) { |
665 | if (!visited.test_set(n->in(i)->_idx)) { |
666 | nodeStack.push(n->in(i)); |
667 | } |
668 | } |
669 | } |
670 | } |
671 | } |
672 | |
673 | void IdealGraphPrinter::print_method(const char *name, int level) { |
674 | if (C->should_print(level)) { |
675 | print(name, (Node *) C->root()); |
676 | } |
677 | } |
678 | |
679 | // Print current ideal graph |
680 | void IdealGraphPrinter::print(const char *name, Node *node) { |
681 | |
682 | if (!_current_method || !_should_send_method || node == NULL__null) return; |
683 | |
684 | // Warning, unsafe cast? |
685 | _chaitin = (PhaseChaitin *)C->regalloc(); |
686 | |
687 | begin_head(GRAPH_ELEMENT); |
688 | print_attr(GRAPH_NAME_PROPERTY, (const char *)name); |
689 | end_head(); |
690 | |
691 | VectorSet temp_set; |
692 | |
693 | head(NODES_ELEMENT); |
694 | if (C->cfg() != NULL__null) { |
695 | // Compute the maximum estimated frequency in the current graph. |
696 | _max_freq = 1.0e-6; |
697 | for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) { |
698 | Block* block = C->cfg()->get_block(i); |
699 | if (block->_freq > _max_freq) { |
700 | _max_freq = block->_freq; |
701 | } |
702 | } |
703 | } |
704 | walk_nodes(node, false, &temp_set); |
705 | tail(NODES_ELEMENT); |
706 | |
707 | head(EDGES_ELEMENT); |
708 | walk_nodes(node, true, &temp_set); |
709 | tail(EDGES_ELEMENT); |
710 | if (C->cfg() != NULL__null) { |
711 | head(CONTROL_FLOW_ELEMENT); |
712 | for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) { |
713 | Block* block = C->cfg()->get_block(i); |
714 | begin_head(BLOCK_ELEMENT); |
715 | print_attr(BLOCK_NAME_PROPERTY, block->_pre_order); |
716 | end_head(); |
717 | |
718 | head(SUCCESSORS_ELEMENT); |
719 | for (uint s = 0; s < block->_num_succs; s++) { |
720 | begin_elem(SUCCESSOR_ELEMENT); |
721 | print_attr(BLOCK_NAME_PROPERTY, block->_succs[s]->_pre_order); |
722 | end_elem(); |
723 | } |
724 | tail(SUCCESSORS_ELEMENT); |
725 | |
726 | head(NODES_ELEMENT); |
727 | for (uint s = 0; s < block->number_of_nodes(); s++) { |
728 | begin_elem(NODE_ELEMENT); |
729 | print_attr(NODE_ID_PROPERTY, block->get_node(s)->_igv_idx); |
730 | end_elem(); |
731 | } |
732 | tail(NODES_ELEMENT); |
733 | |
734 | tail(BLOCK_ELEMENT); |
735 | } |
736 | tail(CONTROL_FLOW_ELEMENT); |
737 | } |
738 | tail(GRAPH_ELEMENT); |
739 | _xml->flush(); |
740 | } |
741 | |
742 | void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files, bool append) { |
743 | ThreadCritical tc; |
744 | if (use_multiple_files && _file_count != 0) { |
745 | assert(!append, "append should only be used for debugging with a single file")do { if (!(!append)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 745, "assert(" "!append" ") failed", "append should only be used for debugging with a single file" ); ::breakpoint(); } } while (0); |
746 | ResourceMark rm; |
747 | stringStream st; |
748 | const char* dot = strrchr(file_name, '.'); |
749 | if (dot) { |
750 | st.write(file_name, dot - file_name); |
751 | st.print("%d%s", _file_count, dot); |
752 | } else { |
753 | st.print("%s%d", file_name, _file_count); |
754 | } |
755 | _output = new (ResourceObj::C_HEAP, mtCompiler) fileStream(st.as_string(), "w"); |
756 | } else { |
757 | _output = new (ResourceObj::C_HEAP, mtCompiler) fileStream(file_name, append ? "a" : "w"); |
758 | } |
759 | if (use_multiple_files) { |
760 | assert(!append, "append should only be used for debugging with a single file")do { if (!(!append)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 760, "assert(" "!append" ") failed", "append should only be used for debugging with a single file" ); ::breakpoint(); } } while (0); |
761 | _file_count++; |
762 | } |
763 | } |
764 | |
765 | void IdealGraphPrinter::init_network_stream() { |
766 | _network_stream = new (ResourceObj::C_HEAP, mtCompiler) networkStream(); |
767 | // Try to connect to visualizer |
768 | if (_network_stream->connect(PrintIdealGraphAddress, PrintIdealGraphPort)) { |
769 | char c = 0; |
770 | _network_stream->read(&c, 1); |
771 | if (c != 'y') { |
772 | tty->print_cr("Client available, but does not want to receive data!"); |
773 | _network_stream->close(); |
774 | delete _network_stream; |
775 | _network_stream = NULL__null; |
776 | return; |
777 | } |
778 | _output = _network_stream; |
779 | } else { |
780 | // It would be nice if we could shut down cleanly but it should |
781 | // be an error if we can't connect to the visualizer. |
782 | fatal("Couldn't connect to visualizer at %s:" INTX_FORMAT,do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 783, "Couldn't connect to visualizer at %s:" "%" "l" "d", PrintIdealGraphAddress , PrintIdealGraphPort); ::breakpoint(); } while (0) |
783 | PrintIdealGraphAddress, PrintIdealGraphPort)do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 783, "Couldn't connect to visualizer at %s:" "%" "l" "d", PrintIdealGraphAddress , PrintIdealGraphPort); ::breakpoint(); } while (0); |
784 | } |
785 | } |
786 | |
787 | void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) { |
788 | assert(C != NULL, "must already be set")do { if (!(C != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/idealGraphPrinter.cpp" , 788, "assert(" "C != __null" ") failed", "must already be set" ); ::breakpoint(); } } while (0); |
789 | if (current_method != _current_method) { |
790 | // If a different method, end the old and begin with the new one. |
791 | end_method(); |
792 | _current_method = NULL__null; |
793 | begin_method(); |
794 | } |
795 | } |
796 | |
797 | extern const char *NodeClassNames[]; |
798 | |
799 | #endif |