src/share/vm/runtime/deoptimization.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6614597 Sdiff src/share/vm/runtime

src/share/vm/runtime/deoptimization.cpp

Print this page




1315       // link the missing class, if any.
1316       make_not_entrant = true;
1317       break;
1318     case Action_make_not_compilable:
1319       // Give up on compiling this method at all.
1320       make_not_entrant = true;
1321       make_not_compilable = true;
1322       break;
1323     default:
1324       ShouldNotReachHere();
1325     }
1326 
1327     // Setting +ProfileTraps fixes the following, on all platforms:
1328     // 4852688: ProfileInterpreter is off by default for ia64.  The result is
1329     // infinite heroic-opt-uncommon-trap/deopt/recompile cycles, since the
1330     // recompile relies on a methodDataOop to record heroic opt failures.
1331 
1332     // Whether the interpreter is producing MDO data or not, we also need
1333     // to use the MDO to detect hot deoptimization points and control
1334     // aggressive optimization.

1335     if (ProfileTraps && update_trap_state && trap_mdo.not_null()) {
1336       assert(trap_mdo() == get_method_data(thread, trap_method, false), "sanity");
1337       uint this_trap_count = 0;
1338       bool maybe_prior_trap = false;
1339       bool maybe_prior_recompile = false;
1340       ProfileData* pdata
1341         = query_update_method_data(trap_mdo, trap_bci, reason,
1342                                    //outputs:
1343                                    this_trap_count,
1344                                    maybe_prior_trap,
1345                                    maybe_prior_recompile);
1346       // Because the interpreter also counts null, div0, range, and class
1347       // checks, these traps from compiled code are double-counted.
1348       // This is harmless; it just means that the PerXTrapLimit values
1349       // are in effect a little smaller than they look.
1350 
1351       DeoptReason per_bc_reason = reason_recorded_per_bytecode_if_any(reason);
1352       if (per_bc_reason != Reason_none) {
1353         // Now take action based on the partially known per-BCI history.
1354         if (maybe_prior_trap


1357           // This will allow the compiler to see the limit overflow, and
1358           // take corrective action, if possible.  The compiler generally
1359           // does not use the exact PerBytecodeTrapLimit value, but instead
1360           // changes its tactics if it sees any traps at all.  This provides
1361           // a little hysteresis, delaying a recompile until a trap happens
1362           // several times.
1363           //
1364           // Actually, since there is only one bit of counter per BCI,
1365           // the possible per-BCI counts are {0,1,(per-method count)}.
1366           // This produces accurate results if in fact there is only
1367           // one hot trap site, but begins to get fuzzy if there are
1368           // many sites.  For example, if there are ten sites each
1369           // trapping two or more times, they each get the blame for
1370           // all of their traps.
1371           make_not_entrant = true;
1372         }
1373 
1374         // Detect repeated recompilation at the same BCI, and enforce a limit.
1375         if (make_not_entrant && maybe_prior_recompile) {
1376           // More than one recompile at this point.
1377           trap_mdo->inc_overflow_recompile_count();
1378           if (maybe_prior_trap
1379               && ((uint)trap_mdo->overflow_recompile_count()
1380                   > (uint)PerBytecodeRecompilationCutoff)) {
1381             // Give up on the method containing the bad BCI.
1382             if (trap_method() == nm->method()) {
1383               make_not_compilable = true;
1384             } else {
1385               trap_method->set_not_compilable();
1386               // But give grace to the enclosing nm->method().





1387             }
1388           }
1389         }
1390       } else {
1391         // For reasons which are not recorded per-bytecode, we simply
1392         // force recompiles unconditionally.
1393         // (Note that PerMethodRecompilationCutoff is enforced elsewhere.)
1394         make_not_entrant = true;
1395       }

1396 
1397       // Go back to the compiler if there are too many traps in this method.
1398       if (this_trap_count >= (uint)PerMethodTrapLimit) {
1399         // If there are too many traps in this method, force a recompile.
1400         // This will allow the compiler to see the limit overflow, and
1401         // take corrective action, if possible.
1402         // (This condition is an unlikely backstop only, because the
1403         // PerBytecodeTrapLimit is more likely to take effect first,
1404         // if it is applicable.)
1405         make_not_entrant = true;
1406       }
1407 
1408       // Here's more hysteresis:  If there has been a recompile at
1409       // this trap point already, run the method in the interpreter
1410       // for a while to exercise it more thoroughly.
1411       if (make_not_entrant && maybe_prior_recompile && maybe_prior_trap) {





1412         reset_counters = true;
1413       }
1414 
1415       if (make_not_entrant && pdata != NULL) {
1416         // Record the recompilation event, if any.
1417         int tstate0 = pdata->trap_state();
1418         int tstate1 = trap_state_set_recompiled(tstate0, true);
1419         if (tstate1 != tstate0)
1420           pdata->set_trap_state(tstate1);
1421       }
1422     }
1423 
1424     // Take requested actions on the method:
1425 





















1426     // Reset invocation counters
1427     if (reset_counters) {
1428       if (nm->is_osr_method())
1429         reset_invocation_counter(trap_scope, CompileThreshold);
1430       else
1431         reset_invocation_counter(trap_scope);
1432     }
1433 
1434     // Recompile
1435     if (make_not_entrant) {
1436       nm->make_not_entrant();
1437     }
1438 
1439     // Give up compiling
1440     if (make_not_compilable) {
1441       assert(make_not_entrant, "consistent");
1442       nm->method()->set_not_compilable();
1443     }
1444 
1445   } // Free marked resources
1446 
1447 }
1448 JRT_END
1449 
1450 methodDataOop
1451 Deoptimization::get_method_data(JavaThread* thread, methodHandle m,
1452                                 bool create_if_missing) {
1453   Thread* THREAD = thread;
1454   methodDataOop mdo = m()->method_data();
1455   if (mdo == NULL && create_if_missing && !HAS_PENDING_EXCEPTION) {
1456     // Build an MDO.  Ignore errors like OutOfMemory;
1457     // that simply means we won't have an MDO to update.
1458     methodOopDesc::build_interpreter_method_data(m, THREAD);
1459     if (HAS_PENDING_EXCEPTION) {
1460       assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");


1493     // try to allocate one from the MDO's set of spares.
1494     // This will let us detect a repeated trap at this point.
1495     pdata = trap_mdo->allocate_bci_to_data(trap_bci);
1496 
1497     if (pdata != NULL) {
1498       // Query the trap state of this profile datum.
1499       int tstate0 = pdata->trap_state();
1500       if (!trap_state_has_reason(tstate0, per_bc_reason))
1501         maybe_prior_trap = false;
1502       if (!trap_state_is_recompiled(tstate0))
1503         maybe_prior_recompile = false;
1504 
1505       // Update the trap state of this profile datum.
1506       int tstate1 = tstate0;
1507       // Record the reason.
1508       tstate1 = trap_state_add_reason(tstate1, per_bc_reason);
1509       // Store the updated state on the MDO, for next time.
1510       if (tstate1 != tstate0)
1511         pdata->set_trap_state(tstate1);
1512     } else {
1513       if (LogCompilation && xtty != NULL)

1514         // Missing MDP?  Leave a small complaint in the log.
1515         xtty->elem("missing_mdp bci='%d'", trap_bci);
1516     }
1517   }

1518 
1519   // Return results:
1520   ret_this_trap_count = this_trap_count;
1521   ret_maybe_prior_trap = maybe_prior_trap;
1522   ret_maybe_prior_recompile = maybe_prior_recompile;
1523   return pdata;
1524 }
1525 
1526 void
1527 Deoptimization::update_method_data_from_interpreter(methodDataHandle trap_mdo, int trap_bci, int reason) {
1528   ResourceMark rm;
1529   // Ignored outputs:
1530   uint ignore_this_trap_count;
1531   bool ignore_maybe_prior_trap;
1532   bool ignore_maybe_prior_recompile;
1533   query_update_method_data(trap_mdo, trap_bci,
1534                            (DeoptReason)reason,
1535                            ignore_this_trap_count,
1536                            ignore_maybe_prior_trap,
1537                            ignore_maybe_prior_recompile);


1656 
1657 //--------------------------------statics--------------------------------------
1658 Deoptimization::DeoptAction Deoptimization::_unloaded_action
1659   = Deoptimization::Action_reinterpret;
1660 const char* Deoptimization::_trap_reason_name[Reason_LIMIT] = {
1661   // Note:  Keep this in sync. with enum DeoptReason.
1662   "none",
1663   "null_check",
1664   "null_assert",
1665   "range_check",
1666   "class_check",
1667   "array_check",
1668   "intrinsic",
1669   "unloaded",
1670   "uninitialized",
1671   "unreached",
1672   "unhandled",
1673   "constraint",
1674   "div0_check",
1675   "age",
1676   "predicate"

1677 };
1678 const char* Deoptimization::_trap_action_name[Action_LIMIT] = {
1679   // Note:  Keep this in sync. with enum DeoptAction.
1680   "none",
1681   "maybe_recompile",
1682   "reinterpret",
1683   "make_not_entrant",
1684   "make_not_compilable"
1685 };
1686 
1687 const char* Deoptimization::trap_reason_name(int reason) {
1688   if (reason == Reason_many)  return "many";
1689   if ((uint)reason < Reason_LIMIT)
1690     return _trap_reason_name[reason];
1691   static char buf[20];
1692   sprintf(buf, "reason%d", reason);
1693   return buf;
1694 }
1695 const char* Deoptimization::trap_action_name(int action) {
1696   if ((uint)action < Action_LIMIT)




1315       // link the missing class, if any.
1316       make_not_entrant = true;
1317       break;
1318     case Action_make_not_compilable:
1319       // Give up on compiling this method at all.
1320       make_not_entrant = true;
1321       make_not_compilable = true;
1322       break;
1323     default:
1324       ShouldNotReachHere();
1325     }
1326 
1327     // Setting +ProfileTraps fixes the following, on all platforms:
1328     // 4852688: ProfileInterpreter is off by default for ia64.  The result is
1329     // infinite heroic-opt-uncommon-trap/deopt/recompile cycles, since the
1330     // recompile relies on a methodDataOop to record heroic opt failures.
1331 
1332     // Whether the interpreter is producing MDO data or not, we also need
1333     // to use the MDO to detect hot deoptimization points and control
1334     // aggressive optimization.
1335     bool inc_recompile_count = false;
1336     if (ProfileTraps && update_trap_state && trap_mdo.not_null()) {
1337       assert(trap_mdo() == get_method_data(thread, trap_method, false), "sanity");
1338       uint this_trap_count = 0;
1339       bool maybe_prior_trap = false;
1340       bool maybe_prior_recompile = false;
1341       ProfileData* pdata
1342         = query_update_method_data(trap_mdo, trap_bci, reason,
1343                                    //outputs:
1344                                    this_trap_count,
1345                                    maybe_prior_trap,
1346                                    maybe_prior_recompile);
1347       // Because the interpreter also counts null, div0, range, and class
1348       // checks, these traps from compiled code are double-counted.
1349       // This is harmless; it just means that the PerXTrapLimit values
1350       // are in effect a little smaller than they look.
1351 
1352       DeoptReason per_bc_reason = reason_recorded_per_bytecode_if_any(reason);
1353       if (per_bc_reason != Reason_none) {
1354         // Now take action based on the partially known per-BCI history.
1355         if (maybe_prior_trap


1358           // This will allow the compiler to see the limit overflow, and
1359           // take corrective action, if possible.  The compiler generally
1360           // does not use the exact PerBytecodeTrapLimit value, but instead
1361           // changes its tactics if it sees any traps at all.  This provides
1362           // a little hysteresis, delaying a recompile until a trap happens
1363           // several times.
1364           //
1365           // Actually, since there is only one bit of counter per BCI,
1366           // the possible per-BCI counts are {0,1,(per-method count)}.
1367           // This produces accurate results if in fact there is only
1368           // one hot trap site, but begins to get fuzzy if there are
1369           // many sites.  For example, if there are ten sites each
1370           // trapping two or more times, they each get the blame for
1371           // all of their traps.
1372           make_not_entrant = true;
1373         }
1374 
1375         // Detect repeated recompilation at the same BCI, and enforce a limit.
1376         if (make_not_entrant && maybe_prior_recompile) {
1377           // More than one recompile at this point.
1378           inc_recompile_count = maybe_prior_trap;
1379         }





1380       } else {
1381         if (reason == Reason_bimorphic) {
1382           // This isn't recorded per bci because of MDO limitations
1383           // but lets piggy back the invalidation on the
1384           // Reason_class_check count.
1385           uint prior_trap_count = trap_mdo->trap_count(Reason_bimorphic);
1386           if (prior_trap_count >= (uint)PerBytecodeTrapLimit) {
1387             make_not_entrant = true;
1388           }


1389         } else {
1390           // For reasons which are not recorded per-bytecode, we simply
1391           // force recompiles unconditionally.
1392           // (Note that PerMethodRecompilationCutoff is enforced elsewhere.)
1393           make_not_entrant = true;
1394         }
1395       }
1396 
1397       // Go back to the compiler if there are too many traps in this method.
1398       if (this_trap_count >= (uint)PerMethodTrapLimit) {
1399         // If there are too many traps in this method, force a recompile.
1400         // This will allow the compiler to see the limit overflow, and
1401         // take corrective action, if possible.
1402         // (This condition is an unlikely backstop only, because the
1403         // PerBytecodeTrapLimit is more likely to take effect first,
1404         // if it is applicable.)
1405         make_not_entrant = true;
1406       }
1407 
1408       // Here's more hysteresis:  If there has been a recompile at
1409       // this trap point already, run the method in the interpreter
1410       // for a while to exercise it more thoroughly.
1411       // Also do this to collect more data for transition from monomorphic
1412       // case to bimorphic. But recompile method immediately if it is already
1413       // compiled with bimorphic code.
1414       if (make_not_entrant && maybe_prior_trap && 
1415           ((maybe_prior_recompile && reason != Reason_bimorphic) ||
1416            (UseBimorphicInlining  && reason == Reason_class_check))) {
1417         reset_counters = true;
1418       }
1419 
1420       if (make_not_entrant && pdata != NULL) {
1421         // Record the recompilation event, if any.
1422         int tstate0 = pdata->trap_state();
1423         int tstate1 = trap_state_set_recompiled(tstate0, true);
1424         if (tstate1 != tstate0)
1425           pdata->set_trap_state(tstate1);
1426       }
1427     }
1428 
1429     // Take requested actions on the method:
1430 
1431     // Recompile
1432     if (make_not_entrant) {
1433       if (!nm->make_not_entrant()) {
1434         return; // the call did not change nmethod's state
1435       }
1436     }
1437 
1438     if (inc_recompile_count) {
1439       trap_mdo->inc_overflow_recompile_count();
1440       if ((uint)trap_mdo->overflow_recompile_count() >
1441           (uint)PerBytecodeRecompilationCutoff) {
1442         // Give up on the method containing the bad BCI.
1443         if (trap_method() == nm->method()) {
1444           make_not_compilable = true;
1445         } else {
1446           trap_method->set_not_compilable();
1447           // But give grace to the enclosing nm->method().
1448         }
1449       }
1450     }
1451 
1452     // Reset invocation counters
1453     if (reset_counters) {
1454       if (nm->is_osr_method())
1455         reset_invocation_counter(trap_scope, CompileThreshold);
1456       else
1457         reset_invocation_counter(trap_scope);
1458     }
1459 





1460     // Give up compiling
1461     if (make_not_compilable && !nm->method()->is_not_compilable()) {
1462       assert(make_not_entrant, "consistent");
1463       nm->method()->set_not_compilable();
1464     }
1465 
1466   } // Free marked resources
1467 
1468 }
1469 JRT_END
1470 
1471 methodDataOop
1472 Deoptimization::get_method_data(JavaThread* thread, methodHandle m,
1473                                 bool create_if_missing) {
1474   Thread* THREAD = thread;
1475   methodDataOop mdo = m()->method_data();
1476   if (mdo == NULL && create_if_missing && !HAS_PENDING_EXCEPTION) {
1477     // Build an MDO.  Ignore errors like OutOfMemory;
1478     // that simply means we won't have an MDO to update.
1479     methodOopDesc::build_interpreter_method_data(m, THREAD);
1480     if (HAS_PENDING_EXCEPTION) {
1481       assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");


1514     // try to allocate one from the MDO's set of spares.
1515     // This will let us detect a repeated trap at this point.
1516     pdata = trap_mdo->allocate_bci_to_data(trap_bci);
1517 
1518     if (pdata != NULL) {
1519       // Query the trap state of this profile datum.
1520       int tstate0 = pdata->trap_state();
1521       if (!trap_state_has_reason(tstate0, per_bc_reason))
1522         maybe_prior_trap = false;
1523       if (!trap_state_is_recompiled(tstate0))
1524         maybe_prior_recompile = false;
1525 
1526       // Update the trap state of this profile datum.
1527       int tstate1 = tstate0;
1528       // Record the reason.
1529       tstate1 = trap_state_add_reason(tstate1, per_bc_reason);
1530       // Store the updated state on the MDO, for next time.
1531       if (tstate1 != tstate0)
1532         pdata->set_trap_state(tstate1);
1533     } else {
1534       if (LogCompilation && xtty != NULL) {
1535         ttyLocker ttyl;
1536         // Missing MDP?  Leave a small complaint in the log.
1537         xtty->elem("missing_mdp bci='%d'", trap_bci);
1538       }
1539     }
1540   }
1541 
1542   // Return results:
1543   ret_this_trap_count = this_trap_count;
1544   ret_maybe_prior_trap = maybe_prior_trap;
1545   ret_maybe_prior_recompile = maybe_prior_recompile;
1546   return pdata;
1547 }
1548 
1549 void
1550 Deoptimization::update_method_data_from_interpreter(methodDataHandle trap_mdo, int trap_bci, int reason) {
1551   ResourceMark rm;
1552   // Ignored outputs:
1553   uint ignore_this_trap_count;
1554   bool ignore_maybe_prior_trap;
1555   bool ignore_maybe_prior_recompile;
1556   query_update_method_data(trap_mdo, trap_bci,
1557                            (DeoptReason)reason,
1558                            ignore_this_trap_count,
1559                            ignore_maybe_prior_trap,
1560                            ignore_maybe_prior_recompile);


1679 
1680 //--------------------------------statics--------------------------------------
1681 Deoptimization::DeoptAction Deoptimization::_unloaded_action
1682   = Deoptimization::Action_reinterpret;
1683 const char* Deoptimization::_trap_reason_name[Reason_LIMIT] = {
1684   // Note:  Keep this in sync. with enum DeoptReason.
1685   "none",
1686   "null_check",
1687   "null_assert",
1688   "range_check",
1689   "class_check",
1690   "array_check",
1691   "intrinsic",
1692   "unloaded",
1693   "uninitialized",
1694   "unreached",
1695   "unhandled",
1696   "constraint",
1697   "div0_check",
1698   "age",
1699   "predicate",
1700   "bimorphic"
1701 };
1702 const char* Deoptimization::_trap_action_name[Action_LIMIT] = {
1703   // Note:  Keep this in sync. with enum DeoptAction.
1704   "none",
1705   "maybe_recompile",
1706   "reinterpret",
1707   "make_not_entrant",
1708   "make_not_compilable"
1709 };
1710 
1711 const char* Deoptimization::trap_reason_name(int reason) {
1712   if (reason == Reason_many)  return "many";
1713   if ((uint)reason < Reason_LIMIT)
1714     return _trap_reason_name[reason];
1715   static char buf[20];
1716   sprintf(buf, "reason%d", reason);
1717   return buf;
1718 }
1719 const char* Deoptimization::trap_action_name(int action) {
1720   if ((uint)action < Action_LIMIT)


src/share/vm/runtime/deoptimization.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File