LCOV - code coverage report
Current view: top level - src - code-events.h (source / functions) Hit Total Coverage
Test: app.info Lines: 45 45 100.0 %
Date: 2017-10-20 Functions: 16 18 88.9 %

          Line data    Source code
       1             : // Copyright 2016 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_CODE_EVENTS_H_
       6             : #define V8_CODE_EVENTS_H_
       7             : 
       8             : #include <unordered_set>
       9             : 
      10             : #include "src/base/platform/mutex.h"
      11             : #include "src/globals.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : class AbstractCode;
      17             : class Name;
      18             : class SharedFunctionInfo;
      19             : class String;
      20             : 
      21             : #define LOG_EVENTS_AND_TAGS_LIST(V)                                      \
      22             :   V(CODE_CREATION_EVENT, "code-creation")                                \
      23             :   V(CODE_DISABLE_OPT_EVENT, "code-disable-optimization")                 \
      24             :   V(CODE_MOVE_EVENT, "code-move")                                        \
      25             :   V(CODE_DELETE_EVENT, "code-delete")                                    \
      26             :   V(CODE_MOVING_GC, "code-moving-gc")                                    \
      27             :   V(SHARED_FUNC_MOVE_EVENT, "sfi-move")                                  \
      28             :   V(SNAPSHOT_CODE_NAME_EVENT, "snapshot-code-name")                      \
      29             :   V(TICK_EVENT, "tick")                                                  \
      30             :   V(BUILTIN_TAG, "Builtin")                                              \
      31             :   V(CALLBACK_TAG, "Callback")                                            \
      32             :   V(EVAL_TAG, "Eval")                                                    \
      33             :   V(FUNCTION_TAG, "Function")                                            \
      34             :   V(HANDLER_TAG, "Handler")                                              \
      35             :   V(BYTECODE_HANDLER_TAG, "BytecodeHandler")                             \
      36             :   V(LAZY_COMPILE_TAG, "LazyCompile")                                     \
      37             :   V(REG_EXP_TAG, "RegExp")                                               \
      38             :   V(SCRIPT_TAG, "Script")                                                \
      39             :   V(STUB_TAG, "Stub")                                                    \
      40             :   V(NATIVE_FUNCTION_TAG, "Function")                                     \
      41             :   V(NATIVE_LAZY_COMPILE_TAG, "LazyCompile")                              \
      42             :   V(NATIVE_SCRIPT_TAG, "Script")
      43             : // Note that 'NATIVE_' cases for functions and scripts are mapped onto
      44             : // original tags when writing to the log.
      45             : 
      46             : #define PROFILE(the_isolate, Call) (the_isolate)->code_event_dispatcher()->Call;
      47             : 
      48       55594 : class CodeEventListener {
      49             :  public:
      50             : #define DECLARE_ENUM(enum_item, _) enum_item,
      51             :   enum LogEventsAndTags {
      52             :     LOG_EVENTS_AND_TAGS_LIST(DECLARE_ENUM) NUMBER_OF_LOG_EVENTS
      53             :   };
      54             : #undef DECLARE_ENUM
      55             : 
      56       53943 :   virtual ~CodeEventListener() {}
      57             : 
      58             :   virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
      59             :                                const char* comment) = 0;
      60             :   virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
      61             :                                Name* name) = 0;
      62             :   virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
      63             :                                SharedFunctionInfo* shared, Name* source) = 0;
      64             :   virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
      65             :                                SharedFunctionInfo* shared, Name* source,
      66             :                                int line, int column) = 0;
      67             :   virtual void CallbackEvent(Name* name, Address entry_point) = 0;
      68             :   virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
      69             :   virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
      70             :   virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0;
      71             :   virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0;
      72             :   virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
      73             :   virtual void CodeMovingGCEvent() = 0;
      74             :   virtual void CodeDisableOptEvent(AbstractCode* code,
      75             :                                    SharedFunctionInfo* shared) = 0;
      76             :   enum DeoptKind { kSoft, kLazy, kEager };
      77             :   virtual void CodeDeoptEvent(Code* code, DeoptKind kind, Address pc,
      78             :                               int fp_to_sp_delta) = 0;
      79             : };
      80             : 
      81      106730 : class CodeEventDispatcher {
      82             :  public:
      83             :   using LogEventsAndTags = CodeEventListener::LogEventsAndTags;
      84             : 
      85      109998 :   CodeEventDispatcher() {}
      86             : 
      87         646 :   bool AddListener(CodeEventListener* listener) {
      88         646 :     base::LockGuard<base::Mutex> guard(&mutex_);
      89        1292 :     return listeners_.insert(listener).second;
      90             :   }
      91         823 :   void RemoveListener(CodeEventListener* listener) {
      92         823 :     base::LockGuard<base::Mutex> guard(&mutex_);
      93             :     listeners_.erase(listener);
      94         823 :   }
      95             : 
      96             : #define CODE_EVENT_DISPATCH(code)              \
      97             :   base::LockGuard<base::Mutex> guard(&mutex_); \
      98             :   for (auto it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->code
      99             : 
     100      115943 :   void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
     101             :                        const char* comment) {
     102      383937 :     CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment));
     103      115943 :   }
     104      245699 :   void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, Name* name) {
     105      737097 :     CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
     106      245699 :   }
     107      149236 :   void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
     108             :                        SharedFunctionInfo* shared, Name* name) {
     109      596944 :     CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, shared, name));
     110      149236 :   }
     111        1962 :   void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
     112             :                        SharedFunctionInfo* shared, Name* source, int line,
     113             :                        int column) {
     114        9858 :     CODE_EVENT_DISPATCH(
     115        3972 :         CodeCreateEvent(tag, code, shared, source, line, column));
     116        1962 :   }
     117        6017 :   void CallbackEvent(Name* name, Address entry_point) {
     118       24068 :     CODE_EVENT_DISPATCH(CallbackEvent(name, entry_point));
     119        6017 :   }
     120       18370 :   void GetterCallbackEvent(Name* name, Address entry_point) {
     121       73480 :     CODE_EVENT_DISPATCH(GetterCallbackEvent(name, entry_point));
     122       18370 :   }
     123       18365 :   void SetterCallbackEvent(Name* name, Address entry_point) {
     124       73460 :     CODE_EVENT_DISPATCH(SetterCallbackEvent(name, entry_point));
     125       18365 :   }
     126       93584 :   void RegExpCodeCreateEvent(AbstractCode* code, String* source) {
     127      280753 :     CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
     128       93584 :   }
     129         192 :   void CodeMoveEvent(AbstractCode* from, Address to) {
     130         768 :     CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
     131         192 :   }
     132             :   void SharedFunctionInfoMoveEvent(Address from, Address to) {
     133             :     CODE_EVENT_DISPATCH(SharedFunctionInfoMoveEvent(from, to));
     134             :   }
     135      227371 :   void CodeMovingGCEvent() { CODE_EVENT_DISPATCH(CodeMovingGCEvent()); }
     136       24667 :   void CodeDisableOptEvent(AbstractCode* code, SharedFunctionInfo* shared) {
     137       74023 :     CODE_EVENT_DISPATCH(CodeDisableOptEvent(code, shared));
     138       24667 :   }
     139      146823 :   void CodeDeoptEvent(Code* code, CodeEventListener::DeoptKind kind, Address pc,
     140             :                       int fp_to_sp_delta) {
     141      440478 :     CODE_EVENT_DISPATCH(CodeDeoptEvent(code, kind, pc, fp_to_sp_delta));
     142      146823 :   }
     143             : #undef CODE_EVENT_DISPATCH
     144             : 
     145             :  private:
     146             :   std::unordered_set<CodeEventListener*> listeners_;
     147             :   base::Mutex mutex_;
     148             : 
     149             :   DISALLOW_COPY_AND_ASSIGN(CodeEventDispatcher);
     150             : };
     151             : 
     152             : }  // namespace internal
     153             : }  // namespace v8
     154             : 
     155             : #endif  // V8_CODE_EVENTS_H_

Generated by: LCOV version 1.10