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/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 ReadOnlyHandles() { } | 67 ReadOnlyHandles() { } |
68 | 68 |
69 private: | 69 private: |
70 VMHandles handles_; | 70 VMHandles handles_; |
71 | 71 |
72 friend class Dart; | 72 friend class Dart; |
73 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); | 73 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); |
74 }; | 74 }; |
75 | 75 |
76 | 76 |
77 // TODO(turnidge): We should add a corresponding Dart::Cleanup. | |
78 const char* Dart::InitOnce(Dart_IsolateCreateCallback create, | 77 const char* Dart::InitOnce(Dart_IsolateCreateCallback create, |
79 Dart_IsolateInterruptCallback interrupt, | 78 Dart_IsolateInterruptCallback interrupt, |
80 Dart_IsolateUnhandledExceptionCallback unhandled, | 79 Dart_IsolateUnhandledExceptionCallback unhandled, |
81 Dart_IsolateShutdownCallback shutdown, | 80 Dart_IsolateShutdownCallback shutdown, |
82 Dart_FileOpenCallback file_open, | 81 Dart_FileOpenCallback file_open, |
83 Dart_FileReadCallback file_read, | 82 Dart_FileReadCallback file_read, |
84 Dart_FileWriteCallback file_write, | 83 Dart_FileWriteCallback file_write, |
85 Dart_FileCloseCallback file_close) { | 84 Dart_FileCloseCallback file_close) { |
86 // TODO(iposva): Fix race condition here. | 85 // TODO(iposva): Fix race condition here. |
87 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 86 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 136 |
138 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. | 137 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. |
139 Isolate::SetCreateCallback(create); | 138 Isolate::SetCreateCallback(create); |
140 Isolate::SetInterruptCallback(interrupt); | 139 Isolate::SetInterruptCallback(interrupt); |
141 Isolate::SetUnhandledExceptionCallback(unhandled); | 140 Isolate::SetUnhandledExceptionCallback(unhandled); |
142 Isolate::SetShutdownCallback(shutdown); | 141 Isolate::SetShutdownCallback(shutdown); |
143 return NULL; | 142 return NULL; |
144 } | 143 } |
145 | 144 |
146 | 145 |
| 146 const char* Dart::Cleanup() { |
| 147 #if 0 |
| 148 // Ideally we should shutdown the VM isolate here, but the thread pool |
| 149 // shutdown does not seem to ensure that all the threads have stopped |
| 150 // execution before it terminates, this results in racing isolates. |
| 151 if (vm_isolate_ == NULL) { |
| 152 return "VM already terminated."; |
| 153 } |
| 154 |
| 155 ASSERT(Isolate::Current() == NULL); |
| 156 |
| 157 delete thread_pool_; |
| 158 thread_pool_ = NULL; |
| 159 |
| 160 // Set the VM isolate as current isolate. |
| 161 Isolate::SetCurrent(vm_isolate_); |
| 162 |
| 163 // There is a planned and known asymmetry here: We exit one scope for the VM |
| 164 // isolate to account for the scope that was entered in Dart_InitOnce. |
| 165 Dart_ExitScope(); |
| 166 |
| 167 ShutdownIsolate(); |
| 168 vm_isolate_ = NULL; |
| 169 #endif |
| 170 |
| 171 CodeObservers::DeleteAll(); |
| 172 |
| 173 return NULL; |
| 174 } |
| 175 |
| 176 |
147 Isolate* Dart::CreateIsolate(const char* name_prefix) { | 177 Isolate* Dart::CreateIsolate(const char* name_prefix) { |
148 // Create a new isolate. | 178 // Create a new isolate. |
149 Isolate* isolate = Isolate::Init(name_prefix); | 179 Isolate* isolate = Isolate::Init(name_prefix); |
150 ASSERT(isolate != NULL); | 180 ASSERT(isolate != NULL); |
151 return isolate; | 181 return isolate; |
152 } | 182 } |
153 | 183 |
154 | 184 |
155 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { | 185 RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) { |
156 // Initialize the new isolate. | 186 // Initialize the new isolate. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return predefined_handles_->handles_.AllocateScopedHandle(); | 265 return predefined_handles_->handles_.AllocateScopedHandle(); |
236 } | 266 } |
237 | 267 |
238 | 268 |
239 bool Dart::IsReadOnlyHandle(uword address) { | 269 bool Dart::IsReadOnlyHandle(uword address) { |
240 ASSERT(predefined_handles_ != NULL); | 270 ASSERT(predefined_handles_ != NULL); |
241 return predefined_handles_->handles_.IsValidScopedHandle(address); | 271 return predefined_handles_->handles_.IsValidScopedHandle(address); |
242 } | 272 } |
243 | 273 |
244 } // namespace dart | 274 } // namespace dart |
OLD | NEW |