fix code check and realm parameter

Signed-off-by: xiongluo <xiongluo@huawei.com>
Change-Id: I71a9206f553eebdf4af791d34d0f9401776a70be
This commit is contained in:
xiongluo 2023-06-11 16:00:16 +08:00
parent e0a80d811f
commit b3bbcbf573
23 changed files with 57 additions and 47 deletions

View File

@ -185,7 +185,7 @@ using SharedArrayBuffer = builtins::BuiltinsSharedArrayBuffer;
using BuiltinsAsyncIterator = builtins::BuiltinsAsyncIterator;
using AsyncGeneratorObject = builtins::BuiltinsAsyncGenerator;
void Builtins::Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool lazyInit)
void Builtins::Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool lazyInit, bool isRealm)
{
thread_ = thread;
vm_ = thread->GetEcmaVM();
@ -266,15 +266,15 @@ void Builtins::Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool
JSType::JS_FUNCTION, env->GetFunctionPrototype());
env->SetFunctionClassWithoutName(thread_, FunctionClass);
if (env == vm_->GetGlobalEnv()) {
if (!isRealm) {
InitializeAllTypeError(env, objFuncClass);
InitializeSymbol(env, primRefObjHClass);
InitializeBigInt(env, primRefObjHClass);
} else {
// error and symbol need to be shared when initialize realm
InitializeAllTypeError(env, objFuncClass);
InitializeSymbol(env, primRefObjHClass);
InitializeBigInt(env, primRefObjHClass);
InitializeAllTypeErrorWithRealm(env);
InitializeSymbolWithRealm(env, primRefObjHClass);
InitializeBigIntWithRealm(env);
}
InitializeArray(env, objFuncPrototypeVal);

View File

@ -43,7 +43,7 @@ public:
NO_COPY_SEMANTIC(Builtins);
NO_MOVE_SEMANTIC(Builtins);
void Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool lazyInit = false);
void Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool lazyInit = false, bool isRealm = false);
void InitializeForSnapshot(JSThread *thread);
private:

View File

@ -27,7 +27,7 @@ bool PassManager::ShouldCollect() const
{
return passOptions_->EnableTypeInfer() &&
(profilerDecoder_.IsLoaded() || vm_->GetJSThread()->GetCurrentEcmaContext()->GetTSManager()->AssertTypes() ||
log_->OutputType());
log_->OutputType());
}
bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &gen)

View File

@ -14,12 +14,14 @@
*/
#include "ecmascript/ecma_context.h"
#include "ecmascript/base/path_helper.h"
#include "ecmascript/builtins/builtins.h"
#include "ecmascript/builtins/builtins_global.h"
#include "ecmascript/builtins/builtins_regexp.h"
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
#include "ecmascript/compiler/common_stubs.h"
#include "ecmascript/ecma_string_table.h"
#include "ecmascript/builtins/builtins_regexp.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/global_env_constants-inl.h"
@ -27,7 +29,6 @@
#include "ecmascript/jobs/micro_job_queue.h"
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_thread.h"
@ -62,7 +63,6 @@ EcmaContext *EcmaContext::Create(JSThread *thread)
// static
bool EcmaContext::Destroy(EcmaContext *context)
{
LOG_ECMA(INFO) << "EcmaContext::Destroy";
if (context != nullptr) {
delete context;
context = nullptr;
@ -73,7 +73,7 @@ bool EcmaContext::Destroy(EcmaContext *context)
bool EcmaContext::Initialize()
{
LOG_ECMA(INFO) << "EcmaContext::Initialize";
LOG_ECMA(DEBUG) << "EcmaContext::Initialize";
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "EcmaContext::Initialize");
[[maybe_unused]] EcmaHandleScope scope(thread_);
aotFileManager_ = new AOTFileManager(vm_);
@ -129,6 +129,7 @@ void EcmaContext::InitializeEcmaScriptRunStat()
UNREACHABLE();
}
}
void EcmaContext::SetRuntimeStatEnable(bool flag)
{
static uint64_t start = 0;
@ -151,7 +152,6 @@ void EcmaContext::SetRuntimeStatEnable(bool flag)
EcmaContext::~EcmaContext()
{
LOG_ECMA(INFO) << "~EcmaContext";
if (runtimeStat_ != nullptr && runtimeStat_->IsRuntimeStatEnabled()) {
runtimeStat_->Print();
}
@ -203,6 +203,7 @@ EcmaContext::~EcmaContext()
propertiesCache_ = nullptr;
}
}
JSTaggedValue EcmaContext::InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
const JSPandaFile *jsPandaFile, std::string_view entryPoint,
CJSInfo* cjsInfo)
@ -225,6 +226,7 @@ JSTaggedValue EcmaContext::ExecuteAot(size_t actualNumArgs, JSTaggedType *args,
needPushUndefined);
return res;
}
Expected<JSTaggedValue, bool> EcmaContext::InvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile,
std::string_view entryPoint, bool excuteFromJob)
{
@ -689,6 +691,7 @@ void EcmaContext::ShrinkHandleStorage(int prevIndex)
}
}
}
void EcmaContext::LoadStubFile()
{
std::string stubFile = vm_->GetJSOptions().GetStubFile();
@ -724,5 +727,4 @@ void EcmaContext::DumpAOTInfo() const
{
aotFileManager_->DumpAOTInfo();
}
} // namespace panda::ecmascript

View File

@ -18,15 +18,15 @@
#include <optional>
#include "ecmascript/base/config.h"
#include "ecmascript/common.h"
#include "ecmascript/dfx/vmstat/opt_code_profiler.h"
#include "ecmascript/frames.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/dfx/vmstat/opt_code_profiler.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/mem/visitor.h"
#include "ecmascript/regexp/regexp_parser_cache.h"
#include "libpandafile/file.h"
#include "ecmascript/waiter_list.h"
#include "libpandafile/file.h"
namespace panda {
class JSNApi;
@ -383,10 +383,10 @@ private:
const JSPandaFile *jsPandaFile, std::string_view entryPoint);
JSTaggedValue InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
const JSPandaFile *jsPandaFile, std::string_view entryPoint,
CJSInfo* cjsInfo = nullptr);
CJSInfo *cjsInfo = nullptr);
Expected<JSTaggedValue, bool> InvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile, std::string_view entryPoint,
bool excuteFromJob = false);
bool LoadAOTFiles(const std::string& aotFileName);
bool LoadAOTFiles(const std::string &aotFileName);
NO_MOVE_SEMANTIC(EcmaContext);
NO_COPY_SEMANTIC(EcmaContext);
@ -419,7 +419,7 @@ private:
// Registered Callbacks
PromiseRejectCallback promiseRejectCallback_ {nullptr};
HostPromiseRejectionTracker hostPromiseRejectionTracker_ {nullptr};
void* data_ {nullptr};
void* data_{nullptr};
// opt code Profiler
OptCodeProfiler *optCodeProfiler_ {nullptr};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2023 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

View File

@ -28,7 +28,7 @@ FrameIterator::FrameIterator(JSTaggedType *sp, const JSThread *thread) : current
{
if (thread != nullptr) {
arkStackMapParser_ =
const_cast<JSThread*>(thread)->GetCurrentEcmaContext()->GetAOTFileManager()->GetStackMapParser();
const_cast<JSThread *>(thread)->GetCurrentEcmaContext()->GetAOTFileManager()->GetStackMapParser();
}
}
@ -111,7 +111,7 @@ JSTaggedValue FrameIterator::GetFunction() const
AOTFileInfo::CallSiteInfo FrameIterator::CalCallSiteInfo(uintptr_t retAddr) const
{
auto loader = const_cast<JSThread*>(thread_)->GetCurrentEcmaContext()->GetAOTFileManager();
auto loader = const_cast<JSThread *>(thread_)->GetCurrentEcmaContext()->GetAOTFileManager();
return loader->CalCallSiteInfo(retAddr);
}

View File

@ -360,7 +360,7 @@ void FrameHandler::Iterate(const RootVisitor &visitor, const RootRangeVisitor &r
// lazy assignment: only Iterate need arkStackMapParser_ in order to high improve performance
if (arkStackMapParser_ == nullptr) {
arkStackMapParser_ =
const_cast<JSThread*>(thread_)->GetCurrentEcmaContext()->GetAOTFileManager()->GetStackMapParser();
const_cast<JSThread *>(thread_)->GetCurrentEcmaContext()->GetAOTFileManager()->GetStackMapParser();
}
IterateFrameChain(current, visitor, rangeVisitor, derivedVisitor);
}

View File

@ -7202,6 +7202,7 @@ void EcmaInterpreter::InitStackFrame(EcmaContext *context)
}
InitStackFrameForSP(const_cast<JSTaggedType *>(context->GetCurrentFrame()));
}
void EcmaInterpreter::InitStackFrameForSP(JSTaggedType *prevSp)
{
InterpretedFrame *state = GET_FRAME(prevSp);

View File

@ -203,10 +203,12 @@ void InterpreterAssembly::InitStackFrame(JSThread *thread)
{
InitStackFrameForSP(const_cast<JSTaggedType *>(thread->GetCurrentSPFrame()));
}
void InterpreterAssembly::InitStackFrame(EcmaContext *context)
{
InitStackFrameForSP(const_cast<JSTaggedType *>(context->GetCurrentFrame()));
}
void InterpreterAssembly::InitStackFrameForSP(JSTaggedType *prevSp)
{
InterpretedEntryFrame *entryState = InterpretedEntryFrame::GetFrameFromSp(prevSp);
@ -214,6 +216,7 @@ void InterpreterAssembly::InitStackFrameForSP(JSTaggedType *prevSp)
entryState->base.prev = nullptr;
entryState->pc = nullptr;
}
JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info)
{
ASSERT(info);

View File

@ -668,8 +668,8 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle<JSN
std::string cacheEntry =
locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
auto formatterPointer = new icu::number::LocalizedNumberFormatter(icuNumberFormatter);
thread->GetCurrentEcmaContext()->SetIcuFormatterToCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry, formatterPointer,
JSNumberFormat::FreeIcuNumberformat);
thread->GetCurrentEcmaContext()->SetIcuFormatterToCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry,
formatterPointer, JSNumberFormat::FreeIcuNumberformat);
} else {
// Set numberFormat.[[IcuNumberForma]] to handleNumberFormatter
factory->NewJSIntlIcuData(numberFormat, icuNumberFormatter, JSNumberFormat::FreeIcuNumberformat);
@ -696,7 +696,8 @@ icu::number::LocalizedNumberFormatter *JSNumberFormat::GetCachedIcuNumberFormatt
const JSHandle<JSTaggedValue> &locales)
{
std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString();
void *cachedNumberFormatter = thread->GetCurrentEcmaContext()->GetIcuFormatterFromCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry);
void *cachedNumberFormatter = thread->GetCurrentEcmaContext()->GetIcuFormatterFromCache(
IcuFormatterType::NUMBER_FORMATTER, cacheEntry);
if (cachedNumberFormatter) {
return reinterpret_cast<icu::number::LocalizedNumberFormatter*>(cachedNumberFormatter);
}

View File

@ -234,7 +234,8 @@ JSHandle<JSFunction> LiteralDataExtractor::DefineMethodInLiteral(JSThread *threa
entry = entryPoint;
}
if (jsPandaFile->IsModule(thread, entry)) {
JSHandle<SourceTextModule> module = thread->GetCurrentEcmaContext()->GetModuleManager()->HostGetImportedModule(moduleName);
JSHandle<SourceTextModule> module = thread->GetCurrentEcmaContext()->GetModuleManager()->HostGetImportedModule(
moduleName);
jsFunc->SetModule(thread, module.GetTaggedValue());
}
return jsFunc;

View File

@ -107,7 +107,8 @@ JSHandle<Program> PandaFileTranslator::GenerateProgram(EcmaVM *vm, const JSPanda
JSHandle<ConstantPool> constpool;
bool isNewVersion = jsPandaFile->IsNewVersion();
if (isNewVersion) {
constpool = vm->GetJSThread()->GetCurrentEcmaContext()->FindOrCreateConstPool(jsPandaFile, EntityId(mainMethodIndex));
constpool = vm->GetJSThread()->GetCurrentEcmaContext()->FindOrCreateConstPool(
jsPandaFile, EntityId(mainMethodIndex));
} else {
JSTaggedValue constpoolVal = vm->GetJSThread()->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, 0);
if (constpoolVal.IsHole()) {

View File

@ -19,6 +19,7 @@ namespace panda::ecmascript {
JSHandle<ConstantPool> ConstantPool::GetDeserializedConstantPool(EcmaVM *vm, const JSPandaFile *jsPandaFile,
int32_t cpID)
{
return JSHandle<ConstantPool>(vm->GetJSThread()->GetCurrentEcmaContext()->GetAOTFileManager()->GetDeserializedConstantPool(jsPandaFile, cpID));
auto context = vm->GetJSThread()->GetCurrentEcmaContext();
return JSHandle<ConstantPool>(context->GetAOTFileManager()->GetDeserializedConstantPool(jsPandaFile, cpID));
}
}

View File

@ -102,10 +102,6 @@ inline int LayoutInfo::FindElementWithCache(const JSThread *thread, JSHClass *cl
if (propertiesNumber <= MAX_ELEMENTS_LINER_SEARCH) {
Span<struct Properties> sp(GetProperties(), propertiesNumber);
for (int i = 0; i < propertiesNumber; i++) {
if (key.IsString() && sp[i].key_.IsString()) {
EcmaStringAccessor::StringsAreEqual(EcmaString::Cast(sp[i].key_.GetTaggedObject()),
EcmaString::Cast(key.GetTaggedObject()));
}
if (sp[i].key_ == key) {
return i;
}

View File

@ -1240,7 +1240,7 @@ public:
// JS code
static bool ExecuteInContext(EcmaVM *vm, const std::string &fileName, const std::string &entry,
bool needUpdate = false);
bool needUpdate = false);
static bool Execute(EcmaVM *vm, const std::string &fileName, const std::string &entry, bool needUpdate = false);
static bool Execute(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &entry,
const std::string &filename = "", bool needUpdate = false);

View File

@ -803,7 +803,8 @@ void HostPromiseRejectionTracker(const EcmaVM *vm,
void JSNApi::SetHostPromiseRejectionTracker(EcmaVM *vm, void *cb, void* data)
{
vm->GetJSThread()->GetCurrentEcmaContext()->SetHostPromiseRejectionTracker(HostPromiseRejectionTracker);
vm->GetJSThread()->GetCurrentEcmaContext()->SetPromiseRejectCallback(reinterpret_cast<ecmascript::PromiseRejectCallback>(cb));
vm->GetJSThread()->GetCurrentEcmaContext()->SetPromiseRejectCallback(
reinterpret_cast<ecmascript::PromiseRejectCallback>(cb));
vm->GetJSThread()->GetCurrentEcmaContext()->SetData(data);
}

View File

@ -2113,7 +2113,7 @@ JSHandle<JSRealm> ObjectFactory::NewJSRealm()
realmEnvHandle->SetTemplateMap(thread_, result);
Builtins builtins;
builtins.Initialize(realmEnvHandle, thread_);
builtins.Initialize(realmEnvHandle, thread_, false, true);
JSHandle<JSTaggedValue> protoValue = thread_->GlobalConstants()->GetHandledJSRealmClass();
JSHandle<JSHClass> hclassHandle = NewEcmaHClass(JSRealm::SIZE, JSType::JS_REALM, protoValue);
JSHandle<JSRealm> realm(NewJSObject(hclassHandle));

View File

@ -111,7 +111,8 @@ bool PatchLoader::ExecutePatchMain(JSThread *thread, const JSPandaFile *patchFil
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
JSHandle<JSFunction> func(thread, program->GetMainFunction());
JSHandle<JSTaggedValue> module =
thread->GetCurrentEcmaContext()->GetModuleManager()->HostResolveImportedModuleWithMerge(patchFile->GetJSPandaFileDesc(), recordName);
thread->GetCurrentEcmaContext()->GetModuleManager()->HostResolveImportedModuleWithMerge(
patchFile->GetJSPandaFileDesc(), recordName);
func->SetModule(thread, module);
EcmaRuntimeCallInfo *info =
EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle<JSTaggedValue>(func), undefined, undefined, 0);
@ -178,7 +179,8 @@ PatchErrorCode PatchLoader::UnloadPatchInternal(JSThread *thread, const CString
}
MethodLiteral *baseMethodLiteral = item.second;
JSTaggedValue baseConstpoolValue = thread->GetCurrentEcmaContext()->FindConstpool(baseFile.get(), baseMethodLiteral->GetMethodId());
JSTaggedValue baseConstpoolValue = thread->GetCurrentEcmaContext()->FindConstpool(
baseFile.get(), baseMethodLiteral->GetMethodId());
ReplaceMethod(thread, patchMethod, baseMethodLiteral, baseConstpoolValue);
LOG_ECMA(INFO) << "Replace base method: "
<< patchMethod->GetRecordName()
@ -231,7 +233,8 @@ void PatchLoader::ReplaceMethod(JSThread *thread,
void PatchLoader::FindAndReplaceSameMethod(JSThread *thread, const JSPandaFile *baseFile,
const JSPandaFile *patchFile, PatchInfo &patchInfo)
{
const CMap<int32_t, JSTaggedValue> &baseConstpoolValues = thread->GetCurrentEcmaContext()->FindConstpools(baseFile).value();
auto context = thread->GetCurrentEcmaContext();
const CMap<int32_t, JSTaggedValue> &baseConstpoolValues = context->FindConstpools(baseFile).value();
for (const auto &item : baseConstpoolValues) {
if (item.second.IsHole()) {
continue;
@ -255,7 +258,7 @@ void PatchLoader::FindAndReplaceSameMethod(JSThread *thread, const JSPandaFile *
continue;
}
JSTaggedValue patchConstpoolValue = thread->GetCurrentEcmaContext()->FindConstpool(patchFile, patchMethodLiteral->GetMethodId());
JSTaggedValue patchConstpoolValue = context->FindConstpool(patchFile, patchMethodLiteral->GetMethodId());
ReplaceMethod(thread, baseMethod, patchMethodLiteral, patchConstpoolValue);
BaseMethodIndex indexs = {constpoolNum, constpoolIndex};
@ -280,7 +283,7 @@ void PatchLoader::FindAndReplaceSameMethod(JSThread *thread, const JSPandaFile *
continue;
}
JSTaggedValue patchConstpoolValue = thread->GetCurrentEcmaContext()->FindConstpool(patchFile, patchMethodLiteral->GetMethodId());
JSTaggedValue patchConstpoolValue = context->FindConstpool(patchFile, patchMethodLiteral->GetMethodId());
ReplaceMethod(thread, baseMethod, patchMethodLiteral, patchConstpoolValue);
BaseMethodIndex indexs = {constpoolNum, constpoolIndex, literalIndex};

View File

@ -59,7 +59,7 @@ HWTEST_F_L0(EcmaContextTest, Create)
EXPECT_EQ(Cv1.size(), 1);
thread->PushContext(context2);
Cv1 = thread->GetEcmaContexts();
EXPECT_EQ(Cv1.size(), 2);
EXPECT_EQ(Cv1.size(), 2); // 2: size of contexts.
}
HWTEST_F_L0(EcmaContextTest, CreatePushContext)
@ -68,13 +68,13 @@ HWTEST_F_L0(EcmaContextTest, CreatePushContext)
auto context1 = EcmaContext::Create(thread);
thread->PushContext(context1);
CVector<EcmaContext *> context3 = thread->GetEcmaContexts();
EXPECT_EQ(context3.size(), 2);
EXPECT_EQ(context3.size(), 2); // 2: size of contexts.
thread->PushContext(context);
context3 = thread->GetEcmaContexts();
EXPECT_EQ(context3.size(), 3);
EXPECT_EQ(context3.size(), 3); // 3: size of contexts.
thread->PopContext();
context3 = thread->GetEcmaContexts();
EXPECT_EQ(context3.size(), 2);
EXPECT_EQ(context3.size(), 2); // 2: size of contexts.
}
HWTEST_F_L0(EcmaContextTest, GetRegExpCache)

View File

@ -51,7 +51,7 @@ def judge_output(args):
if input_args.timeout_limit:
timeout_limit = int(input_args.timeout_limit)
else:
timeout_limit = 400 # units: s
timeout_limit = 120 # units: s
subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env={'LD_LIBRARY_PATH': str(input_args.env_path)})
try:

View File

@ -102,5 +102,5 @@ host_moduletest_action("container") {
":gen_container_treeset_abc",
":gen_container_vector_abc",
]
timeout = "1200"
timeout = "300"
}

View File

@ -87,7 +87,7 @@ template("host_moduletest_action") {
if (defined(invoker.is_json) && invoker.is_json) {
_is_json_ = true
}
_timeout_ = "400"
_timeout_ = "120"
if (defined(invoker.timeout)) {
_timeout_ = invoker.timeout
}