diff --git a/include/cppgc/internal/persistent-node.h b/include/cppgc/internal/persistent-node.h index c42ebe35c1..68a8096cb6 100644 --- a/include/cppgc/internal/persistent-node.h +++ b/include/cppgc/internal/persistent-node.h @@ -141,18 +141,18 @@ class V8_EXPORT PersistentRegion final : public PersistentRegionBase { PersistentRegion& operator=(const PersistentRegion&) = delete; V8_INLINE PersistentNode* AllocateNode(void* owner, TraceCallback trace) { - CPPGC_CHECK(IsCreationThread()); + CPPGC_DCHECK(IsCreationThread()); return PersistentRegionBase::AllocateNode(owner, trace); } V8_INLINE void FreeNode(PersistentNode* node) { - CPPGC_CHECK(IsCreationThread()); + CPPGC_DCHECK(IsCreationThread()); PersistentRegionBase::FreeNode(node); } + private: bool IsCreationThread(); - private: int creation_thread_id_; }; diff --git a/include/cppgc/persistent.h b/include/cppgc/persistent.h index 08440cdc98..bd0d3a6652 100644 --- a/include/cppgc/persistent.h +++ b/include/cppgc/persistent.h @@ -190,13 +190,7 @@ class BasicPersistent final : public PersistentBase, // based on their actual types. V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const { // TODO(chromium:1253650): Temporary CHECK to diagnose issues. - if (IsValid()) { - CPPGC_CHECK( - WeaknessPolicy::GetPersistentRegion(GetValue()).IsCreationThread()); - CPPGC_CHECK(GetNode() != nullptr); - } else { - CPPGC_CHECK(GetNode() == nullptr); - } + CPPGC_CHECK(IsValid() == !!GetNode()); // The const_cast below removes the constness from PersistentBase storage. // The following static_cast re-adds any constness if specified through the @@ -206,13 +200,7 @@ class BasicPersistent final : public PersistentBase, void Clear() { // TODO(chromium:1253650): Temporary CHECK to diagnose issues. - if (IsValid()) { - CPPGC_CHECK( - WeaknessPolicy::GetPersistentRegion(GetValue()).IsCreationThread()); - CPPGC_CHECK(GetNode() != nullptr); - } else { - CPPGC_CHECK(GetNode() == nullptr); - } + CPPGC_CHECK(IsValid() == !!GetNode()); // Simplified version of `Assign()` to allow calling without a complete type // `T`. if (IsValid()) { diff --git a/src/heap/cppgc/persistent-node.cc b/src/heap/cppgc/persistent-node.cc index 377bd316a6..ac6ffb624a 100644 --- a/src/heap/cppgc/persistent-node.cc +++ b/src/heap/cppgc/persistent-node.cc @@ -103,28 +103,14 @@ void PersistentRegionBase::Trace(Visitor* visitor) { nodes_.end()); } -namespace { - -thread_local int thread_id = 0; -std::atomic next_thread_id{1}; - -int GetCurrentThreadId() { - if (thread_id == 0) { - thread_id = next_thread_id.fetch_add(1); - } - return thread_id; -} - -} // namespace - PersistentRegion::PersistentRegion(const FatalOutOfMemoryHandler& oom_handler) : PersistentRegionBase(oom_handler), - creation_thread_id_(GetCurrentThreadId()) { + creation_thread_id_(v8::base::OS::GetCurrentThreadId()) { USE(creation_thread_id_); } bool PersistentRegion::IsCreationThread() { - return creation_thread_id_ == GetCurrentThreadId(); + return creation_thread_id_ == v8::base::OS::GetCurrentThreadId(); } PersistentRegionLock::PersistentRegionLock() {