Blame SOURCES/jdk8215727-rh1889532-restore_jfr_thread_sampler_loop.patch

e6c518
# HG changeset patch
e6c518
# User mgronlun
e6c518
# Date 1545407800 -3600
e6c518
#      Fri Dec 21 16:56:40 2018 +0100
e6c518
# Node ID 321a84a5e5b88cbb88f72aa98645affc57689fb0
e6c518
# Parent  002b9c947f0f3d53aebccffb922460701555b456
e6c518
8215727: Restore JFR thread sampler loop to old / previous behavior
e6c518
Reviewed-by: egahlin, mgronlun
e6c518
Contributed-by: milan.mimica@gmail.com
e6c518
e6c518
diff --git openjdk.orig/hotspot/src/share/vm/jfr/periodic/sampling/jfrThreadSampler.cpp openjdk/hotspot/src/share/vm/jfr/periodic/sampling/jfrThreadSampler.cpp
e6c518
--- openjdk.orig/hotspot/src/share/vm/jfr/periodic/sampling/jfrThreadSampler.cpp
e6c518
+++ openjdk/hotspot/src/share/vm/jfr/periodic/sampling/jfrThreadSampler.cpp
e6c518
@@ -285,13 +285,13 @@
e6c518
 
e6c518
 void JfrThreadSampleClosure::commit_events(JfrSampleType type) {
e6c518
   if (JAVA_SAMPLE == type) {
e6c518
-    assert(_added_java <= MAX_NR_OF_JAVA_SAMPLES, "invariant");
e6c518
+    assert(_added_java > 0 && _added_java <= MAX_NR_OF_JAVA_SAMPLES, "invariant");
e6c518
     for (uint i = 0; i < _added_java; ++i) {
e6c518
       _events[i].commit();
e6c518
     }
e6c518
   } else {
e6c518
     assert(NATIVE_SAMPLE == type, "invariant");
e6c518
-    assert(_added_native <= MAX_NR_OF_NATIVE_SAMPLES, "invariant");
e6c518
+    assert(_added_native > 0 && _added_native <= MAX_NR_OF_NATIVE_SAMPLES, "invariant");
e6c518
     for (uint i = 0; i < _added_native; ++i) {
e6c518
       _events_native[i].commit();
e6c518
     }
e6c518
@@ -537,7 +537,7 @@
e6c518
   JfrThreadSampleClosure sample_task(samples, samples_native);
e6c518
 
e6c518
   const uint sample_limit = JAVA_SAMPLE == type ? MAX_NR_OF_JAVA_SAMPLES : MAX_NR_OF_NATIVE_SAMPLES;
e6c518
-  uint num_sample_attempts = 0;
e6c518
+  uint num_samples = 0;
e6c518
   JavaThread* start = NULL;
e6c518
 
e6c518
   {
e6c518
@@ -555,7 +555,7 @@
e6c518
       JavaThread* current = Threads::includes(*last_thread) ? *last_thread : NULL;
e6c518
       JavaThread* start = NULL;
e6c518
 
e6c518
-      while (num_sample_attempts < sample_limit) {
e6c518
+      while (num_samples < sample_limit) {
e6c518
         current = next_thread(threads_list, index, start, current);
e6c518
         if (current == NULL) {
e6c518
           break;
e6c518
@@ -566,8 +566,9 @@
e6c518
         if (current->is_Compiler_thread()) {
e6c518
           continue;
e6c518
         }
e6c518
-        sample_task.do_sample_thread(current, _frames, _max_frames, type);
e6c518
-        num_sample_attempts++;
e6c518
+        if (sample_task.do_sample_thread(current, _frames, _max_frames, type)) {
e6c518
+          num_samples++;
e6c518
+        }
e6c518
       }
e6c518
       *last_thread = current;  // remember the thread we last attempted to sample
e6c518
       FREE_C_HEAP_ARRAY(JavaThread *, threads_list, mtInternal);
e6c518
@@ -576,7 +577,7 @@
e6c518
     if (LogJFR && Verbose) tty->print_cr("JFR thread sampling done in %3.7f secs with %d java %d native samples",
e6c518
                    sample_time.seconds(), sample_task.java_entries(), sample_task.native_entries());
e6c518
   }
e6c518
-  if (num_sample_attempts > 0) {
e6c518
+  if (num_samples > 0) {
e6c518
     sample_task.commit_events(type);
e6c518
   }
e6c518
 }