src/share/vm/c1/c1_GraphBuilder.cpp

changeset 3969
1d7922586cf6
parent 3926
6d8f36bcef55
child 3970
977007096840
     1.1 --- a/src/share/vm/c1/c1_GraphBuilder.cpp	Mon Jul 23 13:04:59 2012 -0700
     1.2 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp	Tue Jul 24 10:51:00 2012 -0700
     1.3 @@ -31,7 +31,7 @@
     1.4  #include "ci/ciCallSite.hpp"
     1.5  #include "ci/ciField.hpp"
     1.6  #include "ci/ciKlass.hpp"
     1.7 -#include "ci/ciMethodHandle.hpp"
     1.8 +#include "ci/ciMemberName.hpp"
     1.9  #include "compiler/compileBroker.hpp"
    1.10  #include "interpreter/bytecode.hpp"
    1.11  #include "runtime/sharedRuntime.hpp"
    1.12 @@ -914,11 +914,11 @@
    1.13  
    1.14  void GraphBuilder::store_local(ValueType* type, int index) {
    1.15    Value x = pop(type);
    1.16 -  store_local(state(), x, type, index);
    1.17 +  store_local(state(), x, index);
    1.18  }
    1.19  
    1.20  
    1.21 -void GraphBuilder::store_local(ValueStack* state, Value x, ValueType* type, int index) {
    1.22 +void GraphBuilder::store_local(ValueStack* state, Value x, int index) {
    1.23    if (parsing_jsr()) {
    1.24      // We need to do additional tracking of the location of the return
    1.25      // address for jsrs since we don't handle arbitrary jsr/ret
    1.26 @@ -1535,7 +1535,7 @@
    1.27          case T_ARRAY:
    1.28          case T_OBJECT:
    1.29            if (field_val.as_object()->should_be_constant()) {
    1.30 -            constant =  new Constant(as_ValueType(field_val));
    1.31 +            constant = new Constant(as_ValueType(field_val));
    1.32            }
    1.33            break;
    1.34  
    1.35 @@ -1562,12 +1562,51 @@
    1.36          append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching));
    1.37        }
    1.38        break;
    1.39 -    case Bytecodes::_getfield :
    1.40 -      {
    1.41 +    case Bytecodes::_getfield: {
    1.42 +      // Check for compile-time constants, i.e., trusted final non-static fields.
    1.43 +      Instruction* constant = NULL;
    1.44 +      obj = apop();
    1.45 +      ObjectType* obj_type = obj->type()->as_ObjectType();
    1.46 +      if (obj_type->is_constant() && !PatchALot) {
    1.47 +        ciObject* const_oop = obj_type->constant_value();
    1.48 +        if (field->is_constant()) {
    1.49 +          ciConstant field_val = field->constant_value_of(const_oop);
    1.50 +          BasicType field_type = field_val.basic_type();
    1.51 +          switch (field_type) {
    1.52 +          case T_ARRAY:
    1.53 +          case T_OBJECT:
    1.54 +            if (field_val.as_object()->should_be_constant()) {
    1.55 +              constant = new Constant(as_ValueType(field_val));
    1.56 +            }
    1.57 +            break;
    1.58 +          default:
    1.59 +            constant = new Constant(as_ValueType(field_val));
    1.60 +          }
    1.61 +        } else {
    1.62 +          // For constant CallSites treat the target field as a compile time constant.
    1.63 +          if (const_oop->is_call_site()) {
    1.64 +            ciCallSite* call_site = const_oop->as_call_site();
    1.65 +            if (field->is_call_site_target()) {
    1.66 +              ciMethodHandle* target = call_site->get_target();
    1.67 +              if (target != NULL) {  // just in case
    1.68 +                ciConstant field_val(T_OBJECT, target);
    1.69 +                constant = new Constant(as_ValueType(field_val));
    1.70 +                // Add a dependence for invalidation of the optimization.
    1.71 +                if (!call_site->is_constant_call_site()) {
    1.72 +                  dependency_recorder()->assert_call_site_target_value(call_site, target);
    1.73 +                }
    1.74 +              }
    1.75 +            }
    1.76 +          }
    1.77 +        }
    1.78 +      }
    1.79 +      if (constant != NULL) {
    1.80 +        push(type, append(constant));
    1.81 +      } else {
    1.82          if (state_before == NULL) {
    1.83            state_before = copy_state_for_exception();
    1.84          }
    1.85 -        LoadField* load = new LoadField(apop(), offset, field, false, state_before, needs_patching);
    1.86 +        LoadField* load = new LoadField(obj, offset, field, false, state_before, needs_patching);
    1.87          Value replacement = !needs_patching ? _memory->load(load) : load;
    1.88          if (replacement != load) {
    1.89            assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked");
    1.90 @@ -1575,22 +1614,23 @@
    1.91          } else {
    1.92            push(type, append(load));
    1.93          }
    1.94 -        break;
    1.95 -      }
    1.96 -
    1.97 -    case Bytecodes::_putfield :
    1.98 -      { Value val = pop(type);
    1.99 -        if (state_before == NULL) {
   1.100 -          state_before = copy_state_for_exception();
   1.101 -        }
   1.102 -        StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, needs_patching);
   1.103 -        if (!needs_patching) store = _memory->store(store);
   1.104 -        if (store != NULL) {
   1.105 -          append(store);
   1.106 -        }
   1.107        }
   1.108        break;
   1.109 -    default                   :
   1.110 +    }
   1.111 +    case Bytecodes::_putfield: {
   1.112 +      Value val = pop(type);
   1.113 +      obj = apop();
   1.114 +      if (state_before == NULL) {
   1.115 +        state_before = copy_state_for_exception();
   1.116 +      }
   1.117 +      StoreField* store = new StoreField(obj, offset, field, val, false, state_before, needs_patching);
   1.118 +      if (!needs_patching) store = _memory->store(store);
   1.119 +      if (store != NULL) {
   1.120 +        append(store);
   1.121 +      }
   1.122 +      break;
   1.123 +    }
   1.124 +    default:
   1.125        ShouldNotReachHere();
   1.126        break;
   1.127    }
   1.128 @@ -1604,38 +1644,73 @@
   1.129  
   1.130  
   1.131  void GraphBuilder::invoke(Bytecodes::Code code) {
   1.132 +  const bool has_receiver =
   1.133 +    code == Bytecodes::_invokespecial   ||
   1.134 +    code == Bytecodes::_invokevirtual   ||
   1.135 +    code == Bytecodes::_invokeinterface;
   1.136 +  const bool is_invokedynamic = (code == Bytecodes::_invokedynamic);
   1.137 +
   1.138    bool will_link;
   1.139 -  ciMethod* target = stream()->get_method(will_link);
   1.140 +  ciMethod*             target = stream()->get_method(will_link);
   1.141 +  ciKlass*              holder = stream()->get_declared_method_holder();
   1.142 +  const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
   1.143 +
   1.144 +  // FIXME bail out for now
   1.145 +  if ((bc_raw == Bytecodes::_invokehandle || is_invokedynamic) && !will_link) {
   1.146 +    BAILOUT("unlinked call site (FIXME needs patching or recompile support)");
   1.147 +  }
   1.148 +
   1.149    // we have to make sure the argument size (incl. the receiver)
   1.150    // is correct for compilation (the call would fail later during
   1.151    // linkage anyway) - was bug (gri 7/28/99)
   1.152 -  if (target->is_loaded() && target->is_static() != (code == Bytecodes::_invokestatic)) BAILOUT("will cause link error");
   1.153 +  {
   1.154 +    // Use raw to get rewritten bytecode.
   1.155 +    const bool is_invokestatic = bc_raw == Bytecodes::_invokestatic;
   1.156 +    const bool allow_static =
   1.157 +          is_invokestatic ||
   1.158 +          bc_raw == Bytecodes::_invokehandle ||
   1.159 +          bc_raw == Bytecodes::_invokedynamic;
   1.160 +    if (target->is_loaded()) {
   1.161 +      if (( target->is_static() && !allow_static) ||
   1.162 +          (!target->is_static() &&  is_invokestatic)) {
   1.163 +        BAILOUT("will cause link error");
   1.164 +      }
   1.165 +    }
   1.166 +  }
   1.167    ciInstanceKlass* klass = target->holder();
   1.168  
   1.169    // check if CHA possible: if so, change the code to invoke_special
   1.170    ciInstanceKlass* calling_klass = method()->holder();
   1.171 -  ciKlass* holder = stream()->get_declared_method_holder();
   1.172    ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
   1.173    ciInstanceKlass* actual_recv = callee_holder;
   1.174  
   1.175 -  // some methods are obviously bindable without any type checks so
   1.176 -  // convert them directly to an invokespecial.
   1.177 -  if (target->is_loaded() && !target->is_abstract() &&
   1.178 -      target->can_be_statically_bound() && code == Bytecodes::_invokevirtual) {
   1.179 -    code = Bytecodes::_invokespecial;
   1.180 +  // Some methods are obviously bindable without any type checks so
   1.181 +  // convert them directly to an invokespecial or invokestatic.
   1.182 +  if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
   1.183 +    switch (bc_raw) {
   1.184 +    case Bytecodes::_invokevirtual:  code = Bytecodes::_invokespecial;  break;
   1.185 +    case Bytecodes::_invokehandle:   code = Bytecodes::_invokestatic;   break;
   1.186 +    }
   1.187    }
   1.188  
   1.189 -  bool is_invokedynamic = code == Bytecodes::_invokedynamic;
   1.190 +  // Push appendix argument (MethodType, CallSite, etc.), if one.
   1.191 +  if (stream()->has_appendix()) {
   1.192 +    ciObject* appendix = stream()->get_appendix();
   1.193 +    Value arg = append(new Constant(new ObjectConstant(appendix)));
   1.194 +    apush(arg);
   1.195 +  }
   1.196  
   1.197    // NEEDS_CLEANUP
   1.198 -  // I've added the target-is_loaded() test below but I don't really understand
   1.199 +  // I've added the target->is_loaded() test below but I don't really understand
   1.200    // how klass->is_loaded() can be true and yet target->is_loaded() is false.
   1.201    // this happened while running the JCK invokevirtual tests under doit.  TKR
   1.202    ciMethod* cha_monomorphic_target = NULL;
   1.203    ciMethod* exact_target = NULL;
   1.204    Value better_receiver = NULL;
   1.205    if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
   1.206 -      !target->is_method_handle_invoke()) {
   1.207 +      !(// %%% FIXME: Are both of these relevant?
   1.208 +        target->is_method_handle_intrinsic() ||
   1.209 +        target->is_compiled_lambda_form())) {
   1.210      Value receiver = NULL;
   1.211      ciInstanceKlass* receiver_klass = NULL;
   1.212      bool type_is_exact = false;
   1.213 @@ -1761,23 +1836,15 @@
   1.214          code == Bytecodes::_invokedynamic) {
   1.215        ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
   1.216        bool success = false;
   1.217 -      if (target->is_method_handle_invoke()) {
   1.218 +      if (target->is_method_handle_intrinsic()) {
   1.219          // method handle invokes
   1.220 -        success = !is_invokedynamic ? for_method_handle_inline(target) : for_invokedynamic_inline(target);
   1.221 -      }
   1.222 -      if (!success) {
   1.223 +        success = for_method_handle_inline(target);
   1.224 +      } else {
   1.225          // static binding => check if callee is ok
   1.226 -        success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), better_receiver);
   1.227 +        success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), code, better_receiver);
   1.228        }
   1.229        CHECK_BAILOUT();
   1.230  
   1.231 -#ifndef PRODUCT
   1.232 -      // printing
   1.233 -      if (PrintInlining && !success) {
   1.234 -        // if it was successfully inlined, then it was already printed.
   1.235 -        print_inline_result(inline_target, success);
   1.236 -      }
   1.237 -#endif
   1.238        clear_inline_bailout();
   1.239        if (success) {
   1.240          // Register dependence if JVMTI has either breakpoint
   1.241 @@ -1788,8 +1855,13 @@
   1.242          }
   1.243          return;
   1.244        }
   1.245 +    } else {
   1.246 +      print_inlining(target, "no static binding", /*success*/ false);
   1.247      }
   1.248 +  } else {
   1.249 +    print_inlining(target, "not inlineable", /*success*/ false);
   1.250    }
   1.251 +
   1.252    // If we attempted an inline which did not succeed because of a
   1.253    // bailout during construction of the callee graph, the entire
   1.254    // compilation has to be aborted. This is fairly rare and currently
   1.255 @@ -1803,10 +1875,6 @@
   1.256  
   1.257    // inlining not successful => standard invoke
   1.258    bool is_loaded = target->is_loaded();
   1.259 -  bool has_receiver =
   1.260 -    code == Bytecodes::_invokespecial   ||
   1.261 -    code == Bytecodes::_invokevirtual   ||
   1.262 -    code == Bytecodes::_invokeinterface;
   1.263    ValueType* result_type = as_ValueType(target->return_type());
   1.264  
   1.265    // We require the debug info to be the "state before" because
   1.266 @@ -1855,7 +1923,7 @@
   1.267        } else if (exact_target != NULL) {
   1.268          target_klass = exact_target->holder();
   1.269        }
   1.270 -      profile_call(recv, target_klass);
   1.271 +      profile_call(target, recv, target_klass);
   1.272      }
   1.273    }
   1.274  
   1.275 @@ -3097,30 +3165,61 @@
   1.276  }
   1.277  
   1.278  
   1.279 -bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, Value receiver) {
   1.280 -  // Clear out any existing inline bailout condition
   1.281 +bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, Bytecodes::Code bc, Value receiver) {
   1.282 +  const char* msg = NULL;
   1.283 +
   1.284 +  // clear out any existing inline bailout condition
   1.285    clear_inline_bailout();
   1.286  
   1.287 -  if (callee->should_exclude()) {
   1.288 -    // callee is excluded
   1.289 -    INLINE_BAILOUT("excluded by CompilerOracle")
   1.290 -  } else if (callee->should_not_inline()) {
   1.291 -    // callee is excluded
   1.292 -    INLINE_BAILOUT("disallowed by CompilerOracle")
   1.293 -  } else if (!callee->can_be_compiled()) {
   1.294 -    // callee is not compilable (prob. has breakpoints)
   1.295 -    INLINE_BAILOUT("not compilable (disabled)")
   1.296 -  } else if (callee->intrinsic_id() != vmIntrinsics::_none && try_inline_intrinsics(callee)) {
   1.297 -    // intrinsics can be native or not
   1.298 +  // exclude methods we don't want to inline
   1.299 +  msg = should_not_inline(callee);
   1.300 +  if (msg != NULL) {
   1.301 +    print_inlining(callee, msg, /*success*/ false);
   1.302 +    return false;
   1.303 +  }
   1.304 +
   1.305 +  // handle intrinsics
   1.306 +  if (callee->intrinsic_id() != vmIntrinsics::_none) {
   1.307 +    if (try_inline_intrinsics(callee)) {
   1.308 +      print_inlining(callee, "intrinsic");
   1.309 +      return true;
   1.310 +    }
   1.311 +    // try normal inlining
   1.312 +  }
   1.313 +
   1.314 +  // certain methods cannot be parsed at all
   1.315 +  msg = check_can_parse(callee);
   1.316 +  if (msg != NULL) {
   1.317 +    print_inlining(callee, msg, /*success*/ false);
   1.318 +    return false;
   1.319 +  }
   1.320 +
   1.321 +  // If bytecode not set use the current one.
   1.322 +  if (bc == Bytecodes::_illegal) {
   1.323 +    bc = code();
   1.324 +  }
   1.325 +  if (try_inline_full(callee, holder_known, bc, receiver))
   1.326      return true;
   1.327 -  } else if (callee->is_native()) {
   1.328 -    // non-intrinsic natives cannot be inlined
   1.329 -    INLINE_BAILOUT("non-intrinsic native")
   1.330 -  } else if (callee->is_abstract()) {
   1.331 -    INLINE_BAILOUT("abstract")
   1.332 -  } else {
   1.333 -    return try_inline_full(callee, holder_known, NULL, receiver);
   1.334 -  }
   1.335 +  print_inlining(callee, _inline_bailout_msg, /*success*/ false);
   1.336 +  return false;
   1.337 +}
   1.338 +
   1.339 +
   1.340 +const char* GraphBuilder::check_can_parse(ciMethod* callee) const {
   1.341 +  // Certain methods cannot be parsed at all:
   1.342 +  if ( callee->is_native())            return "native method";
   1.343 +  if ( callee->is_abstract())          return "abstract method";
   1.344 +  if (!callee->can_be_compiled())      return "not compilable (disabled)";
   1.345 +  return NULL;
   1.346 +}
   1.347 +
   1.348 +
   1.349 +// negative filter: should callee NOT be inlined?  returns NULL, ok to inline, or rejection msg
   1.350 +const char* GraphBuilder::should_not_inline(ciMethod* callee) const {
   1.351 +  if ( callee->should_exclude())       return "excluded by CompilerOracle";
   1.352 +  if ( callee->should_not_inline())    return "disallowed by CompilerOracle";
   1.353 +  if ( callee->dont_inline())          return "don't inline by annotation";
   1.354 +  return NULL;
   1.355  }
   1.356  
   1.357  
   1.358 @@ -3304,7 +3403,7 @@
   1.359            recv = args->at(0);
   1.360            null_check(recv);
   1.361          }
   1.362 -        profile_call(recv, NULL);
   1.363 +        profile_call(callee, recv, NULL);
   1.364        }
   1.365      }
   1.366    }
   1.367 @@ -3315,13 +3414,6 @@
   1.368    Value value = append_split(result);
   1.369    if (result_type != voidType) push(result_type, value);
   1.370  
   1.371 -#ifndef PRODUCT
   1.372 -  // printing
   1.373 -  if (PrintInlining) {
   1.374 -    print_inline_result(callee, true);
   1.375 -  }
   1.376 -#endif
   1.377 -
   1.378    // done
   1.379    return true;
   1.380  }
   1.381 @@ -3477,7 +3569,7 @@
   1.382  }
   1.383  
   1.384  
   1.385 -bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, BlockBegin* cont_block, Value receiver) {
   1.386 +bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, Bytecodes::Code bc, Value receiver) {
   1.387    assert(!callee->is_native(), "callee must not be native");
   1.388    if (CompilationPolicy::policy()->should_not_inline(compilation()->env(), callee)) {
   1.389      INLINE_BAILOUT("inlining prohibited by policy");
   1.390 @@ -3508,10 +3600,10 @@
   1.391    if (callee->force_inline() || callee->should_inline()) {
   1.392      // ignore heuristic controls on inlining
   1.393      if (callee->force_inline())
   1.394 -      CompileTask::print_inlining(callee, scope()->level(), bci(), "force inline by annotation");
   1.395 +      print_inlining(callee, "force inline by annotation");
   1.396    } else {
   1.397 -    if (inline_level() > MaxInlineLevel                         ) INLINE_BAILOUT("too-deep inlining");
   1.398 -    if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("too-deep recursive inlining");
   1.399 +    if (inline_level() > MaxInlineLevel                         ) INLINE_BAILOUT("inlining too deep");
   1.400 +    if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("recursive inlining too deep");
   1.401      if (callee->code_size_for_inlining() > max_inline_size()    ) INLINE_BAILOUT("callee is too large");
   1.402  
   1.403      // don't inline throwable methods unless the inlining tree is rooted in a throwable class
   1.404 @@ -3530,28 +3622,25 @@
   1.405      if (compilation()->env()->num_inlined_bytecodes() > DesiredMethodLimit) {
   1.406        INLINE_BAILOUT("total inlining greater than DesiredMethodLimit");
   1.407      }
   1.408 +    // printing
   1.409 +    print_inlining(callee, "");
   1.410    }
   1.411  
   1.412 -#ifndef PRODUCT
   1.413 -  // printing
   1.414 -  if (PrintInlining) {
   1.415 -    print_inline_result(callee, true);
   1.416 -  }
   1.417 -#endif
   1.418 -
   1.419    // NOTE: Bailouts from this point on, which occur at the
   1.420    // GraphBuilder level, do not cause bailout just of the inlining but
   1.421    // in fact of the entire compilation.
   1.422  
   1.423    BlockBegin* orig_block = block();
   1.424  
   1.425 +  const bool is_invokedynamic = bc == Bytecodes::_invokedynamic;
   1.426 +  const bool has_receiver = (bc != Bytecodes::_invokestatic && !is_invokedynamic);
   1.427 +
   1.428    const int args_base = state()->stack_size() - callee->arg_size();
   1.429    assert(args_base >= 0, "stack underflow during inlining");
   1.430  
   1.431    // Insert null check if necessary
   1.432    Value recv = NULL;
   1.433 -  if (code() != Bytecodes::_invokestatic &&
   1.434 -      code() != Bytecodes::_invokedynamic) {
   1.435 +  if (has_receiver) {
   1.436      // note: null check must happen even if first instruction of callee does
   1.437      //       an implicit null check since the callee is in a different scope
   1.438      //       and we must make sure exception handling does the right thing
   1.439 @@ -3567,7 +3656,7 @@
   1.440      compilation()->set_would_profile(true);
   1.441  
   1.442      if (profile_calls()) {
   1.443 -      profile_call(recv, holder_known ? callee->holder() : NULL);
   1.444 +      profile_call(callee, recv, holder_known ? callee->holder() : NULL);
   1.445      }
   1.446    }
   1.447  
   1.448 @@ -3576,7 +3665,7 @@
   1.449    // fall-through of control flow, all return instructions of the
   1.450    // callee will need to be replaced by Goto's pointing to this
   1.451    // continuation point.
   1.452 -  BlockBegin* cont = cont_block != NULL ? cont_block : block_at(next_bci());
   1.453 +  BlockBegin* cont = block_at(next_bci());
   1.454    bool continuation_existed = true;
   1.455    if (cont == NULL) {
   1.456      cont = new BlockBegin(next_bci());
   1.457 @@ -3609,17 +3698,10 @@
   1.458    // note: this will also ensure that all arguments are computed before being passed
   1.459    ValueStack* callee_state = state();
   1.460    ValueStack* caller_state = state()->caller_state();
   1.461 -  { int i = args_base;
   1.462 -    while (i < caller_state->stack_size()) {
   1.463 -      const int par_no = i - args_base;
   1.464 -      Value  arg = caller_state->stack_at_inc(i);
   1.465 -      // NOTE: take base() of arg->type() to avoid problems storing
   1.466 -      // constants
   1.467 -      if (receiver != NULL && par_no == 0) {
   1.468 -        arg = receiver;
   1.469 -      }
   1.470 -      store_local(callee_state, arg, arg->type()->base(), par_no);
   1.471 -    }
   1.472 +  for (int i = args_base; i < caller_state->stack_size(); ) {
   1.473 +    const int arg_no = i - args_base;
   1.474 +    Value arg = caller_state->stack_at_inc(i);
   1.475 +    store_local(callee_state, arg, arg_no);
   1.476    }
   1.477  
   1.478    // Remove args from stack.
   1.479 @@ -3695,29 +3777,27 @@
   1.480    // block merging. This allows load elimination and CSE to take place
   1.481    // across multiple callee scopes if they are relatively simple, and
   1.482    // is currently essential to making inlining profitable.
   1.483 -  if (cont_block == NULL) {
   1.484 -    if (num_returns() == 1
   1.485 -        && block() == orig_block
   1.486 -        && block() == inline_cleanup_block()) {
   1.487 -      _last  = inline_cleanup_return_prev();
   1.488 -      _state = inline_cleanup_state();
   1.489 -    } else if (continuation_preds == cont->number_of_preds()) {
   1.490 -      // Inlining caused that the instructions after the invoke in the
   1.491 -      // caller are not reachable any more. So skip filling this block
   1.492 -      // with instructions!
   1.493 -      assert(cont == continuation(), "");
   1.494 +  if (num_returns() == 1
   1.495 +      && block() == orig_block
   1.496 +      && block() == inline_cleanup_block()) {
   1.497 +    _last  = inline_cleanup_return_prev();
   1.498 +    _state = inline_cleanup_state();
   1.499 +  } else if (continuation_preds == cont->number_of_preds()) {
   1.500 +    // Inlining caused that the instructions after the invoke in the
   1.501 +    // caller are not reachable any more. So skip filling this block
   1.502 +    // with instructions!
   1.503 +    assert(cont == continuation(), "");
   1.504 +    assert(_last && _last->as_BlockEnd(), "");
   1.505 +    _skip_block = true;
   1.506 +  } else {
   1.507 +    // Resume parsing in continuation block unless it was already parsed.
   1.508 +    // Note that if we don't change _last here, iteration in
   1.509 +    // iterate_bytecodes_for_block will stop when we return.
   1.510 +    if (!continuation()->is_set(BlockBegin::was_visited_flag)) {
   1.511 +      // add continuation to work list instead of parsing it immediately
   1.512        assert(_last && _last->as_BlockEnd(), "");
   1.513 +      scope_data()->parent()->add_to_work_list(continuation());
   1.514        _skip_block = true;
   1.515 -    } else {
   1.516 -      // Resume parsing in continuation block unless it was already parsed.
   1.517 -      // Note that if we don't change _last here, iteration in
   1.518 -      // iterate_bytecodes_for_block will stop when we return.
   1.519 -      if (!continuation()->is_set(BlockBegin::was_visited_flag)) {
   1.520 -        // add continuation to work list instead of parsing it immediately
   1.521 -        assert(_last && _last->as_BlockEnd(), "");
   1.522 -        scope_data()->parent()->add_to_work_list(continuation());
   1.523 -        _skip_block = true;
   1.524 -      }
   1.525      }
   1.526    }
   1.527  
   1.528 @@ -3735,114 +3815,88 @@
   1.529  
   1.530  
   1.531  bool GraphBuilder::for_method_handle_inline(ciMethod* callee) {
   1.532 -  assert(!callee->is_static(), "change next line");
   1.533 -  int index = state()->stack_size() - (callee->arg_size_no_receiver() + 1);
   1.534 -  Value receiver = state()->stack_at(index);
   1.535 -
   1.536 -  if (receiver->type()->is_constant()) {
   1.537 -    ciMethodHandle* method_handle = receiver->type()->as_ObjectType()->constant_value()->as_method_handle();
   1.538 -
   1.539 -    // Set the callee to have access to the class and signature in
   1.540 -    // the MethodHandleCompiler.
   1.541 -    method_handle->set_callee(callee);
   1.542 -    method_handle->set_caller(method());
   1.543 -
   1.544 -    // Get an adapter for the MethodHandle.
   1.545 -    ciMethod* method_handle_adapter = method_handle->get_method_handle_adapter();
   1.546 -    if (method_handle_adapter != NULL) {
   1.547 -      return try_inline(method_handle_adapter, /*holder_known=*/ true);
   1.548 -    }
   1.549 -  } else if (receiver->as_CheckCast()) {
   1.550 -    // Match MethodHandle.selectAlternative idiom
   1.551 -    Phi* phi = receiver->as_CheckCast()->obj()->as_Phi();
   1.552 -
   1.553 -    if (phi != NULL && phi->operand_count() == 2) {
   1.554 -      // Get the two MethodHandle inputs from the Phi.
   1.555 -      Value op1 = phi->operand_at(0);
   1.556 -      Value op2 = phi->operand_at(1);
   1.557 -      ObjectType* op1type = op1->type()->as_ObjectType();
   1.558 -      ObjectType* op2type = op2->type()->as_ObjectType();
   1.559 -
   1.560 -      if (op1type->is_constant() && op2type->is_constant()) {
   1.561 -        ciMethodHandle* mh1 = op1type->constant_value()->as_method_handle();
   1.562 -        ciMethodHandle* mh2 = op2type->constant_value()->as_method_handle();
   1.563 -
   1.564 -        // Set the callee to have access to the class and signature in
   1.565 -        // the MethodHandleCompiler.
   1.566 -        mh1->set_callee(callee);
   1.567 -        mh1->set_caller(method());
   1.568 -        mh2->set_callee(callee);
   1.569 -        mh2->set_caller(method());
   1.570 -
   1.571 -        // Get adapters for the MethodHandles.
   1.572 -        ciMethod* mh1_adapter = mh1->get_method_handle_adapter();
   1.573 -        ciMethod* mh2_adapter = mh2->get_method_handle_adapter();
   1.574 -
   1.575 -        if (mh1_adapter != NULL && mh2_adapter != NULL) {
   1.576 -          set_inline_cleanup_info();
   1.577 -
   1.578 -          // Build the If guard
   1.579 -          BlockBegin* one = new BlockBegin(next_bci());
   1.580 -          BlockBegin* two = new BlockBegin(next_bci());
   1.581 -          BlockBegin* end = new BlockBegin(next_bci());
   1.582 -          Instruction* iff = append(new If(phi, If::eql, false, op1, one, two, NULL, false));
   1.583 -          block()->set_end(iff->as_BlockEnd());
   1.584 -
   1.585 -          // Connect up the states
   1.586 -          one->merge(block()->end()->state());
   1.587 -          two->merge(block()->end()->state());
   1.588 -
   1.589 -          // Save the state for the second inlinee
   1.590 -          ValueStack* state_before = copy_state_before();
   1.591 -
   1.592 -          // Parse first adapter
   1.593 -          _last = _block = one;
   1.594 -          if (!try_inline_full(mh1_adapter, /*holder_known=*/ true, end, NULL)) {
   1.595 -            restore_inline_cleanup_info();
   1.596 -            block()->clear_end();  // remove appended iff
   1.597 -            return false;
   1.598 -          }
   1.599 -
   1.600 -          // Parse second adapter
   1.601 -          _last = _block = two;
   1.602 -          _state = state_before;
   1.603 -          if (!try_inline_full(mh2_adapter, /*holder_known=*/ true, end, NULL)) {
   1.604 -            restore_inline_cleanup_info();
   1.605 -            block()->clear_end();  // remove appended iff
   1.606 -            return false;
   1.607 -          }
   1.608 -
   1.609 -          connect_to_end(end);
   1.610 +  ValueStack* state_before = state()->copy_for_parsing();
   1.611 +  vmIntrinsics::ID iid = callee->intrinsic_id();
   1.612 +  switch (iid) {
   1.613 +  case vmIntrinsics::_invokeBasic:
   1.614 +    {
   1.615 +      // get MethodHandle receiver
   1.616 +      const int args_base = state()->stack_size() - callee->arg_size();
   1.617 +      ValueType* type = state()->stack_at(args_base)->type();
   1.618 +      if (type->is_constant()) {
   1.619 +        ciMethod* target = type->as_ObjectType()->constant_value()->as_method_handle()->get_vmtarget();
   1.620 +        guarantee(!target->is_method_handle_intrinsic(), "should not happen");  // XXX remove
   1.621 +        Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
   1.622 +        if (try_inline(target, /*holder_known*/ true, bc)) {
   1.623            return true;
   1.624          }
   1.625 +      } else {
   1.626 +        print_inlining(callee, "receiver not constant", /*success*/ false);
   1.627        }
   1.628      }
   1.629 +    break;
   1.630 +
   1.631 +  case vmIntrinsics::_linkToVirtual:
   1.632 +  case vmIntrinsics::_linkToStatic:
   1.633 +  case vmIntrinsics::_linkToSpecial:
   1.634 +  case vmIntrinsics::_linkToInterface:
   1.635 +    {
   1.636 +      // pop MemberName argument
   1.637 +      const int args_base = state()->stack_size() - callee->arg_size();
   1.638 +      ValueType* type = apop()->type();
   1.639 +      if (type->is_constant()) {
   1.640 +        ciMethod* target = type->as_ObjectType()->constant_value()->as_member_name()->get_vmtarget();
   1.641 +        // If the target is another method handle invoke try recursivly to get
   1.642 +        // a better target.
   1.643 +        if (target->is_method_handle_intrinsic()) {
   1.644 +          if (for_method_handle_inline(target)) {
   1.645 +            return true;
   1.646 +          }
   1.647 +        } else {
   1.648 +          ciSignature* signature = target->signature();
   1.649 +          const int receiver_skip = target->is_static() ? 0 : 1;
   1.650 +          // Cast receiver to its type.
   1.651 +          if (!target->is_static()) {
   1.652 +            ciKlass* tk = signature->accessing_klass();
   1.653 +            Value obj = state()->stack_at(args_base);
   1.654 +            if (obj->exact_type() == NULL &&
   1.655 +                obj->declared_type() != tk && tk != compilation()->env()->Object_klass()) {
   1.656 +              TypeCast* c = new TypeCast(tk, obj, state_before);
   1.657 +              append(c);
   1.658 +              state()->stack_at_put(args_base, c);
   1.659 +            }
   1.660 +          }
   1.661 +          // Cast reference arguments to its type.
   1.662 +          for (int i = 0, j = 0; i < signature->count(); i++) {
   1.663 +            ciType* t = signature->type_at(i);
   1.664 +            if (t->is_klass()) {
   1.665 +              ciKlass* tk = t->as_klass();
   1.666 +              Value obj = state()->stack_at(args_base + receiver_skip + j);
   1.667 +              if (obj->exact_type() == NULL &&
   1.668 +                  obj->declared_type() != tk && tk != compilation()->env()->Object_klass()) {
   1.669 +                TypeCast* c = new TypeCast(t, obj, state_before);
   1.670 +                append(c);
   1.671 +                state()->stack_at_put(args_base + receiver_skip + j, c);
   1.672 +              }
   1.673 +            }
   1.674 +            j += t->size();  // long and double take two slots
   1.675 +          }
   1.676 +          Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
   1.677 +          if (try_inline(target, /*holder_known*/ true, bc)) {
   1.678 +            return true;
   1.679 +          }
   1.680 +        }
   1.681 +      } else {
   1.682 +        print_inlining(callee, "MemberName not constant", /*success*/ false);
   1.683 +      }
   1.684 +    }
   1.685 +    break;
   1.686 +
   1.687 +  default:
   1.688 +    fatal(err_msg("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
   1.689 +    break;
   1.690    }
   1.691 -  return false;
   1.692 -}
   1.693 -
   1.694 -
   1.695 -bool GraphBuilder::for_invokedynamic_inline(ciMethod* callee) {
   1.696 -  // Get the MethodHandle from the CallSite.
   1.697 -  ciCallSite*     call_site     = stream()->get_call_site();
   1.698 -  ciMethodHandle* method_handle = call_site->get_target();
   1.699 -
   1.700 -  // Set the callee to have access to the class and signature in the
   1.701 -  // MethodHandleCompiler.
   1.702 -  method_handle->set_callee(callee);
   1.703 -  method_handle->set_caller(method());
   1.704 -
   1.705 -  // Get an adapter for the MethodHandle.
   1.706 -  ciMethod* method_handle_adapter = method_handle->get_invokedynamic_adapter();
   1.707 -  if (method_handle_adapter != NULL) {
   1.708 -    if (try_inline(method_handle_adapter, /*holder_known=*/ true)) {
   1.709 -      // Add a dependence for invalidation of the optimization.
   1.710 -      if (!call_site->is_constant_call_site()) {
   1.711 -        dependency_recorder()->assert_call_site_target_value(call_site, method_handle);
   1.712 -      }
   1.713 -      return true;
   1.714 -    }
   1.715 -  }
   1.716 +  set_state(state_before);
   1.717    return false;
   1.718  }
   1.719  
   1.720 @@ -4034,22 +4088,24 @@
   1.721  }
   1.722  
   1.723  
   1.724 -#ifndef PRODUCT
   1.725 -void GraphBuilder::print_inline_result(ciMethod* callee, bool res) {
   1.726 -  CompileTask::print_inlining(callee, scope()->level(), bci(), _inline_bailout_msg);
   1.727 -  if (res && CIPrintMethodCodes) {
   1.728 +void GraphBuilder::print_inlining(ciMethod* callee, const char* msg, bool success) {
   1.729 +  if (!PrintInlining)  return;
   1.730 +  assert(msg != NULL, "must be");
   1.731 +  CompileTask::print_inlining(callee, scope()->level(), bci(), msg);
   1.732 +  if (success && CIPrintMethodCodes) {
   1.733      callee->print_codes();
   1.734    }
   1.735  }
   1.736  
   1.737  
   1.738 +#ifndef PRODUCT
   1.739  void GraphBuilder::print_stats() {
   1.740    vmap()->print();
   1.741  }
   1.742  #endif // PRODUCT
   1.743  
   1.744 -void GraphBuilder::profile_call(Value recv, ciKlass* known_holder) {
   1.745 -  append(new ProfileCall(method(), bci(), recv, known_holder));
   1.746 +void GraphBuilder::profile_call(ciMethod* callee, Value recv, ciKlass* known_holder) {
   1.747 +  append(new ProfileCall(method(), bci(), callee, recv, known_holder));
   1.748  }
   1.749  
   1.750  void GraphBuilder::profile_invocation(ciMethod* callee, ValueStack* state) {

mercurial