< prev index next >

src/hotspot/share/c1/c1_Instruction.cpp

Print this page


 810     // copy state because it is altered
 811     new_state = new_state->copy(ValueStack::BlockBeginState, bci());
 812 
 813     // Use method liveness to invalidate dead locals
 814     MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
 815     if (liveness.is_valid()) {
 816       assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
 817 
 818       for_each_local_value(new_state, index, new_value) {
 819         if (!liveness.at(index) || new_value->type()->is_illegal()) {
 820           new_state->invalidate_local(index);
 821           TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
 822         }
 823       }
 824     }
 825 
 826     if (is_set(BlockBegin::parser_loop_header_flag)) {
 827       TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
 828 
 829       for_each_stack_value(new_state, index, new_value) {
 830         new_state->setup_phi_for_stack(this, index);
 831         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));
 832       }
 833 
 834       BitMap& requires_phi_function = new_state->scope()->requires_phi_function();
 835 
 836       for_each_local_value(new_state, index, new_value) {
 837         bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
 838         if (requires_phi || !SelectivePhiFunctions) {
 839           new_state->setup_phi_for_local(this, index);
 840           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));
 841         }
 842       }
 843     }
 844 
 845     // initialize state of block
 846     set_state(new_state);
 847 
 848   } else if (existing_state->is_same(new_state)) {
 849     TRACE_PHI(tty->print_cr("exisiting state found"));
 850 
 851     assert(existing_state->scope() == new_state->scope(), "not matching");
 852     assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
 853     assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
 854 
 855     if (is_set(BlockBegin::was_visited_flag)) {
 856       TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
 857 
 858       if (!is_set(BlockBegin::parser_loop_header_flag)) {
 859         // this actually happens for complicated jsr/ret structures


 871 
 872 #ifdef ASSERT
 873       // check that all necessary phi functions are present
 874       for_each_stack_value(existing_state, index, existing_value) {
 875         assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
 876       }
 877       for_each_local_value(existing_state, index, existing_value) {
 878         assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
 879       }
 880 #endif
 881 
 882     } else {
 883       TRACE_PHI(tty->print_cr("creating phi functions on demand"));
 884 
 885       // create necessary phi functions for stack
 886       for_each_stack_value(existing_state, index, existing_value) {
 887         Value new_value = new_state->stack_at(index);
 888         Phi* existing_phi = existing_value->as_Phi();
 889 
 890         if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 891           existing_state->setup_phi_for_stack(this, index);
 892           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));
 893         }
 894       }
 895 
 896       // create necessary phi functions for locals
 897       for_each_local_value(existing_state, index, existing_value) {
 898         Value new_value = new_state->local_at(index);
 899         Phi* existing_phi = existing_value->as_Phi();
 900 
 901         if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
 902           existing_state->invalidate_local(index);
 903           TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
 904         } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 905           existing_state->setup_phi_for_local(this, index);
 906           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));
 907         }
 908       }
 909     }
 910 
 911     assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
 912 
 913   } else {
 914     assert(false, "stack or locks not matching (invalid bytecodes)");
 915     return false;
 916   }
 917 
 918   TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
 919 
 920   return true;
 921 }
 922 
 923 
 924 #ifndef PRODUCT
 925 void BlockBegin::print_block() {




 810     // copy state because it is altered
 811     new_state = new_state->copy(ValueStack::BlockBeginState, bci());
 812 
 813     // Use method liveness to invalidate dead locals
 814     MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
 815     if (liveness.is_valid()) {
 816       assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
 817 
 818       for_each_local_value(new_state, index, new_value) {
 819         if (!liveness.at(index) || new_value->type()->is_illegal()) {
 820           new_state->invalidate_local(index);
 821           TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
 822         }
 823       }
 824     }
 825 
 826     if (is_set(BlockBegin::parser_loop_header_flag)) {
 827       TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
 828 
 829       for_each_stack_value(new_state, index, new_value) {
 830         new_state->setup_phi_for_stack(this, index, NULL, new_value);
 831         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));
 832       }
 833 
 834       BitMap& requires_phi_function = new_state->scope()->requires_phi_function();
 835 
 836       for_each_local_value(new_state, index, new_value) {
 837         bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
 838         if (requires_phi || !SelectivePhiFunctions) {
 839           new_state->setup_phi_for_local(this, index, NULL, new_value);
 840           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));
 841         }
 842       }
 843     }
 844 
 845     // initialize state of block
 846     set_state(new_state);
 847 
 848   } else if (existing_state->is_same(new_state)) {
 849     TRACE_PHI(tty->print_cr("exisiting state found"));
 850 
 851     assert(existing_state->scope() == new_state->scope(), "not matching");
 852     assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
 853     assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
 854 
 855     if (is_set(BlockBegin::was_visited_flag)) {
 856       TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
 857 
 858       if (!is_set(BlockBegin::parser_loop_header_flag)) {
 859         // this actually happens for complicated jsr/ret structures


 871 
 872 #ifdef ASSERT
 873       // check that all necessary phi functions are present
 874       for_each_stack_value(existing_state, index, existing_value) {
 875         assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
 876       }
 877       for_each_local_value(existing_state, index, existing_value) {
 878         assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
 879       }
 880 #endif
 881 
 882     } else {
 883       TRACE_PHI(tty->print_cr("creating phi functions on demand"));
 884 
 885       // create necessary phi functions for stack
 886       for_each_stack_value(existing_state, index, existing_value) {
 887         Value new_value = new_state->stack_at(index);
 888         Phi* existing_phi = existing_value->as_Phi();
 889 
 890         if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 891           existing_state->setup_phi_for_stack(this, index, existing_value, new_value);
 892           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));
 893         }
 894       }
 895 
 896       // create necessary phi functions for locals
 897       for_each_local_value(existing_state, index, existing_value) {
 898         Value new_value = new_state->local_at(index);
 899         Phi* existing_phi = existing_value->as_Phi();
 900 
 901         if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
 902           existing_state->invalidate_local(index);
 903           TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
 904         } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
 905           existing_state->setup_phi_for_local(this, index, existing_value, new_value);
 906           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));
 907         }
 908       }
 909     }
 910 
 911     assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
 912 
 913   } else {
 914     assert(false, "stack or locks not matching (invalid bytecodes)");
 915     return false;
 916   }
 917 
 918   TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
 919 
 920   return true;
 921 }
 922 
 923 
 924 #ifndef PRODUCT
 925 void BlockBegin::print_block() {


< prev index next >