8211980: Remove ThreadHeapSampler enable/disable/enabled methods

Remove methods from ThreadHeapSampler

Reviewed-by: dholmes, phh
This commit is contained in:
Jean Christophe Beyler 2018-10-15 14:16:35 -07:00
parent 6352b5f64d
commit d7c7ce19f1
6 changed files with 33 additions and 62 deletions

View file

@ -187,7 +187,7 @@ void MemAllocator::Allocation::notify_allocation_jvmti_sampler() {
// support for JVMTI VMObjectAlloc event (no-op if not enabled) // support for JVMTI VMObjectAlloc event (no-op if not enabled)
JvmtiExport::vm_object_alloc_event_collector(obj()); JvmtiExport::vm_object_alloc_event_collector(obj());
if (!ThreadHeapSampler::enabled()) { if (!JvmtiExport::should_post_sampled_object_alloc()) {
// Sampling disabled // Sampling disabled
return; return;
} }
@ -282,7 +282,7 @@ HeapWord* MemAllocator::allocate_inside_tlab_slow(Allocation& allocation) const
HeapWord* mem = NULL; HeapWord* mem = NULL;
ThreadLocalAllocBuffer& tlab = _thread->tlab(); ThreadLocalAllocBuffer& tlab = _thread->tlab();
if (ThreadHeapSampler::enabled()) { if (JvmtiExport::should_post_sampled_object_alloc()) {
// Try to allocate the sampled object from TLAB, it is possible a sample // Try to allocate the sampled object from TLAB, it is possible a sample
// point was put and the TLAB still has space. // point was put and the TLAB still has space.
tlab.set_back_allocation_end(); tlab.set_back_allocation_end();

View file

@ -540,13 +540,6 @@ JvmtiEnv::SetEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event_type, j
record_class_file_load_hook_enabled(); record_class_file_load_hook_enabled();
} }
if (event_type == JVMTI_EVENT_SAMPLED_OBJECT_ALLOC) {
if (enabled) {
ThreadHeapSampler::enable();
} else {
ThreadHeapSampler::disable();
}
}
JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL, event_type, enabled); JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL, event_type, enabled);
} else { } else {
// We have a specified event_thread. // We have a specified event_thread.

View file

@ -133,8 +133,6 @@ Monitor* Service_lock = NULL;
Monitor* PeriodicTask_lock = NULL; Monitor* PeriodicTask_lock = NULL;
Monitor* RedefineClasses_lock = NULL; Monitor* RedefineClasses_lock = NULL;
Mutex* ThreadHeapSampler_lock = NULL;
#if INCLUDE_JFR #if INCLUDE_JFR
Mutex* JfrStacktrace_lock = NULL; Mutex* JfrStacktrace_lock = NULL;
Monitor* JfrMsg_lock = NULL; Monitor* JfrMsg_lock = NULL;
@ -301,8 +299,6 @@ void mutex_init() {
def(PeriodicTask_lock , PaddedMonitor, nonleaf+5, true, Monitor::_safepoint_check_sometimes); def(PeriodicTask_lock , PaddedMonitor, nonleaf+5, true, Monitor::_safepoint_check_sometimes);
def(RedefineClasses_lock , PaddedMonitor, nonleaf+5, true, Monitor::_safepoint_check_always); def(RedefineClasses_lock , PaddedMonitor, nonleaf+5, true, Monitor::_safepoint_check_always);
def(ThreadHeapSampler_lock , PaddedMutex, nonleaf, false, Monitor::_safepoint_check_never);
if (WhiteBoxAPI) { if (WhiteBoxAPI) {
def(Compilation_lock , PaddedMonitor, leaf, false, Monitor::_safepoint_check_never); def(Compilation_lock , PaddedMonitor, leaf, false, Monitor::_safepoint_check_never);
} }

View file

@ -132,7 +132,6 @@ extern Mutex* Management_lock; // a lock used to serialize JVM
extern Monitor* Service_lock; // a lock used for service thread operation extern Monitor* Service_lock; // a lock used for service thread operation
extern Monitor* PeriodicTask_lock; // protects the periodic task structure extern Monitor* PeriodicTask_lock; // protects the periodic task structure
extern Monitor* RedefineClasses_lock; // locks classes from parallel redefinition extern Monitor* RedefineClasses_lock; // locks classes from parallel redefinition
extern Mutex* ThreadHeapSampler_lock; // protects the static data for initialization.
#if INCLUDE_JFR #if INCLUDE_JFR
extern Mutex* JfrStacktrace_lock; // used to guard access to the JFR stacktrace table extern Mutex* JfrStacktrace_lock; // used to guard access to the JFR stacktrace table

View file

@ -29,22 +29,29 @@
#include "runtime/sharedRuntime.hpp" #include "runtime/sharedRuntime.hpp"
#include "runtime/threadHeapSampler.hpp" #include "runtime/threadHeapSampler.hpp"
// Cheap random number generator // Cheap random number generator.
uint64_t ThreadHeapSampler::_rnd; uint64_t ThreadHeapSampler::_rnd;
// Default is 512kb. // Default is 512kb.
int ThreadHeapSampler::_sampling_interval = 512 * 1024; volatile int ThreadHeapSampler::_sampling_interval = 512 * 1024;
int ThreadHeapSampler::_enabled;
// Statics for the fast log // Ordering here is important: _log_table first, _log_table_initialized second.
static const int FastLogNumBits = 10; double ThreadHeapSampler::_log_table[1 << ThreadHeapSampler::FastLogNumBits] = {};
static const int FastLogMask = (1 << FastLogNumBits) - 1;
static double log_table[1<<FastLogNumBits]; // Constant // Force initialization of the log_table.
static bool log_table_initialized; bool ThreadHeapSampler::_log_table_initialized = init_log_table();
bool ThreadHeapSampler::init_log_table() {
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));
}
return true;
}
// Returns the next prng value. // Returns the next prng value.
// pRNG is: aX+b mod c with a = 0x5DEECE66D, b = 0xB, c = 1<<48 // pRNG is: aX+b mod c with a = 0x5DEECE66D, b = 0xB, c = 1<<48
// This is the lrand64 generator. // This is the lrand64 generator.
static uint64_t next_random(uint64_t rnd) { uint64_t ThreadHeapSampler::next_random(uint64_t rnd) {
const uint64_t PrngMult = 0x5DEECE66DLL; const uint64_t PrngMult = 0x5DEECE66DLL;
const uint64_t PrngAdd = 0xB; const uint64_t PrngAdd = 0xB;
const uint64_t PrngModPower = 48; const uint64_t PrngModPower = 48;
@ -54,7 +61,7 @@ static uint64_t next_random(uint64_t rnd) {
return (PrngMult * rnd + PrngAdd) & PrngModMask; return (PrngMult * rnd + PrngAdd) & PrngModMask;
} }
static double fast_log2(const double & d) { double ThreadHeapSampler::fast_log2(const double& d) {
assert(d>0, "bad value passed to assert"); assert(d>0, "bad value passed to assert");
uint64_t x = 0; uint64_t x = 0;
assert(sizeof(d) == sizeof(x), assert(sizeof(d) == sizeof(x),
@ -64,7 +71,9 @@ static double fast_log2(const double & d) {
assert(FastLogNumBits <= 20, "FastLogNumBits should be less than 20."); assert(FastLogNumBits <= 20, "FastLogNumBits should be less than 20.");
const uint32_t y = x_high >> (20 - FastLogNumBits) & FastLogMask; const uint32_t y = x_high >> (20 - FastLogNumBits) & FastLogMask;
const int32_t exponent = ((x_high >> 20) & 0x7FF) - 1023; const int32_t exponent = ((x_high >> 20) & 0x7FF) - 1023;
return exponent + log_table[y];
assert(_log_table_initialized, "log table should be initialized");
return exponent + _log_table[y];
} }
// Generates a geometric variable with the specified mean (512K by default). // Generates a geometric variable with the specified mean (512K by default).
@ -134,36 +143,6 @@ void ThreadHeapSampler::check_for_sampling(oop obj, size_t allocation_size, size
pick_next_sample(overflow_bytes); pick_next_sample(overflow_bytes);
} }
void ThreadHeapSampler::init_log_table() {
MutexLockerEx mu(ThreadHeapSampler_lock, Mutex::_no_safepoint_check_flag);
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::enable() {
// Done here to be done when things have settled. This adds a mutex lock but
// presumably, users won't be enabling and disabling all the time.
init_log_table();
OrderAccess::release_store(&_enabled, 1);
}
int ThreadHeapSampler::enabled() {
return OrderAccess::load_acquire(&_enabled);
}
void ThreadHeapSampler::disable() {
OrderAccess::release_store(&_enabled, 0);
}
int ThreadHeapSampler::get_sampling_interval() { int ThreadHeapSampler::get_sampling_interval() {
return OrderAccess::load_acquire(&_sampling_interval); return OrderAccess::load_acquire(&_sampling_interval);
} }

View file

@ -30,16 +30,24 @@
class ThreadHeapSampler { class ThreadHeapSampler {
private: private:
// Statics for the fast log
static const int FastLogNumBits = 10;
static const int FastLogMask = (1 << FastLogNumBits) - 1;
size_t _bytes_until_sample; size_t _bytes_until_sample;
// Cheap random number generator // Cheap random number generator
static uint64_t _rnd; static uint64_t _rnd;
static bool _log_table_initialized;
static double _log_table[1<<FastLogNumBits]; // Constant
static volatile int _sampling_interval;
void pick_next_geometric_sample(); void pick_next_geometric_sample();
void pick_next_sample(size_t overflowed_bytes = 0); void pick_next_sample(size_t overflowed_bytes = 0);
static int _enabled;
static int _sampling_interval;
static void init_log_table(); static double fast_log2(const double& d);
static bool init_log_table();
uint64_t next_random(uint64_t rnd);
public: public:
ThreadHeapSampler() : _bytes_until_sample(0) { ThreadHeapSampler() : _bytes_until_sample(0) {
@ -54,10 +62,6 @@ class ThreadHeapSampler {
void check_for_sampling(oop obj, size_t size_in_bytes, size_t bytes_allocated_before); void check_for_sampling(oop obj, size_t size_in_bytes, size_t bytes_allocated_before);
static int enabled();
static void enable();
static void disable();
static void set_sampling_interval(int sampling_interval); static void set_sampling_interval(int sampling_interval);
static int get_sampling_interval(); static int get_sampling_interval();
}; };