Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/vm/runtime/sharedRuntime.cpp
          +++ new/src/share/vm/runtime/sharedRuntime.cpp
↓ open down ↓ 248 lines elided ↑ open up ↑
 249  249  JRT_LEAF(jdouble, SharedRuntime::l2d(jlong x))
 250  250    return (jdouble)x;
 251  251  JRT_END
 252  252  
 253  253  // Exception handling accross interpreter/compiler boundaries
 254  254  //
 255  255  // exception_handler_for_return_address(...) returns the continuation address.
 256  256  // The continuation address is the entry point of the exception handler of the
 257  257  // previous frame depending on the return address.
 258  258  
 259      -address SharedRuntime::raw_exception_handler_for_return_address(address return_address) {
      259 +address SharedRuntime::raw_exception_handler_for_return_address(JavaThread* thread, address return_address) {
 260  260    assert(frame::verify_return_pc(return_address), "must be a return pc");
 261  261  
 262  262    // the fastest case first
 263  263    CodeBlob* blob = CodeCache::find_blob(return_address);
 264  264    if (blob != NULL && blob->is_nmethod()) {
 265  265      nmethod* code = (nmethod*)blob;
 266  266      assert(code != NULL, "nmethod must be present");
      267 +    // Check if the return address is a MethodHandle call site.
      268 +    thread->set_is_method_handle_exception(code->is_method_handle_return(return_address));
 267  269      // native nmethods don't have exception handlers
 268  270      assert(!code->is_native_method(), "no exception handler");
 269  271      assert(code->header_begin() != code->exception_begin(), "no exception handler");
 270  272      if (code->is_deopt_pc(return_address)) {
 271  273        return SharedRuntime::deopt_blob()->unpack_with_exception();
 272  274      } else {
 273  275        return code->exception_begin();
 274  276      }
 275  277    }
 276  278  
↓ open down ↓ 5 lines elided ↑ open up ↑
 282  284    if (Interpreter::contains(return_address)) {
 283  285      return Interpreter::rethrow_exception_entry();
 284  286    }
 285  287  
 286  288    // Compiled code
 287  289    if (CodeCache::contains(return_address)) {
 288  290      CodeBlob* blob = CodeCache::find_blob(return_address);
 289  291      if (blob->is_nmethod()) {
 290  292        nmethod* code = (nmethod*)blob;
 291  293        assert(code != NULL, "nmethod must be present");
      294 +      // Check if the return address is a MethodHandle call site.
      295 +      thread->set_is_method_handle_exception(code->is_method_handle_return(return_address));
 292  296        assert(code->header_begin() != code->exception_begin(), "no exception handler");
 293  297        return code->exception_begin();
 294  298      }
 295  299      if (blob->is_runtime_stub()) {
 296  300        ShouldNotReachHere();   // callers are responsible for skipping runtime stub frames
 297  301      }
 298  302    }
 299  303    guarantee(!VtableStubs::contains(return_address), "NULL exceptions in vtables should have been handled already!");
 300  304  #ifndef PRODUCT
 301  305    { ResourceMark rm;
 302  306      tty->print_cr("No exception handler found for exception at " INTPTR_FORMAT " - potential problems:", return_address);
 303  307      tty->print_cr("a) exception happened in (new?) code stubs/buffers that is not handled here");
 304  308      tty->print_cr("b) other problem");
 305  309    }
 306  310  #endif // PRODUCT
 307  311    ShouldNotReachHere();
 308  312    return NULL;
 309  313  }
 310  314  
 311  315  
 312      -JRT_LEAF(address, SharedRuntime::exception_handler_for_return_address(address return_address))
 313      -  return raw_exception_handler_for_return_address(return_address);
      316 +JRT_LEAF(address, SharedRuntime::exception_handler_for_return_address(JavaThread* thread, address return_address))
      317 +  return raw_exception_handler_for_return_address(thread, return_address);
 314  318  JRT_END
 315  319  
      320 +
 316  321  address SharedRuntime::get_poll_stub(address pc) {
 317  322    address stub;
 318  323    // Look up the code blob
 319  324    CodeBlob *cb = CodeCache::find_blob(pc);
 320  325  
 321  326    // Should be an nmethod
 322  327    assert( cb && cb->is_nmethod(), "safepoint polling: pc must refer to an nmethod" );
 323  328  
 324  329    // Look up the relocation information
 325  330    assert( ((nmethod*)cb)->is_at_poll_or_poll_return(pc),
↓ open down ↓ 132 lines elided ↑ open up ↑
 458  463    if (t == NULL && (nm->is_compiled_by_c1() || handler_bci != -1)) {
 459  464      // Allow abbreviated catch tables.  The idea is to allow a method
 460  465      // to materialize its exceptions without committing to the exact
 461  466      // routing of exceptions.  In particular this is needed for adding
 462  467      // a synthethic handler to unlock monitors when inlining
 463  468      // synchonized methods since the unlock path isn't represented in
 464  469      // the bytecodes.
 465  470      t = table.entry_for(catch_pco, -1, 0);
 466  471    }
 467  472  
 468      -#ifdef COMPILER1
 469      -  if (nm->is_compiled_by_c1() && t == NULL && handler_bci == -1) {
 470      -    // Exception is not handled by this frame so unwind.  Note that
 471      -    // this is not the same as how C2 does this.  C2 emits a table
 472      -    // entry that dispatches to the unwind code in the nmethod.
 473      -    return NULL;
 474      -  }
 475      -#endif /* COMPILER1 */
 476      -
 477      -
 478  473    if (t == NULL) {
 479  474      tty->print_cr("MISSING EXCEPTION HANDLER for pc " INTPTR_FORMAT " and handler bci %d", ret_pc, handler_bci);
 480  475      tty->print_cr("   Exception:");
 481  476      exception->print();
 482  477      tty->cr();
 483  478      tty->print_cr(" Compiled exception table :");
 484  479      table.print();
 485  480      nm->print_code();
 486  481      guarantee(false, "missing exception handler");
 487  482      return NULL;
↓ open down ↓ 397 lines elided ↑ open up ↑
 885  880  // Resolves a call.  The compilers generate code for calls that go here
 886  881  // and are patched with the real destination of the call.
 887  882  methodHandle SharedRuntime::resolve_sub_helper(JavaThread *thread,
 888  883                                             bool is_virtual,
 889  884                                             bool is_optimized, TRAPS) {
 890  885  
 891  886    ResourceMark rm(thread);
 892  887    RegisterMap cbl_map(thread, false);
 893  888    frame caller_frame = thread->last_frame().sender(&cbl_map);
 894  889  
 895      -  CodeBlob* cb = caller_frame.cb();
 896      -  guarantee(cb != NULL && cb->is_nmethod(), "must be called from nmethod");
      890 +  CodeBlob* caller_cb = caller_frame.cb();
      891 +  guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
      892 +  nmethod* caller_nm = caller_cb->as_nmethod_or_null();
 897  893    // make sure caller is not getting deoptimized
 898  894    // and removed before we are done with it.
 899  895    // CLEANUP - with lazy deopt shouldn't need this lock
 900      -  nmethodLocker caller_lock((nmethod*)cb);
      896 +  nmethodLocker caller_lock(caller_nm);
 901  897  
 902  898  
 903  899    // determine call info & receiver
 904  900    // note: a) receiver is NULL for static calls
 905  901    //       b) an exception is thrown if receiver is NULL for non-static calls
 906  902    CallInfo call_info;
 907  903    Bytecodes::Code invoke_code = Bytecodes::_illegal;
 908  904    Handle receiver = find_callee_info(thread, invoke_code,
 909  905                                       call_info, CHECK_(methodHandle()));
 910  906    methodHandle callee_method = call_info.selected_method();
↓ open down ↓ 11 lines elided ↑ open up ↑
 922  918    if (TraceCallFixup) {
 923  919      ResourceMark rm(thread);
 924  920      tty->print("resolving %s%s (%s) call to",
 925  921        (is_optimized) ? "optimized " : "", (is_virtual) ? "virtual" : "static",
 926  922        Bytecodes::name(invoke_code));
 927  923      callee_method->print_short_name(tty);
 928  924      tty->print_cr(" code: " INTPTR_FORMAT, callee_method->code());
 929  925    }
 930  926  #endif
 931  927  
      928 +  // JSR 292
      929 +  // If the resolved method is a MethodHandle invoke target the call
      930 +  // site must be a MethodHandle call site.
      931 +  if (callee_method->is_method_handle_invoke()) {
      932 +    assert(caller_nm->is_method_handle_return(caller_frame.pc()), "must be MH call site");
      933 +  }
      934 +
 932  935    // Compute entry points. This might require generation of C2I converter
 933  936    // frames, so we cannot be holding any locks here. Furthermore, the
 934  937    // computation of the entry points is independent of patching the call.  We
 935  938    // always return the entry-point, but we only patch the stub if the call has
 936  939    // not been deoptimized.  Return values: For a virtual call this is an
 937  940    // (cached_oop, destination address) pair. For a static call/optimized
 938  941    // virtual this is just a destination address.
 939  942  
 940  943    StaticCallInfo static_call_info;
 941  944    CompiledICInfo virtual_call_info;
 942  945  
 943      -
 944  946    // Make sure the callee nmethod does not get deoptimized and removed before
 945  947    // we are done patching the code.
 946      -  nmethod* nm = callee_method->code();
 947      -  nmethodLocker nl_callee(nm);
      948 +  nmethod* callee_nm = callee_method->code();
      949 +  nmethodLocker nl_callee(callee_nm);
 948  950  #ifdef ASSERT
 949      -  address dest_entry_point = nm == NULL ? 0 : nm->entry_point(); // used below
      951 +  address dest_entry_point = callee_nm == NULL ? 0 : callee_nm->entry_point(); // used below
 950  952  #endif
 951  953  
 952  954    if (is_virtual) {
 953  955      assert(receiver.not_null(), "sanity check");
 954  956      bool static_bound = call_info.resolved_method()->can_be_statically_bound();
 955  957      KlassHandle h_klass(THREAD, receiver->klass());
 956  958      CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
 957  959                       is_optimized, static_bound, virtual_call_info,
 958  960                       CHECK_(methodHandle()));
 959  961    } else {
↓ open down ↓ 1693 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX