!6060 feat: JsRuntime新增suspendvm接口并确保在获取js栈前suspend vm

Merge pull request !6060 from 任堂宇/master
This commit is contained in:
openharmony_ci
2023-07-27 09:00:21 +00:00
committed by Gitee
7 changed files with 46 additions and 6 deletions
@@ -207,18 +207,25 @@ bool MixStackDumper::DumpMixFrame(int fd, pid_t nstid, pid_t tid)
std::vector<DfxFrame> nativeFrames;
bool hasNativeFrame = true;
bool isVmSuspended = false;
auto application = application_.lock();
if (application != nullptr && application->GetRuntime() != nullptr) {
isVmSuspended = application->GetRuntime()->SuspendVM(nstid);
}
if (!catcher_->CatchFrame(nstid, nativeFrames)) {
hasNativeFrame = false;
}
bool hasJsFrame = true;
std::vector<JsFrames> jsFrames;
auto application = application_.lock();
// if we failed to get native frame, target thread may not be seized
if (application != nullptr && application->GetRuntime() != nullptr && hasNativeFrame) {
if (isVmSuspended) {
hasJsFrame = application->GetRuntime()->BuildJsStackInfoList(nstid, jsFrames);
}
catcher_->ReleaseThread(nstid);
if (isVmSuspended) {
application->GetRuntime()->ResumeVM(nstid);
}
if (jsFrames.size() == 0) {
hasJsFrame = false;
+24
View File
@@ -955,6 +955,30 @@ void JsRuntime::NotifyApplicationState(bool isBackground)
HILOG_INFO("NotifyApplicationState, isBackground %{public}d.", isBackground);
}
bool JsRuntime::SuspendVM(uint32_t tid)
{
auto nativeEngine = GetNativeEnginePointer();
CHECK_POINTER_AND_RETURN(nativeEngine, false);
auto arkNativeEngine = nativeEngine->GetWorkerEngine(tid);
if (arkNativeEngine == nullptr) {
HILOG_ERROR("SuspendVM arkNativeEngine is nullptr");
return false;
}
return arkNativeEngine->SuspendVM();
}
void JsRuntime::ResumeVM(uint32_t tid)
{
auto nativeEngine = GetNativeEnginePointer();
CHECK_POINTER(nativeEngine);
auto arkNativeEngine = nativeEngine->GetWorkerEngine(tid);
if (arkNativeEngine == nullptr) {
HILOG_ERROR("ResumeVM arkNativeEngine is nullptr");
return;
}
arkNativeEngine->ResumeVM();
}
void JsRuntime::PreloadSystemModule(const std::string& moduleName)
{
HandleScope handleScope(*this);
@@ -85,6 +85,8 @@ public:
void DumpHeapSnapshot(bool isPrivate) override;
bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) override;
void NotifyApplicationState(bool isBackground) override;
bool SuspendVM(uint32_t tid) override;
void ResumeVM(uint32_t tid) override;
bool RunSandboxScript(const std::string& path, const std::string& hapPath);
bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false);
@@ -79,6 +79,8 @@ public:
virtual bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) = 0;
virtual void DumpHeapSnapshot(bool isPrivate) = 0;
virtual void NotifyApplicationState(bool isBackground) = 0;
virtual bool SuspendVM(uint32_t tid) = 0;
virtual void ResumeVM(uint32_t tid) = 0;
virtual void PreloadSystemModule(const std::string& moduleName) = 0;
virtual void FinishPreload() = 0;
virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0;
@@ -47,6 +47,11 @@ public:
{
return true;
}
bool SuspendVM(uint32_t tid) override
{
return true;
}
void ResumeVM(uint32_t tid) override {}
bool UnLoadRepairPatch(const std::string& patchFile) override
{
return true;
@@ -310,12 +310,12 @@ public:
return true;
}
bool DeleteWorker(NativeEngine* hostEngine, NativeEngine* workerEngine) override
bool DeleteWorker(NativeEngine* workerEngine) override
{
return true;
}
NativeEngine* GetWorkerVm(NativeEngine* hostEngine, uint32_t tid) override
NativeEngine* GetWorkerEngine(uint32_t tid) override
{
return nullptr;
}
@@ -309,12 +309,12 @@ public:
return true;
}
bool DeleteWorker(NativeEngine* hostEngine, NativeEngine* workerEngine) override
bool DeleteWorker(NativeEngine* workerEngine) override
{
return true;
}
NativeEngine* GetWorkerVm(NativeEngine* hostEngine, uint32_t tid) override
NativeEngine* GetWorkerEngine(uint32_t tid) override
{
return nullptr;
}