< prev index next >

src/share/vm/opto/cfgnode.cpp

Print this page




  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/convertnode.hpp"
  33 #include "opto/loopnode.hpp"
  34 #include "opto/machnode.hpp"
  35 #include "opto/movenode.hpp"
  36 #include "opto/narrowptrnode.hpp"
  37 #include "opto/mulnode.hpp"
  38 #include "opto/phaseX.hpp"
  39 #include "opto/regmask.hpp"
  40 #include "opto/runtime.hpp"
  41 #include "opto/subnode.hpp"
  42 
  43 // Portions of code courtesy of Clifford Click
  44 
  45 // Optimization - Graph Style
  46 
  47 //=============================================================================
  48 //------------------------------Value------------------------------------------
  49 // Compute the type of the RegionNode.
  50 const Type *RegionNode::Value( PhaseTransform *phase ) const {
  51   for( uint i=1; i<req(); ++i ) {       // For all paths in
  52     Node *n = in(i);            // Get Control source
  53     if( !n ) continue;          // Missing inputs are TOP
  54     if( phase->type(n) == Type::CONTROL )
  55       return Type::CONTROL;
  56   }
  57   return Type::TOP;             // All paths dead?  Then so are we
  58 }
  59 
  60 //------------------------------Identity---------------------------------------
  61 // Check for Region being Identity.
  62 Node *RegionNode::Identity( PhaseTransform *phase ) {
  63   // Cannot have Region be an identity, even if it has only 1 input.
  64   // Phi users cannot have their Region input folded away for them,
  65   // since they need to select the proper data input
  66   return this;
  67 }
  68 
  69 //------------------------------merge_region-----------------------------------
  70 // If a Region flows into a Region, merge into one big happy merge.  This is
  71 // hard to do if there is stuff that has to happen
  72 static Node *merge_region(RegionNode *region, PhaseGVN *phase) {
  73   if( region->Opcode() != Op_Region ) // Do not do to LoopNodes
  74     return NULL;
  75   Node *progress = NULL;        // Progress flag
  76   PhaseIterGVN *igvn = phase->is_IterGVN();
  77 
  78   uint rreq = region->req();
  79   for( uint i = 1; i < rreq; i++ ) {
  80     Node *r = region->in(i);
  81     if( r && r->Opcode() == Op_Region && // Found a region?
  82         r->in(0) == r &&        // Not already collapsed?


 874   if (is_error_reported())  return;  // muzzle asserts when debugging an error
 875   if (Node::in_dump())      return;  // muzzle asserts when printing
 876 
 877   assert((_type == Type::MEMORY) == (_adr_type != NULL), "adr_type for memory phis only");
 878 
 879   if (!VerifyAliases)       return;  // verify thoroughly only if requested
 880 
 881   assert(_adr_type == flatten_phi_adr_type(_adr_type),
 882          "Phi::adr_type must be pre-normalized");
 883 
 884   if (recursive) {
 885     VectorSet visited(Thread::current()->resource_area());
 886     verify_adr_type(visited, _adr_type);
 887   }
 888 }
 889 #endif
 890 
 891 
 892 //------------------------------Value------------------------------------------
 893 // Compute the type of the PhiNode
 894 const Type *PhiNode::Value( PhaseTransform *phase ) const {
 895   Node *r = in(0);              // RegionNode
 896   if( !r )                      // Copy or dead
 897     return in(1) ? phase->type(in(1)) : Type::TOP;
 898 
 899   // Note: During parsing, phis are often transformed before their regions.
 900   // This means we have to use type_or_null to defend against untyped regions.
 901   if( phase->type_or_null(r) == Type::TOP )  // Dead code?
 902     return Type::TOP;
 903 
 904   // Check for trip-counted loop.  If so, be smarter.
 905   CountedLoopNode *l = r->is_CountedLoop() ? r->as_CountedLoop() : NULL;
 906   if( l && l->can_be_counted_loop(phase) &&
 907       ((const Node*)l->phi() == this) ) { // Trip counted loop!
 908     // protect against init_trip() or limit() returning NULL
 909     const Node *init   = l->init_trip();
 910     const Node *limit  = l->limit();
 911     if( init != NULL && limit != NULL && l->stride_is_con() ) {
 912       const TypeInt *lo = init ->bottom_type()->isa_int();
 913       const TypeInt *hi = limit->bottom_type()->isa_int();
 914       if( lo && hi ) {            // Dying loops might have TOP here


1125     return NULL;
1126 
1127   // Either value might be a cast that depends on a branch of 'iff'.
1128   // Since the 'id' value will float free of the diamond, either
1129   // decast or return failure.
1130   Node* ctl = id->in(0);
1131   if (ctl != NULL && ctl->in(0) == iff) {
1132     if (id->is_ConstraintCast()) {
1133       return id->in(1);
1134     } else {
1135       // Don't know how to disentangle this value.
1136       return NULL;
1137     }
1138   }
1139 
1140   return id;
1141 }
1142 
1143 //------------------------------Identity---------------------------------------
1144 // Check for Region being Identity.
1145 Node *PhiNode::Identity( PhaseTransform *phase ) {
1146   // Check for no merging going on
1147   // (There used to be special-case code here when this->region->is_Loop.
1148   // It would check for a tributary phi on the backedge that the main phi
1149   // trivially, perhaps with a single cast.  The unique_input method
1150   // does all this and more, by reducing such tributaries to 'this'.)
1151   Node* uin = unique_input(phase);
1152   if (uin != NULL) {
1153     return uin;
1154   }
1155 
1156   int true_path = is_diamond_phi();
1157   if (true_path != 0) {
1158     Node* id = is_cmove_id(phase, true_path);
1159     if (id != NULL)  return id;
1160   }
1161 
1162   return this;                     // No identity
1163 }
1164 
1165 //-----------------------------unique_input------------------------------------


2031 
2032 #ifndef PRODUCT
2033 void PhiNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2034   // For a PhiNode, the set of related nodes includes all inputs till level 2,
2035   // and all outputs till level 1. In compact mode, inputs till level 1 are
2036   // collected.
2037   this->collect_nodes(in_rel, compact ? 1 : 2, false, false);
2038   this->collect_nodes(out_rel, -1, false, false);
2039 }
2040 
2041 void PhiNode::dump_spec(outputStream *st) const {
2042   TypeNode::dump_spec(st);
2043   if (is_tripcount()) {
2044     st->print(" #tripcount");
2045   }
2046 }
2047 #endif
2048 
2049 
2050 //=============================================================================
2051 const Type *GotoNode::Value( PhaseTransform *phase ) const {
2052   // If the input is reachable, then we are executed.
2053   // If the input is not reachable, then we are not executed.
2054   return phase->type(in(0));
2055 }
2056 
2057 Node *GotoNode::Identity( PhaseTransform *phase ) {
2058   return in(0);                // Simple copy of incoming control
2059 }
2060 
2061 const RegMask &GotoNode::out_RegMask() const {
2062   return RegMask::Empty;
2063 }
2064 
2065 #ifndef PRODUCT
2066 //-----------------------------related-----------------------------------------
2067 // The related nodes of a GotoNode are all inputs at level 1, as well as the
2068 // outputs at level 1. This is regardless of compact mode.
2069 void GotoNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2070   this->collect_nodes(in_rel, 1, false, false);
2071   this->collect_nodes(out_rel, -1, false, false);
2072 }
2073 #endif
2074 
2075 
2076 //=============================================================================
2077 const RegMask &JumpNode::out_RegMask() const {


2099   return RegMask::Empty;
2100 }
2101 
2102 
2103 
2104 //=============================================================================
2105 
2106 uint PCTableNode::hash() const { return Node::hash() + _size; }
2107 uint PCTableNode::cmp( const Node &n ) const
2108 { return _size == ((PCTableNode&)n)._size; }
2109 
2110 const Type *PCTableNode::bottom_type() const {
2111   const Type** f = TypeTuple::fields(_size);
2112   for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;
2113   return TypeTuple::make(_size, f);
2114 }
2115 
2116 //------------------------------Value------------------------------------------
2117 // Compute the type of the PCTableNode.  If reachable it is a tuple of
2118 // Control, otherwise the table targets are not reachable
2119 const Type *PCTableNode::Value( PhaseTransform *phase ) const {
2120   if( phase->type(in(0)) == Type::CONTROL )
2121     return bottom_type();
2122   return Type::TOP;             // All paths dead?  Then so are we
2123 }
2124 
2125 //------------------------------Ideal------------------------------------------
2126 // Return a node which is more "ideal" than the current node.  Strip out
2127 // control copies
2128 Node *PCTableNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2129   return remove_dead_region(phase, can_reshape) ? this : NULL;
2130 }
2131 
2132 //=============================================================================
2133 uint JumpProjNode::hash() const {
2134   return Node::hash() + _dest_bci;
2135 }
2136 
2137 uint JumpProjNode::cmp( const Node &n ) const {
2138   return ProjNode::cmp(n) &&
2139     _dest_bci == ((JumpProjNode&)n)._dest_bci;


2144   ProjNode::dump_spec(st);
2145   st->print("@bci %d ",_dest_bci);
2146 }
2147 
2148 void JumpProjNode::dump_compact_spec(outputStream *st) const {
2149   ProjNode::dump_compact_spec(st);
2150   st->print("(%d)%d@%d", _switch_val, _proj_no, _dest_bci);
2151 }
2152 
2153 void JumpProjNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2154   // The related nodes of a JumpProjNode are its inputs and outputs at level 1.
2155   this->collect_nodes(in_rel, 1, false, false);
2156   this->collect_nodes(out_rel, -1, false, false);
2157 }
2158 #endif
2159 
2160 //=============================================================================
2161 //------------------------------Value------------------------------------------
2162 // Check for being unreachable, or for coming from a Rethrow.  Rethrow's cannot
2163 // have the default "fall_through_index" path.
2164 const Type *CatchNode::Value( PhaseTransform *phase ) const {
2165   // Unreachable?  Then so are all paths from here.
2166   if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
2167   // First assume all paths are reachable
2168   const Type** f = TypeTuple::fields(_size);
2169   for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;
2170   // Identify cases that will always throw an exception
2171   // () rethrow call
2172   // () virtual or interface call with NULL receiver
2173   // () call is a check cast with incompatible arguments
2174   if( in(1)->is_Proj() ) {
2175     Node *i10 = in(1)->in(0);
2176     if( i10->is_Call() ) {
2177       CallNode *call = i10->as_Call();
2178       // Rethrows always throw exceptions, never return
2179       if (call->entry_point() == OptoRuntime::rethrow_stub()) {
2180         f[CatchProjNode::fall_through_index] = Type::TOP;
2181       } else if( call->req() > TypeFunc::Parms ) {
2182         const Type *arg0 = phase->type( call->in(TypeFunc::Parms) );
2183         // Check for null receiver to virtual or interface calls
2184         if( call->is_CallDynamicJava() &&


2188       } // End of if not a runtime stub
2189     } // End of if have call above me
2190   } // End of slot 1 is not a projection
2191   return TypeTuple::make(_size, f);
2192 }
2193 
2194 //=============================================================================
2195 uint CatchProjNode::hash() const {
2196   return Node::hash() + _handler_bci;
2197 }
2198 
2199 
2200 uint CatchProjNode::cmp( const Node &n ) const {
2201   return ProjNode::cmp(n) &&
2202     _handler_bci == ((CatchProjNode&)n)._handler_bci;
2203 }
2204 
2205 
2206 //------------------------------Identity---------------------------------------
2207 // If only 1 target is possible, choose it if it is the main control
2208 Node *CatchProjNode::Identity( PhaseTransform *phase ) {
2209   // If my value is control and no other value is, then treat as ID
2210   const TypeTuple *t = phase->type(in(0))->is_tuple();
2211   if (t->field_at(_con) != Type::CONTROL)  return this;
2212   // If we remove the last CatchProj and elide the Catch/CatchProj, then we
2213   // also remove any exception table entry.  Thus we must know the call
2214   // feeding the Catch will not really throw an exception.  This is ok for
2215   // the main fall-thru control (happens when we know a call can never throw
2216   // an exception) or for "rethrow", because a further optimization will
2217   // yank the rethrow (happens when we inline a function that can throw an
2218   // exception and the caller has no handler).  Not legal, e.g., for passing
2219   // a NULL receiver to a v-call, or passing bad types to a slow-check-cast.
2220   // These cases MUST throw an exception via the runtime system, so the VM
2221   // will be looking for a table entry.
2222   Node *proj = in(0)->in(1);    // Expect a proj feeding CatchNode
2223   CallNode *call;
2224   if (_con != TypeFunc::Control && // Bail out if not the main control.
2225       !(proj->is_Proj() &&      // AND NOT a rethrow
2226         proj->in(0)->is_Call() &&
2227         (call = proj->in(0)->as_Call()) &&
2228         call->entry_point() == OptoRuntime::rethrow_stub()))


2231   // Search for any other path being control
2232   for (uint i = 0; i < t->cnt(); i++) {
2233     if (i != _con && t->field_at(i) == Type::CONTROL)
2234       return this;
2235   }
2236   // Only my path is possible; I am identity on control to the jump
2237   return in(0)->in(0);
2238 }
2239 
2240 
2241 #ifndef PRODUCT
2242 void CatchProjNode::dump_spec(outputStream *st) const {
2243   ProjNode::dump_spec(st);
2244   st->print("@bci %d ",_handler_bci);
2245 }
2246 #endif
2247 
2248 //=============================================================================
2249 //------------------------------Identity---------------------------------------
2250 // Check for CreateEx being Identity.
2251 Node *CreateExNode::Identity( PhaseTransform *phase ) {
2252   if( phase->type(in(1)) == Type::TOP ) return in(1);
2253   if( phase->type(in(0)) == Type::TOP ) return in(0);
2254   // We only come from CatchProj, unless the CatchProj goes away.
2255   // If the CatchProj is optimized away, then we just carry the
2256   // exception oop through.
2257   CallNode *call = in(1)->in(0)->as_Call();
2258 
2259   return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )
2260     ? this
2261     : call->in(TypeFunc::Parms);
2262 }
2263 
2264 //=============================================================================
2265 //------------------------------Value------------------------------------------
2266 // Check for being unreachable.
2267 const Type *NeverBranchNode::Value( PhaseTransform *phase ) const {
2268   if (!in(0) || in(0)->is_top()) return Type::TOP;
2269   return bottom_type();
2270 }
2271 
2272 //------------------------------Ideal------------------------------------------
2273 // Check for no longer being part of a loop
2274 Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2275   if (can_reshape && !in(0)->is_Loop()) {
2276     // Dead code elimination can sometimes delete this projection so
2277     // if it's not there, there's nothing to do.
2278     Node* fallthru = proj_out(0);
2279     if (fallthru != NULL) {
2280       phase->is_IterGVN()->replace_node(fallthru, in(0));
2281     }
2282     return phase->C->top();
2283   }
2284   return NULL;
2285 }
2286 
2287 #ifndef PRODUCT


  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/convertnode.hpp"
  33 #include "opto/loopnode.hpp"
  34 #include "opto/machnode.hpp"
  35 #include "opto/movenode.hpp"
  36 #include "opto/narrowptrnode.hpp"
  37 #include "opto/mulnode.hpp"
  38 #include "opto/phaseX.hpp"
  39 #include "opto/regmask.hpp"
  40 #include "opto/runtime.hpp"
  41 #include "opto/subnode.hpp"
  42 
  43 // Portions of code courtesy of Clifford Click
  44 
  45 // Optimization - Graph Style
  46 
  47 //=============================================================================
  48 //------------------------------Value------------------------------------------
  49 // Compute the type of the RegionNode.
  50 const Type* RegionNode::Value(PhaseGVN* phase) const {
  51   for( uint i=1; i<req(); ++i ) {       // For all paths in
  52     Node *n = in(i);            // Get Control source
  53     if( !n ) continue;          // Missing inputs are TOP
  54     if( phase->type(n) == Type::CONTROL )
  55       return Type::CONTROL;
  56   }
  57   return Type::TOP;             // All paths dead?  Then so are we
  58 }
  59 
  60 //------------------------------Identity---------------------------------------
  61 // Check for Region being Identity.
  62 Node* RegionNode::Identity(PhaseGVN* phase) {
  63   // Cannot have Region be an identity, even if it has only 1 input.
  64   // Phi users cannot have their Region input folded away for them,
  65   // since they need to select the proper data input
  66   return this;
  67 }
  68 
  69 //------------------------------merge_region-----------------------------------
  70 // If a Region flows into a Region, merge into one big happy merge.  This is
  71 // hard to do if there is stuff that has to happen
  72 static Node *merge_region(RegionNode *region, PhaseGVN *phase) {
  73   if( region->Opcode() != Op_Region ) // Do not do to LoopNodes
  74     return NULL;
  75   Node *progress = NULL;        // Progress flag
  76   PhaseIterGVN *igvn = phase->is_IterGVN();
  77 
  78   uint rreq = region->req();
  79   for( uint i = 1; i < rreq; i++ ) {
  80     Node *r = region->in(i);
  81     if( r && r->Opcode() == Op_Region && // Found a region?
  82         r->in(0) == r &&        // Not already collapsed?


 874   if (is_error_reported())  return;  // muzzle asserts when debugging an error
 875   if (Node::in_dump())      return;  // muzzle asserts when printing
 876 
 877   assert((_type == Type::MEMORY) == (_adr_type != NULL), "adr_type for memory phis only");
 878 
 879   if (!VerifyAliases)       return;  // verify thoroughly only if requested
 880 
 881   assert(_adr_type == flatten_phi_adr_type(_adr_type),
 882          "Phi::adr_type must be pre-normalized");
 883 
 884   if (recursive) {
 885     VectorSet visited(Thread::current()->resource_area());
 886     verify_adr_type(visited, _adr_type);
 887   }
 888 }
 889 #endif
 890 
 891 
 892 //------------------------------Value------------------------------------------
 893 // Compute the type of the PhiNode
 894 const Type* PhiNode::Value(PhaseGVN* phase) const {
 895   Node *r = in(0);              // RegionNode
 896   if( !r )                      // Copy or dead
 897     return in(1) ? phase->type(in(1)) : Type::TOP;
 898 
 899   // Note: During parsing, phis are often transformed before their regions.
 900   // This means we have to use type_or_null to defend against untyped regions.
 901   if( phase->type_or_null(r) == Type::TOP )  // Dead code?
 902     return Type::TOP;
 903 
 904   // Check for trip-counted loop.  If so, be smarter.
 905   CountedLoopNode *l = r->is_CountedLoop() ? r->as_CountedLoop() : NULL;
 906   if( l && l->can_be_counted_loop(phase) &&
 907       ((const Node*)l->phi() == this) ) { // Trip counted loop!
 908     // protect against init_trip() or limit() returning NULL
 909     const Node *init   = l->init_trip();
 910     const Node *limit  = l->limit();
 911     if( init != NULL && limit != NULL && l->stride_is_con() ) {
 912       const TypeInt *lo = init ->bottom_type()->isa_int();
 913       const TypeInt *hi = limit->bottom_type()->isa_int();
 914       if( lo && hi ) {            // Dying loops might have TOP here


1125     return NULL;
1126 
1127   // Either value might be a cast that depends on a branch of 'iff'.
1128   // Since the 'id' value will float free of the diamond, either
1129   // decast or return failure.
1130   Node* ctl = id->in(0);
1131   if (ctl != NULL && ctl->in(0) == iff) {
1132     if (id->is_ConstraintCast()) {
1133       return id->in(1);
1134     } else {
1135       // Don't know how to disentangle this value.
1136       return NULL;
1137     }
1138   }
1139 
1140   return id;
1141 }
1142 
1143 //------------------------------Identity---------------------------------------
1144 // Check for Region being Identity.
1145 Node* PhiNode::Identity(PhaseGVN* phase) {
1146   // Check for no merging going on
1147   // (There used to be special-case code here when this->region->is_Loop.
1148   // It would check for a tributary phi on the backedge that the main phi
1149   // trivially, perhaps with a single cast.  The unique_input method
1150   // does all this and more, by reducing such tributaries to 'this'.)
1151   Node* uin = unique_input(phase);
1152   if (uin != NULL) {
1153     return uin;
1154   }
1155 
1156   int true_path = is_diamond_phi();
1157   if (true_path != 0) {
1158     Node* id = is_cmove_id(phase, true_path);
1159     if (id != NULL)  return id;
1160   }
1161 
1162   return this;                     // No identity
1163 }
1164 
1165 //-----------------------------unique_input------------------------------------


2031 
2032 #ifndef PRODUCT
2033 void PhiNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2034   // For a PhiNode, the set of related nodes includes all inputs till level 2,
2035   // and all outputs till level 1. In compact mode, inputs till level 1 are
2036   // collected.
2037   this->collect_nodes(in_rel, compact ? 1 : 2, false, false);
2038   this->collect_nodes(out_rel, -1, false, false);
2039 }
2040 
2041 void PhiNode::dump_spec(outputStream *st) const {
2042   TypeNode::dump_spec(st);
2043   if (is_tripcount()) {
2044     st->print(" #tripcount");
2045   }
2046 }
2047 #endif
2048 
2049 
2050 //=============================================================================
2051 const Type* GotoNode::Value(PhaseGVN* phase) const {
2052   // If the input is reachable, then we are executed.
2053   // If the input is not reachable, then we are not executed.
2054   return phase->type(in(0));
2055 }
2056 
2057 Node* GotoNode::Identity(PhaseGVN* phase) {
2058   return in(0);                // Simple copy of incoming control
2059 }
2060 
2061 const RegMask &GotoNode::out_RegMask() const {
2062   return RegMask::Empty;
2063 }
2064 
2065 #ifndef PRODUCT
2066 //-----------------------------related-----------------------------------------
2067 // The related nodes of a GotoNode are all inputs at level 1, as well as the
2068 // outputs at level 1. This is regardless of compact mode.
2069 void GotoNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2070   this->collect_nodes(in_rel, 1, false, false);
2071   this->collect_nodes(out_rel, -1, false, false);
2072 }
2073 #endif
2074 
2075 
2076 //=============================================================================
2077 const RegMask &JumpNode::out_RegMask() const {


2099   return RegMask::Empty;
2100 }
2101 
2102 
2103 
2104 //=============================================================================
2105 
2106 uint PCTableNode::hash() const { return Node::hash() + _size; }
2107 uint PCTableNode::cmp( const Node &n ) const
2108 { return _size == ((PCTableNode&)n)._size; }
2109 
2110 const Type *PCTableNode::bottom_type() const {
2111   const Type** f = TypeTuple::fields(_size);
2112   for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;
2113   return TypeTuple::make(_size, f);
2114 }
2115 
2116 //------------------------------Value------------------------------------------
2117 // Compute the type of the PCTableNode.  If reachable it is a tuple of
2118 // Control, otherwise the table targets are not reachable
2119 const Type* PCTableNode::Value(PhaseGVN* phase) const {
2120   if( phase->type(in(0)) == Type::CONTROL )
2121     return bottom_type();
2122   return Type::TOP;             // All paths dead?  Then so are we
2123 }
2124 
2125 //------------------------------Ideal------------------------------------------
2126 // Return a node which is more "ideal" than the current node.  Strip out
2127 // control copies
2128 Node *PCTableNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2129   return remove_dead_region(phase, can_reshape) ? this : NULL;
2130 }
2131 
2132 //=============================================================================
2133 uint JumpProjNode::hash() const {
2134   return Node::hash() + _dest_bci;
2135 }
2136 
2137 uint JumpProjNode::cmp( const Node &n ) const {
2138   return ProjNode::cmp(n) &&
2139     _dest_bci == ((JumpProjNode&)n)._dest_bci;


2144   ProjNode::dump_spec(st);
2145   st->print("@bci %d ",_dest_bci);
2146 }
2147 
2148 void JumpProjNode::dump_compact_spec(outputStream *st) const {
2149   ProjNode::dump_compact_spec(st);
2150   st->print("(%d)%d@%d", _switch_val, _proj_no, _dest_bci);
2151 }
2152 
2153 void JumpProjNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2154   // The related nodes of a JumpProjNode are its inputs and outputs at level 1.
2155   this->collect_nodes(in_rel, 1, false, false);
2156   this->collect_nodes(out_rel, -1, false, false);
2157 }
2158 #endif
2159 
2160 //=============================================================================
2161 //------------------------------Value------------------------------------------
2162 // Check for being unreachable, or for coming from a Rethrow.  Rethrow's cannot
2163 // have the default "fall_through_index" path.
2164 const Type* CatchNode::Value(PhaseGVN* phase) const {
2165   // Unreachable?  Then so are all paths from here.
2166   if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
2167   // First assume all paths are reachable
2168   const Type** f = TypeTuple::fields(_size);
2169   for( uint i = 0; i < _size; i++ ) f[i] = Type::CONTROL;
2170   // Identify cases that will always throw an exception
2171   // () rethrow call
2172   // () virtual or interface call with NULL receiver
2173   // () call is a check cast with incompatible arguments
2174   if( in(1)->is_Proj() ) {
2175     Node *i10 = in(1)->in(0);
2176     if( i10->is_Call() ) {
2177       CallNode *call = i10->as_Call();
2178       // Rethrows always throw exceptions, never return
2179       if (call->entry_point() == OptoRuntime::rethrow_stub()) {
2180         f[CatchProjNode::fall_through_index] = Type::TOP;
2181       } else if( call->req() > TypeFunc::Parms ) {
2182         const Type *arg0 = phase->type( call->in(TypeFunc::Parms) );
2183         // Check for null receiver to virtual or interface calls
2184         if( call->is_CallDynamicJava() &&


2188       } // End of if not a runtime stub
2189     } // End of if have call above me
2190   } // End of slot 1 is not a projection
2191   return TypeTuple::make(_size, f);
2192 }
2193 
2194 //=============================================================================
2195 uint CatchProjNode::hash() const {
2196   return Node::hash() + _handler_bci;
2197 }
2198 
2199 
2200 uint CatchProjNode::cmp( const Node &n ) const {
2201   return ProjNode::cmp(n) &&
2202     _handler_bci == ((CatchProjNode&)n)._handler_bci;
2203 }
2204 
2205 
2206 //------------------------------Identity---------------------------------------
2207 // If only 1 target is possible, choose it if it is the main control
2208 Node* CatchProjNode::Identity(PhaseGVN* phase) {
2209   // If my value is control and no other value is, then treat as ID
2210   const TypeTuple *t = phase->type(in(0))->is_tuple();
2211   if (t->field_at(_con) != Type::CONTROL)  return this;
2212   // If we remove the last CatchProj and elide the Catch/CatchProj, then we
2213   // also remove any exception table entry.  Thus we must know the call
2214   // feeding the Catch will not really throw an exception.  This is ok for
2215   // the main fall-thru control (happens when we know a call can never throw
2216   // an exception) or for "rethrow", because a further optimization will
2217   // yank the rethrow (happens when we inline a function that can throw an
2218   // exception and the caller has no handler).  Not legal, e.g., for passing
2219   // a NULL receiver to a v-call, or passing bad types to a slow-check-cast.
2220   // These cases MUST throw an exception via the runtime system, so the VM
2221   // will be looking for a table entry.
2222   Node *proj = in(0)->in(1);    // Expect a proj feeding CatchNode
2223   CallNode *call;
2224   if (_con != TypeFunc::Control && // Bail out if not the main control.
2225       !(proj->is_Proj() &&      // AND NOT a rethrow
2226         proj->in(0)->is_Call() &&
2227         (call = proj->in(0)->as_Call()) &&
2228         call->entry_point() == OptoRuntime::rethrow_stub()))


2231   // Search for any other path being control
2232   for (uint i = 0; i < t->cnt(); i++) {
2233     if (i != _con && t->field_at(i) == Type::CONTROL)
2234       return this;
2235   }
2236   // Only my path is possible; I am identity on control to the jump
2237   return in(0)->in(0);
2238 }
2239 
2240 
2241 #ifndef PRODUCT
2242 void CatchProjNode::dump_spec(outputStream *st) const {
2243   ProjNode::dump_spec(st);
2244   st->print("@bci %d ",_handler_bci);
2245 }
2246 #endif
2247 
2248 //=============================================================================
2249 //------------------------------Identity---------------------------------------
2250 // Check for CreateEx being Identity.
2251 Node* CreateExNode::Identity(PhaseGVN* phase) {
2252   if( phase->type(in(1)) == Type::TOP ) return in(1);
2253   if( phase->type(in(0)) == Type::TOP ) return in(0);
2254   // We only come from CatchProj, unless the CatchProj goes away.
2255   // If the CatchProj is optimized away, then we just carry the
2256   // exception oop through.
2257   CallNode *call = in(1)->in(0)->as_Call();
2258 
2259   return ( in(0)->is_CatchProj() && in(0)->in(0)->in(1) == in(1) )
2260     ? this
2261     : call->in(TypeFunc::Parms);
2262 }
2263 
2264 //=============================================================================
2265 //------------------------------Value------------------------------------------
2266 // Check for being unreachable.
2267 const Type* NeverBranchNode::Value(PhaseGVN* phase) const {
2268   if (!in(0) || in(0)->is_top()) return Type::TOP;
2269   return bottom_type();
2270 }
2271 
2272 //------------------------------Ideal------------------------------------------
2273 // Check for no longer being part of a loop
2274 Node *NeverBranchNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2275   if (can_reshape && !in(0)->is_Loop()) {
2276     // Dead code elimination can sometimes delete this projection so
2277     // if it's not there, there's nothing to do.
2278     Node* fallthru = proj_out(0);
2279     if (fallthru != NULL) {
2280       phase->is_IterGVN()->replace_node(fallthru, in(0));
2281     }
2282     return phase->C->top();
2283   }
2284   return NULL;
2285 }
2286 
2287 #ifndef PRODUCT
< prev index next >