src/hotspot/share/runtime/deoptimization.cpp
changeset 55479 80b27dc96ca3
parent 55279 d59aec2ead21
child 55540 d4de822dc421
equal deleted inserted replaced
55478:ae2e53e379cb 55479:80b27dc96ca3
   777 
   777 
   778 
   778 
   779   return bt;
   779   return bt;
   780 JRT_END
   780 JRT_END
   781 
   781 
   782 class DeoptimizeMarkedTC : public ThreadClosure {
   782 
   783   bool _in_handshake;
   783 int Deoptimization::deoptimize_dependents() {
   784  public:
   784   Threads::deoptimized_wrt_marked_nmethods();
   785   DeoptimizeMarkedTC(bool in_handshake) : _in_handshake(in_handshake) {}
   785   return 0;
   786   virtual void do_thread(Thread* thread) {
       
   787     assert(thread->is_Java_thread(), "must be");
       
   788     JavaThread* jt = (JavaThread*)thread;
       
   789     jt->deoptimize_marked_methods(_in_handshake);
       
   790   }
       
   791 };
       
   792 
       
   793 void Deoptimization::deoptimize_all_marked() {
       
   794   ResourceMark rm;
       
   795   DeoptimizationMarker dm;
       
   796 
       
   797   if (SafepointSynchronize::is_at_safepoint()) {
       
   798     DeoptimizeMarkedTC deopt(false);
       
   799     // Make the dependent methods not entrant
       
   800     CodeCache::make_marked_nmethods_not_entrant();
       
   801     Threads::java_threads_do(&deopt);
       
   802   } else {
       
   803     // Make the dependent methods not entrant
       
   804     {
       
   805       MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
       
   806       CodeCache::make_marked_nmethods_not_entrant();
       
   807     }
       
   808     DeoptimizeMarkedTC deopt(true);
       
   809     Handshake::execute(&deopt);
       
   810   }
       
   811 }
   786 }
   812 
   787 
   813 Deoptimization::DeoptAction Deoptimization::_unloaded_action
   788 Deoptimization::DeoptAction Deoptimization::_unloaded_action
   814   = Deoptimization::Action_reinterpret;
   789   = Deoptimization::Action_reinterpret;
   815 
   790 
  1410       objects_to_revoke->append(Handle(thread, mon_info->owner()));
  1385       objects_to_revoke->append(Handle(thread, mon_info->owner()));
  1411     }
  1386     }
  1412   }
  1387   }
  1413 }
  1388 }
  1414 
  1389 
  1415 static void get_monitors_from_stack(GrowableArray<Handle>* objects_to_revoke, JavaThread* thread, frame fr, RegisterMap* map) {
  1390 
       
  1391 void Deoptimization::revoke_biases_of_monitors(JavaThread* thread, frame fr, RegisterMap* map) {
       
  1392   if (!UseBiasedLocking) {
       
  1393     return;
       
  1394   }
       
  1395 
       
  1396   GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
       
  1397 
  1416   // Unfortunately we don't have a RegisterMap available in most of
  1398   // Unfortunately we don't have a RegisterMap available in most of
  1417   // the places we want to call this routine so we need to walk the
  1399   // the places we want to call this routine so we need to walk the
  1418   // stack again to update the register map.
  1400   // stack again to update the register map.
  1419   if (map == NULL || !map->update_map()) {
  1401   if (map == NULL || !map->update_map()) {
  1420     StackFrameStream sfs(thread, true);
  1402     StackFrameStream sfs(thread, true);
  1434   while (!cvf->is_top()) {
  1416   while (!cvf->is_top()) {
  1435     collect_monitors(cvf, objects_to_revoke);
  1417     collect_monitors(cvf, objects_to_revoke);
  1436     cvf = compiledVFrame::cast(cvf->sender());
  1418     cvf = compiledVFrame::cast(cvf->sender());
  1437   }
  1419   }
  1438   collect_monitors(cvf, objects_to_revoke);
  1420   collect_monitors(cvf, objects_to_revoke);
  1439 }
       
  1440 
       
  1441 void Deoptimization::revoke_using_safepoint(JavaThread* thread, frame fr, RegisterMap* map) {
       
  1442   if (!UseBiasedLocking) {
       
  1443     return;
       
  1444   }
       
  1445   GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
       
  1446   get_monitors_from_stack(objects_to_revoke, thread, fr, map);
       
  1447 
  1421 
  1448   if (SafepointSynchronize::is_at_safepoint()) {
  1422   if (SafepointSynchronize::is_at_safepoint()) {
  1449     BiasedLocking::revoke_at_safepoint(objects_to_revoke);
  1423     BiasedLocking::revoke_at_safepoint(objects_to_revoke);
  1450   } else {
  1424   } else {
  1451     BiasedLocking::revoke(objects_to_revoke);
  1425     BiasedLocking::revoke(objects_to_revoke);
  1452   }
       
  1453 }
       
  1454 
       
  1455 void Deoptimization::revoke_using_handshake(JavaThread* thread, frame fr, RegisterMap* map) {
       
  1456   if (!UseBiasedLocking) {
       
  1457     return;
       
  1458   }
       
  1459   GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
       
  1460   get_monitors_from_stack(objects_to_revoke, thread, fr, map);
       
  1461 
       
  1462   int len = objects_to_revoke->length();
       
  1463   for (int i = 0; i < len; i++) {
       
  1464     oop obj = (objects_to_revoke->at(i))();
       
  1465     BiasedLocking::revoke_own_locks_in_handshake(objects_to_revoke->at(i), thread);
       
  1466     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
       
  1467   }
  1426   }
  1468 }
  1427 }
  1469 
  1428 
  1470 
  1429 
  1471 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
  1430 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
  1493   // Patch the compiled method so that when execution returns to it we will
  1452   // Patch the compiled method so that when execution returns to it we will
  1494   // deopt the execution state and return to the interpreter.
  1453   // deopt the execution state and return to the interpreter.
  1495   fr.deoptimize(thread);
  1454   fr.deoptimize(thread);
  1496 }
  1455 }
  1497 
  1456 
  1498 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, bool in_handshake) {
  1457 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map) {
  1499   deopt_thread(in_handshake, thread, fr, map, Reason_constraint);
  1458   deoptimize(thread, fr, map, Reason_constraint);
  1500 }
  1459 }
  1501 
  1460 
  1502 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) {
  1461 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) {
  1503   deopt_thread(false, thread, fr, map, reason);
       
  1504 }
       
  1505 
       
  1506 void Deoptimization::deopt_thread(bool in_handshake, JavaThread* thread,
       
  1507                                   frame fr, RegisterMap *map, DeoptReason reason) {
       
  1508   // Deoptimize only if the frame comes from compile code.
  1462   // Deoptimize only if the frame comes from compile code.
  1509   // Do not deoptimize the frame which is already patched
  1463   // Do not deoptimize the frame which is already patched
  1510   // during the execution of the loops below.
  1464   // during the execution of the loops below.
  1511   if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
  1465   if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
  1512     return;
  1466     return;
  1513   }
  1467   }
  1514   ResourceMark rm;
  1468   ResourceMark rm;
  1515   DeoptimizationMarker dm;
  1469   DeoptimizationMarker dm;
  1516   if (UseBiasedLocking) {
  1470   if (UseBiasedLocking) {
  1517     if (in_handshake) {
  1471     revoke_biases_of_monitors(thread, fr, map);
  1518       revoke_using_handshake(thread, fr, map);
       
  1519     } else {
       
  1520       revoke_using_safepoint(thread, fr, map);
       
  1521     }
       
  1522   }
  1472   }
  1523   deoptimize_single_frame(thread, fr, reason);
  1473   deoptimize_single_frame(thread, fr, reason);
  1524 
  1474 
  1525 }
  1475 }
  1526 
  1476