5 #ifndef V8_CODE_EVENTS_H_ 6 #define V8_CODE_EVENTS_H_ 8 #include <unordered_set> 10 #include "src/base/platform/mutex.h" 11 #include "src/globals.h" 12 #include "src/objects/code.h" 13 #include "src/objects/name.h" 14 #include "src/objects/string.h" 15 #include "src/vector.h" 22 class SharedFunctionInfo;
27 using WasmName = Vector<const char>;
30 #define LOG_EVENTS_LIST(V) \ 31 V(CODE_CREATION_EVENT, code-creation) \ 32 V(CODE_DISABLE_OPT_EVENT, code-disable-optimization) \ 33 V(CODE_MOVE_EVENT, code-move) \ 34 V(CODE_DELETE_EVENT, code-delete) \ 35 V(CODE_MOVING_GC, code-moving-gc) \ 36 V(SHARED_FUNC_MOVE_EVENT, sfi-move) \ 37 V(SNAPSHOT_CODE_NAME_EVENT, snapshot-code-name) \ 40 #define TAGS_LIST(V) \ 41 V(BUILTIN_TAG, Builtin) \ 42 V(CALLBACK_TAG, Callback) \ 44 V(FUNCTION_TAG, Function) \ 45 V(INTERPRETED_FUNCTION_TAG, InterpretedFunction) \ 46 V(HANDLER_TAG, Handler) \ 47 V(BYTECODE_HANDLER_TAG, BytecodeHandler) \ 48 V(LAZY_COMPILE_TAG, LazyCompile) \ 49 V(REG_EXP_TAG, RegExp) \ 50 V(SCRIPT_TAG, Script) \ 52 V(NATIVE_FUNCTION_TAG, Function) \ 53 V(NATIVE_LAZY_COMPILE_TAG, LazyCompile) \ 54 V(NATIVE_SCRIPT_TAG, Script) 58 #define LOG_EVENTS_AND_TAGS_LIST(V) \ 62 #define PROFILE(the_isolate, Call) (the_isolate)->code_event_dispatcher()->Call; 66 #define DECLARE_ENUM(enum_item, _) enum_item, 67 enum LogEventsAndTags {
68 LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM) NUMBER_OF_LOG_EVENTS
74 virtual void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
75 const char* comment) = 0;
76 virtual void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
78 virtual void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
80 virtual void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
82 int line,
int column) = 0;
83 virtual void CodeCreateEvent(LogEventsAndTags tag,
const wasm::WasmCode* code,
85 virtual void CallbackEvent(
Name name,
Address entry_point) = 0;
86 virtual void GetterCallbackEvent(
Name name,
Address entry_point) = 0;
87 virtual void SetterCallbackEvent(
Name name,
Address entry_point) = 0;
90 virtual void SharedFunctionInfoMoveEvent(
Address from,
Address to) = 0;
91 virtual void CodeMovingGCEvent() = 0;
94 virtual void CodeDeoptEvent(
Code code, DeoptimizeKind kind,
Address pc,
95 int fp_to_sp_delta) = 0;
97 virtual bool is_listening_to_code_events() {
return false; }
102 using LogEventsAndTags = CodeEventListener::LogEventsAndTags;
107 base::MutexGuard guard(&mutex_);
108 return listeners_.insert(listener).second;
111 base::MutexGuard guard(&mutex_);
112 listeners_.erase(listener);
114 bool IsListeningToCodeEvents() {
115 for (
auto it : listeners_) {
116 if (it->is_listening_to_code_events()) {
123 #define CODE_EVENT_DISPATCH(code) \ 124 base::MutexGuard guard(&mutex_); \ 125 for (auto it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->code 127 void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
128 const char* comment) {
129 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment));
132 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
134 void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
136 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, shared, name));
138 void CodeCreateEvent(LogEventsAndTags tag,
AbstractCode code,
142 CodeCreateEvent(tag, code, shared, source, line, column));
144 void CodeCreateEvent(LogEventsAndTags tag,
const wasm::WasmCode* code,
146 CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
148 void CallbackEvent(
Name name,
Address entry_point) {
149 CODE_EVENT_DISPATCH(CallbackEvent(name, entry_point));
151 void GetterCallbackEvent(
Name name,
Address entry_point) {
152 CODE_EVENT_DISPATCH(GetterCallbackEvent(name, entry_point));
154 void SetterCallbackEvent(
Name name,
Address entry_point) {
155 CODE_EVENT_DISPATCH(SetterCallbackEvent(name, entry_point));
158 CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
161 CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
164 CODE_EVENT_DISPATCH(SharedFunctionInfoMoveEvent(from, to));
166 void CodeMovingGCEvent() { CODE_EVENT_DISPATCH(CodeMovingGCEvent()); }
168 CODE_EVENT_DISPATCH(CodeDisableOptEvent(code, shared));
170 void CodeDeoptEvent(
Code code, DeoptimizeKind kind,
Address pc,
171 int fp_to_sp_delta) {
172 CODE_EVENT_DISPATCH(CodeDeoptEvent(code, kind, pc, fp_to_sp_delta));
174 #undef CODE_EVENT_DISPATCH 177 std::unordered_set<CodeEventListener*> listeners_;
186 #endif // V8_CODE_EVENTS_H_