< prev index next >

src/share/vm/runtime/sharedRuntime.cpp

Print this page




 658       Deoptimization::deoptimize(thread, caller_frame, &reg_map, Deoptimization::Reason_not_compiled_exception_handler);
 659 
 660       return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
 661     }
 662   }
 663 #endif // INCLUDE_JVMCI
 664 
 665   nmethod* nm = cm->as_nmethod();
 666   ScopeDesc* sd = nm->scope_desc_at(ret_pc);
 667   // determine handler bci, if any
 668   EXCEPTION_MARK;
 669 
 670   int handler_bci = -1;
 671   int scope_depth = 0;
 672   if (!force_unwind) {
 673     int bci = sd->bci();
 674     bool recursive_exception = false;
 675     do {
 676       bool skip_scope_increment = false;
 677       // exception handler lookup
 678       KlassHandle ek (THREAD, exception->klass());
 679       methodHandle mh(THREAD, sd->method());
 680       handler_bci = Method::fast_exception_handler_bci_for(mh, ek, bci, THREAD);
 681       if (HAS_PENDING_EXCEPTION) {
 682         recursive_exception = true;
 683         // We threw an exception while trying to find the exception handler.
 684         // Transfer the new exception to the exception handle which will
 685         // be set into thread local storage, and do another lookup for an
 686         // exception handler for this exception, this time starting at the
 687         // BCI of the exception handler which caused the exception to be
 688         // thrown (bugs 4307310 and 4546590). Set "exception" reference
 689         // argument to ensure that the correct exception is thrown (4870175).
 690         recursive_exception_occurred = true;
 691         exception = Handle(THREAD, PENDING_EXCEPTION);
 692         CLEAR_PENDING_EXCEPTION;
 693         if (handler_bci >= 0) {
 694           bci = handler_bci;
 695           handler_bci = -1;
 696           skip_scope_increment = true;
 697         }
 698       }


1168       THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1169     }
1170   }
1171 
1172   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1173 
1174   // Resolve method
1175   if (attached_method.not_null()) {
1176     // Parameterized by attached method.
1177     LinkResolver::resolve_invoke(callinfo, receiver, attached_method, bc, CHECK_NH);
1178   } else {
1179     // Parameterized by bytecode.
1180     constantPoolHandle constants(THREAD, caller->constants());
1181     LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_NH);
1182   }
1183 
1184 #ifdef ASSERT
1185   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1186   if (has_receiver) {
1187     assert(receiver.not_null(), "should have thrown exception");
1188     KlassHandle receiver_klass(THREAD, receiver->klass());
1189     Klass* rk = NULL;
1190     if (attached_method.not_null()) {
1191       // In case there's resolved method attached, use its holder during the check.
1192       rk = attached_method->method_holder();
1193     } else {
1194       // Klass is already loaded.
1195       constantPoolHandle constants(THREAD, caller->constants());
1196       rk = constants->klass_ref_at(bytecode_index, CHECK_NH);
1197     }
1198     KlassHandle static_receiver_klass(THREAD, rk);
1199     methodHandle callee = callinfo.selected_method();
1200     assert(receiver_klass->is_subtype_of(static_receiver_klass()),
1201            "actual receiver must be subclass of static receiver klass");
1202     if (receiver_klass->is_instance_klass()) {
1203       if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
1204         tty->print_cr("ERROR: Klass not yet initialized!!");
1205         receiver_klass()->print();
1206       }
1207       assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
1208     }
1209   }
1210 #endif
1211 
1212   return receiver;
1213 }
1214 
1215 methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
1216   ResourceMark rm(THREAD);
1217   // We need first to check if any Java activations (compiled, interpreted)
1218   // exist on the stack since last JavaCall.  If not, we need
1219   // to get the target method from the JavaCall wrapper.
1220   vframeStream vfst(thread, true);  // Do not skip any javaCalls
1221   methodHandle callee_method;
1222   if (vfst.at_end()) {
1223     // No Java frames were found on stack since we did the JavaCall.
1224     // Hence the stack can only contain an entry_frame.  We need to
1225     // find the target method from the stub frame.
1226     RegisterMap reg_map(thread, false);
1227     frame fr = thread->last_frame();


1346   CompiledMethod* callee = callee_method->code();
1347 
1348   if (callee != NULL) {
1349     assert(callee->is_compiled(), "must be nmethod for patching");
1350   }
1351 
1352   if (callee != NULL && !callee->is_in_use()) {
1353     // Patch call site to C2I adapter if callee nmethod is deoptimized or unloaded.
1354     callee = NULL;
1355   }
1356   nmethodLocker nl_callee(callee);
1357 #ifdef ASSERT
1358   address dest_entry_point = callee == NULL ? 0 : callee->entry_point(); // used below
1359 #endif
1360 
1361   bool is_nmethod = caller_nm->is_nmethod();
1362 
1363   if (is_virtual) {
1364     assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
1365     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1366     KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass());
1367     CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
1368                      is_optimized, static_bound, is_nmethod, virtual_call_info,
1369                      CHECK_(methodHandle()));
1370   } else {
1371     // static call
1372     CompiledStaticCall::compute_entry(callee_method, is_nmethod, static_call_info);
1373   }
1374 
1375   // grab lock, check for deoptimization and potentially patch caller
1376   {
1377     MutexLocker ml_patch(CompiledIC_lock);
1378 
1379     // Lock blocks for safepoint during which both nmethods can change state.
1380 
1381     // Now that we are ready to patch if the Method* was redefined then
1382     // don't update call site and let the caller retry.
1383     // Don't update call site if callee nmethod was unloaded or deoptimized.
1384     // Don't update call site if callee nmethod was replaced by an other nmethod
1385     // which may happen when multiply alive nmethod (tiered compilation)
1386     // will be supported.
1387     if (!callee_method->is_old() &&


1608             // monomorphic compiled call site.
1609             // We can't assert for callee_method->code() != NULL because it
1610             // could have been deoptimized in the meantime
1611             if (TraceCallFixup) {
1612               ResourceMark rm(thread);
1613               tty->print("FALSE IC miss (%s) converting to compiled call to", Bytecodes::name(bc));
1614               callee_method->print_short_name(tty);
1615               tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1616             }
1617             should_be_mono = true;
1618           }
1619         }
1620       }
1621 
1622       if (should_be_mono) {
1623 
1624         // We have a path that was monomorphic but was going interpreted
1625         // and now we have (or had) a compiled entry. We correct the IC
1626         // by using a new icBuffer.
1627         CompiledICInfo info;
1628         KlassHandle receiver_klass(THREAD, receiver()->klass());
1629         inline_cache->compute_monomorphic_entry(callee_method,
1630                                                 receiver_klass,
1631                                                 inline_cache->is_optimized(),
1632                                                 false, caller_nm->is_nmethod(),
1633                                                 info, CHECK_(methodHandle()));
1634         inline_cache->set_to_monomorphic(info);
1635       } else if (!inline_cache->is_megamorphic() && !inline_cache->is_clean()) {
1636         // Potential change to megamorphic
1637         bool successful = inline_cache->set_to_megamorphic(&call_info, bc, CHECK_(methodHandle()));
1638         if (!successful) {
1639           inline_cache->set_to_clean();
1640         }
1641       } else {
1642         // Either clean or megamorphic
1643       }
1644     } else {
1645       fatal("Unimplemented");
1646     }
1647   } // Release CompiledIC_lock
1648 




 658       Deoptimization::deoptimize(thread, caller_frame, &reg_map, Deoptimization::Reason_not_compiled_exception_handler);
 659 
 660       return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
 661     }
 662   }
 663 #endif // INCLUDE_JVMCI
 664 
 665   nmethod* nm = cm->as_nmethod();
 666   ScopeDesc* sd = nm->scope_desc_at(ret_pc);
 667   // determine handler bci, if any
 668   EXCEPTION_MARK;
 669 
 670   int handler_bci = -1;
 671   int scope_depth = 0;
 672   if (!force_unwind) {
 673     int bci = sd->bci();
 674     bool recursive_exception = false;
 675     do {
 676       bool skip_scope_increment = false;
 677       // exception handler lookup
 678       Klass* ek = exception->klass();
 679       methodHandle mh(THREAD, sd->method());
 680       handler_bci = Method::fast_exception_handler_bci_for(mh, ek, bci, THREAD);
 681       if (HAS_PENDING_EXCEPTION) {
 682         recursive_exception = true;
 683         // We threw an exception while trying to find the exception handler.
 684         // Transfer the new exception to the exception handle which will
 685         // be set into thread local storage, and do another lookup for an
 686         // exception handler for this exception, this time starting at the
 687         // BCI of the exception handler which caused the exception to be
 688         // thrown (bugs 4307310 and 4546590). Set "exception" reference
 689         // argument to ensure that the correct exception is thrown (4870175).
 690         recursive_exception_occurred = true;
 691         exception = Handle(THREAD, PENDING_EXCEPTION);
 692         CLEAR_PENDING_EXCEPTION;
 693         if (handler_bci >= 0) {
 694           bci = handler_bci;
 695           handler_bci = -1;
 696           skip_scope_increment = true;
 697         }
 698       }


1168       THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1169     }
1170   }
1171 
1172   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1173 
1174   // Resolve method
1175   if (attached_method.not_null()) {
1176     // Parameterized by attached method.
1177     LinkResolver::resolve_invoke(callinfo, receiver, attached_method, bc, CHECK_NH);
1178   } else {
1179     // Parameterized by bytecode.
1180     constantPoolHandle constants(THREAD, caller->constants());
1181     LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_NH);
1182   }
1183 
1184 #ifdef ASSERT
1185   // Check that the receiver klass is of the right subtype and that it is initialized for virtual calls
1186   if (has_receiver) {
1187     assert(receiver.not_null(), "should have thrown exception");
1188     Klass* receiver_klass = receiver->klass();
1189     Klass* rk = NULL;
1190     if (attached_method.not_null()) {
1191       // In case there's resolved method attached, use its holder during the check.
1192       rk = attached_method->method_holder();
1193     } else {
1194       // Klass is already loaded.
1195       constantPoolHandle constants(THREAD, caller->constants());
1196       rk = constants->klass_ref_at(bytecode_index, CHECK_NH);
1197     }
1198     Klass* static_receiver_klass = rk;
1199     methodHandle callee = callinfo.selected_method();
1200     assert(receiver_klass->is_subtype_of(static_receiver_klass),
1201            "actual receiver must be subclass of static receiver klass");
1202     if (receiver_klass->is_instance_klass()) {
1203       if (InstanceKlass::cast(receiver_klass)->is_not_initialized()) {
1204         tty->print_cr("ERROR: Klass not yet initialized!!");
1205         receiver_klass->print();
1206       }
1207       assert(!InstanceKlass::cast(receiver_klass)->is_not_initialized(), "receiver_klass must be initialized");
1208     }
1209   }
1210 #endif
1211 
1212   return receiver;
1213 }
1214 
1215 methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
1216   ResourceMark rm(THREAD);
1217   // We need first to check if any Java activations (compiled, interpreted)
1218   // exist on the stack since last JavaCall.  If not, we need
1219   // to get the target method from the JavaCall wrapper.
1220   vframeStream vfst(thread, true);  // Do not skip any javaCalls
1221   methodHandle callee_method;
1222   if (vfst.at_end()) {
1223     // No Java frames were found on stack since we did the JavaCall.
1224     // Hence the stack can only contain an entry_frame.  We need to
1225     // find the target method from the stub frame.
1226     RegisterMap reg_map(thread, false);
1227     frame fr = thread->last_frame();


1346   CompiledMethod* callee = callee_method->code();
1347 
1348   if (callee != NULL) {
1349     assert(callee->is_compiled(), "must be nmethod for patching");
1350   }
1351 
1352   if (callee != NULL && !callee->is_in_use()) {
1353     // Patch call site to C2I adapter if callee nmethod is deoptimized or unloaded.
1354     callee = NULL;
1355   }
1356   nmethodLocker nl_callee(callee);
1357 #ifdef ASSERT
1358   address dest_entry_point = callee == NULL ? 0 : callee->entry_point(); // used below
1359 #endif
1360 
1361   bool is_nmethod = caller_nm->is_nmethod();
1362 
1363   if (is_virtual) {
1364     assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
1365     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1366     Klass* klass = invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass();
1367     CompiledIC::compute_monomorphic_entry(callee_method, klass,
1368                      is_optimized, static_bound, is_nmethod, virtual_call_info,
1369                      CHECK_(methodHandle()));
1370   } else {
1371     // static call
1372     CompiledStaticCall::compute_entry(callee_method, is_nmethod, static_call_info);
1373   }
1374 
1375   // grab lock, check for deoptimization and potentially patch caller
1376   {
1377     MutexLocker ml_patch(CompiledIC_lock);
1378 
1379     // Lock blocks for safepoint during which both nmethods can change state.
1380 
1381     // Now that we are ready to patch if the Method* was redefined then
1382     // don't update call site and let the caller retry.
1383     // Don't update call site if callee nmethod was unloaded or deoptimized.
1384     // Don't update call site if callee nmethod was replaced by an other nmethod
1385     // which may happen when multiply alive nmethod (tiered compilation)
1386     // will be supported.
1387     if (!callee_method->is_old() &&


1608             // monomorphic compiled call site.
1609             // We can't assert for callee_method->code() != NULL because it
1610             // could have been deoptimized in the meantime
1611             if (TraceCallFixup) {
1612               ResourceMark rm(thread);
1613               tty->print("FALSE IC miss (%s) converting to compiled call to", Bytecodes::name(bc));
1614               callee_method->print_short_name(tty);
1615               tty->print_cr(" code: " INTPTR_FORMAT, p2i(callee_method->code()));
1616             }
1617             should_be_mono = true;
1618           }
1619         }
1620       }
1621 
1622       if (should_be_mono) {
1623 
1624         // We have a path that was monomorphic but was going interpreted
1625         // and now we have (or had) a compiled entry. We correct the IC
1626         // by using a new icBuffer.
1627         CompiledICInfo info;
1628         Klass* receiver_klass = receiver()->klass();
1629         inline_cache->compute_monomorphic_entry(callee_method,
1630                                                 receiver_klass,
1631                                                 inline_cache->is_optimized(),
1632                                                 false, caller_nm->is_nmethod(),
1633                                                 info, CHECK_(methodHandle()));
1634         inline_cache->set_to_monomorphic(info);
1635       } else if (!inline_cache->is_megamorphic() && !inline_cache->is_clean()) {
1636         // Potential change to megamorphic
1637         bool successful = inline_cache->set_to_megamorphic(&call_info, bc, CHECK_(methodHandle()));
1638         if (!successful) {
1639           inline_cache->set_to_clean();
1640         }
1641       } else {
1642         // Either clean or megamorphic
1643       }
1644     } else {
1645       fatal("Unimplemented");
1646     }
1647   } // Release CompiledIC_lock
1648 


< prev index next >