mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
e68673a13f
add baseline builtins Change-Id: Ib8d7c392c62e21eab19b17e45c0fafb499cbbed9 support running baseline compiler by option --compiler-force-baseline-compile-main=true Change-Id: I7c7337faf9fad39ccffb2de28d46403e2f6cb22b baseline jit part3 Change-Id: I36e8dd6a6fa6fffb738029a8620bbcd01df1e017 baseline part4 Change-Id: Ib45bcf7255a85aa48f864a6021adf819927e6a13 baseline part5 move baseline into compiler folder Change-Id: Ia8781c95ae00c4f300e7267a6da0078b5d04e4c8 !185 support BaselinePrologue * support BaselinePrologue part3 * support BaselinePrologue part2 * support BaselinePrologue !187 [BaselineJit] support load baseline builtins * [BaselineJit]support load baseline builtins !186[BaselineJIT] workaround for baselinejit support install code * install code part3 * install code part2 * baseline jit support intall code !188 [BaselineJit] support CallBuiltin * [BaselineJit] baseline support CallBuiltin !189 [BaselineJIT]implement StackOffset class * [BaselineJIT]implement StackOffset class !190 [BaselineJIT]refactor BaselineAssembler and MacroAssembler * [BaselineJIT]refactor BaselineAssembler and MacroAssembler !191 [BaselineJIT] refactor class BaselineCompiler * [BaselineJIT] refactor class BaselineCompiler !192 [BaselineJIT] callbuiltin support new parameter type new parameter type: int32_t,SpecialParameter,VirtualRegister !193 [BaselineJIT]modify BaselineLoadObjByName function * [BaselineJIT]modify BaselineLoadObjByName function !194 [BaselineJIT] support new builtins * [BaselineJIT] add BaselineTryLdGLobalByNameImm8ID16, BaselineStToGlobalRecordImm16ID16, BaselineLdaStrID16 !196 [BaselineJIT]bugfix for BaselinePrologue, align the rsp * [BaselineJIT]bugfix for BaselinePrologue, align the rsp !197 [BaselineJIT]bugfix for StackOffsetDescriptor * [BaselineJIT]bugfix for StackOffsetDescriptor !198 [BaselineJIT]workaround for helloworld testcase, helloworld can run successfully * workaround for helloworld testcase, helloworld can run successfully !200 [BaselineJIT]adapt profile collection * [BaselineJIT]adapt profile collection !201 [BaselineJIT]refactor baseline jit * [BaselineJIT]refactor baseline jit !203 [BaselineJIT]support trigger BaselineJITCompile and call baselinecode async * [BaselineJIT]support trigger BaselineJITCompile and call baselinecode async !202 [BaselineJIT]enable update hotness * [BaselineJIT]enable update hotness !205 [BaselineJIT]adapt JSCallDispatch interface * [BaselineJIT]adapt JSCallDispatch interface Change-Id: I4efce4346f985c7e074d7fc4bbfe3b081272e950 !195 [Baseline JIT] bytecode to builtin funs * !206 enable bytecode builtins and call CHECK_PENDING_EXCEPTION * [Baseline JIT] builtins:StobjbynameImm9Id16V8,StobjbynameImm16Id16V8,S… * [Baseline JIT] builtins:CopyrestargsImm8,LdlexvarImm4Imm4,StlexvarImm4… * [Baseline JIT] builtins: LdsuperbyvalueImm8V8,LdsuperbyvalueImm16V8,St… * [Baseline JIT] builtins: DelobjpropV8,AsyncfunctionawaituncaughtV8,Cop… * !204 enable bytecode builtins * [Baseline JIT] builtins: DefineclasswithbufferImm8Id16Id16Imm16V8,Defi… * [Baseline JIT] builtins: LdthisbynameImm8Id16,Definegettersetterbyval… * [Baseline JIT] builtins: Callarg0Imm8,SupercallspreadImm8V8,ApplyImm8V… * !199 enable bytecode builtin func * [Baseline JIT] builtins: StrictnoteqImm8V8,StricteqImm8V8,Istrue,Isfal… * [Baseline JIT] builtins: NegImm8,NotImm8,IncImm8,DecImm8,IsinImm8V8,In… * [Baseline JIT] builtins: And2Imm8V8,Or2Imm8V8,Xor2Imm8V8,ExpImm8V8,Typ… * [Baseline JIT] builtins:LessImm8V8,LesseqImm8V8,GreaterImm8V8,Greatere… * [Baseline JIT] builtins:Add2Imm8V8,SUB2_IMM8_V8,MUL2_IMM8_V8,DIV2_IMM8… * [Baseline JIT] builtins:CreateobjectwithbufferImm8Id16,Createobjectwit… * [Baseline JIT]builtins:Createemptyobject,CreateemptyarrayImm8,Createem… * [Baseline JIT] builtins:GetiteratorImm16,Asyncfunctionenter,Createasyn… * [Baseline JIT] builtins:ldsymbol,ldglobal,Poplexenv,Getunmappedargs,Ge… * [BaselineJIT] builtins: add base class !209 handle opcode in baseline compiler * handle opcode in baseline compiler !210 [baseline jit]: add baseline stub call signature target kind info * [baseline jit]: add baseline stub call signature target kind info !212 [BaselineJIT]baseline builtin bugfix * [BaselineJIT]baseline builtin bugfix !207 [BaselineJIT]support BaselineBuiltinFrame * [BaselineJIT]support BaselineBuiltinFrame !214 [BaselineJIT]baseline builtin bugfix of using JSCallDispatch * [BaselineJIT]baseline builtin bugfix JSCallDispatch Change-Id: Id67b991df5dee753a38c284234d15b02f0d8a091 !215 [BaselineJIT]bugfix for StackOffsetDescriptor * [BaselineJIT]bugfix for StackOffsetDescriptor !216 [baseline jit]update bytecode builtins * [baseline jit]update bytecode builtins !213 [BaselineJIT]support BaselineReturn and BaselineReturnundefined * [BaselineJIT]support BaselineReturn and BaselineReturnundefined !218 [BaselineJIT]baseline builtin * [BaselineJIT]baseline builtin:ldfunction,ldthis,asyncgeneratorresolvev… !217 parse baseline-jit bytecode v1.0 * parse bytecode in baseline-jit !220 [BaselineJIT]baseline refactor ParameterIndex * [BaselineJIT]baseline refactor ParameterIndex !223 [BaselineJIT]get function and method from stack, avoiding method is used after call * [BaselineJIT]get function and method from stack, avoiding method is us… !224 [BaselineJIT]bugfix for compiling x64.release * [BaselineJIT]bugfix for compiling x64.release !226 [BaselineJIT] adapt gc for BASELINE_BUILTIN_FRAME type * [BaselineJIT]adapt gc for BASELINE_BUILTIN_FRAME type !222 [BaselineJIT] parse baseline builtin args * [BaselineJIT] parse baseline builtin args:part 2 * [BaselineJIT] parse baseline builtin args !229 parse baseline-jit bytecode v2.0 * [BaselineJIT] parse bytecode v2.0 !230 [BaselineJIT] remove including undefined_function file * [BaselineJIT] remove including undefined_function file !228 handle byte opcode of jmp v2 * [baseline jit]handle opcode of jmp V2 [BaselineJIT]rebase bugfix Change-Id: I078298849139317dfa89fb139979c1b7d938b344 !231 [BaselineJIT] fix bugs about reading bytecode * [BaselineJIT] fix bugs about read bytecode !232 [BaselineJIT] fix bug about processing arguments in stub * [BaselineJIT] fix bug about processing argument in baseline-stubs !233 handle int64_t type in CallBuiltin * [baseline jit]handle int64_t type in CallBuiltin !234 [BaselineJIT] fix bug for StToGlobalRecordImm16ID16 * [BaselineJIT] fix bug for StToGlobalRecordImm16ID16 !235 [BaselineJIT] fix bugs about args type * [BaselineJIT] fix type of args that passing to builtins !236 [BaselineJIT] do not pass constpool to builtins * [BaselineJIT] do not passing constpool to builtin Change-Id: I8c46d70527a3fedd841d28ac1908a02d4a66edeb !237 [baselineJit]Bugfix for sp used in JSCallDispatch and incorretc type * [baselineJit]Bugfix for sp used in JSCallDispatch and incorretc type Change-Id: I3f42ecd06266a20b2b145cfe98bcbd97a2848bab [BaselineJIT] dump_test bugfix Change-Id: I97d21960ca98cd1a6fc9b1e81b647ff9d8d5d0c2 [BaselineJIT]codecheck fix Change-Id: I93eb02e45b70f4a5bfee84fec0c8e2cdc765d348 code check bugfix part2 Change-Id: I8680dd2c098193705709691fa78e8e6f3ad8cd6c bugfix for review Change-Id: I49b28e109530b9f8b403ba22ba39948e02834021 [BaselineJIT]change file folder Change-Id: I1f46110a804f17270badcff7cdeb2058ca164161 [BaselineJIT]bugfix for review part2 Change-Id: I190406652697f9b17ac6c84dd706262046dbb5f7 !238 [BaselineJIT] fix more than 6 args builtins * [BaselineJIT] fix more than 6 args builtins !239 [BaselineJIT] fix bug in parsing CALLTHISRANGE_IMM8_IMM8_V8 * [BaselineJIT] fix bug in parsing CALLTHISRANGE_IMM8_IMM8_V8 !240 [BaselineJIT] fix bug and add NewobjrangeImm8Imm8V8,NewobjrangeImm16Imm8V8 * [BaselineJIT] fix bug and add NewobjrangeImm8Imm8V8,NewobjrangeImm16Imm8V8 !241 [BaselineJIT] fix bug of ldnan, ldinfinity * [BaselineJIT] fix bug of ldnan, ldinfinity !242 [BaselineJIT] return JSCallDispatch result * [BaselineJIT] return result of JSCallDispatch for baselinecode !245 [BaselineJIT] fix builtins return value * [BaselineJIT] fix builtins return value !244 [BaselineJIT] save result to acc * [BaselineJIT] save result to acc !243 Bugfix for StlexvarImm4Imm4 * [baselineJit]Bugfix for StlexvarImm4Imm4 !246 [BaselineJIT] remove ldfunction * [BaselineJIT] remove ldfunction !248 [BaselineJIT] save result of DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8 * [BaselineJIT] fix return !247 [baselineJit]Bugfix for Stlexvar and Ldlexvar * [baselineJit]Bugfix for Stlexvar and Ldlexvar !249 [BaselineJIT] Revert "!242[BaselineJIT] return JSCallDispatch result" * Revert "!242 [BaselineJIT] return JSCallDispatch result" !251 Bugfix for BaselineCreateobjectwithexcludedkeysImm8V8V8 * [baselineJit]Bugfix for BaselineCreateobjectwithexcludedkeysImm8V8V8 !252 [baselineJit]Bugfix for notException branch * [baselineJit]Bugfix for notException branch !250 [BaselineJIT] save result to acc in JSCallDispatch for baselinemethodcode * [BaselineJIT] save result of JSCallDispatch to acc for baselinecode !254 [BaselineJIT] fix type bug * [BaselineJIT] fix type bug !255 [BaselineJIT] fix bug of LDAI_IMM32 * [BaselineJIT] fix bug of LDAI_IMM32 !253 Bugfix for Poplexenv * [baselineJit]Bugfix for Poplexenv !256 [BaselineJIT] fix pc & refractor jscalldispatch for baseline-jit * [BaselineJIT] fix pc of baseline-jit & refactor jscalldispatch for baseline-jit !257 [BaselineJIT] replace indirectly jscalldispatch with jscalldispatchforbaseline * [BaselineJIT] replace indirectly jscalldispatch with jscalldispatchforbaseline !258 [BaselineJIT] fix using shl2 builtin bug * [BaselineJIT] fix using shl2 builtin bug !259 Bugfix and enable BaselineIstrue and BaselineIsFalse * [baselineJit]Bugfix and enable BaselineIstrue and BaselineIsFalse !260 [BaselineJIT] fix bug about passing FUNC parameter * [BaselineJIT] fix bug about passing FUNC parameter !261 [BaselineJIT] support passing parameters by stack and fix offset param bug * [BaselineJIT] support passing parameters by stack and fix offset param bug !263 [BaselineJIT] fix parameters bug of LdobjbyvalueImm16V8 & StobjbyvalueImm16V8V8 * [BaselineJIT] fix parameters bug of LdobjbyvalueImm16V8 & StobjbyvalueImm16V8V8 !262 Bugfix for jump offset * [baselineJit]Bugfix for jump offset !264 [BaselineJIT] fix intermediates v8 parameters bug * [BaselineJIT] fix intermediates v8 parameters bug Change-Id: I8bf4fdf7621770a1976925423de23693570365c9 !267 [BaselineJIT] fix bug of BaselineInstanceofImm8V8 * [BaselineJIT] fix bug of BaselineInstanceofImm8V8 !269 [BaselineJIT] support NEWOBJRANGE_IMM16_IMM8_V8 & fix calling DefineMethod runtimeStub * [BaselineJIT] support NEWOBJRANGE_IMM16_IMM8_V8 & fix calling DefineMe… !268 [BaselineJIT]support update hotness * [BaselineJIT]enable update hotness part2 * [BaselineJIT]support update hotness Change-Id: I24b02a9e015df7263b1e9d7210377add0bfc558c CI bugfix Change-Id: I2d5aef07a1f14b3c64585790cff99d64be0d6396 Signed-off-by: w00443755 <wangzhilei2@huawei.com>
827 lines
21 KiB
C++
827 lines
21 KiB
C++
/*
|
|
* Copyright (c) 2021-2022 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_ECMA_VM_H
|
|
#define ECMASCRIPT_ECMA_VM_H
|
|
|
|
#include <mutex>
|
|
|
|
#include "ecmascript/base/config.h"
|
|
#include "ecmascript/builtins/builtins_method_index.h"
|
|
#include "ecmascript/ecma_context.h"
|
|
#include "ecmascript/js_runtime_options.h"
|
|
#include "ecmascript/js_thread.h"
|
|
#include "ecmascript/mem/c_containers.h"
|
|
#include "ecmascript/mem/c_string.h"
|
|
#include "ecmascript/mem/gc_stats.h"
|
|
#include "ecmascript/mem/gc_key_stats.h"
|
|
#include "ecmascript/napi/include/dfx_jsnapi.h"
|
|
#include "ecmascript/napi/include/jsnapi.h"
|
|
#include "ecmascript/pgo_profiler/pgo_profiler.h"
|
|
#include "ecmascript/taskpool/taskpool.h"
|
|
|
|
namespace panda {
|
|
class JSNApi;
|
|
struct HmsMap;
|
|
namespace panda_file {
|
|
class File;
|
|
} // namespace panda_file
|
|
|
|
namespace ecmascript {
|
|
class GlobalEnv;
|
|
class ObjectFactory;
|
|
class RegExpParserCache;
|
|
class EcmaRuntimeStat;
|
|
class Heap;
|
|
class HeapTracker;
|
|
class JSNativePointer;
|
|
class Program;
|
|
class GCStats;
|
|
class GCKeyStats;
|
|
class CpuProfiler;
|
|
class Tracing;
|
|
class RegExpExecResultCache;
|
|
class JSPromise;
|
|
enum class PromiseRejectionEvent : uint8_t;
|
|
enum class Concurrent { YES, NO };
|
|
class JSPandaFileManager;
|
|
class JSPandaFile;
|
|
class EcmaStringTable;
|
|
class SnapshotEnv;
|
|
class SnapshotSerialize;
|
|
class SnapshotProcessor;
|
|
using PGOProfiler = pgo::PGOProfiler;
|
|
#if !WIN_OR_MAC_OR_IOS_PLATFORM
|
|
class HeapProfilerInterface;
|
|
class HeapProfiler;
|
|
#endif
|
|
namespace job {
|
|
class MicroJobQueue;
|
|
} // namespace job
|
|
|
|
namespace tooling {
|
|
class JsDebuggerManager;
|
|
} // namespace tooling
|
|
|
|
template<typename T>
|
|
class JSHandle;
|
|
class JSArrayBuffer;
|
|
class JSFunction;
|
|
class SourceTextModule;
|
|
class Program;
|
|
class AOTFileManager;
|
|
class SlowRuntimeStub;
|
|
class RequireManager;
|
|
class QuickFixManager;
|
|
class ConstantPool;
|
|
class FunctionCallTimer;
|
|
class EcmaStringTable;
|
|
class JSObjectResizingStrategy;
|
|
class Jit;
|
|
class JitThread;
|
|
|
|
using NativePtrGetter = void* (*)(void* info);
|
|
using SourceMapCallback = std::function<std::string(const std::string& rawStack)>;
|
|
using SourceMapTranslateCallback = std::function<bool(std::string& url, int& line, int& column)>;
|
|
using ResolveBufferCallback = std::function<bool(std::string dirPath, uint8_t **buff, size_t *buffSize)>;
|
|
using UnloadNativeModuleCallback = std::function<bool(const std::string &moduleKey)>;
|
|
using RequestAotCallback =
|
|
std::function<int32_t(const std::string &bundleName, const std::string &moduleName, int32_t triggerMode)>;
|
|
using SearchHapPathCallBack = std::function<bool(const std::string moduleName, std::string &hapPath)>;
|
|
using DeviceDisconnectCallback = std::function<bool()>;
|
|
using UncatchableErrorHandler = std::function<void(panda::TryCatch&)>;
|
|
using DeleteEntryPoint = void (*)(void *, void *);
|
|
class EcmaVM {
|
|
public:
|
|
static EcmaVM *Create(const JSRuntimeOptions &options);
|
|
|
|
static bool Destroy(EcmaVM *vm);
|
|
|
|
EcmaVM(JSRuntimeOptions options, EcmaParamConfiguration config);
|
|
|
|
EcmaVM();
|
|
|
|
virtual ~EcmaVM();
|
|
|
|
void SetLoop(void *loop)
|
|
{
|
|
loop_ = loop;
|
|
}
|
|
|
|
void *GetLoop() const
|
|
{
|
|
return loop_;
|
|
}
|
|
|
|
bool IsInitialized() const
|
|
{
|
|
return initialized_;
|
|
}
|
|
|
|
ObjectFactory *GetFactory() const
|
|
{
|
|
return factory_;
|
|
}
|
|
|
|
void InitializePGOProfiler();
|
|
void ResetPGOProfiler();
|
|
|
|
bool PUBLIC_API IsEnablePGOProfiler() const;
|
|
bool PUBLIC_API IsEnableElementsKind() const;
|
|
|
|
bool Initialize();
|
|
void InitializeForJit(JitThread *thread);
|
|
|
|
GCStats *GetEcmaGCStats() const
|
|
{
|
|
return gcStats_;
|
|
}
|
|
|
|
GCKeyStats *GetEcmaGCKeyStats() const
|
|
{
|
|
return gcKeyStats_;
|
|
}
|
|
|
|
JSThread *GetAssociatedJSThread() const
|
|
{
|
|
return thread_;
|
|
}
|
|
|
|
JSRuntimeOptions &GetJSOptions()
|
|
{
|
|
return options_;
|
|
}
|
|
|
|
const EcmaParamConfiguration &GetEcmaParamConfiguration() const
|
|
{
|
|
return ecmaParamConfiguration_;
|
|
}
|
|
|
|
JSHandle<GlobalEnv> PUBLIC_API GetGlobalEnv() const;
|
|
|
|
static EcmaVM *ConstCast(const EcmaVM *vm)
|
|
{
|
|
return const_cast<EcmaVM *>(vm);
|
|
}
|
|
|
|
void CheckThread() const
|
|
{
|
|
// Exclude GC thread
|
|
if (thread_ == nullptr) {
|
|
LOG_FULL(FATAL) << "Fatal: ecma_vm has been destructed! vm address is: " << this;
|
|
}
|
|
if (!Taskpool::GetCurrentTaskpool()->IsInThreadPool(std::this_thread::get_id()) &&
|
|
thread_->GetThreadId() != JSThread::GetCurrentThreadId() && !thread_->IsCrossThreadExecutionEnable()) {
|
|
LOG_FULL(FATAL) << "Fatal: ecma_vm cannot run in multi-thread!"
|
|
<< " thread:" << thread_->GetThreadId()
|
|
<< " currentThread:" << JSThread::GetCurrentThreadId();
|
|
}
|
|
}
|
|
|
|
JSThread *GetAndFastCheckJSThread() const
|
|
{
|
|
if (thread_ == nullptr) {
|
|
LOG_FULL(FATAL) << "Fatal: ecma_vm has been destructed! vm address is: " << this;
|
|
}
|
|
if (thread_->GetThreadId() != JSThread::GetCurrentThreadId() && !thread_->IsCrossThreadExecutionEnable()) {
|
|
LOG_FULL(FATAL) << "Fatal: ecma_vm cannot run in multi-thread!"
|
|
<< " thread:" << thread_->GetThreadId()
|
|
<< " currentThread:" << JSThread::GetCurrentThreadId();
|
|
}
|
|
return thread_;
|
|
}
|
|
|
|
ARK_INLINE JSThread *GetJSThread() const
|
|
{
|
|
if (options_.EnableThreadCheck()) {
|
|
CheckThread();
|
|
}
|
|
return thread_;
|
|
}
|
|
|
|
bool ICEnabled() const
|
|
{
|
|
return icEnabled_;
|
|
}
|
|
|
|
void PushToNativePointerList(JSNativePointer *pointer, Concurrent isConcurrent = Concurrent::NO);
|
|
void RemoveFromNativePointerList(JSNativePointer *pointer);
|
|
void PushToDeregisterModuleList(CString module);
|
|
void RemoveFromDeregisterModuleList(CString module);
|
|
bool ContainInDeregisterModuleList(CString module);
|
|
JSHandle<ecmascript::JSTaggedValue> GetAndClearEcmaUncaughtException() const;
|
|
JSHandle<ecmascript::JSTaggedValue> GetEcmaUncaughtException() const;
|
|
bool IsOptionalLogEnabled() const
|
|
{
|
|
return optionalLogEnabled_;
|
|
}
|
|
|
|
void Iterate(const RootVisitor &v, const RootRangeVisitor &rv);
|
|
|
|
const Heap *GetHeap() const
|
|
{
|
|
return heap_;
|
|
}
|
|
void CollectGarbage(TriggerGCType gcType, GCReason reason = GCReason::OTHER) const;
|
|
|
|
NativeAreaAllocator *GetNativeAreaAllocator() const
|
|
{
|
|
return nativeAreaAllocator_.get();
|
|
}
|
|
|
|
HeapRegionAllocator *GetHeapRegionAllocator() const
|
|
{
|
|
return heapRegionAllocator_.get();
|
|
}
|
|
|
|
Chunk *GetChunk() const
|
|
{
|
|
return const_cast<Chunk *>(&chunk_);
|
|
}
|
|
void ProcessNativeDelete(const WeakRootVisitor &visitor);
|
|
void ProcessReferences(const WeakRootVisitor &visitor);
|
|
|
|
void PushToSharedNativePointerList(JSNativePointer *pointer);
|
|
void ProcessSharedNativeDelete(const WeakRootVisitor &visitor);
|
|
|
|
SnapshotEnv *GetSnapshotEnv() const
|
|
{
|
|
return snapshotEnv_;
|
|
}
|
|
|
|
tooling::JsDebuggerManager *GetJsDebuggerManager() const
|
|
{
|
|
return debuggerManager_;
|
|
}
|
|
|
|
void SetDeviceDisconnectCallback(DeviceDisconnectCallback cb)
|
|
{
|
|
deviceDisconnectCallback_ = cb;
|
|
}
|
|
|
|
DeviceDisconnectCallback GetDeviceDisconnectCallback() const
|
|
{
|
|
return deviceDisconnectCallback_;
|
|
}
|
|
|
|
void SetEnableForceGC(bool enable)
|
|
{
|
|
options_.SetEnableForceGC(enable);
|
|
}
|
|
|
|
void SetNativePtrGetter(NativePtrGetter cb)
|
|
{
|
|
nativePtrGetter_ = cb;
|
|
}
|
|
|
|
NativePtrGetter GetNativePtrGetter() const
|
|
{
|
|
return nativePtrGetter_;
|
|
}
|
|
|
|
void SetSourceMapCallback(SourceMapCallback cb)
|
|
{
|
|
sourceMapCallback_ = cb;
|
|
}
|
|
|
|
SourceMapCallback GetSourceMapCallback() const
|
|
{
|
|
return sourceMapCallback_;
|
|
}
|
|
|
|
void SetSourceMapTranslateCallback(SourceMapTranslateCallback cb)
|
|
{
|
|
sourceMapTranslateCallback_ = cb;
|
|
}
|
|
|
|
SourceMapTranslateCallback GetSourceMapTranslateCallback() const
|
|
{
|
|
return sourceMapTranslateCallback_;
|
|
}
|
|
|
|
size_t GetNativePointerListSize()
|
|
{
|
|
return nativePointerList_.size();
|
|
}
|
|
|
|
const CList<JSNativePointer *> GetNativePointerList() const
|
|
{
|
|
return nativePointerList_;
|
|
}
|
|
|
|
size_t GetConcurrentNativePointerListSize() const
|
|
{
|
|
return concurrentNativePointerList_.size();
|
|
}
|
|
|
|
void SetResolveBufferCallback(ResolveBufferCallback cb)
|
|
{
|
|
resolveBufferCallback_ = cb;
|
|
}
|
|
|
|
ResolveBufferCallback GetResolveBufferCallback() const
|
|
{
|
|
return resolveBufferCallback_;
|
|
}
|
|
|
|
void SetSearchHapPathCallBack(SearchHapPathCallBack cb)
|
|
{
|
|
SearchHapPathCallBack_ = cb;
|
|
}
|
|
|
|
SearchHapPathCallBack GetSearchHapPathCallBack() const
|
|
{
|
|
return SearchHapPathCallBack_;
|
|
}
|
|
|
|
void SetUnloadNativeModuleCallback(const UnloadNativeModuleCallback &cb)
|
|
{
|
|
unloadNativeModuleCallback_ = cb;
|
|
}
|
|
|
|
UnloadNativeModuleCallback GetUnloadNativeModuleCallback() const
|
|
{
|
|
return unloadNativeModuleCallback_;
|
|
}
|
|
|
|
void SetConcurrentCallback(ConcurrentCallback callback, void *data)
|
|
{
|
|
concurrentCallback_ = callback;
|
|
concurrentData_ = data;
|
|
}
|
|
|
|
void TriggerConcurrentCallback(JSTaggedValue result, JSTaggedValue hint);
|
|
|
|
void WorkersetInfo(EcmaVM *workerVm);
|
|
|
|
EcmaVM *GetWorkerVm(uint32_t tid);
|
|
|
|
bool DeleteWorker(EcmaVM *workerVm);
|
|
|
|
bool SuspendWorkerVm(uint32_t tid);
|
|
|
|
void ResumeWorkerVm(uint32_t tid);
|
|
|
|
template<typename Callback>
|
|
void EnumerateWorkerVm(Callback cb)
|
|
{
|
|
// since there is a lock, so cannot mark function const
|
|
LockHolder lock(mutex_);
|
|
for (const auto &item : workerList_) {
|
|
cb(item.second);
|
|
}
|
|
}
|
|
|
|
bool IsWorkerThread() const
|
|
{
|
|
return options_.IsWorker();
|
|
}
|
|
|
|
bool IsBundlePack() const
|
|
{
|
|
return isBundlePack_;
|
|
}
|
|
|
|
void SetIsBundlePack(bool value)
|
|
{
|
|
isBundlePack_ = value;
|
|
}
|
|
|
|
// UnifiedOhmUrlPack means app compiles ohmurl using old format like "@bundle:",
|
|
// or new unified rules like "@normalize:"
|
|
// if pkgContextInfoList is empty, means use old ohmurl packing.
|
|
bool IsNormalizedOhmUrlPack() const
|
|
{
|
|
return !pkgContextInfoList_.empty();
|
|
}
|
|
|
|
void SetPkgNameList(const std::map<std::string, std::string> &list)
|
|
{
|
|
for (auto it = list.begin(); it != list.end(); ++it) {
|
|
pkgNameList_.emplace(it->first.c_str(), it->second.c_str());
|
|
}
|
|
}
|
|
|
|
inline CString GetPkgName(const CString &moduleName) const
|
|
{
|
|
auto it = pkgNameList_.find(moduleName);
|
|
if (it == pkgNameList_.end()) {
|
|
LOG_ECMA(ERROR) << " Get Pkg Name failed";
|
|
return "";
|
|
}
|
|
return it->second;
|
|
}
|
|
|
|
inline CMap<CString, CMap<CString, CVector<CString>>> GetPkgContextInfoLit() const
|
|
{
|
|
return pkgContextInfoList_;
|
|
}
|
|
|
|
inline CString GetPkgNameWithAlias(const CString &alias) const
|
|
{
|
|
auto it = pkgAliasList_.find(alias);
|
|
if (it == pkgAliasList_.end()) {
|
|
return alias;
|
|
}
|
|
return it->second;
|
|
}
|
|
|
|
void SetPkgAliasList(const std::map<std::string, std::string> &list)
|
|
{
|
|
for (auto it = list.begin(); it != list.end(); ++it) {
|
|
pkgAliasList_.emplace(it->first.c_str(), it->second.c_str());
|
|
}
|
|
}
|
|
|
|
void SetMockModuleList(const std::map<std::string, std::string> &list)
|
|
{
|
|
for (auto it = list.begin(); it != list.end(); ++it) {
|
|
mockModuleList_.emplace(it->first.c_str(), it->second.c_str());
|
|
}
|
|
}
|
|
|
|
inline bool IsMockModule(const CString &moduleStr) const
|
|
{
|
|
if (mockModuleList_.empty()) {
|
|
return false;
|
|
}
|
|
auto it = mockModuleList_.find(moduleStr);
|
|
if (it == mockModuleList_.end()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
inline CString GetMockModule(const CString &module) const
|
|
{
|
|
auto it = mockModuleList_.find(module);
|
|
if (it == mockModuleList_.end()) {
|
|
LOG_ECMA(FATAL) << " Get Mock Module failed";
|
|
}
|
|
return it->second;
|
|
}
|
|
|
|
#if defined(ECMASCRIPT_SUPPORT_HEAPPROFILER)
|
|
void DeleteHeapProfile();
|
|
HeapProfilerInterface *GetHeapProfile();
|
|
void SetHeapProfile(HeapProfilerInterface *heapProfile) { heapProfile_ = heapProfile; }
|
|
HeapProfilerInterface *GetOrNewHeapProfile();
|
|
void StartHeapTracking();
|
|
void StopHeapTracking();
|
|
#endif
|
|
|
|
bool EnableReportModuleResolvingFailure() const
|
|
{
|
|
return options_.EnableReportModuleResolvingFailure();
|
|
}
|
|
|
|
void SetAssetPath(const CString &assetPath)
|
|
{
|
|
assetPath_ = assetPath;
|
|
}
|
|
|
|
CString GetAssetPath() const
|
|
{
|
|
return assetPath_;
|
|
}
|
|
|
|
void SetBundleName(const CString &bundleName)
|
|
{
|
|
bundleName_ = bundleName;
|
|
}
|
|
|
|
CString GetBundleName() const
|
|
{
|
|
return bundleName_;
|
|
}
|
|
|
|
void SetModuleName(const CString &moduleName)
|
|
{
|
|
moduleName_ = moduleName;
|
|
}
|
|
|
|
CString GetModuleName() const
|
|
{
|
|
return moduleName_;
|
|
}
|
|
|
|
std::pair<std::string, std::string> GetCurrentModuleInfo(bool needRecordName = false);
|
|
|
|
void SetHmsModuleList(const std::vector<panda::HmsMap> &list);
|
|
|
|
bool IsHmsModule(const CString &moduleStr) const;
|
|
|
|
CString GetHmsModule(const CString &module) const;
|
|
|
|
void SetpkgContextInfoList(const std::map<std::string, std::vector<std::vector<std::string>>> &list);
|
|
|
|
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
|
|
CpuProfiler *GetProfiler() const
|
|
{
|
|
return profiler_;
|
|
}
|
|
|
|
void SetProfiler(CpuProfiler *profiler)
|
|
{
|
|
profiler_ = profiler;
|
|
}
|
|
#endif
|
|
|
|
#if defined(ECMASCRIPT_SUPPORT_TRACING)
|
|
Tracing *GetTracing() const
|
|
{
|
|
return tracing_;
|
|
}
|
|
|
|
void SetTracing(Tracing *tracing)
|
|
{
|
|
tracing_ = tracing;
|
|
}
|
|
#endif
|
|
|
|
std::shared_ptr<PGOProfiler> GetPGOProfiler() const
|
|
{
|
|
return pgoProfiler_;
|
|
}
|
|
|
|
void PreFork();
|
|
void PostFork();
|
|
|
|
// For Internal Native MethodLiteral.
|
|
JSTaggedValue GetMethodByIndex(MethodIndex idx);
|
|
|
|
QuickFixManager *GetQuickFixManager() const
|
|
{
|
|
return quickFixManager_;
|
|
}
|
|
|
|
JSTaggedValue FastCallAot(size_t actualNumArgs, JSTaggedType *args, const JSTaggedType *prevFp);
|
|
|
|
void RegisterUncatchableErrorHandler(const UncatchableErrorHandler &uncatchableErrorHandler)
|
|
{
|
|
uncatchableErrorHandler_ = uncatchableErrorHandler;
|
|
}
|
|
|
|
// handle uncatchable errors, such as oom
|
|
void HandleUncatchableError()
|
|
{
|
|
if (uncatchableErrorHandler_ != nullptr) {
|
|
panda::TryCatch trycatch(this);
|
|
uncatchableErrorHandler_(trycatch);
|
|
}
|
|
}
|
|
|
|
void DumpCallTimeInfo();
|
|
|
|
FunctionCallTimer *GetCallTimer() const
|
|
{
|
|
return callTimer_;
|
|
}
|
|
|
|
EcmaStringTable *GetEcmaStringTable() const
|
|
{
|
|
ASSERT(stringTable_ != nullptr);
|
|
return stringTable_;
|
|
}
|
|
|
|
void IncreaseCallDepth()
|
|
{
|
|
callDepth_++;
|
|
}
|
|
|
|
void DecreaseCallDepth()
|
|
{
|
|
ASSERT(callDepth_ > 0);
|
|
callDepth_--;
|
|
}
|
|
|
|
bool IsTopLevelCallDepth()
|
|
{
|
|
return callDepth_ == 0;
|
|
}
|
|
|
|
void SetProfilerState(bool state)
|
|
{
|
|
isProfiling_ = state;
|
|
}
|
|
|
|
bool GetProfilerState()
|
|
{
|
|
return isProfiling_;
|
|
}
|
|
|
|
JSObjectResizingStrategy *GetJSObjectResizingStrategy()
|
|
{
|
|
return strategy_;
|
|
}
|
|
|
|
CMap<uint32_t, EcmaVM *> GetWorkList() const
|
|
{
|
|
return workerList_;
|
|
}
|
|
|
|
Jit *GetJit() const;
|
|
bool PUBLIC_API IsEnableFastJit() const;
|
|
bool PUBLIC_API IsEnableBaselineJit() const;
|
|
void EnableJit();
|
|
|
|
bool IsEnableOsr() const
|
|
{
|
|
return isEnableOsr_;
|
|
}
|
|
|
|
void SetEnableOsr(bool state)
|
|
{
|
|
isEnableOsr_ = state;
|
|
}
|
|
|
|
bool isOverLimit() const
|
|
{
|
|
return overLimit_;
|
|
}
|
|
|
|
void SetOverLimit(bool state)
|
|
{
|
|
overLimit_ = state;
|
|
}
|
|
|
|
AOTFileManager *GetAOTFileManager() const
|
|
{
|
|
return aotFileManager_;
|
|
}
|
|
|
|
uint32_t GetTid() const
|
|
{
|
|
return thread_->GetThreadId();
|
|
}
|
|
|
|
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> &GetNativePointerCallbacks()
|
|
{
|
|
return nativePointerCallbacks_;
|
|
}
|
|
|
|
void SetIsJitCompileVM(bool isJitCompileVM)
|
|
{
|
|
isJitCompileVM_ = isJitCompileVM;
|
|
}
|
|
|
|
bool IsJitCompileVM() const
|
|
{
|
|
return isJitCompileVM_;
|
|
}
|
|
|
|
static void InitializeIcuData(const JSRuntimeOptions &options);
|
|
|
|
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> &GetSharedNativePointerCallbacks()
|
|
{
|
|
return sharedNativePointerCallbacks_;
|
|
}
|
|
|
|
void *GetEnv() const
|
|
{
|
|
return env_;
|
|
}
|
|
|
|
void SetEnv(void *env)
|
|
{
|
|
env_ = env;
|
|
}
|
|
|
|
protected:
|
|
|
|
void PrintJSErrorInfo(const JSHandle<JSTaggedValue> &exceptionInfo) const;
|
|
|
|
private:
|
|
void ClearBufferData();
|
|
void CheckStartCpuProfiler();
|
|
|
|
// For Internal Native MethodLiteral.
|
|
void GenerateInternalNativeMethods();
|
|
|
|
NO_MOVE_SEMANTIC(EcmaVM);
|
|
NO_COPY_SEMANTIC(EcmaVM);
|
|
|
|
// VM startup states.
|
|
JSRuntimeOptions options_;
|
|
bool icEnabled_ {true};
|
|
bool initialized_ {false};
|
|
GCStats *gcStats_ {nullptr};
|
|
GCKeyStats *gcKeyStats_ {nullptr};
|
|
EcmaStringTable *stringTable_ {nullptr};
|
|
|
|
// VM memory management.
|
|
std::unique_ptr<NativeAreaAllocator> nativeAreaAllocator_;
|
|
std::unique_ptr<HeapRegionAllocator> heapRegionAllocator_;
|
|
Chunk chunk_;
|
|
Heap *heap_ {nullptr};
|
|
ObjectFactory *factory_ {nullptr};
|
|
CList<JSNativePointer *> nativePointerList_;
|
|
CList<JSNativePointer *> concurrentNativePointerList_;
|
|
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> nativePointerCallbacks_ {};
|
|
CList<JSNativePointer *> sharedNativePointerList_;
|
|
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> sharedNativePointerCallbacks_ {};
|
|
// VM execution states.
|
|
JSThread *thread_ {nullptr};
|
|
|
|
// VM resources.
|
|
SnapshotEnv *snapshotEnv_ {nullptr};
|
|
bool optionalLogEnabled_ {false};
|
|
// Debugger
|
|
tooling::JsDebuggerManager *debuggerManager_ {nullptr};
|
|
// isBundle means app compile mode is JSBundle
|
|
bool isBundlePack_ {true};
|
|
#if !WIN_OR_MAC_OR_IOS_PLATFORM
|
|
HeapProfilerInterface *heapProfile_ {nullptr};
|
|
#endif
|
|
CString assetPath_;
|
|
CString bundleName_;
|
|
CString moduleName_;
|
|
CList<CString> deregisterModuleList_;
|
|
CMap<CString, CString> mockModuleList_;
|
|
CMap<CString, HmsMap> hmsModuleList_;
|
|
CMap<CString, CString> pkgNameList_;
|
|
CMap<CString, CMap<CString, CVector<CString>>> pkgContextInfoList_;
|
|
CMap<CString, CString> pkgAliasList_;
|
|
NativePtrGetter nativePtrGetter_ {nullptr};
|
|
SourceMapCallback sourceMapCallback_ {nullptr};
|
|
SourceMapTranslateCallback sourceMapTranslateCallback_ {nullptr};
|
|
void *loop_ {nullptr};
|
|
|
|
// resolve path to get abc's buffer
|
|
ResolveBufferCallback resolveBufferCallback_ {nullptr};
|
|
|
|
// delete the native module and dlclose so from NativeModuleManager
|
|
UnloadNativeModuleCallback unloadNativeModuleCallback_ {nullptr};
|
|
|
|
// Concurrent taskpool callback and data
|
|
ConcurrentCallback concurrentCallback_ {nullptr};
|
|
void *concurrentData_ {nullptr};
|
|
|
|
// serch happath callback
|
|
SearchHapPathCallBack SearchHapPathCallBack_ {nullptr};
|
|
|
|
// vm parameter configurations
|
|
EcmaParamConfiguration ecmaParamConfiguration_;
|
|
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
|
|
CpuProfiler *profiler_ {nullptr};
|
|
#endif
|
|
#if defined(ECMASCRIPT_SUPPORT_TRACING)
|
|
Tracing *tracing_ {nullptr};
|
|
#endif
|
|
FunctionCallTimer *callTimer_ {nullptr};
|
|
JSObjectResizingStrategy *strategy_ {nullptr};
|
|
|
|
// For Native MethodLiteral
|
|
static void *InternalMethodTable[static_cast<uint8_t>(MethodIndex::METHOD_END)];
|
|
CVector<JSTaggedValue> internalNativeMethods_;
|
|
|
|
// For repair patch.
|
|
QuickFixManager *quickFixManager_ {nullptr};
|
|
|
|
// PGO Profiler
|
|
std::shared_ptr<PGOProfiler> pgoProfiler_ {nullptr};
|
|
|
|
//AOT File Manager
|
|
AOTFileManager *aotFileManager_ {nullptr};
|
|
|
|
// c++ call js
|
|
size_t callDepth_ {0};
|
|
|
|
bool isProfiling_ {false};
|
|
|
|
DeviceDisconnectCallback deviceDisconnectCallback_ {nullptr};
|
|
|
|
UncatchableErrorHandler uncatchableErrorHandler_ {nullptr};
|
|
|
|
friend class Snapshot;
|
|
friend class SnapshotProcessor;
|
|
friend class ObjectFactory;
|
|
friend class ValueSerializer;
|
|
friend class panda::JSNApi;
|
|
friend class JSPandaFileExecutor;
|
|
friend class EcmaContext;
|
|
friend class JitVM;
|
|
CMap<uint32_t, EcmaVM *> workerList_ {};
|
|
Mutex mutex_;
|
|
bool isEnableOsr_ {false};
|
|
bool isJitCompileVM_ {false};
|
|
bool overLimit_ {false};
|
|
void *env_ = nullptr;
|
|
};
|
|
} // namespace ecmascript
|
|
} // namespace panda
|
|
|
|
#endif
|