8215727: Restore JFR thread sampler loop to old / previous behavior
authormgronlun
Fri, 21 Dec 2018 16:56:40 +0100
changeset 53096 58154bf80f90
parent 53095 33a51275fee0
child 53097 2e82ca64b25d
8215727: Restore JFR thread sampler loop to old / previous behavior Reviewed-by: egahlin, mgronlun Contributed-by: milan.mimica@gmail.com
src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp
--- a/src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp	Fri Dec 21 09:54:32 2018 -0500
+++ b/src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp	Fri Dec 21 16:56:40 2018 +0100
@@ -287,13 +287,13 @@
 
 void JfrThreadSampleClosure::commit_events(JfrSampleType type) {
   if (JAVA_SAMPLE == type) {
-    assert(_added_java <= MAX_NR_OF_JAVA_SAMPLES, "invariant");
+    assert(_added_java > 0 && _added_java <= MAX_NR_OF_JAVA_SAMPLES, "invariant");
     for (uint i = 0; i < _added_java; ++i) {
       _events[i].commit();
     }
   } else {
     assert(NATIVE_SAMPLE == type, "invariant");
-    assert(_added_native <= MAX_NR_OF_NATIVE_SAMPLES, "invariant");
+    assert(_added_native > 0 && _added_native <= MAX_NR_OF_NATIVE_SAMPLES, "invariant");
     for (uint i = 0; i < _added_native; ++i) {
       _events_native[i].commit();
     }
@@ -495,7 +495,7 @@
   JfrThreadSampleClosure sample_task(samples, samples_native);
 
   const uint sample_limit = JAVA_SAMPLE == type ? MAX_NR_OF_JAVA_SAMPLES : MAX_NR_OF_NATIVE_SAMPLES;
-  uint num_sample_attempts = 0;
+  uint num_samples = 0;
   JavaThread* start = NULL;
 
   {
@@ -509,7 +509,7 @@
       _cur_index = tlh.list()->find_index_of_JavaThread(*last_thread);
       JavaThread* current = _cur_index != -1 ? *last_thread : NULL;
 
-      while (num_sample_attempts < sample_limit) {
+      while (num_samples < sample_limit) {
         current = next_thread(tlh.list(), start, current);
         if (current == NULL) {
           break;
@@ -520,8 +520,9 @@
         if (current->is_Compiler_thread()) {
           continue;
         }
-        sample_task.do_sample_thread(current, _frames, _max_frames, type);
-        num_sample_attempts++;
+        if (sample_task.do_sample_thread(current, _frames, _max_frames, type)) {
+          num_samples++;
+        }
       }
       *last_thread = current;  // remember the thread we last attempted to sample
     }
@@ -529,7 +530,7 @@
     log_trace(jfr)("JFR thread sampling done in %3.7f secs with %d java %d native samples",
                    sample_time.seconds(), sample_task.java_entries(), sample_task.native_entries());
   }
-  if (num_sample_attempts > 0) {
+  if (num_samples > 0) {
     sample_task.commit_events(type);
   }
 }