< prev index next >

src/hotspot/share/runtime/threadHeapSampler.cpp

Print this page
rev 49244 : [mq]: event-only
rev 49247 : [mq]: event5

@@ -25,17 +25,18 @@
 #include "runtime/sharedRuntime.hpp"
 #include "runtime/threadHeapSampler.hpp"
 
 // Cheap random number generator
 uint64_t ThreadHeapSampler::_rnd;
-int ThreadHeapSampler::_monitoring_rate;
+int ThreadHeapSampler::_sampling_rate;
 int ThreadHeapSampler::_enabled;
 
 // Statics for the fast log
 static const int FastLogNumBits = 10;
 static const int FastLogMask = (1 << FastLogNumBits) - 1;
-static double _log_table[1<<FastLogNumBits];  // Constant
+static double log_table[1<<FastLogNumBits];  // Constant
+static bool log_table_initialized;
 
 // Returns the next prng value.
 // pRNG is: aX+b mod c with a = 0x5DEECE66D, b =  0xB, c = 1<<48
 // This is the lrand64 generator.
 static uint64_t next_random(uint64_t rnd) {

@@ -51,11 +52,11 @@
   uint64_t x = 0;
   memcpy(&x, &d, sizeof(uint64_t));
   const uint32_t x_high = x >> 32;
   const uint32_t y = x_high >> (20 - FastLogNumBits) & FastLogMask;
   const int32_t exponent = ((x_high >> 20) & 0x7FF) - 1023;
-  return exponent + _log_table[y];
+  return exponent + log_table[y];
 }
 
 // Generates a geometric variable with the specified mean (512K by default).
 // This is done by generating a random number between 0 and 1 and applying
 // the inverse cumulative distribution function for an exponential.

@@ -84,11 +85,11 @@
   // The value 26.000705 is used rather than 26 to compensate
   // for inaccuracies in FastLog2 which otherwise result in a
   // negative answer.
   double log_val = (fast_log2(q) - 26);
   size_t rate = static_cast<size_t>(
-      (0.0 < log_val ? 0.0 : log_val) * (-log(2.0) * (_monitoring_rate)) + 1);
+      (0.0 < log_val ? 0.0 : log_val) * (-log(2.0) * (_sampling_rate)) + 1);
   _bytes_until_sample = rate;
 
   // Try to correct sample size by removing extra space from last allocation.
   if (overflowed_bytes > 0 && _bytes_until_sample > overflowed_bytes) {
     _bytes_until_sample -= overflowed_bytes;

@@ -109,14 +110,29 @@
 
   size_t overflow_bytes = total_allocated_bytes - _bytes_until_sample;
   pick_next_sample(overflow_bytes);
 }
 
-void ThreadHeapSampler::set_tlab_heap_sampling(int monitoring_rate) {
-  if (monitoring_rate == 0) {
+void ThreadHeapSampler::init_log_table() {
+  MutexLocker mu(ThreadHeapSampler_lock);
+
+  if (log_table_initialized) {
+    return;
+  }
+
+  for (int i = 0; i < (1 << FastLogNumBits); i++) {
+    log_table[i] = (log(1.0 + static_cast<double>(i+0.5) / (1 << FastLogNumBits))
+                     / log(2.0));
+  }
+
+  log_table_initialized = true;
+}
+
+void ThreadHeapSampler::set_tlab_heap_sampling(int sampling_rate) {
+  if (sampling_rate == 0) {
     disable();
-    _monitoring_rate = monitoring_rate;
+    _sampling_rate = sampling_rate;
   } else {
-    _monitoring_rate = monitoring_rate;
+    _sampling_rate = sampling_rate;
     enable();
   }
 }
< prev index next >