diff options
Diffstat (limited to 'deps/v8/src/log.h')
-rw-r--r-- | deps/v8/src/log.h | 252 |
1 files changed, 66 insertions, 186 deletions
diff --git a/deps/v8/src/log.h b/deps/v8/src/log.h index fdc50471b4..a05b187282 100644 --- a/deps/v8/src/log.h +++ b/deps/v8/src/log.h @@ -8,14 +8,19 @@ #include <string> #include "src/allocation.h" +#include "src/base/compiler-specific.h" #include "src/base/platform/elapsed-timer.h" #include "src/base/platform/platform.h" +#include "src/code-events.h" +#include "src/isolate.h" #include "src/objects.h" namespace v8 { -namespace base { -class Semaphore; +struct TickSample; + +namespace sampler { +class Sampler; } namespace internal { @@ -56,108 +61,35 @@ namespace internal { // Forward declarations. class CodeEventListener; -class CompilationInfo; class CpuProfiler; class Isolate; +class JitLogger; class Log; -class PositionsRecorder; +class LowLevelLogger; +class PerfBasicLogger; +class PerfJitLogger; class Profiler; +class ProfilerListener; +class RuntimeCallTimer; class Ticker; -struct TickSample; #undef LOG -#define LOG(isolate, Call) \ - do { \ - v8::internal::Logger* logger = \ - (isolate)->logger(); \ - if (logger->is_logging()) \ - logger->Call; \ +#define LOG(isolate, Call) \ + do { \ + v8::internal::Logger* logger = (isolate)->logger(); \ + if (logger->is_logging()) logger->Call; \ } while (false) -#define LOG_CODE_EVENT(isolate, Call) \ - do { \ - v8::internal::Logger* logger = \ - (isolate)->logger(); \ - if (logger->is_logging_code_events()) \ - logger->Call; \ +#define LOG_CODE_EVENT(isolate, Call) \ + do { \ + v8::internal::Logger* logger = (isolate)->logger(); \ + if (logger->is_logging_code_events()) logger->Call; \ } while (false) -#define LOG_EVENTS_AND_TAGS_LIST(V) \ - V(CODE_CREATION_EVENT, "code-creation") \ - V(CODE_DISABLE_OPT_EVENT, "code-disable-optimization") \ - V(CODE_MOVE_EVENT, "code-move") \ - V(CODE_DELETE_EVENT, "code-delete") \ - V(CODE_MOVING_GC, "code-moving-gc") \ - V(SHARED_FUNC_MOVE_EVENT, "sfi-move") \ - V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name") \ - V(TICK_EVENT, "tick") \ - V(REPEAT_META_EVENT, "repeat") \ - V(BUILTIN_TAG, "Builtin") \ - V(CALL_DEBUG_BREAK_TAG, "CallDebugBreak") \ - V(CALL_DEBUG_PREPARE_STEP_IN_TAG, "CallDebugPrepareStepIn") \ - V(CALL_INITIALIZE_TAG, "CallInitialize") \ - V(CALL_MEGAMORPHIC_TAG, "CallMegamorphic") \ - V(CALL_MISS_TAG, "CallMiss") \ - V(CALL_NORMAL_TAG, "CallNormal") \ - V(CALL_PRE_MONOMORPHIC_TAG, "CallPreMonomorphic") \ - V(LOAD_INITIALIZE_TAG, "LoadInitialize") \ - V(LOAD_PREMONOMORPHIC_TAG, "LoadPreMonomorphic") \ - V(LOAD_MEGAMORPHIC_TAG, "LoadMegamorphic") \ - V(STORE_INITIALIZE_TAG, "StoreInitialize") \ - V(STORE_PREMONOMORPHIC_TAG, "StorePreMonomorphic") \ - V(STORE_GENERIC_TAG, "StoreGeneric") \ - V(STORE_MEGAMORPHIC_TAG, "StoreMegamorphic") \ - V(KEYED_CALL_DEBUG_BREAK_TAG, "KeyedCallDebugBreak") \ - V(KEYED_CALL_DEBUG_PREPARE_STEP_IN_TAG, "KeyedCallDebugPrepareStepIn") \ - V(KEYED_CALL_INITIALIZE_TAG, "KeyedCallInitialize") \ - V(KEYED_CALL_MEGAMORPHIC_TAG, "KeyedCallMegamorphic") \ - V(KEYED_CALL_MISS_TAG, "KeyedCallMiss") \ - V(KEYED_CALL_NORMAL_TAG, "KeyedCallNormal") \ - V(KEYED_CALL_PRE_MONOMORPHIC_TAG, "KeyedCallPreMonomorphic") \ - V(CALLBACK_TAG, "Callback") \ - V(EVAL_TAG, "Eval") \ - V(FUNCTION_TAG, "Function") \ - V(HANDLER_TAG, "Handler") \ - V(BYTECODE_HANDLER_TAG, "BytecodeHandler") \ - V(KEYED_LOAD_IC_TAG, "KeyedLoadIC") \ - V(KEYED_LOAD_POLYMORPHIC_IC_TAG, "KeyedLoadPolymorphicIC") \ - V(KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, "KeyedExternalArrayLoadIC") \ - V(KEYED_STORE_IC_TAG, "KeyedStoreIC") \ - V(KEYED_STORE_POLYMORPHIC_IC_TAG, "KeyedStorePolymorphicIC") \ - V(KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, "KeyedExternalArrayStoreIC") \ - V(LAZY_COMPILE_TAG, "LazyCompile") \ - V(CALL_IC_TAG, "CallIC") \ - V(LOAD_IC_TAG, "LoadIC") \ - V(LOAD_POLYMORPHIC_IC_TAG, "LoadPolymorphicIC") \ - V(REG_EXP_TAG, "RegExp") \ - V(SCRIPT_TAG, "Script") \ - V(STORE_IC_TAG, "StoreIC") \ - V(STORE_POLYMORPHIC_IC_TAG, "StorePolymorphicIC") \ - V(STUB_TAG, "Stub") \ - V(NATIVE_FUNCTION_TAG, "Function") \ - V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile") \ - V(NATIVE_SCRIPT_TAG, "Script") -// Note that 'NATIVE_' cases for functions and scripts are mapped onto -// original tags when writing to the log. - - -class JitLogger; -class PerfBasicLogger; -class LowLevelLogger; -class PerfJitLogger; -class Sampler; - -class Logger { +class Logger : public CodeEventListener { public: enum StartEnd { START = 0, END = 1 }; -#define DECLARE_ENUM(enum_item, ignore) enum_item, - enum LogEventsAndTags { - LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM) - NUMBER_OF_LOG_EVENTS - }; -#undef DECLARE_ENUM - // Acquires resources for logging if the right flags are set. bool SetUp(Isolate* isolate); @@ -165,7 +97,15 @@ class Logger { void SetCodeEventHandler(uint32_t options, JitCodeEventHandler event_handler); - Sampler* sampler(); + // Sets up ProfilerListener. + void SetUpProfilerListener(); + + // Tear down ProfilerListener if it has no observers. + void TearDownProfilerListener(); + + sampler::Sampler* sampler(); + + ProfilerListener* profiler_listener() { return profiler_listener_.get(); } // Frees resources acquired in SetUp. // When a temporary file is used for the log, returns its stream descriptor, @@ -211,29 +151,27 @@ class Logger { void ApiObjectAccess(const char* tag, JSObject* obj); void ApiEntryCall(const char* name); - // ==== Events logged by --log-code. ==== void addCodeEventListener(CodeEventListener* listener); void removeCodeEventListener(CodeEventListener* listener); - bool hasCodeEventListener(CodeEventListener* listener); - // Emits a code event for a callback function. void CallbackEvent(Name* name, Address entry_point); void GetterCallbackEvent(Name* name, Address entry_point); void SetterCallbackEvent(Name* name, Address entry_point); // Emits a code create event. - void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, - const char* source); - void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name); - void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, - SharedFunctionInfo* shared, CompilationInfo* info, + void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, + AbstractCode* code, const char* source); + void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, + AbstractCode* code, Name* name); + void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, + AbstractCode* code, SharedFunctionInfo* shared, Name* name); - void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, - SharedFunctionInfo* shared, CompilationInfo* info, + void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, + AbstractCode* code, SharedFunctionInfo* shared, Name* source, int line, int column); - void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, - int args_count); + void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, + AbstractCode* code, int args_count); // Emits a code deoptimization event. void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared); void CodeMovingGCEvent(); @@ -241,25 +179,16 @@ class Logger { void RegExpCodeCreateEvent(AbstractCode* code, String* source); // Emits a code move event. void CodeMoveEvent(AbstractCode* from, Address to); - // Emits a code line info add event with Postion type. - void CodeLinePosInfoAddPositionEvent(void* jit_handler_data, - int pc_offset, - int position); - // Emits a code line info add event with StatementPostion type. - void CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data, - int pc_offset, - int position); - // Emits a code line info start to record event - void CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder); - // Emits a code line info finish record event. - // It's the callee's responsibility to dispose the parameter jit_handler_data. - void CodeEndLinePosInfoRecordEvent(AbstractCode* code, - void* jit_handler_data); + // Emits a code line info record event. + void CodeLinePosInfoRecordEvent(AbstractCode* code, + ByteArray* source_position_table); void SharedFunctionInfoMoveEvent(Address from, Address to); void CodeNameEvent(Address addr, int pos, const char* code_name); + void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta); + // ==== Events logged by --log-gc. ==== // Heap sampling events: start, end, and individual types. void HeapSampleBeginEvent(const char* space, const char* kind); @@ -274,11 +203,9 @@ class Logger { void HeapSampleStats(const char* space, const char* kind, intptr_t capacity, intptr_t used); - void SharedLibraryEvent(const std::string& library_path, - uintptr_t start, - uintptr_t end); + void SharedLibraryEvent(const std::string& library_path, uintptr_t start, + uintptr_t end, intptr_t aslr_slide); - void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta); void CurrentTimeEvent(); void TimerEvent(StartEnd se, const char* name); @@ -320,7 +247,8 @@ class Logger { void LogBytecodeHandlers(); // Converts tag to a corresponding NATIVE_... if the script is native. - INLINE(static LogEventsAndTags ToNativeByScript(LogEventsAndTags, Script*)); + INLINE(static CodeEventListener::LogEventsAndTags ToNativeByScript( + CodeEventListener::LogEventsAndTags, Script*)); // Profiler's sampling interval (in milliseconds). #if defined(ANDROID) @@ -347,18 +275,20 @@ class Logger { Address entry_point); // Internal configurable move event. - void MoveEventInternal(LogEventsAndTags event, Address from, Address to); + void MoveEventInternal(CodeEventListener::LogEventsAndTags event, + Address from, Address to); // Used for logging stubs found in the snapshot. void LogCodeObject(Object* code_object); // Helper method. It resets name_buffer_ and add tag name into it. - void InitNameBuffer(LogEventsAndTags tag); + void InitNameBuffer(CodeEventListener::LogEventsAndTags tag); // Emits a profiler tick event. Used by the profiler thread. void TickEvent(TickSample* sample, bool overflow); + void RuntimeCallTimerEvent(); - void ApiEvent(const char* name, ...); + PRINTF_FORMAT(2, 3) void ApiEvent(const char* format, ...); // Logs a StringEvent regardless of whether FLAG_log is true. void UncheckedStringEvent(const char* name, const char* value); @@ -395,6 +325,7 @@ class Logger { PerfJitLogger* perf_jit_logger_; LowLevelLogger* ll_logger_; JitLogger* jit_logger_; + std::unique_ptr<ProfilerListener> profiler_listener_; List<CodeEventListener*> listeners_; // Guards against multiple calls to TearDown() that can happen in some tests. @@ -437,79 +368,27 @@ class TimerEventScope { ~TimerEventScope() { LogTimerEvent(Logger::END); } - void LogTimerEvent(Logger::StartEnd se); - private: + void LogTimerEvent(Logger::StartEnd se); Isolate* isolate_; }; -class PositionsRecorder BASE_EMBEDDED { - public: - PositionsRecorder() { jit_handler_data_ = NULL; } - - void AttachJITHandlerData(void* user_data) { jit_handler_data_ = user_data; } - - void* DetachJITHandlerData() { - void* old_data = jit_handler_data_; - jit_handler_data_ = NULL; - return old_data; - } - - protected: - // Currently jit_handler_data_ is used to store JITHandler-specific data - // over the lifetime of a PositionsRecorder - void* jit_handler_data_; - - private: - DISALLOW_COPY_AND_ASSIGN(PositionsRecorder); -}; - -class CodeEventListener { - public: - virtual ~CodeEventListener() {} - - virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - const char* comment) = 0; - virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - Name* name) = 0; - virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - SharedFunctionInfo* shared, - CompilationInfo* info, Name* name) = 0; - virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - SharedFunctionInfo* shared, - CompilationInfo* info, Name* source, int line, - int column) = 0; - virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - int args_count) = 0; - virtual void CallbackEvent(Name* name, Address entry_point) = 0; - virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0; - virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0; - virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0; - virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0; - virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0; - virtual void CodeMovingGCEvent() = 0; - virtual void CodeDisableOptEvent(AbstractCode* code, - SharedFunctionInfo* shared) = 0; -}; - - class CodeEventLogger : public CodeEventListener { public: CodeEventLogger(); ~CodeEventLogger() override; - void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, + void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, const char* comment) override; - void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, + void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name) override; - void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, + void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, int args_count) override; - void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - SharedFunctionInfo* shared, CompilationInfo* info, - Name* name) override; - void CodeCreateEvent(Logger::LogEventsAndTags tag, AbstractCode* code, - SharedFunctionInfo* shared, CompilationInfo* info, - Name* source, int line, int column) override; + void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, + SharedFunctionInfo* shared, Name* name) override; + void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, + SharedFunctionInfo* shared, Name* source, int line, + int column) override; void RegExpCodeCreateEvent(AbstractCode* code, String* source) override; void CallbackEvent(Name* name, Address entry_point) override {} @@ -517,6 +396,7 @@ class CodeEventLogger : public CodeEventListener { void SetterCallbackEvent(Name* name, Address entry_point) override {} void SharedFunctionInfoMoveEvent(Address from, Address to) override {} void CodeMovingGCEvent() override {} + void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) override {} private: class NameBuffer; |