Wed, 27 Aug 2008 09:15:46 -0700
6736417: Fastdebug C2 crashes in StoreBNode::Ideal
Summary: The result of step_through_mergemem() and remove_dead_region() is not checked in some cases.
Reviewed-by: never
1.1 --- a/src/share/vm/opto/callnode.cpp Wed Aug 27 00:21:55 2008 -0700 1.2 +++ b/src/share/vm/opto/callnode.cpp Wed Aug 27 09:15:46 2008 -0700 1.3 @@ -829,9 +829,7 @@ 1.4 //------------------------------Ideal------------------------------------------ 1.5 // Skip over any collapsed Regions 1.6 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) { 1.7 - if (remove_dead_region(phase, can_reshape)) return this; 1.8 - 1.9 - return NULL; 1.10 + return remove_dead_region(phase, can_reshape) ? this : NULL; 1.11 } 1.12 1.13 //------------------------------Identity---------------------------------------
2.1 --- a/src/share/vm/opto/connode.cpp Wed Aug 27 00:21:55 2008 -0700 2.2 +++ b/src/share/vm/opto/connode.cpp Wed Aug 27 09:15:46 2008 -0700 2.3 @@ -101,6 +101,8 @@ 2.4 // Move constants to the right. 2.5 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) { 2.6 if( in(0) && remove_dead_region(phase, can_reshape) ) return this; 2.7 + // Don't bother trying to transform a dead node 2.8 + if( in(0) && in(0)->is_top() ) return NULL; 2.9 assert( !phase->eqv(in(Condition), this) && 2.10 !phase->eqv(in(IfFalse), this) && 2.11 !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
3.1 --- a/src/share/vm/opto/divnode.cpp Wed Aug 27 00:21:55 2008 -0700 3.2 +++ b/src/share/vm/opto/divnode.cpp Wed Aug 27 09:15:46 2008 -0700 3.3 @@ -402,6 +402,8 @@ 3.4 // Divides can be changed to multiplies and/or shifts 3.5 Node *DivINode::Ideal(PhaseGVN *phase, bool can_reshape) { 3.6 if (in(0) && remove_dead_region(phase, can_reshape)) return this; 3.7 + // Don't bother trying to transform a dead node 3.8 + if( in(0) && in(0)->is_top() ) return NULL; 3.9 3.10 const Type *t = phase->type( in(2) ); 3.11 if( t == TypeInt::ONE ) // Identity? 3.12 @@ -499,6 +501,8 @@ 3.13 // Dividing by a power of 2 is a shift. 3.14 Node *DivLNode::Ideal( PhaseGVN *phase, bool can_reshape) { 3.15 if (in(0) && remove_dead_region(phase, can_reshape)) return this; 3.16 + // Don't bother trying to transform a dead node 3.17 + if( in(0) && in(0)->is_top() ) return NULL; 3.18 3.19 const Type *t = phase->type( in(2) ); 3.20 if( t == TypeLong::ONE ) // Identity? 3.21 @@ -640,6 +644,8 @@ 3.22 //------------------------------Idealize--------------------------------------- 3.23 Node *DivFNode::Ideal(PhaseGVN *phase, bool can_reshape) { 3.24 if (in(0) && remove_dead_region(phase, can_reshape)) return this; 3.25 + // Don't bother trying to transform a dead node 3.26 + if( in(0) && in(0)->is_top() ) return NULL; 3.27 3.28 const Type *t2 = phase->type( in(2) ); 3.29 if( t2 == TypeF::ONE ) // Identity? 3.30 @@ -725,6 +731,8 @@ 3.31 //------------------------------Idealize--------------------------------------- 3.32 Node *DivDNode::Ideal(PhaseGVN *phase, bool can_reshape) { 3.33 if (in(0) && remove_dead_region(phase, can_reshape)) return this; 3.34 + // Don't bother trying to transform a dead node 3.35 + if( in(0) && in(0)->is_top() ) return NULL; 3.36 3.37 const Type *t2 = phase->type( in(2) ); 3.38 if( t2 == TypeD::ONE ) // Identity? 3.39 @@ -760,7 +768,9 @@ 3.40 //------------------------------Idealize--------------------------------------- 3.41 Node *ModINode::Ideal(PhaseGVN *phase, bool can_reshape) { 3.42 // Check for dead control input 3.43 - if( remove_dead_region(phase, can_reshape) ) return this; 3.44 + if( in(0) && remove_dead_region(phase, can_reshape) ) return this; 3.45 + // Don't bother trying to transform a dead node 3.46 + if( in(0) && in(0)->is_top() ) return NULL; 3.47 3.48 // Get the modulus 3.49 const Type *t = phase->type( in(2) ); 3.50 @@ -929,7 +939,9 @@ 3.51 //------------------------------Idealize--------------------------------------- 3.52 Node *ModLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 3.53 // Check for dead control input 3.54 - if( remove_dead_region(phase, can_reshape) ) return this; 3.55 + if( in(0) && remove_dead_region(phase, can_reshape) ) return this; 3.56 + // Don't bother trying to transform a dead node 3.57 + if( in(0) && in(0)->is_top() ) return NULL; 3.58 3.59 // Get the modulus 3.60 const Type *t = phase->type( in(2) );
4.1 --- a/src/share/vm/opto/memnode.cpp Wed Aug 27 00:21:55 2008 -0700 4.2 +++ b/src/share/vm/opto/memnode.cpp Wed Aug 27 09:15:46 2008 -0700 4.3 @@ -214,6 +214,9 @@ 4.4 Node *ctl = in(MemNode::Control); 4.5 if (ctl && remove_dead_region(phase, can_reshape)) 4.6 return this; 4.7 + ctl = in(MemNode::Control); 4.8 + // Don't bother trying to transform a dead node 4.9 + if( ctl && ctl->is_top() ) return NodeSentinel; 4.10 4.11 // Ignore if memory is dead, or self-loop 4.12 Node *mem = in(MemNode::Memory); 4.13 @@ -244,6 +247,7 @@ 4.14 4.15 if (mem != old_mem) { 4.16 set_req(MemNode::Memory, mem); 4.17 + if (phase->type( mem ) == Type::TOP) return NodeSentinel; 4.18 return this; 4.19 } 4.20 4.21 @@ -1316,6 +1320,7 @@ 4.22 Node* opt_mem = MemNode::optimize_memory_chain(mem, addr_t, phase); 4.23 if (opt_mem != mem) { 4.24 set_req(MemNode::Memory, opt_mem); 4.25 + if (phase->type( opt_mem ) == Type::TOP) return NULL; 4.26 return this; 4.27 } 4.28 const TypeOopPtr *t_oop = addr_t->isa_oopptr(); 4.29 @@ -2447,8 +2452,7 @@ 4.30 // Return a node which is more "ideal" than the current node. Strip out 4.31 // control copies 4.32 Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) { 4.33 - if (remove_dead_region(phase, can_reshape)) return this; 4.34 - return NULL; 4.35 + return remove_dead_region(phase, can_reshape) ? this : NULL; 4.36 } 4.37 4.38 //------------------------------Value------------------------------------------
5.1 --- a/src/share/vm/opto/node.cpp Wed Aug 27 00:21:55 2008 -0700 5.2 +++ b/src/share/vm/opto/node.cpp Wed Aug 27 09:15:46 2008 -0700 5.3 @@ -1166,16 +1166,15 @@ 5.4 // using it dead as well. This will happen normally via the usual IterGVN 5.5 // worklist but this call is more efficient. Do not update use-def info 5.6 // inside the dead region, just at the borders. 5.7 -static bool kill_dead_code( Node *dead, PhaseIterGVN *igvn ) { 5.8 +static void kill_dead_code( Node *dead, PhaseIterGVN *igvn ) { 5.9 // Con's are a popular node to re-hit in the hash table again. 5.10 - if( dead->is_Con() ) return false; 5.11 + if( dead->is_Con() ) return; 5.12 5.13 // Can't put ResourceMark here since igvn->_worklist uses the same arena 5.14 // for verify pass with +VerifyOpto and we add/remove elements in it here. 5.15 Node_List nstack(Thread::current()->resource_area()); 5.16 5.17 Node *top = igvn->C->top(); 5.18 - bool progress = false; 5.19 nstack.push(dead); 5.20 5.21 while (nstack.size() > 0) { 5.22 @@ -1214,7 +1213,6 @@ 5.23 for (uint i=0; i < dead->req(); i++) { 5.24 Node *n = dead->in(i); // Get input to dead guy 5.25 if (n != NULL && !n->is_top()) { // Input is valid? 5.26 - progress = true; 5.27 dead->set_req(i, top); // Smash input away 5.28 if (n->outcnt() == 0) { // Input also goes dead? 5.29 if (!n->is_Con()) 5.30 @@ -1233,7 +1231,7 @@ 5.31 } 5.32 } // (dead->outcnt() == 0) 5.33 } // while (nstack.size() > 0) for outputs 5.34 - return progress; 5.35 + return; 5.36 } 5.37 5.38 //------------------------------remove_dead_region----------------------------- 5.39 @@ -1243,7 +1241,8 @@ 5.40 // Lost control into this guy? I.e., it became unreachable? 5.41 // Aggressively kill all unreachable code. 5.42 if (can_reshape && n->is_top()) { 5.43 - return kill_dead_code(this, phase->is_IterGVN()); 5.44 + kill_dead_code(this, phase->is_IterGVN()); 5.45 + return false; // Node is dead. 5.46 } 5.47 5.48 if( n->is_Region() && n->as_Region()->is_copy() ) {
6.1 --- a/src/share/vm/opto/phaseX.cpp Wed Aug 27 00:21:55 2008 -0700 6.2 +++ b/src/share/vm/opto/phaseX.cpp Wed Aug 27 09:15:46 2008 -0700 6.3 @@ -986,7 +986,9 @@ 6.4 // Apply the Ideal call in a loop until it no longer applies 6.5 Node *k = n; 6.6 DEBUG_ONLY(dead_loop_check(k);) 6.7 + DEBUG_ONLY(bool is_new = (k->outcnt() == 0);) 6.8 Node *i = k->Ideal(this, /*can_reshape=*/true); 6.9 + assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes"); 6.10 #ifndef PRODUCT 6.11 if( VerifyIterativeGVN ) 6.12 verify_step(k); 6.13 @@ -1024,7 +1026,9 @@ 6.14 } 6.15 DEBUG_ONLY(dead_loop_check(k);) 6.16 // Try idealizing again 6.17 + DEBUG_ONLY(is_new = (k->outcnt() == 0);) 6.18 i = k->Ideal(this, /*can_reshape=*/true); 6.19 + assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes"); 6.20 #ifndef PRODUCT 6.21 if( VerifyIterativeGVN ) 6.22 verify_step(k);