mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
fix conflict and move fields in JSThread into context
Signed-off-by: xiongluo <xiongluo@huawei.com> Change-Id: Id3eceac5f2b6a515ee946b8d9d806a04326863a6
This commit is contained in:
parent
f14ab3c325
commit
a07240968b
1
BUILD.gn
1
BUILD.gn
@ -604,6 +604,7 @@ ecma_source = [
|
|||||||
"ecmascript/dfx/vm_thread_control.cpp",
|
"ecmascript/dfx/vm_thread_control.cpp",
|
||||||
"ecmascript/dump.cpp",
|
"ecmascript/dump.cpp",
|
||||||
"ecmascript/ecma_context.cpp",
|
"ecmascript/ecma_context.cpp",
|
||||||
|
"ecmascript/ecma_handle_scope.cpp",
|
||||||
"ecmascript/ecma_string.cpp",
|
"ecmascript/ecma_string.cpp",
|
||||||
"ecmascript/ecma_string_table.cpp",
|
"ecmascript/ecma_string_table.cpp",
|
||||||
"ecmascript/ecma_vm.cpp",
|
"ecmascript/ecma_vm.cpp",
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "ecmascript/ecma_context.h"
|
#include "ecmascript/ecma_context.h"
|
||||||
|
|
||||||
|
#include "ecmascript/base/path_helper.h"
|
||||||
#include "ecmascript/builtins/builtins.h"
|
#include "ecmascript/builtins/builtins.h"
|
||||||
#include "ecmascript/builtins/builtins_global.h"
|
#include "ecmascript/builtins/builtins_global.h"
|
||||||
#include "ecmascript/compiler/common_stubs.h"
|
#include "ecmascript/compiler/common_stubs.h"
|
||||||
@ -29,10 +30,16 @@
|
|||||||
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
||||||
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
|
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
|
||||||
#include "ecmascript/jspandafile/program_object.h"
|
#include "ecmascript/jspandafile/program_object.h"
|
||||||
|
#include "ecmascript/js_function.h"
|
||||||
#include "ecmascript/js_thread.h"
|
#include "ecmascript/js_thread.h"
|
||||||
#include "ecmascript/object_factory.h"
|
#include "ecmascript/object_factory.h"
|
||||||
|
#include "ecmascript/require/js_cjs_module_cache.h"
|
||||||
|
#include "ecmascript/require/js_require_manager.h"
|
||||||
#include "ecmascript/snapshot/mem/snapshot.h"
|
#include "ecmascript/snapshot/mem/snapshot.h"
|
||||||
|
|
||||||
namespace panda::ecmascript {
|
namespace panda::ecmascript {
|
||||||
|
using PathHelper = base::PathHelper;
|
||||||
|
|
||||||
EcmaContext::EcmaContext(JSThread *thread)
|
EcmaContext::EcmaContext(JSThread *thread)
|
||||||
: thread_(thread),
|
: thread_(thread),
|
||||||
vm_(thread->GetEcmaVM()),
|
vm_(thread->GetEcmaVM()),
|
||||||
@ -71,6 +78,7 @@ bool EcmaContext::Initialize()
|
|||||||
LOG_ECMA(INFO) << "EcmaContext::Initialize";
|
LOG_ECMA(INFO) << "EcmaContext::Initialize";
|
||||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "EcmaContext::Initialize");
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "EcmaContext::Initialize");
|
||||||
[[maybe_unused]] EcmaHandleScope scope(thread_);
|
[[maybe_unused]] EcmaHandleScope scope(thread_);
|
||||||
|
propertiesCache_ = new PropertiesCache();
|
||||||
regExpParserCache_ = new RegExpParserCache();
|
regExpParserCache_ = new RegExpParserCache();
|
||||||
auto globalConst = const_cast<GlobalEnvConstants *>(thread_->GlobalConstants());
|
auto globalConst = const_cast<GlobalEnvConstants *>(thread_->GlobalConstants());
|
||||||
if (!vm_->GetJSOptions().EnableSnapshotDeserialize()) {
|
if (!vm_->GetJSOptions().EnableSnapshotDeserialize()) {
|
||||||
@ -167,6 +175,13 @@ EcmaContext::~EcmaContext()
|
|||||||
if (runtimeStat_ != nullptr && runtimeStat_->IsRuntimeStatEnabled()) {
|
if (runtimeStat_ != nullptr && runtimeStat_->IsRuntimeStatEnabled()) {
|
||||||
runtimeStat_->Print();
|
runtimeStat_->Print();
|
||||||
}
|
}
|
||||||
|
for (auto n : handleStorageNodes_) {
|
||||||
|
delete n;
|
||||||
|
}
|
||||||
|
handleStorageNodes_.clear();
|
||||||
|
currentHandleStorageIndex_ = -1;
|
||||||
|
handleScopeCount_ = 0;
|
||||||
|
handleScopeStorageNext_ = handleScopeStorageEnd_ = nullptr;
|
||||||
ClearBufferData();
|
ClearBufferData();
|
||||||
// clear c_address: c++ pointer delete
|
// clear c_address: c++ pointer delete
|
||||||
if (!vm_->IsBundlePack()) {
|
if (!vm_->IsBundlePack()) {
|
||||||
@ -206,16 +221,21 @@ EcmaContext::~EcmaContext()
|
|||||||
delete aotFileManager_;
|
delete aotFileManager_;
|
||||||
aotFileManager_ = nullptr;
|
aotFileManager_ = nullptr;
|
||||||
}
|
}
|
||||||
|
if (propertiesCache_ != nullptr) {
|
||||||
|
delete propertiesCache_;
|
||||||
|
propertiesCache_ = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
JSTaggedValue EcmaContext::InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
|
JSTaggedValue EcmaContext::InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
|
||||||
const JSPandaFile *jsPandaFile, std::string_view entryPoint)
|
const JSPandaFile *jsPandaFile, std::string_view entryPoint,
|
||||||
|
CJSInfo* cjsInfo)
|
||||||
{
|
{
|
||||||
aotFileManager_->SetAOTMainFuncEntry(mainFunc, jsPandaFile, entryPoint);
|
aotFileManager_->SetAOTMainFuncEntry(mainFunc, jsPandaFile, entryPoint);
|
||||||
return JSFunction::InvokeOptimizedEntrypoint(thread_, mainFunc, thisArg, entryPoint);
|
return JSFunction::InvokeOptimizedEntrypoint(thread_, mainFunc, thisArg, entryPoint, cjsInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSTaggedValue EcmaContext::ExecuteAot(size_t actualNumArgs, JSTaggedType *args, const JSTaggedType *prevFp,
|
JSTaggedValue EcmaContext::ExecuteAot(size_t actualNumArgs, JSTaggedType *args,
|
||||||
OptimizedEntryFrame::CallType callType)
|
const JSTaggedType *prevFp, bool needPushUndefined)
|
||||||
{
|
{
|
||||||
INTERPRETER_TRACE(thread_, ExecuteAot);
|
INTERPRETER_TRACE(thread_, ExecuteAot);
|
||||||
auto entry = thread_->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry);
|
auto entry = thread_->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry);
|
||||||
@ -238,7 +258,8 @@ Expected<JSTaggedValue, bool> EcmaContext::InvokeEcmaEntrypoint(const JSPandaFil
|
|||||||
return Unexpected(false);
|
return Unexpected(false);
|
||||||
}
|
}
|
||||||
// for debugger
|
// for debugger
|
||||||
debuggerManager_->GetNotificationManager()->LoadModuleEvent(jsPandaFile->GetJSPandaFileDesc(), entryPoint);
|
vm_->GetJsDebuggerManager()->GetNotificationManager()->LoadModuleEvent(
|
||||||
|
jsPandaFile->GetJSPandaFileDesc(), entryPoint);
|
||||||
|
|
||||||
JSHandle<JSFunction> func(thread_, program->GetMainFunction());
|
JSHandle<JSFunction> func(thread_, program->GetMainFunction());
|
||||||
JSHandle<JSTaggedValue> global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject();
|
JSHandle<JSTaggedValue> global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject();
|
||||||
@ -262,16 +283,16 @@ Expected<JSTaggedValue, bool> EcmaContext::InvokeEcmaEntrypoint(const JSPandaFil
|
|||||||
JSTaggedValue result;
|
JSTaggedValue result;
|
||||||
if (jsPandaFile->IsCjs(thread_, entryPoint.data())) {
|
if (jsPandaFile->IsCjs(thread_, entryPoint.data())) {
|
||||||
if (!thread_->HasPendingException()) {
|
if (!thread_->HasPendingException()) {
|
||||||
vm_->CJSExecution(func, global, jsPandaFile, entryPoint);
|
CJSExecution(func, global, jsPandaFile, entryPoint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (aotFileManager_->IsLoadMain(jsPandaFile, entryPoint.data())) {
|
if (aotFileManager_->IsLoadMain(jsPandaFile, entryPoint.data())) {
|
||||||
EcmaRuntimeStatScope runtimeStatScope(this);
|
EcmaRuntimeStatScope runtimeStatScope(vm_);
|
||||||
result = InvokeEcmaAotEntrypoint(func, global, jsPandaFile, entryPoint);
|
result = InvokeEcmaAotEntrypoint(func, global, jsPandaFile, entryPoint);
|
||||||
} else {
|
} else {
|
||||||
EcmaRuntimeCallInfo *info =
|
EcmaRuntimeCallInfo *info =
|
||||||
EcmaInterpreter::NewRuntimeCallInfo(thread_, JSHandle<JSTaggedValue>(func), global, undefined, 0);
|
EcmaInterpreter::NewRuntimeCallInfo(thread_, JSHandle<JSTaggedValue>(func), global, undefined, 0);
|
||||||
EcmaRuntimeStatScope runtimeStatScope(this);
|
EcmaRuntimeStatScope runtimeStatScope(vm_);
|
||||||
EcmaInterpreter::Execute(info);
|
EcmaInterpreter::Execute(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,6 +307,57 @@ Expected<JSTaggedValue, bool> EcmaContext::InvokeEcmaEntrypoint(const JSPandaFil
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EcmaContext::CJSExecution(JSHandle<JSFunction> &func, JSHandle<JSTaggedValue> &thisArg,
|
||||||
|
const JSPandaFile *jsPandaFile, std::string_view entryPoint)
|
||||||
|
{
|
||||||
|
// create "module", "exports", "require", "filename", "dirname"
|
||||||
|
JSHandle<CjsModule> module = factory_->NewCjsModule();
|
||||||
|
JSHandle<JSTaggedValue> require = GetGlobalEnv()->GetCjsRequireFunction();
|
||||||
|
JSHandle<CjsExports> exports = factory_->NewCjsExports();
|
||||||
|
JSMutableHandle<JSTaggedValue> filename(thread_, JSTaggedValue::Undefined());
|
||||||
|
JSMutableHandle<JSTaggedValue> dirname(thread_, JSTaggedValue::Undefined());
|
||||||
|
if (jsPandaFile->IsBundlePack()) {
|
||||||
|
PathHelper::ResolveCurrentPath(thread_, dirname, filename, jsPandaFile);
|
||||||
|
} else {
|
||||||
|
filename.Update(func->GetModule());
|
||||||
|
ASSERT(filename->IsString());
|
||||||
|
dirname.Update(PathHelper::ResolveDirPath(thread_, filename));
|
||||||
|
}
|
||||||
|
CJSInfo cjsInfo(module, require, exports, filename, dirname);
|
||||||
|
RequireManager::InitializeCommonJS(thread_, cjsInfo);
|
||||||
|
if (aotFileManager_->IsLoadMain(jsPandaFile, entryPoint.data())) {
|
||||||
|
EcmaRuntimeStatScope runtimeStateScope(vm_);
|
||||||
|
InvokeEcmaAotEntrypoint(func, thisArg, jsPandaFile, entryPoint, &cjsInfo);
|
||||||
|
} else {
|
||||||
|
// Execute main function
|
||||||
|
JSHandle<JSTaggedValue> undefined = thread_->GlobalConstants()->GetHandledUndefined();
|
||||||
|
EcmaRuntimeCallInfo *info =
|
||||||
|
EcmaInterpreter::NewRuntimeCallInfo(thread_,
|
||||||
|
JSHandle<JSTaggedValue>(func),
|
||||||
|
thisArg, undefined, 5); // 5 : argument numbers
|
||||||
|
RETURN_IF_ABRUPT_COMPLETION(thread_);
|
||||||
|
if (info == nullptr) {
|
||||||
|
LOG_ECMA(ERROR) << "CJSExecution Stack overflow!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
info->SetCallArg(cjsInfo.exportsHdl.GetTaggedValue(),
|
||||||
|
cjsInfo.requireHdl.GetTaggedValue(),
|
||||||
|
cjsInfo.moduleHdl.GetTaggedValue(),
|
||||||
|
cjsInfo.filenameHdl.GetTaggedValue(),
|
||||||
|
cjsInfo.dirnameHdl.GetTaggedValue());
|
||||||
|
EcmaRuntimeStatScope runtimeStatScope(this);
|
||||||
|
EcmaInterpreter::Execute(info);
|
||||||
|
}
|
||||||
|
if (!thread_->HasPendingException()) {
|
||||||
|
job::MicroJobQueue::ExecutePendingJob(thread_, thread_->GetCurrentEcmaContext()->GetMicroJobQueue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!thread_->HasPendingException()) {
|
||||||
|
// Collecting module.exports : exports ---> module.exports --->Module._cache
|
||||||
|
RequireManager::CollectExecutedExp(thread_, cjsInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool EcmaContext::HasCachedConstpool(const JSPandaFile *jsPandaFile) const
|
bool EcmaContext::HasCachedConstpool(const JSPandaFile *jsPandaFile) const
|
||||||
{
|
{
|
||||||
return cachedConstpools_.find(jsPandaFile) != cachedConstpools_.end();
|
return cachedConstpools_.find(jsPandaFile) != cachedConstpools_.end();
|
||||||
@ -534,20 +606,101 @@ void EcmaContext::UnmountContext(JSThread *thread)
|
|||||||
Destroy(context);
|
Destroy(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EcmaContext::SetupRegExpResultCache()
|
||||||
void EcmaContext::Iterate(const RootVisitor &v, [[maybe_unused]] const RootRangeVisitor &rv)
|
|
||||||
{
|
{
|
||||||
|
regexpCache_ = builtins::RegExpExecResultCache::CreateCacheTable(thread_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EcmaContext::Iterate(const RootVisitor &v, const RootRangeVisitor &rv)
|
||||||
|
{
|
||||||
|
if (propertiesCache_ != nullptr) {
|
||||||
|
propertiesCache_->Clear();
|
||||||
|
}
|
||||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(®expCache_)));
|
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(®expCache_)));
|
||||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&globalEnv_)));
|
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>(µJobQueue_)));
|
||||||
moduleManager_->Iterate(v);
|
moduleManager_->Iterate(v);
|
||||||
tsManager_->Iterate(v);
|
tsManager_->Iterate(v);
|
||||||
aotFileManager_->Iterate(v);
|
aotFileManager_->Iterate(v);
|
||||||
|
if (vm_->GetJSOptions().EnableGlobalLeakCheck()) {
|
||||||
|
IterateHandle(rv);
|
||||||
|
} else {
|
||||||
|
if (currentHandleStorageIndex_ != -1) {
|
||||||
|
int32_t nid = currentHandleStorageIndex_;
|
||||||
|
for (int32_t i = 0; i <= nid; ++i) {
|
||||||
|
auto node = handleStorageNodes_.at(i);
|
||||||
|
auto start = node->data();
|
||||||
|
auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handleScopeStorageNext_;
|
||||||
|
rv(ecmascript::Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EcmaContext::SetupRegExpResultCache()
|
size_t EcmaContext::IterateHandle(const RootRangeVisitor &rangeVisitor)
|
||||||
{
|
{
|
||||||
regexpCache_ = builtins::RegExpExecResultCache::CreateCacheTable(thread_);
|
size_t handleCount = 0;
|
||||||
|
if (currentHandleStorageIndex_ != -1) {
|
||||||
|
int32_t nid = currentHandleStorageIndex_;
|
||||||
|
for (int32_t i = 0; i <= nid; ++i) {
|
||||||
|
auto node = handleStorageNodes_.at(i);
|
||||||
|
auto start = node->data();
|
||||||
|
auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handleScopeStorageNext_;
|
||||||
|
rangeVisitor(ecmascript::Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end)));
|
||||||
|
handleCount += (ToUintPtr(end) - ToUintPtr(start)) / sizeof(JSTaggedType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return handleCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t *EcmaContext::ExpandHandleStorage()
|
||||||
|
{
|
||||||
|
uintptr_t *result = nullptr;
|
||||||
|
int32_t lastIndex = static_cast<int32_t>(handleStorageNodes_.size() - 1);
|
||||||
|
if (currentHandleStorageIndex_ == lastIndex) {
|
||||||
|
auto n = new std::array<JSTaggedType, NODE_BLOCK_SIZE>();
|
||||||
|
handleStorageNodes_.push_back(n);
|
||||||
|
currentHandleStorageIndex_++;
|
||||||
|
result = reinterpret_cast<uintptr_t *>(&n->data()[0]);
|
||||||
|
handleScopeStorageEnd_ = &n->data()[NODE_BLOCK_SIZE];
|
||||||
|
} else {
|
||||||
|
currentHandleStorageIndex_++;
|
||||||
|
auto lastNode = handleStorageNodes_[currentHandleStorageIndex_];
|
||||||
|
result = reinterpret_cast<uintptr_t *>(&lastNode->data()[0]);
|
||||||
|
handleScopeStorageEnd_ = &lastNode->data()[NODE_BLOCK_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EcmaContext::ShrinkHandleStorage(int prevIndex)
|
||||||
|
{
|
||||||
|
currentHandleStorageIndex_ = prevIndex;
|
||||||
|
int32_t lastIndex = static_cast<int32_t>(handleStorageNodes_.size() - 1);
|
||||||
|
#if ECMASCRIPT_ENABLE_ZAP_MEM
|
||||||
|
uintptr_t size = ToUintPtr(handleScopeStorageEnd_) - ToUintPtr(handleScopeStorageNext_);
|
||||||
|
if (memset_s(handleScopeStorageNext_, size, 0, size) != EOK) {
|
||||||
|
LOG_FULL(FATAL) << "memset_s failed";
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
for (int32_t i = currentHandleStorageIndex_ + 1; i < lastIndex; i++) {
|
||||||
|
if (memset_s(handleStorageNodes_[i],
|
||||||
|
NODE_BLOCK_SIZE * sizeof(JSTaggedType), 0,
|
||||||
|
NODE_BLOCK_SIZE * sizeof(JSTaggedType)) !=
|
||||||
|
EOK) {
|
||||||
|
LOG_FULL(FATAL) << "memset_s failed";
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (lastIndex > MIN_HANDLE_STORAGE_SIZE && currentHandleStorageIndex_ < MIN_HANDLE_STORAGE_SIZE) {
|
||||||
|
for (int i = MIN_HANDLE_STORAGE_SIZE; i < lastIndex; i++) {
|
||||||
|
auto node = handleStorageNodes_.back();
|
||||||
|
delete node;
|
||||||
|
handleStorageNodes_.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void EcmaContext::LoadStubFile()
|
void EcmaContext::LoadStubFile()
|
||||||
{
|
{
|
||||||
@ -577,4 +730,5 @@ void EcmaContext::DumpAOTInfo() const
|
|||||||
{
|
{
|
||||||
aotFileManager_->DumpAOTInfo();
|
aotFileManager_->DumpAOTInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace panda::ecmascript
|
} // namespace panda::ecmascript
|
||||||
|
@ -60,6 +60,7 @@ class TSManager;
|
|||||||
class AOTFileManager;
|
class AOTFileManager;
|
||||||
class QuickFixManager;
|
class QuickFixManager;
|
||||||
class OptCodeProfiler;
|
class OptCodeProfiler;
|
||||||
|
struct CJSInfo;
|
||||||
|
|
||||||
namespace job {
|
namespace job {
|
||||||
class MicroJobQueue;
|
class MicroJobQueue;
|
||||||
@ -92,15 +93,6 @@ public:
|
|||||||
EcmaContext(JSThread *thread);
|
EcmaContext(JSThread *thread);
|
||||||
~EcmaContext();
|
~EcmaContext();
|
||||||
|
|
||||||
void SetLoop(void *loop)
|
|
||||||
{
|
|
||||||
loop_ = loop;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *GetLoop() const
|
|
||||||
{
|
|
||||||
return loop_;
|
|
||||||
}
|
|
||||||
EcmaVM *GetEcmaVM() const
|
EcmaVM *GetEcmaVM() const
|
||||||
{
|
{
|
||||||
return vm_;
|
return vm_;
|
||||||
@ -274,13 +266,91 @@ public:
|
|||||||
void InitializeEcmaScriptRunStat();
|
void InitializeEcmaScriptRunStat();
|
||||||
void DumpAOTInfo() const DUMP_API_ATTR;
|
void DumpAOTInfo() const DUMP_API_ATTR;
|
||||||
|
|
||||||
JSTaggedValue ExecuteAot(size_t actualNumArgs, JSTaggedType *args, const JSTaggedType *prevFp,
|
JSTaggedValue ExecuteAot(size_t actualNumArgs, JSTaggedType *args,
|
||||||
OptimizedEntryFrame::CallType callType);
|
const JSTaggedType *prevFp, bool needPushUndefined);
|
||||||
void LoadStubFile();
|
void LoadStubFile();
|
||||||
|
|
||||||
|
JSTaggedType *GetHandleScopeStorageNext() const
|
||||||
|
{
|
||||||
|
return handleScopeStorageNext_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetHandleScopeStorageNext(JSTaggedType *value)
|
||||||
|
{
|
||||||
|
handleScopeStorageNext_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSTaggedType *GetHandleScopeStorageEnd() const
|
||||||
|
{
|
||||||
|
return handleScopeStorageEnd_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetHandleScopeStorageEnd(JSTaggedType *value)
|
||||||
|
{
|
||||||
|
handleScopeStorageEnd_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetCurrentHandleStorageIndex() const
|
||||||
|
{
|
||||||
|
return currentHandleStorageIndex_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleScopeCountAdd()
|
||||||
|
{
|
||||||
|
handleScopeCount_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleScopeCountDec()
|
||||||
|
{
|
||||||
|
handleScopeCount_--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetLastHandleScope(EcmaHandleScope *scope)
|
||||||
|
{
|
||||||
|
lastHandleScope_ = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
EcmaHandleScope *GetLastHandleScope() const
|
||||||
|
{
|
||||||
|
return lastHandleScope_;
|
||||||
|
}
|
||||||
|
size_t IterateHandle(const RootRangeVisitor &rangeVisitor);
|
||||||
|
uintptr_t *ExpandHandleStorage();
|
||||||
|
void ShrinkHandleStorage(int prevIndex);
|
||||||
|
JSTaggedType *GetCurrentFrame() const
|
||||||
|
{
|
||||||
|
return currentFrame_;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSTaggedType *GetLeaveFrame() const
|
||||||
|
{
|
||||||
|
return leaveFrame_;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSTaggedType *GetLastFp() const
|
||||||
|
{
|
||||||
|
return lastFp_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetFramePointers(JSTaggedType *currentFrame, JSTaggedType *leaveFrame, JSTaggedType *lastFp)
|
||||||
|
{
|
||||||
|
currentFrame_ = currentFrame;
|
||||||
|
leaveFrame_ = leaveFrame;
|
||||||
|
lastFp_ = lastFp;
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertiesCache *GetPropertiesCache() const
|
||||||
|
{
|
||||||
|
return propertiesCache_;
|
||||||
|
}
|
||||||
void ClearBufferData();
|
void ClearBufferData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CJSExecution(JSHandle<JSFunction> &func, JSHandle<JSTaggedValue> &thisArg,
|
||||||
|
const JSPandaFile *jsPandaFile, std::string_view entryPoint);
|
||||||
JSTaggedValue InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
|
JSTaggedValue InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
|
||||||
const JSPandaFile *jsPandaFile, std::string_view entryPoint);
|
const JSPandaFile *jsPandaFile, std::string_view entryPoint,
|
||||||
|
CJSInfo* cjsInfo = nullptr);
|
||||||
Expected<JSTaggedValue, bool> InvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile, std::string_view entryPoint,
|
Expected<JSTaggedValue, bool> InvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile, std::string_view entryPoint,
|
||||||
bool excuteFromJob = false);
|
bool excuteFromJob = false);
|
||||||
bool LoadAOTFiles(const std::string& aotFileName);
|
bool LoadAOTFiles(const std::string& aotFileName);
|
||||||
@ -333,7 +403,6 @@ private:
|
|||||||
: locale(locale), icuObj(icuObj), deleteEntry(deleteEntry) {}
|
: locale(locale), icuObj(icuObj), deleteEntry(deleteEntry) {}
|
||||||
};
|
};
|
||||||
std::unordered_map<IcuFormatterType, IcuFormatter> icuObjCache_;
|
std::unordered_map<IcuFormatterType, IcuFormatter> icuObjCache_;
|
||||||
void *loop_ {nullptr};
|
|
||||||
|
|
||||||
static const uint32_t NODE_BLOCK_SIZE_LOG2 = 10;
|
static const uint32_t NODE_BLOCK_SIZE_LOG2 = 10;
|
||||||
static const uint32_t NODE_BLOCK_SIZE = 1U << NODE_BLOCK_SIZE_LOG2;
|
static const uint32_t NODE_BLOCK_SIZE = 1U << NODE_BLOCK_SIZE_LOG2;
|
||||||
|
87
ecmascript/ecma_handle_scope.cpp
Normal file
87
ecmascript/ecma_handle_scope.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ECMASCRIPT_HANDLE_SCOPE_INL_H
|
||||||
|
#define ECMASCRIPT_HANDLE_SCOPE_INL_H
|
||||||
|
|
||||||
|
#include "ecmascript/ecma_handle_scope.h"
|
||||||
|
|
||||||
|
#include "ecmascript/ecma_context.h"
|
||||||
|
|
||||||
|
namespace panda::ecmascript {
|
||||||
|
EcmaHandleScope::EcmaHandleScope(JSThread *thread) :
|
||||||
|
thread_(thread)
|
||||||
|
{
|
||||||
|
auto context = thread_->GetCurrentEcmaContext();
|
||||||
|
prevNext_ = context->handleScopeStorageNext_;
|
||||||
|
prevEnd_ = context->handleScopeStorageEnd_;
|
||||||
|
prevHandleStorageIndex_ = context->currentHandleStorageIndex_;
|
||||||
|
#ifdef ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK
|
||||||
|
thread_->HandleScopeCountAdd();
|
||||||
|
prevHandleScope_ = thread->GetLastHandleScope();
|
||||||
|
thread_->SetLastHandleScope(this);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
EcmaHandleScope::~EcmaHandleScope()
|
||||||
|
{
|
||||||
|
auto context = thread_->GetCurrentEcmaContext();
|
||||||
|
#ifdef ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK
|
||||||
|
context->HandleScopeCountDec();
|
||||||
|
context->SetLastHandleScope(prevHandleScope_);
|
||||||
|
prevHandleScope_ = nullptr;
|
||||||
|
#endif
|
||||||
|
context->handleScopeStorageNext_ = prevNext_;
|
||||||
|
if (context->handleScopeStorageEnd_ != prevEnd_) {
|
||||||
|
context->handleScopeStorageEnd_ = prevEnd_;
|
||||||
|
context->ShrinkHandleStorage(prevHandleStorageIndex_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
uintptr_t EcmaHandleScope::NewHandle(JSThread *thread, JSTaggedType value)
|
||||||
|
{
|
||||||
|
auto context = thread->GetCurrentEcmaContext();
|
||||||
|
#ifdef ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK
|
||||||
|
// Each Handle must be managed by HandleScope, otherwise it may cause Handle leakage.
|
||||||
|
if (context->handleScopeCount_ <= 0) {
|
||||||
|
LOG_ECMA(ERROR) << "New handle must be in handlescope" << context->handleScopeCount_;
|
||||||
|
}
|
||||||
|
static const long MAYBE_HANDLE_LEAK_TIME_MS = 5000;
|
||||||
|
if (context->GetLastHandleScope() != nullptr) {
|
||||||
|
float totalSpentTime = context->GetLastHandleScope()->scope_.TotalSpentTime();
|
||||||
|
if (totalSpentTime >= MAYBE_HANDLE_LEAK_TIME_MS) {
|
||||||
|
LOG_ECMA(INFO) << "New handle in scope count:" << context->handleScopeCount_
|
||||||
|
<< ", time:" << totalSpentTime << "ms";
|
||||||
|
std::ostringstream stack;
|
||||||
|
Backtrace(stack, true);
|
||||||
|
LOG_ECMA(INFO) << stack.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if ECMASCRIPT_ENABLE_NEW_HANDLE_CHECK
|
||||||
|
thread->CheckJSTaggedType(value);
|
||||||
|
#endif
|
||||||
|
auto result = context->handleScopeStorageNext_;
|
||||||
|
if (result == context->handleScopeStorageEnd_) {
|
||||||
|
result = reinterpret_cast<JSTaggedType *>(context->ExpandHandleStorage());
|
||||||
|
}
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
|
context->handleScopeStorageNext_ = result + 1;
|
||||||
|
*result = value;
|
||||||
|
return reinterpret_cast<uintptr_t>(result);
|
||||||
|
}
|
||||||
|
} // namespace panda::ecmascript
|
||||||
|
#endif
|
@ -29,64 +29,13 @@ namespace panda::ecmascript {
|
|||||||
* Handles are only valid within a HandleScope. When a handle is created for an object a cell is allocated in the
|
* Handles are only valid within a HandleScope. When a handle is created for an object a cell is allocated in the
|
||||||
* current HandleScope.
|
* current HandleScope.
|
||||||
*/
|
*/
|
||||||
|
class JSThread;
|
||||||
class EcmaHandleScope {
|
class EcmaHandleScope {
|
||||||
public:
|
public:
|
||||||
inline explicit EcmaHandleScope(JSThread *thread) :
|
explicit EcmaHandleScope(JSThread *thread);
|
||||||
thread_(thread), prevNext_(thread->handleScopeStorageNext_), prevEnd_(thread->handleScopeStorageEnd_),
|
|
||||||
prevHandleStorageIndex_(thread->currentHandleStorageIndex_)
|
|
||||||
{
|
|
||||||
#ifdef ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK
|
|
||||||
thread_->HandleScopeCountAdd();
|
|
||||||
prevHandleScope_ = thread->GetLastHandleScope();
|
|
||||||
thread_->SetLastHandleScope(this);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ~EcmaHandleScope()
|
~EcmaHandleScope();
|
||||||
{
|
static uintptr_t PUBLIC_API NewHandle(JSThread *thread, JSTaggedType value);
|
||||||
#ifdef ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK
|
|
||||||
thread_->HandleScopeCountDec();
|
|
||||||
thread_->SetLastHandleScope(prevHandleScope_);
|
|
||||||
prevHandleScope_ = nullptr;
|
|
||||||
#endif
|
|
||||||
thread_->handleScopeStorageNext_ = prevNext_;
|
|
||||||
if (thread_->handleScopeStorageEnd_ != prevEnd_) {
|
|
||||||
thread_->handleScopeStorageEnd_ = prevEnd_;
|
|
||||||
thread_->ShrinkHandleStorage(prevHandleStorageIndex_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uintptr_t PUBLIC_API NewHandle(JSThread *thread, JSTaggedType value)
|
|
||||||
{
|
|
||||||
#ifdef ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK
|
|
||||||
// Each Handle must be managed by HandleScope, otherwise it may cause Handle leakage.
|
|
||||||
if (thread->handleScopeCount_ <= 0) {
|
|
||||||
LOG_ECMA(ERROR) << "New handle must be in handlescope" << thread->handleScopeCount_;
|
|
||||||
}
|
|
||||||
static const long MAYBE_HANDLE_LEAK_TIME_MS = 5000;
|
|
||||||
if (thread->GetLastHandleScope() != nullptr) {
|
|
||||||
float totalSpentTime = thread->GetLastHandleScope()->scope_.TotalSpentTime();
|
|
||||||
if (totalSpentTime >= MAYBE_HANDLE_LEAK_TIME_MS) {
|
|
||||||
LOG_ECMA(INFO) << "New handle in scope count:" << thread->handleScopeCount_
|
|
||||||
<< ", time:" << totalSpentTime << "ms";
|
|
||||||
std::ostringstream stack;
|
|
||||||
Backtrace(stack, true);
|
|
||||||
LOG_ECMA(INFO) << stack.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if ECMASCRIPT_ENABLE_NEW_HANDLE_CHECK
|
|
||||||
thread->CheckJSTaggedType(value);
|
|
||||||
#endif
|
|
||||||
auto result = thread->handleScopeStorageNext_;
|
|
||||||
if (result == thread->handleScopeStorageEnd_) {
|
|
||||||
result = reinterpret_cast<JSTaggedType *>(thread->ExpandHandleStorage());
|
|
||||||
}
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
||||||
thread->handleScopeStorageNext_ = result + 1;
|
|
||||||
*result = value;
|
|
||||||
return reinterpret_cast<uintptr_t>(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSThread *GetThread() const
|
JSThread *GetThread() const
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include "ecmascript/ecma_vm.h"
|
#include "ecmascript/ecma_vm.h"
|
||||||
|
|
||||||
#include "ecmascript/base/path_helper.h"
|
|
||||||
#include "ecmascript/base/string_helper.h"
|
#include "ecmascript/base/string_helper.h"
|
||||||
#include "ecmascript/builtins/builtins.h"
|
#include "ecmascript/builtins/builtins.h"
|
||||||
#include "ecmascript/builtins/builtins_ark_tools.h"
|
#include "ecmascript/builtins/builtins_ark_tools.h"
|
||||||
@ -78,8 +77,6 @@
|
|||||||
#include "ecmascript/patch/quick_fix_manager.h"
|
#include "ecmascript/patch/quick_fix_manager.h"
|
||||||
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
|
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
|
||||||
#include "ecmascript/regexp/regexp_parser_cache.h"
|
#include "ecmascript/regexp/regexp_parser_cache.h"
|
||||||
#include "ecmascript/require/js_cjs_module_cache.h"
|
|
||||||
#include "ecmascript/require/js_require_manager.h"
|
|
||||||
#include "ecmascript/runtime_call_id.h"
|
#include "ecmascript/runtime_call_id.h"
|
||||||
#include "ecmascript/snapshot/mem/snapshot.h"
|
#include "ecmascript/snapshot/mem/snapshot.h"
|
||||||
#include "ecmascript/snapshot/mem/snapshot_env.h"
|
#include "ecmascript/snapshot/mem/snapshot_env.h"
|
||||||
@ -93,7 +90,6 @@
|
|||||||
#include "ecmascript/ts_types/ts_manager.h"
|
#include "ecmascript/ts_types/ts_manager.h"
|
||||||
|
|
||||||
namespace panda::ecmascript {
|
namespace panda::ecmascript {
|
||||||
using PathHelper = base::PathHelper;
|
|
||||||
using RandomGenerator = base::RandomGenerator;
|
using RandomGenerator = base::RandomGenerator;
|
||||||
AOTFileManager *JsStackInfo::loader = nullptr;
|
AOTFileManager *JsStackInfo::loader = nullptr;
|
||||||
/* static */
|
/* static */
|
||||||
@ -242,13 +238,10 @@ EcmaVM::~EcmaVM()
|
|||||||
pgoProfiler_ = nullptr;
|
pgoProfiler_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runtimeStat_ != nullptr && runtimeStat_->IsRuntimeStatEnabled()) {
|
|
||||||
runtimeStat_->Print();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
|
#if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER
|
||||||
DumpCallTimeInfo();
|
DumpCallTimeInfo();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// clear c_address: c++ pointer delete
|
// clear c_address: c++ pointer delete
|
||||||
ClearBufferData();
|
ClearBufferData();
|
||||||
if (!isBundlePack_) {
|
if (!isBundlePack_) {
|
||||||
@ -336,57 +329,6 @@ void EcmaVM::CheckStartCpuProfiler()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void EcmaVM::CJSExecution(JSHandle<JSFunction> &func, JSHandle<JSTaggedValue> &thisArg,
|
|
||||||
const JSPandaFile *jsPandaFile, std::string_view entryPoint)
|
|
||||||
{
|
|
||||||
// create "module", "exports", "require", "filename", "dirname"
|
|
||||||
JSHandle<CjsModule> module = factory_->NewCjsModule();
|
|
||||||
JSHandle<JSTaggedValue> require = GetGlobalEnv()->GetCjsRequireFunction();
|
|
||||||
JSHandle<CjsExports> exports = factory_->NewCjsExports();
|
|
||||||
JSMutableHandle<JSTaggedValue> filename(thread_, JSTaggedValue::Undefined());
|
|
||||||
JSMutableHandle<JSTaggedValue> dirname(thread_, JSTaggedValue::Undefined());
|
|
||||||
if (jsPandaFile->IsBundlePack()) {
|
|
||||||
PathHelper::ResolveCurrentPath(thread_, dirname, filename, jsPandaFile);
|
|
||||||
} else {
|
|
||||||
filename.Update(func->GetModule());
|
|
||||||
ASSERT(filename->IsString());
|
|
||||||
dirname.Update(PathHelper::ResolveDirPath(thread_, filename));
|
|
||||||
}
|
|
||||||
CJSInfo cjsInfo(module, require, exports, filename, dirname);
|
|
||||||
RequireManager::InitializeCommonJS(thread_, cjsInfo);
|
|
||||||
if (aotFileManager_->IsLoadMain(jsPandaFile, entryPoint.data())) {
|
|
||||||
EcmaRuntimeStatScope runtimeStateScope(this);
|
|
||||||
InvokeEcmaAotEntrypoint(func, thisArg, jsPandaFile, entryPoint, &cjsInfo);
|
|
||||||
} else {
|
|
||||||
// Execute main function
|
|
||||||
JSHandle<JSTaggedValue> undefined = thread_->GlobalConstants()->GetHandledUndefined();
|
|
||||||
EcmaRuntimeCallInfo *info =
|
|
||||||
EcmaInterpreter::NewRuntimeCallInfo(thread_,
|
|
||||||
JSHandle<JSTaggedValue>(func),
|
|
||||||
thisArg, undefined, 5); // 5 : argument numbers
|
|
||||||
RETURN_IF_ABRUPT_COMPLETION(thread_);
|
|
||||||
if (info == nullptr) {
|
|
||||||
LOG_ECMA(ERROR) << "CJSExecution Stack overflow!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
info->SetCallArg(cjsInfo.exportsHdl.GetTaggedValue(),
|
|
||||||
cjsInfo.requireHdl.GetTaggedValue(),
|
|
||||||
cjsInfo.moduleHdl.GetTaggedValue(),
|
|
||||||
cjsInfo.filenameHdl.GetTaggedValue(),
|
|
||||||
cjsInfo.dirnameHdl.GetTaggedValue());
|
|
||||||
EcmaRuntimeStatScope runtimeStatScope(this);
|
|
||||||
EcmaInterpreter::Execute(info);
|
|
||||||
}
|
|
||||||
if (!thread_->HasPendingException()) {
|
|
||||||
job::MicroJobQueue::ExecutePendingJob(thread_, thread_->GetCurrentEcmaContext()->GetMicroJobQueue());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!thread_->HasPendingException()) {
|
|
||||||
// Collecting module.exports : exports ---> module.exports --->Module._cache
|
|
||||||
RequireManager::CollectExecutedExp(thread_, cjsInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JSHandle<JSTaggedValue> EcmaVM::GetAndClearEcmaUncaughtException() const
|
JSHandle<JSTaggedValue> EcmaVM::GetAndClearEcmaUncaughtException() const
|
||||||
{
|
{
|
||||||
JSHandle<JSTaggedValue> exceptionHandle = GetEcmaUncaughtException();
|
JSHandle<JSTaggedValue> exceptionHandle = GetEcmaUncaughtException();
|
||||||
@ -510,9 +452,6 @@ void EcmaVM::Iterate(const RootVisitor &v, const RootRangeVisitor &rv)
|
|||||||
if (pgoProfiler_ != nullptr) {
|
if (pgoProfiler_ != nullptr) {
|
||||||
pgoProfiler_->Iterate(v);
|
pgoProfiler_->Iterate(v);
|
||||||
}
|
}
|
||||||
for (EcmaContext *context : contexts_) {
|
|
||||||
context->Iterate(v, rv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ECMASCRIPT_SUPPORT_HEAPPROFILER)
|
#if defined(ECMASCRIPT_SUPPORT_HEAPPROFILER)
|
||||||
|
@ -75,13 +75,8 @@ class JSFunction;
|
|||||||
class Program;
|
class Program;
|
||||||
class TSManager;
|
class TSManager;
|
||||||
class AOTFileManager;
|
class AOTFileManager;
|
||||||
class CjsModule;
|
|
||||||
class CjsExports;
|
|
||||||
class CjsRequire;
|
|
||||||
class CjsModuleCache;
|
|
||||||
class SlowRuntimeStub;
|
class SlowRuntimeStub;
|
||||||
class RequireManager;
|
class RequireManager;
|
||||||
struct CJSInfo;
|
|
||||||
class QuickFixManager;
|
class QuickFixManager;
|
||||||
class ConstantPool;
|
class ConstantPool;
|
||||||
class FunctionCallTimer;
|
class FunctionCallTimer;
|
||||||
@ -103,6 +98,16 @@ public:
|
|||||||
|
|
||||||
~EcmaVM();
|
~EcmaVM();
|
||||||
|
|
||||||
|
void SetLoop(void *loop)
|
||||||
|
{
|
||||||
|
loop_ = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *GetLoop() const
|
||||||
|
{
|
||||||
|
return loop_;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsInitialized() const
|
bool IsInitialized() const
|
||||||
{
|
{
|
||||||
return initialized_;
|
return initialized_;
|
||||||
@ -402,14 +407,12 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
void SetGlobalEnv(GlobalEnv *global);
|
void SetGlobalEnv(GlobalEnv *global);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void PrintJSErrorInfo(const JSHandle<JSTaggedValue> &exceptionInfo) const;
|
void PrintJSErrorInfo(const JSHandle<JSTaggedValue> &exceptionInfo) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CJSExecution(JSHandle<JSFunction> &func, JSHandle<JSTaggedValue> &thisArg,
|
|
||||||
const JSPandaFile *jsPandaFile, std::string_view entryPoint);
|
|
||||||
|
|
||||||
void ClearBufferData();
|
void ClearBufferData();
|
||||||
void CheckStartCpuProfiler();
|
void CheckStartCpuProfiler();
|
||||||
|
|
||||||
@ -450,6 +453,7 @@ private:
|
|||||||
CString moduleName_;
|
CString moduleName_;
|
||||||
// Registered Callbacks
|
// Registered Callbacks
|
||||||
NativePtrGetter nativePtrGetter_ {nullptr};
|
NativePtrGetter nativePtrGetter_ {nullptr};
|
||||||
|
void *loop_ {nullptr};
|
||||||
|
|
||||||
// CJS resolve path Callbacks
|
// CJS resolve path Callbacks
|
||||||
ResolvePathCallback resolvePathCallback_ {nullptr};
|
ResolvePathCallback resolvePathCallback_ {nullptr};
|
||||||
|
@ -82,7 +82,7 @@ private:
|
|||||||
|
|
||||||
std::array<PropertyKey, CACHE_LENGTH> keys_{};
|
std::array<PropertyKey, CACHE_LENGTH> keys_{};
|
||||||
|
|
||||||
friend class JSThread;
|
friend class EcmaContext;
|
||||||
};
|
};
|
||||||
} // namespace panda::ecmascript
|
} // namespace panda::ecmascript
|
||||||
#endif // ECMASCRIPT_IC_PROPERTIES_CACHE_H
|
#endif // ECMASCRIPT_IC_PROPERTIES_CACHE_H
|
||||||
|
@ -75,17 +75,17 @@ class NameDictionary;
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class JSHandle {
|
class JSHandle {
|
||||||
public:
|
public:
|
||||||
inline JSHandle() : address_(reinterpret_cast<uintptr_t>(nullptr)) {}
|
PUBLIC_API inline JSHandle() : address_(reinterpret_cast<uintptr_t>(nullptr)) {}
|
||||||
~JSHandle() = default;
|
~JSHandle() = default;
|
||||||
DEFAULT_NOEXCEPT_MOVE_SEMANTIC(JSHandle);
|
DEFAULT_NOEXCEPT_MOVE_SEMANTIC(JSHandle);
|
||||||
DEFAULT_COPY_SEMANTIC(JSHandle);
|
DEFAULT_COPY_SEMANTIC(JSHandle);
|
||||||
|
|
||||||
JSHandle(const JSThread *thread, JSTaggedValue value)
|
PUBLIC_API JSHandle(const JSThread *thread, JSTaggedValue value)
|
||||||
{
|
{
|
||||||
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), value.GetRawData());
|
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), value.GetRawData());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSHandle(const JSThread *thread, const TaggedObject *value)
|
PUBLIC_API JSHandle(const JSThread *thread, const TaggedObject *value)
|
||||||
{
|
{
|
||||||
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), JSTaggedValue(value).GetRawData());
|
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), JSTaggedValue(value).GetRawData());
|
||||||
}
|
}
|
||||||
|
@ -85,20 +85,12 @@ JSThread::JSThread(EcmaVM *vm) : id_(os::thread::GetCurrentThreadId()), vm_(vm)
|
|||||||
clearWeak_ = std::bind(&EcmaGlobalStorage<DebugNode>::ClearWeak, globalDebugStorage_, std::placeholders::_1);
|
clearWeak_ = std::bind(&EcmaGlobalStorage<DebugNode>::ClearWeak, globalDebugStorage_, std::placeholders::_1);
|
||||||
isWeak_ = std::bind(&EcmaGlobalStorage<DebugNode>::IsWeak, globalDebugStorage_, std::placeholders::_1);
|
isWeak_ = std::bind(&EcmaGlobalStorage<DebugNode>::IsWeak, globalDebugStorage_, std::placeholders::_1);
|
||||||
}
|
}
|
||||||
propertiesCache_ = new PropertiesCache();
|
|
||||||
vmThreadControl_ = new VmThreadControl(this);
|
vmThreadControl_ = new VmThreadControl(this);
|
||||||
SetBCStubStatus(BCStubStatus::NORMAL_BC_STUB);
|
SetBCStubStatus(BCStubStatus::NORMAL_BC_STUB);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSThread::~JSThread()
|
JSThread::~JSThread()
|
||||||
{
|
{
|
||||||
for (auto n : handleStorageNodes_) {
|
|
||||||
delete n;
|
|
||||||
}
|
|
||||||
handleStorageNodes_.clear();
|
|
||||||
currentHandleStorageIndex_ = -1;
|
|
||||||
handleScopeCount_ = 0;
|
|
||||||
handleScopeStorageNext_ = handleScopeStorageEnd_ = nullptr;
|
|
||||||
if (globalStorage_ != nullptr) {
|
if (globalStorage_ != nullptr) {
|
||||||
GetEcmaVM()->GetChunk()->Delete(globalStorage_);
|
GetEcmaVM()->GetChunk()->Delete(globalStorage_);
|
||||||
globalStorage_ = nullptr;
|
globalStorage_ = nullptr;
|
||||||
@ -113,10 +105,6 @@ JSThread::~JSThread()
|
|||||||
glueData_.frameBase_ = nullptr;
|
glueData_.frameBase_ = nullptr;
|
||||||
nativeAreaAllocator_ = nullptr;
|
nativeAreaAllocator_ = nullptr;
|
||||||
heapRegionAllocator_ = nullptr;
|
heapRegionAllocator_ = nullptr;
|
||||||
if (propertiesCache_ != nullptr) {
|
|
||||||
delete propertiesCache_;
|
|
||||||
propertiesCache_ = nullptr;
|
|
||||||
}
|
|
||||||
if (vmThreadControl_ != nullptr) {
|
if (vmThreadControl_ != nullptr) {
|
||||||
delete vmThreadControl_;
|
delete vmThreadControl_;
|
||||||
vmThreadControl_ = nullptr;
|
vmThreadControl_ = nullptr;
|
||||||
@ -219,10 +207,6 @@ void JSThread::CloseStackTraceFd()
|
|||||||
void JSThread::Iterate(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor,
|
void JSThread::Iterate(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor,
|
||||||
const RootBaseAndDerivedVisitor &derivedVisitor)
|
const RootBaseAndDerivedVisitor &derivedVisitor)
|
||||||
{
|
{
|
||||||
if (propertiesCache_ != nullptr) {
|
|
||||||
propertiesCache_->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!glueData_.exception_.IsHole()) {
|
if (!glueData_.exception_.IsHole()) {
|
||||||
visitor(Root::ROOT_VM, ObjectSlot(ToUintPtr(&glueData_.exception_)));
|
visitor(Root::ROOT_VM, ObjectSlot(ToUintPtr(&glueData_.exception_)));
|
||||||
}
|
}
|
||||||
@ -235,16 +219,6 @@ void JSThread::Iterate(const RootVisitor &visitor, const RootRangeVisitor &range
|
|||||||
if (vm_->GetJSOptions().EnableGlobalLeakCheck()) {
|
if (vm_->GetJSOptions().EnableGlobalLeakCheck()) {
|
||||||
IterateHandleWithCheck(visitor, rangeVisitor);
|
IterateHandleWithCheck(visitor, rangeVisitor);
|
||||||
} else {
|
} else {
|
||||||
if (currentHandleStorageIndex_ != -1) {
|
|
||||||
int32_t nid = currentHandleStorageIndex_;
|
|
||||||
for (int32_t i = 0; i <= nid; ++i) {
|
|
||||||
auto node = handleStorageNodes_.at(i);
|
|
||||||
auto start = node->data();
|
|
||||||
auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handleScopeStorageNext_;
|
|
||||||
rangeVisitor(ecmascript::Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
globalStorage_->IterateUsageGlobal([visitor](Node *node) {
|
globalStorage_->IterateUsageGlobal([visitor](Node *node) {
|
||||||
JSTaggedValue value(node->GetObject());
|
JSTaggedValue value(node->GetObject());
|
||||||
if (value.IsHeapObject()) {
|
if (value.IsHeapObject()) {
|
||||||
@ -261,15 +235,8 @@ void JSThread::Iterate(const RootVisitor &visitor, const RootRangeVisitor &range
|
|||||||
void JSThread::IterateHandleWithCheck(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor)
|
void JSThread::IterateHandleWithCheck(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor)
|
||||||
{
|
{
|
||||||
size_t handleCount = 0;
|
size_t handleCount = 0;
|
||||||
if (currentHandleStorageIndex_ != -1) {
|
for (EcmaContext *context : contexts_) {
|
||||||
int32_t nid = currentHandleStorageIndex_;
|
handleCount += context->IterateHandle(rangeVisitor);
|
||||||
for (int32_t i = 0; i <= nid; ++i) {
|
|
||||||
auto node = handleStorageNodes_.at(i);
|
|
||||||
auto start = node->data();
|
|
||||||
auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handleScopeStorageNext_;
|
|
||||||
rangeVisitor(ecmascript::Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end)));
|
|
||||||
handleCount += (ToUintPtr(end) - ToUintPtr(start)) / sizeof(JSTaggedType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t globalCount = 0;
|
size_t globalCount = 0;
|
||||||
@ -380,52 +347,12 @@ bool JSThread::DoStackOverflowCheck(const JSTaggedType *sp)
|
|||||||
|
|
||||||
uintptr_t *JSThread::ExpandHandleStorage()
|
uintptr_t *JSThread::ExpandHandleStorage()
|
||||||
{
|
{
|
||||||
uintptr_t *result = nullptr;
|
return GetCurrentEcmaContext()->ExpandHandleStorage();
|
||||||
int32_t lastIndex = static_cast<int32_t>(handleStorageNodes_.size() - 1);
|
|
||||||
if (currentHandleStorageIndex_ == lastIndex) {
|
|
||||||
auto n = new std::array<JSTaggedType, NODE_BLOCK_SIZE>();
|
|
||||||
handleStorageNodes_.push_back(n);
|
|
||||||
currentHandleStorageIndex_++;
|
|
||||||
result = reinterpret_cast<uintptr_t *>(&n->data()[0]);
|
|
||||||
handleScopeStorageEnd_ = &n->data()[NODE_BLOCK_SIZE];
|
|
||||||
} else {
|
|
||||||
currentHandleStorageIndex_++;
|
|
||||||
auto lastNode = handleStorageNodes_[currentHandleStorageIndex_];
|
|
||||||
result = reinterpret_cast<uintptr_t *>(&lastNode->data()[0]);
|
|
||||||
handleScopeStorageEnd_ = &lastNode->data()[NODE_BLOCK_SIZE];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSThread::ShrinkHandleStorage(int prevIndex)
|
void JSThread::ShrinkHandleStorage(int prevIndex)
|
||||||
{
|
{
|
||||||
currentHandleStorageIndex_ = prevIndex;
|
GetCurrentEcmaContext()->ShrinkHandleStorage(prevIndex);
|
||||||
int32_t lastIndex = static_cast<int32_t>(handleStorageNodes_.size() - 1);
|
|
||||||
#if ECMASCRIPT_ENABLE_ZAP_MEM
|
|
||||||
uintptr_t size = ToUintPtr(handleScopeStorageEnd_) - ToUintPtr(handleScopeStorageNext_);
|
|
||||||
if (memset_s(handleScopeStorageNext_, size, 0, size) != EOK) {
|
|
||||||
LOG_FULL(FATAL) << "memset_s failed";
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
for (int32_t i = currentHandleStorageIndex_ + 1; i < lastIndex; i++) {
|
|
||||||
if (memset_s(handleStorageNodes_[i],
|
|
||||||
NODE_BLOCK_SIZE * sizeof(JSTaggedType), 0,
|
|
||||||
NODE_BLOCK_SIZE * sizeof(JSTaggedType)) !=
|
|
||||||
EOK) {
|
|
||||||
LOG_FULL(FATAL) << "memset_s failed";
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (lastIndex > MIN_HANDLE_STORAGE_SIZE && currentHandleStorageIndex_ < MIN_HANDLE_STORAGE_SIZE) {
|
|
||||||
for (int i = MIN_HANDLE_STORAGE_SIZE; i < lastIndex; i++) {
|
|
||||||
auto node = handleStorageNodes_.back();
|
|
||||||
delete node;
|
|
||||||
handleStorageNodes_.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSThread::NotifyStableArrayElementsGuardians(JSHandle<JSObject> receiver)
|
void JSThread::NotifyStableArrayElementsGuardians(JSHandle<JSObject> receiver)
|
||||||
@ -629,10 +556,34 @@ bool JSThread::IsMainThread()
|
|||||||
void JSThread::PushContext(EcmaContext *context)
|
void JSThread::PushContext(EcmaContext *context)
|
||||||
{
|
{
|
||||||
contexts_.emplace_back(context);
|
contexts_.emplace_back(context);
|
||||||
|
currentContext_ = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSThread::PopContext()
|
void JSThread::PopContext()
|
||||||
{
|
{
|
||||||
contexts_.pop_back();
|
contexts_.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSThread::SwitchCurrentContext(EcmaContext *currentContext)
|
||||||
|
{
|
||||||
|
ASSERT(std::count(contexts_.begin(), contexts_.end(), currentContext));
|
||||||
|
|
||||||
|
currentContext_->SetFramePointers(const_cast<JSTaggedType *>(GetCurrentSPFrame()),
|
||||||
|
const_cast<JSTaggedType *>(GetLastLeaveFrame()),
|
||||||
|
const_cast<JSTaggedType *>(GetLastFp()));
|
||||||
|
currentContext_->SetGlobalEnv(GetGlueGlobalEnv());
|
||||||
|
|
||||||
|
SetCurrentSPFrame(currentContext->GetCurrentFrame());
|
||||||
|
SetLastLeaveFrame(currentContext->GetLeaveFrame());
|
||||||
|
SetLastFp(currentContext->GetLastFp());
|
||||||
|
SetGlueGlobalEnv(*currentContext->GetGlobalEnv());
|
||||||
|
SetGlobalObject(currentContext->GetGlobalEnv()->GetGlobalObject());
|
||||||
|
|
||||||
|
currentContext_ = currentContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertiesCache *JSThread::GetPropertiesCache() const
|
||||||
|
{
|
||||||
|
return currentContext_->GetPropertiesCache();
|
||||||
|
}
|
||||||
} // namespace panda::ecmascript
|
} // namespace panda::ecmascript
|
||||||
|
@ -30,9 +30,9 @@
|
|||||||
#include "ecmascript/mem/visitor.h"
|
#include "ecmascript/mem/visitor.h"
|
||||||
|
|
||||||
namespace panda::ecmascript {
|
namespace panda::ecmascript {
|
||||||
class EcmaHandleScope;
|
|
||||||
class EcmaVM;
|
class EcmaVM;
|
||||||
class EcmaContext;
|
class EcmaContext;
|
||||||
|
class EcmaHandleScope;
|
||||||
class HeapRegionAllocator;
|
class HeapRegionAllocator;
|
||||||
class PropertiesCache;
|
class PropertiesCache;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -223,6 +223,11 @@ public:
|
|||||||
glueData_.lastFp_ = fp;
|
glueData_.lastFp_ = fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const JSTaggedType *GetLastFp()const
|
||||||
|
{
|
||||||
|
return glueData_.lastFp_;
|
||||||
|
}
|
||||||
|
|
||||||
const JSTaggedType *GetCurrentSPFrame() const
|
const JSTaggedType *GetCurrentSPFrame() const
|
||||||
{
|
{
|
||||||
return glueData_.currentFrame_;
|
return glueData_.currentFrame_;
|
||||||
@ -282,56 +287,11 @@ public:
|
|||||||
void PUBLIC_API CheckJSTaggedType(JSTaggedType value) const;
|
void PUBLIC_API CheckJSTaggedType(JSTaggedType value) const;
|
||||||
bool PUBLIC_API CpuProfilerCheckJSTaggedType(JSTaggedType value) const;
|
bool PUBLIC_API CpuProfilerCheckJSTaggedType(JSTaggedType value) const;
|
||||||
|
|
||||||
JSTaggedType *GetHandleScopeStorageNext() const
|
|
||||||
{
|
|
||||||
return handleScopeStorageNext_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetHandleScopeStorageNext(JSTaggedType *value)
|
|
||||||
{
|
|
||||||
handleScopeStorageNext_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSTaggedType *GetHandleScopeStorageEnd() const
|
|
||||||
{
|
|
||||||
return handleScopeStorageEnd_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::pair<WeakClearCallback, void *>> *GetWeakNodeNativeFinalizeCallbacks()
|
std::vector<std::pair<WeakClearCallback, void *>> *GetWeakNodeNativeFinalizeCallbacks()
|
||||||
{
|
{
|
||||||
return &weakNodeNativeFinalizeCallbacks_;
|
return &weakNodeNativeFinalizeCallbacks_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHandleScopeStorageEnd(JSTaggedType *value)
|
|
||||||
{
|
|
||||||
handleScopeStorageEnd_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetCurrentHandleStorageIndex() const
|
|
||||||
{
|
|
||||||
return currentHandleStorageIndex_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleScopeCountAdd()
|
|
||||||
{
|
|
||||||
handleScopeCount_++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleScopeCountDec()
|
|
||||||
{
|
|
||||||
handleScopeCount_--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetLastHandleScope(EcmaHandleScope *scope)
|
|
||||||
{
|
|
||||||
lastHandleScope_ = scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
EcmaHandleScope *GetLastHandleScope() const
|
|
||||||
{
|
|
||||||
return lastHandleScope_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetException(JSTaggedValue exception);
|
void SetException(JSTaggedValue exception);
|
||||||
|
|
||||||
JSTaggedValue GetException() const
|
JSTaggedValue GetException() const
|
||||||
@ -439,10 +399,7 @@ public:
|
|||||||
|
|
||||||
void IterateWeakEcmaGlobalStorage(const WeakRootVisitor &visitor);
|
void IterateWeakEcmaGlobalStorage(const WeakRootVisitor &visitor);
|
||||||
|
|
||||||
PropertiesCache *GetPropertiesCache() const
|
PropertiesCache *GetPropertiesCache() const;
|
||||||
{
|
|
||||||
return propertiesCache_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMarkStatus(MarkStatus status)
|
void SetMarkStatus(MarkStatus status)
|
||||||
{
|
{
|
||||||
@ -867,10 +824,11 @@ public:
|
|||||||
void PushContext(EcmaContext *context);
|
void PushContext(EcmaContext *context);
|
||||||
void PopContext();
|
void PopContext();
|
||||||
|
|
||||||
EcmaContext *GetCurrentEcmaContext() {
|
EcmaContext *GetCurrentEcmaContext() const
|
||||||
|
{
|
||||||
return contexts_.back();
|
return contexts_.back();
|
||||||
}
|
}
|
||||||
|
void SwitchCurrentContext(EcmaContext *currentContext);
|
||||||
private:
|
private:
|
||||||
NO_COPY_SEMANTIC(JSThread);
|
NO_COPY_SEMANTIC(JSThread);
|
||||||
NO_MOVE_SEMANTIC(JSThread);
|
NO_MOVE_SEMANTIC(JSThread);
|
||||||
@ -885,10 +843,13 @@ private:
|
|||||||
return contexts_;
|
return contexts_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
static const uint32_t NODE_BLOCK_SIZE_LOG2 = 10;
|
static const uint32_t NODE_BLOCK_SIZE_LOG2 = 10;
|
||||||
static const uint32_t NODE_BLOCK_SIZE = 1U << NODE_BLOCK_SIZE_LOG2;
|
static const uint32_t NODE_BLOCK_SIZE = 1U << NODE_BLOCK_SIZE_LOG2;
|
||||||
static constexpr int32_t MIN_HANDLE_STORAGE_SIZE = 2;
|
static constexpr int32_t MIN_HANDLE_STORAGE_SIZE = 2;
|
||||||
static constexpr size_t DEFAULT_MAX_SYSTEM_STACK_SIZE = 8_MB;
|
static constexpr size_t DEFAULT_MAX_SYSTEM_STACK_SIZE = 8_MB;
|
||||||
|
=======
|
||||||
|
>>>>>>> fix conflict and move fields in JSThread into context
|
||||||
GlueData glueData_;
|
GlueData glueData_;
|
||||||
std::atomic<ThreadId> id_;
|
std::atomic<ThreadId> id_;
|
||||||
EcmaVM *vm_ {nullptr};
|
EcmaVM *vm_ {nullptr};
|
||||||
@ -897,15 +858,8 @@ private:
|
|||||||
int nestedLevel_ = 0;
|
int nestedLevel_ = 0;
|
||||||
NativeAreaAllocator *nativeAreaAllocator_ {nullptr};
|
NativeAreaAllocator *nativeAreaAllocator_ {nullptr};
|
||||||
HeapRegionAllocator *heapRegionAllocator_ {nullptr};
|
HeapRegionAllocator *heapRegionAllocator_ {nullptr};
|
||||||
JSTaggedType *handleScopeStorageNext_ {nullptr};
|
|
||||||
JSTaggedType *handleScopeStorageEnd_ {nullptr};
|
|
||||||
std::vector<std::array<JSTaggedType, NODE_BLOCK_SIZE> *> handleStorageNodes_ {};
|
|
||||||
int32_t currentHandleStorageIndex_ {-1};
|
|
||||||
int32_t handleScopeCount_ {0};
|
|
||||||
EcmaHandleScope *lastHandleScope_ {nullptr};
|
|
||||||
std::vector<std::pair<WeakClearCallback, void *>> weakNodeNativeFinalizeCallbacks_ {};
|
std::vector<std::pair<WeakClearCallback, void *>> weakNodeNativeFinalizeCallbacks_ {};
|
||||||
|
|
||||||
PropertiesCache *propertiesCache_ {nullptr};
|
|
||||||
EcmaGlobalStorage<Node> *globalStorage_ {nullptr};
|
EcmaGlobalStorage<Node> *globalStorage_ {nullptr};
|
||||||
EcmaGlobalStorage<DebugNode> *globalDebugStorage_ {nullptr};
|
EcmaGlobalStorage<DebugNode> *globalDebugStorage_ {nullptr};
|
||||||
int32_t stackTraceFd_ {-1};
|
int32_t stackTraceFd_ {-1};
|
||||||
@ -929,8 +883,7 @@ private:
|
|||||||
bool finalizationCheckState_ {false};
|
bool finalizationCheckState_ {false};
|
||||||
|
|
||||||
CVector<EcmaContext *> contexts_;
|
CVector<EcmaContext *> contexts_;
|
||||||
|
EcmaContext *currentContext_ {nullptr};
|
||||||
friend class EcmaHandleScope;
|
|
||||||
friend class GlobalHandleCollection;
|
friend class GlobalHandleCollection;
|
||||||
friend class EcmaVM;
|
friend class EcmaVM;
|
||||||
};
|
};
|
||||||
|
@ -208,7 +208,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::Execute(JSThread *thread, con
|
|||||||
// For Ark application startup
|
// For Ark application startup
|
||||||
EcmaContext *context = thread->GetCurrentEcmaContext();
|
EcmaContext *context = thread->GetCurrentEcmaContext();
|
||||||
|
|
||||||
QuickFixManager *quickFixManager = vm->GetQuickFixManager();
|
QuickFixManager *quickFixManager = thread->GetEcmaVM()->GetQuickFixManager();
|
||||||
quickFixManager->LoadPatchIfNeeded(thread, jsPandaFile);
|
quickFixManager->LoadPatchIfNeeded(thread, jsPandaFile);
|
||||||
|
|
||||||
Expected<JSTaggedValue, bool> result = context->InvokeEcmaEntrypoint(jsPandaFile, entryPoint, excuteFromJob);
|
Expected<JSTaggedValue, bool> result = context->InvokeEcmaEntrypoint(jsPandaFile, entryPoint, excuteFromJob);
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include "ecmascript/ecma_runtime_call_info.h"
|
#include "ecmascript/ecma_runtime_call_info.h"
|
||||||
#include "ecmascript/ecma_string.h"
|
#include "ecmascript/ecma_string.h"
|
||||||
#include "ecmascript/ecma_vm.h"
|
#include "ecmascript/ecma_vm.h"
|
||||||
#include "ecmascript/ecma_context.h"
|
|
||||||
#include "ecmascript/global_env.h"
|
#include "ecmascript/global_env.h"
|
||||||
#include "ecmascript/interpreter/fast_runtime_stub-inl.h"
|
#include "ecmascript/interpreter/fast_runtime_stub-inl.h"
|
||||||
#include "ecmascript/jobs/micro_job_queue.h"
|
#include "ecmascript/jobs/micro_job_queue.h"
|
||||||
@ -963,31 +962,31 @@ void JSNApi::DestroyAnDataManager()
|
|||||||
// ----------------------------------- HandleScope -------------------------------------
|
// ----------------------------------- HandleScope -------------------------------------
|
||||||
LocalScope::LocalScope(const EcmaVM *vm) : thread_(vm->GetJSThread())
|
LocalScope::LocalScope(const EcmaVM *vm) : thread_(vm->GetJSThread())
|
||||||
{
|
{
|
||||||
auto thread = reinterpret_cast<JSThread *>(thread_);
|
auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext();
|
||||||
prevNext_ = thread->GetHandleScopeStorageNext();
|
prevNext_ = context->GetHandleScopeStorageNext();
|
||||||
prevEnd_ = thread->GetHandleScopeStorageEnd();
|
prevEnd_ = context->GetHandleScopeStorageEnd();
|
||||||
prevHandleStorageIndex_ = thread->GetCurrentHandleStorageIndex();
|
prevHandleStorageIndex_ = context->GetCurrentHandleStorageIndex();
|
||||||
thread->HandleScopeCountAdd();
|
context->HandleScopeCountAdd();
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalScope::LocalScope(const EcmaVM *vm, JSTaggedType value) : thread_(vm->GetJSThread())
|
LocalScope::LocalScope(const EcmaVM *vm, JSTaggedType value) : thread_(vm->GetJSThread())
|
||||||
{
|
{
|
||||||
auto thread = reinterpret_cast<JSThread *>(thread_);
|
auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext();
|
||||||
ecmascript::EcmaHandleScope::NewHandle(thread, value);
|
ecmascript::EcmaHandleScope::NewHandle(reinterpret_cast<JSThread *>(thread_), value);
|
||||||
prevNext_ = thread->GetHandleScopeStorageNext();
|
prevNext_ = context->GetHandleScopeStorageNext();
|
||||||
prevEnd_ = thread->GetHandleScopeStorageEnd();
|
prevEnd_ = context->GetHandleScopeStorageEnd();
|
||||||
prevHandleStorageIndex_ = thread->GetCurrentHandleStorageIndex();
|
prevHandleStorageIndex_ = context->GetCurrentHandleStorageIndex();
|
||||||
thread->HandleScopeCountAdd();
|
context->HandleScopeCountAdd();
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalScope::~LocalScope()
|
LocalScope::~LocalScope()
|
||||||
{
|
{
|
||||||
auto thread = reinterpret_cast<JSThread *>(thread_);
|
auto context = reinterpret_cast<JSThread *>(thread_)->GetCurrentEcmaContext();
|
||||||
thread->HandleScopeCountDec();
|
context->HandleScopeCountDec();
|
||||||
thread->SetHandleScopeStorageNext(static_cast<JSTaggedType *>(prevNext_));
|
context->SetHandleScopeStorageNext(static_cast<JSTaggedType *>(prevNext_));
|
||||||
if (thread->GetHandleScopeStorageEnd() != prevEnd_) {
|
if (context->GetHandleScopeStorageEnd() != prevEnd_) {
|
||||||
thread->SetHandleScopeStorageEnd(static_cast<JSTaggedType *>(prevEnd_));
|
context->SetHandleScopeStorageEnd(static_cast<JSTaggedType *>(prevEnd_));
|
||||||
thread->ShrinkHandleStorage(prevHandleStorageIndex_);
|
context->ShrinkHandleStorage(prevHandleStorageIndex_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -996,7 +995,7 @@ EscapeLocalScope::EscapeLocalScope(const EcmaVM *vm) : LocalScope(vm, JSTaggedVa
|
|||||||
{
|
{
|
||||||
auto thread = vm->GetJSThread();
|
auto thread = vm->GetJSThread();
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
escapeHandle_ = ToUintPtr(thread->GetHandleScopeStorageNext() - 1);
|
escapeHandle_ = ToUintPtr(thread->GetCurrentEcmaContext()->GetHandleScopeStorageNext() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------- PritimitiveRef ---------------------------------------
|
// ----------------------------------- PritimitiveRef ---------------------------------------
|
||||||
@ -3186,7 +3185,7 @@ void JSNApi::SetAssetPath(EcmaVM *vm, const std::string &assetPath)
|
|||||||
|
|
||||||
void JSNApi::SetLoop(EcmaVM *vm, void *loop)
|
void JSNApi::SetLoop(EcmaVM *vm, void *loop)
|
||||||
{
|
{
|
||||||
vm->GetJSThread()->GetCurrentEcmaContext()->SetLoop(loop);
|
vm->SetLoop(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JSNApi::GetAssetPath(EcmaVM *vm)
|
std::string JSNApi::GetAssetPath(EcmaVM *vm)
|
||||||
@ -3226,36 +3225,12 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
|
|||||||
auto *notificationMgr = vm->GetJsDebuggerManager()->GetNotificationManager();
|
auto *notificationMgr = vm->GetJsDebuggerManager()->GetNotificationManager();
|
||||||
notificationMgr->LoadModuleEvent(moduleName, recordName);
|
notificationMgr->LoadModuleEvent(moduleName, recordName);
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
// check ESM or CJS
|
// check ESM or CJS
|
||||||
if (!jsPandaFile->IsModule(thread, recordName)) {
|
if (!jsPandaFile->IsModule(thread, recordName)) {
|
||||||
LOG_ECMA(DEBUG) << "Current function is not from ES Module's file.";
|
LOG_ECMA(DEBUG) << "Current function is not from ES Module's file.";
|
||||||
=======
|
|
||||||
bool isModule = jsPandaFile->IsModule(thread, recordName);
|
|
||||||
if (isModule) {
|
|
||||||
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
|
|
||||||
JSHandle<ecmascript::JSTaggedValue> moduleRecord;
|
|
||||||
if (jsPandaFile->IsBundlePack()) {
|
|
||||||
moduleRecord = moduleManager->HostResolveImportedModule(moduleName);
|
|
||||||
} else {
|
|
||||||
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(moduleName, recordName);
|
|
||||||
if (ecmascript::AnFileDataManager::GetInstance()->IsEnable()) {
|
|
||||||
vm->GetJSThread()->GetCurrentEcmaContext()->GetAOTFileManager()->LoadAiFile(jsPandaFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ecmascript::SourceTextModule::Instantiate(thread, moduleRecord);
|
|
||||||
if (thread->HasPendingException()) {
|
|
||||||
vm->GetJSThread()->GetCurrentEcmaContext()->HandleUncaughtException(thread->GetException());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
JSHandle<ecmascript::SourceTextModule> module = JSHandle<ecmascript::SourceTextModule>::Cast(moduleRecord);
|
|
||||||
module->SetStatus(ecmascript::ModuleStatus::INSTANTIATED);
|
|
||||||
ecmascript::SourceTextModule::EvaluateForConcurrent(thread, module);
|
|
||||||
transFunc->SetModule(thread, module);
|
|
||||||
>>>>>>> add cachedconstpools from vm to context
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ecmascript::ModuleManager *moduleManager = vm->GetModuleManager();
|
ecmascript::ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
|
||||||
JSHandle<ecmascript::JSTaggedValue> moduleRecord;
|
JSHandle<ecmascript::JSTaggedValue> moduleRecord;
|
||||||
// check compileMode
|
// check compileMode
|
||||||
if (jsPandaFile->IsBundlePack()) {
|
if (jsPandaFile->IsBundlePack()) {
|
||||||
@ -3265,7 +3240,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
|
|||||||
LOG_ECMA(DEBUG) << "compileMode is esmodule";
|
LOG_ECMA(DEBUG) << "compileMode is esmodule";
|
||||||
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(moduleName, recordName);
|
moduleRecord = moduleManager->HostResolveImportedModuleWithMerge(moduleName, recordName);
|
||||||
if (ecmascript::AnFileDataManager::GetInstance()->IsEnable()) {
|
if (ecmascript::AnFileDataManager::GetInstance()->IsEnable()) {
|
||||||
vm->GetAOTFileManager()->LoadAiFile(jsPandaFile);
|
thread->GetCurrentEcmaContext()->GetAOTFileManager()->LoadAiFile(jsPandaFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ecmascript::SourceTextModule::Instantiate(thread, moduleRecord);
|
ecmascript::SourceTextModule::Instantiate(thread, moduleRecord);
|
||||||
@ -3310,7 +3285,8 @@ void JSNApi::SynchronizVMInfo(EcmaVM *vm, const EcmaVM *hostVM)
|
|||||||
vm->SetModuleName(hostVM->GetModuleName());
|
vm->SetModuleName(hostVM->GetModuleName());
|
||||||
vm->SetAssetPath(hostVM->GetAssetPath());
|
vm->SetAssetPath(hostVM->GetAssetPath());
|
||||||
vm->SetIsBundlePack(hostVM->IsBundlePack());
|
vm->SetIsBundlePack(hostVM->IsBundlePack());
|
||||||
vm->GetModuleManager()->SetExecuteMode(hostVM->GetModuleManager()->GetCurrentMode());
|
vm->GetJSThread()->GetCurrentEcmaContext()->GetModuleManager()->SetExecuteMode(
|
||||||
|
hostVM->GetJSThread()->GetCurrentEcmaContext()->GetModuleManager()->GetCurrentMode());
|
||||||
vm->SetResolveBufferCallback(hostVM->GetResolveBufferCallback());
|
vm->SetResolveBufferCallback(hostVM->GetResolveBufferCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1304,7 +1304,7 @@ HWTEST_F_L0(JSNApiTests, JSNApi_SetAssetPath_GetAssetPath)
|
|||||||
ASSERT_EQ(str, res);
|
ASSERT_EQ(str, res);
|
||||||
void *data = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
|
void *data = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
|
||||||
JSNApi::SetLoop(vm_, data);
|
JSNApi::SetLoop(vm_, data);
|
||||||
void* res1 = vm_->GetJSThread()->GetCurrentEcmaContext()->GetLoop();
|
void* res1 = vm_->GetLoop();
|
||||||
ASSERT_EQ(res1, data);
|
ASSERT_EQ(res1, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user