diff --git a/src/hotspot/share/nmt/nmtNativeCallStackStorage.hpp b/src/hotspot/share/nmt/nmtNativeCallStackStorage.hpp index 1b09002028e..258c3284a18 100644 --- a/src/hotspot/share/nmt/nmtNativeCallStackStorage.hpp +++ b/src/hotspot/share/nmt/nmtNativeCallStackStorage.hpp @@ -28,6 +28,7 @@ #include "nmt/arrayWithFreeList.hpp" #include "utilities/growableArray.hpp" #include "utilities/nativeCallStack.hpp" +#include // Virtual memory regions that are tracked by NMT also have their NativeCallStack (NCS) tracked. // NCS:s are: @@ -41,19 +42,19 @@ // We achieve this by using a closed hashtable for finding previously existing NCS:s and referring to them by an index that's smaller than a pointer. class NativeCallStackStorage : public CHeapObjBase { public: - struct StackIndex { - friend NativeCallStackStorage; - int32_t _stack_index; - public: - static constexpr const int32_t invalid = -1; - static bool equals(const StackIndex& a, const StackIndex& b) { - return a._stack_index == b._stack_index; - } + using StackIndex = int; - bool is_invalid() { - return _stack_index == invalid; - } - }; +private: + constexpr static const StackIndex invalid = std::numeric_limits::max() - 1; + +public: + static bool equals(const StackIndex a, const StackIndex b) { + return a == b; + } + + static bool is_invalid(StackIndex a) { + return a == invalid; + } private: struct TableEntry; @@ -83,16 +84,16 @@ public: StackIndex push(const NativeCallStack& stack) { // Not in detailed mode, so not tracking stacks. if (!_is_detailed_mode) { - return StackIndex{StackIndex::invalid}; + return invalid; } return put(stack); } const inline NativeCallStack& get(StackIndex si) { - if (si._stack_index == -1) { + if (is_invalid(si)) { return _fake_stack; } - return _stacks.at(si._stack_index); + return _stacks.at(si); } NativeCallStackStorage(bool is_detailed_mode, int table_size = default_table_size); diff --git a/src/hotspot/share/nmt/vmatree.hpp b/src/hotspot/share/nmt/vmatree.hpp index a93c282f4d2..3316219a1d3 100644 --- a/src/hotspot/share/nmt/vmatree.hpp +++ b/src/hotspot/share/nmt/vmatree.hpp @@ -78,7 +78,7 @@ public: static bool equals(const RegionData& a, const RegionData& b) { return a.flag == b.flag && - NativeCallStackStorage::StackIndex::equals(a.stack_idx, b.stack_idx); + NativeCallStackStorage::equals(a.stack_idx, b.stack_idx); } }; @@ -112,7 +112,7 @@ private: return RegionData{sidx, flag()}; } - const NativeCallStackStorage::StackIndex stack() const { + NativeCallStackStorage::StackIndex stack() const { return sidx; } }; diff --git a/test/hotspot/gtest/nmt/test_nmt_nativecallstackstorage.cpp b/test/hotspot/gtest/nmt/test_nmt_nativecallstackstorage.cpp index 71e924b7b9d..867d32c4a66 100644 --- a/test/hotspot/gtest/nmt/test_nmt_nativecallstackstorage.cpp +++ b/test/hotspot/gtest/nmt/test_nmt_nativecallstackstorage.cpp @@ -35,7 +35,7 @@ TEST_VM_F(NMTNativeCallStackStorageTest, DoNotStoreStackIfNotDetailed) { NativeCallStack ncs{}; NCSS ncss(false); NCSS::StackIndex si = ncss.push(ncs); - EXPECT_TRUE(si.is_invalid()); + EXPECT_TRUE(NCSS::is_invalid(si)); NativeCallStack ncs_received = ncss.get(si); EXPECT_TRUE(ncs_received.is_empty()); } @@ -57,7 +57,7 @@ TEST_VM_F(NMTNativeCallStackStorageTest, CollisionsReceiveDifferentIndexes) { for (int i = 0; i < nr_of_stacks; i++) { for (int j = 0; j < nr_of_stacks; j++) { if (i == j) continue; - EXPECT_FALSE(NCSS::StackIndex::equals(si_arr[i],si_arr[j])); + EXPECT_FALSE(NCSS::equals(si_arr[i],si_arr[j])); } } }