!5803 优化napi_call_function--优化thread::CheckSafePoint中的锁

Merge pull request !5803 from huangzhenghua/master20240106
This commit is contained in:
openharmony_ci 2024-01-08 10:12:28 +00:00 committed by Gitee
commit 36e1860ada
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 67 additions and 10 deletions

View File

@ -217,7 +217,7 @@ bool Jit::IsCompiling(JSHandle<JSFunction> &jsFunction)
return false;
}
void Jit::InstallTasks()
void Jit::InstallTasksWithoutClearFlag()
{
LockHolder holder(installJitTasksDequeMtx_);
for (auto it = installJitTasks_.begin(); it != installJitTasks_.end(); it++) {
@ -228,6 +228,11 @@ void Jit::InstallTasks()
delete task;
}
installJitTasks_.clear();
}
void Jit::InstallTasks()
{
InstallTasksWithoutClearFlag();
// clear flag
vm_->GetJSThread()->SetInstallMachineCode(false);
}

View File

@ -47,6 +47,7 @@ public:
void RequestInstallCode(JitTask *jitTask);
void InstallTasks();
void InstallTasksWithoutClearFlag();
bool IsCompiling(JSHandle<JSFunction> &jsFunction);
void AddCompilingTask(JitTask *jitTask);
void RemoveCompilingTask(JitTask *jitTask);

View File

@ -534,18 +534,27 @@ void JSThread::TerminateExecution()
bool JSThread::CheckSafepoint()
{
ResetCheckSafePointStatus();
if (HasTerminationRequest()) {
interruptMutex_.Lock();
ResetCheckSafePointStatusWithoutLock();
if (HasTerminationRequestWithoutLock()) {
TerminateExecution();
SetVMTerminated(true);
SetTerminationRequest(false);
}
if (vmThreadControl_->VMNeedSuspension()) {
vmThreadControl_->SuspendVM();
SetVMTerminatedWithoutLock(true);
SetTerminationRequestWithoutLock(false);
}
if (vm_->IsEnableJit() && HasInstallMachineCode()) {
vm_->GetJit()->InstallTasks();
if (vm_->IsEnableJit() && HasInstallMachineCodeWithoutLock()) {
vm_->GetJit()->InstallTasksWithoutClearFlag();
// jit 's thread_ is current JSThread's this.
SetInstallMachineCodeWithoutLock(false);
}
// vmThreadControl_ 's thread_ is current JSThread's this.
if (VMNeedSuspensionWithoutLock()) {
interruptMutex_.Unlock();
vmThreadControl_->SuspendVM();
} else {
interruptMutex_.Unlock();
}
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)

View File

@ -482,6 +482,12 @@ public:
void ResetCheckSafePointStatus()
{
LockHolder lock(interruptMutex_);
ResetCheckSafePointStatusWithoutLock();
}
inline void ResetCheckSafePointStatusWithoutLock()
{
// The interruptMutex_ should be locked before calling this function.
ASSERT(static_cast<uint8_t>(glueData_.interruptVector_ & 0xFF) <= 1);
CheckSafePointBit::Set(false, &glueData_.interruptVector_);
}
@ -495,6 +501,12 @@ public:
bool VMNeedSuspension()
{
LockHolder lock(interruptMutex_);
return VMNeedSuspensionWithoutLock();
}
inline bool VMNeedSuspensionWithoutLock()
{
// The interruptMutex_ should be locked before calling this function.
return VMNeedSuspensionBit::Decode(glueData_.interruptVector_);
}
@ -513,18 +525,36 @@ public:
bool HasTerminationRequest() const
{
LockHolder lock(interruptMutex_);
return HasTerminationRequestWithoutLock();
}
inline bool HasTerminationRequestWithoutLock() const
{
// The interruptMutex_ should be locked before calling this function.
return VMNeedTerminationBit::Decode(glueData_.interruptVector_);
}
void SetTerminationRequest(bool flag)
{
LockHolder lock(interruptMutex_);
SetTerminationRequestWithoutLock(flag);
}
inline void SetTerminationRequestWithoutLock(bool flag)
{
// The interruptMutex_ should be locked before calling this function.
VMNeedTerminationBit::Set(flag, &glueData_.interruptVector_);
}
void SetVMTerminated(bool flag)
{
LockHolder lock(interruptMutex_);
SetVMTerminatedWithoutLock(flag);
}
inline void SetVMTerminatedWithoutLock(bool flag)
{
// The interruptMutex_ should be locked before calling this function.
VMHasTerminatedBit::Set(flag, &glueData_.interruptVector_);
}
@ -539,12 +569,24 @@ public:
void SetInstallMachineCode(bool flag)
{
LockHolder lock(interruptMutex_);
SetInstallMachineCodeWithoutLock(flag);
}
inline void SetInstallMachineCodeWithoutLock(bool flag)
{
// The interruptMutex_ should be locked before calling this function.
InstallMachineCodeBit::Set(flag, &glueData_.interruptVector_);
}
bool HasInstallMachineCode() const
{
LockHolder lock(interruptMutex_);
return HasInstallMachineCodeWithoutLock();
}
inline bool HasInstallMachineCodeWithoutLock() const
{
// The interruptMutex_ should be locked before calling this function.
return InstallMachineCodeBit::Decode(glueData_.interruptVector_);
}