1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_VM_CODE_OBSERVERS_H_ |
6 | #define RUNTIME_VM_CODE_OBSERVERS_H_ |
7 | |
8 | #include "vm/allocation.h" |
9 | #include "vm/globals.h" |
10 | |
11 | #include "include/dart_api.h" |
12 | |
13 | namespace dart { |
14 | |
15 | #if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) |
16 | |
17 | // An abstract representation of comments associated with the given code |
18 | // object. We assume that comments are sorted by PCOffset. |
19 | class : public ValueObject { |
20 | public: |
21 | () = default; |
22 | virtual () = default; |
23 | |
24 | virtual intptr_t () const = 0; |
25 | virtual intptr_t (intptr_t index) const = 0; |
26 | virtual const char* (intptr_t index) const = 0; |
27 | }; |
28 | |
29 | #endif // !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) |
30 | |
31 | #if !defined(PRODUCT) |
32 | |
33 | // Object observing code creation events. Used by external profilers and |
34 | // debuggers to map address ranges to function names. |
35 | class CodeObserver { |
36 | public: |
37 | CodeObserver() {} |
38 | |
39 | virtual ~CodeObserver() {} |
40 | |
41 | // Returns true if this observer is active and should be notified |
42 | // about newly created code objects. |
43 | virtual bool IsActive() const = 0; |
44 | |
45 | // Notify code observer about a newly created code object with the |
46 | // given properties. |
47 | virtual void (const char* name, |
48 | uword base, |
49 | uword prologue_offset, |
50 | uword size, |
51 | bool optimized, |
52 | const CodeComments* ) = 0; |
53 | |
54 | private: |
55 | DISALLOW_COPY_AND_ASSIGN(CodeObserver); |
56 | }; |
57 | |
58 | class Mutex; |
59 | |
60 | class CodeObservers : public AllStatic { |
61 | public: |
62 | static void Init(); |
63 | |
64 | static void RegisterExternal(Dart_CodeObserver observer); |
65 | |
66 | static void Register(CodeObserver* observer); |
67 | |
68 | // Notify all active code observers about a newly created code object. |
69 | static void (const char* name, |
70 | uword base, |
71 | uword prologue_offset, |
72 | uword size, |
73 | bool optimized, |
74 | const CodeComments* ); |
75 | |
76 | // Returns true if there is at least one active code observer. |
77 | static bool AreActive(); |
78 | |
79 | static void Cleanup(); |
80 | |
81 | static Mutex* mutex() { return mutex_; } |
82 | |
83 | private: |
84 | static Mutex* mutex_; |
85 | static intptr_t observers_length_; |
86 | static CodeObserver** observers_; |
87 | }; |
88 | |
89 | #endif // !defined(PRODUCT) |
90 | |
91 | } // namespace dart |
92 | |
93 | #endif // RUNTIME_VM_CODE_OBSERVERS_H_ |
94 | |