8335062: NMT: Make StackIndex non-opaque
Reviewed-by: stuefe, gziemski
This commit is contained in:
parent
8c8b5801fd
commit
e57b593258
@ -28,6 +28,7 @@
|
||||
#include "nmt/arrayWithFreeList.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
#include "utilities/nativeCallStack.hpp"
|
||||
#include <limits>
|
||||
|
||||
// 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<StackIndex>::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);
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user