From 7aa5a22e0e81c35af2677c52d31a1f2d2bc05a0e Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Thu, 12 Jan 2023 19:41:07 +0300 Subject: [PATCH] Fix some CSA issues Change-Id: I51562bad49a6dbd58c70526a13f412624a1878bb Signed-off-by: Artem Udovichenko --- runtime/ecma_entrypoints.cpp | 4 ++-- runtime/interpreter/ecma-interpreter-inl.h | 3 +++ runtime/interpreter/fast_runtime_stub-inl.h | 13 ++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/runtime/ecma_entrypoints.cpp b/runtime/ecma_entrypoints.cpp index 580499087..73245ee68 100644 --- a/runtime/ecma_entrypoints.cpp +++ b/runtime/ecma_entrypoints.cpp @@ -26,12 +26,12 @@ extern "C" uintptr_t JSGetGlobalVarAddress(uint32_t id) auto thread = JSThread::GetCurrent(); JSTaggedValue key = GetConstantPool(thread)->GetObjectFromCache(id); auto global_obj = thread->GetGlobalObject(); + [[maybe_unused]] EcmaHandleScope scope(thread); + JSHandle global_handle(thread, global_obj); ObjectOperator op(thread, global_obj, key); auto res = op.GetValue(); if (res.IsUndefined() || !res.IsPropertyBox()) { PropertyAttributes attributes = PropertyAttributes::Default(true, true, false); - [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle global_handle(thread, global_obj); // Reread key because GC can move it in ctor of ObjectOperator JSHandle key_handle(thread, GetConstantPool(thread)->GetObjectFromCache(id)); op.AddProperty(global_handle, key_handle, attributes); diff --git a/runtime/interpreter/ecma-interpreter-inl.h b/runtime/interpreter/ecma-interpreter-inl.h index 915c68f6f..2f1a48c65 100644 --- a/runtime/interpreter/ecma-interpreter-inl.h +++ b/runtime/interpreter/ecma-interpreter-inl.h @@ -372,6 +372,9 @@ public: return; } + // CSA reports js_function usage after GC triggered in ThrowStackOverflowException. + // In this case control doesn't reach this point. + // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) ConstantPool *constant_pool = ConstantPool::Cast(js_function->GetConstantPool().GetHeapObject()); JSTaggedValue lexical_env = js_function->GetLexicalEnv(); diff --git a/runtime/interpreter/fast_runtime_stub-inl.h b/runtime/interpreter/fast_runtime_stub-inl.h index 8d3f59f1b..a5fa6d121 100644 --- a/runtime/interpreter/fast_runtime_stub-inl.h +++ b/runtime/interpreter/fast_runtime_stub-inl.h @@ -669,14 +669,17 @@ JSTaggedValue FastRuntimeStub::FastGetPropertyByName(JSThread *thread, JSHandle< { INTERPRETER_TRACE(thread, FastGetPropertyByName); ASSERT(key->IsStringOrSymbol()); - JSTaggedValue raw_key = key.GetTaggedValue(); - if (raw_key.IsString() && !EcmaString::Cast(raw_key.GetTaggedObject())->IsInternString()) { - raw_key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key)); + JSTaggedType raw_key = key->GetRawData(); + if (key->IsString() && !EcmaString::Cast(key->GetTaggedObject())->IsInternString()) { + raw_key = ToUintPtr(thread->GetEcmaVM()->GetFactory()->InternString(key)); } - JSTaggedValue result = FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), raw_key); + [[maybe_unused]] size_t gc = thread->GetEcmaVM()->GetGC()->GetCounter(); + JSTaggedValue result = + FastRuntimeStub::GetPropertyByName(thread, receiver.GetTaggedValue(), JSTaggedValue(raw_key)); if (result.IsHole()) { + ASSERT_PRINT(gc == thread->GetEcmaVM()->GetGC()->GetCounter(), "GC happend where it is not supposed"); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - return JSTaggedValue::GetProperty(thread, receiver, JSHandle(thread, raw_key)) + return JSTaggedValue::GetProperty(thread, receiver, JSHandle(thread, JSTaggedValue(raw_key))) .GetValue() .GetTaggedValue(); } -- Gitee