From f4e631e9c7819304950ff5cba957ab8aa6f5e1fb Mon Sep 17 00:00:00 2001 From: zbx Date: Wed, 9 Jul 2025 15:20:27 +0800 Subject: [PATCH] Remove Some CheckSafepoint in LoopEnd Signed-off-by: zbx Change-Id: Ic756abf87a48ee6876499beea2164eef10bb52ab --- ecmascript/compiler/interpreter_stub.cpp | 12 +++---- ecmascript/compiler/stub_builder.cpp | 40 +++++++++++++++++++----- ecmascript/compiler/stub_builder.h | 1 + 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index 80e7ee62e6..90910662f2 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -1077,7 +1077,7 @@ DECLARE_ASM_HANDLER(HandleLdlexvarImm4Imm4) i = Int32Add(*i, Int32(1)); BRANCH(Int32LessThan(*i, level), &loopEnd, &afterLoop); Bind(&loopEnd); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + LoopEnd(&loopHead); Bind(&afterLoop); GateRef variable = GetPropertiesFromLexicalEnv(glue, *currentEnv, slot); varAcc = variable; @@ -1106,7 +1106,7 @@ DECLARE_ASM_HANDLER(HandleLdlexvarImm8Imm8) i = Int32Add(*i, Int32(1)); BRANCH(Int32LessThan(*i, level), &loopEnd, &afterLoop); Bind(&loopEnd); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + LoopEnd(&loopHead); Bind(&afterLoop); GateRef variable = GetPropertiesFromLexicalEnv(glue, *currentEnv, slot); varAcc = variable; @@ -1134,7 +1134,7 @@ DECLARE_ASM_HANDLER(HandleWideLdlexvarPrefImm16Imm16) i = Int32Add(*i, Int32(1)); BRANCH(Int32LessThan(*i, level), &loopEnd, &afterLoop); Bind(&loopEnd); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + LoopEnd(&loopHead); Bind(&afterLoop); GateRef variable = GetPropertiesFromLexicalEnv(glue, *currentEnv, slot); varAcc = variable; @@ -1161,7 +1161,7 @@ DECLARE_ASM_HANDLER(HandleStlexvarImm4Imm4) i = Int32Add(*i, Int32(1)); BRANCH(Int32LessThan(*i, level), &loopEnd, &afterLoop); Bind(&loopEnd); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + LoopEnd(&loopHead); Bind(&afterLoop); SetPropertiesToLexicalEnv(glue, *currentEnv, slot, value); DISPATCH(STLEXVAR_IMM4_IMM4); @@ -1187,7 +1187,7 @@ DECLARE_ASM_HANDLER(HandleStlexvarImm8Imm8) i = Int32Add(*i, Int32(1)); BRANCH(Int32LessThan(*i, level), &loopEnd, &afterLoop); Bind(&loopEnd); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + LoopEnd(&loopHead); Bind(&afterLoop); SetPropertiesToLexicalEnv(glue, *currentEnv, slot, value); DISPATCH(STLEXVAR_IMM8_IMM8); @@ -1213,7 +1213,7 @@ DECLARE_ASM_HANDLER(HandleWideStlexvarPrefImm16Imm16) i = Int32Add(*i, Int32(1)); BRANCH(Int32LessThan(*i, level), &loopEnd, &afterLoop); Bind(&loopEnd); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + LoopEnd(&loopHead); Bind(&afterLoop); SetPropertiesToLexicalEnv(glue, *currentEnv, slot, value); DISPATCH(WIDE_STLEXVAR_PREF_IMM16_IMM16); diff --git a/ecmascript/compiler/stub_builder.cpp b/ecmascript/compiler/stub_builder.cpp index 2f92b62539..cfc589652c 100644 --- a/ecmascript/compiler/stub_builder.cpp +++ b/ecmascript/compiler/stub_builder.cpp @@ -127,13 +127,13 @@ GateRef StubBuilder::CheckSuspendForCMCGC(GateRef glue) return safepointActive; } -void StubBuilder::LoopEndWithCheckSafePoint(Label *loopHead, Environment *env, GateRef glue) +void StubBuilder::CheckSafePointIfSuspended(Environment *env, GateRef glue) { Label loopEnd(env); Label needSuspend(env); Label checkSuspendForCMCGC(env); Label checkSuspend(env); - BRANCH_UNLIKELY(LoadPrimitive( + BRANCH(LoadPrimitive( VariableType::BOOL(), glue, IntPtr(JSThread::GlueData::GetIsEnableCMCGCOffset(env->Is32Bit()))), &checkSuspendForCMCGC, &checkSuspend); Bind(&checkSuspend); @@ -146,6 +146,11 @@ void StubBuilder::LoopEndWithCheckSafePoint(Label *loopHead, Environment *env, G Jump(&loopEnd); } Bind(&loopEnd); +} + +void StubBuilder::LoopEndWithCheckSafePoint(Label *loopHead, Environment *env, GateRef glue) +{ + CheckSafePointIfSuspended(env, glue); LoopEnd(loopHead); } @@ -2709,9 +2714,12 @@ GateRef StubBuilder::LoadICWithHandler( Label cellNotUndefined(env); Label loopHead(env); Label loopEnd(env); + Label checkSuspend(env); + Label finishCheckSuspend(env); DEFVARIABLE(result, VariableType::JS_ANY(), Undefined()); DEFVARIABLE(holder, VariableType::JS_ANY(), argHolder); DEFVARIABLE(handler, VariableType::JS_ANY(), argHandler); + DEFVARIABLE(shouldCheckSuspend, VariableType::BOOL(), False()); Jump(&loopHead); LoopBegin(&loopHead); @@ -2792,8 +2800,8 @@ GateRef StubBuilder::LoadICWithHandler( BRANCH(Equal(*holder, Undefined()), &handleInfoIsNotFound, &handleInfoIsFound); Bind(&handleInfoIsFound); { - handler = GetPrototypeHandlerHandlerInfo(glue, *handler); - LoopEndWithCheckSafePoint(&loopHead, env, glue); + handler = GetPrototypeHandlerHandlerInfo(glue, *handler); + LoopEnd(&loopHead); } // For "Not Found" case (holder equals Undefined()), @@ -2816,10 +2824,17 @@ GateRef StubBuilder::LoadICWithHandler( } Bind(&handlerNotPrototypeHandler); { - result = LoadGlobal(glue, *handler); - Jump(&exit); + result = LoadGlobal(glue, *handler); + Jump(&exit); } Bind(&exit); + BRANCH(*shouldCheckSuspend, &checkSuspend, &finishCheckSuspend); + Bind(&checkSuspend); + { + CheckSafePointIfSuspended(env, glue); + Jump(&finishCheckSuspend); + } + Bind(&finishCheckSuspend); auto ret = *result; env->SubCfgExit(); return ret; @@ -3202,10 +3217,13 @@ GateRef StubBuilder::StoreICWithHandler(GateRef glue, GateRef receiver, GateRef Label loopEnd(env); Label JumpLoopHead(env); Label cellNotNull(env); + Label checkSuspend(env); + Label finishCheckSuspend(env); DEFVARIABLE(result, VariableType::JS_ANY(), Undefined()); DEFVARIABLE(holder, VariableType::JS_ANY(), argHolder); DEFVARIABLE(handler, VariableType::JS_ANY(), argHandler); DEFVARIABLE(actualValue, VariableType::JS_ANY(), value); + DEFVARIABLE(shouldCheckSuspend, VariableType::BOOL(), False()); Jump(&loopHead); LoopBegin(&loopHead); { @@ -3331,10 +3349,18 @@ GateRef StubBuilder::StoreICWithHandler(GateRef glue, GateRef receiver, GateRef } Bind(&JumpLoopHead); { - LoopEndWithCheckSafePoint(&loopHead, env, glue); + shouldCheckSuspend = True(); + LoopEnd(&loopHead); } } Bind(&exit); + BRANCH(*shouldCheckSuspend, &checkSuspend, &finishCheckSuspend); + Bind(&checkSuspend); + { + CheckSafePointIfSuspended(env, glue); + Jump(&finishCheckSuspend); + } + Bind(&finishCheckSuspend); auto ret = *result; env->SubCfgExit(); return ret; diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index 07003e6903..0414daf2d0 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -180,6 +180,7 @@ public: void LoopBegin(Label *loopHead); void LoopEnd(Label *loopHead); void LoopEndWithCheckSafePoint(Label *loopHead, Environment *env, GateRef glue); + void CheckSafePointIfSuspended(Environment *env, GateRef glue); GateRef CheckSuspend(GateRef glue); GateRef CheckSuspendForCMCGC(GateRef glue); // call operation -- Gitee