Commit 6af91b35 by Abseil Team Committed by Derek Mauro

Export of internal Abseil changes

--
0e6d5abe305df4e943e0bc0256c67afc00956691 by Abseil Team <absl-team@google.com>:

Ensure that Hashtablez does not pull in absl::Mutex dependency when turned off at compile time.

PiperOrigin-RevId: 331142625
GitOrigin-RevId: 0e6d5abe305df4e943e0bc0256c67afc00956691
Change-Id: I984d6d3436e4825a7b20758c45b3142c0f3bb45a
parent f2c9c663
...@@ -139,6 +139,11 @@ inline void RecordEraseSlow(HashtablezInfo* info) { ...@@ -139,6 +139,11 @@ inline void RecordEraseSlow(HashtablezInfo* info) {
HashtablezInfo* SampleSlow(int64_t* next_sample); HashtablezInfo* SampleSlow(int64_t* next_sample);
void UnsampleSlow(HashtablezInfo* info); void UnsampleSlow(HashtablezInfo* info);
#if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
#error ABSL_INTERNAL_HASHTABLEZ_SAMPLE cannot be directly set
#endif // defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
#if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
class HashtablezInfoHandle { class HashtablezInfoHandle {
public: public:
explicit HashtablezInfoHandle() : info_(nullptr) {} explicit HashtablezInfoHandle() : info_(nullptr) {}
...@@ -190,9 +195,22 @@ class HashtablezInfoHandle { ...@@ -190,9 +195,22 @@ class HashtablezInfoHandle {
friend class HashtablezInfoHandlePeer; friend class HashtablezInfoHandlePeer;
HashtablezInfo* info_; HashtablezInfo* info_;
}; };
#else
// Ensure that when Hashtablez is turned off at compile time, HashtablezInfo can
// be removed by the linker, in order to reduce the binary size.
class HashtablezInfoHandle {
public:
explicit HashtablezInfoHandle() = default;
explicit HashtablezInfoHandle(std::nullptr_t) {}
#if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE) inline void RecordStorageChanged(size_t /*size*/, size_t /*capacity*/) {}
#error ABSL_INTERNAL_HASHTABLEZ_SAMPLE cannot be directly set inline void RecordRehash(size_t /*total_probe_length*/) {}
inline void RecordInsert(size_t /*hash*/, size_t /*distance_from_desired*/) {}
inline void RecordErase() {}
friend inline void swap(HashtablezInfoHandle& /*lhs*/,
HashtablezInfoHandle& /*rhs*/) {}
};
#endif // defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE) #endif // defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
#if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE) #if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
......
...@@ -38,6 +38,7 @@ constexpr int kProbeLength = 8; ...@@ -38,6 +38,7 @@ constexpr int kProbeLength = 8;
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
namespace container_internal { namespace container_internal {
#if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
class HashtablezInfoHandlePeer { class HashtablezInfoHandlePeer {
public: public:
static bool IsSampled(const HashtablezInfoHandle& h) { static bool IsSampled(const HashtablezInfoHandle& h) {
...@@ -46,6 +47,13 @@ class HashtablezInfoHandlePeer { ...@@ -46,6 +47,13 @@ class HashtablezInfoHandlePeer {
static HashtablezInfo* GetInfo(HashtablezInfoHandle* h) { return h->info_; } static HashtablezInfo* GetInfo(HashtablezInfoHandle* h) { return h->info_; }
}; };
#else
class HashtablezInfoHandlePeer {
public:
static bool IsSampled(const HashtablezInfoHandle&) { return false; }
static HashtablezInfo* GetInfo(HashtablezInfoHandle*) { return nullptr; }
};
#endif // defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
namespace { namespace {
using ::absl::synchronization_internal::ThreadPool; using ::absl::synchronization_internal::ThreadPool;
...@@ -172,7 +180,7 @@ TEST(HashtablezInfoTest, RecordRehash) { ...@@ -172,7 +180,7 @@ TEST(HashtablezInfoTest, RecordRehash) {
EXPECT_EQ(info.num_rehashes.load(), 1); EXPECT_EQ(info.num_rehashes.load(), 1);
} }
#if defined(ABSL_HASHTABLEZ_SAMPLE) #if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
TEST(HashtablezSamplerTest, SmallSampleParameter) { TEST(HashtablezSamplerTest, SmallSampleParameter) {
SetHashtablezEnabled(true); SetHashtablezEnabled(true);
SetHashtablezSampleParameter(100); SetHashtablezSampleParameter(100);
...@@ -216,7 +224,6 @@ TEST(HashtablezSamplerTest, Sample) { ...@@ -216,7 +224,6 @@ TEST(HashtablezSamplerTest, Sample) {
} }
EXPECT_NEAR(sample_rate, 0.01, 0.005); EXPECT_NEAR(sample_rate, 0.01, 0.005);
} }
#endif
TEST(HashtablezSamplerTest, Handle) { TEST(HashtablezSamplerTest, Handle) {
auto& sampler = HashtablezSampler::Global(); auto& sampler = HashtablezSampler::Global();
...@@ -246,6 +253,8 @@ TEST(HashtablezSamplerTest, Handle) { ...@@ -246,6 +253,8 @@ TEST(HashtablezSamplerTest, Handle) {
}); });
EXPECT_FALSE(found); EXPECT_FALSE(found);
} }
#endif
TEST(HashtablezSamplerTest, Registration) { TEST(HashtablezSamplerTest, Registration) {
HashtablezSampler sampler; HashtablezSampler sampler;
......
...@@ -1796,7 +1796,7 @@ TEST(TableDeathTest, EraseOfEndAsserts) { ...@@ -1796,7 +1796,7 @@ TEST(TableDeathTest, EraseOfEndAsserts) {
EXPECT_DEATH_IF_SUPPORTED(t.erase(t.end()), kDeathMsg); EXPECT_DEATH_IF_SUPPORTED(t.erase(t.end()), kDeathMsg);
} }
#if defined(ABSL_HASHTABLEZ_SAMPLE) #if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
TEST(RawHashSamplerTest, Sample) { TEST(RawHashSamplerTest, Sample) {
// Enable the feature even if the prod default is off. // Enable the feature even if the prod default is off.
SetHashtablezEnabled(true); SetHashtablezEnabled(true);
...@@ -1817,7 +1817,7 @@ TEST(RawHashSamplerTest, Sample) { ...@@ -1817,7 +1817,7 @@ TEST(RawHashSamplerTest, Sample) {
EXPECT_NEAR((end_size - start_size) / static_cast<double>(tables.size()), EXPECT_NEAR((end_size - start_size) / static_cast<double>(tables.size()),
0.01, 0.005); 0.01, 0.005);
} }
#endif // ABSL_HASHTABLEZ_SAMPLER #endif // ABSL_INTERNAL_HASHTABLEZ_SAMPLE
TEST(RawHashSamplerTest, DoNotSampleCustomAllocators) { TEST(RawHashSamplerTest, DoNotSampleCustomAllocators) {
// Enable the feature even if the prod default is off. // Enable the feature even if the prod default is off.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment