src/share/vm/c1/c1_Instruction.cpp

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "incls/_precompiled.incl"
  26 #include "incls/_c1_Instruction.cpp.incl"
  27 
  28 
  29 // Implementation of Instruction
  30 
  31 
  32 int Instruction::_next_id = 0;
  33 
  34 #ifdef ASSERT
  35 void Instruction::create_hi_word() {
  36   assert(type()->is_double_word() && _hi_word == NULL, "only double word has high word");
  37   _hi_word = new HiWord(this);
  38 }
  39 #endif
  40 
  41 Instruction::Condition Instruction::mirror(Condition cond) {
  42   switch (cond) {
  43     case eql: return eql;
  44     case neq: return neq;
  45     case lss: return gtr;
  46     case leq: return geq;
  47     case gtr: return lss;
  48     case geq: return leq;
  49   }
  50   ShouldNotReachHere();
  51   return eql;
  52 }
  53 


 176 ciType* NewInstance::exact_type() const {
 177   return klass();
 178 }
 179 
 180 
 181 ciType* CheckCast::declared_type() const {
 182   return klass();
 183 }
 184 
 185 ciType* CheckCast::exact_type() const {
 186   if (klass()->is_instance_klass()) {
 187     ciInstanceKlass* ik = (ciInstanceKlass*)klass();
 188     if (ik->is_loaded() && ik->is_final()) {
 189       return ik;
 190     }
 191   }
 192   return NULL;
 193 }
 194 
 195 
 196 void ArithmeticOp::other_values_do(void f(Value*)) {
 197   if (lock_stack() != NULL) lock_stack()->values_do(f);
 198 }
 199 
 200 void NullCheck::other_values_do(void f(Value*)) {
 201   lock_stack()->values_do(f);
 202 }
 203 
 204 void AccessArray::other_values_do(void f(Value*)) {
 205   if (lock_stack() != NULL) lock_stack()->values_do(f);
 206 }
 207 
 208 
 209 // Implementation of AccessField
 210 
 211 void AccessField::other_values_do(void f(Value*)) {
 212   if (state_before() != NULL) state_before()->values_do(f);
 213   if (lock_stack() != NULL) lock_stack()->values_do(f);
 214 }
 215 
 216 
 217 // Implementation of StoreIndexed
 218 
 219 IRScope* StoreIndexed::scope() const {
 220   return lock_stack()->scope();
 221 }
 222 
 223 
 224 // Implementation of ArithmeticOp
 225 
 226 bool ArithmeticOp::is_commutative() const {
 227   switch (op()) {
 228     case Bytecodes::_iadd: // fall through
 229     case Bytecodes::_ladd: // fall through
 230     case Bytecodes::_fadd: // fall through
 231     case Bytecodes::_dadd: // fall through


 253 
 254 bool LogicOp::is_commutative() const {
 255 #ifdef ASSERT
 256   switch (op()) {
 257     case Bytecodes::_iand: // fall through
 258     case Bytecodes::_land: // fall through
 259     case Bytecodes::_ior : // fall through
 260     case Bytecodes::_lor : // fall through
 261     case Bytecodes::_ixor: // fall through
 262     case Bytecodes::_lxor: break;
 263     default              : ShouldNotReachHere();
 264   }
 265 #endif
 266   // all LogicOps are commutative
 267   return true;
 268 }
 269 
 270 
 271 // Implementation of CompareOp
 272 
 273 void CompareOp::other_values_do(void f(Value*)) {
 274   if (state_before() != NULL) state_before()->values_do(f);
 275 }
 276 
 277 
 278 // Implementation of IfOp
 279 
 280 bool IfOp::is_commutative() const {
 281   return cond() == eql || cond() == neq;
 282 }
 283 
 284 
 285 // Implementation of StateSplit
 286 
 287 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
 288   NOT_PRODUCT(bool assigned = false;)
 289   for (int i = 0; i < list.length(); i++) {
 290     BlockBegin** b = list.adr_at(i);
 291     if (*b == old_block) {
 292       *b = new_block;
 293       NOT_PRODUCT(assigned = true;)
 294     }
 295   }
 296   assert(assigned == true, "should have assigned at least once");
 297 }
 298 
 299 
 300 IRScope* StateSplit::scope() const {
 301   return _state->scope();
 302 }
 303 
 304 
 305 void StateSplit::state_values_do(void f(Value*)) {
 306   if (state() != NULL) state()->values_do(f);
 307 }
 308 
 309 
 310 void BlockBegin::state_values_do(void f(Value*)) {
 311   StateSplit::state_values_do(f);
 312 
 313   if (is_set(BlockBegin::exception_entry_flag)) {
 314     for (int i = 0; i < number_of_exception_states(); i++) {
 315       exception_state_at(i)->values_do(f);
 316     }
 317   }
 318 }
 319 
 320 
 321 void MonitorEnter::state_values_do(void f(Value*)) {
 322   StateSplit::state_values_do(f);
 323   _lock_stack_before->values_do(f);
 324 }
 325 
 326 
 327 void Intrinsic::state_values_do(void f(Value*)) {
 328   StateSplit::state_values_do(f);
 329   if (lock_stack() != NULL) lock_stack()->values_do(f);
 330 }
 331 
 332 
 333 // Implementation of Invoke
 334 
 335 
 336 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 337                int vtable_index, ciMethod* target, ValueStack* state_before)
 338   : StateSplit(result_type)
 339   , _code(code)
 340   , _recv(recv)
 341   , _args(args)
 342   , _vtable_index(vtable_index)
 343   , _target(target)
 344   , _state_before(state_before)
 345 {
 346   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 347   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 348   set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
 349 
 350   assert(args != NULL, "args must exist");
 351 #ifdef ASSERT
 352   values_do(assert_value);
 353 #endif // ASSERT

 354 
 355   // provide an initial guess of signature size.
 356   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 357   if (has_receiver()) {
 358     _signature->append(as_BasicType(receiver()->type()));
 359   } else if (is_invokedynamic()) {
 360     // Add the synthetic MethodHandle argument to the signature.
 361     _signature->append(T_OBJECT);
 362   }
 363   for (int i = 0; i < number_of_arguments(); i++) {
 364     ValueType* t = argument_at(i)->type();
 365     BasicType bt = as_BasicType(t);
 366     _signature->append(bt);
 367   }
 368 }
 369 
 370 
 371 void Invoke::state_values_do(void f(Value*)) {
 372   StateSplit::state_values_do(f);
 373   if (state_before() != NULL) state_before()->values_do(f);
 374   if (state()        != NULL) state()->values_do(f);
 375 }
 376 
 377 
 378 // Implementation of Contant
 379 intx Constant::hash() const {
 380   if (_state == NULL) {
 381     switch (type()->tag()) {
 382     case intTag:
 383       return HASH2(name(), type()->as_IntConstant()->value());
 384     case longTag:
 385       {
 386         jlong temp = type()->as_LongConstant()->value();
 387         return HASH3(name(), high(temp), low(temp));
 388       }
 389     case floatTag:
 390       return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
 391     case doubleTag:


 483     }
 484     break;
 485   }
 486   case objectTag: {
 487     ciObject* xvalue = lt->as_ObjectType()->constant_value();
 488     ciObject* yvalue = rt->as_ObjectType()->constant_value();
 489     assert(xvalue != NULL && yvalue != NULL, "not constants");
 490     if (xvalue->is_loaded() && yvalue->is_loaded()) {
 491       switch (cond) {
 492       case If::eql: return xvalue == yvalue ? true_sux : false_sux;
 493       case If::neq: return xvalue != yvalue ? true_sux : false_sux;
 494       }
 495     }
 496     break;
 497   }
 498   }
 499   return NULL;
 500 }
 501 
 502 
 503 void Constant::other_values_do(void f(Value*)) {
 504   if (state() != NULL) state()->values_do(f);
 505 }
 506 
 507 
 508 // Implementation of NewArray
 509 
 510 void NewArray::other_values_do(void f(Value*)) {
 511   if (state_before() != NULL) state_before()->values_do(f);
 512 }
 513 
 514 
 515 // Implementation of TypeCheck
 516 
 517 void TypeCheck::other_values_do(void f(Value*)) {
 518   if (state_before() != NULL) state_before()->values_do(f);
 519 }
 520 
 521 
 522 // Implementation of BlockBegin
 523 
 524 int BlockBegin::_next_block_id = 0;
 525 
 526 
 527 void BlockBegin::set_end(BlockEnd* end) {
 528   assert(end != NULL, "should not reset block end to NULL");
 529   BlockEnd* old_end = _end;
 530   if (end == old_end) {
 531     return;
 532   }
 533   // Must make the predecessors/successors match up with the
 534   // BlockEnd's notion.
 535   int i, n;
 536   if (old_end != NULL) {
 537     // disconnect from the old end
 538     old_end->set_begin(NULL);
 539 
 540     // disconnect this block from it's current successors
 541     for (i = 0; i < _successors.length(); i++) {
 542       _successors.at(i)->remove_predecessor(this);
 543     }
 544   }
 545   _end = end;
 546 


 721     BlockEnd* e = end();
 722     { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
 723     { for (int i = e->number_of_sux            () - 1; i >= 0; i--) e->sux_at           (i)->iterate_postorder(mark, closure); }
 724     closure->block_do(this);
 725   }
 726 }
 727 
 728 
 729 void BlockBegin::iterate_preorder(BlockClosure* closure) {
 730   boolArray mark(number_of_blocks(), false);
 731   iterate_preorder(mark, closure);
 732 }
 733 
 734 
 735 void BlockBegin::iterate_postorder(BlockClosure* closure) {
 736   boolArray mark(number_of_blocks(), false);
 737   iterate_postorder(mark, closure);
 738 }
 739 
 740 
 741 void BlockBegin::block_values_do(void f(Value*)) {
 742   for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
 743 }
 744 
 745 
 746 #ifndef PRODUCT
 747   #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
 748 #else
 749   #define TRACE_PHI(coce)
 750 #endif
 751 
 752 
 753 bool BlockBegin::try_merge(ValueStack* new_state) {
 754   TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
 755 
 756   // local variables used for state iteration
 757   int index;
 758   Value new_value, existing_value;
 759 
 760   ValueStack* existing_state = state();
 761   if (existing_state == NULL) {


 913 
 914 
 915 // Implementation of BlockList
 916 
 917 void BlockList::iterate_forward (BlockClosure* closure) {
 918   const int l = length();
 919   for (int i = 0; i < l; i++) closure->block_do(at(i));
 920 }
 921 
 922 
 923 void BlockList::iterate_backward(BlockClosure* closure) {
 924   for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
 925 }
 926 
 927 
 928 void BlockList::blocks_do(void f(BlockBegin*)) {
 929   for (int i = length() - 1; i >= 0; i--) f(at(i));
 930 }
 931 
 932 
 933 void BlockList::values_do(void f(Value*)) {
 934   for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
 935 }
 936 
 937 
 938 #ifndef PRODUCT
 939 void BlockList::print(bool cfg_only, bool live_only) {
 940   InstructionPrinter ip;
 941   for (int i = 0; i < length(); i++) {
 942     BlockBegin* block = at(i);
 943     if (cfg_only) {
 944       ip.print_instr(block); tty->cr();
 945     } else {
 946       block->print_block(ip, live_only);
 947     }
 948   }
 949 }
 950 #endif // PRODUCT
 951 
 952 
 953 // Implementation of BlockEnd


 956   BlockList* sux = NULL;
 957   if (begin != NULL) {
 958     sux = begin->successors();
 959   } else if (_begin != NULL) {
 960     // copy our sux list
 961     BlockList* sux = new BlockList(_begin->number_of_sux());
 962     for (int i = 0; i < _begin->number_of_sux(); i++) {
 963       sux->append(_begin->sux_at(i));
 964     }
 965   }
 966   _sux = sux;
 967   _begin = begin;
 968 }
 969 
 970 
 971 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
 972   substitute(*_sux, old_sux, new_sux);
 973 }
 974 
 975 
 976 void BlockEnd::other_values_do(void f(Value*)) {
 977   if (state_before() != NULL) state_before()->values_do(f);
 978 }
 979 
 980 
 981 // Implementation of Phi
 982 
 983 // Normal phi functions take their operands from the last instruction of the
 984 // predecessor. Special handling is needed for xhanlder entries because there
 985 // the state of arbitrary instructions are needed.
 986 
 987 Value Phi::operand_at(int i) const {
 988   ValueStack* state;
 989   if (_block->is_set(BlockBegin::exception_entry_flag)) {
 990     state = _block->exception_state_at(i);
 991   } else {
 992     state = _block->pred_at(i)->end()->state();
 993   }
 994   assert(state != NULL, "");
 995 
 996   if (is_local()) {
 997     return state->local_at(local_index());
 998   } else {
 999     return state->stack_at(stack_index());
1000   }
1001 }
1002 
1003 
1004 int Phi::operand_count() const {
1005   if (_block->is_set(BlockBegin::exception_entry_flag)) {
1006     return _block->number_of_exception_states();
1007   } else {
1008     return _block->number_of_preds();
1009   }
1010 }
1011 
1012 
1013 // Implementation of Throw
1014 
1015 void Throw::state_values_do(void f(Value*)) {
1016   BlockEnd::state_values_do(f);
1017 }


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "incls/_precompiled.incl"
  26 #include "incls/_c1_Instruction.cpp.incl"
  27 
  28 
  29 // Implementation of Instruction
  30 
  31 


  32 #ifdef ASSERT
  33 void Instruction::create_hi_word() {
  34   assert(type()->is_double_word() && _hi_word == NULL, "only double word has high word");
  35   _hi_word = new HiWord(this);
  36 }
  37 #endif
  38 
  39 Instruction::Condition Instruction::mirror(Condition cond) {
  40   switch (cond) {
  41     case eql: return eql;
  42     case neq: return neq;
  43     case lss: return gtr;
  44     case leq: return geq;
  45     case gtr: return lss;
  46     case geq: return leq;
  47   }
  48   ShouldNotReachHere();
  49   return eql;
  50 }
  51 


 174 ciType* NewInstance::exact_type() const {
 175   return klass();
 176 }
 177 
 178 
 179 ciType* CheckCast::declared_type() const {
 180   return klass();
 181 }
 182 
 183 ciType* CheckCast::exact_type() const {
 184   if (klass()->is_instance_klass()) {
 185     ciInstanceKlass* ik = (ciInstanceKlass*)klass();
 186     if (ik->is_loaded() && ik->is_final()) {
 187       return ik;
 188     }
 189   }
 190   return NULL;
 191 }
 192 
 193 
 194 void ArithmeticOp::other_values_do(ValueVisitor* f) {
 195   if (lock_stack() != NULL) lock_stack()->values_do(f);
 196 }
 197 
 198 void NullCheck::other_values_do(ValueVisitor* f) {
 199   lock_stack()->values_do(f);
 200 }
 201 
 202 void AccessArray::other_values_do(ValueVisitor* f) {
 203   if (lock_stack() != NULL) lock_stack()->values_do(f);
 204 }
 205 
 206 
 207 // Implementation of AccessField
 208 
 209 void AccessField::other_values_do(ValueVisitor* f) {
 210   if (state_before() != NULL) state_before()->values_do(f);
 211   if (lock_stack() != NULL) lock_stack()->values_do(f);
 212 }
 213 
 214 
 215 // Implementation of StoreIndexed
 216 
 217 IRScope* StoreIndexed::scope() const {
 218   return lock_stack()->scope();
 219 }
 220 
 221 
 222 // Implementation of ArithmeticOp
 223 
 224 bool ArithmeticOp::is_commutative() const {
 225   switch (op()) {
 226     case Bytecodes::_iadd: // fall through
 227     case Bytecodes::_ladd: // fall through
 228     case Bytecodes::_fadd: // fall through
 229     case Bytecodes::_dadd: // fall through


 251 
 252 bool LogicOp::is_commutative() const {
 253 #ifdef ASSERT
 254   switch (op()) {
 255     case Bytecodes::_iand: // fall through
 256     case Bytecodes::_land: // fall through
 257     case Bytecodes::_ior : // fall through
 258     case Bytecodes::_lor : // fall through
 259     case Bytecodes::_ixor: // fall through
 260     case Bytecodes::_lxor: break;
 261     default              : ShouldNotReachHere();
 262   }
 263 #endif
 264   // all LogicOps are commutative
 265   return true;
 266 }
 267 
 268 
 269 // Implementation of CompareOp
 270 
 271 void CompareOp::other_values_do(ValueVisitor* f) {
 272   if (state_before() != NULL) state_before()->values_do(f);
 273 }
 274 
 275 
 276 // Implementation of IfOp
 277 
 278 bool IfOp::is_commutative() const {
 279   return cond() == eql || cond() == neq;
 280 }
 281 
 282 
 283 // Implementation of StateSplit
 284 
 285 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
 286   NOT_PRODUCT(bool assigned = false;)
 287   for (int i = 0; i < list.length(); i++) {
 288     BlockBegin** b = list.adr_at(i);
 289     if (*b == old_block) {
 290       *b = new_block;
 291       NOT_PRODUCT(assigned = true;)
 292     }
 293   }
 294   assert(assigned == true, "should have assigned at least once");
 295 }
 296 
 297 
 298 IRScope* StateSplit::scope() const {
 299   return _state->scope();
 300 }
 301 
 302 
 303 void StateSplit::state_values_do(ValueVisitor* f) {
 304   if (state() != NULL) state()->values_do(f);
 305 }
 306 
 307 
 308 void BlockBegin::state_values_do(ValueVisitor* f) {
 309   StateSplit::state_values_do(f);
 310 
 311   if (is_set(BlockBegin::exception_entry_flag)) {
 312     for (int i = 0; i < number_of_exception_states(); i++) {
 313       exception_state_at(i)->values_do(f);
 314     }
 315   }
 316 }
 317 
 318 
 319 void MonitorEnter::state_values_do(ValueVisitor* f) {
 320   StateSplit::state_values_do(f);
 321   _lock_stack_before->values_do(f);
 322 }
 323 
 324 
 325 void Intrinsic::state_values_do(ValueVisitor* f) {
 326   StateSplit::state_values_do(f);
 327   if (lock_stack() != NULL) lock_stack()->values_do(f);
 328 }
 329 
 330 
 331 // Implementation of Invoke
 332 
 333 
 334 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 335                int vtable_index, ciMethod* target, ValueStack* state_before)
 336   : StateSplit(result_type)
 337   , _code(code)
 338   , _recv(recv)
 339   , _args(args)
 340   , _vtable_index(vtable_index)
 341   , _target(target)
 342   , _state_before(state_before)
 343 {
 344   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 345   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 346   set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
 347 
 348   assert(args != NULL, "args must exist");
 349 #ifdef ASSERT
 350   AssertValues assert_value;
 351   values_do(&assert_value);
 352 #endif
 353 
 354   // provide an initial guess of signature size.
 355   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 356   if (has_receiver()) {
 357     _signature->append(as_BasicType(receiver()->type()));
 358   } else if (is_invokedynamic()) {
 359     // Add the synthetic MethodHandle argument to the signature.
 360     _signature->append(T_OBJECT);
 361   }
 362   for (int i = 0; i < number_of_arguments(); i++) {
 363     ValueType* t = argument_at(i)->type();
 364     BasicType bt = as_BasicType(t);
 365     _signature->append(bt);
 366   }
 367 }
 368 
 369 
 370 void Invoke::state_values_do(ValueVisitor* f) {
 371   StateSplit::state_values_do(f);
 372   if (state_before() != NULL) state_before()->values_do(f);
 373   if (state()        != NULL) state()->values_do(f);
 374 }
 375 
 376 
 377 // Implementation of Contant
 378 intx Constant::hash() const {
 379   if (_state == NULL) {
 380     switch (type()->tag()) {
 381     case intTag:
 382       return HASH2(name(), type()->as_IntConstant()->value());
 383     case longTag:
 384       {
 385         jlong temp = type()->as_LongConstant()->value();
 386         return HASH3(name(), high(temp), low(temp));
 387       }
 388     case floatTag:
 389       return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
 390     case doubleTag:


 482     }
 483     break;
 484   }
 485   case objectTag: {
 486     ciObject* xvalue = lt->as_ObjectType()->constant_value();
 487     ciObject* yvalue = rt->as_ObjectType()->constant_value();
 488     assert(xvalue != NULL && yvalue != NULL, "not constants");
 489     if (xvalue->is_loaded() && yvalue->is_loaded()) {
 490       switch (cond) {
 491       case If::eql: return xvalue == yvalue ? true_sux : false_sux;
 492       case If::neq: return xvalue != yvalue ? true_sux : false_sux;
 493       }
 494     }
 495     break;
 496   }
 497   }
 498   return NULL;
 499 }
 500 
 501 
 502 void Constant::other_values_do(ValueVisitor* f) {
 503   if (state() != NULL) state()->values_do(f);
 504 }
 505 
 506 
 507 // Implementation of NewArray
 508 
 509 void NewArray::other_values_do(ValueVisitor* f) {
 510   if (state_before() != NULL) state_before()->values_do(f);
 511 }
 512 
 513 
 514 // Implementation of TypeCheck
 515 
 516 void TypeCheck::other_values_do(ValueVisitor* f) {
 517   if (state_before() != NULL) state_before()->values_do(f);
 518 }
 519 
 520 
 521 // Implementation of BlockBegin
 522 



 523 void BlockBegin::set_end(BlockEnd* end) {
 524   assert(end != NULL, "should not reset block end to NULL");
 525   BlockEnd* old_end = _end;
 526   if (end == old_end) {
 527     return;
 528   }
 529   // Must make the predecessors/successors match up with the
 530   // BlockEnd's notion.
 531   int i, n;
 532   if (old_end != NULL) {
 533     // disconnect from the old end
 534     old_end->set_begin(NULL);
 535 
 536     // disconnect this block from it's current successors
 537     for (i = 0; i < _successors.length(); i++) {
 538       _successors.at(i)->remove_predecessor(this);
 539     }
 540   }
 541   _end = end;
 542 


 717     BlockEnd* e = end();
 718     { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
 719     { for (int i = e->number_of_sux            () - 1; i >= 0; i--) e->sux_at           (i)->iterate_postorder(mark, closure); }
 720     closure->block_do(this);
 721   }
 722 }
 723 
 724 
 725 void BlockBegin::iterate_preorder(BlockClosure* closure) {
 726   boolArray mark(number_of_blocks(), false);
 727   iterate_preorder(mark, closure);
 728 }
 729 
 730 
 731 void BlockBegin::iterate_postorder(BlockClosure* closure) {
 732   boolArray mark(number_of_blocks(), false);
 733   iterate_postorder(mark, closure);
 734 }
 735 
 736 
 737 void BlockBegin::block_values_do(ValueVisitor* f) {
 738   for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
 739 }
 740 
 741 
 742 #ifndef PRODUCT
 743   #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
 744 #else
 745   #define TRACE_PHI(coce)
 746 #endif
 747 
 748 
 749 bool BlockBegin::try_merge(ValueStack* new_state) {
 750   TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
 751 
 752   // local variables used for state iteration
 753   int index;
 754   Value new_value, existing_value;
 755 
 756   ValueStack* existing_state = state();
 757   if (existing_state == NULL) {


 909 
 910 
 911 // Implementation of BlockList
 912 
 913 void BlockList::iterate_forward (BlockClosure* closure) {
 914   const int l = length();
 915   for (int i = 0; i < l; i++) closure->block_do(at(i));
 916 }
 917 
 918 
 919 void BlockList::iterate_backward(BlockClosure* closure) {
 920   for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
 921 }
 922 
 923 
 924 void BlockList::blocks_do(void f(BlockBegin*)) {
 925   for (int i = length() - 1; i >= 0; i--) f(at(i));
 926 }
 927 
 928 
 929 void BlockList::values_do(ValueVisitor* f) {
 930   for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
 931 }
 932 
 933 
 934 #ifndef PRODUCT
 935 void BlockList::print(bool cfg_only, bool live_only) {
 936   InstructionPrinter ip;
 937   for (int i = 0; i < length(); i++) {
 938     BlockBegin* block = at(i);
 939     if (cfg_only) {
 940       ip.print_instr(block); tty->cr();
 941     } else {
 942       block->print_block(ip, live_only);
 943     }
 944   }
 945 }
 946 #endif // PRODUCT
 947 
 948 
 949 // Implementation of BlockEnd


 952   BlockList* sux = NULL;
 953   if (begin != NULL) {
 954     sux = begin->successors();
 955   } else if (_begin != NULL) {
 956     // copy our sux list
 957     BlockList* sux = new BlockList(_begin->number_of_sux());
 958     for (int i = 0; i < _begin->number_of_sux(); i++) {
 959       sux->append(_begin->sux_at(i));
 960     }
 961   }
 962   _sux = sux;
 963   _begin = begin;
 964 }
 965 
 966 
 967 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
 968   substitute(*_sux, old_sux, new_sux);
 969 }
 970 
 971 
 972 void BlockEnd::other_values_do(ValueVisitor* f) {
 973   if (state_before() != NULL) state_before()->values_do(f);
 974 }
 975 
 976 
 977 // Implementation of Phi
 978 
 979 // Normal phi functions take their operands from the last instruction of the
 980 // predecessor. Special handling is needed for xhanlder entries because there
 981 // the state of arbitrary instructions are needed.
 982 
 983 Value Phi::operand_at(int i) const {
 984   ValueStack* state;
 985   if (_block->is_set(BlockBegin::exception_entry_flag)) {
 986     state = _block->exception_state_at(i);
 987   } else {
 988     state = _block->pred_at(i)->end()->state();
 989   }
 990   assert(state != NULL, "");
 991 
 992   if (is_local()) {
 993     return state->local_at(local_index());
 994   } else {
 995     return state->stack_at(stack_index());
 996   }
 997 }
 998 
 999 
1000 int Phi::operand_count() const {
1001   if (_block->is_set(BlockBegin::exception_entry_flag)) {
1002     return _block->number_of_exception_states();
1003   } else {
1004     return _block->number_of_preds();
1005   }
1006 }
1007 
1008 
1009 // Implementation of Throw
1010 
1011 void Throw::state_values_do(ValueVisitor* f) {
1012   BlockEnd::state_values_do(f);
1013 }