diff --git a/runtime/ecma_language_context.h b/runtime/ecma_language_context.h index 9259b5575b6b48fabd6ca7ab0d339a831191a857..973bf4aa44c3b1736168482d3a8dd33bc605dfde 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 f656e28f20899775b3beaffe26bc7704b4ffc939..cf6fdf2eb906857b76bd0adaba36e64cc8c38f09 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 a68988824bf89515e2d22c041e422535d07a5f18..474f2639cee8b1421fce1ba853c4133537dbd452 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_);