< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page
rev 54936 : imported patch 8221734-v3
rev 54937 : imported patch 8221734-v4


 759             vframeArrayElement* el = cur_array->element(k);
 760             tty->print_cr("    %s (bci %d)", el->method()->name_and_sig_as_C_string(), el->bci());
 761           }
 762           cur_array->print_on_2(tty);
 763         } // release tty lock before calling guarantee
 764         guarantee(false, "wrong number of expression stack elements during deopt");
 765       }
 766       VerifyOopClosure verify;
 767       iframe->oops_interpreted_do(&verify, &rm, false);
 768       callee_size_of_parameters = mh->size_of_parameters();
 769       callee_max_locals = mh->max_locals();
 770       is_top_frame = false;
 771     }
 772   }
 773 #endif /* !PRODUCT */
 774 
 775 
 776   return bt;
 777 JRT_END
 778 














 779 
 780 int Deoptimization::deoptimize_dependents() {
 781   Threads::deoptimized_wrt_marked_nmethods();
 782   return 0;











 783 }
 784 
 785 Deoptimization::DeoptAction Deoptimization::_unloaded_action
 786   = Deoptimization::Action_reinterpret;
 787 
 788 #if COMPILER2_OR_JVMCI
 789 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
 790   Handle pending_exception(THREAD, thread->pending_exception());
 791   const char* exception_file = thread->exception_file();
 792   int exception_line = thread->exception_line();
 793   thread->clear_pending_exception();
 794 
 795   bool failures = false;
 796 
 797   for (int i = 0; i < objects->length(); i++) {
 798     assert(objects->at(i)->is_object(), "invalid debug information");
 799     ObjectValue* sv = (ObjectValue*) objects->at(i);
 800 
 801     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
 802     oop obj = NULL;


1226       array->element(i)->free_monitors(thread);
1227 #ifdef ASSERT
1228       array->element(i)->set_removed_monitors();
1229 #endif
1230     }
1231   }
1232 }
1233 #endif
1234 
1235 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
1236   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1237   Thread* thread = Thread::current();
1238   for (int i = 0; i < monitors->length(); i++) {
1239     MonitorInfo* mon_info = monitors->at(i);
1240     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
1241       objects_to_revoke->append(Handle(thread, mon_info->owner()));
1242     }
1243   }
1244 }
1245 
1246 
1247 void Deoptimization::revoke_biases_of_monitors(JavaThread* thread, frame fr, RegisterMap* map) {
1248   if (!UseBiasedLocking) {
1249     return;
1250   }
1251 
1252   GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
1253 
1254   // Unfortunately we don't have a RegisterMap available in most of
1255   // the places we want to call this routine so we need to walk the
1256   // stack again to update the register map.
1257   if (map == NULL || !map->update_map()) {
1258     StackFrameStream sfs(thread, true);
1259     bool found = false;
1260     while (!found && !sfs.is_done()) {
1261       frame* cur = sfs.current();
1262       sfs.next();
1263       found = cur->id() == fr.id();
1264     }
1265     assert(found, "frame to be deoptimized not found on target thread's stack");
1266     map = sfs.register_map();
1267   }
1268 
1269   vframe* vf = vframe::new_vframe(&fr, map, thread);
1270   compiledVFrame* cvf = compiledVFrame::cast(vf);
1271   // Revoke monitors' biases in all scopes
1272   while (!cvf->is_top()) {
1273     collect_monitors(cvf, objects_to_revoke);
1274     cvf = compiledVFrame::cast(cvf->sender());
1275   }
1276   collect_monitors(cvf, objects_to_revoke);








1277 
1278   if (SafepointSynchronize::is_at_safepoint()) {
1279     BiasedLocking::revoke_at_safepoint(objects_to_revoke);
1280   } else {
1281     BiasedLocking::revoke(objects_to_revoke);
1282   }
1283 }
1284 
















1285 
1286 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
1287   assert(fr.can_be_deoptimized(), "checking frame type");
1288 
1289   gather_statistics(reason, Action_none, Bytecodes::_illegal);
1290 
1291   if (LogCompilation && xtty != NULL) {
1292     CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
1293     assert(cm != NULL, "only compiled methods can deopt");
1294 
1295     ttyLocker ttyl;
1296     xtty->begin_head("deoptimized thread='" UINTX_FORMAT "' reason='%s' pc='" INTPTR_FORMAT "'",(uintx)thread->osthread()->thread_id(), trap_reason_name(reason), p2i(fr.pc()));
1297     cm->log_identity(xtty);
1298     xtty->end_head();
1299     for (ScopeDesc* sd = cm->scope_desc_at(fr.pc()); ; sd = sd->sender()) {
1300       xtty->begin_elem("jvms bci='%d'", sd->bci());
1301       xtty->method(sd->method());
1302       xtty->end_elem();
1303       if (sd->is_top())  break;
1304     }
1305     xtty->tail("deoptimized");
1306   }
1307 
1308   // Patch the compiled method so that when execution returns to it we will
1309   // deopt the execution state and return to the interpreter.
1310   fr.deoptimize(thread);
1311 }
1312 
1313 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map) {
1314   deoptimize(thread, fr, map, Reason_constraint);
1315 }
1316 
1317 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) {





1318   // Deoptimize only if the frame comes from compile code.
1319   // Do not deoptimize the frame which is already patched
1320   // during the execution of the loops below.
1321   if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
1322     return;
1323   }
1324   ResourceMark rm;
1325   DeoptimizationMarker dm;
1326   if (UseBiasedLocking) {
1327     revoke_biases_of_monitors(thread, fr, map);




1328   }
1329   deoptimize_single_frame(thread, fr, reason);
1330 
1331 }
1332 
1333 #if INCLUDE_JVMCI
1334 address Deoptimization::deoptimize_for_missing_exception_handler(CompiledMethod* cm) {
1335   // there is no exception handler for this pc => deoptimize
1336   cm->make_not_entrant();
1337 
1338   // Use Deoptimization::deoptimize for all of its side-effects:
1339   // revoking biases of monitors, gathering traps statistics, logging...
1340   // it also patches the return pc but we do not care about that
1341   // since we return a continuation to the deopt_blob below.
1342   JavaThread* thread = JavaThread::current();
1343   RegisterMap reg_map(thread, UseBiasedLocking);
1344   frame runtime_frame = thread->last_frame();
1345   frame caller_frame = runtime_frame.sender(&reg_map);
1346   assert(caller_frame.cb()->as_compiled_method_or_null() == cm, "expect top frame compiled method");
1347   Deoptimization::deoptimize(thread, caller_frame, &reg_map, Deoptimization::Reason_not_compiled_exception_handler);




 759             vframeArrayElement* el = cur_array->element(k);
 760             tty->print_cr("    %s (bci %d)", el->method()->name_and_sig_as_C_string(), el->bci());
 761           }
 762           cur_array->print_on_2(tty);
 763         } // release tty lock before calling guarantee
 764         guarantee(false, "wrong number of expression stack elements during deopt");
 765       }
 766       VerifyOopClosure verify;
 767       iframe->oops_interpreted_do(&verify, &rm, false);
 768       callee_size_of_parameters = mh->size_of_parameters();
 769       callee_max_locals = mh->max_locals();
 770       is_top_frame = false;
 771     }
 772   }
 773 #endif /* !PRODUCT */
 774 
 775 
 776   return bt;
 777 JRT_END
 778 
 779 class DeoptimizeMarkedTC : public ThreadClosure {
 780   bool _in_handshake;
 781  public:
 782   DeoptimizeMarkedTC(bool in_handshake) : _in_handshake(in_handshake) {}
 783   virtual void do_thread(Thread* thread) {
 784     assert(thread->is_Java_thread(), "must be");
 785     JavaThread* jt = (JavaThread*)thread;
 786     jt->deoptimize_marked_methods(_in_handshake);
 787   }
 788 };
 789 
 790 void Deoptimization::deoptimize_all_marked() {
 791   ResourceMark rm;
 792   DeoptimizationMarker dm;
 793 
 794   if (SafepointSynchronize::is_at_safepoint()) {
 795     DeoptimizeMarkedTC deopt(false);
 796     // Make the dependent methods not entrant
 797     CodeCache::make_marked_nmethods_not_entrant();
 798     Threads::java_threads_do(&deopt);
 799   } else {
 800     // Make the dependent methods not entrant
 801     {
 802       MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 803       CodeCache::make_marked_nmethods_not_entrant();
 804     }
 805     DeoptimizeMarkedTC deopt(true);
 806     Handshake::execute(&deopt);
 807   }
 808 }
 809 
 810 Deoptimization::DeoptAction Deoptimization::_unloaded_action
 811   = Deoptimization::Action_reinterpret;
 812 
 813 #if COMPILER2_OR_JVMCI
 814 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
 815   Handle pending_exception(THREAD, thread->pending_exception());
 816   const char* exception_file = thread->exception_file();
 817   int exception_line = thread->exception_line();
 818   thread->clear_pending_exception();
 819 
 820   bool failures = false;
 821 
 822   for (int i = 0; i < objects->length(); i++) {
 823     assert(objects->at(i)->is_object(), "invalid debug information");
 824     ObjectValue* sv = (ObjectValue*) objects->at(i);
 825 
 826     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
 827     oop obj = NULL;


1251       array->element(i)->free_monitors(thread);
1252 #ifdef ASSERT
1253       array->element(i)->set_removed_monitors();
1254 #endif
1255     }
1256   }
1257 }
1258 #endif
1259 
1260 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
1261   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1262   Thread* thread = Thread::current();
1263   for (int i = 0; i < monitors->length(); i++) {
1264     MonitorInfo* mon_info = monitors->at(i);
1265     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
1266       objects_to_revoke->append(Handle(thread, mon_info->owner()));
1267     }
1268   }
1269 }
1270 
1271 static void get_monitors_from_stack(GrowableArray<Handle>* objects_to_revoke, JavaThread* thread, frame fr, RegisterMap* map) {







1272   // Unfortunately we don't have a RegisterMap available in most of
1273   // the places we want to call this routine so we need to walk the
1274   // stack again to update the register map.
1275   if (map == NULL || !map->update_map()) {
1276     StackFrameStream sfs(thread, true);
1277     bool found = false;
1278     while (!found && !sfs.is_done()) {
1279       frame* cur = sfs.current();
1280       sfs.next();
1281       found = cur->id() == fr.id();
1282     }
1283     assert(found, "frame to be deoptimized not found on target thread's stack");
1284     map = sfs.register_map();
1285   }
1286 
1287   vframe* vf = vframe::new_vframe(&fr, map, thread);
1288   compiledVFrame* cvf = compiledVFrame::cast(vf);
1289   // Revoke monitors' biases in all scopes
1290   while (!cvf->is_top()) {
1291     collect_monitors(cvf, objects_to_revoke);
1292     cvf = compiledVFrame::cast(cvf->sender());
1293   }
1294   collect_monitors(cvf, objects_to_revoke);
1295 }
1296 
1297 void Deoptimization::revoke_safepoint(JavaThread* thread, frame fr, RegisterMap* map) {
1298   if (!UseBiasedLocking) {
1299     return;
1300   }
1301   GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
1302   get_monitors_from_stack(objects_to_revoke, thread, fr, map);
1303 
1304   if (SafepointSynchronize::is_at_safepoint()) {
1305     BiasedLocking::revoke_at_safepoint(objects_to_revoke);
1306   } else {
1307     BiasedLocking::revoke(objects_to_revoke);
1308   }
1309 }
1310 
1311 void Deoptimization::revoke_handshake(JavaThread* thread, frame fr, RegisterMap* map) {
1312   if (!UseBiasedLocking) {
1313     return;
1314   }
1315   GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
1316   get_monitors_from_stack(objects_to_revoke, thread, fr, map);
1317 
1318   int len = objects_to_revoke->length();
1319   for (int i = 0; i < len; i++) {
1320     oop obj = (objects_to_revoke->at(i))();
1321     markOop mark = obj->mark();
1322     BiasedLocking::revoke_own_locks_in_handshake(objects_to_revoke->at(i), thread);
1323     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
1324   }
1325 }
1326 
1327 
1328 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
1329   assert(fr.can_be_deoptimized(), "checking frame type");
1330 
1331   gather_statistics(reason, Action_none, Bytecodes::_illegal);
1332 
1333   if (LogCompilation && xtty != NULL) {
1334     CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
1335     assert(cm != NULL, "only compiled methods can deopt");
1336 
1337     ttyLocker ttyl;
1338     xtty->begin_head("deoptimized thread='" UINTX_FORMAT "' reason='%s' pc='" INTPTR_FORMAT "'",(uintx)thread->osthread()->thread_id(), trap_reason_name(reason), p2i(fr.pc()));
1339     cm->log_identity(xtty);
1340     xtty->end_head();
1341     for (ScopeDesc* sd = cm->scope_desc_at(fr.pc()); ; sd = sd->sender()) {
1342       xtty->begin_elem("jvms bci='%d'", sd->bci());
1343       xtty->method(sd->method());
1344       xtty->end_elem();
1345       if (sd->is_top())  break;
1346     }
1347     xtty->tail("deoptimized");
1348   }
1349 
1350   // Patch the compiled method so that when execution returns to it we will
1351   // deopt the execution state and return to the interpreter.
1352   fr.deoptimize(thread);
1353 }
1354 
1355 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, bool in_handshake) {
1356   deopt_thread(in_handshake, thread, fr, map, Reason_constraint);
1357 }
1358 
1359 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) {
1360   deopt_thread(false, thread, fr, map, reason);
1361 }
1362 
1363 void Deoptimization::deopt_thread(bool in_handshake, JavaThread* thread,
1364                                   frame fr, RegisterMap *map, DeoptReason reason) {
1365   // Deoptimize only if the frame comes from compile code.
1366   // Do not deoptimize the frame which is already patched
1367   // during the execution of the loops below.
1368   if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
1369     return;
1370   }
1371   ResourceMark rm;
1372   DeoptimizationMarker dm;
1373   if (UseBiasedLocking) {
1374     if (in_handshake) {
1375       revoke_handshake(thread, fr, map);
1376     } else {
1377       revoke_safepoint(thread, fr, map);
1378     }
1379   }
1380   deoptimize_single_frame(thread, fr, reason);
1381 
1382 }
1383 
1384 #if INCLUDE_JVMCI
1385 address Deoptimization::deoptimize_for_missing_exception_handler(CompiledMethod* cm) {
1386   // there is no exception handler for this pc => deoptimize
1387   cm->make_not_entrant();
1388 
1389   // Use Deoptimization::deoptimize for all of its side-effects:
1390   // revoking biases of monitors, gathering traps statistics, logging...
1391   // it also patches the return pc but we do not care about that
1392   // since we return a continuation to the deopt_blob below.
1393   JavaThread* thread = JavaThread::current();
1394   RegisterMap reg_map(thread, UseBiasedLocking);
1395   frame runtime_frame = thread->last_frame();
1396   frame caller_frame = runtime_frame.sender(&reg_map);
1397   assert(caller_frame.cb()->as_compiled_method_or_null() == cm, "expect top frame compiled method");
1398   Deoptimization::deoptimize(thread, caller_frame, &reg_map, Deoptimization::Reason_not_compiled_exception_handler);


< prev index next >