1.1 --- a/src/share/vm/opto/compile.cpp Tue Nov 27 12:48:52 2012 -0800 1.2 +++ b/src/share/vm/opto/compile.cpp Tue Nov 27 17:24:15 2012 -0800 1.3 @@ -316,7 +316,12 @@ 1.4 } 1.5 1.6 1.7 - 1.8 +static inline bool not_a_node(const Node* n) { 1.9 + if (n == NULL) return true; 1.10 + if (((intptr_t)n & 1) != 0) return true; // uninitialized, etc. 1.11 + if (*(address*)n == badAddress) return true; // kill by Node::destruct 1.12 + return false; 1.13 +} 1.14 1.15 // Identify all nodes that are reachable from below, useful. 1.16 // Use breadth-first pass that records state in a Unique_Node_List, 1.17 @@ -337,12 +342,27 @@ 1.18 uint max = n->len(); 1.19 for( uint i = 0; i < max; ++i ) { 1.20 Node *m = n->in(i); 1.21 - if( m == NULL ) continue; 1.22 + if (not_a_node(m)) continue; 1.23 useful.push(m); 1.24 } 1.25 } 1.26 } 1.27 1.28 +// Update dead_node_list with any missing dead nodes using useful 1.29 +// list. Consider all non-useful nodes to be useless i.e., dead nodes. 1.30 +void Compile::update_dead_node_list(Unique_Node_List &useful) { 1.31 + uint max_idx = unique(); 1.32 + VectorSet& useful_node_set = useful.member_set(); 1.33 + 1.34 + for (uint node_idx = 0; node_idx < max_idx; node_idx++) { 1.35 + // If node with index node_idx is not in useful set, 1.36 + // mark it as dead in dead node list. 1.37 + if (! useful_node_set.test(node_idx) ) { 1.38 + record_dead_node(node_idx); 1.39 + } 1.40 + } 1.41 +} 1.42 + 1.43 // Disconnect all useless nodes by disconnecting those at the boundary. 1.44 void Compile::remove_useless_nodes(Unique_Node_List &useful) { 1.45 uint next = 0; 1.46 @@ -582,6 +602,8 @@ 1.47 _inner_loops(0), 1.48 _scratch_const_size(-1), 1.49 _in_scratch_emit_size(false), 1.50 + _dead_node_list(comp_arena()), 1.51 + _dead_node_count(0), 1.52 #ifndef PRODUCT 1.53 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), 1.54 _printer(IdealGraphPrinter::printer()), 1.55 @@ -873,6 +895,8 @@ 1.56 _trace_opto_output(TraceOptoOutput), 1.57 _printer(NULL), 1.58 #endif 1.59 + _dead_node_list(comp_arena()), 1.60 + _dead_node_count(0), 1.61 _congraph(NULL) { 1.62 C = this; 1.63 1.64 @@ -1069,6 +1093,72 @@ 1.65 assert(_top == NULL || top()->is_top(), ""); 1.66 } 1.67 1.68 +#ifdef ASSERT 1.69 +uint Compile::count_live_nodes_by_graph_walk() { 1.70 + Unique_Node_List useful(comp_arena()); 1.71 + // Get useful node list by walking the graph. 1.72 + identify_useful_nodes(useful); 1.73 + return useful.size(); 1.74 +} 1.75 + 1.76 +void Compile::print_missing_nodes() { 1.77 + 1.78 + // Return if CompileLog is NULL and PrintIdealNodeCount is false. 1.79 + if ((_log == NULL) && (! PrintIdealNodeCount)) { 1.80 + return; 1.81 + } 1.82 + 1.83 + // This is an expensive function. It is executed only when the user 1.84 + // specifies VerifyIdealNodeCount option or otherwise knows the 1.85 + // additional work that needs to be done to identify reachable nodes 1.86 + // by walking the flow graph and find the missing ones using 1.87 + // _dead_node_list. 1.88 + 1.89 + Unique_Node_List useful(comp_arena()); 1.90 + // Get useful node list by walking the graph. 1.91 + identify_useful_nodes(useful); 1.92 + 1.93 + uint l_nodes = C->live_nodes(); 1.94 + uint l_nodes_by_walk = useful.size(); 1.95 + 1.96 + if (l_nodes != l_nodes_by_walk) { 1.97 + if (_log != NULL) { 1.98 + _log->begin_head("mismatched_nodes count='%d'", abs((int) (l_nodes - l_nodes_by_walk))); 1.99 + _log->stamp(); 1.100 + _log->end_head(); 1.101 + } 1.102 + VectorSet& useful_member_set = useful.member_set(); 1.103 + int last_idx = l_nodes_by_walk; 1.104 + for (int i = 0; i < last_idx; i++) { 1.105 + if (useful_member_set.test(i)) { 1.106 + if (_dead_node_list.test(i)) { 1.107 + if (_log != NULL) { 1.108 + _log->elem("mismatched_node_info node_idx='%d' type='both live and dead'", i); 1.109 + } 1.110 + if (PrintIdealNodeCount) { 1.111 + // Print the log message to tty 1.112 + tty->print_cr("mismatched_node idx='%d' both live and dead'", i); 1.113 + useful.at(i)->dump(); 1.114 + } 1.115 + } 1.116 + } 1.117 + else if (! _dead_node_list.test(i)) { 1.118 + if (_log != NULL) { 1.119 + _log->elem("mismatched_node_info node_idx='%d' type='neither live nor dead'", i); 1.120 + } 1.121 + if (PrintIdealNodeCount) { 1.122 + // Print the log message to tty 1.123 + tty->print_cr("mismatched_node idx='%d' type='neither live nor dead'", i); 1.124 + } 1.125 + } 1.126 + } 1.127 + if (_log != NULL) { 1.128 + _log->tail("mismatched_nodes"); 1.129 + } 1.130 + } 1.131 +} 1.132 +#endif 1.133 + 1.134 #ifndef PRODUCT 1.135 void Compile::verify_top(Node* tn) const { 1.136 if (tn != NULL) { 1.137 @@ -2087,7 +2177,7 @@ 1.138 1.139 // Eliminate trivially redundant StoreCMs and accumulate their 1.140 // precedence edges. 1.141 -static void eliminate_redundant_card_marks(Node* n) { 1.142 +void Compile::eliminate_redundant_card_marks(Node* n) { 1.143 assert(n->Opcode() == Op_StoreCM, "expected StoreCM"); 1.144 if (n->in(MemNode::Address)->outcnt() > 1) { 1.145 // There are multiple users of the same address so it might be 1.146 @@ -2122,7 +2212,7 @@ 1.147 // Eliminate the previous StoreCM 1.148 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory)); 1.149 assert(mem->outcnt() == 0, "should be dead"); 1.150 - mem->disconnect_inputs(NULL); 1.151 + mem->disconnect_inputs(NULL, this); 1.152 } else { 1.153 prev = mem; 1.154 } 1.155 @@ -2133,7 +2223,7 @@ 1.156 1.157 //------------------------------final_graph_reshaping_impl---------------------- 1.158 // Implement items 1-5 from final_graph_reshaping below. 1.159 -static void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc ) { 1.160 +void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) { 1.161 1.162 if ( n->outcnt() == 0 ) return; // dead node 1.163 uint nop = n->Opcode(); 1.164 @@ -2163,8 +2253,7 @@ 1.165 1.166 #ifdef ASSERT 1.167 if( n->is_Mem() ) { 1.168 - Compile* C = Compile::current(); 1.169 - int alias_idx = C->get_alias_index(n->as_Mem()->adr_type()); 1.170 + int alias_idx = get_alias_index(n->as_Mem()->adr_type()); 1.171 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw || 1.172 // oop will be recorded in oop map if load crosses safepoint 1.173 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || 1.174 @@ -2213,7 +2302,7 @@ 1.175 break; 1.176 case Op_Opaque1: // Remove Opaque Nodes before matching 1.177 case Op_Opaque2: // Remove Opaque Nodes before matching 1.178 - n->subsume_by(n->in(1)); 1.179 + n->subsume_by(n->in(1), this); 1.180 break; 1.181 case Op_CallStaticJava: 1.182 case Op_CallJava: 1.183 @@ -2337,8 +2426,7 @@ 1.184 int op = t->isa_oopptr() ? Op_ConN : Op_ConNKlass; 1.185 1.186 // Look for existing ConN node of the same exact type. 1.187 - Compile* C = Compile::current(); 1.188 - Node* r = C->root(); 1.189 + Node* r = root(); 1.190 uint cnt = r->outcnt(); 1.191 for (uint i = 0; i < cnt; i++) { 1.192 Node* m = r->raw_out(i); 1.193 @@ -2352,14 +2440,14 @@ 1.194 // Decode a narrow oop to match address 1.195 // [R12 + narrow_oop_reg<<3 + offset] 1.196 if (t->isa_oopptr()) { 1.197 - nn = new (C) DecodeNNode(nn, t); 1.198 + nn = new (this) DecodeNNode(nn, t); 1.199 } else { 1.200 - nn = new (C) DecodeNKlassNode(nn, t); 1.201 + nn = new (this) DecodeNKlassNode(nn, t); 1.202 } 1.203 n->set_req(AddPNode::Base, nn); 1.204 n->set_req(AddPNode::Address, nn); 1.205 if (addp->outcnt() == 0) { 1.206 - addp->disconnect_inputs(NULL); 1.207 + addp->disconnect_inputs(NULL, this); 1.208 } 1.209 } 1.210 } 1.211 @@ -2371,7 +2459,6 @@ 1.212 #ifdef _LP64 1.213 case Op_CastPP: 1.214 if (n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) { 1.215 - Compile* C = Compile::current(); 1.216 Node* in1 = n->in(1); 1.217 const Type* t = n->bottom_type(); 1.218 Node* new_in1 = in1->clone(); 1.219 @@ -2400,9 +2487,9 @@ 1.220 new_in1->set_req(0, n->in(0)); 1.221 } 1.222 1.223 - n->subsume_by(new_in1); 1.224 + n->subsume_by(new_in1, this); 1.225 if (in1->outcnt() == 0) { 1.226 - in1->disconnect_inputs(NULL); 1.227 + in1->disconnect_inputs(NULL, this); 1.228 } 1.229 } 1.230 break; 1.231 @@ -2419,7 +2506,6 @@ 1.232 } 1.233 assert(in1->is_DecodeNarrowPtr(), "sanity"); 1.234 1.235 - Compile* C = Compile::current(); 1.236 Node* new_in2 = NULL; 1.237 if (in2->is_DecodeNarrowPtr()) { 1.238 assert(in2->Opcode() == in1->Opcode(), "must be same node type"); 1.239 @@ -2432,7 +2518,7 @@ 1.240 // oops implicit null check is not generated. 1.241 // This will allow to generate normal oop implicit null check. 1.242 if (Matcher::gen_narrow_oop_implicit_null_checks()) 1.243 - new_in2 = ConNode::make(C, TypeNarrowOop::NULL_PTR); 1.244 + new_in2 = ConNode::make(this, TypeNarrowOop::NULL_PTR); 1.245 // 1.246 // This transformation together with CastPP transformation above 1.247 // will generated code for implicit NULL checks for compressed oops. 1.248 @@ -2471,19 +2557,19 @@ 1.249 // NullCheck base_reg 1.250 // 1.251 } else if (t->isa_oopptr()) { 1.252 - new_in2 = ConNode::make(C, t->make_narrowoop()); 1.253 + new_in2 = ConNode::make(this, t->make_narrowoop()); 1.254 } else if (t->isa_klassptr()) { 1.255 - new_in2 = ConNode::make(C, t->make_narrowklass()); 1.256 + new_in2 = ConNode::make(this, t->make_narrowklass()); 1.257 } 1.258 } 1.259 if (new_in2 != NULL) { 1.260 - Node* cmpN = new (C) CmpNNode(in1->in(1), new_in2); 1.261 - n->subsume_by( cmpN ); 1.262 + Node* cmpN = new (this) CmpNNode(in1->in(1), new_in2); 1.263 + n->subsume_by(cmpN, this); 1.264 if (in1->outcnt() == 0) { 1.265 - in1->disconnect_inputs(NULL); 1.266 + in1->disconnect_inputs(NULL, this); 1.267 } 1.268 if (in2->outcnt() == 0) { 1.269 - in2->disconnect_inputs(NULL); 1.270 + in2->disconnect_inputs(NULL, this); 1.271 } 1.272 } 1.273 } 1.274 @@ -2501,21 +2587,20 @@ 1.275 case Op_EncodePKlass: { 1.276 Node* in1 = n->in(1); 1.277 if (in1->is_DecodeNarrowPtr()) { 1.278 - n->subsume_by(in1->in(1)); 1.279 + n->subsume_by(in1->in(1), this); 1.280 } else if (in1->Opcode() == Op_ConP) { 1.281 - Compile* C = Compile::current(); 1.282 const Type* t = in1->bottom_type(); 1.283 if (t == TypePtr::NULL_PTR) { 1.284 assert(t->isa_oopptr(), "null klass?"); 1.285 - n->subsume_by(ConNode::make(C, TypeNarrowOop::NULL_PTR)); 1.286 + n->subsume_by(ConNode::make(this, TypeNarrowOop::NULL_PTR), this); 1.287 } else if (t->isa_oopptr()) { 1.288 - n->subsume_by(ConNode::make(C, t->make_narrowoop())); 1.289 + n->subsume_by(ConNode::make(this, t->make_narrowoop()), this); 1.290 } else if (t->isa_klassptr()) { 1.291 - n->subsume_by(ConNode::make(C, t->make_narrowklass())); 1.292 + n->subsume_by(ConNode::make(this, t->make_narrowklass()), this); 1.293 } 1.294 } 1.295 if (in1->outcnt() == 0) { 1.296 - in1->disconnect_inputs(NULL); 1.297 + in1->disconnect_inputs(NULL, this); 1.298 } 1.299 break; 1.300 } 1.301 @@ -2538,7 +2623,7 @@ 1.302 } 1.303 } 1.304 assert(proj != NULL, "must be found"); 1.305 - p->subsume_by(proj); 1.306 + p->subsume_by(proj, this); 1.307 } 1.308 } 1.309 break; 1.310 @@ -2558,7 +2643,7 @@ 1.311 unique_in = NULL; 1.312 } 1.313 if (unique_in != NULL) { 1.314 - n->subsume_by(unique_in); 1.315 + n->subsume_by(unique_in, this); 1.316 } 1.317 } 1.318 break; 1.319 @@ -2571,16 +2656,15 @@ 1.320 Node* d = n->find_similar(Op_DivI); 1.321 if (d) { 1.322 // Replace them with a fused divmod if supported 1.323 - Compile* C = Compile::current(); 1.324 if (Matcher::has_match_rule(Op_DivModI)) { 1.325 - DivModINode* divmod = DivModINode::make(C, n); 1.326 - d->subsume_by(divmod->div_proj()); 1.327 - n->subsume_by(divmod->mod_proj()); 1.328 + DivModINode* divmod = DivModINode::make(this, n); 1.329 + d->subsume_by(divmod->div_proj(), this); 1.330 + n->subsume_by(divmod->mod_proj(), this); 1.331 } else { 1.332 // replace a%b with a-((a/b)*b) 1.333 - Node* mult = new (C) MulINode(d, d->in(2)); 1.334 - Node* sub = new (C) SubINode(d->in(1), mult); 1.335 - n->subsume_by( sub ); 1.336 + Node* mult = new (this) MulINode(d, d->in(2)); 1.337 + Node* sub = new (this) SubINode(d->in(1), mult); 1.338 + n->subsume_by(sub, this); 1.339 } 1.340 } 1.341 } 1.342 @@ -2592,16 +2676,15 @@ 1.343 Node* d = n->find_similar(Op_DivL); 1.344 if (d) { 1.345 // Replace them with a fused divmod if supported 1.346 - Compile* C = Compile::current(); 1.347 if (Matcher::has_match_rule(Op_DivModL)) { 1.348 - DivModLNode* divmod = DivModLNode::make(C, n); 1.349 - d->subsume_by(divmod->div_proj()); 1.350 - n->subsume_by(divmod->mod_proj()); 1.351 + DivModLNode* divmod = DivModLNode::make(this, n); 1.352 + d->subsume_by(divmod->div_proj(), this); 1.353 + n->subsume_by(divmod->mod_proj(), this); 1.354 } else { 1.355 // replace a%b with a-((a/b)*b) 1.356 - Node* mult = new (C) MulLNode(d, d->in(2)); 1.357 - Node* sub = new (C) SubLNode(d->in(1), mult); 1.358 - n->subsume_by( sub ); 1.359 + Node* mult = new (this) MulLNode(d, d->in(2)); 1.360 + Node* sub = new (this) SubLNode(d->in(1), mult); 1.361 + n->subsume_by(sub, this); 1.362 } 1.363 } 1.364 } 1.365 @@ -2620,8 +2703,8 @@ 1.366 if (n->req()-1 > 2) { 1.367 // Replace many operand PackNodes with a binary tree for matching 1.368 PackNode* p = (PackNode*) n; 1.369 - Node* btp = p->binary_tree_pack(Compile::current(), 1, n->req()); 1.370 - n->subsume_by(btp); 1.371 + Node* btp = p->binary_tree_pack(this, 1, n->req()); 1.372 + n->subsume_by(btp, this); 1.373 } 1.374 break; 1.375 case Op_Loop: 1.376 @@ -2645,18 +2728,16 @@ 1.377 if (t != NULL && t->is_con()) { 1.378 juint shift = t->get_con(); 1.379 if (shift > mask) { // Unsigned cmp 1.380 - Compile* C = Compile::current(); 1.381 - n->set_req(2, ConNode::make(C, TypeInt::make(shift & mask))); 1.382 + n->set_req(2, ConNode::make(this, TypeInt::make(shift & mask))); 1.383 } 1.384 } else { 1.385 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) { 1.386 - Compile* C = Compile::current(); 1.387 - Node* shift = new (C) AndINode(in2, ConNode::make(C, TypeInt::make(mask))); 1.388 + Node* shift = new (this) AndINode(in2, ConNode::make(this, TypeInt::make(mask))); 1.389 n->set_req(2, shift); 1.390 } 1.391 } 1.392 if (in2->outcnt() == 0) { // Remove dead node 1.393 - in2->disconnect_inputs(NULL); 1.394 + in2->disconnect_inputs(NULL, this); 1.395 } 1.396 } 1.397 break; 1.398 @@ -2674,7 +2755,7 @@ 1.399 //------------------------------final_graph_reshaping_walk--------------------- 1.400 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(), 1.401 // requires that the walk visits a node's inputs before visiting the node. 1.402 -static void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) { 1.403 +void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) { 1.404 ResourceArea *area = Thread::current()->resource_area(); 1.405 Unique_Node_List sfpt(area); 1.406 1.407 @@ -2741,7 +2822,7 @@ 1.408 n->set_req(j, in->in(1)); 1.409 } 1.410 if (in->outcnt() == 0) { 1.411 - in->disconnect_inputs(NULL); 1.412 + in->disconnect_inputs(NULL, this); 1.413 } 1.414 } 1.415 } 1.416 @@ -3014,7 +3095,8 @@ 1.417 } 1.418 1.419 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog) 1.420 - : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false) 1.421 + : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false), 1.422 + _phase_name(name), _dolog(dolog) 1.423 { 1.424 if (dolog) { 1.425 C = Compile::current(); 1.426 @@ -3024,15 +3106,34 @@ 1.427 _log = NULL; 1.428 } 1.429 if (_log != NULL) { 1.430 - _log->begin_head("phase name='%s' nodes='%d'", name, C->unique()); 1.431 + _log->begin_head("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes()); 1.432 _log->stamp(); 1.433 _log->end_head(); 1.434 } 1.435 } 1.436 1.437 Compile::TracePhase::~TracePhase() { 1.438 + 1.439 + C = Compile::current(); 1.440 + if (_dolog) { 1.441 + _log = C->log(); 1.442 + } else { 1.443 + _log = NULL; 1.444 + } 1.445 + 1.446 +#ifdef ASSERT 1.447 + if (PrintIdealNodeCount) { 1.448 + tty->print_cr("phase name='%s' nodes='%d' live='%d' live_graph_walk='%d'", 1.449 + _phase_name, C->unique(), C->live_nodes(), C->count_live_nodes_by_graph_walk()); 1.450 + } 1.451 + 1.452 + if (VerifyIdealNodeCount) { 1.453 + Compile::current()->print_missing_nodes(); 1.454 + } 1.455 +#endif 1.456 + 1.457 if (_log != NULL) { 1.458 - _log->done("phase nodes='%d'", C->unique()); 1.459 + _log->done("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes()); 1.460 } 1.461 } 1.462