状态管理AOT动态加载方案

Issue:https://gitee.com/openharmony/arkui_ace_engine/issues/I9T1ZI

Signed-off-by: wu_zhang_da <wuzhangda@huawei.com>
Change-Id: I9d46e4a089ff968de0f35687b72166b95aa1a48c
This commit is contained in:
wu_zhang_da 2024-05-30 10:02:55 +08:00
parent 953d3bb4ba
commit 4b488152a9
4 changed files with 65 additions and 21 deletions

View File

@ -63,21 +63,10 @@ std::pair<CString, CString> JSPandaFileExecutor::ParseAbcEntryPoint(JSThread *th
return std::make_pair(name, entry);
}
Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbcFile(JSThread *thread, const CString &filename,
std::string_view entryPoint, bool needUpdate, bool executeFromJob)
Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromFile(JSThread *thread, const CString &name,
CString entry, bool needUpdate, bool executeFromJob)
{
LOG_ECMA(DEBUG) << "JSPandaFileExecutor::ExecuteFromFile filename " << filename;
CString traceInfo = "JSPandaFileExecutor::ExecuteFromFile " + filename;
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, traceInfo.c_str());
CString entry;
CString name;
EcmaVM *vm = thread->GetEcmaVM();
if (!vm->IsBundlePack() && !executeFromJob) {
std::tie(name, entry) = ParseAbcEntryPoint(thread, filename, entryPoint);
} else {
name = filename;
entry = entryPoint.data();
}
std::shared_ptr<JSPandaFile> jsPandaFile =
JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry, needUpdate);
@ -89,8 +78,6 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbcFile(JSThread *
LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << name;
#endif
}
// realEntry is used to record the original record, which is easy to throw when there are exceptions
const CString realEntry = entry;
// If it is an old record, delete the bundleName and moduleName
if (!jsPandaFile->IsBundlePack() && !vm->IsNormalizedOhmUrlPack() && !executeFromJob &&
!vm->GetBundleName().empty()) {
@ -103,12 +90,11 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbcFile(JSThread *
JSRecordInfo recordInfo;
bool hasRecord = jsPandaFile->CheckAndGetRecordInfo(entry, recordInfo);
if (!hasRecord) {
CString msg = "Cannot find module '" + realEntry + "' , which is application Entry Point";
CString msg = "Cannot find module '" + entry + "' , which is application Entry Point";
THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), Unexpected(false));
}
if (jsPandaFile->IsModule(recordInfo)) {
ThreadManagedScope managedScope(thread);
[[maybe_unused]] EcmaHandleScope scope(thread);
SharedModuleManager* sharedModuleManager = SharedModuleManager::GetInstance();
JSHandle<JSTaggedValue> moduleRecord(thread->GlobalConstants()->GetHandledUndefined());
if (jsPandaFile->IsBundlePack()) {
@ -116,7 +102,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbcFile(JSThread *
} else {
moduleRecord = sharedModuleManager->ResolveImportedModuleWithMerge(thread, name, entry, executeFromJob);
}
SourceTextModule::Instantiate(thread, moduleRecord, executeFromJob);
if (thread->HasPendingException()) {
return Unexpected(false);
@ -134,6 +120,37 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbcFile(JSThread *
return JSPandaFileExecutor::Execute(thread, jsPandaFile.get(), entry.c_str(), executeFromJob);
}
Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbsolutePathAbcFile(JSThread *thread,
const CString &filename, std::string_view entryPoint, bool needUpdate, bool executeFromJob)
{
LOG_ECMA(DEBUG) << "JSPandaFileExecutor::ExecuteFromAbsolutePathAbcFile filename " << filename;
CString traceInfo = "JSPandaFileExecutor::ExecuteFromAbsolutePathAbcFile " + filename;
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, traceInfo.c_str());
CString entry = entryPoint.data();
CString name = filename;
return ExecuteFromFile(thread, name, entry, needUpdate, executeFromJob);
}
Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromAbcFile(JSThread *thread, const CString &filename,
std::string_view entryPoint, bool needUpdate, bool executeFromJob)
{
LOG_ECMA(DEBUG) << "JSPandaFileExecutor::ExecuteFromAbcFile filename " << filename;
CString traceInfo = "JSPandaFileExecutor::ExecuteFromAbcFile " + filename;
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, traceInfo.c_str());
CString entry;
CString name;
EcmaVM *vm = thread->GetEcmaVM();
if (!vm->IsBundlePack() && !executeFromJob) {
std::tie(name, entry) = ParseAbcEntryPoint(thread, filename, entryPoint);
} else {
name = filename;
entry = entryPoint.data();
}
return ExecuteFromFile(thread, name, entry, needUpdate, executeFromJob);
}
// The security interface needs to be modified accordingly.
Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromBuffer(JSThread *thread,
const void *buffer, size_t size, std::string_view entryPoint, const CString &filename, bool needUpdate)

View File

@ -28,12 +28,18 @@ public:
static constexpr int ROUTE_SUCCESS = 0;
static constexpr int ROUTE_INTERNAL_ERROR = 100001;
static constexpr int ROUTE_URI_ERROR = 100002;
std::pair<CString, CString> ParseEntryPointWithUnifiedRules(EcmaVM *vm, const CString &filename,
std::string_view entryPoint);
static std::pair<CString, CString> ParseAbcEntryPoint(JSThread *thread, const CString &filename,
[[maybe_unused]] std::string_view entryPoint);
static Expected<JSTaggedValue, bool> ExecuteFromFile(JSThread *thread, const CString &name,
CString entry, bool needUpdate = false,
bool executeFromJob = false);
static Expected<JSTaggedValue, bool> ExecuteFromAbsolutePathAbcFile(JSThread *thread, const CString &filename,
std::string_view entryPoint,
bool needUpdate = false,
bool executeFromJob = false);
static Expected<JSTaggedValue, bool> ExecuteFromAbcFile(JSThread *thread, const CString &filename,
std::string_view entryPoint, bool needUpdate = false,
bool executeFromJob = false);

View File

@ -1388,6 +1388,8 @@ public:
static bool ExecuteInContext(EcmaVM *vm, const std::string &fileName, const std::string &entry,
bool needUpdate = false);
// JS code
static bool ExecuteForAbsolutePath(const EcmaVM *vm, const std::string &fileName, const std::string &entry,
bool needUpdate = false, bool executeFromJob = false);
static bool Execute(const EcmaVM *vm, const std::string &fileName, const std::string &entry,
bool needUpdate = false, bool executeFromJob = false);
static bool Execute(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &entry,

View File

@ -4459,6 +4459,25 @@ bool JSNApi::ExecuteInContext(EcmaVM *vm, const std::string &fileName, const std
return true;
}
bool JSNApi::ExecuteForAbsolutePath(const EcmaVM *vm, const std::string &fileName, const std::string &entry,
bool needUpdate, bool executeFromJob)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, false);
LOG_ECMA(DEBUG) << "start to execute absolute path ark file: " << fileName;
ecmascript::ThreadManagedScope scope(thread);
if (!ecmascript::JSPandaFileExecutor::ExecuteFromAbsolutePathAbcFile(
thread, fileName.c_str(), entry, needUpdate, executeFromJob)) {
if (thread->HasPendingException()) {
ecmascript::JsStackInfo::BuildCrashInfo(true);
thread->GetCurrentEcmaContext()->HandleUncaughtException();
}
LOG_ECMA(ERROR) << "Cannot execute absolute path ark file '" << fileName
<< "' with entry '" << entry << "'" << std::endl;
return false;
}
return true;
}
bool JSNApi::Execute(const EcmaVM *vm, const std::string &fileName, const std::string &entry,
bool needUpdate, bool executeFromJob)
{
@ -4996,7 +5015,7 @@ Local<JSValueRef> JSNApi::NapiGetProperty(const EcmaVM *vm, uintptr_t nativeObj,
RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm));
return scope.Escape(JSNApiHelper::ToLocal<JSValueRef>(JSHandle<JSTaggedValue>(thread, res)));
}
JSTaggedValue ret = ObjectFastOperator::FastGetPropertyByValue(thread, obj.GetTaggedValue(),
keyValue.GetTaggedValue());
RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm));