774 |
774 |
775 |
775 |
776 return bt; |
776 return bt; |
777 JRT_END |
777 JRT_END |
778 |
778 |
779 |
779 class DeoptimizeMarkedTC : public ThreadClosure { |
780 int Deoptimization::deoptimize_dependents() { |
780 bool _in_handshake; |
781 Threads::deoptimized_wrt_marked_nmethods(); |
781 public: |
782 return 0; |
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 } |
783 } |
808 } |
784 |
809 |
785 Deoptimization::DeoptAction Deoptimization::_unloaded_action |
810 Deoptimization::DeoptAction Deoptimization::_unloaded_action |
786 = Deoptimization::Action_reinterpret; |
811 = Deoptimization::Action_reinterpret; |
787 |
812 |
1241 objects_to_revoke->append(Handle(thread, mon_info->owner())); |
1266 objects_to_revoke->append(Handle(thread, mon_info->owner())); |
1242 } |
1267 } |
1243 } |
1268 } |
1244 } |
1269 } |
1245 |
1270 |
1246 |
1271 static void get_monitors_from_stack(GrowableArray<Handle>* objects_to_revoke, JavaThread* thread, frame fr, RegisterMap* map) { |
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 |
1272 // 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 |
1273 // the places we want to call this routine so we need to walk the |
1256 // stack again to update the register map. |
1274 // stack again to update the register map. |
1257 if (map == NULL || !map->update_map()) { |
1275 if (map == NULL || !map->update_map()) { |
1258 StackFrameStream sfs(thread, true); |
1276 StackFrameStream sfs(thread, true); |
1272 while (!cvf->is_top()) { |
1290 while (!cvf->is_top()) { |
1273 collect_monitors(cvf, objects_to_revoke); |
1291 collect_monitors(cvf, objects_to_revoke); |
1274 cvf = compiledVFrame::cast(cvf->sender()); |
1292 cvf = compiledVFrame::cast(cvf->sender()); |
1275 } |
1293 } |
1276 collect_monitors(cvf, objects_to_revoke); |
1294 collect_monitors(cvf, objects_to_revoke); |
|
1295 } |
|
1296 |
|
1297 void Deoptimization::revoke_using_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); |
1277 |
1303 |
1278 if (SafepointSynchronize::is_at_safepoint()) { |
1304 if (SafepointSynchronize::is_at_safepoint()) { |
1279 BiasedLocking::revoke_at_safepoint(objects_to_revoke); |
1305 BiasedLocking::revoke_at_safepoint(objects_to_revoke); |
1280 } else { |
1306 } else { |
1281 BiasedLocking::revoke(objects_to_revoke); |
1307 BiasedLocking::revoke(objects_to_revoke); |
|
1308 } |
|
1309 } |
|
1310 |
|
1311 void Deoptimization::revoke_using_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 BiasedLocking::revoke_own_locks_in_handshake(objects_to_revoke->at(i), thread); |
|
1322 assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now"); |
1282 } |
1323 } |
1283 } |
1324 } |
1284 |
1325 |
1285 |
1326 |
1286 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) { |
1327 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) { |
1308 // Patch the compiled method so that when execution returns to it we will |
1349 // Patch the compiled method so that when execution returns to it we will |
1309 // deopt the execution state and return to the interpreter. |
1350 // deopt the execution state and return to the interpreter. |
1310 fr.deoptimize(thread); |
1351 fr.deoptimize(thread); |
1311 } |
1352 } |
1312 |
1353 |
1313 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map) { |
1354 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, bool in_handshake) { |
1314 deoptimize(thread, fr, map, Reason_constraint); |
1355 deopt_thread(in_handshake, thread, fr, map, Reason_constraint); |
1315 } |
1356 } |
1316 |
1357 |
1317 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) { |
1358 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) { |
|
1359 deopt_thread(false, thread, fr, map, reason); |
|
1360 } |
|
1361 |
|
1362 void Deoptimization::deopt_thread(bool in_handshake, JavaThread* thread, |
|
1363 frame fr, RegisterMap *map, DeoptReason reason) { |
1318 // Deoptimize only if the frame comes from compile code. |
1364 // Deoptimize only if the frame comes from compile code. |
1319 // Do not deoptimize the frame which is already patched |
1365 // Do not deoptimize the frame which is already patched |
1320 // during the execution of the loops below. |
1366 // during the execution of the loops below. |
1321 if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) { |
1367 if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) { |
1322 return; |
1368 return; |
1323 } |
1369 } |
1324 ResourceMark rm; |
1370 ResourceMark rm; |
1325 DeoptimizationMarker dm; |
1371 DeoptimizationMarker dm; |
1326 if (UseBiasedLocking) { |
1372 if (UseBiasedLocking) { |
1327 revoke_biases_of_monitors(thread, fr, map); |
1373 if (in_handshake) { |
|
1374 revoke_using_handshake(thread, fr, map); |
|
1375 } else { |
|
1376 revoke_using_safepoint(thread, fr, map); |
|
1377 } |
1328 } |
1378 } |
1329 deoptimize_single_frame(thread, fr, reason); |
1379 deoptimize_single_frame(thread, fr, reason); |
1330 |
1380 |
1331 } |
1381 } |
1332 |
1382 |