Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/dart.h" | 5 #include "vm/dart.h" |
| 6 | 6 |
| 7 #include "vm/dart_api_state.h" | 7 #include "vm/dart_api_state.h" |
| 8 #include "vm/debuginfo.h" | |
| 8 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 9 #include "vm/freelist.h" | 10 #include "vm/freelist.h" |
| 10 #include "vm/handles.h" | 11 #include "vm/handles.h" |
| 11 #include "vm/heap.h" | 12 #include "vm/heap.h" |
| 12 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
| 13 #include "vm/object.h" | 14 #include "vm/object.h" |
| 14 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
| 15 #include "vm/port.h" | 16 #include "vm/port.h" |
| 16 #include "vm/snapshot.h" | 17 #include "vm/snapshot.h" |
| 17 #include "vm/stub_code.h" | 18 #include "vm/stub_code.h" |
| 18 #include "vm/symbols.h" | 19 #include "vm/symbols.h" |
| 19 #include "vm/thread_pool.h" | 20 #include "vm/thread_pool.h" |
| 20 #include "vm/virtual_memory.h" | 21 #include "vm/virtual_memory.h" |
| 22 #include "vm/vtune.h" | |
| 21 #include "vm/zone.h" | 23 #include "vm/zone.h" |
| 22 | 24 |
| 23 namespace dart { | 25 namespace dart { |
| 24 | 26 |
| 27 DEFINE_FLAG(bool, generate_gdb_symbols, false, | |
| 28 "Generate symbols of generated dart functions for debugging with GDB"); | |
| 25 DECLARE_FLAG(bool, print_bootstrap); | 29 DECLARE_FLAG(bool, print_bootstrap); |
| 26 DECLARE_FLAG(bool, print_class_table); | 30 DECLARE_FLAG(bool, print_class_table); |
| 27 DECLARE_FLAG(bool, trace_isolates); | 31 DECLARE_FLAG(bool, trace_isolates); |
| 28 | 32 |
| 29 Isolate* Dart::vm_isolate_ = NULL; | 33 Isolate* Dart::vm_isolate_ = NULL; |
| 30 ThreadPool* Dart::thread_pool_ = NULL; | 34 ThreadPool* Dart::thread_pool_ = NULL; |
| 31 Dart_FileWriterFunction Dart::perf_events_writer_ = NULL; | 35 Dart_FileWriterFunction Dart::perf_events_writer_ = NULL; |
| 32 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 36 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
| 33 Dart_FileWriterFunction Dart::flow_graph_writer_ = NULL; | 37 Dart_FileWriterFunction Dart::flow_graph_writer_ = NULL; |
| 38 intptr_t Dart::code_observers_length_ = 0; | |
| 39 CodeObserver** Dart::code_observers_ = NULL; | |
| 34 | 40 |
| 35 // An object visitor which will mark all visited objects. This is used to | 41 // An object visitor which will mark all visited objects. This is used to |
| 36 // premark all objects in the vm_isolate_ heap. | 42 // premark all objects in the vm_isolate_ heap. |
| 37 class PremarkingVisitor : public ObjectVisitor { | 43 class PremarkingVisitor : public ObjectVisitor { |
| 38 public: | 44 public: |
| 39 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} | 45 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} |
| 40 | 46 |
| 41 void VisitObject(RawObject* obj) { | 47 void VisitObject(RawObject* obj) { |
| 42 // RawInstruction objects are premarked on allocation. | 48 // RawInstruction objects are premarked on allocation. |
| 43 if (!obj->IsMarked()) { | 49 if (!obj->IsMarked()) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 54 // TODO(iposva): Fix race condition here. | 60 // TODO(iposva): Fix race condition here. |
| 55 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 61 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
| 56 return "VM already initialized."; | 62 return "VM already initialized."; |
| 57 } | 63 } |
| 58 OS::InitOnce(); | 64 OS::InitOnce(); |
| 59 VirtualMemory::InitOnce(); | 65 VirtualMemory::InitOnce(); |
| 60 Isolate::InitOnce(); | 66 Isolate::InitOnce(); |
| 61 PortMap::InitOnce(); | 67 PortMap::InitOnce(); |
| 62 FreeListElement::InitOnce(); | 68 FreeListElement::InitOnce(); |
| 63 Api::InitOnce(); | 69 Api::InitOnce(); |
| 70 RegisterDefaultCodeObservers(); | |
| 64 // Create the VM isolate and finish the VM initialization. | 71 // Create the VM isolate and finish the VM initialization. |
| 65 ASSERT(thread_pool_ == NULL); | 72 ASSERT(thread_pool_ == NULL); |
| 66 thread_pool_ = new ThreadPool(); | 73 thread_pool_ = new ThreadPool(); |
| 67 { | 74 { |
| 68 ASSERT(vm_isolate_ == NULL); | 75 ASSERT(vm_isolate_ == NULL); |
| 69 ASSERT(Flags::Initialized()); | 76 ASSERT(Flags::Initialized()); |
| 70 vm_isolate_ = Isolate::Init("vm-isolate"); | 77 vm_isolate_ = Isolate::Init("vm-isolate"); |
| 71 StackZone zone(vm_isolate_); | 78 StackZone zone(vm_isolate_); |
| 72 HandleScope handle_scope(vm_isolate_); | 79 HandleScope handle_scope(vm_isolate_); |
| 73 Heap::Init(vm_isolate_); | 80 Heap::Init(vm_isolate_); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 void* callback_data = isolate->init_callback_data(); | 191 void* callback_data = isolate->init_callback_data(); |
| 185 isolate->Shutdown(); | 192 isolate->Shutdown(); |
| 186 delete isolate; | 193 delete isolate; |
| 187 | 194 |
| 188 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); | 195 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); |
| 189 if (callback != NULL) { | 196 if (callback != NULL) { |
| 190 (callback)(callback_data); | 197 (callback)(callback_data); |
| 191 } | 198 } |
| 192 } | 199 } |
| 193 | 200 |
| 201 | |
| 202 void Dart::RegisterCodeObserver(CodeObserver* observer) { | |
| 203 code_observers_length_++; | |
| 204 code_observers_ = reinterpret_cast<CodeObserver**>( | |
| 205 realloc(code_observers_, | |
| 206 sizeof(CodeObserver*) * code_observers_length_)); // NOLINT | |
|
Ivan Posva
2012/11/27 09:11:20
sizeof(observer) should make the lint warning go a
Vyacheslav Egorov (Google)
2012/11/27 16:26:12
Done.
| |
| 207 if (code_observers_ == NULL) { | |
| 208 FATAL("failed to grow code observers array"); | |
| 209 } | |
| 210 code_observers_[code_observers_length_ - 1] = observer; | |
| 211 } | |
| 212 | |
| 213 | |
| 214 void Dart::NotifyCodeObservers(const char* name, | |
| 215 uword base, | |
| 216 uword prologue_offset, | |
| 217 uword size, | |
| 218 bool optimized) { | |
| 219 ASSERT(!AreCodeObserversActive() || (strlen(name) != 0)); | |
| 220 for (intptr_t i = 0; i < code_observers_length_; i++) { | |
| 221 if (code_observers_[i]->IsActive()) { | |
| 222 code_observers_[i]->Notify(name, base, prologue_offset, size, optimized); | |
| 223 } | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 | |
| 228 bool Dart::AreCodeObserversActive() { | |
| 229 for (intptr_t i = 0; i < code_observers_length_; i++) { | |
| 230 if (code_observers_[i]->IsActive()) return true; | |
| 231 } | |
| 232 return false; | |
| 233 } | |
| 234 | |
| 235 | |
| 236 class PerfCodeObserver : public CodeObserver { | |
| 237 public: | |
| 238 virtual bool IsActive() const { | |
| 239 return Dart::perf_events_writer() != NULL; | |
| 240 } | |
| 241 | |
| 242 virtual void Notify(const char* name, | |
| 243 uword base, | |
| 244 uword prologue_offset, | |
| 245 uword size, | |
| 246 bool optimized) { | |
| 247 Dart_FileWriterFunction perf_events_writer = Dart::perf_events_writer(); | |
| 248 ASSERT(perf_events_writer != NULL); | |
| 249 | |
| 250 const char* format = "%"Px" %"Px" %s%s\n"; | |
| 251 const char* marker = optimized ? "*" : ""; | |
| 252 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); | |
| 253 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | |
| 254 OS::SNPrint(buffer, len + 1, format, base, size, marker, name); | |
| 255 (*perf_events_writer)(buffer, len); | |
| 256 } | |
| 257 }; | |
| 258 | |
| 259 | |
| 260 class PprofCodeObserver : public CodeObserver { | |
| 261 public: | |
| 262 virtual bool IsActive() const { | |
| 263 return Dart::pprof_symbol_generator() != NULL; | |
| 264 } | |
| 265 | |
| 266 virtual void Notify(const char* name, | |
| 267 uword base, | |
| 268 uword prologue_offset, | |
| 269 uword size, | |
| 270 bool optimized) { | |
| 271 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); | |
| 272 ASSERT(pprof_symbol_generator != NULL); | |
| 273 pprof_symbol_generator->AddCode(base, size); | |
| 274 pprof_symbol_generator->AddCodeRegion(name, base, size); | |
| 275 } | |
| 276 }; | |
| 277 | |
| 278 | |
| 279 class GdbCodeObserver : public CodeObserver { | |
| 280 public: | |
| 281 virtual bool IsActive() const { | |
| 282 return FLAG_generate_gdb_symbols; | |
| 283 } | |
| 284 | |
| 285 virtual void Notify(const char* name, | |
| 286 uword base, | |
| 287 uword prologue_offset, | |
| 288 uword size, | |
| 289 bool optimized) { | |
| 290 if (prologue_offset > 0) { | |
| 291 // In order to ensure that gdb sees the first instruction of a function | |
| 292 // as the prolog sequence we register two symbols for the cases when | |
| 293 // the prolog sequence is not the first instruction: | |
| 294 // <name>_entry is used for code preceding the prolog sequence. | |
|
Ivan Posva
2012/11/27 09:11:20
prologue
| |
| 295 // <name> for rest of the code (first instruction is prolog sequence). | |
|
Ivan Posva
2012/11/27 09:11:20
prologue
| |
| 296 const char* kFormat = "%s_%s"; | |
| 297 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); | |
| 298 char* pname = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | |
| 299 OS::SNPrint(pname, (len + 1), kFormat, name, "entry"); | |
| 300 DebugInfo::RegisterSection(pname, base, size); | |
| 301 DebugInfo::RegisterSection(name, | |
| 302 (base + prologue_offset), | |
| 303 (size - prologue_offset)); | |
| 304 } else { | |
| 305 DebugInfo::RegisterSection(name, base, size); | |
| 306 } | |
| 307 } | |
| 308 }; | |
| 309 | |
| 310 | |
| 311 void Dart::RegisterDefaultCodeObservers() { | |
| 312 RegisterCodeObserver(new PerfCodeObserver); | |
| 313 RegisterCodeObserver(new PprofCodeObserver); | |
| 314 RegisterCodeObserver(new GdbCodeObserver); | |
| 315 #if defined(DART_VTUNE_SUPPORT) | |
| 316 RegisterCodeObserver(new VTuneCodeObserver; | |
|
Ivan Posva
2012/11/27 09:11:20
Does not compile).
Vyacheslav Egorov (Google)
2012/11/27 16:26:12
Indeed. Fixed
| |
| 317 #endif | |
| 318 } | |
| 319 | |
| 194 } // namespace dart | 320 } // namespace dart |
| OLD | NEW |