| 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" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 #if defined(USING_SIMULATOR) | 106 #if defined(USING_SIMULATOR) |
| 107 Simulator::InitOnce(); | 107 Simulator::InitOnce(); |
| 108 #endif | 108 #endif |
| 109 // Create the read-only handles area. | 109 // Create the read-only handles area. |
| 110 ASSERT(predefined_handles_ == NULL); | 110 ASSERT(predefined_handles_ == NULL); |
| 111 predefined_handles_ = new ReadOnlyHandles(); | 111 predefined_handles_ = new ReadOnlyHandles(); |
| 112 // Create the VM isolate and finish the VM initialization. | 112 // Create the VM isolate and finish the VM initialization. |
| 113 ASSERT(thread_pool_ == NULL); | 113 ASSERT(thread_pool_ == NULL); |
| 114 thread_pool_ = new ThreadPool(); | 114 thread_pool_ = new ThreadPool(); |
| 115 { | 115 { |
| 116 Thread* thread = Thread::Current(); |
| 117 ASSERT(thread != NULL); |
| 116 ASSERT(vm_isolate_ == NULL); | 118 ASSERT(vm_isolate_ == NULL); |
| 117 ASSERT(Flags::Initialized()); | 119 ASSERT(Flags::Initialized()); |
| 118 const bool is_vm_isolate = true; | 120 const bool is_vm_isolate = true; |
| 119 | 121 |
| 120 // Setup default flags for the VM isolate. | 122 // Setup default flags for the VM isolate. |
| 121 Isolate::Flags vm_flags; | 123 Isolate::Flags vm_flags; |
| 122 Dart_IsolateFlags api_flags; | 124 Dart_IsolateFlags api_flags; |
| 123 vm_flags.CopyTo(&api_flags); | 125 vm_flags.CopyTo(&api_flags); |
| 124 vm_isolate_ = Isolate::Init("vm-isolate", api_flags, is_vm_isolate); | 126 vm_isolate_ = Isolate::Init("vm-isolate", api_flags, is_vm_isolate); |
| 127 // Verify assumptions about executing in the VM isolate. |
| 128 ASSERT(vm_isolate_ == Isolate::Current()); |
| 129 ASSERT(vm_isolate_ == Thread::Current()->isolate()); |
| 125 | 130 |
| 126 StackZone zone(vm_isolate_); | 131 StackZone zone(vm_isolate_); |
| 127 HandleScope handle_scope(vm_isolate_); | 132 HandleScope handle_scope(thread); |
| 128 Object::InitNull(vm_isolate_); | 133 Object::InitNull(vm_isolate_); |
| 129 ObjectStore::Init(vm_isolate_); | 134 ObjectStore::Init(vm_isolate_); |
| 130 TargetCPUFeatures::InitOnce(); | 135 TargetCPUFeatures::InitOnce(); |
| 131 Object::InitOnce(vm_isolate_); | 136 Object::InitOnce(vm_isolate_); |
| 132 ArgumentsDescriptor::InitOnce(); | 137 ArgumentsDescriptor::InitOnce(); |
| 133 StubCode::InitOnce(); | 138 StubCode::InitOnce(); |
| 134 Thread::InitOnceAfterObjectAndStubCode(); | 139 Thread::InitOnceAfterObjectAndStubCode(); |
| 135 // Now that the needed stub has been generated, set the stack limit. | 140 // Now that the needed stub has been generated, set the stack limit. |
| 136 vm_isolate_->InitializeStackLimit(); | 141 vm_isolate_->InitializeStackLimit(); |
| 137 if (vm_isolate_snapshot != NULL) { | 142 if (vm_isolate_snapshot != NULL) { |
| 138 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); | 143 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); |
| 139 if (snapshot == NULL) { | 144 if (snapshot == NULL) { |
| 140 return "Invalid vm isolate snapshot seen."; | 145 return "Invalid vm isolate snapshot seen."; |
| 141 } | 146 } |
| 142 ASSERT(snapshot->kind() == Snapshot::kFull); | 147 ASSERT(snapshot->kind() == Snapshot::kFull); |
| 143 VmIsolateSnapshotReader reader(snapshot->content(), | 148 VmIsolateSnapshotReader reader(snapshot->content(), |
| 144 snapshot->length(), | 149 snapshot->length(), |
| 145 zone.GetZone()); | 150 thread); |
| 146 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); | 151 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); |
| 147 if (!error.IsNull()) { | 152 if (!error.IsNull()) { |
| 148 return error.ToCString(); | 153 return error.ToCString(); |
| 149 } | 154 } |
| 150 if (FLAG_trace_isolates) { | 155 if (FLAG_trace_isolates) { |
| 151 OS::Print("Size of vm isolate snapshot = %" Pd "\n", | 156 OS::Print("Size of vm isolate snapshot = %" Pd "\n", |
| 152 snapshot->length()); | 157 snapshot->length()); |
| 153 vm_isolate_->heap()->PrintSizes(); | 158 vm_isolate_->heap()->PrintSizes(); |
| 154 vm_isolate_->megamorphic_cache_table()->PrintSizes(); | 159 vm_isolate_->megamorphic_cache_table()->PrintSizes(); |
| 155 intptr_t size; | 160 intptr_t size; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 Isolate* isolate = thread->isolate(); | 249 Isolate* isolate = thread->isolate(); |
| 245 TIMERSCOPE(thread, time_isolate_initialization); | 250 TIMERSCOPE(thread, time_isolate_initialization); |
| 246 TimelineDurationScope tds(isolate, | 251 TimelineDurationScope tds(isolate, |
| 247 isolate->GetIsolateStream(), | 252 isolate->GetIsolateStream(), |
| 248 "InitializeIsolate"); | 253 "InitializeIsolate"); |
| 249 tds.SetNumArguments(1); | 254 tds.SetNumArguments(1); |
| 250 tds.CopyArgument(0, "isolateName", isolate->name()); | 255 tds.CopyArgument(0, "isolateName", isolate->name()); |
| 251 | 256 |
| 252 ASSERT(isolate != NULL); | 257 ASSERT(isolate != NULL); |
| 253 StackZone zone(isolate); | 258 StackZone zone(isolate); |
| 254 HandleScope handle_scope(isolate); | 259 HandleScope handle_scope(thread); |
| 255 { | 260 { |
| 256 TimelineDurationScope tds(isolate, | 261 TimelineDurationScope tds(isolate, |
| 257 isolate->GetIsolateStream(), | 262 isolate->GetIsolateStream(), |
| 258 "ObjectStore::Init"); | 263 "ObjectStore::Init"); |
| 259 ObjectStore::Init(isolate); | 264 ObjectStore::Init(isolate); |
| 260 } | 265 } |
| 261 | 266 |
| 262 // Setup for profiling. | 267 // Setup for profiling. |
| 263 Profiler::InitProfilingForIsolate(isolate); | 268 Profiler::InitProfilingForIsolate(isolate); |
| 264 | 269 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 277 const String& message = String::Handle( | 282 const String& message = String::Handle( |
| 278 String::New("Invalid snapshot.")); | 283 String::New("Invalid snapshot.")); |
| 279 return ApiError::New(message); | 284 return ApiError::New(message); |
| 280 } | 285 } |
| 281 ASSERT(snapshot->kind() == Snapshot::kFull); | 286 ASSERT(snapshot->kind() == Snapshot::kFull); |
| 282 if (FLAG_trace_isolates) { | 287 if (FLAG_trace_isolates) { |
| 283 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); | 288 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); |
| 284 } | 289 } |
| 285 IsolateSnapshotReader reader(snapshot->content(), | 290 IsolateSnapshotReader reader(snapshot->content(), |
| 286 snapshot->length(), | 291 snapshot->length(), |
| 287 isolate, | 292 thread); |
| 288 zone.GetZone()); | |
| 289 const Error& error = Error::Handle(reader.ReadFullSnapshot()); | 293 const Error& error = Error::Handle(reader.ReadFullSnapshot()); |
| 290 if (!error.IsNull()) { | 294 if (!error.IsNull()) { |
| 291 return error.raw(); | 295 return error.raw(); |
| 292 } | 296 } |
| 293 if (FLAG_trace_isolates) { | 297 if (FLAG_trace_isolates) { |
| 294 isolate->heap()->PrintSizes(); | 298 isolate->heap()->PrintSizes(); |
| 295 isolate->megamorphic_cache_table()->PrintSizes(); | 299 isolate->megamorphic_cache_table()->PrintSizes(); |
| 296 } | 300 } |
| 297 } else { | 301 } else { |
| 298 // Populate the isolate's symbol table with all symbols from the | 302 // Populate the isolate's symbol table with all symbols from the |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 return predefined_handles_->handles_.IsValidScopedHandle(address); | 386 return predefined_handles_->handles_.IsValidScopedHandle(address); |
| 383 } | 387 } |
| 384 | 388 |
| 385 | 389 |
| 386 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 390 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
| 387 ASSERT(predefined_handles_ != NULL); | 391 ASSERT(predefined_handles_ != NULL); |
| 388 return predefined_handles_->api_handles_.IsValidHandle(handle); | 392 return predefined_handles_->api_handles_.IsValidHandle(handle); |
| 389 } | 393 } |
| 390 | 394 |
| 391 } // namespace dart | 395 } // namespace dart |
| OLD | NEW |