148 149 // Find and remove n from block list 150 void Block::find_remove( const Node *n ) { 151 _nodes.remove(find_node(n)); 152 } 153 154 //------------------------------is_Empty--------------------------------------- 155 // Return empty status of a block. Empty blocks contain only the head, other 156 // ideal nodes, and an optional trailing goto. 157 int Block::is_Empty() const { 158 159 // Root or start block is not considered empty 160 if (head()->is_Root() || head()->is_Start()) { 161 return not_empty; 162 } 163 164 int success_result = completely_empty; 165 int end_idx = _nodes.size()-1; 166 167 // Check for ending goto 168 if ((end_idx > 0) && (_nodes[end_idx]->is_Goto())) { 169 success_result = empty_with_goto; 170 end_idx--; 171 } 172 173 // Unreachable blocks are considered empty 174 if (num_preds() <= 1) { 175 return success_result; 176 } 177 178 // Ideal nodes are allowable in empty blocks: skip them Only MachNodes 179 // turn directly into code, because only MachNodes have non-trivial 180 // emit() functions. 181 while ((end_idx > 0) && !_nodes[end_idx]->is_Mach()) { 182 end_idx--; 183 } 184 185 // No room for any interesting instructions? 186 if (end_idx == 0) { 187 return success_result; 188 } 189 190 return not_empty; 191 } 192 193 //------------------------------has_uncommon_code------------------------------ 194 // Return true if the block's code implies that it is likely to be 195 // executed infrequently. Check to see if the block ends in a Halt or 196 // a low probability call. 197 bool Block::has_uncommon_code() const { 198 Node* en = end(); 199 200 if (en->is_Goto()) 201 en = en->in(0); 202 if (en->is_Catch()) 203 en = en->in(0); 204 if (en->is_Proj() && en->in(0)->is_MachCall()) { 205 MachCallNode* call = en->in(0)->as_MachCall(); 206 if (call->cnt() != COUNT_UNKNOWN && call->cnt() <= PROB_UNLIKELY_MAG(4)) { 207 // This is true for slow-path stubs like new_{instance,array}, 208 // slow_arraycopy, complete_monitor_locking, uncommon_trap. 209 // The magic number corresponds to the probability of an uncommon_trap, 210 // even though it is a count not a probability. 211 return true; 212 } 213 } 214 215 int op = en->is_Mach() ? en->as_Mach()->ideal_Opcode() : en->Opcode(); 216 return op == Op_Halt; 217 } 218 219 //------------------------------is_uncommon------------------------------------ 220 // True if block is low enough frequency or guarded by a test which 221 // mostly does not go here. 222 bool Block::is_uncommon( Block_Array &bbs ) const { 223 // Initial blocks must never be moved, so are never uncommon. 224 if (head()->is_Root() || head()->is_Start()) return false; 928 is_loop = true; 929 break; // Some kind of loop 930 } 931 } 932 } 933 assert( is_loop || b->find_node(def) < j, "uses must follow definitions" ); 934 } 935 if( def->is_SafePointScalarObject() ) { 936 assert(_bbs[def->_idx] == b, "SafePointScalarObject Node should be at the same block as its SafePoint node"); 937 assert(_bbs[def->_idx] == _bbs[def->in(0)->_idx], "SafePointScalarObject Node should be at the same block as its control edge"); 938 } 939 } 940 } 941 } 942 943 j = b->end_idx(); 944 Node *bp = (Node*)b->_nodes[b->_nodes.size()-1]->is_block_proj(); 945 assert( bp, "last instruction must be a block proj" ); 946 assert( bp == b->_nodes[j], "wrong number of successors for this block" ); 947 if( bp->is_Catch() ) { 948 while( b->_nodes[--j]->Opcode() == Op_MachProj ) ; 949 assert( b->_nodes[j]->is_Call(), "CatchProj must follow call" ); 950 } 951 else if( bp->is_Mach() && bp->as_Mach()->ideal_Opcode() == Op_If ) { 952 assert( b->_num_succs == 2, "Conditional branch must have two targets"); 953 } 954 } 955 #endif 956 } 957 #endif 958 959 //============================================================================= 960 //------------------------------UnionFind-------------------------------------- 961 UnionFind::UnionFind( uint max ) : _cnt(max), _max(max), _indices(NEW_RESOURCE_ARRAY(uint,max)) { 962 Copy::zero_to_bytes( _indices, sizeof(uint)*max ); 963 } 964 965 void UnionFind::extend( uint from_idx, uint to_idx ) { 966 _nesting.check(); 967 if( from_idx >= _max ) { 968 uint size = 16; 969 while( size <= from_idx ) size <<=1; | 148 149 // Find and remove n from block list 150 void Block::find_remove( const Node *n ) { 151 _nodes.remove(find_node(n)); 152 } 153 154 //------------------------------is_Empty--------------------------------------- 155 // Return empty status of a block. Empty blocks contain only the head, other 156 // ideal nodes, and an optional trailing goto. 157 int Block::is_Empty() const { 158 159 // Root or start block is not considered empty 160 if (head()->is_Root() || head()->is_Start()) { 161 return not_empty; 162 } 163 164 int success_result = completely_empty; 165 int end_idx = _nodes.size()-1; 166 167 // Check for ending goto 168 if ((end_idx > 0) && (_nodes[end_idx]->is_MachGoto())) { 169 success_result = empty_with_goto; 170 end_idx--; 171 } 172 173 // Unreachable blocks are considered empty 174 if (num_preds() <= 1) { 175 return success_result; 176 } 177 178 // Ideal nodes are allowable in empty blocks: skip them Only MachNodes 179 // turn directly into code, because only MachNodes have non-trivial 180 // emit() functions. 181 while ((end_idx > 0) && !_nodes[end_idx]->is_Mach()) { 182 end_idx--; 183 } 184 185 // No room for any interesting instructions? 186 if (end_idx == 0) { 187 return success_result; 188 } 189 190 return not_empty; 191 } 192 193 //------------------------------has_uncommon_code------------------------------ 194 // Return true if the block's code implies that it is likely to be 195 // executed infrequently. Check to see if the block ends in a Halt or 196 // a low probability call. 197 bool Block::has_uncommon_code() const { 198 Node* en = end(); 199 200 if (en->is_MachGoto()) 201 en = en->in(0); 202 if (en->is_Catch()) 203 en = en->in(0); 204 if (en->is_MachProj() && en->in(0)->is_MachCall()) { 205 MachCallNode* call = en->in(0)->as_MachCall(); 206 if (call->cnt() != COUNT_UNKNOWN && call->cnt() <= PROB_UNLIKELY_MAG(4)) { 207 // This is true for slow-path stubs like new_{instance,array}, 208 // slow_arraycopy, complete_monitor_locking, uncommon_trap. 209 // The magic number corresponds to the probability of an uncommon_trap, 210 // even though it is a count not a probability. 211 return true; 212 } 213 } 214 215 int op = en->is_Mach() ? en->as_Mach()->ideal_Opcode() : en->Opcode(); 216 return op == Op_Halt; 217 } 218 219 //------------------------------is_uncommon------------------------------------ 220 // True if block is low enough frequency or guarded by a test which 221 // mostly does not go here. 222 bool Block::is_uncommon( Block_Array &bbs ) const { 223 // Initial blocks must never be moved, so are never uncommon. 224 if (head()->is_Root() || head()->is_Start()) return false; 928 is_loop = true; 929 break; // Some kind of loop 930 } 931 } 932 } 933 assert( is_loop || b->find_node(def) < j, "uses must follow definitions" ); 934 } 935 if( def->is_SafePointScalarObject() ) { 936 assert(_bbs[def->_idx] == b, "SafePointScalarObject Node should be at the same block as its SafePoint node"); 937 assert(_bbs[def->_idx] == _bbs[def->in(0)->_idx], "SafePointScalarObject Node should be at the same block as its control edge"); 938 } 939 } 940 } 941 } 942 943 j = b->end_idx(); 944 Node *bp = (Node*)b->_nodes[b->_nodes.size()-1]->is_block_proj(); 945 assert( bp, "last instruction must be a block proj" ); 946 assert( bp == b->_nodes[j], "wrong number of successors for this block" ); 947 if( bp->is_Catch() ) { 948 while( b->_nodes[--j]->is_MachProj() ) ; 949 assert( b->_nodes[j]->is_MachCall(), "CatchProj must follow call" ); 950 } 951 else if( bp->is_Mach() && bp->as_Mach()->ideal_Opcode() == Op_If ) { 952 assert( b->_num_succs == 2, "Conditional branch must have two targets"); 953 } 954 } 955 #endif 956 } 957 #endif 958 959 //============================================================================= 960 //------------------------------UnionFind-------------------------------------- 961 UnionFind::UnionFind( uint max ) : _cnt(max), _max(max), _indices(NEW_RESOURCE_ARRAY(uint,max)) { 962 Copy::zero_to_bytes( _indices, sizeof(uint)*max ); 963 } 964 965 void UnionFind::extend( uint from_idx, uint to_idx ) { 966 _nesting.check(); 967 if( from_idx >= _max ) { 968 uint size = 16; 969 while( size <= from_idx ) size <<=1; |