< prev index next >
src/hotspot/share/runtime/threadHeapSampler.cpp
Print this page
rev 49264 : [mq]: event-only
rev 49267 : [mq]: event5
rev 49268 : [mq]: event6
@@ -25,11 +25,12 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/threadHeapSampler.hpp"
// Cheap random number generator
uint64_t ThreadHeapSampler::_rnd;
-int ThreadHeapSampler::_sampling_rate;
+// Default is 512kb.
+int ThreadHeapSampler::_sampling_rate = 512 * 1024;
int ThreadHeapSampler::_enabled;
// Statics for the fast log
static const int FastLogNumBits = 10;
static const int FastLogMask = (1 << FastLogNumBits) - 1;
@@ -66,11 +67,11 @@
// q = 1 - p = exp(-mx)
// log_e(q) = -mx
// -log_e(q)/m = x
// log_2(q) * (-log_e(2) * 1/m) = x
// In the code, q is actually in the range 1 to 2**26, hence the -26 below
-void ThreadHeapSampler::pick_next_sample(size_t overflowed_bytes) {
+void ThreadHeapSampler::pick_next_geometric_sample() {
_rnd = next_random(_rnd);
// Take the top 26 bits as the random number
// (This plus a 1<<58 sampling bound gives a max possible step of
// 5194297183973780480 bytes. In this case,
// for sample_parameter = 1<<19, max possible step is
@@ -87,10 +88,19 @@
// 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) * (_sampling_rate)) + 1);
_bytes_until_sample = rate;
+}
+
+void ThreadHeapSampler::pick_next_sample(size_t overflowed_bytes) {
+ if (_sampling_rate == 1) {
+ _bytes_until_sample = 1;
+ return;
+ }
+
+ pick_next_geometric_sample();
// 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;
}
@@ -126,13 +136,8 @@
log_table_initialized = true;
}
void ThreadHeapSampler::set_tlab_heap_sampling(int sampling_rate) {
- if (sampling_rate == 0) {
- disable();
- _sampling_rate = sampling_rate;
- } else {
+ MutexLocker mu(ThreadHeapSampler_lock);
_sampling_rate = sampling_rate;
- enable();
- }
}
< prev index next >