!3146 Encapsulate some interface in PandaFile

Merge pull request !3146 from weng-changcheng/refactor_file
This commit is contained in:
openharmony_ci 2023-01-05 07:14:36 +00:00 committed by Gitee
commit 14a8c96338
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
64 changed files with 189 additions and 252 deletions

View File

@ -383,7 +383,7 @@ void AOTFileManager::LoadSnapshotFile([[maybe_unused]] const std::string& filena
const std::shared_ptr<AnFileInfo> AOTFileManager::GetAnFileInfo(const JSPandaFile *jsPandaFile) const
{
uint32_t index = GetAnFileIndex(jsPandaFile);
if (index == JSPandaFile::INVALID_INDEX) {
if (index == INVALID_INDEX) {
return nullptr;
}
AnFileDataManager *anFileDataManager = AnFileDataManager::GetInstance();
@ -426,7 +426,7 @@ uint32_t AOTFileManager::GetAnFileIndex(const JSPandaFile *jsPandaFile) const
std::string jsPandaFileDesc = jsPandaFile->GetJSPandaFileDesc().c_str();
std::string baseName = JSFilePath::GetFileName(jsPandaFileDesc);
if (baseName.empty()) {
return JSPandaFile::INVALID_INDEX;
return INVALID_INDEX;
}
std::string anFileName = baseName + FILE_EXTENSION_AN;
return anFileDataManager->SafeGetFileInfoIndex(anFileName);
@ -435,7 +435,7 @@ uint32_t AOTFileManager::GetAnFileIndex(const JSPandaFile *jsPandaFile) const
// run from app hap
std::string hapName = JSFilePath::GetHapName(jsPandaFile);
if (hapName.empty()) {
return JSPandaFile::INVALID_INDEX;
return INVALID_INDEX;
}
std::string anFileName = hapName + FILE_EXTENSION_AN;
return anFileDataManager->SafeGetFileInfoIndex(anFileName);
@ -834,7 +834,7 @@ uint32_t AnFileDataManager::SafeGetFileInfoIndex(const std::string &fileName)
os::memory::ReadLockHolder lock(lock_);
auto iter = anFileNameToIndexMap_.find(fileName);
if (iter == anFileNameToIndexMap_.end()) {
return JSPandaFile::INVALID_INDEX;
return INVALID_INDEX;
}
return anFileNameToIndexMap_.at(fileName);
}

View File

@ -17,7 +17,7 @@
#include "ecmascript/base/atomic_helper.h"
#include "ecmascript/base/typed_array_helper-inl.h"
#include "utils/time.h"
#include "libpandabase/utils/time.h"
namespace panda::ecmascript::builtins {
using NumberHelper = base::NumberHelper;

View File

@ -40,6 +40,7 @@ enum TriggerGCType {
};
constexpr uint32_t NUM_MANDATORY_JSFUNC_ARGS = 3;
constexpr uint32_t INVALID_INDEX = std::numeric_limits<uint32_t>::max();
using Address = uintptr_t;

View File

@ -22,7 +22,6 @@
#include "ecmascript/compiler/trampoline/aarch64/common_call.h"
#include "ecmascript/compiler/trampoline/x64/common_call.h"
#include "ecmascript/compiler/rt_call_signature.h"
#include "libpandafile/bytecode_instruction-inl.h"
namespace panda::ecmascript::kungfu {
void AssemblerModule::Run(const CompilationConfig *cfg, Chunk* chunk)

View File

@ -100,8 +100,9 @@ void BytecodeCircuitBuilder::CollectRegionInfo(uint32_t bcIndex)
void BytecodeCircuitBuilder::CollectTryCatchBlockInfo(ExceptionInfo &byteCodeException)
{
panda_file::MethodDataAccessor mda(*pf_, method_->GetMethodId());
panda_file::CodeDataAccessor cda(*pf_, mda.GetCodeId().value());
auto pf = file_->GetPandaFile();
panda_file::MethodDataAccessor mda(*pf, method_->GetMethodId());
panda_file::CodeDataAccessor cda(*pf, mda.GetCodeId().value());
cda.EnumerateTryBlocks([this, &byteCodeException](
panda_file::CodeDataAccessor::TryBlock &tryBlock) {

View File

@ -264,7 +264,7 @@ public:
bool enableTypeLowering,
std::string name,
const CString &recordName)
: tsManager_(tsManager), circuit_(circuit), file_(jsPandaFile), pf_(jsPandaFile->GetPandaFile()),
: tsManager_(tsManager), circuit_(circuit), file_(jsPandaFile),
method_(methodLiteral), gateAcc_(circuit), argAcc_(circuit, method_),
typeRecorder_(jsPandaFile, method_, tsManager, recordName), hasTypes_(hasTypes),
enableLog_(enableLog), enableTypeLowering_(enableTypeLowering),
@ -455,7 +455,6 @@ private:
std::vector<GateRef> byteCodeToJSGate_;
BytecodeGraph graph_;
const JSPandaFile *file_ {nullptr};
const panda_file::File *pf_ {nullptr};
const MethodLiteral *method_ {nullptr};
GateAccessor gateAcc_;
ArgumentAccessor argAcc_;

View File

@ -42,7 +42,7 @@ void BytecodeInfoCollector::ProcessClasses()
for (const uint32_t index : classIndexes) {
panda_file::File::EntityId classId(index);
if (pf->IsExternal(classId)) {
if (jsPandaFile_->IsExternal(classId)) {
continue;
}
panda_file::ClassDataAccessor cda(*pf, classId);
@ -55,7 +55,7 @@ void BytecodeInfoCollector::ProcessClasses()
vm_->FindOrCreateConstPool(jsPandaFile_, methodId);
auto methodOffset = methodId.GetOffset();
CString name = reinterpret_cast<const char *>(pf->GetStringData(mda.GetNameId()).data);
CString name = reinterpret_cast<const char *>(jsPandaFile_->GetStringData(mda.GetNameId()).data);
if (JSPandaFile::IsEntryOrPatch(name)) {
const CString recordName = jsPandaFile_->ParseEntryPoint(desc);
jsPandaFile_->UpdateMainMethodIndex(methodOffset, recordName);
@ -289,7 +289,6 @@ void BytecodeInfoCollector::CollectMethodInfoFromBC(const BytecodeInstruction &b
const MethodLiteral *method, std::vector<std::string> &classNameVec,
int32_t bcIndex)
{
const panda_file::File *pf = jsPandaFile_->GetPandaFile();
if (!(bcIns.HasFlag(BytecodeInstruction::Flags::STRING_ID) &&
BytecodeInstruction::HasId(BytecodeInstruction::GetFormat(bcIns.GetOpcode()), 0))) {
BytecodeInstruction::Opcode opcode = static_cast<BytecodeInstruction::Opcode>(bcIns.GetOpcode());
@ -297,46 +296,46 @@ void BytecodeInfoCollector::CollectMethodInfoFromBC(const BytecodeInstruction &b
uint32_t methodId;
case BytecodeInstruction::Opcode::DEFINEFUNC_IMM8_ID16_IMM8:
case BytecodeInstruction::Opcode::DEFINEFUNC_IMM16_ID16_IMM8: {
methodId = pf->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue())).GetOffset();
methodId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue())).GetOffset();
CollectInnerMethods(method, methodId);
break;
}
case BytecodeInstruction::Opcode::DEFINEMETHOD_IMM8_ID16_IMM8:
case BytecodeInstruction::Opcode::DEFINEMETHOD_IMM16_ID16_IMM8: {
methodId = pf->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue())).GetOffset();
methodId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue())).GetOffset();
CollectInnerMethods(method, methodId);
break;
}
case BytecodeInstruction::Opcode::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:{
auto entityId = pf->ResolveMethodIndex(method->GetMethodId(),
auto entityId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
(bcIns.GetId <BytecodeInstruction::Format::IMM8_ID16_ID16_IMM16_V8, 0>()).AsRawValue());
classNameVec.emplace_back(GetClassName(entityId));
classDefBCIndexes_.insert(bcIndex);
methodId = entityId.GetOffset();
CollectInnerMethods(method, methodId);
auto literalId = pf->ResolveMethodIndex(method->GetMethodId(),
auto literalId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
(bcIns.GetId <BytecodeInstruction::Format::IMM8_ID16_ID16_IMM16_V8, 1>()).AsRawValue());
CollectInnerMethodsFromNewLiteral(method, literalId);
break;
}
case BytecodeInstruction::Opcode::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8: {
auto entityId = pf->ResolveMethodIndex(method->GetMethodId(),
auto entityId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
(bcIns.GetId <BytecodeInstruction::Format::IMM16_ID16_ID16_IMM16_V8, 0>()).AsRawValue());
classNameVec.emplace_back(GetClassName(entityId));
classDefBCIndexes_.insert(bcIndex);
methodId = entityId.GetOffset();
CollectInnerMethods(method, methodId);
auto literalId = pf->ResolveMethodIndex(method->GetMethodId(),
auto literalId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
(bcIns.GetId <BytecodeInstruction::Format::IMM16_ID16_ID16_IMM16_V8, 1>()).AsRawValue());
CollectInnerMethodsFromNewLiteral(method, literalId);
break;
}
case BytecodeInstruction::Opcode::CREATEARRAYWITHBUFFER_IMM8_ID16:
case BytecodeInstruction::Opcode::CREATEARRAYWITHBUFFER_IMM16_ID16: {
auto literalId = pf->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue()));
auto literalId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue()));
CollectInnerMethodsFromNewLiteral(method, literalId);
break;
}
@ -347,8 +346,8 @@ void BytecodeInfoCollector::CollectMethodInfoFromBC(const BytecodeInstruction &b
}
case BytecodeInstruction::Opcode::CREATEOBJECTWITHBUFFER_IMM8_ID16:
case BytecodeInstruction::Opcode::CREATEOBJECTWITHBUFFER_IMM16_ID16: {
auto literalId = pf->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue()));
auto literalId = jsPandaFile_->ResolveMethodIndex(method->GetMethodId(),
static_cast<uint16_t>(bcIns.GetId().AsRawValue()));
CollectInnerMethodsFromNewLiteral(method, literalId);
break;
}

View File

@ -584,8 +584,6 @@ public:
const uint8_t *PeekPrevPc(size_t i) const;
private:
static constexpr uint32_t INVALID_INDEX = std::numeric_limits<uint32_t>::max();
BytecodeCircuitBuilder *builder_ {nullptr};
uint32_t start_ {0};
uint32_t end_ {0};

View File

@ -42,7 +42,7 @@ void TypeRecorder::LoadTypes(const JSPandaFile *jsPandaFile, const MethodLiteral
panda_file::MethodDataAccessor mda(*pf, fieldId);
mda.EnumerateAnnotations([&](panda_file::File::EntityId annotationId) {
panda_file::AnnotationDataAccessor ada(*pf, annotationId);
auto *annotationName = reinterpret_cast<const char *>(pf->GetStringData(ada.GetClassId()).data);
auto *annotationName = reinterpret_cast<const char *>(jsPandaFile->GetStringData(ada.GetClassId()).data);
ASSERT(annotationName != nullptr);
if (::strcmp("L_ESTypeAnnotation;", annotationName) != 0) {
return;
@ -50,7 +50,7 @@ void TypeRecorder::LoadTypes(const JSPandaFile *jsPandaFile, const MethodLiteral
uint32_t length = ada.GetCount();
for (uint32_t i = 0; i < length; i++) {
panda_file::AnnotationDataAccessor::Elem adae = ada.GetElement(i);
auto *elemName = reinterpret_cast<const char *>(pf->GetStringData(adae.GetNameId()).data);
auto *elemName = reinterpret_cast<const char *>(jsPandaFile->GetStringData(adae.GetNameId()).data);
ASSERT(elemName != nullptr);
if (::strcmp("_TypeOfInstruction", elemName) != 0) {
continue;

View File

@ -571,7 +571,7 @@ bool DebuggerApi::IsExceptionCaught(const EcmaVM *ecmaVm)
return false;
}
auto method = frameHandler.GetMethod();
if (ecmaVm->FindCatchBlock(method, frameHandler.GetBytecodeOffset())) {
if (method->FindCatchBlock(frameHandler.GetBytecodeOffset() != INVALID_INDEX)) {
return true;
}
}

View File

@ -20,9 +20,6 @@
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/debugger/js_pt_location.h"
#include "libpandafile/file.h"
#include "libpandabase/macros.h"
#include "libpandabase/utils/expected.h"
namespace panda::ecmascript::tooling {
struct JSPtStepRange {

View File

@ -12,7 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "deoptimizer.h"
#include "ecmascript/deoptimizer/deoptimizer.h"
#include "ecmascript/compiler/assembler/assembler.h"
#include "ecmascript/dfx/stackinfo/js_stackinfo.h"
#include "ecmascript/frames.h"

View File

@ -22,7 +22,7 @@
#include "ecmascript/interpreter/frame_handler.h"
#include "ecmascript/js_thread.h"
#include "os/mutex.h"
#include "libpandabase/os/mutex.h"
namespace panda::ecmascript {
using JSTaggedType = uint64_t;

View File

@ -24,8 +24,6 @@
#include "ecmascript/dfx/hprof/file_stream.h"
#include "ecmascript/dfx/hprof/progress.h"
#include "os/mem.h"
namespace panda::ecmascript {
class HeapSnapshot;
class EcmaVM;

View File

@ -19,6 +19,7 @@
#include <atomic>
#include <cstdint>
#include <fstream>
#include <sys/time.h>
#include "ecmascript/dfx/hprof/heap_profiler.h"
#include "ecmascript/dfx/hprof/heap_root_visitor.h"
@ -31,9 +32,6 @@
#include "ecmascript/dfx/hprof/file_stream.h"
#include "ecmascript/interpreter/frame_handler.h"
#include <sys/time.h>
#include "os/mem.h"
namespace panda::ecmascript {
// Define the Object Graphic
using Address = uintptr_t;

View File

@ -19,11 +19,13 @@
#include <fstream>
#include <sstream>
#include <limits.h>
#include "ecmascript/mem/c_string.h"
#include "ecmascript/dfx/hprof/file_stream.h"
#include "ecmascript/mem/c_containers.h"
#include "os/mem.h"
#include "securec.h"
namespace panda::ecmascript {
using fstream = std::fstream;

View File

@ -20,8 +20,6 @@
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/mem/c_string.h"
#include "os/mem.h"
namespace panda::ecmascript {
using StringKey = uint64_t;
using StringId = uint64_t;

View File

@ -22,7 +22,7 @@
#include <unwind.h>
#include "ecmascript/log_wrapper.h"
#include "mem/mem.h"
#include "ecmascript/mem/mem.h"
namespace panda::ecmascript {
static const std::string LIB_UNWIND_SO_NAME = "libunwind.so";

View File

@ -19,7 +19,7 @@
#include <unistd.h>
#include "ecmascript/log_wrapper.h"
#include "mem/mem.h"
#include "ecmascript/mem/mem.h"
namespace panda::ecmascript {
static const int MAX_STACK_SIZE = 256;

View File

@ -16,8 +16,8 @@
#ifndef ECMASCRIPT_VM_THREAD_CONTROL_H
#define ECMASCRIPT_VM_THREAD_CONTROL_H
#include "libpandabase/os/mutex.h"
#include "libpandabase/utils/bit_field.h"
#include "os/mutex.h"
namespace panda::ecmascript {
class VmThreadControl {

View File

@ -414,17 +414,6 @@ EcmaVM::CpuProfilingScope::~CpuProfilingScope()
#endif
}
bool EcmaVM::FindCatchBlock(Method *method, uint32_t pc) const
{
uint32_t pcOffset = panda_file::INVALID_OFFSET;
if (thread_->IsAsmInterpreter()) {
pcOffset = InterpreterAssembly::FindCatchBlock(method, pc);
} else {
pcOffset = EcmaInterpreter::FindCatchBlock(method, pc);
}
return pcOffset != panda_file::INVALID_OFFSET;
}
JSTaggedValue EcmaVM::InvokeEcmaAotEntrypoint(JSHandle<JSFunction> mainFunc, JSHandle<JSTaggedValue> &thisArg,
const JSPandaFile *jsPandaFile, std::string_view entryPoint)
{

View File

@ -531,8 +531,6 @@ public:
return pgoProfiler_;
}
bool FindCatchBlock(Method *method, uint32_t pc) const;
void PreFork();
void PostFork();

View File

@ -37,10 +37,6 @@
#include "ecmascript/runtime_call_id.h"
#include "ecmascript/stubs/runtime_stubs.h"
#include "ecmascript/template_string.h"
#include "libpandafile/code_data_accessor.h"
#include "libpandafile/file.h"
#include "libpandafile/method_data_accessor-inl.h"
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
#endif
@ -3639,21 +3635,21 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t
}
NOPRINT_HANDLE_OPCODE(EXCEPTION) {
FrameHandler frameHandler(thread);
uint32_t pcOffset = panda_file::INVALID_OFFSET;
uint32_t pcOffset = INVALID_INDEX;
for (; frameHandler.HasFrame(); frameHandler.PrevInterpretedFrame()) {
if (frameHandler.IsEntryFrame()) {
return;
}
auto method = frameHandler.GetMethod();
pcOffset = FindCatchBlock(method, frameHandler.GetBytecodeOffset());
if (pcOffset != panda_file::INVALID_OFFSET) {
pcOffset = method->FindCatchBlock(frameHandler.GetBytecodeOffset());
if (pcOffset != INVALID_INDEX) {
sp = frameHandler.GetSp();
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
pc = method->GetBytecodeArray() + pcOffset;
break;
}
}
if (pcOffset == panda_file::INVALID_OFFSET) {
if (pcOffset == INVALID_INDEX) {
return;
}
@ -7088,25 +7084,6 @@ void EcmaInterpreter::InitStackFrame(JSThread *thread)
state->base.prev = nullptr;
}
uint32_t EcmaInterpreter::FindCatchBlock(Method *caller, uint32_t pc)
{
auto *pandaFile = caller->GetPandaFile();
panda_file::MethodDataAccessor mda(*pandaFile, caller->GetMethodId());
panda_file::CodeDataAccessor cda(*pandaFile, mda.GetCodeId().value());
uint32_t pcOffset = panda_file::INVALID_OFFSET;
cda.EnumerateTryBlocks([&pcOffset, pc](panda_file::CodeDataAccessor::TryBlock &try_block) {
if ((try_block.GetStartPc() <= pc) && ((try_block.GetStartPc() + try_block.GetLength()) > pc)) {
try_block.EnumerateCatchBlocks([&](panda_file::CodeDataAccessor::CatchBlock &catch_block) {
pcOffset = catch_block.GetHandlerPc();
return false;
});
}
return pcOffset == panda_file::INVALID_OFFSET;
});
return pcOffset;
}
JSTaggedValue EcmaInterpreter::GetFunction(JSTaggedType *sp)
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)

View File

@ -48,7 +48,6 @@ public:
static inline JSTaggedValue GeneratorReEnterAot(JSThread *thread, JSHandle<GeneratorContext> context);
static inline void RunInternal(JSThread *thread, const uint8_t *pc, JSTaggedType *sp);
static inline void InitStackFrame(JSThread *thread);
static inline uint32_t FindCatchBlock(Method *caller, uint32_t pc);
static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc);
static inline JSTaggedValue GetRuntimeProfileTypeInfo(JSTaggedType *sp);

View File

@ -32,10 +32,6 @@
#include "ecmascript/runtime_call_id.h"
#include "ecmascript/template_string.h"
#include "libpandafile/code_data_accessor.h"
#include "libpandafile/file.h"
#include "libpandafile/method_data_accessor-inl.h"
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
#endif
@ -7359,15 +7355,15 @@ void InterpreterAssembly::ExceptionHandler(
JSTaggedValue acc, int16_t hotnessCounter)
{
FrameHandler frameHandler(thread);
uint32_t pcOffset = panda_file::INVALID_OFFSET;
uint32_t pcOffset = INVALID_INDEX;
for (; frameHandler.HasFrame(); frameHandler.PrevInterpretedFrame()) {
if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
thread->SetLastFp(frameHandler.GetFp());
return;
}
auto method = frameHandler.GetMethod();
pcOffset = FindCatchBlock(method, frameHandler.GetBytecodeOffset());
if (pcOffset != panda_file::INVALID_OFFSET) {
pcOffset = method->FindCatchBlock(frameHandler.GetBytecodeOffset());
if (pcOffset != INVALID_INDEX) {
thread->SetCurrentFrame(frameHandler.GetSp());
thread->SetLastFp(frameHandler.GetFp());
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
@ -7375,7 +7371,7 @@ void InterpreterAssembly::ExceptionHandler(
break;
}
}
if (pcOffset == panda_file::INVALID_OFFSET) {
if (pcOffset == INVALID_INDEX) {
return;
}
@ -7395,25 +7391,6 @@ void InterpreterAssembly::ExceptionHandler(
ASM_UNUSED_BC_STUB_LIST(DECLARE_UNUSED_ASM_HANDLE)
#undef DECLARE_UNUSED_ASM_HANDLE
uint32_t InterpreterAssembly::FindCatchBlock(Method *caller, uint32_t pc)
{
auto *pandaFile = caller->GetPandaFile();
panda_file::MethodDataAccessor mda(*pandaFile, caller->GetMethodId());
panda_file::CodeDataAccessor cda(*pandaFile, mda.GetCodeId().value());
uint32_t pcOffset = panda_file::INVALID_OFFSET;
cda.EnumerateTryBlocks([&pcOffset, pc](panda_file::CodeDataAccessor::TryBlock &try_block) {
if ((try_block.GetStartPc() <= pc) && ((try_block.GetStartPc() + try_block.GetLength()) > pc)) {
try_block.EnumerateCatchBlocks([&](panda_file::CodeDataAccessor::CatchBlock &catch_block) {
pcOffset = catch_block.GetHandlerPc();
return false;
});
}
return pcOffset == panda_file::INVALID_OFFSET;
});
return pcOffset;
}
inline void InterpreterAssembly::InterpreterFrameCopyArgs(
JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, uint32_t numDeclaredArgs, bool haveExtraArgs)
{

View File

@ -38,7 +38,6 @@ public:
static void InitStackFrame(JSThread *thread);
static JSTaggedValue Execute(EcmaRuntimeCallInfo *info);
static JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle<GeneratorContext> context);
static uint32_t FindCatchBlock(Method *caller, uint32_t pc);
static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc);
static inline JSTaggedValue UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp);

View File

@ -26,8 +26,6 @@
#include "ecmascript/tagged_queue.h"
#include "ecmascript/tagged_queue.h"
#include "utils/expected.h"
namespace panda::ecmascript::job {
void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueue, QueueType queueType,
const JSHandle<JSFunction> &job, const JSHandle<TaggedArray> &argv)

View File

@ -146,8 +146,8 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle<JSObject>
if (method.IsUndefined()) {
return JSTaggedValue::Undefined();
}
JSHandle<Method> target = JSHandle<Method>(thread, method);
if (target->GetPandaFile() == nullptr) {
Method *target = Method::Cast(method.GetTaggedObject());
if (target->IsNativeWithCallField()) {
return JSTaggedValue::Undefined();
}
std::string funcName = target->ParseFunctionName();

View File

@ -13,13 +13,14 @@
* limitations under the License.
*/
#include "ecmascript/js_runtime_options.h"
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <getopt.h>
#include "ecmascript/mem/mem_common.h"
#include "js_runtime_options.h"
namespace panda::ecmascript {
const std::string PUBLIC_API COMMON_HELP_HEAD_MSG =

View File

@ -28,8 +28,6 @@
#include "ecmascript/global_env_constants.h"
#include "ecmascript/mem/visitor.h"
#include "libpandabase/os/thread.h"
namespace panda::ecmascript {
class EcmaHandleScope;
class EcmaVM;

View File

@ -17,10 +17,11 @@
#include "ecmascript/jspandafile/js_pandafile_manager.h"
namespace panda::ecmascript {
ModuleDataAccessor::ModuleDataAccessor(const panda_file::File &pandaFile, panda_file::File::EntityId moduleDataId)
ModuleDataAccessor::ModuleDataAccessor(const JSPandaFile *pandaFile, panda_file::File::EntityId moduleDataId)
: pandaFile_(pandaFile), moduleDataId_(moduleDataId)
{
auto sp = pandaFile_.GetSpanFromId(moduleDataId);
auto &pf = *pandaFile_->GetPandaFile();
auto sp = pf.GetSpanFromId(moduleDataId);
auto moduleSp = sp.SubSpan(panda_file::ID_SIZE); // skip literalnum
@ -53,10 +54,10 @@ void ModuleDataAccessor::EnumerateImportEntry(JSThread *thread,
auto localNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
auto importNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
auto moduleRequestIdx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
StringData sd = pandaFile_.GetStringData(panda_file::File::EntityId(localNameOffset));
auto sd = pandaFile_->GetStringData(panda_file::File::EntityId(localNameOffset));
localName.Update(JSTaggedValue(factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii)));
sd = pandaFile_.GetStringData(panda_file::File::EntityId(importNameOffset));
sd = pandaFile_->GetStringData(panda_file::File::EntityId(importNameOffset));
importName.Update(JSTaggedValue(factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii)));
if (requestArraySize != 0) {
@ -77,7 +78,7 @@ void ModuleDataAccessor::EnumerateImportEntry(JSThread *thread,
for (size_t idx = regularImportNum; idx < totalSize; idx++) {
auto localNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
auto moduleRequestIdx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
StringData sd = pandaFile_.GetStringData(panda_file::File::EntityId(localNameOffset));
auto sd = pandaFile_->GetStringData(panda_file::File::EntityId(localNameOffset));
localName.Update(JSTaggedValue(factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii)));
if (requestArraySize != 0) {
@ -105,11 +106,11 @@ void ModuleDataAccessor::EnumerateLocalExportEntry(JSThread *thread, JSHandle<So
for (size_t idx = 0; idx < localExportNum; idx++) {
auto localNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
auto exportNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
StringData sd = pandaFile_.GetStringData(panda_file::File::EntityId(localNameOffset));
auto sd = pandaFile_->GetStringData(panda_file::File::EntityId(localNameOffset));
JSHandle<JSTaggedValue> localName(thread,
factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii));
sd = pandaFile_.GetStringData(panda_file::File::EntityId(exportNameOffset));
sd = pandaFile_->GetStringData(panda_file::File::EntityId(exportNameOffset));
JSHandle<JSTaggedValue> exportName(thread,
factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii));
@ -140,11 +141,11 @@ void ModuleDataAccessor::EnumerateIndirectExportEntry(JSThread *thread, const JS
auto exportNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
auto importNameOffset = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint32_t)>(&sp));
auto moduleRequestIdx = static_cast<uint32_t>(panda_file::helpers::Read<sizeof(uint16_t)>(&sp));
StringData sd = pandaFile_.GetStringData(panda_file::File::EntityId(exportNameOffset));
auto sd = pandaFile_->GetStringData(panda_file::File::EntityId(exportNameOffset));
JSHandle<JSTaggedValue> exportName(thread,
factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii));
sd = pandaFile_.GetStringData(panda_file::File::EntityId(importNameOffset));
sd = pandaFile_->GetStringData(panda_file::File::EntityId(importNameOffset));
JSHandle<JSTaggedValue> importName(thread,
factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii));

View File

@ -21,20 +21,15 @@
#include <variant>
#include <vector>
#include "libpandabase/macros.h"
#include "libpandabase/utils/span.h"
#include "libpandafile/file.h"
#include "libpandafile/file_items.h"
#include "libpandafile/helpers.h"
#include "ecmascript/module/js_module_source_text.h"
namespace panda::ecmascript {
using StringData = panda_file::File::StringData;
#include "libpandabase/macros.h"
#include "libpandabase/utils/span.h"
namespace panda::ecmascript {
class ModuleDataAccessor {
public:
ModuleDataAccessor(const panda_file::File &panda_file, panda_file::File::EntityId module_data_id);
ModuleDataAccessor(const JSPandaFile *pandaFile, panda_file::File::EntityId module_data_id);
~ModuleDataAccessor() = default;
DEFAULT_MOVE_CTOR(ModuleDataAccessor)
DEFAULT_COPY_CTOR(ModuleDataAccessor)
@ -52,11 +47,6 @@ public:
void EnumerateStarExportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray,
JSHandle<SourceTextModule> &moduleRecord);
const panda_file::File &GetPandaFile() const
{
return pandaFile_;
}
panda_file::File::EntityId GetModuleDataId() const
{
return moduleDataId_;
@ -67,10 +57,8 @@ public:
return moduleRequests_;
}
using ModuleValue = std::variant<uint32_t, StringData>;
private:
const panda_file::File &pandaFile_;
const JSPandaFile *pandaFile_;
panda_file::File::EntityId moduleDataId_;
uint32_t numModuleRequests_;
std::vector<uint32_t> moduleRequests_;

View File

@ -169,13 +169,11 @@ private:
void DebugInfoExtractor::Extract()
{
const panda_file::File *pf = jsPandaFile_->GetPandaFile();
ASSERT(pf != nullptr);
const auto &pandaFile = *pf;
auto classes = pf->GetClasses();
auto &pandaFile = *jsPandaFile_->GetPandaFile();
auto classes = jsPandaFile_->GetClasses();
for (size_t i = 0; i < classes.Size(); i++) {
panda_file::File::EntityId id(classes[i]);
if (pandaFile.IsExternal(id)) {
if (jsPandaFile_->IsExternal(id)) {
continue;
}

View File

@ -45,7 +45,7 @@ void JSPandaFile::CheckIsBundlePack()
panda_file::ClassDataAccessor cda(*pf_, classId);
cda.EnumerateFields([&](panda_file::FieldDataAccessor &fieldAccessor) -> void {
panda_file::File::EntityId fieldNameId = fieldAccessor.GetNameId();
panda_file::File::StringData sd = pf_->GetStringData(fieldNameId);
panda_file::File::StringData sd = GetStringData(fieldNameId);
const char *fieldName = utf::Mutf8AsCString(sd.data);
if (std::strcmp(IS_COMMON_JS, fieldName) == 0 || std::strcmp(MODULE_RECORD_IDX, fieldName) == 0) {
isBundlePack_ = false;
@ -111,7 +111,7 @@ void JSPandaFile::InitializeUnMergedPF()
if (info.moduleRecordIdx == -1 && std::strcmp(MODULE_CLASS, desc) == 0) {
cda.EnumerateFields([&](panda_file::FieldDataAccessor &fieldAccessor) -> void {
panda_file::File::EntityId fieldNameId = fieldAccessor.GetNameId();
panda_file::File::StringData sd = pf_->GetStringData(fieldNameId);
panda_file::File::StringData sd = GetStringData(fieldNameId);
if (std::strcmp(reinterpret_cast<const char *>(sd.data), desc_.c_str())) {
info.moduleRecordIdx = fieldAccessor.GetValue<int32_t>().value();
return;
@ -144,7 +144,7 @@ void JSPandaFile::InitializeMergedPF()
bool hasJsonFiled = false;
cda.EnumerateFields([&](panda_file::FieldDataAccessor &fieldAccessor) -> void {
panda_file::File::EntityId fieldNameId = fieldAccessor.GetNameId();
panda_file::File::StringData sd = pf_->GetStringData(fieldNameId);
panda_file::File::StringData sd = GetStringData(fieldNameId);
const char *fieldName = utf::Mutf8AsCString(sd.data);
if (std::strcmp(IS_COMMON_JS, fieldName) == 0) {
hasCjsFiled = true;
@ -252,7 +252,7 @@ CString JSPandaFile::FindEntryPoint(const CString &recordName) const
if (std::strcmp(recordName.c_str(), ParseEntryPoint(desc).c_str()) == 0) {
cda.EnumerateFields([&](panda_file::FieldDataAccessor &fieldAccessor) -> void {
panda_file::File::EntityId fieldNameId = fieldAccessor.GetNameId();
panda_file::File::StringData sd = pf_->GetStringData(fieldNameId);
panda_file::File::StringData sd = GetStringData(fieldNameId);
CString fieldName = utf::Mutf8AsCString(sd.data);
if (HasRecord(fieldName)) {
entryPoint = fieldName;

View File

@ -24,6 +24,7 @@
#include "libpandafile/file.h"
#include "libpandafile/file_items.h"
namespace panda {
namespace ecmascript {
class JSPandaFile {
@ -89,7 +90,6 @@ public:
static constexpr char PREVIEW_OF_ACROSS_HAP_FLAG[] = "[preview]";
static constexpr int PACKAGE_NAME_LEN = 8;
static constexpr int MODULE_OR_BUNDLE_PREFIX_LEN = 8;
static constexpr uint32_t INVALID_INDEX = -1;
JSPandaFile(const panda_file::File *pf, const CString &descriptor);
~JSPandaFile();
@ -203,6 +203,41 @@ public:
return pf_->GetClasses();
}
inline bool IsExternal(panda_file::File::EntityId id) const
{
return pf_->IsExternal(id);
}
inline panda_file::File::StringData GetStringData(panda_file::File::EntityId id) const
{
return pf_->GetStringData(id);
}
panda_file::File::EntityId ResolveMethodIndex(panda_file::File::EntityId id, uint16_t idx) const
{
return pf_->ResolveMethodIndex(id, idx);
}
panda_file::File::EntityId GetLiteralArraysId() const
{
return pf_->GetLiteralArraysId();
}
Span<const panda_file::File::EntityId> GetMethodIndex(const panda_file::File::IndexHeader *indexHeader) const
{
return pf_->GetMethodIndex(indexHeader);
}
const void *GetHeader() const
{
return static_cast<const void *>(pf_->GetHeader());
}
uint32_t GetFileSize() const
{
return pf_->GetHeader()->file_size;
}
bool PUBLIC_API IsModule(const CString &recordName = ENTRY_FUNCTION_NAME) const;
bool IsCjs(const CString &recordName = ENTRY_FUNCTION_NAME) const;

View File

@ -21,8 +21,6 @@
#include "ecmascript/jspandafile/panda_file_translator.h"
#include "ecmascript/jspandafile/debug_info_extractor.h"
#include "libpandafile/file.h"
namespace panda {
namespace ecmascript {
class Program;

View File

@ -39,7 +39,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
LOG_ECMA(VERBOSE) << "Panda File" << jsPandaFile->GetJSPandaFileDesc();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half
@ -51,7 +51,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
uint32_t methodId;
FunctionKind kind;
lda.EnumerateLiteralVals(
index, [elements, properties, &epos, &ppos, vm, factory, thread, jsPandaFile, pf,
index, [elements, properties, &epos, &ppos, vm, factory, thread, jsPandaFile,
&methodId, &kind, &constpool, &entryPoint]
(const LiteralValue &value, const LiteralTag &tag) {
JSTaggedValue jt = JSTaggedValue::Null();
@ -70,7 +70,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
break;
}
case LiteralTag::STRING: {
StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
StringData sd = jsPandaFile->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii,
MemSpaceType::OLD_SPACE);
jt = JSTaggedValue(str);
@ -137,7 +137,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreTypeForClass(JSThread
const JSPandaFile *jsPandaFile, size_t index, JSHandle<ConstantPool> constpool, const CString &entryPoint)
{
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half
// The num is 1, indicating that the current class has no member variable.
@ -154,7 +154,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread,
{
LOG_ECMA(VERBOSE) << "Panda File" << jsPandaFile->GetJSPandaFileDesc();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
return EnumerateLiteralVals(thread, lda, jsPandaFile, index, constpool, entryPoint);
}
@ -187,8 +187,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::EnumerateLiteralVals(JSThread *threa
break;
}
case LiteralTag::STRING: {
const panda_file::File *pf = jsPandaFile->GetPandaFile();
StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
StringData sd = jsPandaFile->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii,
MemSpaceType::OLD_SPACE);
jt = JSTaggedValue(str);
@ -280,7 +279,7 @@ void LiteralDataExtractor::GetMethodOffsets(const JSPandaFile *jsPandaFile, size
std::vector<uint32_t> &methodOffsets)
{
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
lda.EnumerateLiteralVals(
@ -303,7 +302,7 @@ void LiteralDataExtractor::GetMethodOffsets(const JSPandaFile *jsPandaFile, pand
std::vector<uint32_t> &methodOffsets)
{
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
lda.EnumerateLiteralVals(
@ -333,7 +332,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
LOG_ECMA(VERBOSE) << "Panda File" << jsPandaFile->GetJSPandaFileDesc();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half
@ -346,7 +345,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
FunctionKind kind;
lda.EnumerateLiteralVals(
index, [elements, properties, &epos, &ppos, vm, factory, thread, jsPandaFile,
pf, &methodId, &kind, &constpool, &entry]
&methodId, &kind, &constpool, &entry]
(const LiteralValue &value, const LiteralTag &tag) {
JSTaggedValue jt = JSTaggedValue::Null();
bool flag = false;
@ -364,7 +363,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil
break;
}
case LiteralTag::STRING: {
StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
StringData sd = jsPandaFile->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii,
MemSpaceType::OLD_SPACE);
jt = JSTaggedValue(str);
@ -437,7 +436,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread,
LOG_ECMA(VERBOSE) << "Panda File" << jsPandaFile->GetJSPandaFileDesc();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half
@ -463,8 +462,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread,
break;
}
case LiteralTag::STRING: {
const panda_file::File *pf = jsPandaFile->GetPandaFile();
StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
StringData sd = jsPandaFile->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii,
MemSpaceType::OLD_SPACE);
jt = JSTaggedValue(str);
@ -527,7 +525,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetTypeLiteral(JSThread *thread, con
panda_file::File::EntityId offset)
{
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
@ -535,7 +533,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetTypeLiteral(JSThread *thread, con
JSHandle<TaggedArray> literals = factory->NewOldSpaceTaggedArray(num);
uint32_t pos = 0;
lda.EnumerateLiteralVals(
offset, [literals, &pos, factory, thread, pf]
offset, [literals, &pos, factory, thread, jsPandaFile]
(const panda_file::LiteralDataAccessor::LiteralValue &value, const LiteralTag &tag) {
JSTaggedValue jt = JSTaggedValue::Null();
switch (tag) {
@ -553,7 +551,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetTypeLiteral(JSThread *thread, con
break;
}
case LiteralTag::STRING: {
StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
StringData sd = jsPandaFile->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii,
MemSpaceType::OLD_SPACE);
jt = JSTaggedValue(str);

View File

@ -104,7 +104,7 @@ const char *MethodLiteral::GetMethodName(const JSPandaFile *jsPandaFile, EntityI
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::MethodDataAccessor mda(*pf, methodId);
panda_file::File::StringData sd = pf->GetStringData(mda.GetNameId());
auto sd = jsPandaFile->GetStringData(mda.GetNameId());
return utf::Mutf8AsCString(sd.data);
}

View File

@ -33,7 +33,7 @@ JSHandle<JSTaggedValue> ModuleDataExtractor::ParseModule(JSThread *thread, const
int moduleIdx = jsPandaFile->GetModuleRecordIdx(descriptor);
ASSERT(moduleIdx != -1);
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::File::EntityId literalArraysId = jsPandaFile->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
panda_file::File::EntityId moduleId;
if (jsPandaFile->IsNewVersion()) { // new pandafile version use new literal offset mechanism
@ -61,14 +61,13 @@ void ModuleDataExtractor::ExtractModuleDatas(JSThread *thread, const JSPandaFile
JSHandle<SourceTextModule> &moduleRecord)
{
[[maybe_unused]] EcmaHandleScope scope(thread);
const panda_file::File *pf = jsPandaFile->GetPandaFile();
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
ModuleDataAccessor mda(*pf, moduleId);
ModuleDataAccessor mda(jsPandaFile, moduleId);
const std::vector<uint32_t> &requestModules = mda.getRequestModules();
size_t len = requestModules.size();
JSHandle<TaggedArray> requestModuleArray = factory->NewTaggedArray(len);
for (size_t idx = 0; idx < len; idx++) {
StringData sd = pf->GetStringData(panda_file::File::EntityId(requestModules[idx]));
StringData sd = jsPandaFile->GetStringData(panda_file::File::EntityId(requestModules[idx]));
JSTaggedValue value(factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii));
requestModuleArray->Set(thread, idx, value);
}

View File

@ -48,7 +48,7 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri
Span<const uint32_t> classIndexes = jsPandaFile->GetClasses();
for (const uint32_t index : classIndexes) {
panda_file::File::EntityId classId(index);
if (pf->IsExternal(classId)) {
if (jsPandaFile->IsExternal(classId)) {
continue;
}
panda_file::ClassDataAccessor cda(*pf, classId);
@ -58,7 +58,7 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri
&isUpdateMainMethodIndex]
(panda_file::MethodDataAccessor &mda) {
auto methodId = mda.GetMethodId();
CString name = reinterpret_cast<const char *>(pf->GetStringData(mda.GetNameId()).data);
CString name = reinterpret_cast<const char *>(jsPandaFile->GetStringData(mda.GetNameId()).data);
auto methodOffset = methodId.GetOffset();
if (jsPandaFile->IsBundlePack()) {
if (!isUpdateMainMethodIndex && name == methodName) {
@ -159,14 +159,12 @@ JSHandle<ConstantPool> PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSP
[[maybe_unused]] EcmaHandleScope handleScope(thread);
const CUnorderedMap<uint32_t, uint64_t> &constpoolMap = jsPandaFile->GetConstpoolMap();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
for (const auto &it : constpoolMap) {
ConstPoolValue value(it.second);
ConstPoolType type = value.GetConstpoolType();
if (type == ConstPoolType::STRING) {
panda_file::File::EntityId id(it.first);
auto foundStr = pf->GetStringData(id);
auto foundStr = jsPandaFile->GetStringData(id);
auto string = factory->GetRawStringFromStringTable(foundStr.data, foundStr.utf16_length, foundStr.is_ascii,
MemSpaceType::OLD_SPACE);
constpool->SetObjectToCache(thread, value.GetConstpoolIndex(), JSTaggedValue(string));
@ -1501,7 +1499,6 @@ void PandaFileTranslator::FixInstructionId32(const OldBytecodeInst &inst, uint32
void PandaFileTranslator::TranslateBytecode(JSPandaFile *jsPandaFile, uint32_t insSz, const uint8_t *insArr,
const MethodLiteral *method, const CString &entryPoint)
{
const panda_file::File *pf = jsPandaFile->GetPandaFile();
auto bcIns = OldBytecodeInst(insArr);
auto bcInsLast = bcIns.JumpTo(insSz);
const CUnorderedMap<uint32_t, uint64_t> *ConstpoolMap = jsPandaFile->GetConstpoolMapByReocrd(entryPoint);
@ -1516,34 +1513,34 @@ void PandaFileTranslator::TranslateBytecode(JSPandaFile *jsPandaFile, uint32_t i
uint32_t index;
uint32_t methodId;
case OldBytecodeInst::Opcode::ECMA_DEFINEFUNCDYN_PREF_ID16_IMM16_V8:
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::BASE_FUNCTION, methodId, ConstpoolMap);
FixInstructionId32(bcIns, index);
break;
case OldBytecodeInst::Opcode::ECMA_DEFINENCFUNCDYN_PREF_ID16_IMM16_V8:
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::NC_FUNCTION, methodId, ConstpoolMap);
FixInstructionId32(bcIns, index);
break;
case OldBytecodeInst::Opcode::ECMA_DEFINEGENERATORFUNC_PREF_ID16_IMM16_V8:
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::GENERATOR_FUNCTION, methodId,
ConstpoolMap);
FixInstructionId32(bcIns, index);
break;
case OldBytecodeInst::Opcode::ECMA_DEFINEASYNCGENERATORFUNC_PREF_ID16_IMM16_V8:
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::ASYNC_GENERATOR_FUNCTION, methodId,
ConstpoolMap);
FixInstructionId32(bcIns, index);
break;
case OldBytecodeInst::Opcode::ECMA_DEFINEASYNCFUNC_PREF_ID16_IMM16_V8:
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::ASYNC_FUNCTION, methodId, ConstpoolMap);
FixInstructionId32(bcIns, index);
break;
case OldBytecodeInst::Opcode::ECMA_DEFINEMETHOD_PREF_ID16_IMM16_V8:
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::METHOD, methodId, ConstpoolMap);
FixInstructionId32(bcIns, index);
break;
@ -1564,7 +1561,7 @@ void PandaFileTranslator::TranslateBytecode(JSPandaFile *jsPandaFile, uint32_t i
break;
}
case OldBytecodeInst::Opcode::ECMA_DEFINECLASSWITHBUFFER_PREF_ID16_IMM16_IMM16_V8_V8: {
methodId = pf->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
methodId = jsPandaFile->ResolveMethodIndex(method->GetMethodId(), bcIns.GetId()).GetOffset();
index = jsPandaFile->GetOrInsertConstantPool(ConstPoolType::CLASS_FUNCTION, methodId, ConstpoolMap);
FixInstructionId32(bcIns, index);
auto imm = bcIns.GetImm<OldBytecodeInst::Format::PREF_ID16_IMM16_IMM16_V8_V8>();

View File

@ -101,8 +101,7 @@ public:
{
JSPandaFile *jsPandaFile = GetJSPandaFile();
panda_file::File::IndexHeader *indexHeader = GetIndexHeader();
auto pf = jsPandaFile->GetPandaFile();
Span<const panda_file::File::EntityId> indexs = pf->GetMethodIndex(indexHeader);
Span<const panda_file::File::EntityId> indexs = jsPandaFile->GetMethodIndex(indexHeader);
return indexs[index];
}
@ -320,8 +319,7 @@ public:
JSPandaFile *jsPandaFile = taggedPool->GetJSPandaFile();
panda_file::File::EntityId id = taggedPool->GetEntityId(index);
auto pf = jsPandaFile->GetPandaFile();
auto foundStr = pf->GetStringData(id);
auto foundStr = jsPandaFile->GetStringData(id);
EcmaVM *vm = thread->GetEcmaVM();
ObjectFactory *factory = vm->GetFactory();

View File

@ -33,10 +33,7 @@ JSTaggedValue ScopeInfoExtractor::GenerateScopeInfo(JSThread *thread, uint16_t s
JSHandle<TaggedArray> elementsLiteral;
if (jsPandaFile->IsNewVersion()) {
panda_file::File::IndexHeader *indexHeader = constpool->GetIndexHeader();
auto pf = jsPandaFile->GetPandaFile();
Span<const panda_file::File::EntityId> indexs = pf->GetMethodIndex(indexHeader);
panda_file::File::EntityId id = indexs[scopeId];
panda_file::File::EntityId id = constpool->GetEntityId(scopeId);
elementsLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, id, constpool);
} else {
elementsLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, scopeId, constpool);

View File

@ -29,8 +29,6 @@
#include "ecmascript/taskpool/taskpool.h"
#include "ecmascript/runtime_call_id.h"
#include "libpandabase/os/mutex.h"
namespace panda::ecmascript {
size_t ConcurrentMarker::taskCounts_ = 0;
os::memory::Mutex ConcurrentMarker::taskCountMutex_;

View File

@ -24,6 +24,7 @@
#include "ecmascript/mem/mem.h"
#include "ecmascript/mem/mem_common.h"
#include "ecmascript/log_wrapper.h"
#include "libpandabase/os/mutex.h"
namespace panda::ecmascript {

View File

@ -26,7 +26,6 @@
#include "ecmascript/platform/map.h"
#include "libpandabase/os/mutex.h"
#include "libpandabase/utils/aligned_storage.h"
#include "securec.h"

View File

@ -23,8 +23,6 @@
#include "ecmascript/mem/mem.h"
#include "ecmascript/mem/region.h"
#include "libpandabase/utils/type_helpers.h"
#include "securec.h"
namespace panda::ecmascript {

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "verification.h"
#include "ecmascript/mem/verification.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/mem/slots.h"

View File

@ -59,15 +59,6 @@ const JSPandaFile *Method::GetJSPandaFile() const
return taggedPool->GetJSPandaFile();
}
const panda_file::File *Method::GetPandaFile() const
{
const JSPandaFile *jsPandaFile = GetJSPandaFile();
if (jsPandaFile == nullptr) {
return nullptr;
}
return jsPandaFile->GetPandaFile();
}
MethodLiteral *Method::GetMethodLiteral() const
{
if (IsAotWithCallField()) {
@ -77,4 +68,24 @@ MethodLiteral *Method::GetMethodLiteral() const
}
return reinterpret_cast<MethodLiteral *>(GetCodeEntryOrLiteral());
}
uint32_t Method::FindCatchBlock(uint32_t pc) const
{
ASSERT(!IsNativeWithCallField());
auto *pandaFile = GetJSPandaFile()->GetPandaFile();
panda_file::MethodDataAccessor mda(*pandaFile, GetMethodId());
panda_file::CodeDataAccessor cda(*pandaFile, mda.GetCodeId().value());
uint32_t pcOffset = INVALID_INDEX;
cda.EnumerateTryBlocks([&pcOffset, pc](panda_file::CodeDataAccessor::TryBlock &tryBlock) {
if ((tryBlock.GetStartPc() <= pc) && ((tryBlock.GetStartPc() + tryBlock.GetLength()) > pc)) {
tryBlock.EnumerateCatchBlocks([&](panda_file::CodeDataAccessor::CatchBlock &catchBlock) {
pcOffset = catchBlock.GetHandlerPc();
return false;
});
}
return pcOffset == INVALID_INDEX;
});
return pcOffset;
}
} // namespace panda::ecmascript

View File

@ -242,7 +242,6 @@ public:
}
const JSPandaFile *PUBLIC_API GetJSPandaFile() const;
const panda_file::File *GetPandaFile() const;
uint32_t GetCodeSize() const;
MethodLiteral *GetMethodLiteral() const;
@ -251,6 +250,8 @@ public:
std::string PUBLIC_API ParseFunctionName() const;
const CString GetRecordName() const;
uint32_t FindCatchBlock(uint32_t pc) const;
static constexpr size_t CONSTANT_POOL_OFFSET = TaggedObjectSize();
ACCESSORS(ConstantPool, CONSTANT_POOL_OFFSET, PROFILE_TYPE_INFO_OFFSET)
ACCESSORS(ProfileTypeInfo, PROFILE_TYPE_INFO_OFFSET, CALL_FIELD_OFFSET)

View File

@ -78,7 +78,7 @@
#include "ohos/init_data.h"
#include "os/mutex.h"
#include "libpandabase/os/mutex.h"
#if defined(PANDA_TARGET_IOS)
namespace OHOS::ArkCompiler::Toolchain {

View File

@ -108,8 +108,8 @@ void PatchLoader::GenerateConstpoolCache(JSThread *thread, const JSPandaFile *js
const panda_file::File *pf = jsPandaFile->GetPandaFile();
Span<const uint32_t> classIndexes = jsPandaFile->GetClasses();
for (const uint32_t index : classIndexes) {
EntityId classId(index);
if (pf->IsExternal(classId)) {
panda_file::File::EntityId classId(index);
if (jsPandaFile->IsExternal(classId)) {
continue;
}
panda_file::ClassDataAccessor cda(*pf, classId);

View File

@ -17,7 +17,7 @@
#define ECMASCRIPT_SHARED_MEMORY_MANAGER_MANAGER_H
#include "ecmascript/mem/c_containers.h"
#include "os/mutex.h"
#include "libpandabase/os/mutex.h"
namespace panda {
class EcmaVm;

View File

@ -20,7 +20,7 @@
#include "ecmascript/mem/slots.h"
#include "ecmascript/snapshot/mem/constants.h"
#include "utils/bit_field.h"
#include "libpandabase/utils/bit_field.h"
/*
* EncodeBit: use uint64_t value to encode TaggedObject when serialize

View File

@ -40,7 +40,7 @@ void Snapshot::Serialize(const CString &fileName)
Serialize(root.GetTaggedObject(), nullptr, fileName);
}
void Snapshot::Serialize(TaggedObject *objectHeader, const panda_file::File *pf, const CString &fileName)
void Snapshot::Serialize(TaggedObject *objectHeader, const JSPandaFile *jsPandaFile, const CString &fileName)
{
std::string realPath;
if (!RealPath(std::string(fileName), realPath, false)) {
@ -65,7 +65,7 @@ void Snapshot::Serialize(TaggedObject *objectHeader, const panda_file::File *pf,
processor.EncodeTaggedObject(objectHeader, &objectQueue, &data);
size_t rootObjSize = objectQueue.size();
processor.ProcessObjectQueue(&objectQueue, &data);
WriteToFile(writer, pf, rootObjSize, processor);
WriteToFile(writer, jsPandaFile, rootObjSize, processor);
}
void Snapshot::Serialize(uintptr_t startAddr, size_t size, const CString &fileName)
@ -195,7 +195,8 @@ size_t Snapshot::AlignUpPageSize(size_t spaceSize)
return Constants::PAGE_SIZE_ALIGN_UP * (spaceSize / Constants::PAGE_SIZE_ALIGN_UP + 1);
}
void Snapshot::WriteToFile(std::fstream &writer, const panda_file::File *pf, size_t size, SnapshotProcessor &processor)
void Snapshot::WriteToFile(std::fstream &writer, const JSPandaFile *jsPandaFile,
size_t size, SnapshotProcessor &processor)
{
uint32_t totalStringSize = 0U;
CVector<uintptr_t> stringVector = processor.GetStringVector();
@ -226,9 +227,9 @@ void Snapshot::WriteToFile(std::fstream &writer, const panda_file::File *pf, siz
writer.flush();
}
ASSERT(static_cast<size_t>(writer.tellp()) == totalObjSize + sizeof(Header));
if (pf) {
if (jsPandaFile) {
writer.seekp(pandaFileBegin);
writer.write(reinterpret_cast<const char *>(pf->GetBase()), pf->GetHeader()->file_size);
writer.write(static_cast<const char *>(jsPandaFile->GetHeader()), jsPandaFile->GetFileSize());
}
writer.close();
}

View File

@ -22,7 +22,6 @@
#include "ecmascript/mem/c_string.h"
#include "libpandabase/macros.h"
#include "libpandafile/file.h"
namespace panda::ecmascript {
class Program;
@ -35,7 +34,7 @@ public:
~Snapshot() = default;
void Serialize(const CString &fileName = "./snapshot");
void Serialize(TaggedObject *objectHeader, const panda_file::File *pf, const CString &fileName = "./snapshot");
void Serialize(TaggedObject *objectHeader, const JSPandaFile *jsPandaFile, const CString &fileName = "./snapshot");
void Serialize(uintptr_t startAddr, size_t size, const CString &fileName = "./snapshot");
void SerializeBuiltins(const CString &fileName = "./snapshot");
const JSPandaFile *Deserialize(SnapshotType type, const CString &snapshotFile, bool isBuiltins = false);
@ -54,7 +53,7 @@ private:
private:
size_t AlignUpPageSize(size_t spaceSize);
void WriteToFile(std::fstream &writer, const panda_file::File *pf, size_t size, SnapshotProcessor &processor);
void WriteToFile(std::fstream &writer, const JSPandaFile *jsPandaFile, size_t size, SnapshotProcessor &processor);
NO_MOVE_SEMANTIC(Snapshot);
NO_COPY_SEMANTIC(Snapshot);

View File

@ -2450,11 +2450,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptGenerateScopeInfo(JSThread *thread, uint16
Method *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget();
const JSPandaFile *jsPandaFile = method->GetJSPandaFile();
JSHandle<ConstantPool> constpool(thread, method->GetConstantPool());
panda_file::File::IndexHeader *indexHeader = constpool->GetIndexHeader();
auto pf = jsPandaFile->GetPandaFile();
Span<const panda_file::File::EntityId> indexs = pf->GetMethodIndex(indexHeader);
panda_file::File::EntityId id = indexs[scopeId];
panda_file::File::EntityId id = constpool->GetEntityId(scopeId);
JSHandle<TaggedArray> elementsLiteral =
LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, id, constpool);

View File

@ -1029,7 +1029,7 @@ DEF_RUNTIME_STUBS(UpFrame)
{
RUNTIME_STUBS_HEADER(UpFrame);
FrameHandler frameHandler(thread);
uint32_t pcOffset = panda_file::INVALID_OFFSET;
uint32_t pcOffset = INVALID_INDEX;
for (; frameHandler.HasFrame(); frameHandler.PrevInterpretedFrame()) {
if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
thread->SetCurrentFrame(frameHandler.GetSp());
@ -1037,8 +1037,8 @@ DEF_RUNTIME_STUBS(UpFrame)
return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
}
auto method = frameHandler.GetMethod();
pcOffset = InterpreterAssembly::FindCatchBlock(method, frameHandler.GetBytecodeOffset());
if (pcOffset != panda_file::INVALID_OFFSET) {
pcOffset = method->FindCatchBlock(frameHandler.GetBytecodeOffset());
if (pcOffset != INVALID_INDEX) {
thread->SetCurrentFrame(frameHandler.GetSp());
thread->SetLastFp(frameHandler.GetFp());
uintptr_t pc = reinterpret_cast<uintptr_t>(method->GetBytecodeArray() + pcOffset);

View File

@ -15,7 +15,8 @@
#include "ecmascript/taskpool/runner.h"
#include "os/thread.h"
#include "libpandabase/os/mutex.h"
#include "libpandabase/os/thread.h"
namespace panda::ecmascript {
Runner::Runner(uint32_t threadNum) : totalThreadNum_(threadNum)

View File

@ -23,7 +23,7 @@
#include "ecmascript/common.h"
#include "ecmascript/taskpool/task_queue.h"
#include "os/mutex.h"
#include "libpandabase/os/mutex.h"
namespace panda::ecmascript {
static constexpr uint32_t MIN_TASKPOOL_THREAD_NUM = 3;

View File

@ -22,7 +22,7 @@
#include <memory>
#include "ecmascript/taskpool/task.h"
#include "os/mutex.h"
#include "libpandabase/os/mutex.h"
namespace panda::ecmascript {
class TaskQueue {

View File

@ -20,7 +20,7 @@
#include "ecmascript/common.h"
#include "ecmascript/taskpool/runner.h"
#include "os/mutex.h"
#include "libpandabase/os/mutex.h"
namespace panda::ecmascript {
class Taskpool {

View File

@ -1053,9 +1053,7 @@ void TSManager::FillSnapshotConstantPoolList(const std::map<int32_t, uint32_t> &
int32_t oldCPID = GetOldConstantPoolIDByMethodOffset(jsPandaFile, data.outerMethodOffset);
JSHandle<ConstantPool> oldCP(thread_, vm_->FindConstpool(jsPandaFile, oldCPID));
panda_file::File::IndexHeader *indexHeader = oldCP->GetIndexHeader();
Span<const panda_file::File::EntityId> indexs = jsPandaFile->GetPandaFile()->GetMethodIndex(indexHeader);
uint32_t methodOffset = indexs[data.index].GetOffset();
uint32_t methodOffset = oldCP->GetEntityId(data.index).GetOffset();
uint32_t cpListIndex = cpListIndexMap.at(oldCPID);
JSHandle<ConstantPool> newCP = GetSnapshotConstantPool(cpListIndex);

View File

@ -416,7 +416,7 @@ JSHandle<TaggedArray> TSTypeParser::GetExportDataFromRecord(const JSPandaFile *j
JSHandle<TaggedArray> typeOfExportedSymbols(thread_, thread_->GlobalConstants()->GetEmptyArray());
mda.EnumerateAnnotations([&](panda_file::File::EntityId annotationId) {
panda_file::AnnotationDataAccessor ada(pf, annotationId);
auto *annotationName = reinterpret_cast<const char *>(pf.GetStringData(ada.GetClassId()).data);
auto *annotationName = reinterpret_cast<const char *>(jsPandaFile->GetStringData(ada.GetClassId()).data);
ASSERT(annotationName != nullptr);
if (::strcmp("L_ESTypeAnnotation;", annotationName) != 0) {
return;
@ -424,7 +424,7 @@ JSHandle<TaggedArray> TSTypeParser::GetExportDataFromRecord(const JSPandaFile *j
uint32_t length = ada.GetCount();
for (uint32_t i = 0; i < length; i++) {
panda_file::AnnotationDataAccessor::Elem adae = ada.GetElement(i);
auto *elemName = reinterpret_cast<const char *>(pf.GetStringData(adae.GetNameId()).data);
auto *elemName = reinterpret_cast<const char *>(jsPandaFile->GetStringData(adae.GetNameId()).data);
ASSERT(elemName != nullptr);
if (::strcmp(symbolTypes, elemName) != 0) {

View File

@ -17,8 +17,6 @@
#include "ecmascript/base/number_helper.h"
#include "libpandabase/os/time.h"
namespace panda::ecmascript {
// --------------------------WaiterList------------------------------
void WaiterList::AddNode(WaiterListNode *node)