fixup! fixup! [K/N][New MM] Disallow getting thread data for detached threads

This commit is contained in:
Ilya Matveev
2021-09-15 20:15:00 +07:00
committed by Space
parent 474b2fc90e
commit 35ff131608
3 changed files with 7 additions and 3 deletions
@@ -3739,7 +3739,6 @@ ALWAYS_INLINE void kotlin::AssertThreadState(MemoryState* thread, std::initializ
}
MemoryState* kotlin::mm::GetMemoryState() noexcept {
RuntimeAssert(memoryState != nullptr, "Thread is not attached to the runtime");
return ::memoryState;
}
+2 -1
View File
@@ -389,7 +389,8 @@ namespace kotlin {
namespace mm {
// Returns the MemoryState for the current thread.
// The current thread must be attached to the runtime.
// For the new MM, the current thread must be attached to the runtime.
// For the legacy MM, returns nullptr if called on a thread that is not attached to the runtime.
// Try not to use it very often, as (1) thread local access can be slow on some platforms,
// (2) TLS gets deallocated before our thread destruction hooks run.
MemoryState* GetMemoryState() noexcept;
@@ -12,7 +12,11 @@
using namespace kotlin;
TEST(MemoryStateTestDeathTest, GetMemoryStateForUnregisteredThread) {
EXPECT_DEATH(mm::GetMemoryState(), "Thread is not attached to the runtime");
if (CurrentMemoryModel == MemoryModel::kExperimental) {
EXPECT_DEATH(mm::GetMemoryState(), "Thread is not attached to the runtime");
} else {
EXPECT_EQ(mm::GetMemoryState(), nullptr);
}
}
TEST(MemoryStateTest, GetMemoryStateForRegisteredThread) {