hotspot/src/share/vm/c1/c1_IR.cpp
changeset 6745 a34ef8968a84
parent 6453 970dc585ab63
child 7100 6bcf9255d470
equal deleted inserted replaced
6743:ef1795cd50a7 6745:a34ef8968a84
   114   return true;
   114   return true;
   115 }
   115 }
   116 
   116 
   117 
   117 
   118 // Implementation of IRScope
   118 // Implementation of IRScope
   119 
       
   120 BlockBegin* IRScope::header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state) {
       
   121   if (entry == NULL) return NULL;
       
   122   assert(entry->is_set(f), "entry/flag mismatch");
       
   123   // create header block
       
   124   BlockBegin* h = new BlockBegin(entry->bci());
       
   125   BlockEnd* g = new Goto(entry, false);
       
   126   h->set_next(g, entry->bci());
       
   127   h->set_end(g);
       
   128   h->set(f);
       
   129   // setup header block end state
       
   130   ValueStack* s = state->copy(); // can use copy since stack is empty (=> no phis)
       
   131   assert(s->stack_is_empty(), "must have empty stack at entry point");
       
   132   g->set_state(s);
       
   133   return h;
       
   134 }
       
   135 
       
   136 
       
   137 BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) {
   119 BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) {
   138   GraphBuilder gm(compilation, this);
   120   GraphBuilder gm(compilation, this);
   139   NOT_PRODUCT(if (PrintValueNumbering && Verbose) gm.print_stats());
   121   NOT_PRODUCT(if (PrintValueNumbering && Verbose) gm.print_stats());
   140   if (compilation->bailed_out()) return NULL;
   122   if (compilation->bailed_out()) return NULL;
   141   return gm.start();
   123   return gm.start();
   143 
   125 
   144 
   126 
   145 IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph)
   127 IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph)
   146 : _callees(2)
   128 : _callees(2)
   147 , _compilation(compilation)
   129 , _compilation(compilation)
   148 , _lock_stack_size(-1)
       
   149 , _requires_phi_function(method->max_locals())
   130 , _requires_phi_function(method->max_locals())
   150 {
   131 {
   151   _caller             = caller;
   132   _caller             = caller;
   152   _caller_bci         = caller == NULL ? -1 : caller_bci;
       
   153   _caller_state       = NULL; // Must be set later if needed
       
   154   _level              = caller == NULL ?  0 : caller->level() + 1;
   133   _level              = caller == NULL ?  0 : caller->level() + 1;
   155   _method             = method;
   134   _method             = method;
   156   _xhandlers          = new XHandlers(method);
   135   _xhandlers          = new XHandlers(method);
   157   _number_of_locks    = 0;
   136   _number_of_locks    = 0;
   158   _monitor_pairing_ok = method->has_balanced_monitors();
   137   _monitor_pairing_ok = method->has_balanced_monitors();
   179     callee_max = MAX2(callee_max, callee_no(i)->max_stack());
   158     callee_max = MAX2(callee_max, callee_no(i)->max_stack());
   180   }
   159   }
   181   return my_max + callee_max;
   160   return my_max + callee_max;
   182 }
   161 }
   183 
   162 
   184 
       
   185 void IRScope::compute_lock_stack_size() {
       
   186   if (!InlineMethodsWithExceptionHandlers) {
       
   187     _lock_stack_size = 0;
       
   188     return;
       
   189   }
       
   190 
       
   191   // Figure out whether we have to preserve expression stack elements
       
   192   // for parent scopes, and if so, how many
       
   193   IRScope* cur_scope = this;
       
   194   while (cur_scope != NULL && !cur_scope->xhandlers()->has_handlers()) {
       
   195     cur_scope = cur_scope->caller();
       
   196   }
       
   197   _lock_stack_size = (cur_scope == NULL ? 0 :
       
   198                       (cur_scope->caller_state() == NULL ? 0 :
       
   199                        cur_scope->caller_state()->stack_size()));
       
   200 }
       
   201 
       
   202 int IRScope::top_scope_bci() const {
       
   203   assert(!is_top_scope(), "no correct answer for top scope possible");
       
   204   const IRScope* scope = this;
       
   205   while (!scope->caller()->is_top_scope()) {
       
   206     scope = scope->caller();
       
   207   }
       
   208   return scope->caller_bci();
       
   209 }
       
   210 
   163 
   211 bool IRScopeDebugInfo::should_reexecute() {
   164 bool IRScopeDebugInfo::should_reexecute() {
   212   ciMethod* cur_method = scope()->method();
   165   ciMethod* cur_method = scope()->method();
   213   int       cur_bci    = bci();
   166   int       cur_bci    = bci();
   214   if (cur_method != NULL && cur_bci != SynchronizationEntryBCI) {
   167   if (cur_method != NULL && cur_bci != SynchronizationEntryBCI) {
   220 
   173 
   221 
   174 
   222 // Implementation of CodeEmitInfo
   175 // Implementation of CodeEmitInfo
   223 
   176 
   224 // Stack must be NON-null
   177 // Stack must be NON-null
   225 CodeEmitInfo::CodeEmitInfo(int bci, ValueStack* stack, XHandlers* exception_handlers)
   178 CodeEmitInfo::CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers)
   226   : _scope(stack->scope())
   179   : _scope(stack->scope())
   227   , _bci(bci)
       
   228   , _scope_debug_info(NULL)
   180   , _scope_debug_info(NULL)
   229   , _oop_map(NULL)
   181   , _oop_map(NULL)
   230   , _stack(stack)
   182   , _stack(stack)
   231   , _exception_handlers(exception_handlers)
   183   , _exception_handlers(exception_handlers)
   232   , _next(NULL)
       
   233   , _id(-1)
       
   234   , _is_method_handle_invoke(false) {
   184   , _is_method_handle_invoke(false) {
   235   assert(_stack != NULL, "must be non null");
   185   assert(_stack != NULL, "must be non null");
   236   assert(_bci == SynchronizationEntryBCI || Bytecodes::is_defined(scope()->method()->java_code_at_bci(_bci)), "make sure bci points at a real bytecode");
   186 }
   237 }
   187 
   238 
   188 
   239 
   189 CodeEmitInfo::CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack)
   240 CodeEmitInfo::CodeEmitInfo(CodeEmitInfo* info, bool lock_stack_only)
       
   241   : _scope(info->_scope)
   190   : _scope(info->_scope)
   242   , _exception_handlers(NULL)
   191   , _exception_handlers(NULL)
   243   , _bci(info->_bci)
       
   244   , _scope_debug_info(NULL)
   192   , _scope_debug_info(NULL)
   245   , _oop_map(NULL)
   193   , _oop_map(NULL)
       
   194   , _stack(stack == NULL ? info->_stack : stack)
   246   , _is_method_handle_invoke(info->_is_method_handle_invoke) {
   195   , _is_method_handle_invoke(info->_is_method_handle_invoke) {
   247   if (lock_stack_only) {
       
   248     if (info->_stack != NULL) {
       
   249       _stack = info->_stack->copy_locks();
       
   250     } else {
       
   251       _stack = NULL;
       
   252     }
       
   253   } else {
       
   254     _stack = info->_stack;
       
   255   }
       
   256 
   196 
   257   // deep copy of exception handlers
   197   // deep copy of exception handlers
   258   if (info->_exception_handlers != NULL) {
   198   if (info->_exception_handlers != NULL) {
   259     _exception_handlers = new XHandlers(info->_exception_handlers);
   199     _exception_handlers = new XHandlers(info->_exception_handlers);
   260   }
   200   }
   271 
   211 
   272 void CodeEmitInfo::add_register_oop(LIR_Opr opr) {
   212 void CodeEmitInfo::add_register_oop(LIR_Opr opr) {
   273   assert(_oop_map != NULL, "oop map must already exist");
   213   assert(_oop_map != NULL, "oop map must already exist");
   274   assert(opr->is_single_cpu(), "should not call otherwise");
   214   assert(opr->is_single_cpu(), "should not call otherwise");
   275 
   215 
   276   int frame_size = frame_map()->framesize();
       
   277   int arg_count = frame_map()->oop_map_arg_count();
       
   278   VMReg name = frame_map()->regname(opr);
   216   VMReg name = frame_map()->regname(opr);
   279   _oop_map->set_oop(name);
   217   _oop_map->set_oop(name);
   280 }
   218 }
   281 
   219 
   282 
   220 
   381 class UseCountComputer: public ValueVisitor, BlockClosure {
   319 class UseCountComputer: public ValueVisitor, BlockClosure {
   382  private:
   320  private:
   383   void visit(Value* n) {
   321   void visit(Value* n) {
   384     // Local instructions and Phis for expression stack values at the
   322     // Local instructions and Phis for expression stack values at the
   385     // start of basic blocks are not added to the instruction list
   323     // start of basic blocks are not added to the instruction list
   386     if ((*n)->bci() == -99 && (*n)->as_Local() == NULL &&
   324     if (!(*n)->is_linked()&& (*n)->can_be_linked()) {
   387         (*n)->as_Phi() == NULL) {
       
   388       assert(false, "a node was not appended to the graph");
   325       assert(false, "a node was not appended to the graph");
   389       Compilation::current()->bailout("a node was not appended to the graph");
   326       Compilation::current()->bailout("a node was not appended to the graph");
   390     }
   327     }
   391     // use n's input if not visited before
   328     // use n's input if not visited before
   392     if (!(*n)->is_pinned() && !(*n)->has_uses()) {
   329     if (!(*n)->is_pinned() && !(*n)->has_uses()) {
  1336   for (Instruction* n = block; n != NULL;) {
  1273   for (Instruction* n = block; n != NULL;) {
  1337     n->values_do(this);
  1274     n->values_do(this);
  1338     // need to remove this instruction from the instruction stream
  1275     // need to remove this instruction from the instruction stream
  1339     if (n->subst() != n) {
  1276     if (n->subst() != n) {
  1340       assert(last != NULL, "must have last");
  1277       assert(last != NULL, "must have last");
  1341       last->set_next(n->next(), n->next()->bci());
  1278       last->set_next(n->next());
  1342     } else {
  1279     } else {
  1343       last = n;
  1280       last = n;
  1344     }
  1281     }
  1345     n = last->next();
  1282     n = last->next();
  1346   }
  1283   }