2021-09-04 08:06:49 +00:00
|
|
|
/*
|
2022-04-16 07:57:40 +00:00
|
|
|
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
2021-09-04 08:06:49 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ecmascript/ecma_vm.h"
|
|
|
|
|
|
|
|
#include "ecmascript/base/string_helper.h"
|
|
|
|
#include "ecmascript/builtins.h"
|
|
|
|
#include "ecmascript/builtins/builtins_regexp.h"
|
2022-05-16 11:38:24 +00:00
|
|
|
#include "ecmascript/compiler/call_signature.h"
|
2022-03-19 01:17:21 +00:00
|
|
|
#include "ecmascript/compiler/common_stubs.h"
|
2022-03-16 10:12:15 +00:00
|
|
|
#include "ecmascript/compiler/interpreter_stub.h"
|
|
|
|
#include "ecmascript/compiler/rt_call_signature.h"
|
2022-02-26 03:08:37 +00:00
|
|
|
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
|
2022-03-03 14:22:54 +00:00
|
|
|
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
|
2022-02-26 03:08:37 +00:00
|
|
|
#endif
|
2022-03-03 14:22:54 +00:00
|
|
|
#include "ecmascript/dfx/vmstat/runtime_stat.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/ecma_string_table.h"
|
2022-05-16 11:38:24 +00:00
|
|
|
#include "ecmascript/file_loader.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/global_env.h"
|
|
|
|
#include "ecmascript/global_env_constants-inl.h"
|
|
|
|
#include "ecmascript/global_env_constants.h"
|
2022-03-24 07:04:57 +00:00
|
|
|
#include "ecmascript/interpreter/interpreter-inl.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/jobs/micro_job_queue.h"
|
2022-05-06 08:34:15 +00:00
|
|
|
#include "ecmascript/jspandafile/constpool_value.h"
|
2022-02-06 15:16:08 +00:00
|
|
|
#include "ecmascript/jspandafile/js_pandafile.h"
|
|
|
|
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
2022-01-30 08:01:33 +00:00
|
|
|
#include "ecmascript/jspandafile/module_data_extractor.h"
|
|
|
|
#include "ecmascript/jspandafile/panda_file_translator.h"
|
2022-04-05 13:28:18 +00:00
|
|
|
#include "ecmascript/jspandafile/program_object.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/js_arraybuffer.h"
|
|
|
|
#include "ecmascript/js_for_in_iterator.h"
|
2021-12-16 03:41:16 +00:00
|
|
|
#include "ecmascript/js_native_pointer.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/js_thread.h"
|
2021-12-17 09:18:10 +00:00
|
|
|
#include "ecmascript/mem/concurrent_marker.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/mem/heap.h"
|
2022-05-11 09:36:28 +00:00
|
|
|
#include "ecmascript/mem/gc_stats.h"
|
|
|
|
#include "ecmascript/mem/mem.h"
|
|
|
|
#include "ecmascript/mem/space.h"
|
|
|
|
#include "ecmascript/mem/visitor.h"
|
|
|
|
#include "ecmascript/taskpool/task.h"
|
2022-01-30 08:01:33 +00:00
|
|
|
#include "ecmascript/module/js_module_manager.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/object_factory.h"
|
2022-03-23 07:43:38 +00:00
|
|
|
#include "ecmascript/taskpool/taskpool.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/regexp/regexp_parser_cache.h"
|
|
|
|
#include "ecmascript/runtime_call_id.h"
|
2022-05-11 09:36:28 +00:00
|
|
|
#include "ecmascript/snapshot/mem/snapshot_env.h"
|
|
|
|
#include "ecmascript/snapshot/mem/snapshot.h"
|
2022-03-16 10:12:15 +00:00
|
|
|
#include "ecmascript/stubs/runtime_stubs.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/tagged_array-inl.h"
|
2021-12-17 09:18:10 +00:00
|
|
|
#include "ecmascript/tagged_dictionary.h"
|
2022-04-05 13:28:18 +00:00
|
|
|
#include "ecmascript/tagged_queue.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/tagged_queue.h"
|
2022-02-22 08:50:20 +00:00
|
|
|
#include "ecmascript/ts_types/ts_loader.h"
|
2022-06-08 02:59:06 +00:00
|
|
|
#include "ecmascript/require/js_cjs_module_cache.h"
|
|
|
|
#include "ecmascript/require/js_require_manager.h"
|
2022-05-11 09:36:28 +00:00
|
|
|
#include "ecmascript/tooling/interface/js_debugger_manager.h"
|
2022-02-26 03:08:37 +00:00
|
|
|
#ifdef PANDA_TARGET_WINDOWS
|
|
|
|
#ifdef ERROR
|
|
|
|
#undef ERROR
|
|
|
|
#endif
|
|
|
|
#ifdef GetObject
|
|
|
|
#undef GetObject
|
|
|
|
#endif
|
|
|
|
#endif
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
namespace panda::ecmascript {
|
|
|
|
/* static */
|
2022-06-15 03:23:16 +00:00
|
|
|
EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options, EcmaParamConfiguration &config)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-06-15 03:23:16 +00:00
|
|
|
auto vm = new EcmaVM(options, config);
|
2021-09-04 08:06:49 +00:00
|
|
|
if (UNLIKELY(vm == nullptr)) {
|
|
|
|
LOG_ECMA(ERROR) << "Failed to create jsvm";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-04-20 08:27:09 +00:00
|
|
|
auto jsThread = JSThread::Create(vm);
|
2021-09-04 08:06:49 +00:00
|
|
|
vm->thread_ = jsThread;
|
|
|
|
vm->Initialize();
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2022-04-20 08:27:09 +00:00
|
|
|
bool EcmaVM::Destroy(EcmaVM *vm)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
|
|
|
if (vm != nullptr) {
|
2022-04-20 08:27:09 +00:00
|
|
|
delete vm;
|
|
|
|
vm = nullptr;
|
2021-09-04 08:06:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-15 03:23:16 +00:00
|
|
|
EcmaVM::EcmaVM(JSRuntimeOptions options, EcmaParamConfiguration config)
|
2021-10-19 03:55:00 +00:00
|
|
|
: stringTable_(new EcmaStringTable(this)),
|
2022-02-17 07:11:23 +00:00
|
|
|
nativeAreaAllocator_(std::make_unique<NativeAreaAllocator>()),
|
|
|
|
heapRegionAllocator_(std::make_unique<HeapRegionAllocator>()),
|
|
|
|
chunk_(nativeAreaAllocator_.get()),
|
2022-06-15 03:23:16 +00:00
|
|
|
nativePointerList_(&chunk_),
|
|
|
|
ecmaParamConfiguration_(std::move(config))
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2021-10-19 03:55:00 +00:00
|
|
|
options_ = std::move(options);
|
2022-04-30 12:02:19 +00:00
|
|
|
icEnabled_ = options_.EnableIC();
|
|
|
|
optionalLogEnabled_ = options_.EnableOptionalLog();
|
2022-03-31 15:38:07 +00:00
|
|
|
snapshotFileName_ = options_.GetSnapshotFile().c_str();
|
|
|
|
frameworkAbcFileName_ = options_.GetFrameworkAbcFile().c_str();
|
2022-03-18 07:17:30 +00:00
|
|
|
options_.ParseAsmInterOption();
|
2021-10-18 08:54:11 +00:00
|
|
|
|
2022-04-16 07:57:40 +00:00
|
|
|
debuggerManager_ = chunk_.New<tooling::JsDebuggerManager>();
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EcmaVM::Initialize()
|
|
|
|
{
|
2022-04-29 08:46:53 +00:00
|
|
|
LOG(INFO, RUNTIME) << "EcmaVM Initialize";
|
2022-05-11 08:51:55 +00:00
|
|
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "EcmaVM::Initialize");
|
2022-03-23 07:43:38 +00:00
|
|
|
Taskpool::GetCurrentTaskpool()->Initialize();
|
2022-02-26 03:08:37 +00:00
|
|
|
#ifndef PANDA_TARGET_WINDOWS
|
2022-03-16 10:12:15 +00:00
|
|
|
RuntimeStubs::Initialize(thread_);
|
2022-02-26 03:08:37 +00:00
|
|
|
#endif
|
2021-09-04 08:06:49 +00:00
|
|
|
auto globalConst = const_cast<GlobalEnvConstants *>(thread_->GlobalConstants());
|
|
|
|
regExpParserCache_ = new RegExpParserCache();
|
|
|
|
heap_ = new Heap(this);
|
2021-09-07 14:24:16 +00:00
|
|
|
heap_->Initialize();
|
2022-05-27 09:56:07 +00:00
|
|
|
gcStats_ = chunk_.New<GCStats>(heap_, options_.GetLongPauseTime());
|
2022-05-23 12:57:44 +00:00
|
|
|
factory_ = chunk_.New<ObjectFactory>(thread_, heap_, &chunk_);
|
2021-09-04 08:06:49 +00:00
|
|
|
if (UNLIKELY(factory_ == nullptr)) {
|
|
|
|
LOG_ECMA(FATAL) << "alloc factory_ failed";
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2021-12-17 09:18:10 +00:00
|
|
|
[[maybe_unused]] EcmaHandleScope scope(thread_);
|
2022-03-26 09:00:26 +00:00
|
|
|
|
2022-06-07 08:44:17 +00:00
|
|
|
if (!options_.EnableSnapshotDeserialize()) {
|
|
|
|
LOG_ECMA(DEBUG) << "EcmaVM::Initialize run builtins";
|
|
|
|
JSHandle<JSHClass> dynClassClassHandle = factory_->InitClassClass();
|
|
|
|
JSHandle<JSHClass> globalEnvClass = factory_->NewEcmaDynClass(*dynClassClassHandle,
|
|
|
|
GlobalEnv::SIZE,
|
|
|
|
JSType::GLOBAL_ENV);
|
|
|
|
globalConst->Init(thread_, *dynClassClassHandle);
|
|
|
|
globalConstInitialized_ = true;
|
|
|
|
JSHandle<GlobalEnv> globalEnv = factory_->NewGlobalEnv(*globalEnvClass);
|
|
|
|
globalEnv->Init(thread_);
|
|
|
|
globalEnv_ = globalEnv.GetTaggedValue();
|
|
|
|
Builtins builtins;
|
|
|
|
builtins.Initialize(globalEnv, thread_);
|
|
|
|
if (!WIN_OR_MAC_PLATFORM && options_.EnableSnapshotSerialize()) {
|
|
|
|
const CString fileName = "builtins.snapshot";
|
|
|
|
Snapshot snapshot(this);
|
|
|
|
snapshot.SerializeBuiltins(fileName);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const CString fileName = "builtins.snapshot";
|
|
|
|
Snapshot snapshot(this);
|
|
|
|
if (!WIN_OR_MAC_PLATFORM) {
|
|
|
|
snapshot.Deserialize(SnapshotType::BUILTINS, fileName, true);
|
|
|
|
}
|
|
|
|
globalConst->InitSpecialForSnapshot();
|
|
|
|
Builtins builtins;
|
|
|
|
builtins.InitializeForSnapshot(thread_);
|
|
|
|
}
|
|
|
|
|
2022-03-26 09:00:26 +00:00
|
|
|
SetupRegExpResultCache();
|
|
|
|
microJobQueue_ = factory_->NewMicroJobQueue().GetTaggedValue();
|
2022-05-23 12:57:44 +00:00
|
|
|
factory_->GenerateInternalNativeMethods();
|
2022-02-19 02:09:52 +00:00
|
|
|
thread_->SetGlobalObject(GetGlobalEnv()->GetGlobalObject());
|
2021-09-04 08:06:49 +00:00
|
|
|
moduleManager_ = new ModuleManager(this);
|
2022-04-22 07:19:24 +00:00
|
|
|
debuggerManager_->Initialize();
|
2022-05-12 02:23:24 +00:00
|
|
|
tsLoader_ = new TSLoader(this);
|
|
|
|
snapshotEnv_ = new SnapshotEnv(this);
|
2022-06-14 11:18:29 +00:00
|
|
|
if (!WIN_OR_MAC_PLATFORM) {
|
|
|
|
snapshotEnv_->Initialize();
|
|
|
|
}
|
2022-05-16 11:38:24 +00:00
|
|
|
fileLoader_ = new FileLoader(this);
|
2022-06-08 06:43:48 +00:00
|
|
|
if (options_.GetEnableAsmInterpreter()) {
|
2022-05-16 11:38:24 +00:00
|
|
|
LoadStubFile();
|
2022-05-12 02:23:24 +00:00
|
|
|
}
|
2022-06-08 06:43:48 +00:00
|
|
|
if (options_.GetEnableAsmInterpreter() && options_.WasAOTOutputFileSet()) {
|
2022-05-16 11:38:24 +00:00
|
|
|
LoadAOTFiles();
|
2022-05-12 02:23:24 +00:00
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
InitializeFinish();
|
2021-12-17 09:18:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
void EcmaVM::InitializeEcmaScriptRunStat()
|
|
|
|
{
|
|
|
|
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
|
|
|
|
static const char *runtimeCallerNames[] = {
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
2022-02-09 08:48:39 +00:00
|
|
|
#define INTERPRETER_CALLER_NAME(name) "Interpreter::" #name,
|
|
|
|
INTERPRETER_CALLER_LIST(INTERPRETER_CALLER_NAME) // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
|
2021-09-04 08:06:49 +00:00
|
|
|
#undef INTERPRETER_CALLER_NAME
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
|
|
|
#define BUILTINS_API_NAME(class, name) "BuiltinsApi::" #class "_" #name,
|
2022-03-21 09:09:19 +00:00
|
|
|
BUILTINS_API_LIST(BUILTINS_API_NAME)
|
2021-09-04 08:06:49 +00:00
|
|
|
#undef BUILTINS_API_NAME
|
|
|
|
#define ABSTRACT_OPERATION_NAME(class, name) "AbstractOperation::" #class "_" #name,
|
2022-02-09 08:48:39 +00:00
|
|
|
ABSTRACT_OPERATION_LIST(ABSTRACT_OPERATION_NAME)
|
2021-09-04 08:06:49 +00:00
|
|
|
#undef ABSTRACT_OPERATION_NAME
|
2022-02-09 08:48:39 +00:00
|
|
|
#define MEM_ALLOCATE_AND_GC_NAME(name) "Memory::" #name,
|
|
|
|
MEM_ALLOCATE_AND_GC_LIST(MEM_ALLOCATE_AND_GC_NAME)
|
|
|
|
#undef MEM_ALLOCATE_AND_GC_NAME
|
2022-04-16 08:20:50 +00:00
|
|
|
#define DEF_RUNTIME_ID(name) "Runtime::" #name,
|
2022-03-16 10:12:15 +00:00
|
|
|
RUNTIME_STUB_WITH_GC_LIST(DEF_RUNTIME_ID)
|
2022-03-11 08:08:16 +00:00
|
|
|
#undef DEF_RUNTIME_ID
|
2021-09-04 08:06:49 +00:00
|
|
|
};
|
2022-01-16 07:30:39 +00:00
|
|
|
static_assert(sizeof(runtimeCallerNames) == sizeof(const char *) * ecmascript::RUNTIME_CALLER_NUMBER,
|
|
|
|
"Invalid runtime caller number");
|
2021-09-04 08:06:49 +00:00
|
|
|
runtimeStat_ = chunk_.New<EcmaRuntimeStat>(runtimeCallerNames, ecmascript::RUNTIME_CALLER_NUMBER);
|
|
|
|
if (UNLIKELY(runtimeStat_ == nullptr)) {
|
|
|
|
LOG_ECMA(FATAL) << "alloc runtimeStat_ failed";
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::SetRuntimeStatEnable(bool flag)
|
|
|
|
{
|
2022-04-29 08:46:53 +00:00
|
|
|
static uint64_t start = 0;
|
2021-09-04 08:06:49 +00:00
|
|
|
if (flag) {
|
2022-04-29 08:46:53 +00:00
|
|
|
start = PandaRuntimeTimer::Now();
|
2021-09-04 08:06:49 +00:00
|
|
|
if (runtimeStat_ == nullptr) {
|
|
|
|
InitializeEcmaScriptRunStat();
|
|
|
|
}
|
|
|
|
} else {
|
2022-04-29 08:46:53 +00:00
|
|
|
LOG(INFO, RUNTIME) << "Runtime State duration:" << PandaRuntimeTimer::Now() - start << "(ns)";
|
|
|
|
if (runtimeStat_->IsRuntimeStatEnabled()) {
|
2021-09-04 08:06:49 +00:00
|
|
|
runtimeStat_->Print();
|
|
|
|
runtimeStat_->ResetAllCount();
|
|
|
|
}
|
|
|
|
}
|
2022-04-29 08:46:53 +00:00
|
|
|
runtimeStat_->SetRuntimeStatEnabled(flag);
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EcmaVM::InitializeFinish()
|
|
|
|
{
|
|
|
|
vmInitialized_ = true;
|
|
|
|
return true;
|
|
|
|
}
|
2022-01-12 07:43:56 +00:00
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
EcmaVM::~EcmaVM()
|
|
|
|
{
|
2022-06-07 02:58:19 +00:00
|
|
|
LOG(INFO, RUNTIME) << "Destruct ecma_vm, vm address is: " << this;
|
2021-09-04 08:06:49 +00:00
|
|
|
vmInitialized_ = false;
|
2022-03-23 07:43:38 +00:00
|
|
|
Taskpool::GetCurrentTaskpool()->Destroy();
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2022-04-29 08:46:53 +00:00
|
|
|
if (runtimeStat_ != nullptr && runtimeStat_->IsRuntimeStatEnabled()) {
|
2021-09-04 08:06:49 +00:00
|
|
|
runtimeStat_->Print();
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear c_address: c++ pointer delete
|
|
|
|
ClearBufferData();
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
if (gcStats_ != nullptr) {
|
2022-04-30 12:02:19 +00:00
|
|
|
if (options_.EnableGCStatsPrint()) {
|
2022-01-07 09:36:04 +00:00
|
|
|
gcStats_->PrintStatisticResult(true);
|
|
|
|
}
|
2021-09-07 14:24:16 +00:00
|
|
|
chunk_.Delete(gcStats_);
|
|
|
|
gcStats_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
if (heap_ != nullptr) {
|
2021-09-07 14:24:16 +00:00
|
|
|
heap_->Destroy();
|
2021-09-04 08:06:49 +00:00
|
|
|
delete heap_;
|
|
|
|
heap_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete regExpParserCache_;
|
|
|
|
regExpParserCache_ = nullptr;
|
|
|
|
|
2022-04-22 07:19:24 +00:00
|
|
|
if (debuggerManager_ != nullptr) {
|
|
|
|
chunk_.Delete(debuggerManager_);
|
|
|
|
debuggerManager_ = nullptr;
|
2021-10-18 08:54:11 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
if (factory_ != nullptr) {
|
|
|
|
chunk_.Delete(factory_);
|
|
|
|
factory_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stringTable_ != nullptr) {
|
|
|
|
delete stringTable_;
|
|
|
|
stringTable_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (runtimeStat_ != nullptr) {
|
|
|
|
chunk_.Delete(runtimeStat_);
|
|
|
|
runtimeStat_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moduleManager_ != nullptr) {
|
|
|
|
delete moduleManager_;
|
|
|
|
moduleManager_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:50:20 +00:00
|
|
|
if (tsLoader_ != nullptr) {
|
|
|
|
delete tsLoader_;
|
|
|
|
tsLoader_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-05-17 06:52:04 +00:00
|
|
|
if (snapshotEnv_ != nullptr) {
|
|
|
|
delete snapshotEnv_;
|
|
|
|
snapshotEnv_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:24 +00:00
|
|
|
if (fileLoader_ != nullptr) {
|
|
|
|
delete fileLoader_;
|
|
|
|
fileLoader_ = nullptr;
|
2022-02-23 08:50:04 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
if (thread_ != nullptr) {
|
|
|
|
delete thread_;
|
|
|
|
thread_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSHandle<GlobalEnv> EcmaVM::GetGlobalEnv() const
|
|
|
|
{
|
|
|
|
return JSHandle<GlobalEnv>(reinterpret_cast<uintptr_t>(&globalEnv_));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSHandle<job::MicroJobQueue> EcmaVM::GetMicroJobQueue() const
|
|
|
|
{
|
|
|
|
return JSHandle<job::MicroJobQueue>(reinterpret_cast<uintptr_t>(µJobQueue_));
|
|
|
|
}
|
|
|
|
|
2022-04-10 04:28:09 +00:00
|
|
|
EcmaVM::CpuProfilingScope::CpuProfilingScope(EcmaVM* vm) : vm_(vm), profiler_(nullptr)
|
|
|
|
{
|
|
|
|
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
|
2022-06-09 11:22:45 +00:00
|
|
|
if (vm_->GetJSOptions().EnableCpuProfiler()) {
|
2022-04-10 04:28:09 +00:00
|
|
|
profiler_ = CpuProfiler::GetInstance();
|
2022-05-10 13:28:13 +00:00
|
|
|
profiler_->CpuProfiler::StartCpuProfilerForFile(vm, "");
|
2022-04-10 04:28:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
EcmaVM::CpuProfilingScope::~CpuProfilingScope()
|
|
|
|
{
|
|
|
|
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
|
|
|
|
if (profiler_ != nullptr) {
|
2022-05-10 13:28:13 +00:00
|
|
|
profiler_->CpuProfiler::StopCpuProfilerForFile();
|
2022-04-10 04:28:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-06 08:34:15 +00:00
|
|
|
JSTaggedValue EcmaVM::InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, const JSPandaFile *jsPandaFile)
|
|
|
|
{
|
2022-05-16 11:38:24 +00:00
|
|
|
fileLoader_->UpdateJSMethods(mainFunc, jsPandaFile);
|
2022-04-10 04:28:09 +00:00
|
|
|
std::vector<JSTaggedType> args(6, JSTaggedValue::Undefined().GetRawData()); // 6: number of para
|
2022-04-16 09:32:42 +00:00
|
|
|
args[0] = mainFunc.GetTaggedValue().GetRawData();
|
2022-05-17 02:23:58 +00:00
|
|
|
auto entry = thread_->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry);
|
|
|
|
auto res = reinterpret_cast<JSFunctionEntryType>(entry)(thread_->GetGlueAddr(),
|
|
|
|
reinterpret_cast<uintptr_t>(thread_->GetCurrentSPFrame()),
|
|
|
|
static_cast<uint32_t>(args.size()),
|
|
|
|
static_cast<uint32_t>(args.size()),
|
|
|
|
args.data(),
|
|
|
|
mainFunc->GetCodeEntry());
|
2022-04-16 07:57:40 +00:00
|
|
|
return JSTaggedValue(res);
|
2022-04-10 04:28:09 +00:00
|
|
|
}
|
|
|
|
|
2022-04-08 01:23:52 +00:00
|
|
|
Expected<JSTaggedValue, bool> EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-04-08 01:23:52 +00:00
|
|
|
JSTaggedValue result;
|
2021-09-04 08:06:49 +00:00
|
|
|
[[maybe_unused]] EcmaHandleScope scope(thread_);
|
|
|
|
JSHandle<Program> program;
|
2022-03-26 09:00:26 +00:00
|
|
|
if (jsPandaFile != frameworkPandaFile_) {
|
2022-03-21 13:19:10 +00:00
|
|
|
program = JSPandaFileManager::GetInstance()->GenerateProgram(this, jsPandaFile);
|
2021-09-04 08:06:49 +00:00
|
|
|
} else {
|
2022-03-26 09:00:26 +00:00
|
|
|
program = JSHandle<Program>(thread_, frameworkProgram_);
|
|
|
|
frameworkProgram_ = JSTaggedValue::Hole();
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
if (program.IsEmpty()) {
|
|
|
|
LOG_ECMA(ERROR) << "program is empty, invoke entrypoint failed";
|
2022-04-08 01:23:52 +00:00
|
|
|
return Unexpected(false);
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
2022-02-28 07:04:37 +00:00
|
|
|
// for debugger
|
2022-04-22 07:19:24 +00:00
|
|
|
debuggerManager_->GetNotificationManager()->LoadModuleEvent(jsPandaFile->GetJSPandaFileDesc());
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
JSHandle<JSFunction> func = JSHandle<JSFunction>(thread_, program->GetMainFunction());
|
2022-02-26 03:08:37 +00:00
|
|
|
JSHandle<JSTaggedValue> global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject();
|
2022-01-30 08:01:33 +00:00
|
|
|
if (jsPandaFile->IsModule()) {
|
|
|
|
global = JSHandle<JSTaggedValue>(thread_, JSTaggedValue::Undefined());
|
|
|
|
JSHandle<SourceTextModule> module = moduleManager_->HostGetImportedModule(jsPandaFile->GetJSPandaFileDesc());
|
|
|
|
func->SetModule(thread_, module);
|
|
|
|
}
|
2022-04-06 11:22:08 +00:00
|
|
|
|
2022-06-08 06:43:48 +00:00
|
|
|
if (jsPandaFile->IsLoadedAOT()) {
|
2022-06-10 07:22:21 +00:00
|
|
|
thread_->SetPrintBCOffset(true);
|
2022-05-06 08:34:15 +00:00
|
|
|
result = InvokeEcmaAotEntrypoint(func, jsPandaFile);
|
2021-12-17 09:18:10 +00:00
|
|
|
} else {
|
2022-06-08 02:59:06 +00:00
|
|
|
if (jsPandaFile->IsCjs()) {
|
|
|
|
CJSExecution(func, jsPandaFile);
|
|
|
|
} else {
|
|
|
|
JSHandle<JSTaggedValue> undefined = thread_->GlobalConstants()->GetHandledUndefined();
|
|
|
|
EcmaRuntimeCallInfo info =
|
|
|
|
EcmaInterpreter::NewRuntimeCallInfo(thread_, JSHandle<JSTaggedValue>(func), global, undefined, 0);
|
|
|
|
EcmaRuntimeStatScope runtimeStatScope(this);
|
|
|
|
CpuProfilingScope profilingScope(this);
|
|
|
|
EcmaInterpreter::Execute(&info);
|
2022-06-08 06:43:48 +00:00
|
|
|
}
|
2021-12-17 09:18:10 +00:00
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
if (!thread_->HasPendingException()) {
|
2021-10-20 09:35:03 +00:00
|
|
|
job::MicroJobQueue::ExecutePendingJob(thread_, GetMicroJobQueue());
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// print exception information
|
|
|
|
if (thread_->HasPendingException()) {
|
|
|
|
auto exception = thread_->GetException();
|
|
|
|
HandleUncaughtException(exception.GetTaggedObject());
|
|
|
|
}
|
2022-04-08 01:23:52 +00:00
|
|
|
return result;
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 13:19:10 +00:00
|
|
|
JSTaggedValue EcmaVM::FindConstpool(const JSPandaFile *jsPandaFile)
|
|
|
|
{
|
|
|
|
auto iter = cachedConstpools_.find(jsPandaFile);
|
|
|
|
if (iter == cachedConstpools_.end()) {
|
|
|
|
return JSTaggedValue::Hole();
|
|
|
|
}
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2022-06-08 02:59:06 +00:00
|
|
|
void EcmaVM::CJSExecution(JSHandle<JSFunction> &func, const JSPandaFile *jsPandaFile)
|
|
|
|
{
|
|
|
|
[[maybe_unused]] EcmaHandleScope scope(thread_);
|
|
|
|
ObjectFactory *factory = GetFactory();
|
2022-06-08 06:43:48 +00:00
|
|
|
|
2022-06-08 02:59:06 +00:00
|
|
|
// create "module", "exports", "require", "filename", "dirname"
|
|
|
|
JSHandle<JSCjsModule> module = factory->NewCjsModule();
|
|
|
|
JSHandle<JSTaggedValue> require = GetGlobalEnv()->GetCjsRequireFunction();
|
|
|
|
JSHandle<JSCjsExports> exports = factory->NewCjsExports();
|
|
|
|
JSMutableHandle<JSTaggedValue> filename(thread_, JSTaggedValue::Undefined());;
|
|
|
|
JSMutableHandle<JSTaggedValue> dirname(thread_, JSTaggedValue::Undefined());;
|
|
|
|
JSRequireManager::ResolveCurrentPath(thread_, dirname, filename, jsPandaFile);
|
|
|
|
CJSInfo cjsInfo(module, require, exports, filename, dirname);
|
|
|
|
JSRequireManager::InitializeCommonJS(thread_, cjsInfo);
|
|
|
|
|
|
|
|
// Execute main function
|
|
|
|
JSHandle<JSTaggedValue> global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject();
|
|
|
|
JSHandle<JSTaggedValue> undefined = thread_->GlobalConstants()->GetHandledUndefined();
|
|
|
|
EcmaRuntimeCallInfo info =
|
|
|
|
EcmaInterpreter::NewRuntimeCallInfo(thread_,
|
|
|
|
JSHandle<JSTaggedValue>(func),
|
|
|
|
global, undefined, 5); // 5 : argument numbers
|
|
|
|
info.SetCallArg(cjsInfo.exportsHdl.GetTaggedValue(),
|
|
|
|
cjsInfo.requireHdl.GetTaggedValue(),
|
|
|
|
cjsInfo.moduleHdl.GetTaggedValue(),
|
|
|
|
cjsInfo.filenameHdl.GetTaggedValue(),
|
|
|
|
cjsInfo.dirnameHdl.GetTaggedValue());
|
|
|
|
EcmaRuntimeStatScope runtimeStatScope(this);
|
|
|
|
CpuProfilingScope profilingScope(this);
|
|
|
|
EcmaInterpreter::Execute(&info);
|
|
|
|
|
|
|
|
// Collecting module.exports : exports ---> module.exports --->Module._cache
|
|
|
|
JSRequireManager::CollectExecutedExp(thread_, cjsInfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-21 13:19:10 +00:00
|
|
|
void EcmaVM::SetConstpool(const JSPandaFile *jsPandaFile, JSTaggedValue constpool)
|
|
|
|
{
|
|
|
|
ASSERT(constpool.IsTaggedArray());
|
|
|
|
ASSERT(cachedConstpools_.find(jsPandaFile) == cachedConstpools_.end());
|
|
|
|
|
|
|
|
cachedConstpools_[jsPandaFile] = constpool;
|
|
|
|
}
|
|
|
|
|
2022-01-27 07:54:49 +00:00
|
|
|
JSHandle<JSTaggedValue> EcmaVM::GetAndClearEcmaUncaughtException() const
|
|
|
|
{
|
|
|
|
JSHandle<JSTaggedValue> exceptionHandle = GetEcmaUncaughtException();
|
|
|
|
thread_->ClearException(); // clear for ohos app
|
|
|
|
return exceptionHandle;
|
|
|
|
}
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSTaggedValue> EcmaVM::GetEcmaUncaughtException() const
|
|
|
|
{
|
|
|
|
if (thread_->GetException().IsHole()) {
|
|
|
|
return JSHandle<JSTaggedValue>();
|
|
|
|
}
|
|
|
|
JSHandle<JSTaggedValue> exceptionHandle(thread_, thread_->GetException());
|
|
|
|
return exceptionHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::EnableUserUncaughtErrorHandler()
|
|
|
|
{
|
|
|
|
isUncaughtExceptionRegistered_ = true;
|
|
|
|
}
|
|
|
|
|
2022-06-16 15:10:50 +00:00
|
|
|
void EcmaVM::HandleUncaughtException(TaggedObject *exception)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
|
|
|
if (isUncaughtExceptionRegistered_) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-16 07:57:40 +00:00
|
|
|
[[maybe_unused]] EcmaHandleScope handleScope(thread_);
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSTaggedValue> exceptionHandle(thread_, JSTaggedValue(exception));
|
|
|
|
// if caught exceptionHandle type is JSError
|
|
|
|
thread_->ClearException();
|
|
|
|
if (exceptionHandle->IsJSError()) {
|
|
|
|
PrintJSErrorInfo(exceptionHandle);
|
2022-06-10 07:22:21 +00:00
|
|
|
if (thread_->IsPrintBCOffset() && exceptionBCList_.size() != 0) {
|
|
|
|
for (auto info : exceptionBCList_) {
|
|
|
|
LOG(ERROR, RUNTIME) << "Exception at function " << info.first << ": " << info.second;
|
|
|
|
}
|
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-09-26 13:23:54 +00:00
|
|
|
JSHandle<EcmaString> result = JSTaggedValue::ToString(thread_, exceptionHandle);
|
|
|
|
CString string = ConvertToString(*result);
|
|
|
|
LOG(ERROR, RUNTIME) << string;
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::PrintJSErrorInfo(const JSHandle<JSTaggedValue> &exceptionInfo)
|
|
|
|
{
|
|
|
|
JSHandle<JSTaggedValue> nameKey = thread_->GlobalConstants()->GetHandledNameString();
|
|
|
|
JSHandle<EcmaString> name(JSObject::GetProperty(thread_, exceptionInfo, nameKey).GetValue());
|
|
|
|
JSHandle<JSTaggedValue> msgKey = thread_->GlobalConstants()->GetHandledMessageString();
|
|
|
|
JSHandle<EcmaString> msg(JSObject::GetProperty(thread_, exceptionInfo, msgKey).GetValue());
|
|
|
|
JSHandle<JSTaggedValue> stackKey = thread_->GlobalConstants()->GetHandledStackString();
|
|
|
|
JSHandle<EcmaString> stack(JSObject::GetProperty(thread_, exceptionInfo, stackKey).GetValue());
|
|
|
|
|
|
|
|
CString nameBuffer = ConvertToString(*name);
|
|
|
|
CString msgBuffer = ConvertToString(*msg);
|
|
|
|
CString stackBuffer = ConvertToString(*stack);
|
|
|
|
LOG(ERROR, RUNTIME) << nameBuffer << ": " << msgBuffer << "\n" << stackBuffer;
|
|
|
|
}
|
|
|
|
|
2022-03-07 03:58:44 +00:00
|
|
|
void EcmaVM::ProcessNativeDelete(const WeakRootVisitor &v0)
|
|
|
|
{
|
|
|
|
auto iter = nativePointerList_.begin();
|
|
|
|
while (iter != nativePointerList_.end()) {
|
|
|
|
JSNativePointer *object = *iter;
|
|
|
|
auto fwd = v0(reinterpret_cast<TaggedObject *>(object));
|
|
|
|
if (fwd == nullptr) {
|
|
|
|
object->Destroy();
|
|
|
|
iter = nativePointerList_.erase(iter);
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
void EcmaVM::ProcessReferences(const WeakRootVisitor &v0)
|
|
|
|
{
|
|
|
|
if (regExpParserCache_ != nullptr) {
|
|
|
|
regExpParserCache_->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// array buffer
|
2022-03-04 07:23:09 +00:00
|
|
|
for (auto iter = nativePointerList_.begin(); iter != nativePointerList_.end();) {
|
2021-09-04 08:06:49 +00:00
|
|
|
JSNativePointer *object = *iter;
|
|
|
|
auto fwd = v0(reinterpret_cast<TaggedObject *>(object));
|
|
|
|
if (fwd == nullptr) {
|
|
|
|
object->Destroy();
|
2022-03-04 07:23:09 +00:00
|
|
|
iter = nativePointerList_.erase(iter);
|
2022-03-07 03:58:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fwd != reinterpret_cast<TaggedObject *>(object)) {
|
2021-09-04 08:06:49 +00:00
|
|
|
*iter = JSNativePointer::Cast(fwd);
|
|
|
|
}
|
2022-03-07 03:58:44 +00:00
|
|
|
++iter;
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
2022-03-21 13:19:10 +00:00
|
|
|
|
|
|
|
// program maps
|
|
|
|
for (auto iter = cachedConstpools_.begin(); iter != cachedConstpools_.end();) {
|
|
|
|
auto object = iter->second;
|
2022-05-28 06:48:47 +00:00
|
|
|
if (object.IsHeapObject()) {
|
2022-03-21 13:19:10 +00:00
|
|
|
TaggedObject *obj = object.GetTaggedObject();
|
|
|
|
auto fwd = v0(obj);
|
|
|
|
if (fwd == nullptr) {
|
|
|
|
iter = cachedConstpools_.erase(iter);
|
|
|
|
continue;
|
|
|
|
} else if (fwd != obj) {
|
|
|
|
iter->second = JSTaggedValue(fwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 07:23:09 +00:00
|
|
|
void EcmaVM::PushToNativePointerList(JSNativePointer *array)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-03-04 07:23:09 +00:00
|
|
|
nativePointerList_.emplace_back(array);
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 07:23:09 +00:00
|
|
|
void EcmaVM::RemoveFromNativePointerList(JSNativePointer *array)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-03-04 07:23:09 +00:00
|
|
|
auto iter = std::find(nativePointerList_.begin(), nativePointerList_.end(), array);
|
|
|
|
if (iter != nativePointerList_.end()) {
|
2022-05-07 09:21:10 +00:00
|
|
|
JSNativePointer *object = *iter;
|
|
|
|
object->Destroy();
|
2022-03-04 07:23:09 +00:00
|
|
|
nativePointerList_.erase(iter);
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::ClearBufferData()
|
|
|
|
{
|
2022-03-04 07:23:09 +00:00
|
|
|
for (auto iter : nativePointerList_) {
|
2021-09-04 08:06:49 +00:00
|
|
|
iter->Destroy();
|
|
|
|
}
|
2022-03-04 07:23:09 +00:00
|
|
|
nativePointerList_.clear();
|
2022-03-21 13:19:10 +00:00
|
|
|
|
|
|
|
cachedConstpools_.clear();
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 03:16:27 +00:00
|
|
|
bool EcmaVM::ExecutePromisePendingJob()
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-05-23 03:16:27 +00:00
|
|
|
if (isProcessingPendingJob_) {
|
|
|
|
LOG(ERROR, RUNTIME) << "EcmaVM::ExecutePromisePendingJob can not reentrant";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!thread_->HasPendingException()) {
|
|
|
|
isProcessingPendingJob_ = true;
|
2021-10-20 09:35:03 +00:00
|
|
|
job::MicroJobQueue::ExecutePendingJob(thread_, GetMicroJobQueue());
|
2022-05-23 03:16:27 +00:00
|
|
|
isProcessingPendingJob_ = false;
|
2021-09-04 08:06:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::CollectGarbage(TriggerGCType gcType) const
|
|
|
|
{
|
|
|
|
heap_->CollectGarbage(gcType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::StartHeapTracking(HeapTracker *tracker)
|
|
|
|
{
|
|
|
|
heap_->StartHeapTracking(tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::StopHeapTracking()
|
|
|
|
{
|
|
|
|
heap_->StopHeapTracking();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::Iterate(const RootVisitor &v)
|
|
|
|
{
|
|
|
|
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&globalEnv_)));
|
|
|
|
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(µJobQueue_)));
|
|
|
|
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(®expCache_)));
|
2022-03-04 07:23:09 +00:00
|
|
|
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&frameworkProgram_)));
|
2022-02-22 08:50:20 +00:00
|
|
|
moduleManager_->Iterate(v);
|
|
|
|
tsLoader_->Iterate(v);
|
2022-05-16 11:38:24 +00:00
|
|
|
fileLoader_->Iterate(v);
|
2022-06-07 08:44:17 +00:00
|
|
|
if (!WIN_OR_MAC_PLATFORM) {
|
|
|
|
snapshotEnv_->Iterate(v);
|
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::SetGlobalEnv(GlobalEnv *global)
|
|
|
|
{
|
|
|
|
ASSERT(global != nullptr);
|
|
|
|
globalEnv_ = JSTaggedValue(global);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::SetMicroJobQueue(job::MicroJobQueue *queue)
|
|
|
|
{
|
|
|
|
ASSERT(queue != nullptr);
|
|
|
|
microJobQueue_ = JSTaggedValue(queue);
|
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:24 +00:00
|
|
|
void EcmaVM::SetupRegExpResultCache()
|
2022-03-26 09:00:26 +00:00
|
|
|
{
|
2022-05-16 11:38:24 +00:00
|
|
|
regexpCache_ = builtins::RegExpExecResultCache::CreateCacheTable(thread_);
|
2022-03-26 09:00:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 11:38:24 +00:00
|
|
|
void EcmaVM::LoadStubFile()
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-05-16 11:38:24 +00:00
|
|
|
std::string file = options_.GetStubFile();
|
2022-06-08 06:43:48 +00:00
|
|
|
LOG(INFO, RUNTIME) << "Try to load stub file" << file.c_str();
|
2022-05-16 11:38:24 +00:00
|
|
|
fileLoader_->LoadStubFile(file);
|
2021-09-04 08:06:49 +00:00
|
|
|
}
|
2022-02-23 08:50:04 +00:00
|
|
|
|
2022-05-16 11:38:24 +00:00
|
|
|
void EcmaVM::LoadAOTFiles()
|
2022-02-23 08:50:04 +00:00
|
|
|
{
|
2022-05-16 11:38:24 +00:00
|
|
|
std::string file = options_.GetAOTOutputFile();
|
2022-06-08 06:43:48 +00:00
|
|
|
LOG(INFO, RUNTIME) << "Try to load aot file" << file.c_str();
|
2022-05-16 11:38:24 +00:00
|
|
|
fileLoader_->LoadAOTFile(file);
|
|
|
|
fileLoader_->TryLoadSnapshotFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EcmaVM::SetAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry)
|
|
|
|
{
|
|
|
|
fileLoader_->SetAOTFuncEntry(hash, methodId, funcEntry);
|
2022-02-23 08:50:04 +00:00
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
} // namespace panda::ecmascript
|