Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
code_observers.cc
Go to the documentation of this file.
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#include "vm/code_observers.h"
6
7#include "vm/os.h"
8#include "vm/os_thread.h"
9
10namespace dart {
11
12#ifndef PRODUCT
13
14Mutex* CodeObservers::mutex_ = nullptr;
15intptr_t CodeObservers::observers_length_ = 0;
16CodeObserver** CodeObservers::observers_ = nullptr;
17
19 public:
21 : delegate_(delegate) {}
22
23 virtual bool IsActive() const { return true; }
24
25 virtual void Notify(const char* name,
26 uword base,
27 uword prologue_offset,
28 uword size,
29 bool optimized,
30 const CodeComments* comments) {
31 return delegate_.on_new_code(&delegate_, name, base, size);
32 }
33
34 private:
35 Dart_CodeObserver delegate_;
36};
37
41
43 observers_length_++;
44 observers_ = reinterpret_cast<CodeObserver**>(
45 realloc(observers_, sizeof(observer) * observers_length_));
46 observers_[observers_length_ - 1] = observer;
47}
48
50 uword base,
51 uword prologue_offset,
52 uword size,
53 bool optimized,
54 const CodeComments* comments) {
55 ASSERT(!AreActive() || (strlen(name) != 0));
56 for (intptr_t i = 0; i < observers_length_; i++) {
57 if (observers_[i]->IsActive()) {
58 observers_[i]->Notify(name, base, prologue_offset, size, optimized,
59 comments);
60 }
61 }
62}
63
65 for (intptr_t i = 0; i < observers_length_; i++) {
66 if (observers_[i]->IsActive()) return true;
67 }
68 return false;
69}
70
72 for (intptr_t i = 0; i < observers_length_; i++) {
73 delete observers_[i];
74 }
75 free(observers_);
76 observers_length_ = 0;
77 observers_ = nullptr;
78}
79
81 if (mutex_ == nullptr) {
82 mutex_ = new Mutex();
83 }
84 ASSERT(mutex_ != nullptr);
86}
87
88#endif // !PRODUCT
89
90} // namespace dart
virtual void Notify(const char *name, uword base, uword prologue_offset, uword size, bool optimized, const CodeComments *comments)=0
static void Cleanup()
static void RegisterExternal(Dart_CodeObserver observer)
static void NotifyAll(const char *name, uword base, uword prologue_offset, uword size, bool optimized, const CodeComments *comments)
static void Register(CodeObserver *observer)
static bool AreActive()
ExternalCodeObserverAdapter(Dart_CodeObserver delegate)
virtual void Notify(const char *name, uword base, uword prologue_offset, uword size, bool optimized, const CodeComments *comments)
static void RegisterCodeObservers()
#define ASSERT(E)
const char *const name
uintptr_t uword
Definition globals.h:501
void * realloc(void *ptr, size_t size)
Definition allocation.cc:27
Dart_OnNewCodeCallback on_new_code
Definition dart_api.h:862