Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: runtime/vm/dart.cc

Issue 1439483003: - Add an OSThread structure which is the generic TLS structure for all C++ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/lib/timeline.cc ('k') | runtime/vm/dart_api_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 Dart_EntropySource entropy_source, 83 Dart_EntropySource entropy_source,
84 Dart_GetVMServiceAssetsArchive get_service_assets) { 84 Dart_GetVMServiceAssetsArchive get_service_assets) {
85 // TODO(iposva): Fix race condition here. 85 // TODO(iposva): Fix race condition here.
86 if (vm_isolate_ != NULL || !Flags::Initialized()) { 86 if (vm_isolate_ != NULL || !Flags::Initialized()) {
87 return "VM already initialized or flags not initialized."; 87 return "VM already initialized or flags not initialized.";
88 } 88 }
89 Isolate::SetFileCallbacks(file_open, file_read, file_write, file_close); 89 Isolate::SetFileCallbacks(file_open, file_read, file_write, file_close);
90 Isolate::SetEntropySourceCallback(entropy_source); 90 Isolate::SetEntropySourceCallback(entropy_source);
91 OS::InitOnce(); 91 OS::InitOnce();
92 VirtualMemory::InitOnce(); 92 VirtualMemory::InitOnce();
93 Thread::InitOnceBeforeIsolate(); 93 OSThread::InitOnce();
94 Thread::EnsureInit();
95 Timeline::InitOnce(); 94 Timeline::InitOnce();
96 Thread* thread = Thread::Current();
97 thread->set_name("Dart_Initialize");
98 TimelineDurationScope tds(Timeline::GetVMStream(), 95 TimelineDurationScope tds(Timeline::GetVMStream(),
99 "Dart::InitOnce"); 96 "Dart::InitOnce");
100 Isolate::InitOnce(); 97 Isolate::InitOnce();
101 PortMap::InitOnce(); 98 PortMap::InitOnce();
102 FreeListElement::InitOnce(); 99 FreeListElement::InitOnce();
103 Api::InitOnce(); 100 Api::InitOnce();
104 CodeObservers::InitOnce(); 101 CodeObservers::InitOnce();
105 ThreadInterrupter::InitOnce(); 102 ThreadInterrupter::InitOnce();
106 Profiler::InitOnce(); 103 Profiler::InitOnce();
107 SemiSpace::InitOnce(); 104 SemiSpace::InitOnce();
108 Metric::InitOnce(); 105 Metric::InitOnce();
109 StoreBuffer::InitOnce(); 106 StoreBuffer::InitOnce();
110 MarkingStack::InitOnce(); 107 MarkingStack::InitOnce();
111 Thread::EnsureInit();
112 108
113 #if defined(USING_SIMULATOR) 109 #if defined(USING_SIMULATOR)
114 Simulator::InitOnce(); 110 Simulator::InitOnce();
115 #endif 111 #endif
116 // Create the read-only handles area. 112 // Create the read-only handles area.
117 ASSERT(predefined_handles_ == NULL); 113 ASSERT(predefined_handles_ == NULL);
118 predefined_handles_ = new ReadOnlyHandles(); 114 predefined_handles_ = new ReadOnlyHandles();
119 // Create the VM isolate and finish the VM initialization. 115 // Create the VM isolate and finish the VM initialization.
120 ASSERT(thread_pool_ == NULL); 116 ASSERT(thread_pool_ == NULL);
121 thread_pool_ = new ThreadPool(); 117 thread_pool_ = new ThreadPool();
122 { 118 {
123 Thread* T = Thread::Current();
124 ASSERT(T != NULL);
125 ASSERT(vm_isolate_ == NULL); 119 ASSERT(vm_isolate_ == NULL);
126 ASSERT(Flags::Initialized()); 120 ASSERT(Flags::Initialized());
127 const bool is_vm_isolate = true; 121 const bool is_vm_isolate = true;
128 const bool precompiled = instructions_snapshot != NULL; 122 const bool precompiled = instructions_snapshot != NULL;
129 123
130 // Setup default flags for the VM isolate. 124 // Setup default flags for the VM isolate.
131 Isolate::Flags vm_flags; 125 Isolate::Flags vm_flags;
132 Dart_IsolateFlags api_flags; 126 Dart_IsolateFlags api_flags;
133 vm_flags.CopyTo(&api_flags); 127 vm_flags.CopyTo(&api_flags);
134 vm_isolate_ = Isolate::Init("vm-isolate", api_flags, is_vm_isolate); 128 vm_isolate_ = Isolate::Init("vm-isolate", api_flags, is_vm_isolate);
135 vm_isolate_->set_compilation_allowed(!precompiled); 129 vm_isolate_->set_compilation_allowed(!precompiled);
136 // Verify assumptions about executing in the VM isolate. 130 // Verify assumptions about executing in the VM isolate.
137 ASSERT(vm_isolate_ == Isolate::Current()); 131 ASSERT(vm_isolate_ == Isolate::Current());
138 ASSERT(vm_isolate_ == Thread::Current()->isolate()); 132 ASSERT(vm_isolate_ == Thread::Current()->isolate());
139 133
134 Thread* T = Thread::Current();
135 ASSERT(T != NULL);
140 StackZone zone(T); 136 StackZone zone(T);
141 HandleScope handle_scope(T); 137 HandleScope handle_scope(T);
142 Object::InitNull(vm_isolate_); 138 Object::InitNull(vm_isolate_);
143 ObjectStore::Init(vm_isolate_); 139 ObjectStore::Init(vm_isolate_);
144 TargetCPUFeatures::InitOnce(); 140 TargetCPUFeatures::InitOnce();
145 Object::InitOnce(vm_isolate_); 141 Object::InitOnce(vm_isolate_);
146 ArgumentsDescriptor::InitOnce(); 142 ArgumentsDescriptor::InitOnce();
147 ICData::InitOnce(); 143 ICData::InitOnce();
148 // When precompiled the stub code is initialized from the snapshot. 144 // When precompiled the stub code is initialized from the snapshot.
149 if (!precompiled) { 145 if (!precompiled) {
(...skipping 23 matching lines...) Expand all
173 MegamorphicCacheTable::PrintSizes(vm_isolate_); 169 MegamorphicCacheTable::PrintSizes(vm_isolate_);
174 intptr_t size; 170 intptr_t size;
175 intptr_t capacity; 171 intptr_t capacity;
176 Symbols::GetStats(vm_isolate_, &size, &capacity); 172 Symbols::GetStats(vm_isolate_, &size, &capacity);
177 OS::Print("VM Isolate: Number of symbols : %" Pd "\n", size); 173 OS::Print("VM Isolate: Number of symbols : %" Pd "\n", size);
178 OS::Print("VM Isolate: Symbol table capacity : %" Pd "\n", capacity); 174 OS::Print("VM Isolate: Symbol table capacity : %" Pd "\n", capacity);
179 } 175 }
180 } else { 176 } else {
181 Symbols::InitOnce(vm_isolate_); 177 Symbols::InitOnce(vm_isolate_);
182 } 178 }
183 Thread::InitOnceAfterObjectAndStubCode(); 179 // We need to initialize the constants here for the vm isolate thread due to
180 // bootstrapping issues.
181 T->InitVMConstants();
184 Scanner::InitOnce(); 182 Scanner::InitOnce();
185 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 183 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
186 // Dart VM requires at least SSE2. 184 // Dart VM requires at least SSE2.
187 if (!TargetCPUFeatures::sse2_supported()) { 185 if (!TargetCPUFeatures::sse2_supported()) {
188 return "SSE2 is required."; 186 return "SSE2 is required.";
189 } 187 }
190 #endif 188 #endif
191 Object::FinalizeVMIsolate(vm_isolate_); 189 Object::FinalizeVMIsolate(vm_isolate_);
192 #if defined(DEBUG) 190 #if defined(DEBUG)
193 vm_isolate_->heap()->Verify(kRequireMarked); 191 vm_isolate_->heap()->Verify(kRequireMarked);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 241
244 // Wait for all application isolates and the service isolate to shutdown 242 // Wait for all application isolates and the service isolate to shutdown
245 // before shutting down the thread pool. 243 // before shutting down the thread pool.
246 WaitForIsolateShutdown(); 244 WaitForIsolateShutdown();
247 245
248 // Shutdown the thread pool. On return, all thread pool threads have exited. 246 // Shutdown the thread pool. On return, all thread pool threads have exited.
249 delete thread_pool_; 247 delete thread_pool_;
250 thread_pool_ = NULL; 248 thread_pool_ = NULL;
251 249
252 // Set the VM isolate as current isolate. 250 // Set the VM isolate as current isolate.
253 Thread::EnsureInit();
254 Thread::EnterIsolate(vm_isolate_); 251 Thread::EnterIsolate(vm_isolate_);
255 252
256 ShutdownIsolate(); 253 ShutdownIsolate();
257 vm_isolate_ = NULL; 254 vm_isolate_ = NULL;
258 ASSERT(Isolate::IsolateListLength() == 0); 255 ASSERT(Isolate::IsolateListLength() == 0);
259 256
260 TargetCPUFeatures::Cleanup(); 257 TargetCPUFeatures::Cleanup();
261 StoreBuffer::ShutDown(); 258 StoreBuffer::ShutDown();
262 259
263 Thread::Shutdown(); 260 // Delete the current thread's TLS and set it's TLS to null.
261 // If it is the last thread then the destructor would call
262 // OSThread::Cleanup.
263 OSThread* os_thread = OSThread::Current();
264 OSThread::SetCurrent(NULL);
265 delete os_thread;
264 } else { 266 } else {
265 // Shutdown the service isolate. 267 // Shutdown the service isolate.
266 ServiceIsolate::Shutdown(); 268 ServiceIsolate::Shutdown();
267 } 269 }
268 270
269 CodeObservers::DeleteAll(); 271 CodeObservers::DeleteAll();
270 Timeline::Shutdown(); 272 Timeline::Shutdown();
271 Metric::Cleanup(); 273 Metric::Cleanup();
272 274
273 return NULL; 275 return NULL;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return predefined_handles_->handles_.IsValidScopedHandle(address); 438 return predefined_handles_->handles_.IsValidScopedHandle(address);
437 } 439 }
438 440
439 441
440 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { 442 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) {
441 ASSERT(predefined_handles_ != NULL); 443 ASSERT(predefined_handles_ != NULL);
442 return predefined_handles_->api_handles_.IsValidHandle(handle); 444 return predefined_handles_->api_handles_.IsValidHandle(handle);
443 } 445 }
444 446
445 } // namespace dart 447 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/timeline.cc ('k') | runtime/vm/dart_api_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698