changeset 57809:2a0e2304e68b

8237375: SimpleThresholdPolicy misses CounterDecay timestamp initialization Reviewed-by: simonis, dholmes
author mdoerr
date Thu, 23 Jan 2020 13:55:10 +0100
parents 134c76da87c9
children 89e091daad39
files src/hotspot/share/compiler/compilationPolicy.cpp
diffstat 1 files changed, 45 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/compiler/compilationPolicy.cpp	Thu Jan 23 13:51:23 2020 +0800
+++ b/src/hotspot/share/compiler/compilationPolicy.cpp	Thu Jan 23 13:55:10 2020 +0100
@@ -190,6 +190,50 @@
   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 @@
   } else {
     _compiler_count = CICompilerCount;
   }
+  CounterDecay::update_last_timestamp();
 }
 
 // Note: this policy is used ONLY if TieredCompilation is off.
@@ -272,47 +317,6 @@
   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()) {