From b13ed10b2e998fb0d9adb256e991538ebb049df2 Mon Sep 17 00:00:00 2001 From: Petrov Igor Date: Wed, 18 Jan 2023 15:34:54 +0300 Subject: [PATCH] [MM] Fix printing of memory statistics for dyn objects Signed-off-by: Petrov Igor --- runtime/ecma_language_context.h | 6 ++++++ runtime/ecma_vm.cpp | 15 +++++++++++++++ runtime/ecma_vm.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/runtime/ecma_language_context.h b/runtime/ecma_language_context.h index 9259b5575..973bf4aa4 100644 --- a/runtime/ecma_language_context.h +++ b/runtime/ecma_language_context.h @@ -16,6 +16,7 @@ #ifndef ECMASCRIPT_LANGUAGE_CONTEXT_H #define ECMASCRIPT_LANGUAGE_CONTEXT_H +#include "include/language_config.h" #include "plugins/ecmascript/runtime/common.h" #include "include/language_context.h" #include "plugins/ecmascript/runtime/js_hclass.h" @@ -35,6 +36,11 @@ public: return panda_file::SourceLang::ECMASCRIPT; } + LangTypeT GetLanguageType() const override + { + return EcmascriptLanguageConfig::LANG_TYPE; + } + std::pair GetCatchMethodAndOffset(Method *method, ManagedThread *thread) const override; PandaVM *CreateVM(Runtime *runtime, const RuntimeOptions &options) const override; diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index f656e28f2..cf6fdf2eb 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -14,6 +14,7 @@ */ #include "plugins/ecmascript/runtime/ecma_vm.h" +#include "include/mem/panda_containers.h" #include "include/mem/panda_string.h" #include "plugins/ecmascript/runtime/bridge.h" @@ -469,6 +470,20 @@ void EcmaVM::DumpHeap(PandaOStringStream *o_str) const *o_str << "\nTotal dumped " << obj_cnt << std::endl; } +PandaString EcmaVM::GetClassesFootprint() const +{ + PandaUnorderedMap classes_footprint; + PandaStringStream result; + GetHeapManager()->GetObjectAllocator()->IterateOverObjects([&classes_footprint](ObjectHeader *mem) { + auto obj_type = JSTaggedValue(mem).GetTaggedObject()->GetClass()->GetObjectType(); + classes_footprint[obj_type] += mem->ObjectSize(); + }); + for (const auto &it : classes_footprint) { + result << "class: " << JSHClass::DumpJSType(it.first) << ", footprint - " << it.second << std::endl; + } + return result.str(); +} + tooling::ecmascript::PtJSExtractor *EcmaVM::GetDebugInfoExtractor(const panda_file::File *file) { tooling::ecmascript::PtJSExtractor *res = nullptr; diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index a68988824..474f2639c 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -19,6 +19,7 @@ #include #include "include/mem/panda_containers.h" +#include "include/mem/panda_string.h" #include "plugins/ecmascript/runtime/base/config.h" #include "plugins/ecmascript/runtime/ecma_call_profiling_table.h" #include "plugins/ecmascript/runtime/ecma_string_table.h" @@ -453,6 +454,8 @@ public: void DumpHeap(PandaOStringStream *o_str) const final; + PandaString GetClassesFootprint() const final; + static constexpr size_t GetGlobalEnvOffset() { return MEMBER_OFFSET(EcmaVM, global_env_); -- Gitee