From 2551ff94dc00bb3366bdea94138a5a3bfa4ed528 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Fri, 10 Feb 2023 16:24:04 +0300 Subject: [PATCH] Adapt to GC possibility in Method::InvokeContext Method::InvokeContext can now trigger GC (via Verify), so better not pass TaggedValues by value. Also, JSThread::invocation_lexical_env_ should be a root. Signed-off-by: Georgy Bronnikov --- runtime/interpreter/ecma-interpreter-inl.h | 22 ++++++++++------------ runtime/interpreter/interpreter-inl.h | 2 +- runtime/js_thread.cpp | 1 + runtime/js_thread.h | 3 ++- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/runtime/interpreter/ecma-interpreter-inl.h b/runtime/interpreter/ecma-interpreter-inl.h index 5e97cf044..0d3848fef 100644 --- a/runtime/interpreter/ecma-interpreter-inl.h +++ b/runtime/interpreter/ecma-interpreter-inl.h @@ -359,7 +359,9 @@ public: } } else { // Interpreter + [[maybe_unused]] EcmaHandleScope scope(js_thread); UPDATE_CALL_PROFILE(this_func); + JSHandle function_handle(js_thread, js_function); method->DecrementHotnessCounter(0, nullptr, false, JSTaggedValue(function)); @@ -372,15 +374,12 @@ 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(); + ConstantPool *constant_pool = ConstantPool::Cast(function_handle->GetConstantPool().GetHeapObject()); + JSTaggedValue lexical_env = function_handle->GetLexicalEnv(); // Init EcmascriptEnvironment EcmascriptEnvironment *new_env = JSFrame::GetJSEnv(this->GetFrame()); - new (new_env) EcmascriptEnvironment(prev_env, constant_pool, lexical_env.GetHeapObject(), this_func); + new (new_env) EcmascriptEnvironment(prev_env, constant_pool, lexical_env.GetHeapObject(), *function_handle); // Update EcmascriptEnvironment js_thread->SetEcmascriptEnv(new_env); @@ -478,14 +477,13 @@ public: .SetValue(this_obj.GetRawData()); // Init EcmascriptEnvironment - // CSA report ctor_func usage after GC in ThrowStackOverflowException. - // In this case control shouldn't reach this line. - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - ConstantPool *constant_pool = ConstantPool::Cast(ctor_func->GetConstantPool().GetHeapObject()); - JSTaggedValue lexical_env = ctor_func->GetLexicalEnv(); + auto ctor_func_handle = JSHandle(ctor_handle); + ConstantPool *constant_pool = + ConstantPool::Cast(ctor_func_handle->GetConstantPool().GetHeapObject()); + JSTaggedValue lexical_env = ctor_func_handle->GetLexicalEnv(); EcmascriptEnvironment *new_env = JSFrame::GetJSEnv(this->GetFrame()); new (new_env) - EcmascriptEnvironment(prev_env, constant_pool, lexical_env.GetHeapObject(), ctor_func); + EcmascriptEnvironment(prev_env, constant_pool, lexical_env.GetHeapObject(), *ctor_func_handle); // Update EcmascriptEnvironment thread->SetEcmascriptEnv(new_env); diff --git a/runtime/interpreter/interpreter-inl.h b/runtime/interpreter/interpreter-inl.h index 4f988086b..a89db3460 100644 --- a/runtime/interpreter/interpreter-inl.h +++ b/runtime/interpreter/interpreter-inl.h @@ -206,7 +206,7 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) method->GetInstructions() + static_cast(pc_offset.GetInt()) + BytecodeInstruction::Size(format); - TaggedValue acc(context->GetAcc().GetRawData()); + auto *acc = reinterpret_cast(ToUintPtr(*context) + context->GetAccOffset()); uint32_t nregs = context->GetNRegs().GetInt(); TaggedArray *regs_array = TaggedArray::Cast(context->GetRegsArray().GetHeapObject()); auto *regs = reinterpret_cast(regs_array->GetData()); diff --git a/runtime/js_thread.cpp b/runtime/js_thread.cpp index d0d8454a6..0b9eeaf6c 100644 --- a/runtime/js_thread.cpp +++ b/runtime/js_thread.cpp @@ -102,6 +102,7 @@ void JSThread::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) }); } IterateEcmascriptEnvironment(v0, v1); + v0(Root::ROOT_VM, ObjectSlot(ToUintPtr(&invocation_lexical_env_))); // visit internal call params; internal_call_params_->Iterate(v1); diff --git a/runtime/js_thread.h b/runtime/js_thread.h index 62bf9bfb0..9606618f3 100644 --- a/runtime/js_thread.h +++ b/runtime/js_thread.h @@ -173,7 +173,8 @@ public: JSTaggedValue GetInvocationLexicalEnv() const { - return invocation_lexical_env_; + // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) + return invocation_lexical_env_; // GC root } void SetInvocationLexicalEnv(JSTaggedValue invocation_lexical_env) -- Gitee