!8972 Optimize cold patch performance

Merge pull request !8972 from hanweiqi/fix_cold_reload
This commit is contained in:
openharmony_ci 2024-08-30 17:17:35 +00:00 committed by Gitee
commit c2b8c48fd7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 10 additions and 46 deletions

View File

@ -307,7 +307,6 @@ JSHandle<JSFunction> LiteralDataExtractor::DefineMethodInLiteral(JSThread *threa
}
jsFunc->SetModule(thread, module.GetTaggedValue());
QuickFixHelper::SetPatchModule(thread, method, jsFunc);
jsFunc->SetLength(length);
return jsFunc;
}

View File

@ -105,22 +105,6 @@ void PatchLoader::ExecuteFuncOrPatchMain(
if (loadPatch) {
context->SetStageOfHotReload(StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN);
if (context->GetStageOfColdReload() == StageOfColdReload::IS_COLD_RELOAD) {
context->SetStageOfColdReload(StageOfColdReload::COLD_RELOADING);
// change bc stub entry when using assembly interpreter
if (thread->IsAsmInterpreter()) {
auto handleDefinefuncImm8Id16Imm8ColdReload = thread->GetBCStubEntry(
kungfu::BytecodeStubCSigns::HandleDefinefuncImm8Id16Imm8ColdReload);
auto handleDefinefuncImm16Id16Imm8ColdReload = thread->GetBCStubEntry(
kungfu::BytecodeStubCSigns::HandleDefinefuncImm16Id16Imm8ColdReload);
thread->SetBCStubEntry(
kungfu::BytecodeStubCSigns::ID_HandleDefinefuncImm8Id16Imm8,
handleDefinefuncImm8Id16Imm8ColdReload);
thread->SetBCStubEntry(
kungfu::BytecodeStubCSigns::ID_HandleDefinefuncImm16Id16Imm8,
handleDefinefuncImm16Id16Imm8ColdReload);
}
}
} else {
context->SetStageOfHotReload(StageOfHotReload::UNLOAD_END_EXECUTE_PATCHMAIN);
}

View File

@ -93,8 +93,7 @@ enum class StageOfHotReload : int32_t {
enum class StageOfColdReload : int32_t {
NOT_COLD_RELOAD,
IS_COLD_RELOAD,
COLD_RELOADING
IS_COLD_RELOAD
};
class PatchLoader {

View File

@ -22,19 +22,6 @@
namespace panda::ecmascript {
class QuickFixHelper {
public:
static inline void SetPatchModule(JSThread *thread, const JSHandle<Method> &methodHandle,
const JSHandle<JSFunction> &func)
{
if (thread->GetCurrentEcmaContext()->GetStageOfColdReload() == StageOfColdReload::COLD_RELOADING) {
auto coldReloadRecordName =
MethodLiteral::GetRecordName(methodHandle->GetJSPandaFile(), methodHandle->GetMethodId());
const JSHandle<JSTaggedValue> resolvedModule =
thread->GetCurrentEcmaContext()->FindPatchModule(coldReloadRecordName);
if (!resolvedModule->IsHole()) {
func->SetModule(thread, resolvedModule.GetTaggedValue());
}
}
}
static JSTaggedValue CreateMainFuncWithPatch(EcmaVM *vm, MethodLiteral *mainMethodLiteral,
const JSPandaFile *jsPandaFile);
};

View File

@ -45,17 +45,18 @@ void QuickFixManager::LoadPatchIfNeeded(JSThread *thread, const JSPandaFile *bas
uint8_t *patchBuffer = nullptr;
size_t patchSize = 0;
CString baseFileName = baseFile->GetJSPandaFileDesc();
if (checkedFiles_.find(baseFileName) != checkedFiles_.end()) {
LOG_ECMA(DEBUG) << "Do not need check " << baseFileName << " has patch again";
return;
}
checkedFiles_.insert(baseFileName);
bool needLoadPatch = callBack_(baseFileName.c_str(), patchFileName, &patchBuffer, patchSize);
if (!needLoadPatch) {
LOG_ECMA(INFO) << "Do not need load patch of: " << baseFileName;
return;
}
if (methodInfos_.find(baseFileName) != methodInfos_.end()) {
LOG_ECMA(DEBUG) << "Cannot repeat load patch of: " << baseFileName;
return;
}
std::shared_ptr<JSPandaFile> patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFileSecure(
thread, patchFileName.c_str(), "", patchBuffer, patchSize);
if (patchFile == nullptr) {
@ -219,17 +220,14 @@ JSTaggedValue QuickFixManager::CheckAndGetPatch(JSThread *thread, const JSPandaF
CString recordName = MethodLiteral::GetRecordName(baseFile, baseMethodId);
EcmaContext *context = thread->GetCurrentEcmaContext();
JSHandle<JSTaggedValue> moduleRecord = context->FindPatchModule(recordName);
EntityId methodId = method->GetMethodId();
if (moduleRecord->IsHole()) {
PatchLoader::ExecuteFuncOrPatchMain(thread, patchFile.get(), patchInfo);
moduleRecord = context->FindPatchModule(recordName);
if (moduleRecord->IsHole()) {
LOG_ECMA(ERROR) << "cold patch: moduleRecord is still hole after regeneration";
PatchLoader::UpdateModuleForColdPatch(thread, methodId, recordName, false);
return method.GetTaggedValue();
LOG_ECMA(FATAL) << "cold patch: moduleRecord is still hole after regeneration";
UNREACHABLE();
}
}
PatchLoader::UpdateModuleForColdPatch(thread, methodId, recordName);
return method.GetTaggedValue();
}

View File

@ -58,6 +58,7 @@ private:
size_t &patchSize)> callBack_;
CMap<uint32_t, CString> baseClassInfo_ {};
CString currentBaseFileName_;
std::set<CString> checkedFiles_ {};
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_PATCH_QUICK_FIX_MANAGER_H

View File

@ -983,8 +983,6 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread,
cls->SetLexicalEnv(thread, lexenv.GetTaggedValue());
cls->SetModule(thread, module.GetTaggedValue());
const JSHandle<Method> methodHandle(thread, methodObj);
QuickFixHelper::SetPatchModule(thread, methodHandle, cls);
RuntimeSetClassConstructorLength(thread, cls.GetTaggedValue(), length.GetTaggedValue());
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -2334,7 +2332,6 @@ JSTaggedValue RuntimeStubs::RuntimeDefinefunc(JSThread *thread, const JSHandle<J
DefineFuncTryUseAOTHClass(thread, result, ihc, aotLiteralInfo);
result->SetLength(length);
QuickFixHelper::SetPatchModule(thread, methodHandle, result);
return result.GetTaggedValue();
}
@ -2465,7 +2462,6 @@ JSTaggedValue RuntimeStubs::RuntimeDefineMethod(JSThread *thread, const JSHandle
func->SetLength(length);
func->SetLexicalEnv(thread, env);
func->SetModule(thread, module);
QuickFixHelper::SetPatchModule(thread, methodHandle, func);
return func.GetTaggedValue();
}