 Chromium Code Reviews
 Chromium Code Reviews Issue 1294023009:
  Switch to a VM wide timeline recorder  (Closed) 
  Base URL: git@github.com:dart-lang/sdk.git@master
    
  
    Issue 1294023009:
  Switch to a VM wide timeline recorder  (Closed) 
  Base URL: git@github.com:dart-lang/sdk.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/code_observers.h" | 7 #include "vm/code_observers.h" | 
| 8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" | 
| 9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" | 
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" | 
| 11 #include "vm/debugger.h" | 11 #include "vm/debugger.h" | 
| 12 #include "vm/flags.h" | 12 #include "vm/flags.h" | 
| 13 #include "vm/freelist.h" | 13 #include "vm/freelist.h" | 
| 14 #include "vm/handles.h" | 14 #include "vm/handles.h" | 
| 15 #include "vm/heap.h" | 15 #include "vm/heap.h" | 
| 16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" | 
| 17 #include "vm/metrics.h" | 17 #include "vm/metrics.h" | 
| 18 #include "vm/object.h" | 18 #include "vm/object.h" | 
| 19 #include "vm/object_store.h" | 19 #include "vm/object_store.h" | 
| 20 #include "vm/object_id_ring.h" | 20 #include "vm/object_id_ring.h" | 
| 21 #include "vm/port.h" | 21 #include "vm/port.h" | 
| 22 #include "vm/profiler.h" | 22 #include "vm/profiler.h" | 
| 23 #include "vm/service_isolate.h" | 23 #include "vm/service_isolate.h" | 
| 24 #include "vm/simulator.h" | 24 #include "vm/simulator.h" | 
| 25 #include "vm/snapshot.h" | 25 #include "vm/snapshot.h" | 
| 26 #include "vm/stub_code.h" | 26 #include "vm/stub_code.h" | 
| 27 #include "vm/symbols.h" | 27 #include "vm/symbols.h" | 
| 28 #include "vm/thread_interrupter.h" | 28 #include "vm/thread_interrupter.h" | 
| 29 #include "vm/thread_pool.h" | 29 #include "vm/thread_pool.h" | 
| 30 #include "vm/timeline.h" | |
| 31 #include "vm/virtual_memory.h" | 30 #include "vm/virtual_memory.h" | 
| 32 #include "vm/zone.h" | 31 #include "vm/zone.h" | 
| 33 | 32 | 
| 34 namespace dart { | 33 namespace dart { | 
| 35 | 34 | 
| 36 DECLARE_FLAG(bool, complete_timeline); | |
| 37 DECLARE_FLAG(bool, print_class_table); | 35 DECLARE_FLAG(bool, print_class_table); | 
| 38 DECLARE_FLAG(bool, trace_isolates); | 36 DECLARE_FLAG(bool, trace_isolates); | 
| 39 DEFINE_FLAG(bool, keep_code, false, | 37 DEFINE_FLAG(bool, keep_code, false, | 
| 40 "Keep deoptimized code for profiling."); | 38 "Keep deoptimized code for profiling."); | 
| 41 | 39 | 
| 42 Isolate* Dart::vm_isolate_ = NULL; | 40 Isolate* Dart::vm_isolate_ = NULL; | 
| 43 ThreadPool* Dart::thread_pool_ = NULL; | 41 ThreadPool* Dart::thread_pool_ = NULL; | 
| 44 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 42 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 
| 45 ReadOnlyHandles* Dart::predefined_handles_ = NULL; | 43 ReadOnlyHandles* Dart::predefined_handles_ = NULL; | 
| 46 | 44 | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 Dart_EntropySource entropy_source) { | 78 Dart_EntropySource entropy_source) { | 
| 81 // TODO(iposva): Fix race condition here. | 79 // TODO(iposva): Fix race condition here. | 
| 82 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 80 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 
| 83 return "VM already initialized or flags not initialized."; | 81 return "VM already initialized or flags not initialized."; | 
| 84 } | 82 } | 
| 85 Isolate::SetFileCallbacks(file_open, file_read, file_write, file_close); | 83 Isolate::SetFileCallbacks(file_open, file_read, file_write, file_close); | 
| 86 Isolate::SetEntropySourceCallback(entropy_source); | 84 Isolate::SetEntropySourceCallback(entropy_source); | 
| 87 OS::InitOnce(); | 85 OS::InitOnce(); | 
| 88 VirtualMemory::InitOnce(); | 86 VirtualMemory::InitOnce(); | 
| 89 Thread::InitOnceBeforeIsolate(); | 87 Thread::InitOnceBeforeIsolate(); | 
| 88 Timeline::InitOnce(); | |
| 89 Thread::EnsureInit(); | |
| 90 TimelineDurationScope tds(Timeline::GetVMStream(), | |
| 91 "Dart::InitOnce"); | |
| 90 Isolate::InitOnce(); | 92 Isolate::InitOnce(); | 
| 91 PortMap::InitOnce(); | 93 PortMap::InitOnce(); | 
| 92 FreeListElement::InitOnce(); | 94 FreeListElement::InitOnce(); | 
| 93 Api::InitOnce(); | 95 Api::InitOnce(); | 
| 94 CodeObservers::InitOnce(); | 96 CodeObservers::InitOnce(); | 
| 95 ThreadInterrupter::InitOnce(); | 97 ThreadInterrupter::InitOnce(); | 
| 96 Profiler::InitOnce(); | 98 Profiler::InitOnce(); | 
| 97 SemiSpace::InitOnce(); | 99 SemiSpace::InitOnce(); | 
| 98 Metric::InitOnce(); | 100 Metric::InitOnce(); | 
| 99 StoreBuffer::InitOnce(); | 101 StoreBuffer::InitOnce(); | 
| 102 Thread::EnsureInit(); | |
| 
Ivan Posva
2015/08/21 02:25:38
Shouldn't this be called ReallyEnsureInit? Since i
 | |
| 100 | 103 | 
| 101 #if defined(USING_SIMULATOR) | 104 #if defined(USING_SIMULATOR) | 
| 102 Simulator::InitOnce(); | 105 Simulator::InitOnce(); | 
| 103 #endif | 106 #endif | 
| 104 // Create the read-only handles area. | 107 // Create the read-only handles area. | 
| 105 ASSERT(predefined_handles_ == NULL); | 108 ASSERT(predefined_handles_ == NULL); | 
| 106 predefined_handles_ = new ReadOnlyHandles(); | 109 predefined_handles_ = new ReadOnlyHandles(); | 
| 107 // Create the VM isolate and finish the VM initialization. | 110 // Create the VM isolate and finish the VM initialization. | 
| 108 ASSERT(thread_pool_ == NULL); | 111 ASSERT(thread_pool_ == NULL); | 
| 109 thread_pool_ = new ThreadPool(); | 112 thread_pool_ = new ThreadPool(); | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 Dart_ExitScope(); | 212 Dart_ExitScope(); | 
| 210 | 213 | 
| 211 ShutdownIsolate(); | 214 ShutdownIsolate(); | 
| 212 vm_isolate_ = NULL; | 215 vm_isolate_ = NULL; | 
| 213 | 216 | 
| 214 TargetCPUFeatures::Cleanup(); | 217 TargetCPUFeatures::Cleanup(); | 
| 215 #endif | 218 #endif | 
| 216 | 219 | 
| 217 Profiler::Shutdown(); | 220 Profiler::Shutdown(); | 
| 218 CodeObservers::DeleteAll(); | 221 CodeObservers::DeleteAll(); | 
| 222 Timeline::Shutdown(); | |
| 219 | 223 | 
| 220 return NULL; | 224 return NULL; | 
| 221 } | 225 } | 
| 222 | 226 | 
| 223 | 227 | 
| 224 Isolate* Dart::CreateIsolate(const char* name_prefix, | 228 Isolate* Dart::CreateIsolate(const char* name_prefix, | 
| 225 const Dart_IsolateFlags& api_flags) { | 229 const Dart_IsolateFlags& api_flags) { | 
| 226 // Create a new isolate. | 230 // Create a new isolate. | 
| 227 Isolate* isolate = Isolate::Init(name_prefix, api_flags); | 231 Isolate* isolate = Isolate::Init(name_prefix, api_flags); | 
| 228 ASSERT(isolate != NULL); | 232 ASSERT(isolate != NULL); | 
| 229 return isolate; | 233 return isolate; | 
| 230 } | 234 } | 
| 231 | 235 | 
| 232 | 236 | 
| 233 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { | 237 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { | 
| 234 // Initialize the new isolate. | 238 // Initialize the new isolate. | 
| 235 Isolate* isolate = Isolate::Current(); | 239 Isolate* isolate = Isolate::Current(); | 
| 236 TIMERSCOPE(isolate, time_isolate_initialization); | 240 TIMERSCOPE(isolate, time_isolate_initialization); | 
| 241 TimelineDurationScope tds(isolate, | |
| 242 isolate->GetIsolateStream(), | |
| 243 "InitializeIsolate"); | |
| 244 tds.SetNumArguments(1); | |
| 245 tds.CopyArgument(0, "isolateName", isolate->name()); | |
| 246 | |
| 237 ASSERT(isolate != NULL); | 247 ASSERT(isolate != NULL); | 
| 238 StackZone zone(isolate); | 248 StackZone zone(isolate); | 
| 239 HandleScope handle_scope(isolate); | 249 HandleScope handle_scope(isolate); | 
| 240 ObjectStore::Init(isolate); | 250 { | 
| 251 TimelineDurationScope tds(isolate, | |
| 252 isolate->GetIsolateStream(), | |
| 253 "ObjectStore::Init"); | |
| 254 ObjectStore::Init(isolate); | |
| 255 } | |
| 241 | 256 | 
| 242 // Setup for profiling. | 257 // Setup for profiling. | 
| 243 Profiler::InitProfilingForIsolate(isolate); | 258 Profiler::InitProfilingForIsolate(isolate); | 
| 244 | 259 | 
| 245 const Error& error = Error::Handle(Object::Init(isolate)); | 260 const Error& error = Error::Handle(Object::Init(isolate)); | 
| 246 if (!error.IsNull()) { | 261 if (!error.IsNull()) { | 
| 247 return error.raw(); | 262 return error.raw(); | 
| 248 } | 263 } | 
| 249 if (snapshot_buffer != NULL) { | 264 if (snapshot_buffer != NULL) { | 
| 250 // Read the snapshot and setup the initial state. | 265 // Read the snapshot and setup the initial state. | 
| 251 | 266 TimelineDurationScope tds(isolate, | 
| 267 isolate->GetIsolateStream(), | |
| 268 "IsolateSnapshotReader"); | |
| 252 // TODO(turnidge): Remove once length is not part of the snapshot. | 269 // TODO(turnidge): Remove once length is not part of the snapshot. | 
| 253 const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer); | 270 const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer); | 
| 254 if (snapshot == NULL) { | 271 if (snapshot == NULL) { | 
| 255 const String& message = String::Handle( | 272 const String& message = String::Handle( | 
| 256 String::New("Invalid snapshot.")); | 273 String::New("Invalid snapshot.")); | 
| 257 return ApiError::New(message); | 274 return ApiError::New(message); | 
| 258 } | 275 } | 
| 259 ASSERT(snapshot->kind() == Snapshot::kFull); | 276 ASSERT(snapshot->kind() == Snapshot::kFull); | 
| 260 if (FLAG_trace_isolates) { | 277 if (FLAG_trace_isolates) { | 
| 261 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); | 278 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 275 } else { | 292 } else { | 
| 276 // Populate the isolate's symbol table with all symbols from the | 293 // Populate the isolate's symbol table with all symbols from the | 
| 277 // VM isolate. We do this so that when we generate a full snapshot | 294 // VM isolate. We do this so that when we generate a full snapshot | 
| 278 // for the isolate we have a unified symbol table that we can then | 295 // for the isolate we have a unified symbol table that we can then | 
| 279 // read into the VM isolate. | 296 // read into the VM isolate. | 
| 280 Symbols::AddPredefinedSymbolsToIsolate(); | 297 Symbols::AddPredefinedSymbolsToIsolate(); | 
| 281 } | 298 } | 
| 282 | 299 | 
| 283 Object::VerifyBuiltinVtables(); | 300 Object::VerifyBuiltinVtables(); | 
| 284 | 301 | 
| 285 StubCode::Init(isolate); | 302 { | 
| 303 TimelineDurationScope tds(isolate, | |
| 304 isolate->GetIsolateStream(), | |
| 305 "StubCode::Init"); | |
| 306 StubCode::Init(isolate); | |
| 307 } | |
| 308 | |
| 286 isolate->megamorphic_cache_table()->InitMissHandler(); | 309 isolate->megamorphic_cache_table()->InitMissHandler(); | 
| 287 if (snapshot_buffer == NULL) { | 310 if (snapshot_buffer == NULL) { | 
| 288 if (!isolate->object_store()->PreallocateObjects()) { | 311 if (!isolate->object_store()->PreallocateObjects()) { | 
| 289 return isolate->object_store()->sticky_error(); | 312 return isolate->object_store()->sticky_error(); | 
| 290 } | 313 } | 
| 291 } | 314 } | 
| 292 | 315 | 
| 293 isolate->heap()->EnableGrowthControl(); | 316 isolate->heap()->EnableGrowthControl(); | 
| 294 isolate->set_init_callback_data(data); | 317 isolate->set_init_callback_data(data); | 
| 295 Api::SetupAcquiredError(isolate); | 318 Api::SetupAcquiredError(isolate); | 
| 296 if (FLAG_print_class_table) { | 319 if (FLAG_print_class_table) { | 
| 297 isolate->class_table()->Print(); | 320 isolate->class_table()->Print(); | 
| 298 } | 321 } | 
| 299 | 322 | 
| 300 ServiceIsolate::MaybeInjectVMServiceLibrary(isolate); | 323 ServiceIsolate::MaybeInjectVMServiceLibrary(isolate); | 
| 301 | 324 | 
| 302 ServiceIsolate::SendIsolateStartupMessage(); | 325 ServiceIsolate::SendIsolateStartupMessage(); | 
| 303 isolate->debugger()->NotifyIsolateCreated(); | 326 isolate->debugger()->NotifyIsolateCreated(); | 
| 304 | 327 | 
| 305 // Create tag table. | 328 // Create tag table. | 
| 306 isolate->set_tag_table( | 329 isolate->set_tag_table( | 
| 307 GrowableObjectArray::Handle(GrowableObjectArray::New())); | 330 GrowableObjectArray::Handle(GrowableObjectArray::New())); | 
| 308 // Set up default UserTag. | 331 // Set up default UserTag. | 
| 309 const UserTag& default_tag = UserTag::Handle(UserTag::DefaultTag()); | 332 const UserTag& default_tag = UserTag::Handle(UserTag::DefaultTag()); | 
| 310 isolate->set_current_tag(default_tag); | 333 isolate->set_current_tag(default_tag); | 
| 311 | 334 | 
| 312 if (FLAG_complete_timeline) { | |
| 313 isolate->SetTimelineEventRecorder(new TimelineEventEndlessRecorder()); | |
| 314 } else { | |
| 315 isolate->SetTimelineEventRecorder(new TimelineEventRingRecorder()); | |
| 316 } | |
| 317 | |
| 318 | |
| 319 if (FLAG_keep_code) { | 335 if (FLAG_keep_code) { | 
| 320 isolate->set_deoptimized_code_array( | 336 isolate->set_deoptimized_code_array( | 
| 321 GrowableObjectArray::Handle(GrowableObjectArray::New())); | 337 GrowableObjectArray::Handle(GrowableObjectArray::New())); | 
| 322 } | 338 } | 
| 323 return Error::null(); | 339 return Error::null(); | 
| 324 } | 340 } | 
| 325 | 341 | 
| 326 | 342 | 
| 327 void Dart::RunShutdownCallback() { | 343 void Dart::RunShutdownCallback() { | 
| 328 Isolate* isolate = Isolate::Current(); | 344 Isolate* isolate = Isolate::Current(); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 return predefined_handles_->handles_.IsValidScopedHandle(address); | 377 return predefined_handles_->handles_.IsValidScopedHandle(address); | 
| 362 } | 378 } | 
| 363 | 379 | 
| 364 | 380 | 
| 365 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 381 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 
| 366 ASSERT(predefined_handles_ != NULL); | 382 ASSERT(predefined_handles_ != NULL); | 
| 367 return predefined_handles_->api_handles_.IsValidHandle(handle); | 383 return predefined_handles_->api_handles_.IsValidHandle(handle); | 
| 368 } | 384 } | 
| 369 | 385 | 
| 370 } // namespace dart | 386 } // namespace dart | 
| OLD | NEW |