diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index c98d4a265c2c07618348490598f9565ca7498fcc..433b5128ff2ee873981e88c2e49152a7370f7c72 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -179,6 +179,8 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) : string_table_(new EcmaStringTable(thi ecma_reference_processor_ = MakePandaUnique(); } + is_profiling_enabled_ = options_.IsCompilerEnableJit() || options_.WasSetProfileOutput(); + auto heap_manager = mm_->GetHeapManager(); auto internal_allocator = heap_manager->GetInternalAllocator(); runtime_iface_ = internal_allocator->New(this); diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index 8406f864bf36b3c67ca3e0c4d51c0ab0d8da5469..3b3da59ff1518df7f3c5d54ab2cab6cf25dcd9b5 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -390,6 +390,11 @@ public: return notification_manager_; } + bool IsBytecodeProfilingEnabled() const override + { + return is_profiling_enabled_; + } + std::unique_ptr OpenPandaFile(std::string_view location) override; coretypes::String *GetNonMovableString(const panda_file::File &pf, panda_file::File::EntityId id) const override; @@ -502,6 +507,7 @@ private: bool ic_enable_ {true}; bool vm_initialized_ {false}; bool is_uncaught_exception_registered_ {false}; + bool is_profiling_enabled_ {false}; // VM memory management. EcmaStringTable *string_table_ {nullptr}; diff --git a/runtime/interpreter/ecma-interpreter-inl.h b/runtime/interpreter/ecma-interpreter-inl.h index b9e4c7ed00c5756954be6f654449100d2b31c2bd..e389edc60fafd099f9dded1ec1a705b1c653f9b4 100644 --- a/runtime/interpreter/ecma-interpreter-inl.h +++ b/runtime/interpreter/ecma-interpreter-inl.h @@ -59,15 +59,21 @@ namespace panda::ecmascript { } \ } while (false) -#ifdef PANDA_ENABLE_BYTECODE_PROFILING -#define UPDATE_UNARY_ARITH_PROFILE(lhs) UpdateUnaryArithProfile(lhs) -#define UPDATE_BINARY_ARITH_PROFILE(lhs, rhs) UpdateBinaryArithProfile(lhs, rhs) -#else -#define UPDATE_UNARY_ARITH_PROFILE(lhs) UNUSED_VAR(lhs) +#define UPDATE_UNARY_ARITH_PROFILE(lhs) \ + if constexpr (IS_PROFILE_ENABLED) { \ + UpdateUnaryArithProfile(lhs); \ + } else { \ + UNUSED_VAR(lhs); \ + } + #define UPDATE_BINARY_ARITH_PROFILE(lhs, rhs) \ - UNUSED_VAR(lhs); \ - UNUSED_VAR(rhs) -#endif + if constexpr (IS_PROFILE_ENABLED) { \ + UpdateBinaryArithProfile(lhs, rhs); \ + } else { \ + UNUSED_VAR(lhs); \ + UNUSED_VAR(rhs); \ + } + template class JSFrameHelper { public: @@ -100,7 +106,8 @@ public: } }; -template +template class InstructionHandler : public interpreter::InstructionHandler { public: ALWAYS_INLINE inline InstructionHandler(interpreter::InstructionHandlerState *state) @@ -2557,6 +2564,10 @@ public: void UpdateUnaryArithProfile(coretypes::TaggedType value) { auto method = static_cast(this->GetFrame()->GetMethod()); + // Profiling is not initialized + if (method->GetProfileSize() == 0) { + return; + } auto prof_data = method->GetProfilingVector(); auto prof_id = this->GetInst().GetProfileId(); ASSERT(prof_id >= 0); @@ -2570,6 +2581,10 @@ public: auto left = JSTaggedValue(lhs); auto right = JSTaggedValue(rhs); auto method = static_cast(this->GetFrame()->GetMethod()); + // Profiling is not initialized + if (method->GetProfileSize() == 0) { + return; + } auto prof_data = method->GetProfilingVector(); auto prof_id = this->GetInst().GetProfileId(); ASSERT(prof_id >= 0); diff --git a/tests/checked/CMakeLists.txt b/tests/checked/CMakeLists.txt index 63f9e3c5dbfafaedb1fbd4c941302a310670ace1..769c10ab1372e91975372ed07cb99d104b10f986 100644 --- a/tests/checked/CMakeLists.txt +++ b/tests/checked/CMakeLists.txt @@ -92,9 +92,7 @@ endfunction() if (NOT PANDA_TARGET_ARM32) panda_add_checked_test_ecma(FILE ${CMAKE_CURRENT_SOURCE_DIR}/type_resolving.js SUPPORT_RELEASE true) panda_add_checked_test_ecma(FILE ${CMAKE_CURRENT_SOURCE_DIR}/global_var.js SUPPORT_RELEASE true) - if (PANDA_ENABLE_BYTECODE_PROFILING) - panda_add_checked_test_ecma(FILE ${CMAKE_CURRENT_SOURCE_DIR}/ecma_profiling.js SUPPORT_RELEASE true) - endif() + panda_add_checked_test_ecma(FILE ${CMAKE_CURRENT_SOURCE_DIR}/ecma_profiling.js SUPPORT_RELEASE true) # there is flaky bug when turning on TSAN if (NOT PANDA_ENABLE_THREAD_SANITIZER) panda_add_checked_test_ecma(FILE ${CMAKE_CURRENT_SOURCE_DIR}/acc_after_deopt.js SUPPORT_RELEASE true)