From 2d34e24a41000babae3e41fcbd899da100b09bec Mon Sep 17 00:00:00 2001 From: Ishin Pavel Date: Tue, 23 Aug 2022 17:06:42 +0300 Subject: [PATCH] Fix flaky issue in GetGlobalVarAddress Add GlobalDictionary::GetSafeBox for case then value in dictionary can by not HeapObject Signed-off-by: Ishin Pavel --- runtime/compiler/ecmascript_runtime_interface.cpp | 5 +++-- runtime/global_dictionary-inl.h | 10 ++++++++++ runtime/global_dictionary.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/runtime/compiler/ecmascript_runtime_interface.cpp b/runtime/compiler/ecmascript_runtime_interface.cpp index a732d2c38..7eaeab526 100644 --- a/runtime/compiler/ecmascript_runtime_interface.cpp +++ b/runtime/compiler/ecmascript_runtime_interface.cpp @@ -88,11 +88,12 @@ uintptr_t EcmaRuntimeInterface::GetGlobalVarAddress(MethodPtr method, size_t id) return 0; } - JSTaggedValue res(dict->GetBox(entry)); + JSTaggedValue res(dict->GetSafeBox(entry)); // we can't set an attribute in compiler thread. - if (res.IsUndefined() || !res.IsPropertyBox()) { + if (res.IsUndefined() || res.IsHole() || !res.IsPropertyBox()) { return 0; } + ASSERT(res.IsPropertyBox()); return reinterpret_cast(res.GetHeapObject()); } diff --git a/runtime/global_dictionary-inl.h b/runtime/global_dictionary-inl.h index ce7f9b88a..099fed185 100644 --- a/runtime/global_dictionary-inl.h +++ b/runtime/global_dictionary-inl.h @@ -49,6 +49,16 @@ PropertyBox *GlobalDictionary::GetBox(int entry) const return PropertyBox::Cast(Get(index).GetTaggedObject()); } +PropertyBox *GlobalDictionary::GetSafeBox(int entry) const +{ + int index = GetEntryIndex(entry) + ENTRY_VALUE_INDEX; + auto val = Get(index); + if (!val.IsHeapObject()) { + return nullptr; + } + return PropertyBox::Cast(Get(index).GetTaggedObject()); +} + JSTaggedValue GlobalDictionary::GetValue(int entry) const { return GetBox(entry)->GetValue(); diff --git a/runtime/global_dictionary.h b/runtime/global_dictionary.h index bcdb4a4dc..94615863f 100644 --- a/runtime/global_dictionary.h +++ b/runtime/global_dictionary.h @@ -54,6 +54,8 @@ public: inline PropertyBox *GetBox(int entry) const; + inline PropertyBox *GetSafeBox(int entry) const; + inline JSTaggedValue GetValue(int entry) const; inline PropertyAttributes GetAttributes(int entry) const; -- Gitee