< prev index next >

src/hotspot/share/c1/c1_Instruction.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 "precompiled.hpp"
  26 #include "c1/c1_IR.hpp"
  27 #include "c1/c1_Instruction.hpp"
  28 #include "c1/c1_InstructionPrinter.hpp"
  29 #include "c1/c1_ValueStack.hpp"
  30 #include "ci/ciObjArrayKlass.hpp"
  31 #include "ci/ciTypeArrayKlass.hpp"


  32 
  33 
  34 // Implementation of Instruction
  35 
  36 
  37 int Instruction::dominator_depth() {
  38   int result = -1;
  39   if (block()) {
  40     result = block()->dominator_depth();
  41   }
  42   assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
  43   return result;
  44 }
  45 
  46 Instruction::Condition Instruction::mirror(Condition cond) {
  47   switch (cond) {
  48     case eql: return eql;
  49     case neq: return neq;
  50     case lss: return gtr;
  51     case leq: return geq;


  96 
  97 
  98 void Instruction::state_values_do(ValueVisitor* f) {
  99   if (state_before() != NULL) {
 100     state_before()->values_do(f);
 101   }
 102   if (exception_state() != NULL){
 103     exception_state()->values_do(f);
 104   }
 105 }
 106 
 107 ciType* Instruction::exact_type() const {
 108   ciType* t =  declared_type();
 109   if (t != NULL && t->is_klass()) {
 110     return t->as_klass()->exact_klass();
 111   }
 112   return NULL;
 113 }
 114 
 115 

































































 116 #ifndef PRODUCT
 117 void Instruction::check_state(ValueStack* state) {
 118   if (state != NULL) {
 119     state->verify();
 120   }
 121 }
 122 
 123 
 124 void Instruction::print() {
 125   InstructionPrinter ip;
 126   print(ip);
 127 }
 128 
 129 
 130 void Instruction::print_line() {
 131   InstructionPrinter ip;
 132   ip.print_line(this);
 133 }
 134 
 135 


 180       ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
 181       if (ik->is_loaded() && ik->is_final()) {
 182         return ik;
 183       }
 184     }
 185   }
 186   return Instruction::exact_type();
 187 }
 188 
 189 
 190 ciType* LoadIndexed::declared_type() const {
 191   ciType* array_type = array()->declared_type();
 192   if (array_type == NULL || !array_type->is_loaded()) {
 193     return NULL;
 194   }
 195   assert(array_type->is_array_klass(), "what else?");
 196   ciArrayKlass* ak = (ciArrayKlass*)array_type;
 197   return ak->element_type();
 198 }
 199 










 200 
 201 ciType* LoadField::declared_type() const {
 202   return field()->type();
 203 }
 204 
 205 
 206 ciType* NewTypeArray::exact_type() const {
 207   return ciTypeArrayKlass::make(elt_type());
 208 }
 209 
 210 ciType* NewObjectArray::exact_type() const {
 211   return ciObjArrayKlass::make(klass());









 212 }
 213 
 214 ciType* NewArray::declared_type() const {
 215   return exact_type();
 216 }
 217 
 218 ciType* NewInstance::exact_type() const {
 219   return klass();
 220 }
 221 
 222 ciType* NewInstance::declared_type() const {
 223   return exact_type();
 224 }
 225 

















 226 ciType* CheckCast::declared_type() const {
 227   return klass();
 228 }
 229 
 230 // Implementation of ArithmeticOp
 231 
 232 bool ArithmeticOp::is_commutative() const {
 233   switch (op()) {
 234     case Bytecodes::_iadd: // fall through
 235     case Bytecodes::_ladd: // fall through
 236     case Bytecodes::_fadd: // fall through
 237     case Bytecodes::_dadd: // fall through
 238     case Bytecodes::_imul: // fall through
 239     case Bytecodes::_lmul: // fall through
 240     case Bytecodes::_fmul: // fall through
 241     case Bytecodes::_dmul: return true;
 242     default              : return false;
 243   }
 244 }
 245 


 305   Instruction::state_values_do(f);
 306   if (state() != NULL) state()->values_do(f);
 307 }
 308 
 309 
 310 void BlockBegin::state_values_do(ValueVisitor* f) {
 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 // Implementation of Invoke
 322 
 323 
 324 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 325                int vtable_index, ciMethod* target, ValueStack* state_before)
 326   : StateSplit(result_type, state_before)
 327   , _code(code)
 328   , _recv(recv)
 329   , _args(args)
 330   , _vtable_index(vtable_index)
 331   , _target(target)
 332 {
 333   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 334   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 335   set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());

 336 
 337   assert(args != NULL, "args must exist");
 338 #ifdef ASSERT
 339   AssertValues assert_value;
 340   values_do(&assert_value);
 341 #endif
 342 
 343   // provide an initial guess of signature size.
 344   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 345   if (has_receiver()) {
 346     _signature->append(as_BasicType(receiver()->type()));
 347   }
 348   for (int i = 0; i < number_of_arguments(); i++) {
 349     ValueType* t = argument_at(i)->type();
 350     BasicType bt = as_BasicType(t);
 351     _signature->append(bt);
 352   }
 353 }
 354 
 355 


 774     // copy state because it is altered
 775     new_state = new_state->copy(ValueStack::BlockBeginState, bci());
 776 
 777     // Use method liveness to invalidate dead locals
 778     MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
 779     if (liveness.is_valid()) {
 780       assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
 781 
 782       for_each_local_value(new_state, index, new_value) {
 783         if (!liveness.at(index) || new_value->type()->is_illegal()) {
 784           new_state->invalidate_local(index);
 785           TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
 786         }
 787       }
 788     }
 789 
 790     if (is_set(BlockBegin::parser_loop_header_flag)) {
 791       TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
 792 
 793       for_each_stack_value(new_state, index, new_value) {
 794         new_state->setup_phi_for_stack(this, index);
 795         TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
 796       }
 797 
 798       BitMap& requires_phi_function = new_state->scope()->requires_phi_function();
 799 
 800       for_each_local_value(new_state, index, new_value) {
 801         bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
 802         if (requires_phi || !SelectivePhiFunctions) {
 803           new_state->setup_phi_for_local(this, index);
 804           TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
 805         }
 806       }
 807     }
 808 
 809     // initialize state of block
 810     set_state(new_state);
 811 
 812   } else if (existing_state->is_same(new_state)) {
 813     TRACE_PHI(tty->print_cr("exisiting state found"));
 814 
 815     assert(existing_state->scope() == new_state->scope(), "not matching");
 816     assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
 817     assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
 818 
 819     if (is_set(BlockBegin::was_visited_flag)) {
 820       TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
 821 
 822       if (!is_set(BlockBegin::parser_loop_header_flag)) {
 823         // this actually happens for complicated jsr/ret structures


 842 
 843 #ifdef ASSERT
 844       // check that all necessary phi functions are present
 845       for_each_stack_value(existing_state, index, existing_value) {
 846         assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
 847       }
 848       for_each_local_value(existing_state, index, existing_value) {
 849         assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
 850       }
 851 #endif
 852 
 853     } else {
 854       TRACE_PHI(tty->print_cr("creating phi functions on demand"));
 855 
 856       // create necessary phi functions for stack
 857       for_each_stack_value(existing_state, index, existing_value) {
 858         Value new_value = new_state->stack_at(index);
 859         Phi* existing_phi = existing_value->as_Phi();
 860 
 861         if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 862           existing_state->setup_phi_for_stack(this, index);
 863           TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
 864         }
 865       }
 866 
 867       // create necessary phi functions for locals
 868       for_each_local_value(existing_state, index, existing_value) {
 869         Value new_value = new_state->local_at(index);
 870         Phi* existing_phi = existing_value->as_Phi();
 871 
 872         if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
 873           existing_state->invalidate_local(index);
 874           TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
 875         } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 876           existing_state->setup_phi_for_local(this, index);
 877           TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
 878         }
 879       }
 880     }
 881 
 882     assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
 883 
 884   } else {
 885     assert(false, "stack or locks not matching (invalid bytecodes)");
 886     return false;
 887   }
 888 
 889   TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
 890 
 891   return true;
 892 }
 893 
 894 
 895 #ifndef PRODUCT
 896 void BlockBegin::print_block() {


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 "precompiled.hpp"
  26 #include "c1/c1_IR.hpp"
  27 #include "c1/c1_Instruction.hpp"
  28 #include "c1/c1_InstructionPrinter.hpp"
  29 #include "c1/c1_ValueStack.hpp"
  30 #include "ci/ciObjArrayKlass.hpp"
  31 #include "ci/ciTypeArrayKlass.hpp"
  32 #include "ci/ciValueArrayKlass.hpp"
  33 #include "ci/ciValueKlass.hpp"
  34 
  35 
  36 // Implementation of Instruction
  37 
  38 
  39 int Instruction::dominator_depth() {
  40   int result = -1;
  41   if (block()) {
  42     result = block()->dominator_depth();
  43   }
  44   assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
  45   return result;
  46 }
  47 
  48 Instruction::Condition Instruction::mirror(Condition cond) {
  49   switch (cond) {
  50     case eql: return eql;
  51     case neq: return neq;
  52     case lss: return gtr;
  53     case leq: return geq;


  98 
  99 
 100 void Instruction::state_values_do(ValueVisitor* f) {
 101   if (state_before() != NULL) {
 102     state_before()->values_do(f);
 103   }
 104   if (exception_state() != NULL){
 105     exception_state()->values_do(f);
 106   }
 107 }
 108 
 109 ciType* Instruction::exact_type() const {
 110   ciType* t =  declared_type();
 111   if (t != NULL && t->is_klass()) {
 112     return t->as_klass()->exact_klass();
 113   }
 114   return NULL;
 115 }
 116 
 117 
 118 // FIXME -- this is used by ValueStack::merge_types only. We should remove this function
 119 // and use a better way for handling phi nodes.
 120 bool Instruction::is_flattened_array() const {
 121   if (ValueArrayFlatten) {
 122     ciType* type = declared_type();
 123     if (type != NULL && type->is_value_array_klass()) {
 124       ciValueKlass* element_klass = type->as_value_array_klass()->element_klass()->as_value_klass();
 125       assert(element_klass->is_loaded(), "ciValueKlasses are always loaded");
 126       if (element_klass->flatten_array()) {
 127         return true;
 128       }
 129     }
 130   }
 131 
 132   return false;
 133 }
 134 
 135 bool Instruction::is_loaded_flattened_array() const {
 136   if (ValueArrayFlatten) {
 137     ciType* type = declared_type();
 138     if (type != NULL && type->is_value_array_klass()) {
 139       ciValueKlass* element_klass = type->as_value_array_klass()->element_klass()->as_value_klass();
 140       assert(element_klass->is_loaded(), "ciValueKlasses are always loaded");
 141       if (element_klass->flatten_array()) {
 142         return true;
 143       }
 144     }
 145   }
 146 
 147   return false;
 148 }
 149 
 150 bool Instruction::maybe_flattened_array() {
 151   if (ValueArrayFlatten) {
 152     ciType* type = declared_type();
 153     if (type != NULL) {
 154       if (type->is_value_array_klass()) {
 155         ciValueKlass* element_klass = type->as_value_array_klass()->element_klass()->as_value_klass();
 156         assert(element_klass->is_loaded(), "ciValueKlasses are always loaded");
 157         if (element_klass->flatten_array()) {
 158           return true;
 159         }
 160       } else if (type->is_obj_array_klass()) {
 161         ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
 162         if (!element_klass->is_loaded() || element_klass->is_java_lang_Object() || element_klass->is_interface()) {
 163           // Array covariance:
 164           //    (ValueType[] <: Object[])
 165           //    (ValueType[] <: <any interface>[])
 166           // We will add a runtime check for flat-ness.
 167           return true;
 168         }
 169       } else if (type->is_klass() && type->as_klass()->is_java_lang_Object()) {
 170         // This can happen as a parameter to System.arraycopy()
 171         return true;
 172       }
 173     } else if (as_Phi() != NULL) {
 174       // Type info gets lost during Phi merging, but we might be storing into a
 175       // flattened array, so we should do a runtime check.
 176       return true;
 177     }
 178   }
 179 
 180   return false;
 181 }
 182 
 183 #ifndef PRODUCT
 184 void Instruction::check_state(ValueStack* state) {
 185   if (state != NULL) {
 186     state->verify();
 187   }
 188 }
 189 
 190 
 191 void Instruction::print() {
 192   InstructionPrinter ip;
 193   print(ip);
 194 }
 195 
 196 
 197 void Instruction::print_line() {
 198   InstructionPrinter ip;
 199   ip.print_line(this);
 200 }
 201 
 202 


 247       ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
 248       if (ik->is_loaded() && ik->is_final()) {
 249         return ik;
 250       }
 251     }
 252   }
 253   return Instruction::exact_type();
 254 }
 255 
 256 
 257 ciType* LoadIndexed::declared_type() const {
 258   ciType* array_type = array()->declared_type();
 259   if (array_type == NULL || !array_type->is_loaded()) {
 260     return NULL;
 261   }
 262   assert(array_type->is_array_klass(), "what else?");
 263   ciArrayKlass* ak = (ciArrayKlass*)array_type;
 264   return ak->element_type();
 265 }
 266 
 267 bool StoreIndexed::is_exact_flattened_array_store() const {
 268   if (array()->is_loaded_flattened_array() && value()->as_Constant() == NULL) {
 269     ciKlass* element_klass = array()->declared_type()->as_value_array_klass()->element_klass();
 270     ciKlass* actual_klass = value()->declared_type()->as_klass();
 271     if (element_klass == actual_klass) {
 272       return true;
 273     }
 274   }
 275   return false;
 276 }
 277 
 278 ciType* LoadField::declared_type() const {
 279   return field()->type();
 280 }
 281 
 282 
 283 ciType* NewTypeArray::exact_type() const {
 284   return ciTypeArrayKlass::make(elt_type());
 285 }
 286 
 287 ciType* NewObjectArray::exact_type() const {
 288   ciKlass* element_klass = klass();
 289   if (element_klass->is_valuetype()) {
 290     return ciValueArrayKlass::make(element_klass);
 291   } else {
 292     return ciObjArrayKlass::make(element_klass);
 293   }
 294 }
 295 
 296 ciType* NewMultiArray::exact_type() const {
 297   return _klass;
 298 }
 299 
 300 ciType* NewArray::declared_type() const {
 301   return exact_type();
 302 }
 303 
 304 ciType* NewInstance::exact_type() const {
 305   return klass();
 306 }
 307 
 308 ciType* NewInstance::declared_type() const {
 309   return exact_type();
 310 }
 311 
 312 Value NewValueTypeInstance::depends_on() {
 313   if (_depends_on != this) {
 314     if (_depends_on->as_NewValueTypeInstance() != NULL) {
 315       return _depends_on->as_NewValueTypeInstance()->depends_on();
 316     }
 317   }
 318   return _depends_on;
 319 }
 320 
 321 ciType* NewValueTypeInstance::exact_type() const {
 322   return klass();
 323 }
 324 
 325 ciType* NewValueTypeInstance::declared_type() const {
 326   return exact_type();
 327 }
 328 
 329 ciType* CheckCast::declared_type() const {
 330   return klass();
 331 }
 332 
 333 // Implementation of ArithmeticOp
 334 
 335 bool ArithmeticOp::is_commutative() const {
 336   switch (op()) {
 337     case Bytecodes::_iadd: // fall through
 338     case Bytecodes::_ladd: // fall through
 339     case Bytecodes::_fadd: // fall through
 340     case Bytecodes::_dadd: // fall through
 341     case Bytecodes::_imul: // fall through
 342     case Bytecodes::_lmul: // fall through
 343     case Bytecodes::_fmul: // fall through
 344     case Bytecodes::_dmul: return true;
 345     default              : return false;
 346   }
 347 }
 348 


 408   Instruction::state_values_do(f);
 409   if (state() != NULL) state()->values_do(f);
 410 }
 411 
 412 
 413 void BlockBegin::state_values_do(ValueVisitor* f) {
 414   StateSplit::state_values_do(f);
 415 
 416   if (is_set(BlockBegin::exception_entry_flag)) {
 417     for (int i = 0; i < number_of_exception_states(); i++) {
 418       exception_state_at(i)->values_do(f);
 419     }
 420   }
 421 }
 422 
 423 
 424 // Implementation of Invoke
 425 
 426 
 427 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 428                int vtable_index, ciMethod* target, ValueStack* state_before, bool never_null)
 429   : StateSplit(result_type, state_before)
 430   , _code(code)
 431   , _recv(recv)
 432   , _args(args)
 433   , _vtable_index(vtable_index)
 434   , _target(target)
 435 {
 436   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 437   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 438   set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
 439   set_never_null(never_null);
 440 
 441   assert(args != NULL, "args must exist");
 442 #ifdef ASSERT
 443   AssertValues assert_value;
 444   values_do(&assert_value);
 445 #endif
 446 
 447   // provide an initial guess of signature size.
 448   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 449   if (has_receiver()) {
 450     _signature->append(as_BasicType(receiver()->type()));
 451   }
 452   for (int i = 0; i < number_of_arguments(); i++) {
 453     ValueType* t = argument_at(i)->type();
 454     BasicType bt = as_BasicType(t);
 455     _signature->append(bt);
 456   }
 457 }
 458 
 459 


 878     // copy state because it is altered
 879     new_state = new_state->copy(ValueStack::BlockBeginState, bci());
 880 
 881     // Use method liveness to invalidate dead locals
 882     MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
 883     if (liveness.is_valid()) {
 884       assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
 885 
 886       for_each_local_value(new_state, index, new_value) {
 887         if (!liveness.at(index) || new_value->type()->is_illegal()) {
 888           new_state->invalidate_local(index);
 889           TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
 890         }
 891       }
 892     }
 893 
 894     if (is_set(BlockBegin::parser_loop_header_flag)) {
 895       TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
 896 
 897       for_each_stack_value(new_state, index, new_value) {
 898         new_state->setup_phi_for_stack(this, index, NULL, new_value);
 899         TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
 900       }
 901 
 902       BitMap& requires_phi_function = new_state->scope()->requires_phi_function();
 903 
 904       for_each_local_value(new_state, index, new_value) {
 905         bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
 906         if (requires_phi || !SelectivePhiFunctions) {
 907           new_state->setup_phi_for_local(this, index, NULL, new_value);
 908           TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
 909         }
 910       }
 911     }
 912 
 913     // initialize state of block
 914     set_state(new_state);
 915 
 916   } else if (existing_state->is_same(new_state)) {
 917     TRACE_PHI(tty->print_cr("exisiting state found"));
 918 
 919     assert(existing_state->scope() == new_state->scope(), "not matching");
 920     assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
 921     assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
 922 
 923     if (is_set(BlockBegin::was_visited_flag)) {
 924       TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
 925 
 926       if (!is_set(BlockBegin::parser_loop_header_flag)) {
 927         // this actually happens for complicated jsr/ret structures


 946 
 947 #ifdef ASSERT
 948       // check that all necessary phi functions are present
 949       for_each_stack_value(existing_state, index, existing_value) {
 950         assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
 951       }
 952       for_each_local_value(existing_state, index, existing_value) {
 953         assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
 954       }
 955 #endif
 956 
 957     } else {
 958       TRACE_PHI(tty->print_cr("creating phi functions on demand"));
 959 
 960       // create necessary phi functions for stack
 961       for_each_stack_value(existing_state, index, existing_value) {
 962         Value new_value = new_state->stack_at(index);
 963         Phi* existing_phi = existing_value->as_Phi();
 964 
 965         if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 966           existing_state->setup_phi_for_stack(this, index, existing_value, new_value);
 967           TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
 968         }
 969       }
 970 
 971       // create necessary phi functions for locals
 972       for_each_local_value(existing_state, index, existing_value) {
 973         Value new_value = new_state->local_at(index);
 974         Phi* existing_phi = existing_value->as_Phi();
 975 
 976         if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
 977           existing_state->invalidate_local(index);
 978           TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
 979         } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 980           existing_state->setup_phi_for_local(this, index, existing_value, new_value);
 981           TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
 982         }
 983       }
 984     }
 985 
 986     assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
 987 
 988   } else {
 989     assert(false, "stack or locks not matching (invalid bytecodes)");
 990     return false;
 991   }
 992 
 993   TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
 994 
 995   return true;
 996 }
 997 
 998 
 999 #ifndef PRODUCT
1000 void BlockBegin::print_block() {


< prev index next >