blob: 303e352898a0cd76a8774be863fbe787e3b56d65 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_LOG_H_
6#define V8_LOG_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include <string>
9
10#include "src/allocation.h"
Ben Murdochc5610432016-08-08 18:44:38 +010011#include "src/base/compiler-specific.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012#include "src/base/platform/elapsed-timer.h"
13#include "src/base/platform/platform.h"
Ben Murdoch61f157c2016-09-16 13:49:30 +010014#include "src/code-events.h"
15#include "src/isolate.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000016#include "src/objects.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000017
18namespace v8 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019
20namespace base {
21class Semaphore;
22}
23
Ben Murdoch61f157c2016-09-16 13:49:30 +010024namespace sampler {
25class Sampler;
26}
27
Steve Blocka7e24c12009-10-30 11:49:00 +000028namespace internal {
29
30// Logger is used for collecting logging information from V8 during
31// execution. The result is dumped to a file.
32//
33// Available command line flags:
34//
35// --log
36// Minimal logging (no API, code, or GC sample events), default is off.
37//
38// --log-all
39// Log all events to the file, default is off. This is the same as combining
40// --log-api, --log-code, --log-gc, and --log-regexp.
41//
42// --log-api
43// Log API events to the logfile, default is off. --log-api implies --log.
44//
45// --log-code
46// Log code (create, move, and delete) events to the logfile, default is off.
47// --log-code implies --log.
48//
49// --log-gc
50// Log GC heap samples after each GC that can be processed by hp2ps, default
51// is off. --log-gc implies --log.
52//
53// --log-regexp
54// Log creation and use of regular expressions, Default is off.
55// --log-regexp implies --log.
56//
57// --logfile <filename>
58// Specify the name of the logfile, default is "v8.log".
59//
60// --prof
61// Collect statistical profiling information (ticks), default is off. The
62// tick profiler requires code events, so --prof implies --log-code.
63
64// Forward declarations.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065class CodeEventListener;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066class CpuProfiler;
67class Isolate;
68class Log;
69class PositionsRecorder;
Steve Blocka7e24c12009-10-30 11:49:00 +000070class Profiler;
Ben Murdoch257744e2011-11-30 15:57:28 +000071class Ticker;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072struct TickSample;
Ben Murdoch61f157c2016-09-16 13:49:30 +010073class RuntimeCallTimer;
Steve Blocka7e24c12009-10-30 11:49:00 +000074
75#undef LOG
Ben Murdoch61f157c2016-09-16 13:49:30 +010076#define LOG(isolate, Call) \
77 do { \
78 v8::internal::Logger* logger = (isolate)->logger(); \
79 if (logger->is_logging()) logger->Call; \
Steve Blocka7e24c12009-10-30 11:49:00 +000080 } while (false)
Steve Blocka7e24c12009-10-30 11:49:00 +000081
Ben Murdoch61f157c2016-09-16 13:49:30 +010082#define LOG_CODE_EVENT(isolate, Call) \
83 do { \
84 v8::internal::Logger* logger = (isolate)->logger(); \
85 if (logger->is_logging_code_events()) logger->Call; \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086 } while (false)
87
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088class JitLogger;
89class PerfBasicLogger;
90class LowLevelLogger;
Ben Murdochda12d292016-06-02 14:46:10 +010091class PerfJitLogger;
Ben Murdoch61f157c2016-09-16 13:49:30 +010092class ProfilerListener;
Steve Block44f0eee2011-05-26 01:26:41 +010093
Ben Murdoch61f157c2016-09-16 13:49:30 +010094class Logger : public CodeEventListener {
Steve Blocka7e24c12009-10-30 11:49:00 +000095 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096 enum StartEnd { START = 0, END = 1 };
97
Steve Blocka7e24c12009-10-30 11:49:00 +000098 // Acquires resources for logging if the right flags are set.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099 bool SetUp(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000100
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 // Sets the current code event handler.
102 void SetCodeEventHandler(uint32_t options,
103 JitCodeEventHandler event_handler);
Steve Block44f0eee2011-05-26 01:26:41 +0100104
Ben Murdoch61f157c2016-09-16 13:49:30 +0100105 // Sets up ProfilerListener.
106 void SetUpProfilerListener();
107
108 // Tear down ProfilerListener if it has no observers.
109 void TearDownProfilerListener();
110
111 sampler::Sampler* sampler();
112
113 ProfilerListener* profiler_listener() { return profiler_listener_.get(); }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100114
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100115 // Frees resources acquired in SetUp.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000116 // When a temporary file is used for the log, returns its stream descriptor,
117 // leaving the file open.
118 FILE* TearDown();
Steve Blocka7e24c12009-10-30 11:49:00 +0000119
Steve Blocka7e24c12009-10-30 11:49:00 +0000120 // Emits an event with a string value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100121 void StringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000122
123 // Emits an event with an int value -> (name, value).
Steve Block44f0eee2011-05-26 01:26:41 +0100124 void IntEvent(const char* name, int value);
125 void IntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000126
127 // Emits an event with an handle value -> (name, location).
Steve Block44f0eee2011-05-26 01:26:41 +0100128 void HandleEvent(const char* name, Object** location);
Steve Blocka7e24c12009-10-30 11:49:00 +0000129
130 // Emits memory management events for C allocated structures.
Steve Block44f0eee2011-05-26 01:26:41 +0100131 void NewEvent(const char* name, void* object, size_t size);
132 void DeleteEvent(const char* name, void* object);
133
Steve Blocka7e24c12009-10-30 11:49:00 +0000134 // Emits an event with a tag, and some resource usage information.
135 // -> (name, tag, <rusage information>).
136 // Currently, the resource usage information is a process time stamp
137 // and a real time timestamp.
Steve Block44f0eee2011-05-26 01:26:41 +0100138 void ResourceEvent(const char* name, const char* tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000139
140 // Emits an event that an undefined property was read from an
141 // object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000142 void SuspectReadEvent(Name* name, Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000143
144 // Emits an event when a message is put on or read from a debugging queue.
145 // DebugTag lets us put a call-site specific label on the event.
Steve Block44f0eee2011-05-26 01:26:41 +0100146 void DebugTag(const char* call_site_tag);
147 void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
Steve Blocka7e24c12009-10-30 11:49:00 +0000148
149
150 // ==== Events logged by --log-api. ====
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000151 void ApiSecurityCheck();
Steve Block44f0eee2011-05-26 01:26:41 +0100152 void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
153 void ApiIndexedPropertyAccess(const char* tag,
154 JSObject* holder,
155 uint32_t index);
156 void ApiObjectAccess(const char* tag, JSObject* obj);
157 void ApiEntryCall(const char* name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000158
Steve Blocka7e24c12009-10-30 11:49:00 +0000159 // ==== Events logged by --log-code. ====
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000160 void addCodeEventListener(CodeEventListener* listener);
161 void removeCodeEventListener(CodeEventListener* listener);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000162
Steve Blockd0582a62009-12-15 09:54:21 +0000163 // Emits a code event for a callback function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000164 void CallbackEvent(Name* name, Address entry_point);
165 void GetterCallbackEvent(Name* name, Address entry_point);
166 void SetterCallbackEvent(Name* name, Address entry_point);
Steve Blocka7e24c12009-10-30 11:49:00 +0000167 // Emits a code create event.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100168 void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
169 AbstractCode* code, const char* source);
170 void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
171 AbstractCode* code, Name* name);
172 void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
173 AbstractCode* code, SharedFunctionInfo* shared,
174 Name* name);
175 void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
176 AbstractCode* code, SharedFunctionInfo* shared,
177 Name* source, int line, int column);
178 void CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
179 AbstractCode* code, int args_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000180 // Emits a code deoptimization event.
Ben Murdochda12d292016-06-02 14:46:10 +0100181 void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared);
Steve Block44f0eee2011-05-26 01:26:41 +0100182 void CodeMovingGCEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000183 // Emits a code create event for a RegExp.
Ben Murdochda12d292016-06-02 14:46:10 +0100184 void RegExpCodeCreateEvent(AbstractCode* code, String* source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185 // Emits a code move event.
Ben Murdochda12d292016-06-02 14:46:10 +0100186 void CodeMoveEvent(AbstractCode* from, Address to);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187 // Emits a code line info add event with Postion type.
188 void CodeLinePosInfoAddPositionEvent(void* jit_handler_data,
189 int pc_offset,
190 int position);
191 // Emits a code line info add event with StatementPostion type.
192 void CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data,
193 int pc_offset,
194 int position);
195 // Emits a code line info start to record event
196 void CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder);
197 // Emits a code line info finish record event.
198 // It's the callee's responsibility to dispose the parameter jit_handler_data.
Ben Murdochda12d292016-06-02 14:46:10 +0100199 void CodeEndLinePosInfoRecordEvent(AbstractCode* code,
200 void* jit_handler_data);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100201
Steve Block44f0eee2011-05-26 01:26:41 +0100202 void SharedFunctionInfoMoveEvent(Address from, Address to);
Steve Blocka7e24c12009-10-30 11:49:00 +0000203
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000204 void CodeNameEvent(Address addr, int pos, const char* code_name);
Leon Clarkee46be812010-01-19 14:06:41 +0000205
Ben Murdoch61f157c2016-09-16 13:49:30 +0100206 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta);
207
Steve Blocka7e24c12009-10-30 11:49:00 +0000208 // ==== Events logged by --log-gc. ====
209 // Heap sampling events: start, end, and individual types.
Steve Block44f0eee2011-05-26 01:26:41 +0100210 void HeapSampleBeginEvent(const char* space, const char* kind);
211 void HeapSampleEndEvent(const char* space, const char* kind);
212 void HeapSampleItemEvent(const char* type, int number, int bytes);
213 void HeapSampleJSConstructorEvent(const char* constructor,
214 int number, int bytes);
215 void HeapSampleJSRetainersEvent(const char* constructor,
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 const char* event);
Steve Block44f0eee2011-05-26 01:26:41 +0100217 void HeapSampleJSProducerEvent(const char* constructor,
218 Address* stack);
219 void HeapSampleStats(const char* space, const char* kind,
220 intptr_t capacity, intptr_t used);
Steve Blocka7e24c12009-10-30 11:49:00 +0000221
Ben Murdochc5610432016-08-08 18:44:38 +0100222 void SharedLibraryEvent(const std::string& library_path, uintptr_t start,
223 uintptr_t end, intptr_t aslr_slide);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000224
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000225 void CurrentTimeEvent();
226
227 void TimerEvent(StartEnd se, const char* name);
228
229 static void EnterExternal(Isolate* isolate);
230 static void LeaveExternal(Isolate* isolate);
231
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400232 static void DefaultEventLoggerSentinel(const char* name, int event) {}
233
234 INLINE(static void CallEventLogger(Isolate* isolate, const char* name,
235 StartEnd se, bool expose_to_api));
Steve Blocka7e24c12009-10-30 11:49:00 +0000236
237 // ==== Events logged by --log-regexp ====
238 // Regexp compilation and execution events.
239
Steve Block44f0eee2011-05-26 01:26:41 +0100240 void RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241
Steve Block44f0eee2011-05-26 01:26:41 +0100242 bool is_logging() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000243 return is_logging_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000244 }
245
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246 bool is_logging_code_events() {
247 return is_logging() || jit_logger_ != NULL;
248 }
249
250 // Stop collection of profiling data.
251 // When data collection is paused, CPU Tick events are discarded.
252 void StopProfiler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000253
Ben Murdoch589d6972011-11-30 16:04:58 +0000254 void LogExistingFunction(Handle<SharedFunctionInfo> shared,
Ben Murdochda12d292016-06-02 14:46:10 +0100255 Handle<AbstractCode> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000256 // Logs all compiled functions found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100257 void LogCompiledFunctions();
Steve Blockd0582a62009-12-15 09:54:21 +0000258 // Logs all accessor callbacks found in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100259 void LogAccessorCallbacks();
Steve Blockd0582a62009-12-15 09:54:21 +0000260 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100261 void LogCodeObjects();
Ben Murdochda12d292016-06-02 14:46:10 +0100262 // Used for logging bytecode handlers found in the snapshot.
263 void LogBytecodeHandlers();
Steve Blocka7e24c12009-10-30 11:49:00 +0000264
Steve Block6ded16b2010-05-10 14:33:55 +0100265 // Converts tag to a corresponding NATIVE_... if the script is native.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100266 INLINE(static CodeEventListener::LogEventsAndTags ToNativeByScript(
267 CodeEventListener::LogEventsAndTags, Script*));
Steve Blocka7e24c12009-10-30 11:49:00 +0000268
269 // Profiler's sampling interval (in milliseconds).
Ben Murdoch75492482011-12-01 11:18:12 +0000270#if defined(ANDROID)
271 // Phones and tablets have processors that are much slower than desktop
272 // and laptop computers for which current heuristics are tuned.
273 static const int kSamplingIntervalMs = 5;
274#else
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 static const int kSamplingIntervalMs = 1;
Ben Murdoch75492482011-12-01 11:18:12 +0000276#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000277
Steve Block44f0eee2011-05-26 01:26:41 +0100278 // Callback from Log, stops profiling in case of insufficient resources.
279 void LogFailure();
280
Steve Block6ded16b2010-05-10 14:33:55 +0100281 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282 explicit Logger(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100283 ~Logger();
Steve Block6ded16b2010-05-10 14:33:55 +0100284
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 // Emits the profiler's first message.
Steve Block44f0eee2011-05-26 01:26:41 +0100286 void ProfilerBeginEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000287
Steve Blockd0582a62009-12-15 09:54:21 +0000288 // Emits callback event messages.
Steve Block44f0eee2011-05-26 01:26:41 +0100289 void CallbackEventInternal(const char* prefix,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000290 Name* name,
Steve Block44f0eee2011-05-26 01:26:41 +0100291 Address entry_point);
Steve Blockd0582a62009-12-15 09:54:21 +0000292
Leon Clarked91b9f72010-01-27 17:25:45 +0000293 // Internal configurable move event.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100294 void MoveEventInternal(CodeEventListener::LogEventsAndTags event,
295 Address from, Address to);
Leon Clarked91b9f72010-01-27 17:25:45 +0000296
Andrei Popescu31002712010-02-23 13:46:05 +0000297 // Used for logging stubs found in the snapshot.
Steve Block44f0eee2011-05-26 01:26:41 +0100298 void LogCodeObject(Object* code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000299
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000300 // Helper method. It resets name_buffer_ and add tag name into it.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100301 void InitNameBuffer(CodeEventListener::LogEventsAndTags tag);
Ben Murdochf87a2032010-10-22 12:50:53 +0100302
Steve Blocka7e24c12009-10-30 11:49:00 +0000303 // Emits a profiler tick event. Used by the profiler thread.
Steve Block44f0eee2011-05-26 01:26:41 +0100304 void TickEvent(TickSample* sample, bool overflow);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100305 void RuntimeCallTimerEvent();
Steve Blocka7e24c12009-10-30 11:49:00 +0000306
Ben Murdochc5610432016-08-08 18:44:38 +0100307 PRINTF_FORMAT(2, 3) void ApiEvent(const char* format, ...);
Steve Blocka7e24c12009-10-30 11:49:00 +0000308
309 // Logs a StringEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100310 void UncheckedStringEvent(const char* name, const char* value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000311
Steve Block6ded16b2010-05-10 14:33:55 +0100312 // Logs an IntEvent regardless of whether FLAG_log is true.
Steve Block44f0eee2011-05-26 01:26:41 +0100313 void UncheckedIntEvent(const char* name, int value);
314 void UncheckedIntPtrTEvent(const char* name, intptr_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000315
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000316 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000317
318 // The sampler used by the profiler and the sliding state window.
Steve Block44f0eee2011-05-26 01:26:41 +0100319 Ticker* ticker_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000320
321 // When the statistical profile is active, profiler_
322 // points to a Profiler, that handles collection
323 // of samples.
Steve Block44f0eee2011-05-26 01:26:41 +0100324 Profiler* profiler_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
Steve Block44f0eee2011-05-26 01:26:41 +0100326 // An array of log events names.
327 const char* const* log_events_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000328
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 // Internal implementation classes with access to
330 // private members.
Steve Blocka7e24c12009-10-30 11:49:00 +0000331 friend class EventLog;
Steve Block44f0eee2011-05-26 01:26:41 +0100332 friend class Isolate;
Steve Blocka7e24c12009-10-30 11:49:00 +0000333 friend class TimeLog;
334 friend class Profiler;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000335 template <StateTag Tag> friend class VMState;
Steve Blocka7e24c12009-10-30 11:49:00 +0000336 friend class LoggerTestHelper;
337
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338 bool is_logging_;
Steve Block44f0eee2011-05-26 01:26:41 +0100339 Log* log_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000340 PerfBasicLogger* perf_basic_logger_;
Ben Murdochda12d292016-06-02 14:46:10 +0100341 PerfJitLogger* perf_jit_logger_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000342 LowLevelLogger* ll_logger_;
343 JitLogger* jit_logger_;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100344 std::unique_ptr<ProfilerListener> profiler_listener_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000345 List<CodeEventListener*> listeners_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000346
Steve Block44f0eee2011-05-26 01:26:41 +0100347 // Guards against multiple calls to TearDown() that can happen in some tests.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100348 // 'true' between SetUp() and TearDown().
Steve Block44f0eee2011-05-26 01:26:41 +0100349 bool is_initialized_;
350
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351 base::ElapsedTimer timer_;
Steve Block6ded16b2010-05-10 14:33:55 +0100352
353 friend class CpuProfiler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000354};
355
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000356#define TIMER_EVENTS_LIST(V) \
357 V(RecompileSynchronous, true) \
358 V(RecompileConcurrent, true) \
Ben Murdochda12d292016-06-02 14:46:10 +0100359 V(CompileIgnition, true) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000360 V(CompileFullCode, true) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100361 V(OptimizeCode, true) \
362 V(CompileCode, true) \
363 V(DeoptimizeCode, true) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000364 V(Execute, true) \
365 V(External, true) \
366 V(IcMiss, false)
367
368#define V(TimerName, expose) \
369 class TimerEvent##TimerName : public AllStatic { \
370 public: \
371 static const char* name(void* unused = NULL) { return "V8." #TimerName; } \
372 static bool expose_to_api() { return expose; } \
Steve Block44f0eee2011-05-26 01:26:41 +0100373 };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000374TIMER_EVENTS_LIST(V)
375#undef V
Steve Block44f0eee2011-05-26 01:26:41 +0100376
Steve Block44f0eee2011-05-26 01:26:41 +0100377
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000378template <class TimerEvent>
379class TimerEventScope {
380 public:
381 explicit TimerEventScope(Isolate* isolate) : isolate_(isolate) {
382 LogTimerEvent(Logger::START);
Steve Block44f0eee2011-05-26 01:26:41 +0100383 }
384
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000385 ~TimerEventScope() { LogTimerEvent(Logger::END); }
Steve Block44f0eee2011-05-26 01:26:41 +0100386
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 void LogTimerEvent(Logger::StartEnd se);
388
389 private:
390 Isolate* isolate_;
Steve Block44f0eee2011-05-26 01:26:41 +0100391};
392
Ben Murdochda12d292016-06-02 14:46:10 +0100393class PositionsRecorder BASE_EMBEDDED {
394 public:
395 PositionsRecorder() { jit_handler_data_ = NULL; }
396
397 void AttachJITHandlerData(void* user_data) { jit_handler_data_ = user_data; }
398
399 void* DetachJITHandlerData() {
400 void* old_data = jit_handler_data_;
401 jit_handler_data_ = NULL;
402 return old_data;
403 }
404
405 protected:
406 // Currently jit_handler_data_ is used to store JITHandler-specific data
407 // over the lifetime of a PositionsRecorder
408 void* jit_handler_data_;
409
410 private:
411 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
412};
Steve Block44f0eee2011-05-26 01:26:41 +0100413
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000414class CodeEventLogger : public CodeEventListener {
415 public:
416 CodeEventLogger();
Ben Murdochda12d292016-06-02 14:46:10 +0100417 ~CodeEventLogger() override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000418
Ben Murdoch61f157c2016-09-16 13:49:30 +0100419 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochda12d292016-06-02 14:46:10 +0100420 const char* comment) override;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100421 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochda12d292016-06-02 14:46:10 +0100422 Name* name) override;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100423 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochda12d292016-06-02 14:46:10 +0100424 int args_count) override;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100425 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100426 SharedFunctionInfo* shared, Name* name) override;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100427 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
Ben Murdochc5610432016-08-08 18:44:38 +0100428 SharedFunctionInfo* shared, Name* source, int line,
429 int column) override;
Ben Murdochda12d292016-06-02 14:46:10 +0100430 void RegExpCodeCreateEvent(AbstractCode* code, String* source) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000431
Ben Murdochda12d292016-06-02 14:46:10 +0100432 void CallbackEvent(Name* name, Address entry_point) override {}
433 void GetterCallbackEvent(Name* name, Address entry_point) override {}
434 void SetterCallbackEvent(Name* name, Address entry_point) override {}
435 void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
436 void CodeMovingGCEvent() override {}
Ben Murdoch61f157c2016-09-16 13:49:30 +0100437 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) override {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000438
439 private:
440 class NameBuffer;
441
Ben Murdochda12d292016-06-02 14:46:10 +0100442 virtual void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared,
443 const char* name, int length) = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444
445 NameBuffer* name_buffer_;
446};
447
448
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000449} // namespace internal
450} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000451
Steve Block6ded16b2010-05-10 14:33:55 +0100452
Steve Blocka7e24c12009-10-30 11:49:00 +0000453#endif // V8_LOG_H_