1.1 --- a/src/share/vm/opto/idealGraphPrinter.cpp Tue Jun 24 10:43:29 2008 -0700 1.2 +++ b/src/share/vm/opto/idealGraphPrinter.cpp Tue Jun 24 16:00:14 2008 -0700 1.3 @@ -100,16 +100,18 @@ 1.4 // Constructor, either file or network output 1.5 IdealGraphPrinter::IdealGraphPrinter() { 1.6 1.7 - _traverse_outs = false; 1.8 + // By default dump both ins and outs since dead or unreachable code 1.9 + // needs to appear in the graph. There are also some special cases 1.10 + // in the mach where kill projections have no users but should 1.11 + // appear in the dump. 1.12 + _traverse_outs = true; 1.13 _should_send_method = true; 1.14 _output = NULL; 1.15 buffer[0] = 0; 1.16 _depth = 0; 1.17 _current_method = NULL; 1.18 assert(!_current_method, "current method must be initialized to NULL"); 1.19 - _arena = new Arena(); 1.20 - 1.21 - _stream = new (ResourceObj::C_HEAP) networkStream(); 1.22 + _stream = NULL; 1.23 1.24 if (PrintIdealGraphFile != NULL) { 1.25 ThreadCritical tc; 1.26 @@ -124,12 +126,16 @@ 1.27 } else { 1.28 st.print("%s%d", PrintIdealGraphFile, _file_count); 1.29 } 1.30 - _output = new (ResourceObj::C_HEAP) fileStream(st.as_string()); 1.31 + fileStream *stream = new (ResourceObj::C_HEAP) fileStream(st.as_string()); 1.32 + _output = stream; 1.33 } else { 1.34 - _output = new (ResourceObj::C_HEAP) fileStream(PrintIdealGraphFile); 1.35 + fileStream *stream = new (ResourceObj::C_HEAP) fileStream(PrintIdealGraphFile); 1.36 + _output = stream; 1.37 } 1.38 _file_count++; 1.39 } else { 1.40 + _stream = new (ResourceObj::C_HEAP) networkStream(); 1.41 + 1.42 // Try to connect to visualizer 1.43 if (_stream->connect(PrintIdealGraphAddress, PrintIdealGraphPort)) { 1.44 char c = 0; 1.45 @@ -149,13 +155,24 @@ 1.46 } 1.47 } 1.48 1.49 - start_element(TOP_ELEMENT); 1.50 + _xml = new (ResourceObj::C_HEAP) xmlStream(_output); 1.51 + 1.52 + head(TOP_ELEMENT); 1.53 } 1.54 1.55 // Destructor, close file or network stream 1.56 IdealGraphPrinter::~IdealGraphPrinter() { 1.57 1.58 - end_element(TOP_ELEMENT); 1.59 + tail(TOP_ELEMENT); 1.60 + 1.61 + // tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds()); 1.62 + // tty->print_cr("Output time: %d", (int)_output_time.milliseconds()); 1.63 + // tty->print_cr("Build blocks time: %d", (int)_build_blocks_time.milliseconds()); 1.64 + 1.65 + if(_xml) { 1.66 + delete _xml; 1.67 + _xml = NULL; 1.68 + } 1.69 1.70 if (_stream) { 1.71 delete _stream; 1.72 @@ -171,94 +188,93 @@ 1.73 } 1.74 } 1.75 1.76 -void IdealGraphPrinter::print_ifg(PhaseIFG* ifg) { 1.77 1.78 - // Code to print an interference graph to tty, currently not used 1.79 +void IdealGraphPrinter::begin_elem(const char *s) { 1.80 + _xml->begin_elem(s); 1.81 +} 1.82 1.83 - /* 1.84 - if (!_current_method) return; 1.85 - // Remove neighbor colors 1.86 +void IdealGraphPrinter::end_elem() { 1.87 + _xml->end_elem(); 1.88 +} 1.89 1.90 - for (uint i = 0; i < ifg._maxlrg; i++) { 1.91 +void IdealGraphPrinter::begin_head(const char *s) { 1.92 + _xml->begin_head(s); 1.93 +} 1.94 1.95 - IndexSet *s = ifg.neighbors(i); 1.96 - IndexSetIterator elements(s); 1.97 - uint neighbor; 1.98 - while ((neighbor = elements.next()) != 0) { 1.99 - tty->print_cr("Edge between %d and %d\n", i, neighbor); 1.100 - } 1.101 - } 1.102 +void IdealGraphPrinter::end_head() { 1.103 + _xml->end_head(); 1.104 +} 1.105 1.106 +void IdealGraphPrinter::print_attr(const char *name, intptr_t val) { 1.107 + stringStream stream; 1.108 + stream.print(INTX_FORMAT, val); 1.109 + print_attr(name, stream.as_string()); 1.110 +} 1.111 1.112 - for (uint i = 0; i < ifg._maxlrg; i++) { 1.113 - LRG &l = ifg.lrgs(i); 1.114 - if (l._def) { 1.115 - OptoReg::Name name = l.reg(); 1.116 - tty->print("OptoReg::dump: "); 1.117 - OptoReg::dump(name); 1.118 - tty->print_cr(""); 1.119 - tty->print_cr("name=%d\n", name); 1.120 - if (name) { 1.121 - if (OptoReg::is_stack(name)) { 1.122 - tty->print_cr("Stack number %d\n", OptoReg::reg2stack(name)); 1.123 +void IdealGraphPrinter::print_attr(const char *name, const char *val) { 1.124 + _xml->print(" %s='", name); 1.125 + text(val); 1.126 + _xml->print("'"); 1.127 +} 1.128 1.129 - } else if (!OptoReg::is_valid(name)) { 1.130 - tty->print_cr("BAD!!!"); 1.131 - } else { 1.132 +void IdealGraphPrinter::head(const char *name) { 1.133 + _xml->head(name); 1.134 +} 1.135 1.136 - if (OptoReg::is_reg(name)) { 1.137 - tty->print_cr(OptoReg::regname(name)); 1.138 - } else { 1.139 - int x = 0; 1.140 - } 1.141 - } 1.142 - int x = 0; 1.143 - } 1.144 +void IdealGraphPrinter::tail(const char *name) { 1.145 + _xml->tail(name); 1.146 +} 1.147 1.148 - if (l._def == NodeSentinel) { 1.149 - tty->print("multiple mapping from %d: ", i); 1.150 - for (int j=0; j<l._defs->length(); j++) { 1.151 - tty->print("%d ", l._defs->at(j)->_idx); 1.152 - } 1.153 - tty->print_cr(""); 1.154 - } else { 1.155 - tty->print_cr("mapping between %d and %d\n", i, l._def->_idx); 1.156 - } 1.157 - } 1.158 - }*/ 1.159 +void IdealGraphPrinter::text(const char *s) { 1.160 + _xml->text(s); 1.161 +} 1.162 + 1.163 +void IdealGraphPrinter::print_prop(const char *name, int val) { 1.164 + 1.165 + stringStream stream; 1.166 + stream.print("%d", val); 1.167 + print_prop(name, stream.as_string()); 1.168 +} 1.169 + 1.170 +void IdealGraphPrinter::print_prop(const char *name, const char *val) { 1.171 + begin_head(PROPERTY_ELEMENT); 1.172 + print_attr(PROPERTY_NAME_PROPERTY, name); 1.173 + end_head(); 1.174 + text(val); 1.175 + tail(PROPERTY_ELEMENT); 1.176 } 1.177 1.178 void IdealGraphPrinter::print_method(ciMethod *method, int bci, InlineTree *tree) { 1.179 + begin_head(METHOD_ELEMENT); 1.180 1.181 - Properties properties; 1.182 stringStream str; 1.183 method->print_name(&str); 1.184 1.185 stringStream shortStr; 1.186 method->print_short_name(&shortStr); 1.187 1.188 + print_attr(METHOD_NAME_PROPERTY, str.as_string()); 1.189 + print_attr(METHOD_SHORT_NAME_PROPERTY, shortStr.as_string()); 1.190 + print_attr(METHOD_BCI_PROPERTY, bci); 1.191 1.192 - properties.add(new Property(METHOD_NAME_PROPERTY, str.as_string())); 1.193 - properties.add(new Property(METHOD_SHORT_NAME_PROPERTY, shortStr.as_string())); 1.194 - properties.add(new Property(METHOD_BCI_PROPERTY, bci)); 1.195 - start_element(METHOD_ELEMENT, &properties); 1.196 + end_head(); 1.197 1.198 - start_element(BYTECODES_ELEMENT); 1.199 + head(BYTECODES_ELEMENT); 1.200 output()->print_cr("<![CDATA["); 1.201 method->print_codes_on(output()); 1.202 output()->print_cr("]]>"); 1.203 - end_element(BYTECODES_ELEMENT); 1.204 + tail(BYTECODES_ELEMENT); 1.205 1.206 - start_element(INLINE_ELEMENT); 1.207 + head(INLINE_ELEMENT); 1.208 if (tree != NULL) { 1.209 GrowableArray<InlineTree *> subtrees = tree->subtrees(); 1.210 for (int i = 0; i < subtrees.length(); i++) { 1.211 print_inline_tree(subtrees.at(i)); 1.212 } 1.213 } 1.214 - end_element(INLINE_ELEMENT); 1.215 + tail(INLINE_ELEMENT); 1.216 1.217 - end_element(METHOD_ELEMENT); 1.218 + tail(METHOD_ELEMENT); 1.219 output()->flush(); 1.220 } 1.221 1.222 @@ -271,12 +287,6 @@ 1.223 1.224 } 1.225 1.226 -void IdealGraphPrinter::clear_nodes() { 1.227 - // for (int i = 0; i < _nodes.length(); i++) { 1.228 - // _nodes.at(i)->clear_node(); 1.229 - // } 1.230 -} 1.231 - 1.232 void IdealGraphPrinter::print_inlining(Compile* compile) { 1.233 1.234 // Print inline tree 1.235 @@ -298,143 +308,56 @@ 1.236 assert(method, "null methods are not allowed!"); 1.237 assert(!_current_method, "current method must be null!"); 1.238 1.239 - _arena->destruct_contents(); 1.240 + head(GROUP_ELEMENT); 1.241 1.242 - start_element(GROUP_ELEMENT); 1.243 + head(PROPERTIES_ELEMENT); 1.244 1.245 // Print properties 1.246 - Properties properties; 1.247 - 1.248 // Add method name 1.249 stringStream strStream; 1.250 method->print_name(&strStream); 1.251 - properties.add(new Property(METHOD_NAME_PROPERTY, strStream.as_string())); 1.252 + print_prop(METHOD_NAME_PROPERTY, strStream.as_string()); 1.253 1.254 if (method->flags().is_public()) { 1.255 - properties.add(new Property(METHOD_IS_PUBLIC_PROPERTY, TRUE_VALUE)); 1.256 + print_prop(METHOD_IS_PUBLIC_PROPERTY, TRUE_VALUE); 1.257 } 1.258 1.259 if (method->flags().is_static()) { 1.260 - properties.add(new Property(METHOD_IS_STATIC_PROPERTY, TRUE_VALUE)); 1.261 + print_prop(METHOD_IS_STATIC_PROPERTY, TRUE_VALUE); 1.262 } 1.263 1.264 - properties.print(this); 1.265 + tail(PROPERTIES_ELEMENT); 1.266 1.267 if (_stream) { 1.268 char answer = 0; 1.269 - _stream->flush(); 1.270 + _xml->flush(); 1.271 int result = _stream->read(&answer, 1); 1.272 _should_send_method = (answer == 'y'); 1.273 } 1.274 1.275 - this->_nodes = GrowableArray<NodeDescription *>(_arena, 2, 0, NULL); 1.276 - this->_edges = GrowableArray< EdgeDescription * >(_arena, 2, 0, NULL); 1.277 - 1.278 - 1.279 this->_current_method = method; 1.280 1.281 - 1.282 - 1.283 - _output->flush(); 1.284 + _xml->flush(); 1.285 } 1.286 1.287 // Has to be called whenever a method has finished compilation 1.288 void IdealGraphPrinter::end_method() { 1.289 1.290 -// if (finish && !in_method) return; 1.291 - 1.292 nmethod* method = (nmethod*)this->_current_method->code(); 1.293 1.294 - start_element(ASSEMBLY_ELEMENT); 1.295 - // Disassembler::decode(method, _output); 1.296 - end_element(ASSEMBLY_ELEMENT); 1.297 - 1.298 - 1.299 - end_element(GROUP_ELEMENT); 1.300 + tail(GROUP_ELEMENT); 1.301 _current_method = NULL; 1.302 - _output->flush(); 1.303 - for (int i = 0; i < _nodes.length(); i++) { 1.304 - NodeDescription *desc = _nodes.at(i); 1.305 - if (desc) { 1.306 - delete desc; 1.307 - _nodes.at_put(i, NULL); 1.308 - } 1.309 - } 1.310 - this->_nodes.clear(); 1.311 - 1.312 - 1.313 - for (int i = 0; i < _edges.length(); i++) { 1.314 - // for (int j=0; j<_edges.at(i)->length(); j++) { 1.315 - EdgeDescription *conn = _edges.at(i); 1.316 - conn->print(this); 1.317 - if (conn) { 1.318 - delete conn; 1.319 - _edges.at_put(i, NULL); 1.320 - } 1.321 - //} 1.322 - //_edges.at(i)->clear(); 1.323 - //delete _edges.at(i); 1.324 - //_edges.at_put(i, NULL); 1.325 - } 1.326 - this->_edges.clear(); 1.327 - 1.328 -// in_method = false; 1.329 -} 1.330 - 1.331 -// Outputs an XML start element 1.332 -void IdealGraphPrinter::start_element(const char *s, Properties *properties /* = NULL */, bool print_indent /* = false */, bool print_return /* = true */) { 1.333 - 1.334 - start_element_helper(s, properties, false, print_indent, print_return); 1.335 - _depth++; 1.336 - 1.337 -} 1.338 - 1.339 -// Outputs an XML start element without body 1.340 -void IdealGraphPrinter::simple_element(const char *s, Properties *properties /* = NULL */, bool print_indent /* = false */) { 1.341 - start_element_helper(s, properties, true, print_indent, true); 1.342 -} 1.343 - 1.344 -// Outputs an XML start element. If outputEnd is true, the element has no body. 1.345 -void IdealGraphPrinter::start_element_helper(const char *s, Properties *properties, bool outputEnd, bool print_indent /* = false */, bool print_return /* = true */) { 1.346 - 1.347 - assert(_output, "output stream must exist!"); 1.348 - 1.349 - if (print_indent) this->print_indent(); 1.350 - _output->print("<"); 1.351 - _output->print(s); 1.352 - if (properties) properties->print_as_attributes(this); 1.353 - 1.354 - if (outputEnd) { 1.355 - _output->print("/"); 1.356 - } 1.357 - 1.358 - _output->print(">"); 1.359 - if (print_return) _output->print_cr(""); 1.360 - 1.361 + _xml->flush(); 1.362 } 1.363 1.364 // Print indent 1.365 void IdealGraphPrinter::print_indent() { 1.366 + tty->print_cr("printing ident %d", _depth); 1.367 for (int i = 0; i < _depth; i++) { 1.368 - _output->print(INDENT); 1.369 + _xml->print(INDENT); 1.370 } 1.371 } 1.372 1.373 -// Outputs an XML end element 1.374 -void IdealGraphPrinter::end_element(const char *s, bool print_indent /* = true */, bool print_return /* = true */) { 1.375 - 1.376 - assert(_output, "output stream must exist!"); 1.377 - 1.378 - _depth--; 1.379 - 1.380 - if (print_indent) this->print_indent(); 1.381 - _output->print("</"); 1.382 - _output->print(s); 1.383 - _output->print(">"); 1.384 - if (print_return) _output->print_cr(""); 1.385 - 1.386 -} 1.387 - 1.388 bool IdealGraphPrinter::traverse_outs() { 1.389 return _traverse_outs; 1.390 } 1.391 @@ -443,7 +366,255 @@ 1.392 _traverse_outs = b; 1.393 } 1.394 1.395 -void IdealGraphPrinter::walk(Node *start) { 1.396 +intptr_t IdealGraphPrinter::get_node_id(Node *n) { 1.397 + return (intptr_t)(n); 1.398 +} 1.399 + 1.400 +void IdealGraphPrinter::visit_node(Node *n, void *param) { 1.401 + 1.402 + if(param) { 1.403 + 1.404 + // Output edge 1.405 + intptr_t dest_id = get_node_id(n); 1.406 + for ( uint i = 0; i < n->len(); i++ ) { 1.407 + if ( n->in(i) ) { 1.408 + Node *source = n->in(i); 1.409 + begin_elem(EDGE_ELEMENT); 1.410 + intptr_t source_id = get_node_id(source); 1.411 + print_attr(FROM_PROPERTY, source_id); 1.412 + print_attr(TO_PROPERTY, dest_id); 1.413 + print_attr(INDEX_PROPERTY, i); 1.414 + end_elem(); 1.415 + } 1.416 + } 1.417 + 1.418 + } else { 1.419 + 1.420 + // Output node 1.421 + begin_head(NODE_ELEMENT); 1.422 + print_attr(NODE_ID_PROPERTY, get_node_id(n)); 1.423 + end_head(); 1.424 + 1.425 + head(PROPERTIES_ELEMENT); 1.426 + 1.427 + Node *node = n; 1.428 +#ifndef PRODUCT 1.429 + node->_in_dump_cnt++; 1.430 + print_prop(NODE_NAME_PROPERTY, (const char *)node->Name()); 1.431 + const Type *t = node->bottom_type(); 1.432 + print_prop("type", (const char *)Type::msg[t->base()]); 1.433 + print_prop("idx", node->_idx); 1.434 +#ifdef ASSERT 1.435 + print_prop("debug_idx", node->_debug_idx); 1.436 +#endif 1.437 + 1.438 + if(C->cfg() != NULL) { 1.439 + Block *block = C->cfg()->_bbs[node->_idx]; 1.440 + if(block == NULL) { 1.441 + print_prop("block", C->cfg()->_blocks[0]->_pre_order); 1.442 + } else { 1.443 + print_prop("block", block->_pre_order); 1.444 + } 1.445 + } 1.446 + 1.447 + const jushort flags = node->flags(); 1.448 + if (flags & Node::Flag_is_Copy) { 1.449 + print_prop("is_copy", "true"); 1.450 + } 1.451 + if (flags & Node::Flag_is_Call) { 1.452 + print_prop("is_call", "true"); 1.453 + } 1.454 + if (flags & Node::Flag_rematerialize) { 1.455 + print_prop("rematerialize", "true"); 1.456 + } 1.457 + if (flags & Node::Flag_needs_anti_dependence_check) { 1.458 + print_prop("needs_anti_dependence_check", "true"); 1.459 + } 1.460 + if (flags & Node::Flag_is_macro) { 1.461 + print_prop("is_macro", "true"); 1.462 + } 1.463 + if (flags & Node::Flag_is_Con) { 1.464 + print_prop("is_con", "true"); 1.465 + } 1.466 + if (flags & Node::Flag_is_cisc_alternate) { 1.467 + print_prop("is_cisc_alternate", "true"); 1.468 + } 1.469 + if (flags & Node::Flag_is_Branch) { 1.470 + print_prop("is_branch", "true"); 1.471 + } 1.472 + if (flags & Node::Flag_is_block_start) { 1.473 + print_prop("is_block_start", "true"); 1.474 + } 1.475 + if (flags & Node::Flag_is_Goto) { 1.476 + print_prop("is_goto", "true"); 1.477 + } 1.478 + if (flags & Node::Flag_is_dead_loop_safe) { 1.479 + print_prop("is_dead_loop_safe", "true"); 1.480 + } 1.481 + if (flags & Node::Flag_may_be_short_branch) { 1.482 + print_prop("may_be_short_branch", "true"); 1.483 + } 1.484 + if (flags & Node::Flag_is_safepoint_node) { 1.485 + print_prop("is_safepoint_node", "true"); 1.486 + } 1.487 + if (flags & Node::Flag_is_pc_relative) { 1.488 + print_prop("is_pc_relative", "true"); 1.489 + } 1.490 + 1.491 + if (C->matcher() != NULL) { 1.492 + if (C->matcher()->is_shared(node)) { 1.493 + print_prop("is_shared", "true"); 1.494 + } else { 1.495 + print_prop("is_shared", "false"); 1.496 + } 1.497 + if (C->matcher()->is_dontcare(node)) { 1.498 + print_prop("is_dontcare", "true"); 1.499 + } else { 1.500 + print_prop("is_dontcare", "false"); 1.501 + } 1.502 + 1.503 + Node* old = C->matcher()->find_old_node(node); 1.504 + if (old != NULL) { 1.505 + print_prop("old_node_idx", old->_idx); 1.506 + } 1.507 + } 1.508 + 1.509 + if (node->is_Proj()) { 1.510 + print_prop("con", (int)node->as_Proj()->_con); 1.511 + } 1.512 + 1.513 + if (node->is_Mach()) { 1.514 + print_prop("idealOpcode", (const char *)NodeClassNames[node->as_Mach()->ideal_Opcode()]); 1.515 + } 1.516 + 1.517 + buffer[0] = 0; 1.518 + stringStream s2(buffer, sizeof(buffer) - 1); 1.519 + 1.520 + node->dump_spec(&s2); 1.521 + if (t != NULL && (t->isa_instptr() || t->isa_klassptr())) { 1.522 + const TypeInstPtr *toop = t->isa_instptr(); 1.523 + const TypeKlassPtr *tkls = t->isa_klassptr(); 1.524 + ciKlass* klass = toop ? toop->klass() : (tkls ? tkls->klass() : NULL ); 1.525 + if( klass && klass->is_loaded() && klass->is_interface() ) { 1.526 + s2.print(" Interface:"); 1.527 + } else if( toop ) { 1.528 + s2.print(" Oop:"); 1.529 + } else if( tkls ) { 1.530 + s2.print(" Klass:"); 1.531 + } 1.532 + t->dump_on(&s2); 1.533 + } else if( t == Type::MEMORY ) { 1.534 + s2.print(" Memory:"); 1.535 + MemNode::dump_adr_type(node, node->adr_type(), &s2); 1.536 + } 1.537 + 1.538 + assert(s2.size() < sizeof(buffer), "size in range"); 1.539 + print_prop("dump_spec", buffer); 1.540 + 1.541 + if (node->is_block_proj()) { 1.542 + print_prop("is_block_proj", "true"); 1.543 + } 1.544 + 1.545 + if (node->is_block_start()) { 1.546 + print_prop("is_block_start", "true"); 1.547 + } 1.548 + 1.549 + const char *short_name = "short_name"; 1.550 + if (strcmp(node->Name(), "Parm") == 0 && node->as_Proj()->_con >= TypeFunc::Parms) { 1.551 + int index = node->as_Proj()->_con - TypeFunc::Parms; 1.552 + if (index >= 10) { 1.553 + print_prop(short_name, "PA"); 1.554 + } else { 1.555 + sprintf(buffer, "P%d", index); 1.556 + print_prop(short_name, buffer); 1.557 + } 1.558 + } else if (strcmp(node->Name(), "IfTrue") == 0) { 1.559 + print_prop(short_name, "T"); 1.560 + } else if (strcmp(node->Name(), "IfFalse") == 0) { 1.561 + print_prop(short_name, "F"); 1.562 + } else if ((node->is_Con() && node->is_Type()) || node->is_Proj()) { 1.563 + 1.564 + if (t->base() == Type::Int && t->is_int()->is_con()) { 1.565 + const TypeInt *typeInt = t->is_int(); 1.566 + assert(typeInt->is_con(), "must be constant"); 1.567 + jint value = typeInt->get_con(); 1.568 + 1.569 + // max. 2 chars allowed 1.570 + if (value >= -9 && value <= 99) { 1.571 + sprintf(buffer, "%d", value); 1.572 + print_prop(short_name, buffer); 1.573 + } else { 1.574 + print_prop(short_name, "I"); 1.575 + } 1.576 + } else if (t == Type::TOP) { 1.577 + print_prop(short_name, "^"); 1.578 + } else if (t->base() == Type::Long && t->is_long()->is_con()) { 1.579 + const TypeLong *typeLong = t->is_long(); 1.580 + assert(typeLong->is_con(), "must be constant"); 1.581 + jlong value = typeLong->get_con(); 1.582 + 1.583 + // max. 2 chars allowed 1.584 + if (value >= -9 && value <= 99) { 1.585 + sprintf(buffer, "%d", value); 1.586 + print_prop(short_name, buffer); 1.587 + } else { 1.588 + print_prop(short_name, "L"); 1.589 + } 1.590 + } else if (t->base() == Type::KlassPtr) { 1.591 + const TypeKlassPtr *typeKlass = t->is_klassptr(); 1.592 + print_prop(short_name, "CP"); 1.593 + } else if (t->base() == Type::Control) { 1.594 + print_prop(short_name, "C"); 1.595 + } else if (t->base() == Type::Memory) { 1.596 + print_prop(short_name, "M"); 1.597 + } else if (t->base() == Type::Abio) { 1.598 + print_prop(short_name, "IO"); 1.599 + } else if (t->base() == Type::Return_Address) { 1.600 + print_prop(short_name, "RA"); 1.601 + } else if (t->base() == Type::AnyPtr) { 1.602 + print_prop(short_name, "P"); 1.603 + } else if (t->base() == Type::RawPtr) { 1.604 + print_prop(short_name, "RP"); 1.605 + } else if (t->base() == Type::AryPtr) { 1.606 + print_prop(short_name, "AP"); 1.607 + } 1.608 + } 1.609 + 1.610 + JVMState* caller = NULL; 1.611 + if (node->is_SafePoint()) { 1.612 + caller = node->as_SafePoint()->jvms(); 1.613 + } else { 1.614 + Node_Notes* notes = C->node_notes_at(node->_idx); 1.615 + if (notes != NULL) { 1.616 + caller = notes->jvms(); 1.617 + } 1.618 + } 1.619 + 1.620 + if (caller != NULL) { 1.621 + stringStream bciStream; 1.622 + while(caller) { 1.623 + bciStream.print("%d ", caller->bci()); 1.624 + caller = caller->caller(); 1.625 + } 1.626 + print_prop("bci", bciStream.as_string()); 1.627 + } 1.628 + 1.629 + if (_chaitin && _chaitin != (PhaseChaitin *)0xdeadbeef) { 1.630 + buffer[0] = 0; 1.631 + _chaitin->dump_register(node, buffer); 1.632 + print_prop("reg", buffer); 1.633 + print_prop("lrg", _chaitin->n2lidx(node)); 1.634 + } 1.635 + 1.636 + node->_in_dump_cnt--; 1.637 +#endif 1.638 + 1.639 + tail(PROPERTIES_ELEMENT); 1.640 + tail(NODE_ELEMENT); 1.641 + } 1.642 +} 1.643 + 1.644 +void IdealGraphPrinter::walk_nodes(Node *start, void *param) { 1.645 1.646 1.647 VectorSet visited(Thread::current()->resource_area()); 1.648 @@ -453,7 +624,7 @@ 1.649 while(nodeStack.length() > 0) { 1.650 1.651 Node *n = nodeStack.pop(); 1.652 - IdealGraphPrinter::pre_node(n, this); 1.653 + visit_node(n, param); 1.654 1.655 if (_traverse_outs) { 1.656 for (DUIterator i = n->outs(); n->has_out(i); i++) { 1.657 @@ -474,573 +645,6 @@ 1.658 } 1.659 } 1.660 1.661 -void IdealGraphPrinter::compress(int index, GrowableArray<Block>* blocks) { 1.662 - Block *block = blocks->adr_at(index); 1.663 - 1.664 - int ancestor = block->ancestor(); 1.665 - assert(ancestor != -1, ""); 1.666 - 1.667 - Block *ancestor_block = blocks->adr_at(ancestor); 1.668 - if (ancestor_block->ancestor() != -1) { 1.669 - compress(ancestor, blocks); 1.670 - 1.671 - int label = block->label(); 1.672 - Block *label_block = blocks->adr_at(label); 1.673 - 1.674 - int ancestor_label = ancestor_block->label(); 1.675 - Block *ancestor_label_block = blocks->adr_at(label); 1.676 - if (ancestor_label_block->semi() < label_block->semi()) { 1.677 - block->set_label(ancestor_label); 1.678 - } 1.679 - 1.680 - block->set_ancestor(ancestor_block->ancestor()); 1.681 - } 1.682 -} 1.683 - 1.684 -int IdealGraphPrinter::eval(int index, GrowableArray<Block>* blocks) { 1.685 - Block *block = blocks->adr_at(index); 1.686 - if (block->ancestor() == -1) { 1.687 - return index; 1.688 - } else { 1.689 - compress(index, blocks); 1.690 - return block->label(); 1.691 - } 1.692 -} 1.693 - 1.694 -void IdealGraphPrinter::link(int index1, int index2, GrowableArray<Block>* blocks) { 1.695 - Block *block2 = blocks->adr_at(index2); 1.696 - block2->set_ancestor(index1); 1.697 -} 1.698 - 1.699 -void IdealGraphPrinter::build_dominators(GrowableArray<Block>* blocks) { 1.700 - 1.701 - if (blocks->length() == 0) return; 1.702 - 1.703 - GrowableArray<int> stack; 1.704 - stack.append(0); 1.705 - 1.706 - GrowableArray<Block *> array; 1.707 - 1.708 - assert(blocks->length() > 0, ""); 1.709 - blocks->adr_at(0)->set_dominator(0); 1.710 - 1.711 - int n = 0; 1.712 - while(!stack.is_empty()) { 1.713 - int index = stack.pop(); 1.714 - Block *block = blocks->adr_at(index); 1.715 - block->set_semi(n); 1.716 - array.append(block); 1.717 - n = n + 1; 1.718 - for (int i = 0; i < block->succs()->length(); i++) { 1.719 - int succ_index = block->succs()->at(i); 1.720 - Block *succ = blocks->adr_at(succ_index); 1.721 - if (succ->semi() == -1) { 1.722 - succ->set_parent(index); 1.723 - stack.push(succ_index); 1.724 - } 1.725 - succ->add_pred(index); 1.726 - } 1.727 - } 1.728 - 1.729 - for (int i=n-1; i>0; i--) { 1.730 - Block *block = array.at(i); 1.731 - int block_index = block->index(); 1.732 - for (int j=0; j<block->pred()->length(); j++) { 1.733 - int pred_index = block->pred()->at(j); 1.734 - int cur_index = eval(pred_index, blocks); 1.735 - 1.736 - Block *cur_block = blocks->adr_at(cur_index); 1.737 - if (cur_block->semi() < block->semi()) { 1.738 - block->set_semi(cur_block->semi()); 1.739 - } 1.740 - } 1.741 - 1.742 - int semi_index = block->semi(); 1.743 - Block *semi_block = array.at(semi_index); 1.744 - semi_block->add_to_bucket(block_index); 1.745 - 1.746 - link(block->parent(), block_index, blocks); 1.747 - Block *parent_block = blocks->adr_at(block->parent()); 1.748 - 1.749 - for (int j=0; j<parent_block->bucket()->length(); j++) { 1.750 - int cur_index = parent_block->bucket()->at(j); 1.751 - int new_index = eval(cur_index, blocks); 1.752 - Block *cur_block = blocks->adr_at(cur_index); 1.753 - Block *new_block = blocks->adr_at(new_index); 1.754 - int dom = block->parent(); 1.755 - 1.756 - if (new_block->semi() < cur_block->semi()) { 1.757 - dom = new_index; 1.758 - } 1.759 - 1.760 - cur_block->set_dominator(dom); 1.761 - } 1.762 - 1.763 - parent_block->clear_bucket(); 1.764 - } 1.765 - 1.766 - for (int i=1; i < n; i++) { 1.767 - 1.768 - Block *block = array.at(i); 1.769 - int block_index = block->index(); 1.770 - 1.771 - int semi_index = block->semi(); 1.772 - Block *semi_block = array.at(semi_index); 1.773 - 1.774 - if (block->dominator() != semi_block->index()) { 1.775 - int new_dom = blocks->adr_at(block->dominator())->dominator(); 1.776 - block->set_dominator(new_dom); 1.777 - } 1.778 - } 1.779 - 1.780 - for (int i = 0; i < blocks->length(); i++) { 1.781 - if (blocks->adr_at(i)->dominator() == -1) { 1.782 - blocks->adr_at(i)->set_dominator(0); 1.783 - } 1.784 - } 1.785 - 1.786 - // Build dominates array 1.787 - for (int i=1; i < blocks->length(); i++) { 1.788 - Block *block = blocks->adr_at(i); 1.789 - int dominator = block->dominator(); 1.790 - Block *dom_block = blocks->adr_at(dominator); 1.791 - dom_block->add_dominates(i); 1.792 - dom_block->add_child(i); 1.793 - 1.794 - while(dominator != 0) { 1.795 - dominator = dom_block->dominator(); 1.796 - dom_block = blocks->adr_at(dominator); 1.797 - dom_block->add_child(i); 1.798 - } 1.799 - } 1.800 -} 1.801 - 1.802 -void IdealGraphPrinter::build_common_dominator(int **common_dominator, int index, GrowableArray<Block>* blocks) { 1.803 - 1.804 - common_dominator[index][index] = index; 1.805 - Block *block = blocks->adr_at(index); 1.806 - for (int i = 0; i < block->dominates()->length(); i++) { 1.807 - Block *dominated = blocks->adr_at(block->dominates()->at(i)); 1.808 - 1.809 - for (int j=0; j<dominated->children()->length(); j++) { 1.810 - Block *child = blocks->adr_at(dominated->children()->at(j)); 1.811 - common_dominator[index][child->index()] = common_dominator[child->index()][index] = index; 1.812 - 1.813 - for (int k=0; k<i; k++) { 1.814 - Block *other_dominated = blocks->adr_at(block->dominates()->at(k)); 1.815 - common_dominator[child->index()][other_dominated->index()] = common_dominator[other_dominated->index()][child->index()] = index; 1.816 - 1.817 - for (int l=0 ; l<other_dominated->children()->length(); l++) { 1.818 - Block *other_child = blocks->adr_at(other_dominated->children()->at(l)); 1.819 - common_dominator[child->index()][other_child->index()] = common_dominator[other_child->index()][child->index()] = index; 1.820 - } 1.821 - } 1.822 - } 1.823 - 1.824 - build_common_dominator(common_dominator, dominated->index(), blocks); 1.825 - } 1.826 -} 1.827 - 1.828 -void IdealGraphPrinter::schedule_latest(int **common_dominator, GrowableArray<Block>* blocks) { 1.829 - 1.830 - int queue_size = _nodes.length() + 1; 1.831 - NodeDescription **queue = NEW_RESOURCE_ARRAY(NodeDescription *, queue_size); 1.832 - int queue_start = 0; 1.833 - int queue_end = 0; 1.834 - Arena *a = new Arena(); 1.835 - VectorSet on_queue(a); 1.836 - 1.837 - for (int i = 0; i < _nodes.length(); i++) { 1.838 - NodeDescription *desc = _nodes.at(i); 1.839 - if (desc) { 1.840 - desc->init_succs(); 1.841 - } 1.842 - } 1.843 - 1.844 - for (int i = 0; i < _nodes.length(); i++) { 1.845 - NodeDescription *desc = _nodes.at(i); 1.846 - if (desc) { 1.847 - for (uint j=0; j<desc->node()->len(); j++) { 1.848 - Node *n = desc->node()->in(j); 1.849 - if (n) { 1.850 - NodeDescription *other_desc = _nodes.at(n->_idx); 1.851 - other_desc->add_succ(desc); 1.852 - } 1.853 - } 1.854 - } 1.855 - } 1.856 - 1.857 - for (int i = 0; i < _nodes.length(); i++) { 1.858 - NodeDescription *desc = _nodes.at(i); 1.859 - if (desc && desc->block_index() == -1) { 1.860 - 1.861 - // Put Phi into same block as region 1.862 - if (desc->node()->is_Phi() && desc->node()->in(0) && _nodes.at(desc->node()->in(0)->_idx)->block_index() != -1) { 1.863 - int index = _nodes.at(desc->node()->in(0)->_idx)->block_index(); 1.864 - desc->set_block_index(index); 1.865 - blocks->adr_at(index)->add_node(desc); 1.866 - 1.867 - // Put Projections to same block as parent 1.868 - } else if (desc->node()->is_block_proj() && _nodes.at(desc->node()->is_block_proj()->_idx)->block_index() != -1) { 1.869 - int index = _nodes.at(desc->node()->is_block_proj()->_idx)->block_index(); 1.870 - desc->set_block_index(index); 1.871 - blocks->adr_at(index)->add_node(desc); 1.872 - } else { 1.873 - queue[queue_end] = desc; 1.874 - queue_end++; 1.875 - on_queue.set(desc->node()->_idx); 1.876 - } 1.877 - } 1.878 - } 1.879 - 1.880 - 1.881 - int z = 0; 1.882 - while(queue_start != queue_end && z < 10000) { 1.883 - 1.884 - NodeDescription *desc = queue[queue_start]; 1.885 - queue_start = (queue_start + 1) % queue_size; 1.886 - on_queue >>= desc->node()->_idx; 1.887 - 1.888 - Node* node = desc->node(); 1.889 - 1.890 - if (desc->succs()->length() == 0) { 1.891 - int x = 0; 1.892 - } 1.893 - 1.894 - int block_index = -1; 1.895 - if (desc->succs()->length() != 0) { 1.896 - for (int i = 0; i < desc->succs()->length(); i++) { 1.897 - NodeDescription *cur_desc = desc->succs()->at(i); 1.898 - if (cur_desc != desc) { 1.899 - if (cur_desc->succs()->length() == 0) { 1.900 - 1.901 - // Ignore nodes with 0 successors 1.902 - 1.903 - } else if (cur_desc->block_index() == -1) { 1.904 - 1.905 - // Let this node schedule first 1.906 - block_index = -1; 1.907 - break; 1.908 - 1.909 - } else if (cur_desc->node()->is_Phi()){ 1.910 - 1.911 - // Special treatment for Phi functions 1.912 - PhiNode *phi = cur_desc->node()->as_Phi(); 1.913 - assert(phi->in(0) && phi->in(0)->is_Region(), "Must have region node in first input"); 1.914 - RegionNode *region = phi->in(0)->as_Region(); 1.915 - 1.916 - for (uint j=1; j<phi->len(); j++) { 1.917 - Node *cur_phi_input = phi->in(j); 1.918 - if (cur_phi_input == desc->node() && region->in(j)) { 1.919 - NodeDescription *cur_region_input = _nodes.at(region->in(j)->_idx); 1.920 - if (cur_region_input->block_index() == -1) { 1.921 - 1.922 - // Let this node schedule first 1.923 - block_index = -1; 1.924 - break; 1.925 - } else { 1.926 - if (block_index == -1) { 1.927 - block_index = cur_region_input->block_index(); 1.928 - } else { 1.929 - block_index = common_dominator[block_index][cur_region_input->block_index()]; 1.930 - } 1.931 - } 1.932 - } 1.933 - } 1.934 - 1.935 - } else { 1.936 - if (block_index == -1) { 1.937 - block_index = cur_desc->block_index(); 1.938 - } else { 1.939 - block_index = common_dominator[block_index][cur_desc->block_index()]; 1.940 - } 1.941 - } 1.942 - } 1.943 - } 1.944 - } 1.945 - 1.946 - if (block_index == -1) { 1.947 - queue[queue_end] = desc; 1.948 - queue_end = (queue_end + 1) % queue_size; 1.949 - on_queue.set(desc->node()->_idx); 1.950 - z++; 1.951 - } else { 1.952 - assert(desc->block_index() == -1, ""); 1.953 - desc->set_block_index(block_index); 1.954 - blocks->adr_at(block_index)->add_node(desc); 1.955 - z = 0; 1.956 - } 1.957 - } 1.958 - 1.959 - for (int i = 0; i < _nodes.length(); i++) { 1.960 - NodeDescription *desc = _nodes.at(i); 1.961 - if (desc && desc->block_index() == -1) { 1.962 - 1.963 - //if (desc->node()->is_Proj() || desc->node()->is_Con()) { 1.964 - Node *parent = desc->node()->in(0); 1.965 - uint cur = 1; 1.966 - while(!parent && cur < desc->node()->len()) { 1.967 - parent = desc->node()->in(cur); 1.968 - cur++; 1.969 - } 1.970 - 1.971 - if (parent && _nodes.at(parent->_idx)->block_index() != -1) { 1.972 - int index = _nodes.at(parent->_idx)->block_index(); 1.973 - desc->set_block_index(index); 1.974 - blocks->adr_at(index)->add_node(desc); 1.975 - } else { 1.976 - desc->set_block_index(0); 1.977 - blocks->adr_at(0)->add_node(desc); 1.978 - //ShouldNotReachHere(); 1.979 - } 1.980 - //} 1.981 - /* 1.982 - if (desc->node()->is_block_proj() && _nodes.at(desc->node()->is_block_proj()->_idx)->block_index() != -1) { 1.983 - int index = _nodes.at(desc->node()->is_block_proj()->_idx)->block_index(); 1.984 - desc->set_block_index(index); 1.985 - blocks->adr_at(index)->add_node(desc); 1.986 - } */ 1.987 - } 1.988 - } 1.989 - 1.990 - for (int i = 0; i < _nodes.length(); i++) { 1.991 - NodeDescription *desc = _nodes.at(i); 1.992 - if (desc) { 1.993 - desc->clear_succs(); 1.994 - } 1.995 - } 1.996 - 1.997 - for (int i = 0; i < _nodes.length(); i++) { 1.998 - NodeDescription *desc = _nodes.at(i); 1.999 - if (desc) { 1.1000 - int block_index = desc->block_index(); 1.1001 - 1.1002 - assert(block_index >= 0 && block_index < blocks->length(), "Block index must be in range"); 1.1003 - assert(blocks->adr_at(block_index)->nodes()->contains(desc), "Node must be child of block"); 1.1004 - } 1.1005 - } 1.1006 - a->destruct_contents(); 1.1007 -} 1.1008 - 1.1009 -void IdealGraphPrinter::build_blocks(Node *root) { 1.1010 - 1.1011 - Arena *a = new Arena(); 1.1012 - Node_Stack stack(a, 100); 1.1013 - 1.1014 - VectorSet visited(a); 1.1015 - stack.push(root, 0); 1.1016 - GrowableArray<Block> blocks(a, 2, 0, Block(0)); 1.1017 - 1.1018 - for (int i = 0; i < _nodes.length(); i++) { 1.1019 - if (_nodes.at(i)) _nodes.at(i)->set_block_index(-1); 1.1020 - } 1.1021 - 1.1022 - 1.1023 - // Order nodes such that node index is equal to idx 1.1024 - for (int i = 0; i < _nodes.length(); i++) { 1.1025 - 1.1026 - if (_nodes.at(i)) { 1.1027 - NodeDescription *node = _nodes.at(i); 1.1028 - int index = node->node()->_idx; 1.1029 - if (index != i) { 1.1030 - _nodes.at_grow(index); 1.1031 - NodeDescription *tmp = _nodes.at(index); 1.1032 - *(_nodes.adr_at(index)) = node; 1.1033 - *(_nodes.adr_at(i)) = tmp; 1.1034 - i--; 1.1035 - } 1.1036 - } 1.1037 - } 1.1038 - 1.1039 - for (int i = 0; i < _nodes.length(); i++) { 1.1040 - NodeDescription *node = _nodes.at(i); 1.1041 - if (node) { 1.1042 - assert(node->node()->_idx == (uint)i, ""); 1.1043 - } 1.1044 - } 1.1045 - 1.1046 - while(stack.is_nonempty()) { 1.1047 - 1.1048 - //Node *n = stack.node(); 1.1049 - //int index = stack.index(); 1.1050 - Node *proj = stack.node();//n->in(index); 1.1051 - const Node *parent = proj->is_block_proj(); 1.1052 - if (parent == NULL) { 1.1053 - parent = proj; 1.1054 - } 1.1055 - 1.1056 - if (!visited.test_set(parent->_idx)) { 1.1057 - 1.1058 - NodeDescription *end_desc = _nodes.at(parent->_idx); 1.1059 - int block_index = blocks.length(); 1.1060 - Block block(block_index); 1.1061 - blocks.append(block); 1.1062 - Block *b = blocks.adr_at(block_index); 1.1063 - b->set_start(end_desc); 1.1064 - // assert(end_desc->block_index() == -1, ""); 1.1065 - end_desc->set_block_index(block_index); 1.1066 - b->add_node(end_desc); 1.1067 - 1.1068 - // Skip any control-pinned middle'in stuff 1.1069 - Node *p = proj; 1.1070 - NodeDescription *start_desc = NULL; 1.1071 - do { 1.1072 - proj = p; // Update pointer to last Control 1.1073 - if (p->in(0) == NULL) { 1.1074 - start_desc = end_desc; 1.1075 - break; 1.1076 - } 1.1077 - p = p->in(0); // Move control forward 1.1078 - start_desc = _nodes.at(p->_idx); 1.1079 - assert(start_desc, ""); 1.1080 - 1.1081 - if (start_desc != end_desc && start_desc->block_index() == -1) { 1.1082 - assert(start_desc->block_index() == -1, ""); 1.1083 - assert(block_index < blocks.length(), ""); 1.1084 - start_desc->set_block_index(block_index); 1.1085 - b->add_node(start_desc); 1.1086 - } 1.1087 - } while( !p->is_block_proj() && 1.1088 - !p->is_block_start() ); 1.1089 - 1.1090 - for (uint i = 0; i < start_desc->node()->len(); i++) { 1.1091 - 1.1092 - Node *pred_node = start_desc->node()->in(i); 1.1093 - 1.1094 - 1.1095 - if (pred_node && pred_node != start_desc->node()) { 1.1096 - const Node *cur_parent = pred_node->is_block_proj(); 1.1097 - if (cur_parent != NULL) { 1.1098 - pred_node = (Node *)cur_parent; 1.1099 - } 1.1100 - 1.1101 - NodeDescription *pred_node_desc = _nodes.at(pred_node->_idx); 1.1102 - if (pred_node_desc->block_index() != -1) { 1.1103 - blocks.adr_at(pred_node_desc->block_index())->add_succ(block_index); 1.1104 - } 1.1105 - } 1.1106 - } 1.1107 - 1.1108 - for (DUIterator_Fast dmax, i = end_desc->node()->fast_outs(dmax); i < dmax; i++) { 1.1109 - Node* cur_succ = end_desc->node()->fast_out(i); 1.1110 - NodeDescription *cur_succ_desc = _nodes.at(cur_succ->_idx); 1.1111 - 1.1112 - DUIterator_Fast dmax2, i2 = cur_succ->fast_outs(dmax2); 1.1113 - if (cur_succ->is_block_proj() && i2 < dmax2 && !cur_succ->is_Root()) { 1.1114 - 1.1115 - for (; i2<dmax2; i2++) { 1.1116 - Node *cur_succ2 = cur_succ->fast_out(i2); 1.1117 - if (cur_succ2) { 1.1118 - cur_succ_desc = _nodes.at(cur_succ2->_idx); 1.1119 - if (cur_succ_desc == NULL) { 1.1120 - // dead node so skip it 1.1121 - continue; 1.1122 - } 1.1123 - if (cur_succ2 != end_desc->node() && cur_succ_desc->block_index() != -1) { 1.1124 - b->add_succ(cur_succ_desc->block_index()); 1.1125 - } 1.1126 - } 1.1127 - } 1.1128 - 1.1129 - } else { 1.1130 - 1.1131 - if (cur_succ != end_desc->node() && cur_succ_desc && cur_succ_desc->block_index() != -1) { 1.1132 - b->add_succ(cur_succ_desc->block_index()); 1.1133 - } 1.1134 - } 1.1135 - } 1.1136 - 1.1137 - 1.1138 - int num_preds = p->len(); 1.1139 - int bottom = -1; 1.1140 - if (p->is_Region() || p->is_Phi()) { 1.1141 - bottom = 0; 1.1142 - } 1.1143 - 1.1144 - int pushed = 0; 1.1145 - for (int i=num_preds - 1; i > bottom; i--) { 1.1146 - if (p->in(i) != NULL && p->in(i) != p) { 1.1147 - stack.push(p->in(i), 0); 1.1148 - pushed++; 1.1149 - } 1.1150 - } 1.1151 - 1.1152 - if (pushed == 0 && p->is_Root() && !_matcher) { 1.1153 - // Special case when backedges to root are not yet built 1.1154 - for (int i = 0; i < _nodes.length(); i++) { 1.1155 - if (_nodes.at(i) && _nodes.at(i)->node()->is_SafePoint() && _nodes.at(i)->node()->outcnt() == 0) { 1.1156 - stack.push(_nodes.at(i)->node(), 0); 1.1157 - } 1.1158 - } 1.1159 - } 1.1160 - 1.1161 - } else { 1.1162 - stack.pop(); 1.1163 - } 1.1164 - } 1.1165 - 1.1166 - build_dominators(&blocks); 1.1167 - 1.1168 - int **common_dominator = NEW_RESOURCE_ARRAY(int *, blocks.length()); 1.1169 - for (int i = 0; i < blocks.length(); i++) { 1.1170 - int *cur = NEW_RESOURCE_ARRAY(int, blocks.length()); 1.1171 - common_dominator[i] = cur; 1.1172 - 1.1173 - for (int j=0; j<blocks.length(); j++) { 1.1174 - cur[j] = 0; 1.1175 - } 1.1176 - } 1.1177 - 1.1178 - for (int i = 0; i < blocks.length(); i++) { 1.1179 - blocks.adr_at(i)->add_child(blocks.adr_at(i)->index()); 1.1180 - } 1.1181 - build_common_dominator(common_dominator, 0, &blocks); 1.1182 - 1.1183 - schedule_latest(common_dominator, &blocks); 1.1184 - 1.1185 - start_element(CONTROL_FLOW_ELEMENT); 1.1186 - 1.1187 - for (int i = 0; i < blocks.length(); i++) { 1.1188 - Block *block = blocks.adr_at(i); 1.1189 - 1.1190 - Properties props; 1.1191 - props.add(new Property(BLOCK_NAME_PROPERTY, i)); 1.1192 - props.add(new Property(BLOCK_DOMINATOR_PROPERTY, block->dominator())); 1.1193 - start_element(BLOCK_ELEMENT, &props); 1.1194 - 1.1195 - if (block->succs()->length() > 0) { 1.1196 - start_element(SUCCESSORS_ELEMENT); 1.1197 - for (int j=0; j<block->succs()->length(); j++) { 1.1198 - int cur_index = block->succs()->at(j); 1.1199 - if (cur_index != 0 /* start_block has must not have inputs */) { 1.1200 - Properties properties; 1.1201 - properties.add(new Property(BLOCK_NAME_PROPERTY, cur_index)); 1.1202 - simple_element(SUCCESSOR_ELEMENT, &properties); 1.1203 - } 1.1204 - } 1.1205 - end_element(SUCCESSORS_ELEMENT); 1.1206 - } 1.1207 - 1.1208 - start_element(NODES_ELEMENT); 1.1209 - 1.1210 - for (int j=0; j<block->nodes()->length(); j++) { 1.1211 - NodeDescription *n = block->nodes()->at(j); 1.1212 - Properties properties; 1.1213 - properties.add(new Property(NODE_ID_PROPERTY, n->id())); 1.1214 - simple_element(NODE_ELEMENT, &properties); 1.1215 - } 1.1216 - 1.1217 - end_element(NODES_ELEMENT); 1.1218 - 1.1219 - end_element(BLOCK_ELEMENT); 1.1220 - } 1.1221 - 1.1222 - 1.1223 - end_element(CONTROL_FLOW_ELEMENT); 1.1224 - 1.1225 - a->destruct_contents(); 1.1226 -} 1.1227 - 1.1228 void IdealGraphPrinter::print_method(Compile* compile, const char *name, int level, bool clear_nodes) { 1.1229 print(compile, name, (Node *)compile->root(), level, clear_nodes); 1.1230 } 1.1231 @@ -1048,872 +652,53 @@ 1.1232 // Print current ideal graph 1.1233 void IdealGraphPrinter::print(Compile* compile, const char *name, Node *node, int level, bool clear_nodes) { 1.1234 1.1235 -// if (finish && !in_method) return; 1.1236 if (!_current_method || !_should_send_method || level > PrintIdealGraphLevel) return; 1.1237 1.1238 - assert(_current_method, "newMethod has to be called first!"); 1.1239 - 1.1240 - if (clear_nodes) { 1.1241 - int x = 0; 1.1242 - } 1.1243 - 1.1244 - _clear_nodes = clear_nodes; 1.1245 + this->C = compile; 1.1246 1.1247 // Warning, unsafe cast? 1.1248 - _chaitin = (PhaseChaitin *)compile->regalloc(); 1.1249 - _matcher = compile->matcher(); 1.1250 + _chaitin = (PhaseChaitin *)C->regalloc(); 1.1251 1.1252 + begin_head(GRAPH_ELEMENT); 1.1253 + print_attr(GRAPH_NAME_PROPERTY, (const char *)name); 1.1254 + end_head(); 1.1255 1.1256 - // Update nodes 1.1257 - for (int i = 0; i < _nodes.length(); i++) { 1.1258 - NodeDescription *desc = _nodes.at(i); 1.1259 - if (desc) { 1.1260 - desc->set_state(Invalid); 1.1261 + head(NODES_ELEMENT); 1.1262 + walk_nodes(node, NULL); 1.1263 + tail(NODES_ELEMENT); 1.1264 + 1.1265 + head(EDGES_ELEMENT); 1.1266 + walk_nodes(node, (void *)1); 1.1267 + tail(EDGES_ELEMENT); 1.1268 + if (C->cfg() != NULL) { 1.1269 + head(CONTROL_FLOW_ELEMENT); 1.1270 + for (uint i = 0; i < C->cfg()->_blocks.size(); i++) { 1.1271 + Block *b = C->cfg()->_blocks[i]; 1.1272 + begin_head(BLOCK_ELEMENT); 1.1273 + print_attr(BLOCK_NAME_PROPERTY, b->_pre_order); 1.1274 + end_head(); 1.1275 + 1.1276 + head(SUCCESSORS_ELEMENT); 1.1277 + for (uint s = 0; s < C->cfg()->_blocks[i]->_num_succs; s++) { 1.1278 + begin_elem(SUCCESSOR_ELEMENT); 1.1279 + print_attr(BLOCK_NAME_PROPERTY, b->_succs[s]->_pre_order); 1.1280 + end_elem(); 1.1281 + } 1.1282 + tail(SUCCESSORS_ELEMENT); 1.1283 + 1.1284 + tail(BLOCK_ELEMENT); 1.1285 } 1.1286 + 1.1287 + tail(CONTROL_FLOW_ELEMENT); 1.1288 } 1.1289 - Node *n = node; 1.1290 - walk(n); 1.1291 - 1.1292 - // Update edges 1.1293 - for (int i = 0; i < _edges.length(); i++) { 1.1294 - _edges.at(i)->set_state(Invalid); 1.1295 - } 1.1296 - 1.1297 - for (int i = 0; i < _nodes.length(); i++) { 1.1298 - NodeDescription *desc = _nodes.at(i); 1.1299 - if (desc && desc->state() != Invalid) { 1.1300 - 1.1301 - int to = desc->id(); 1.1302 - uint len = desc->node()->len(); 1.1303 - for (uint j=0; j<len; j++) { 1.1304 - Node *n = desc->node()->in(j); 1.1305 - 1.1306 - if (n) { 1.1307 - 1.1308 - 1.1309 - intptr_t from = (intptr_t)n; 1.1310 - 1.1311 - // Assert from node is valid 1.1312 - /* 1.1313 - bool ok = false; 1.1314 - for (int k=0; k<_nodes.length(); k++) { 1.1315 - NodeDescription *desc = _nodes.at(k); 1.1316 - if (desc && desc->id() == from) { 1.1317 - assert(desc->state() != Invalid, ""); 1.1318 - ok = true; 1.1319 - } 1.1320 - } 1.1321 - assert(ok, "");*/ 1.1322 - 1.1323 - uint index = j; 1.1324 - if (index >= desc->node()->req()) { 1.1325 - index = desc->node()->req(); 1.1326 - } 1.1327 - 1.1328 - print_edge(from, to, index); 1.1329 - } 1.1330 - } 1.1331 - } 1.1332 - } 1.1333 - 1.1334 - bool is_different = false; 1.1335 - 1.1336 - for (int i = 0; i < _nodes.length(); i++) { 1.1337 - NodeDescription *desc = _nodes.at(i); 1.1338 - if (desc && desc->state() != Valid) { 1.1339 - is_different = true; 1.1340 - break; 1.1341 - } 1.1342 - } 1.1343 - 1.1344 - if (!is_different) { 1.1345 - for (int i = 0; i < _edges.length(); i++) { 1.1346 - EdgeDescription *conn = _edges.at(i); 1.1347 - if (conn && conn->state() != Valid) { 1.1348 - is_different = true; 1.1349 - break; 1.1350 - } 1.1351 - } 1.1352 - } 1.1353 - 1.1354 - // No changes -> do not print graph 1.1355 - if (!is_different) return; 1.1356 - 1.1357 - Properties properties; 1.1358 - properties.add(new Property(GRAPH_NAME_PROPERTY, (const char *)name)); 1.1359 - start_element(GRAPH_ELEMENT, &properties); 1.1360 - 1.1361 - start_element(NODES_ELEMENT); 1.1362 - for (int i = 0; i < _nodes.length(); i++) { 1.1363 - NodeDescription *desc = _nodes.at(i); 1.1364 - if (desc) { 1.1365 - desc->print(this); 1.1366 - if (desc->state() == Invalid) { 1.1367 - delete desc; 1.1368 - _nodes.at_put(i, NULL); 1.1369 - } else { 1.1370 - desc->set_state(Valid); 1.1371 - } 1.1372 - } 1.1373 - } 1.1374 - end_element(NODES_ELEMENT); 1.1375 - 1.1376 - build_blocks(node); 1.1377 - 1.1378 - start_element(EDGES_ELEMENT); 1.1379 - for (int i = 0; i < _edges.length(); i++) { 1.1380 - EdgeDescription *conn = _edges.at(i); 1.1381 - 1.1382 - // Assert from and to nodes are valid 1.1383 - /* 1.1384 - if (!conn->state() == Invalid) { 1.1385 - bool ok1 = false; 1.1386 - bool ok2 = false; 1.1387 - for (int j=0; j<_nodes.length(); j++) { 1.1388 - NodeDescription *desc = _nodes.at(j); 1.1389 - if (desc && desc->id() == conn->from()) { 1.1390 - ok1 = true; 1.1391 - } 1.1392 - 1.1393 - if (desc && desc->id() == conn->to()) { 1.1394 - ok2 = true; 1.1395 - } 1.1396 - } 1.1397 - 1.1398 - assert(ok1, "from node not found!"); 1.1399 - assert(ok2, "to node not found!"); 1.1400 - }*/ 1.1401 - 1.1402 - conn->print(this); 1.1403 - if (conn->state() == Invalid) { 1.1404 - _edges.remove_at(i); 1.1405 - delete conn; 1.1406 - i--; 1.1407 - } 1.1408 - } 1.1409 - 1.1410 - end_element(EDGES_ELEMENT); 1.1411 - 1.1412 - end_element(GRAPH_ELEMENT); 1.1413 - 1.1414 - _output->flush(); 1.1415 -} 1.1416 - 1.1417 -// Print edge 1.1418 -void IdealGraphPrinter::print_edge(int from, int to, int index) { 1.1419 - 1.1420 - EdgeDescription *conn = new EdgeDescription(from, to, index); 1.1421 - for (int i = 0; i < _edges.length(); i++) { 1.1422 - if (_edges.at(i)->equals(conn)) { 1.1423 - conn->set_state(Valid); 1.1424 - delete _edges.at(i); 1.1425 - _edges.at_put(i, conn); 1.1426 - return; 1.1427 - } 1.1428 - } 1.1429 - 1.1430 - _edges.append(conn); 1.1431 + tail(GRAPH_ELEMENT); 1.1432 + output()->flush(); 1.1433 } 1.1434 1.1435 extern const char *NodeClassNames[]; 1.1436 1.1437 -// Create node description 1.1438 -IdealGraphPrinter::NodeDescription *IdealGraphPrinter::create_node_description(Node* node) { 1.1439 - 1.1440 -#ifndef PRODUCT 1.1441 - node->_in_dump_cnt++; 1.1442 - NodeDescription *desc = new NodeDescription(node); 1.1443 - desc->properties()->add(new Property(NODE_NAME_PROPERTY, (const char *)node->Name())); 1.1444 - 1.1445 - const Type *t = node->bottom_type(); 1.1446 - desc->properties()->add(new Property("type", (const char *)Type::msg[t->base()])); 1.1447 - 1.1448 - desc->properties()->add(new Property("idx", node->_idx)); 1.1449 -#ifdef ASSERT 1.1450 - desc->properties()->add(new Property("debug_idx", node->_debug_idx)); 1.1451 -#endif 1.1452 - 1.1453 - 1.1454 - const jushort flags = node->flags(); 1.1455 - if (flags & Node::Flag_is_Copy) { 1.1456 - desc->properties()->add(new Property("is_copy", "true")); 1.1457 - } 1.1458 - if (flags & Node::Flag_is_Call) { 1.1459 - desc->properties()->add(new Property("is_call", "true")); 1.1460 - } 1.1461 - if (flags & Node::Flag_rematerialize) { 1.1462 - desc->properties()->add(new Property("rematerialize", "true")); 1.1463 - } 1.1464 - if (flags & Node::Flag_needs_anti_dependence_check) { 1.1465 - desc->properties()->add(new Property("needs_anti_dependence_check", "true")); 1.1466 - } 1.1467 - if (flags & Node::Flag_is_macro) { 1.1468 - desc->properties()->add(new Property("is_macro", "true")); 1.1469 - } 1.1470 - if (flags & Node::Flag_is_Con) { 1.1471 - desc->properties()->add(new Property("is_con", "true")); 1.1472 - } 1.1473 - if (flags & Node::Flag_is_cisc_alternate) { 1.1474 - desc->properties()->add(new Property("is_cisc_alternate", "true")); 1.1475 - } 1.1476 - if (flags & Node::Flag_is_Branch) { 1.1477 - desc->properties()->add(new Property("is_branch", "true")); 1.1478 - } 1.1479 - if (flags & Node::Flag_is_block_start) { 1.1480 - desc->properties()->add(new Property("is_block_start", "true")); 1.1481 - } 1.1482 - if (flags & Node::Flag_is_Goto) { 1.1483 - desc->properties()->add(new Property("is_goto", "true")); 1.1484 - } 1.1485 - if (flags & Node::Flag_is_dead_loop_safe) { 1.1486 - desc->properties()->add(new Property("is_dead_loop_safe", "true")); 1.1487 - } 1.1488 - if (flags & Node::Flag_may_be_short_branch) { 1.1489 - desc->properties()->add(new Property("may_be_short_branch", "true")); 1.1490 - } 1.1491 - if (flags & Node::Flag_is_safepoint_node) { 1.1492 - desc->properties()->add(new Property("is_safepoint_node", "true")); 1.1493 - } 1.1494 - if (flags & Node::Flag_is_pc_relative) { 1.1495 - desc->properties()->add(new Property("is_pc_relative", "true")); 1.1496 - } 1.1497 - 1.1498 - if (_matcher) { 1.1499 - if (_matcher->is_shared(desc->node())) { 1.1500 - desc->properties()->add(new Property("is_shared", "true")); 1.1501 - } else { 1.1502 - desc->properties()->add(new Property("is_shared", "false")); 1.1503 - } 1.1504 - 1.1505 - if (_matcher->is_dontcare(desc->node())) { 1.1506 - desc->properties()->add(new Property("is_dontcare", "true")); 1.1507 - } else { 1.1508 - desc->properties()->add(new Property("is_dontcare", "false")); 1.1509 - } 1.1510 - } 1.1511 - 1.1512 - if (node->is_Proj()) { 1.1513 - desc->properties()->add(new Property("con", (int)node->as_Proj()->_con)); 1.1514 - } 1.1515 - 1.1516 - if (node->is_Mach()) { 1.1517 - desc->properties()->add(new Property("idealOpcode", (const char *)NodeClassNames[node->as_Mach()->ideal_Opcode()])); 1.1518 - } 1.1519 - 1.1520 - 1.1521 - 1.1522 - 1.1523 - 1.1524 - outputStream *oldTty = tty; 1.1525 - buffer[0] = 0; 1.1526 - stringStream s2(buffer, sizeof(buffer) - 1); 1.1527 - 1.1528 - node->dump_spec(&s2); 1.1529 - assert(s2.size() < sizeof(buffer), "size in range"); 1.1530 - desc->properties()->add(new Property("dump_spec", buffer)); 1.1531 - 1.1532 - if (node->is_block_proj()) { 1.1533 - desc->properties()->add(new Property("is_block_proj", "true")); 1.1534 - } 1.1535 - 1.1536 - if (node->is_block_start()) { 1.1537 - desc->properties()->add(new Property("is_block_start", "true")); 1.1538 - } 1.1539 - 1.1540 - const char *short_name = "short_name"; 1.1541 - if (strcmp(node->Name(), "Parm") == 0 && node->as_Proj()->_con >= TypeFunc::Parms) { 1.1542 - int index = node->as_Proj()->_con - TypeFunc::Parms; 1.1543 - if (index >= 10) { 1.1544 - desc->properties()->add(new Property(short_name, "PA")); 1.1545 - } else { 1.1546 - sprintf(buffer, "P%d", index); 1.1547 - desc->properties()->add(new Property(short_name, buffer)); 1.1548 - } 1.1549 - } else if (strcmp(node->Name(), "IfTrue") == 0) { 1.1550 - desc->properties()->add(new Property(short_name, "T")); 1.1551 - } else if (strcmp(node->Name(), "IfFalse") == 0) { 1.1552 - desc->properties()->add(new Property(short_name, "F")); 1.1553 - } else if ((node->is_Con() && node->is_Type()) || node->is_Proj()) { 1.1554 - 1.1555 - if (t->base() == Type::Int && t->is_int()->is_con()) { 1.1556 - const TypeInt *typeInt = t->is_int(); 1.1557 - assert(typeInt->is_con(), "must be constant"); 1.1558 - jint value = typeInt->get_con(); 1.1559 - 1.1560 - // max. 2 chars allowed 1.1561 - if (value >= -9 && value <= 99) { 1.1562 - sprintf(buffer, "%d", value); 1.1563 - desc->properties()->add(new Property(short_name, buffer)); 1.1564 - } 1.1565 - else 1.1566 - { 1.1567 - desc->properties()->add(new Property(short_name, "I")); 1.1568 - } 1.1569 - } else if (t == Type::TOP) { 1.1570 - desc->properties()->add(new Property(short_name, "^")); 1.1571 - } else if (t->base() == Type::Long && t->is_long()->is_con()) { 1.1572 - const TypeLong *typeLong = t->is_long(); 1.1573 - assert(typeLong->is_con(), "must be constant"); 1.1574 - jlong value = typeLong->get_con(); 1.1575 - 1.1576 - // max. 2 chars allowed 1.1577 - if (value >= -9 && value <= 99) { 1.1578 - sprintf(buffer, "%d", value); 1.1579 - desc->properties()->add(new Property(short_name, buffer)); 1.1580 - } 1.1581 - else 1.1582 - { 1.1583 - desc->properties()->add(new Property(short_name, "L")); 1.1584 - } 1.1585 - } else if (t->base() == Type::KlassPtr) { 1.1586 - const TypeKlassPtr *typeKlass = t->is_klassptr(); 1.1587 - desc->properties()->add(new Property(short_name, "CP")); 1.1588 - } else if (t->base() == Type::Control) { 1.1589 - desc->properties()->add(new Property(short_name, "C")); 1.1590 - } else if (t->base() == Type::Memory) { 1.1591 - desc->properties()->add(new Property(short_name, "M")); 1.1592 - } else if (t->base() == Type::Abio) { 1.1593 - desc->properties()->add(new Property(short_name, "IO")); 1.1594 - } else if (t->base() == Type::Return_Address) { 1.1595 - desc->properties()->add(new Property(short_name, "RA")); 1.1596 - } else if (t->base() == Type::AnyPtr) { 1.1597 - desc->properties()->add(new Property(short_name, "P")); 1.1598 - } else if (t->base() == Type::RawPtr) { 1.1599 - desc->properties()->add(new Property(short_name, "RP")); 1.1600 - } else if (t->base() == Type::AryPtr) { 1.1601 - desc->properties()->add(new Property(short_name, "AP")); 1.1602 - } 1.1603 - } 1.1604 - 1.1605 - if (node->is_SafePoint()) { 1.1606 - SafePointNode *safePointNode = node->as_SafePoint(); 1.1607 - if (safePointNode->jvms()) { 1.1608 - stringStream bciStream; 1.1609 - bciStream.print("%d ", safePointNode->jvms()->bci()); 1.1610 - JVMState *caller = safePointNode->jvms()->caller(); 1.1611 - while(caller) { 1.1612 - bciStream.print("%d ", caller->bci()); 1.1613 - 1.1614 - caller = caller->caller(); 1.1615 - } 1.1616 - desc->properties()->add(new Property("bci", bciStream.as_string())); 1.1617 - } 1.1618 - } 1.1619 - 1.1620 - if (_chaitin && _chaitin != (PhaseChaitin *)0xdeadbeef) { 1.1621 - buffer[0] = 0; 1.1622 - _chaitin->dump_register(node, buffer); 1.1623 - desc->properties()->add(new Property("reg", buffer)); 1.1624 - desc->properties()->add(new Property("lrg", _chaitin->n2lidx(node))); 1.1625 - } 1.1626 - 1.1627 - 1.1628 - node->_in_dump_cnt--; 1.1629 - return desc; 1.1630 -#else 1.1631 - return NULL; 1.1632 -#endif 1.1633 -} 1.1634 - 1.1635 -void IdealGraphPrinter::pre_node(Node* node, void *env) { 1.1636 - 1.1637 - IdealGraphPrinter *printer = (IdealGraphPrinter *)env; 1.1638 - 1.1639 - NodeDescription *newDesc = printer->create_node_description(node); 1.1640 - 1.1641 - if (printer->_clear_nodes) { 1.1642 - 1.1643 - printer->_nodes.append(newDesc); 1.1644 - } else { 1.1645 - 1.1646 - NodeDescription *desc = printer->_nodes.at_grow(node->_idx, NULL); 1.1647 - 1.1648 - if (desc && desc->equals(newDesc)) { 1.1649 - //desc->set_state(Valid); 1.1650 - //desc->set_node(node); 1.1651 - delete desc; 1.1652 - printer->_nodes.at_put(node->_idx, NULL); 1.1653 - newDesc->set_state(Valid); 1.1654 - //printer->_nodes.at_put(node->_idx, newDesc); 1.1655 - } else { 1.1656 - 1.1657 - if (desc && desc->id() == newDesc->id()) { 1.1658 - delete desc; 1.1659 - printer->_nodes.at_put(node->_idx, NULL); 1.1660 - newDesc->set_state(New); 1.1661 - 1.1662 - } 1.1663 - 1.1664 - //if (desc) { 1.1665 - // delete desc; 1.1666 - //} 1.1667 - 1.1668 - //printer->_nodes.at_put(node->_idx, newDesc); 1.1669 - } 1.1670 - 1.1671 - printer->_nodes.append(newDesc); 1.1672 - } 1.1673 -} 1.1674 - 1.1675 -void IdealGraphPrinter::post_node(Node* node, void *env) { 1.1676 -} 1.1677 - 1.1678 outputStream *IdealGraphPrinter::output() { 1.1679 - return _output; 1.1680 -} 1.1681 - 1.1682 -IdealGraphPrinter::Description::Description() { 1.1683 - _state = New; 1.1684 -} 1.1685 - 1.1686 -void IdealGraphPrinter::Description::print(IdealGraphPrinter *printer) { 1.1687 - if (_state == Invalid) { 1.1688 - print_removed(printer); 1.1689 - } else if (_state == New) { 1.1690 - print_changed(printer); 1.1691 - } 1.1692 -} 1.1693 - 1.1694 -void IdealGraphPrinter::Description::set_state(State s) { 1.1695 - _state = s; 1.1696 -} 1.1697 - 1.1698 -IdealGraphPrinter::State IdealGraphPrinter::Description::state() { 1.1699 - return _state; 1.1700 -} 1.1701 - 1.1702 -void IdealGraphPrinter::Block::set_proj(NodeDescription *n) { 1.1703 - _proj = n; 1.1704 -} 1.1705 - 1.1706 -void IdealGraphPrinter::Block::set_start(NodeDescription *n) { 1.1707 - _start = n; 1.1708 -} 1.1709 - 1.1710 -int IdealGraphPrinter::Block::semi() { 1.1711 - return _semi; 1.1712 -} 1.1713 - 1.1714 -int IdealGraphPrinter::Block::parent() { 1.1715 - return _parent; 1.1716 -} 1.1717 - 1.1718 -GrowableArray<int>* IdealGraphPrinter::Block::bucket() { 1.1719 - return &_bucket; 1.1720 -} 1.1721 - 1.1722 -GrowableArray<int>* IdealGraphPrinter::Block::children() { 1.1723 - return &_children; 1.1724 -} 1.1725 - 1.1726 -void IdealGraphPrinter::Block::add_child(int i) { 1.1727 - _children.append(i); 1.1728 -} 1.1729 - 1.1730 -GrowableArray<int>* IdealGraphPrinter::Block::dominates() { 1.1731 - return &_dominates; 1.1732 -} 1.1733 - 1.1734 -void IdealGraphPrinter::Block::add_dominates(int i) { 1.1735 - _dominates.append(i); 1.1736 -} 1.1737 - 1.1738 -void IdealGraphPrinter::Block::add_to_bucket(int i) { 1.1739 - _bucket.append(i); 1.1740 -} 1.1741 - 1.1742 -void IdealGraphPrinter::Block::clear_bucket() { 1.1743 - _bucket.clear(); 1.1744 -} 1.1745 - 1.1746 -void IdealGraphPrinter::Block::set_dominator(int i) { 1.1747 - _dominator = i; 1.1748 -} 1.1749 - 1.1750 -void IdealGraphPrinter::Block::set_label(int i) { 1.1751 - _label = i; 1.1752 -} 1.1753 - 1.1754 -int IdealGraphPrinter::Block::label() { 1.1755 - return _label; 1.1756 -} 1.1757 - 1.1758 -int IdealGraphPrinter::Block::ancestor() { 1.1759 - return _ancestor; 1.1760 -} 1.1761 - 1.1762 -void IdealGraphPrinter::Block::set_ancestor(int i) { 1.1763 - _ancestor = i; 1.1764 -} 1.1765 - 1.1766 -int IdealGraphPrinter::Block::dominator() { 1.1767 - return _dominator; 1.1768 -} 1.1769 - 1.1770 -int IdealGraphPrinter::Block::index() { 1.1771 - return _index; 1.1772 -} 1.1773 - 1.1774 -void IdealGraphPrinter::Block::set_parent(int i) { 1.1775 - _parent = i; 1.1776 -} 1.1777 - 1.1778 -GrowableArray<int>* IdealGraphPrinter::Block::pred() { 1.1779 - return &_pred; 1.1780 -} 1.1781 - 1.1782 -void IdealGraphPrinter::Block::set_semi(int i) { 1.1783 - _semi = i; 1.1784 -} 1.1785 - 1.1786 -IdealGraphPrinter::Block::Block() { 1.1787 -} 1.1788 - 1.1789 -IdealGraphPrinter::Block::Block(int index) { 1.1790 - _index = index; 1.1791 - _label = index; 1.1792 - _semi = -1; 1.1793 - _ancestor = -1; 1.1794 - _dominator = -1; 1.1795 -} 1.1796 - 1.1797 -void IdealGraphPrinter::Block::add_pred(int i) { 1.1798 - _pred.append(i); 1.1799 -} 1.1800 - 1.1801 -IdealGraphPrinter::NodeDescription *IdealGraphPrinter::Block::proj() { 1.1802 - return _proj; 1.1803 -} 1.1804 - 1.1805 -IdealGraphPrinter::NodeDescription *IdealGraphPrinter::Block::start() { 1.1806 - return _start; 1.1807 -} 1.1808 - 1.1809 -GrowableArray<int>* IdealGraphPrinter::Block::succs() { 1.1810 - return &_succs; 1.1811 -} 1.1812 - 1.1813 -void IdealGraphPrinter::Block::add_succ(int index) { 1.1814 - 1.1815 - if (this->_index == 16 && index == 15) { 1.1816 - int x = 0; 1.1817 - } 1.1818 - 1.1819 - if (!_succs.contains(index)) { 1.1820 - _succs.append(index); 1.1821 - } 1.1822 -} 1.1823 - 1.1824 - 1.1825 -void IdealGraphPrinter::Block::add_node(NodeDescription *n) { 1.1826 - if (!_nodes.contains(n)) { 1.1827 - _nodes.append(n); 1.1828 - } 1.1829 -} 1.1830 - 1.1831 -GrowableArray<IdealGraphPrinter::NodeDescription *>* IdealGraphPrinter::Block::nodes() { 1.1832 - return &_nodes; 1.1833 -} 1.1834 - 1.1835 -int IdealGraphPrinter::NodeDescription::count = 0; 1.1836 - 1.1837 -IdealGraphPrinter::NodeDescription::NodeDescription(Node* node) : _node(node) { 1.1838 - _id = (intptr_t)(node); 1.1839 - _block_index = -1; 1.1840 -} 1.1841 - 1.1842 -IdealGraphPrinter::NodeDescription::~NodeDescription() { 1.1843 - _properties.clean(); 1.1844 -} 1.1845 - 1.1846 -// void IdealGraphPrinter::NodeDescription::set_node(Node* node) { 1.1847 -// //this->_node = node; 1.1848 -// } 1.1849 - 1.1850 -int IdealGraphPrinter::NodeDescription::block_index() { 1.1851 - return _block_index; 1.1852 -} 1.1853 - 1.1854 - 1.1855 -GrowableArray<IdealGraphPrinter::NodeDescription *>* IdealGraphPrinter::NodeDescription::succs() { 1.1856 - return &_succs; 1.1857 -} 1.1858 - 1.1859 -void IdealGraphPrinter::NodeDescription::clear_succs() { 1.1860 - _succs.clear(); 1.1861 -} 1.1862 - 1.1863 -void IdealGraphPrinter::NodeDescription::init_succs() { 1.1864 - _succs = GrowableArray<NodeDescription *>(); 1.1865 -} 1.1866 - 1.1867 -void IdealGraphPrinter::NodeDescription::add_succ(NodeDescription *desc) { 1.1868 - _succs.append(desc); 1.1869 -} 1.1870 - 1.1871 -void IdealGraphPrinter::NodeDescription::set_block_index(int i) { 1.1872 - _block_index = i; 1.1873 -} 1.1874 - 1.1875 -bool IdealGraphPrinter::NodeDescription::equals(NodeDescription *desc) { 1.1876 - if (desc == NULL) return false; 1.1877 - if (desc->id() != id()) return false; 1.1878 - return properties()->equals(desc->properties()); 1.1879 -} 1.1880 - 1.1881 -Node* IdealGraphPrinter::NodeDescription::node() { 1.1882 - return _node; 1.1883 -} 1.1884 - 1.1885 -IdealGraphPrinter::Properties* IdealGraphPrinter::NodeDescription::properties() { 1.1886 - return &_properties; 1.1887 -} 1.1888 - 1.1889 -uint IdealGraphPrinter::NodeDescription::id() { 1.1890 - return _id; 1.1891 -} 1.1892 - 1.1893 -void IdealGraphPrinter::NodeDescription::print_changed(IdealGraphPrinter *printer) { 1.1894 - 1.1895 - 1.1896 - Properties properties; 1.1897 - properties.add(new Property(NODE_ID_PROPERTY, id())); 1.1898 - printer->start_element(NODE_ELEMENT, &properties); 1.1899 - 1.1900 - this->properties()->print(printer); 1.1901 - 1.1902 - 1.1903 - printer->end_element(NODE_ELEMENT); 1.1904 -} 1.1905 - 1.1906 -void IdealGraphPrinter::NodeDescription::print_removed(IdealGraphPrinter *printer) { 1.1907 - 1.1908 - Properties properties; 1.1909 - properties.add(new Property(NODE_ID_PROPERTY, id())); 1.1910 - printer->simple_element(REMOVE_NODE_ELEMENT, &properties); 1.1911 -} 1.1912 - 1.1913 -IdealGraphPrinter::EdgeDescription::EdgeDescription(int from, int to, int index) { 1.1914 - this->_from = from; 1.1915 - this->_to = to; 1.1916 - this->_index = index; 1.1917 -} 1.1918 - 1.1919 -IdealGraphPrinter::EdgeDescription::~EdgeDescription() { 1.1920 -} 1.1921 - 1.1922 -int IdealGraphPrinter::EdgeDescription::from() { 1.1923 - return _from; 1.1924 -} 1.1925 - 1.1926 -int IdealGraphPrinter::EdgeDescription::to() { 1.1927 - return _to; 1.1928 -} 1.1929 - 1.1930 -void IdealGraphPrinter::EdgeDescription::print_changed(IdealGraphPrinter *printer) { 1.1931 - 1.1932 - Properties properties; 1.1933 - properties.add(new Property(INDEX_PROPERTY, _index)); 1.1934 - properties.add(new Property(FROM_PROPERTY, _from)); 1.1935 - properties.add(new Property(TO_PROPERTY, _to)); 1.1936 - printer->simple_element(EDGE_ELEMENT, &properties); 1.1937 -} 1.1938 - 1.1939 -void IdealGraphPrinter::EdgeDescription::print_removed(IdealGraphPrinter *printer) { 1.1940 - 1.1941 - Properties properties; 1.1942 - properties.add(new Property(INDEX_PROPERTY, _index)); 1.1943 - properties.add(new Property(FROM_PROPERTY, _from)); 1.1944 - properties.add(new Property(TO_PROPERTY, _to)); 1.1945 - printer->simple_element(REMOVE_EDGE_ELEMENT, &properties); 1.1946 -} 1.1947 - 1.1948 -bool IdealGraphPrinter::EdgeDescription::equals(IdealGraphPrinter::EdgeDescription *desc) { 1.1949 - if (desc == NULL) return false; 1.1950 - return (_from == desc->_from && _to == desc->_to && _index == desc->_index); 1.1951 -} 1.1952 - 1.1953 -IdealGraphPrinter::Properties::Properties() : list(new (ResourceObj::C_HEAP) GrowableArray<Property *>(2, 0, NULL, true)) { 1.1954 -} 1.1955 - 1.1956 -IdealGraphPrinter::Properties::~Properties() { 1.1957 - clean(); 1.1958 - delete list; 1.1959 -} 1.1960 - 1.1961 -void IdealGraphPrinter::Properties::add(Property *p) { 1.1962 - assert(p != NULL, "Property not NULL"); 1.1963 - list->append(p); 1.1964 -} 1.1965 - 1.1966 -void IdealGraphPrinter::Properties::print(IdealGraphPrinter *printer) { 1.1967 - printer->start_element(PROPERTIES_ELEMENT); 1.1968 - 1.1969 - for (int i = 0; i < list->length(); i++) { 1.1970 - list->at(i)->print(printer); 1.1971 - } 1.1972 - 1.1973 - printer->end_element(PROPERTIES_ELEMENT); 1.1974 -} 1.1975 - 1.1976 -void IdealGraphPrinter::Properties::clean() { 1.1977 - for (int i = 0; i < list->length(); i++) { 1.1978 - delete list->at(i); 1.1979 - list->at_put(i, NULL); 1.1980 - } 1.1981 - list->clear(); 1.1982 - assert(list->length() == 0, "List cleared"); 1.1983 -} 1.1984 - 1.1985 -void IdealGraphPrinter::Properties::remove(const char *name) { 1.1986 - for (int i = 0; i < list->length(); i++) { 1.1987 - if (strcmp(list->at(i)->name(), name) == 0) { 1.1988 - delete list->at(i); 1.1989 - list->remove_at(i); 1.1990 - i--; 1.1991 - } 1.1992 - } 1.1993 -} 1.1994 - 1.1995 -void IdealGraphPrinter::Properties::print_as_attributes(IdealGraphPrinter *printer) { 1.1996 - 1.1997 - for (int i = 0; i < list->length(); i++) { 1.1998 - assert(list->at(i) != NULL, "Property not null!"); 1.1999 - printer->output()->print(" "); 1.2000 - list->at(i)->print_as_attribute(printer); 1.2001 - } 1.2002 -} 1.2003 - 1.2004 -bool IdealGraphPrinter::Properties::equals(Properties* p) { 1.2005 - if (p->list->length() != this->list->length()) return false; 1.2006 - 1.2007 - for (int i = 0; i < list->length(); i++) { 1.2008 - assert(list->at(i) != NULL, "Property not null!"); 1.2009 - if (!list->at(i)->equals(p->list->at(i))) return false; 1.2010 - } 1.2011 - 1.2012 - return true; 1.2013 -} 1.2014 - 1.2015 -IdealGraphPrinter::Property::Property() { 1.2016 - _name = NULL; 1.2017 - _value = NULL; 1.2018 -} 1.2019 - 1.2020 -const char *IdealGraphPrinter::Property::name() { 1.2021 - return _name; 1.2022 -} 1.2023 - 1.2024 -IdealGraphPrinter::Property::Property(const Property* p) { 1.2025 - 1.2026 - this->_name = NULL; 1.2027 - this->_value = NULL; 1.2028 - 1.2029 - if (p->_name != NULL) { 1.2030 - _name = dup(p->_name); 1.2031 - } 1.2032 - 1.2033 - if (p->_value) { 1.2034 - _value = dup(p->_value); 1.2035 - } 1.2036 -} 1.2037 - 1.2038 -IdealGraphPrinter::Property::~Property() { 1.2039 - 1.2040 - clean(); 1.2041 -} 1.2042 - 1.2043 -IdealGraphPrinter::Property::Property(const char *name, const char *value) { 1.2044 - 1.2045 - assert(name, "Name must not be null!"); 1.2046 - assert(value, "Value must not be null!"); 1.2047 - 1.2048 - _name = dup(name); 1.2049 - _value = dup(value); 1.2050 -} 1.2051 - 1.2052 -IdealGraphPrinter::Property::Property(const char *name, int intValue) { 1.2053 - _name = dup(name); 1.2054 - 1.2055 - stringStream stream; 1.2056 - stream.print("%d", intValue); 1.2057 - _value = dup(stream.as_string()); 1.2058 -} 1.2059 - 1.2060 -void IdealGraphPrinter::Property::clean() { 1.2061 - if (_name) { 1.2062 - delete _name; 1.2063 - _name = NULL; 1.2064 - } 1.2065 - 1.2066 - if (_value) { 1.2067 - delete _value; 1.2068 - _value = NULL; 1.2069 - } 1.2070 -} 1.2071 - 1.2072 - 1.2073 -bool IdealGraphPrinter::Property::is_null() { 1.2074 - return _name == NULL; 1.2075 -} 1.2076 - 1.2077 -void IdealGraphPrinter::Property::print(IdealGraphPrinter *printer) { 1.2078 - 1.2079 - assert(!is_null(), "null properties cannot be printed!"); 1.2080 - Properties properties; 1.2081 - properties.add(new Property(PROPERTY_NAME_PROPERTY, _name)); 1.2082 - printer->start_element(PROPERTY_ELEMENT, &properties, false, false); 1.2083 - printer->print_xml(_value); 1.2084 - printer->end_element(PROPERTY_ELEMENT, false, true); 1.2085 -} 1.2086 - 1.2087 -void IdealGraphPrinter::Property::print_as_attribute(IdealGraphPrinter *printer) { 1.2088 - 1.2089 - printer->output()->print(_name); 1.2090 - printer->output()->print("=\""); 1.2091 - printer->print_xml(_value); 1.2092 - printer->output()->print("\""); 1.2093 -} 1.2094 - 1.2095 - 1.2096 -bool IdealGraphPrinter::Property::equals(Property* p) { 1.2097 - 1.2098 - if (is_null() && p->is_null()) return true; 1.2099 - if (is_null()) return false; 1.2100 - if (p->is_null()) return false; 1.2101 - 1.2102 - int cmp1 = strcmp(p->_name, _name); 1.2103 - if (cmp1 != 0) return false; 1.2104 - 1.2105 - int cmp2 = strcmp(p->_value, _value); 1.2106 - if (cmp2 != 0) return false; 1.2107 - 1.2108 - return true; 1.2109 -} 1.2110 - 1.2111 -void IdealGraphPrinter::print_xml(const char *value) { 1.2112 - size_t len = strlen(value); 1.2113 - 1.2114 - char buf[2]; 1.2115 - buf[1] = 0; 1.2116 - for (size_t i = 0; i < len; i++) { 1.2117 - char c = value[i]; 1.2118 - 1.2119 - switch(c) { 1.2120 - case '<': 1.2121 - output()->print("<"); 1.2122 - break; 1.2123 - 1.2124 - case '>': 1.2125 - output()->print(">"); 1.2126 - break; 1.2127 - 1.2128 - default: 1.2129 - buf[0] = c; 1.2130 - output()->print(buf); 1.2131 - break; 1.2132 - } 1.2133 - } 1.2134 + return _xml; 1.2135 } 1.2136 1.2137 #endif