Skip to content
Permalink
Browse files

8237375: SimpleThresholdPolicy misses CounterDecay timestamp initiali…

…zation

Reviewed-by: simonis, dholmes
  • Loading branch information
Martin Doerr
Martin Doerr committed Jan 23, 2020
1 parent a0882bf commit da7cebabb2c1fd8d4c9cd86dc605818b47eb11b1
Showing with 45 additions and 41 deletions.
  1. +45 −41 src/hotspot/share/compiler/compilationPolicy.cpp
@@ -190,6 +190,50 @@ CompileTask* CompilationPolicy::select_task_helper(CompileQueue* compile_queue)
return compile_queue->first();
}


//
// CounterDecay for SimpleCompPolicy
//
// Iterates through invocation counters and decrements them. This
// is done at each safepoint.
//
class CounterDecay : public AllStatic {
static jlong _last_timestamp;
static void do_method(Method* m) {
MethodCounters* mcs = m->method_counters();
if (mcs != NULL) {
mcs->invocation_counter()->decay();
}
}
public:
static void decay();
static bool is_decay_needed() {
return nanos_to_millis(os::javaTimeNanos() - _last_timestamp) > CounterDecayMinIntervalLength;
}
static void update_last_timestamp() { _last_timestamp = os::javaTimeNanos(); }
};

jlong CounterDecay::_last_timestamp = 0;

void CounterDecay::decay() {
update_last_timestamp();

// This operation is going to be performed only at the end of a safepoint
// and hence GC's will not be going on, all Java mutators are suspended
// at this point and hence SystemDictionary_lock is also not needed.
assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint");
size_t nclasses = ClassLoaderDataGraph::num_instance_classes();
size_t classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 /
CounterHalfLifeTime);
for (size_t i = 0; i < classes_per_tick; i++) {
InstanceKlass* k = ClassLoaderDataGraph::try_get_next_class();
if (k != NULL) {
k->methods_do(do_method);
}
}
}


#ifndef PRODUCT
void SimpleCompPolicy::trace_osr_completion(nmethod* osr_nm) {
if (TraceOnStackReplacement) {
@@ -223,6 +267,7 @@ void SimpleCompPolicy::initialize() {
} else {
_compiler_count = CICompilerCount;
}
CounterDecay::update_last_timestamp();
}

// Note: this policy is used ONLY if TieredCompilation is off.
@@ -272,47 +317,6 @@ void SimpleCompPolicy::reset_counter_for_back_branch_event(const methodHandle& m
b->set(b->state(), CompileThreshold / 2);
}

//
// CounterDecay
//
// Iterates through invocation counters and decrements them. This
// is done at each safepoint.
//
class CounterDecay : public AllStatic {
static jlong _last_timestamp;
static void do_method(Method* m) {
MethodCounters* mcs = m->method_counters();
if (mcs != NULL) {
mcs->invocation_counter()->decay();
}
}
public:
static void decay();
static bool is_decay_needed() {
return nanos_to_millis(os::javaTimeNanos() - _last_timestamp) > CounterDecayMinIntervalLength;
}
};

jlong CounterDecay::_last_timestamp = 0;

void CounterDecay::decay() {
_last_timestamp = os::javaTimeNanos();

// This operation is going to be performed only at the end of a safepoint
// and hence GC's will not be going on, all Java mutators are suspended
// at this point and hence SystemDictionary_lock is also not needed.
assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint");
size_t nclasses = ClassLoaderDataGraph::num_instance_classes();
size_t classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 /
CounterHalfLifeTime);
for (size_t i = 0; i < classes_per_tick; i++) {
InstanceKlass* k = ClassLoaderDataGraph::try_get_next_class();
if (k != NULL) {
k->methods_do(do_method);
}
}
}

// Called at the end of the safepoint
void SimpleCompPolicy::do_safepoint_work() {
if(UseCounterDecay && CounterDecay::is_decay_needed()) {

0 comments on commit da7ceba

Please sign in to comment.