src/share/vm/opto/idealGraphPrinter.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 6876
710a3c8b516e
child 9448
73d689add964
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "opto/chaitin.hpp"
aoqi@0 27 #include "opto/idealGraphPrinter.hpp"
aoqi@0 28 #include "opto/machnode.hpp"
aoqi@0 29 #include "opto/parse.hpp"
aoqi@0 30 #include "runtime/threadCritical.hpp"
aoqi@0 31
aoqi@0 32 #ifndef PRODUCT
aoqi@0 33
aoqi@0 34 // Constants
aoqi@0 35 // Keep consistent with Java constants
aoqi@0 36 const char *IdealGraphPrinter::INDENT = " ";
aoqi@0 37 const char *IdealGraphPrinter::TOP_ELEMENT = "graphDocument";
aoqi@0 38 const char *IdealGraphPrinter::GROUP_ELEMENT = "group";
aoqi@0 39 const char *IdealGraphPrinter::GRAPH_ELEMENT = "graph";
aoqi@0 40 const char *IdealGraphPrinter::PROPERTIES_ELEMENT = "properties";
aoqi@0 41 const char *IdealGraphPrinter::EDGES_ELEMENT = "edges";
aoqi@0 42 const char *IdealGraphPrinter::PROPERTY_ELEMENT = "p";
aoqi@0 43 const char *IdealGraphPrinter::EDGE_ELEMENT = "edge";
aoqi@0 44 const char *IdealGraphPrinter::NODE_ELEMENT = "node";
aoqi@0 45 const char *IdealGraphPrinter::NODES_ELEMENT = "nodes";
aoqi@0 46 const char *IdealGraphPrinter::REMOVE_EDGE_ELEMENT = "removeEdge";
aoqi@0 47 const char *IdealGraphPrinter::REMOVE_NODE_ELEMENT = "removeNode";
aoqi@0 48 const char *IdealGraphPrinter::METHOD_NAME_PROPERTY = "name";
aoqi@0 49 const char *IdealGraphPrinter::METHOD_IS_PUBLIC_PROPERTY = "public";
aoqi@0 50 const char *IdealGraphPrinter::METHOD_IS_STATIC_PROPERTY = "static";
aoqi@0 51 const char *IdealGraphPrinter::TRUE_VALUE = "true";
aoqi@0 52 const char *IdealGraphPrinter::NODE_NAME_PROPERTY = "name";
aoqi@0 53 const char *IdealGraphPrinter::EDGE_NAME_PROPERTY = "name";
aoqi@0 54 const char *IdealGraphPrinter::NODE_ID_PROPERTY = "id";
aoqi@0 55 const char *IdealGraphPrinter::FROM_PROPERTY = "from";
aoqi@0 56 const char *IdealGraphPrinter::TO_PROPERTY = "to";
aoqi@0 57 const char *IdealGraphPrinter::PROPERTY_NAME_PROPERTY = "name";
aoqi@0 58 const char *IdealGraphPrinter::GRAPH_NAME_PROPERTY = "name";
aoqi@0 59 const char *IdealGraphPrinter::INDEX_PROPERTY = "index";
aoqi@0 60 const char *IdealGraphPrinter::METHOD_ELEMENT = "method";
aoqi@0 61 const char *IdealGraphPrinter::INLINE_ELEMENT = "inline";
aoqi@0 62 const char *IdealGraphPrinter::BYTECODES_ELEMENT = "bytecodes";
aoqi@0 63 const char *IdealGraphPrinter::METHOD_BCI_PROPERTY = "bci";
aoqi@0 64 const char *IdealGraphPrinter::METHOD_SHORT_NAME_PROPERTY = "shortName";
aoqi@0 65 const char *IdealGraphPrinter::CONTROL_FLOW_ELEMENT = "controlFlow";
aoqi@0 66 const char *IdealGraphPrinter::BLOCK_NAME_PROPERTY = "name";
aoqi@0 67 const char *IdealGraphPrinter::BLOCK_DOMINATOR_PROPERTY = "dom";
aoqi@0 68 const char *IdealGraphPrinter::BLOCK_ELEMENT = "block";
aoqi@0 69 const char *IdealGraphPrinter::SUCCESSORS_ELEMENT = "successors";
aoqi@0 70 const char *IdealGraphPrinter::SUCCESSOR_ELEMENT = "successor";
aoqi@0 71 const char *IdealGraphPrinter::ASSEMBLY_ELEMENT = "assembly";
aoqi@0 72
aoqi@0 73 int IdealGraphPrinter::_file_count = 0;
aoqi@0 74
aoqi@0 75 IdealGraphPrinter *IdealGraphPrinter::printer() {
aoqi@0 76 if (PrintIdealGraphLevel == 0) return NULL;
aoqi@0 77
aoqi@0 78 JavaThread *thread = JavaThread::current();
aoqi@0 79 if (!thread->is_Compiler_thread()) return NULL;
aoqi@0 80
aoqi@0 81 CompilerThread *compiler_thread = (CompilerThread *)thread;
aoqi@0 82 if (compiler_thread->ideal_graph_printer() == NULL) {
aoqi@0 83 IdealGraphPrinter *printer = new IdealGraphPrinter();
aoqi@0 84 compiler_thread->set_ideal_graph_printer(printer);
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 return compiler_thread->ideal_graph_printer();
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 void IdealGraphPrinter::clean_up() {
aoqi@0 91 JavaThread *p;
aoqi@0 92 for (p = Threads::first(); p; p = p->next()) {
aoqi@0 93 if (p->is_Compiler_thread()) {
aoqi@0 94 CompilerThread *c = (CompilerThread *)p;
aoqi@0 95 IdealGraphPrinter *printer = c->ideal_graph_printer();
aoqi@0 96 if (printer) {
aoqi@0 97 delete printer;
aoqi@0 98 }
aoqi@0 99 c->set_ideal_graph_printer(NULL);
aoqi@0 100 }
aoqi@0 101 }
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 // Constructor, either file or network output
aoqi@0 105 IdealGraphPrinter::IdealGraphPrinter() {
aoqi@0 106
aoqi@0 107 // By default dump both ins and outs since dead or unreachable code
aoqi@0 108 // needs to appear in the graph. There are also some special cases
aoqi@0 109 // in the mach where kill projections have no users but should
aoqi@0 110 // appear in the dump.
aoqi@0 111 _traverse_outs = true;
aoqi@0 112 _should_send_method = true;
aoqi@0 113 _output = NULL;
aoqi@0 114 buffer[0] = 0;
aoqi@0 115 _depth = 0;
aoqi@0 116 _current_method = NULL;
aoqi@0 117 assert(!_current_method, "current method must be initialized to NULL");
aoqi@0 118 _stream = NULL;
aoqi@0 119
aoqi@0 120 if (PrintIdealGraphFile != NULL) {
aoqi@0 121 ThreadCritical tc;
aoqi@0 122 // User wants all output to go to files
aoqi@0 123 if (_file_count != 0) {
aoqi@0 124 ResourceMark rm;
aoqi@0 125 stringStream st;
aoqi@0 126 const char* dot = strrchr(PrintIdealGraphFile, '.');
aoqi@0 127 if (dot) {
aoqi@0 128 st.write(PrintIdealGraphFile, dot - PrintIdealGraphFile);
aoqi@0 129 st.print("%d%s", _file_count, dot);
aoqi@0 130 } else {
aoqi@0 131 st.print("%s%d", PrintIdealGraphFile, _file_count);
aoqi@0 132 }
aoqi@0 133 fileStream *stream = new (ResourceObj::C_HEAP, mtCompiler) fileStream(st.as_string());
aoqi@0 134 _output = stream;
aoqi@0 135 } else {
aoqi@0 136 fileStream *stream = new (ResourceObj::C_HEAP, mtCompiler) fileStream(PrintIdealGraphFile);
aoqi@0 137 _output = stream;
aoqi@0 138 }
aoqi@0 139 _file_count++;
aoqi@0 140 } else {
aoqi@0 141 _stream = new (ResourceObj::C_HEAP, mtCompiler) networkStream();
aoqi@0 142
aoqi@0 143 // Try to connect to visualizer
aoqi@0 144 if (_stream->connect(PrintIdealGraphAddress, PrintIdealGraphPort)) {
aoqi@0 145 char c = 0;
aoqi@0 146 _stream->read(&c, 1);
aoqi@0 147 if (c != 'y') {
aoqi@0 148 tty->print_cr("Client available, but does not want to receive data!");
aoqi@0 149 _stream->close();
aoqi@0 150 delete _stream;
aoqi@0 151 _stream = NULL;
aoqi@0 152 return;
aoqi@0 153 }
aoqi@0 154 _output = _stream;
aoqi@0 155 } else {
aoqi@0 156 // It would be nice if we could shut down cleanly but it should
aoqi@0 157 // be an error if we can't connect to the visualizer.
aoqi@0 158 fatal(err_msg_res("Couldn't connect to visualizer at %s:" INTX_FORMAT,
aoqi@0 159 PrintIdealGraphAddress, PrintIdealGraphPort));
aoqi@0 160 }
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 _xml = new (ResourceObj::C_HEAP, mtCompiler) xmlStream(_output);
aoqi@0 164
aoqi@0 165 head(TOP_ELEMENT);
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 // Destructor, close file or network stream
aoqi@0 169 IdealGraphPrinter::~IdealGraphPrinter() {
aoqi@0 170
aoqi@0 171 tail(TOP_ELEMENT);
aoqi@0 172
aoqi@0 173 // tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds());
aoqi@0 174 // tty->print_cr("Output time: %d", (int)_output_time.milliseconds());
aoqi@0 175 // tty->print_cr("Build blocks time: %d", (int)_build_blocks_time.milliseconds());
aoqi@0 176
aoqi@0 177 if(_xml) {
aoqi@0 178 delete _xml;
aoqi@0 179 _xml = NULL;
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 if (_stream) {
aoqi@0 183 delete _stream;
aoqi@0 184 if (_stream == _output) {
aoqi@0 185 _output = NULL;
aoqi@0 186 }
aoqi@0 187 _stream = NULL;
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 if (_output) {
aoqi@0 191 delete _output;
aoqi@0 192 _output = NULL;
aoqi@0 193 }
aoqi@0 194 }
aoqi@0 195
aoqi@0 196
aoqi@0 197 void IdealGraphPrinter::begin_elem(const char *s) {
aoqi@0 198 _xml->begin_elem("%s", s);
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 void IdealGraphPrinter::end_elem() {
aoqi@0 202 _xml->end_elem();
aoqi@0 203 }
aoqi@0 204
aoqi@0 205 void IdealGraphPrinter::begin_head(const char *s) {
aoqi@0 206 _xml->begin_head("%s", s);
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 void IdealGraphPrinter::end_head() {
aoqi@0 210 _xml->end_head();
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 void IdealGraphPrinter::print_attr(const char *name, intptr_t val) {
aoqi@0 214 stringStream stream;
aoqi@0 215 stream.print(INTX_FORMAT, val);
aoqi@0 216 print_attr(name, stream.as_string());
aoqi@0 217 }
aoqi@0 218
aoqi@0 219 void IdealGraphPrinter::print_attr(const char *name, const char *val) {
aoqi@0 220 _xml->print(" %s='", name);
aoqi@0 221 text(val);
aoqi@0 222 _xml->print("'");
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 void IdealGraphPrinter::head(const char *name) {
aoqi@0 226 _xml->head("%s", name);
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 void IdealGraphPrinter::tail(const char *name) {
aoqi@0 230 _xml->tail(name);
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 void IdealGraphPrinter::text(const char *s) {
aoqi@0 234 _xml->text("%s", s);
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 void IdealGraphPrinter::print_prop(const char *name, int val) {
aoqi@0 238
aoqi@0 239 stringStream stream;
aoqi@0 240 stream.print("%d", val);
aoqi@0 241 print_prop(name, stream.as_string());
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 void IdealGraphPrinter::print_prop(const char *name, const char *val) {
aoqi@0 245 begin_head(PROPERTY_ELEMENT);
aoqi@0 246 print_attr(PROPERTY_NAME_PROPERTY, name);
aoqi@0 247 end_head();
aoqi@0 248 text(val);
aoqi@0 249 tail(PROPERTY_ELEMENT);
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 void IdealGraphPrinter::print_method(ciMethod *method, int bci, InlineTree *tree) {
aoqi@0 253 begin_head(METHOD_ELEMENT);
aoqi@0 254
aoqi@0 255 stringStream str;
aoqi@0 256 method->print_name(&str);
aoqi@0 257
aoqi@0 258 stringStream shortStr;
aoqi@0 259 method->print_short_name(&shortStr);
aoqi@0 260
aoqi@0 261 print_attr(METHOD_NAME_PROPERTY, str.as_string());
aoqi@0 262 print_attr(METHOD_SHORT_NAME_PROPERTY, shortStr.as_string());
aoqi@0 263 print_attr(METHOD_BCI_PROPERTY, bci);
aoqi@0 264
aoqi@0 265 end_head();
aoqi@0 266
aoqi@0 267 head(BYTECODES_ELEMENT);
aoqi@0 268 output()->print_cr("<![CDATA[");
aoqi@0 269 method->print_codes_on(output());
aoqi@0 270 output()->print_cr("]]>");
aoqi@0 271 tail(BYTECODES_ELEMENT);
aoqi@0 272
aoqi@0 273 head(INLINE_ELEMENT);
aoqi@0 274 if (tree != NULL) {
aoqi@0 275 GrowableArray<InlineTree *> subtrees = tree->subtrees();
aoqi@0 276 for (int i = 0; i < subtrees.length(); i++) {
aoqi@0 277 print_inline_tree(subtrees.at(i));
aoqi@0 278 }
aoqi@0 279 }
aoqi@0 280 tail(INLINE_ELEMENT);
aoqi@0 281
aoqi@0 282 tail(METHOD_ELEMENT);
aoqi@0 283 output()->flush();
aoqi@0 284 }
aoqi@0 285
aoqi@0 286 void IdealGraphPrinter::print_inline_tree(InlineTree *tree) {
aoqi@0 287
aoqi@0 288 if (tree == NULL) return;
aoqi@0 289
aoqi@0 290 ciMethod *method = tree->method();
aoqi@0 291 print_method(tree->method(), tree->caller_bci(), tree);
aoqi@0 292
aoqi@0 293 }
aoqi@0 294
aoqi@0 295 void IdealGraphPrinter::print_inlining(Compile* compile) {
aoqi@0 296
aoqi@0 297 // Print inline tree
aoqi@0 298 if (_should_send_method) {
aoqi@0 299 InlineTree *inlineTree = compile->ilt();
aoqi@0 300 if (inlineTree != NULL) {
aoqi@0 301 print_inline_tree(inlineTree);
aoqi@0 302 } else {
aoqi@0 303 // print this method only
aoqi@0 304 }
aoqi@0 305 }
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 // Has to be called whenever a method is compiled
aoqi@0 309 void IdealGraphPrinter::begin_method(Compile* compile) {
aoqi@0 310
aoqi@0 311 ciMethod *method = compile->method();
aoqi@0 312 assert(_output, "output stream must exist!");
aoqi@0 313 assert(method, "null methods are not allowed!");
aoqi@0 314 assert(!_current_method, "current method must be null!");
aoqi@0 315
aoqi@0 316 head(GROUP_ELEMENT);
aoqi@0 317
aoqi@0 318 head(PROPERTIES_ELEMENT);
aoqi@0 319
aoqi@0 320 // Print properties
aoqi@0 321 // Add method name
aoqi@0 322 stringStream strStream;
aoqi@0 323 method->print_name(&strStream);
aoqi@0 324 print_prop(METHOD_NAME_PROPERTY, strStream.as_string());
aoqi@0 325
aoqi@0 326 if (method->flags().is_public()) {
aoqi@0 327 print_prop(METHOD_IS_PUBLIC_PROPERTY, TRUE_VALUE);
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 if (method->flags().is_static()) {
aoqi@0 331 print_prop(METHOD_IS_STATIC_PROPERTY, TRUE_VALUE);
aoqi@0 332 }
aoqi@0 333
aoqi@0 334 tail(PROPERTIES_ELEMENT);
aoqi@0 335
aoqi@0 336 if (_stream) {
aoqi@0 337 char answer = 0;
aoqi@0 338 _xml->flush();
aoqi@0 339 int result = _stream->read(&answer, 1);
aoqi@0 340 _should_send_method = (answer == 'y');
aoqi@0 341 }
aoqi@0 342
aoqi@0 343 this->_current_method = method;
aoqi@0 344
aoqi@0 345 _xml->flush();
aoqi@0 346 }
aoqi@0 347
aoqi@0 348 // Has to be called whenever a method has finished compilation
aoqi@0 349 void IdealGraphPrinter::end_method() {
aoqi@0 350
aoqi@0 351 nmethod* method = (nmethod*)this->_current_method->code();
aoqi@0 352
aoqi@0 353 tail(GROUP_ELEMENT);
aoqi@0 354 _current_method = NULL;
aoqi@0 355 _xml->flush();
aoqi@0 356 }
aoqi@0 357
aoqi@0 358 // Print indent
aoqi@0 359 void IdealGraphPrinter::print_indent() {
aoqi@0 360 tty->print_cr("printing ident %d", _depth);
aoqi@0 361 for (int i = 0; i < _depth; i++) {
aoqi@0 362 _xml->print("%s", INDENT);
aoqi@0 363 }
aoqi@0 364 }
aoqi@0 365
aoqi@0 366 bool IdealGraphPrinter::traverse_outs() {
aoqi@0 367 return _traverse_outs;
aoqi@0 368 }
aoqi@0 369
aoqi@0 370 void IdealGraphPrinter::set_traverse_outs(bool b) {
aoqi@0 371 _traverse_outs = b;
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 intptr_t IdealGraphPrinter::get_node_id(Node *n) {
aoqi@0 375 return (intptr_t)(n);
aoqi@0 376 }
aoqi@0 377
aoqi@0 378 void IdealGraphPrinter::visit_node(Node *n, bool edges, VectorSet* temp_set) {
aoqi@0 379
aoqi@0 380 if (edges) {
aoqi@0 381
aoqi@0 382 // Output edge
aoqi@0 383 intptr_t dest_id = get_node_id(n);
aoqi@0 384 for ( uint i = 0; i < n->len(); i++ ) {
aoqi@0 385 if ( n->in(i) ) {
aoqi@0 386 Node *source = n->in(i);
aoqi@0 387 begin_elem(EDGE_ELEMENT);
aoqi@0 388 intptr_t source_id = get_node_id(source);
aoqi@0 389 print_attr(FROM_PROPERTY, source_id);
aoqi@0 390 print_attr(TO_PROPERTY, dest_id);
aoqi@0 391 print_attr(INDEX_PROPERTY, i);
aoqi@0 392 end_elem();
aoqi@0 393 }
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 } else {
aoqi@0 397
aoqi@0 398 // Output node
aoqi@0 399 begin_head(NODE_ELEMENT);
aoqi@0 400 print_attr(NODE_ID_PROPERTY, get_node_id(n));
aoqi@0 401 end_head();
aoqi@0 402
aoqi@0 403 head(PROPERTIES_ELEMENT);
aoqi@0 404
aoqi@0 405 Node *node = n;
aoqi@0 406 #ifndef PRODUCT
aoqi@0 407 Compile::current()->_in_dump_cnt++;
aoqi@0 408 print_prop(NODE_NAME_PROPERTY, (const char *)node->Name());
aoqi@0 409 const Type *t = node->bottom_type();
aoqi@0 410 print_prop("type", t->msg());
aoqi@0 411 print_prop("idx", node->_idx);
aoqi@0 412 #ifdef ASSERT
aoqi@0 413 print_prop("debug_idx", node->_debug_idx);
aoqi@0 414 #endif
aoqi@0 415
aoqi@0 416 if (C->cfg() != NULL) {
aoqi@0 417 Block* block = C->cfg()->get_block_for_node(node);
aoqi@0 418 if (block == NULL) {
aoqi@0 419 print_prop("block", C->cfg()->get_block(0)->_pre_order);
aoqi@0 420 } else {
aoqi@0 421 print_prop("block", block->_pre_order);
aoqi@0 422 }
aoqi@0 423 }
aoqi@0 424
aoqi@0 425 const jushort flags = node->flags();
aoqi@0 426 if (flags & Node::Flag_is_Copy) {
aoqi@0 427 print_prop("is_copy", "true");
aoqi@0 428 }
aoqi@0 429 if (flags & Node::Flag_rematerialize) {
aoqi@0 430 print_prop("rematerialize", "true");
aoqi@0 431 }
aoqi@0 432 if (flags & Node::Flag_needs_anti_dependence_check) {
aoqi@0 433 print_prop("needs_anti_dependence_check", "true");
aoqi@0 434 }
aoqi@0 435 if (flags & Node::Flag_is_macro) {
aoqi@0 436 print_prop("is_macro", "true");
aoqi@0 437 }
aoqi@0 438 if (flags & Node::Flag_is_Con) {
aoqi@0 439 print_prop("is_con", "true");
aoqi@0 440 }
aoqi@0 441 if (flags & Node::Flag_is_cisc_alternate) {
aoqi@0 442 print_prop("is_cisc_alternate", "true");
aoqi@0 443 }
aoqi@0 444 if (flags & Node::Flag_is_dead_loop_safe) {
aoqi@0 445 print_prop("is_dead_loop_safe", "true");
aoqi@0 446 }
aoqi@0 447 if (flags & Node::Flag_may_be_short_branch) {
aoqi@0 448 print_prop("may_be_short_branch", "true");
aoqi@0 449 }
aoqi@0 450 if (flags & Node::Flag_has_call) {
aoqi@0 451 print_prop("has_call", "true");
aoqi@0 452 }
aoqi@0 453
aoqi@0 454 if (C->matcher() != NULL) {
aoqi@0 455 if (C->matcher()->is_shared(node)) {
aoqi@0 456 print_prop("is_shared", "true");
aoqi@0 457 } else {
aoqi@0 458 print_prop("is_shared", "false");
aoqi@0 459 }
aoqi@0 460 if (C->matcher()->is_dontcare(node)) {
aoqi@0 461 print_prop("is_dontcare", "true");
aoqi@0 462 } else {
aoqi@0 463 print_prop("is_dontcare", "false");
aoqi@0 464 }
aoqi@0 465
aoqi@0 466 #ifdef ASSERT
aoqi@0 467 Node* old = C->matcher()->find_old_node(node);
aoqi@0 468 if (old != NULL) {
aoqi@0 469 print_prop("old_node_idx", old->_idx);
aoqi@0 470 }
aoqi@0 471 #endif
aoqi@0 472 }
aoqi@0 473
aoqi@0 474 if (node->is_Proj()) {
aoqi@0 475 print_prop("con", (int)node->as_Proj()->_con);
aoqi@0 476 }
aoqi@0 477
aoqi@0 478 if (node->is_Mach()) {
aoqi@0 479 print_prop("idealOpcode", (const char *)NodeClassNames[node->as_Mach()->ideal_Opcode()]);
aoqi@0 480 }
aoqi@0 481
aoqi@0 482 buffer[0] = 0;
aoqi@0 483 stringStream s2(buffer, sizeof(buffer) - 1);
aoqi@0 484
aoqi@0 485 node->dump_spec(&s2);
aoqi@0 486 if (t != NULL && (t->isa_instptr() || t->isa_klassptr())) {
aoqi@0 487 const TypeInstPtr *toop = t->isa_instptr();
aoqi@0 488 const TypeKlassPtr *tkls = t->isa_klassptr();
aoqi@0 489 ciKlass* klass = toop ? toop->klass() : (tkls ? tkls->klass() : NULL );
aoqi@0 490 if( klass && klass->is_loaded() && klass->is_interface() ) {
aoqi@0 491 s2.print(" Interface:");
aoqi@0 492 } else if( toop ) {
aoqi@0 493 s2.print(" Oop:");
aoqi@0 494 } else if( tkls ) {
aoqi@0 495 s2.print(" Klass:");
aoqi@0 496 }
aoqi@0 497 t->dump_on(&s2);
aoqi@0 498 } else if( t == Type::MEMORY ) {
aoqi@0 499 s2.print(" Memory:");
aoqi@0 500 MemNode::dump_adr_type(node, node->adr_type(), &s2);
aoqi@0 501 }
aoqi@0 502
aoqi@0 503 assert(s2.size() < sizeof(buffer), "size in range");
aoqi@0 504 print_prop("dump_spec", buffer);
aoqi@0 505
aoqi@0 506 if (node->is_block_proj()) {
aoqi@0 507 print_prop("is_block_proj", "true");
aoqi@0 508 }
aoqi@0 509
aoqi@0 510 if (node->is_block_start()) {
aoqi@0 511 print_prop("is_block_start", "true");
aoqi@0 512 }
aoqi@0 513
aoqi@0 514 const char *short_name = "short_name";
aoqi@0 515 if (strcmp(node->Name(), "Parm") == 0 && node->as_Proj()->_con >= TypeFunc::Parms) {
aoqi@0 516 int index = node->as_Proj()->_con - TypeFunc::Parms;
aoqi@0 517 if (index >= 10) {
aoqi@0 518 print_prop(short_name, "PA");
aoqi@0 519 } else {
aoqi@0 520 sprintf(buffer, "P%d", index);
aoqi@0 521 print_prop(short_name, buffer);
aoqi@0 522 }
aoqi@0 523 } else if (strcmp(node->Name(), "IfTrue") == 0) {
aoqi@0 524 print_prop(short_name, "T");
aoqi@0 525 } else if (strcmp(node->Name(), "IfFalse") == 0) {
aoqi@0 526 print_prop(short_name, "F");
aoqi@0 527 } else if ((node->is_Con() && node->is_Type()) || node->is_Proj()) {
aoqi@0 528
aoqi@0 529 if (t->base() == Type::Int && t->is_int()->is_con()) {
aoqi@0 530 const TypeInt *typeInt = t->is_int();
aoqi@0 531 assert(typeInt->is_con(), "must be constant");
aoqi@0 532 jint value = typeInt->get_con();
aoqi@0 533
aoqi@0 534 // max. 2 chars allowed
aoqi@0 535 if (value >= -9 && value <= 99) {
aoqi@0 536 sprintf(buffer, "%d", value);
aoqi@0 537 print_prop(short_name, buffer);
aoqi@0 538 } else {
aoqi@0 539 print_prop(short_name, "I");
aoqi@0 540 }
aoqi@0 541 } else if (t == Type::TOP) {
aoqi@0 542 print_prop(short_name, "^");
aoqi@0 543 } else if (t->base() == Type::Long && t->is_long()->is_con()) {
aoqi@0 544 const TypeLong *typeLong = t->is_long();
aoqi@0 545 assert(typeLong->is_con(), "must be constant");
aoqi@0 546 jlong value = typeLong->get_con();
aoqi@0 547
aoqi@0 548 // max. 2 chars allowed
aoqi@0 549 if (value >= -9 && value <= 99) {
aoqi@0 550 sprintf(buffer, JLONG_FORMAT, value);
aoqi@0 551 print_prop(short_name, buffer);
aoqi@0 552 } else {
aoqi@0 553 print_prop(short_name, "L");
aoqi@0 554 }
aoqi@0 555 } else if (t->base() == Type::KlassPtr) {
aoqi@0 556 const TypeKlassPtr *typeKlass = t->is_klassptr();
aoqi@0 557 print_prop(short_name, "CP");
aoqi@0 558 } else if (t->base() == Type::Control) {
aoqi@0 559 print_prop(short_name, "C");
aoqi@0 560 } else if (t->base() == Type::Memory) {
aoqi@0 561 print_prop(short_name, "M");
aoqi@0 562 } else if (t->base() == Type::Abio) {
aoqi@0 563 print_prop(short_name, "IO");
aoqi@0 564 } else if (t->base() == Type::Return_Address) {
aoqi@0 565 print_prop(short_name, "RA");
aoqi@0 566 } else if (t->base() == Type::AnyPtr) {
aoqi@0 567 print_prop(short_name, "P");
aoqi@0 568 } else if (t->base() == Type::RawPtr) {
aoqi@0 569 print_prop(short_name, "RP");
aoqi@0 570 } else if (t->base() == Type::AryPtr) {
aoqi@0 571 print_prop(short_name, "AP");
aoqi@0 572 }
aoqi@0 573 }
aoqi@0 574
aoqi@0 575 JVMState* caller = NULL;
aoqi@0 576 if (node->is_SafePoint()) {
aoqi@0 577 caller = node->as_SafePoint()->jvms();
aoqi@0 578 } else {
aoqi@0 579 Node_Notes* notes = C->node_notes_at(node->_idx);
aoqi@0 580 if (notes != NULL) {
aoqi@0 581 caller = notes->jvms();
aoqi@0 582 }
aoqi@0 583 }
aoqi@0 584
aoqi@0 585 if (caller != NULL) {
aoqi@0 586 stringStream bciStream;
aoqi@0 587 ciMethod* last = NULL;
aoqi@0 588 int last_bci;
aoqi@0 589 while(caller) {
aoqi@0 590 if (caller->has_method()) {
aoqi@0 591 last = caller->method();
aoqi@0 592 last_bci = caller->bci();
aoqi@0 593 }
aoqi@0 594 bciStream.print("%d ", caller->bci());
aoqi@0 595 caller = caller->caller();
aoqi@0 596 }
aoqi@0 597 print_prop("bci", bciStream.as_string());
aoqi@0 598 if (last != NULL && last->has_linenumber_table() && last_bci >= 0) {
aoqi@0 599 print_prop("line", last->line_number_from_bci(last_bci));
aoqi@0 600 }
aoqi@0 601 }
aoqi@0 602
aoqi@0 603 #ifdef ASSERT
aoqi@0 604 if (node->debug_orig() != NULL) {
aoqi@0 605 temp_set->Clear();
aoqi@0 606 stringStream dorigStream;
aoqi@0 607 Node* dorig = node->debug_orig();
aoqi@0 608 while (dorig && temp_set->test_set(dorig->_idx)) {
aoqi@0 609 dorigStream.print("%d ", dorig->_idx);
aoqi@0 610 }
aoqi@0 611 print_prop("debug_orig", dorigStream.as_string());
aoqi@0 612 }
aoqi@0 613 #endif
aoqi@0 614
aoqi@0 615 if (_chaitin && _chaitin != (PhaseChaitin *)0xdeadbeef) {
aoqi@0 616 buffer[0] = 0;
aoqi@0 617 _chaitin->dump_register(node, buffer);
aoqi@0 618 print_prop("reg", buffer);
aoqi@0 619 uint lrg_id = 0;
aoqi@0 620 if (node->_idx < _chaitin->_lrg_map.size()) {
aoqi@0 621 lrg_id = _chaitin->_lrg_map.live_range_id(node);
aoqi@0 622 }
aoqi@0 623 print_prop("lrg", lrg_id);
aoqi@0 624 }
aoqi@0 625
aoqi@0 626 Compile::current()->_in_dump_cnt--;
aoqi@0 627 #endif
aoqi@0 628
aoqi@0 629 tail(PROPERTIES_ELEMENT);
aoqi@0 630 tail(NODE_ELEMENT);
aoqi@0 631 }
aoqi@0 632 }
aoqi@0 633
aoqi@0 634 void IdealGraphPrinter::walk_nodes(Node *start, bool edges, VectorSet* temp_set) {
aoqi@0 635
aoqi@0 636
aoqi@0 637 VectorSet visited(Thread::current()->resource_area());
aoqi@0 638 GrowableArray<Node *> nodeStack(Thread::current()->resource_area(), 0, 0, NULL);
aoqi@0 639 nodeStack.push(start);
aoqi@0 640 visited.test_set(start->_idx);
aoqi@0 641 if (C->cfg() != NULL) {
aoqi@0 642 // once we have a CFG there are some nodes that aren't really
aoqi@0 643 // reachable but are in the CFG so add them here.
aoqi@0 644 for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) {
aoqi@0 645 Block* block = C->cfg()->get_block(i);
aoqi@0 646 for (uint s = 0; s < block->number_of_nodes(); s++) {
aoqi@0 647 nodeStack.push(block->get_node(s));
aoqi@0 648 }
aoqi@0 649 }
aoqi@0 650 }
aoqi@0 651
aoqi@0 652 while(nodeStack.length() > 0) {
aoqi@0 653
aoqi@0 654 Node *n = nodeStack.pop();
aoqi@0 655 visit_node(n, edges, temp_set);
aoqi@0 656
aoqi@0 657 if (_traverse_outs) {
aoqi@0 658 for (DUIterator i = n->outs(); n->has_out(i); i++) {
aoqi@0 659 Node* p = n->out(i);
aoqi@0 660 if (!visited.test_set(p->_idx)) {
aoqi@0 661 nodeStack.push(p);
aoqi@0 662 }
aoqi@0 663 }
aoqi@0 664 }
aoqi@0 665
aoqi@0 666 for ( uint i = 0; i < n->len(); i++ ) {
aoqi@0 667 if ( n->in(i) ) {
aoqi@0 668 if (!visited.test_set(n->in(i)->_idx)) {
aoqi@0 669 nodeStack.push(n->in(i));
aoqi@0 670 }
aoqi@0 671 }
aoqi@0 672 }
aoqi@0 673 }
aoqi@0 674 }
aoqi@0 675
aoqi@0 676 void IdealGraphPrinter::print_method(Compile* compile, const char *name, int level, bool clear_nodes) {
aoqi@0 677 print(compile, name, (Node *)compile->root(), level, clear_nodes);
aoqi@0 678 }
aoqi@0 679
aoqi@0 680 // Print current ideal graph
aoqi@0 681 void IdealGraphPrinter::print(Compile* compile, const char *name, Node *node, int level, bool clear_nodes) {
aoqi@0 682
aoqi@0 683 if (!_current_method || !_should_send_method || level > PrintIdealGraphLevel) return;
aoqi@0 684
aoqi@0 685 this->C = compile;
aoqi@0 686
aoqi@0 687 // Warning, unsafe cast?
aoqi@0 688 _chaitin = (PhaseChaitin *)C->regalloc();
aoqi@0 689
aoqi@0 690 begin_head(GRAPH_ELEMENT);
aoqi@0 691 print_attr(GRAPH_NAME_PROPERTY, (const char *)name);
aoqi@0 692 end_head();
aoqi@0 693
aoqi@0 694 VectorSet temp_set(Thread::current()->resource_area());
aoqi@0 695
aoqi@0 696 head(NODES_ELEMENT);
aoqi@0 697 walk_nodes(node, false, &temp_set);
aoqi@0 698 tail(NODES_ELEMENT);
aoqi@0 699
aoqi@0 700 head(EDGES_ELEMENT);
aoqi@0 701 walk_nodes(node, true, &temp_set);
aoqi@0 702 tail(EDGES_ELEMENT);
aoqi@0 703 if (C->cfg() != NULL) {
aoqi@0 704 head(CONTROL_FLOW_ELEMENT);
aoqi@0 705 for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) {
aoqi@0 706 Block* block = C->cfg()->get_block(i);
aoqi@0 707 begin_head(BLOCK_ELEMENT);
aoqi@0 708 print_attr(BLOCK_NAME_PROPERTY, block->_pre_order);
aoqi@0 709 end_head();
aoqi@0 710
aoqi@0 711 head(SUCCESSORS_ELEMENT);
aoqi@0 712 for (uint s = 0; s < block->_num_succs; s++) {
aoqi@0 713 begin_elem(SUCCESSOR_ELEMENT);
aoqi@0 714 print_attr(BLOCK_NAME_PROPERTY, block->_succs[s]->_pre_order);
aoqi@0 715 end_elem();
aoqi@0 716 }
aoqi@0 717 tail(SUCCESSORS_ELEMENT);
aoqi@0 718
aoqi@0 719 head(NODES_ELEMENT);
aoqi@0 720 for (uint s = 0; s < block->number_of_nodes(); s++) {
aoqi@0 721 begin_elem(NODE_ELEMENT);
aoqi@0 722 print_attr(NODE_ID_PROPERTY, get_node_id(block->get_node(s)));
aoqi@0 723 end_elem();
aoqi@0 724 }
aoqi@0 725 tail(NODES_ELEMENT);
aoqi@0 726
aoqi@0 727 tail(BLOCK_ELEMENT);
aoqi@0 728 }
aoqi@0 729 tail(CONTROL_FLOW_ELEMENT);
aoqi@0 730 }
aoqi@0 731 tail(GRAPH_ELEMENT);
aoqi@0 732 output()->flush();
aoqi@0 733 }
aoqi@0 734
aoqi@0 735 extern const char *NodeClassNames[];
aoqi@0 736
aoqi@0 737 outputStream *IdealGraphPrinter::output() {
aoqi@0 738 return _xml;
aoqi@0 739 }
aoqi@0 740
aoqi@0 741 #endif

mercurial