// update_rate() is called from select_task() while holding a compile queue lock. void AdvancedThresholdPolicy::update_rate(jlong t, methodOop m) { if (is_old(m)) { // We don't remove old methods from the queue, // so we can just zero the rate. m->set_rate(0); return; } // We don't update the rate if we've just came out of a safepoint. // delta_s is the time since last safepoint in milliseconds. jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint(); jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement // How many events were there since the last time? int event_count = m->invocation_count() + m->backedge_count(); int delta_e = event_count - m->prev_event_count(); // We should be running for at least 1ms. if (delta_s >= TieredRateUpdateMinTime) { // And we must've taken the previous point at least 1ms before. if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) { m->set_prev_time(t); m->set_prev_event_count(event_count); m->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond } else if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) { // If nothing happened for 25ms, zero the rate. Don't modify prev values. m->set_rate(0); } } }
// Check if this method has been stale from a given number of milliseconds. // See select_task(). bool AdvancedThresholdPolicy::is_stale(jlong t, jlong timeout, methodOop m) { jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint(); jlong delta_t = t - m->prev_time(); if (delta_t > timeout && delta_s > timeout) { int event_count = m->invocation_count() + m->backedge_count(); int delta_e = event_count - m->prev_event_count(); // Return true if there were no events. return delta_e == 0; } return false; }