Initialialize jhp's 'enabled_' field
Otherwise, with jemalloc, which doesn't memset(0), we wrongly enable the
sampler, which makes allocations slower due to smaller TLABs.
Also move IsEnabled() to the header file as it is invoked quite a few
times while allocating TLAB.
Bug: 310655393
Test: manual testing on devices using jemalloc
Change-Id: I63e819488fb980db95080fa17400712bd8efdbe5
diff --git a/runtime/javaheapprof/javaheapsampler.cc b/runtime/javaheapprof/javaheapsampler.cc
index a73ed0b..7467134 100644
--- a/runtime/javaheapprof/javaheapsampler.cc
+++ b/runtime/javaheapprof/javaheapsampler.cc
@@ -131,10 +131,6 @@
<< " next_bytes_until_sample = " << next_bytes_until_sample;
}
-bool HeapSampler::IsEnabled() {
- return enabled_.load(std::memory_order_acquire);
-}
-
int HeapSampler::GetSamplingInterval() {
return p_sampling_interval_.load(std::memory_order_acquire);
}
diff --git a/runtime/javaheapprof/javaheapsampler.h b/runtime/javaheapprof/javaheapsampler.h
index 618893c..4151472 100644
--- a/runtime/javaheapprof/javaheapsampler.h
+++ b/runtime/javaheapprof/javaheapsampler.h
@@ -68,7 +68,7 @@
// of new Tlab after Reset.
void AdjustSampleOffset(size_t adjustment);
// Is heap sampler enabled?
- bool IsEnabled();
+ bool IsEnabled() { return enabled_.load(std::memory_order_acquire); }
// Set the sampling interval.
void SetSamplingInterval(int sampling_interval) REQUIRES(!geo_dist_rng_lock_);
// Return the sampling interval.
@@ -80,7 +80,7 @@
// possibly decreasing sample intervals by sample_adj_bytes.
size_t PickAndAdjustNextSample(size_t sample_adj_bytes = 0) REQUIRES(!geo_dist_rng_lock_);
- std::atomic<bool> enabled_;
+ std::atomic<bool> enabled_{false};
// Default sampling interval is 4kb.
// Writes guarded by geo_dist_rng_lock_.
std::atomic<int> p_sampling_interval_{4 * 1024};