< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page
rev 54838 : [mq]: 8221734-v2
rev 54839 : [mq]: 8221734-v3


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::inflate_monitors(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::inflate_monitors_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     assert(!mark->has_bias_pattern() || mark->biased_locker() == thread, "Can't revoke");
1323     BiasedLocking::revoke_and_rebias_in_handshake(objects_to_revoke->at(i), thread);
1324     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
1325     ObjectSynchronizer::inflate(thread, obj, ObjectSynchronizer::inflate_cause_vm_internal);
1326   }
1327 }
1328 
1329 
1330 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
1331   assert(fr.can_be_deoptimized(), "checking frame type");
1332 
1333   gather_statistics(reason, Action_none, Bytecodes::_illegal);
1334 
1335   if (LogCompilation && xtty != NULL) {
1336     CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
1337     assert(cm != NULL, "only compiled methods can deopt");
1338 
1339     ttyLocker ttyl;
1340     xtty->begin_head("deoptimized thread='" UINTX_FORMAT "' reason='%s' pc='" INTPTR_FORMAT "'",(uintx)thread->osthread()->thread_id(), trap_reason_name(reason), p2i(fr.pc()));
1341     cm->log_identity(xtty);
1342     xtty->end_head();
1343     for (ScopeDesc* sd = cm->scope_desc_at(fr.pc()); ; sd = sd->sender()) {
1344       xtty->begin_elem("jvms bci='%d'", sd->bci());
1345       xtty->method(sd->method());


1357 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, bool in_handshake) {
1358   deopt_thread(in_handshake, thread, fr, map, Reason_constraint);
1359 }
1360 
1361 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) {
1362   deopt_thread(false, thread, fr, map, reason);
1363 }
1364 
1365 void Deoptimization::deopt_thread(bool in_handshake, JavaThread* thread,
1366                                   frame fr, RegisterMap *map, DeoptReason reason) {
1367   // Deoptimize only if the frame comes from compile code.
1368   // Do not deoptimize the frame which is already patched
1369   // during the execution of the loops below.
1370   if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
1371     return;
1372   }
1373   ResourceMark rm;
1374   DeoptimizationMarker dm;
1375   if (UseBiasedLocking) {
1376     if (in_handshake) {
1377       inflate_monitors_handshake(thread, fr, map);
1378     } else {
1379       inflate_monitors(thread, fr, map);
1380     }
1381   }
1382   deoptimize_single_frame(thread, fr, reason);
1383 
1384 }
1385 
1386 #if INCLUDE_JVMCI
1387 address Deoptimization::deoptimize_for_missing_exception_handler(CompiledMethod* cm) {
1388   // there is no exception handler for this pc => deoptimize
1389   cm->make_not_entrant();
1390 
1391   // Use Deoptimization::deoptimize for all of its side-effects:
1392   // revoking biases of monitors, gathering traps statistics, logging...
1393   // it also patches the return pc but we do not care about that
1394   // since we return a continuation to the deopt_blob below.
1395   JavaThread* thread = JavaThread::current();
1396   RegisterMap reg_map(thread, UseBiasedLocking);
1397   frame runtime_frame = thread->last_frame();
1398   frame caller_frame = runtime_frame.sender(&reg_map);
1399   assert(caller_frame.cb()->as_compiled_method_or_null() == cm, "expect top frame compiled method");


1525 #if INCLUDE_JVMCI
1526   // JVMCI might need to get an exception from the stack, which in turn requires the register map to be valid
1527   RegisterMap reg_map(thread, true);
1528 #else
1529   RegisterMap reg_map(thread, UseBiasedLocking);
1530 #endif
1531   frame stub_frame = thread->last_frame();
1532   frame fr = stub_frame.sender(&reg_map);
1533   // Make sure the calling nmethod is not getting deoptimized and removed
1534   // before we are done with it.
1535   nmethodLocker nl(fr.pc());
1536 
1537   // Log a message
1538   Events::log(thread, "Uncommon trap: trap_request=" PTR32_FORMAT " fr.pc=" INTPTR_FORMAT " relative=" INTPTR_FORMAT,
1539               trap_request, p2i(fr.pc()), fr.pc() - fr.cb()->code_begin());
1540 
1541   {
1542     ResourceMark rm;
1543 
1544     // Revoke biases of any monitors in the frame to ensure we can migrate them
1545     fix_monitors(thread, fr, &reg_map);
1546 
1547     DeoptReason reason = trap_request_reason(trap_request);
1548     DeoptAction action = trap_request_action(trap_request);
1549 #if INCLUDE_JVMCI
1550     int debug_id = trap_request_debug_id(trap_request);
1551 #endif
1552     jint unloaded_class_index = trap_request_index(trap_request); // CP idx or -1
1553 
1554     vframe*  vf  = vframe::new_vframe(&fr, &reg_map, thread);
1555     compiledVFrame* cvf = compiledVFrame::cast(vf);
1556 
1557     CompiledMethod* nm = cvf->code();
1558 
1559     ScopeDesc*      trap_scope  = cvf->scope();
1560 
1561     if (TraceDeoptimization) {
1562       ttyLocker ttyl;
1563       tty->print_cr("  bci=%d pc=" INTPTR_FORMAT ", relative_pc=" INTPTR_FORMAT ", method=%s" JVMCI_ONLY(", debug_id=%d"), trap_scope->bci(), p2i(fr.pc()), fr.pc() - nm->code_begin(), trap_scope->method()->name_and_sig_as_C_string()
1564 #if INCLUDE_JVMCI
1565           , debug_id




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     assert(!mark->has_bias_pattern() || mark->biased_locker() == thread, "Can't revoke");
1323     BiasedLocking::revoke_own_locks_in_handshake(objects_to_revoke->at(i), thread);
1324     assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");

1325   }
1326 }
1327 
1328 
1329 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
1330   assert(fr.can_be_deoptimized(), "checking frame type");
1331 
1332   gather_statistics(reason, Action_none, Bytecodes::_illegal);
1333 
1334   if (LogCompilation && xtty != NULL) {
1335     CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
1336     assert(cm != NULL, "only compiled methods can deopt");
1337 
1338     ttyLocker ttyl;
1339     xtty->begin_head("deoptimized thread='" UINTX_FORMAT "' reason='%s' pc='" INTPTR_FORMAT "'",(uintx)thread->osthread()->thread_id(), trap_reason_name(reason), p2i(fr.pc()));
1340     cm->log_identity(xtty);
1341     xtty->end_head();
1342     for (ScopeDesc* sd = cm->scope_desc_at(fr.pc()); ; sd = sd->sender()) {
1343       xtty->begin_elem("jvms bci='%d'", sd->bci());
1344       xtty->method(sd->method());


1356 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, bool in_handshake) {
1357   deopt_thread(in_handshake, thread, fr, map, Reason_constraint);
1358 }
1359 
1360 void Deoptimization::deoptimize(JavaThread* thread, frame fr, RegisterMap *map, DeoptReason reason) {
1361   deopt_thread(false, thread, fr, map, reason);
1362 }
1363 
1364 void Deoptimization::deopt_thread(bool in_handshake, JavaThread* thread,
1365                                   frame fr, RegisterMap *map, DeoptReason reason) {
1366   // Deoptimize only if the frame comes from compile code.
1367   // Do not deoptimize the frame which is already patched
1368   // during the execution of the loops below.
1369   if (!fr.is_compiled_frame() || fr.is_deoptimized_frame()) {
1370     return;
1371   }
1372   ResourceMark rm;
1373   DeoptimizationMarker dm;
1374   if (UseBiasedLocking) {
1375     if (in_handshake) {
1376       revoke_handshake(thread, fr, map);
1377     } else {
1378       revoke_safepoint(thread, fr, map);
1379     }
1380   }
1381   deoptimize_single_frame(thread, fr, reason);
1382 
1383 }
1384 
1385 #if INCLUDE_JVMCI
1386 address Deoptimization::deoptimize_for_missing_exception_handler(CompiledMethod* cm) {
1387   // there is no exception handler for this pc => deoptimize
1388   cm->make_not_entrant();
1389 
1390   // Use Deoptimization::deoptimize for all of its side-effects:
1391   // revoking biases of monitors, gathering traps statistics, logging...
1392   // it also patches the return pc but we do not care about that
1393   // since we return a continuation to the deopt_blob below.
1394   JavaThread* thread = JavaThread::current();
1395   RegisterMap reg_map(thread, UseBiasedLocking);
1396   frame runtime_frame = thread->last_frame();
1397   frame caller_frame = runtime_frame.sender(&reg_map);
1398   assert(caller_frame.cb()->as_compiled_method_or_null() == cm, "expect top frame compiled method");


1524 #if INCLUDE_JVMCI
1525   // JVMCI might need to get an exception from the stack, which in turn requires the register map to be valid
1526   RegisterMap reg_map(thread, true);
1527 #else
1528   RegisterMap reg_map(thread, UseBiasedLocking);
1529 #endif
1530   frame stub_frame = thread->last_frame();
1531   frame fr = stub_frame.sender(&reg_map);
1532   // Make sure the calling nmethod is not getting deoptimized and removed
1533   // before we are done with it.
1534   nmethodLocker nl(fr.pc());
1535 
1536   // Log a message
1537   Events::log(thread, "Uncommon trap: trap_request=" PTR32_FORMAT " fr.pc=" INTPTR_FORMAT " relative=" INTPTR_FORMAT,
1538               trap_request, p2i(fr.pc()), fr.pc() - fr.cb()->code_begin());
1539 
1540   {
1541     ResourceMark rm;
1542 
1543     // Revoke biases of any monitors in the frame to ensure we can migrate them
1544     revoke_biases_of_monitors(thread, fr, &reg_map);
1545 
1546     DeoptReason reason = trap_request_reason(trap_request);
1547     DeoptAction action = trap_request_action(trap_request);
1548 #if INCLUDE_JVMCI
1549     int debug_id = trap_request_debug_id(trap_request);
1550 #endif
1551     jint unloaded_class_index = trap_request_index(trap_request); // CP idx or -1
1552 
1553     vframe*  vf  = vframe::new_vframe(&fr, &reg_map, thread);
1554     compiledVFrame* cvf = compiledVFrame::cast(vf);
1555 
1556     CompiledMethod* nm = cvf->code();
1557 
1558     ScopeDesc*      trap_scope  = cvf->scope();
1559 
1560     if (TraceDeoptimization) {
1561       ttyLocker ttyl;
1562       tty->print_cr("  bci=%d pc=" INTPTR_FORMAT ", relative_pc=" INTPTR_FORMAT ", method=%s" JVMCI_ONLY(", debug_id=%d"), trap_scope->bci(), p2i(fr.pc()), fr.pc() - nm->code_begin(), trap_scope->method()->name_and_sig_as_C_string()
1563 #if INCLUDE_JVMCI
1564           , debug_id


< prev index next >