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/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/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/freelist.h" | 10 #include "vm/freelist.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 DEFINE_FLAG(bool, heap_profile_initialize, false, | 26 DEFINE_FLAG(bool, heap_profile_initialize, false, |
27 "Writes a heap profile on isolate initialization."); | 27 "Writes a heap profile on isolate initialization."); |
28 DECLARE_FLAG(bool, heap_trace); | 28 DECLARE_FLAG(bool, heap_trace); |
29 DECLARE_FLAG(bool, print_bootstrap); | 29 DECLARE_FLAG(bool, print_bootstrap); |
30 DECLARE_FLAG(bool, print_class_table); | 30 DECLARE_FLAG(bool, print_class_table); |
31 DECLARE_FLAG(bool, trace_isolates); | 31 DECLARE_FLAG(bool, trace_isolates); |
32 | 32 |
33 Isolate* Dart::vm_isolate_ = NULL; | 33 Isolate* Dart::vm_isolate_ = NULL; |
34 ThreadPool* Dart::thread_pool_ = NULL; | 34 ThreadPool* Dart::thread_pool_ = NULL; |
35 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 35 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
| 36 ReadOnlyHandles* Dart::predefined_handles_ = NULL; |
36 | 37 |
37 // An object visitor which will mark all visited objects. This is used to | 38 // An object visitor which will mark all visited objects. This is used to |
38 // premark all objects in the vm_isolate_ heap. | 39 // premark all objects in the vm_isolate_ heap. |
39 class PremarkingVisitor : public ObjectVisitor { | 40 class PremarkingVisitor : public ObjectVisitor { |
40 public: | 41 public: |
41 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} | 42 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} |
42 | 43 |
43 void VisitObject(RawObject* obj) { | 44 void VisitObject(RawObject* obj) { |
44 // RawInstruction objects are premarked on allocation. | 45 // RawInstruction objects are premarked on allocation. |
45 if (!obj->IsMarked()) { | 46 if (!obj->IsMarked()) { |
46 obj->SetMarkBit(); | 47 obj->SetMarkBit(); |
47 } | 48 } |
48 } | 49 } |
49 }; | 50 }; |
50 | 51 |
51 | 52 |
| 53 // Structure for managing read-only global handles allocation used for |
| 54 // creating global read-only handles that are pre created and initialized |
| 55 // for use across all isolates. Having these global pre created handles |
| 56 // stored in the vm isolate ensures that we don't constantly create and |
| 57 // destroy handles for read-only objects referred in the VM code |
| 58 // (e.g: symbols, null object, empty array etc.) |
| 59 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is |
| 60 // to ensure that the handles area is not trashed by automatic running of C++ |
| 61 // static destructors when 'exit()" is called by any isolate. There might be |
| 62 // other isolates running at the same time and trashing the handles area will |
| 63 // have unintended consequences. |
| 64 class ReadOnlyHandles { |
| 65 public: |
| 66 ReadOnlyHandles() { } |
| 67 |
| 68 private: |
| 69 VMHandles handles_; |
| 70 |
| 71 friend class Dart; |
| 72 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); |
| 73 }; |
| 74 |
| 75 |
52 // TODO(turnidge): We should add a corresponding Dart::Cleanup. | 76 // TODO(turnidge): We should add a corresponding Dart::Cleanup. |
53 const char* Dart::InitOnce(Dart_IsolateCreateCallback create, | 77 const char* Dart::InitOnce(Dart_IsolateCreateCallback create, |
54 Dart_IsolateInterruptCallback interrupt, | 78 Dart_IsolateInterruptCallback interrupt, |
55 Dart_IsolateUnhandledExceptionCallback unhandled, | 79 Dart_IsolateUnhandledExceptionCallback unhandled, |
56 Dart_IsolateShutdownCallback shutdown, | 80 Dart_IsolateShutdownCallback shutdown, |
57 Dart_FileOpenCallback file_open, | 81 Dart_FileOpenCallback file_open, |
58 Dart_FileWriteCallback file_write, | 82 Dart_FileWriteCallback file_write, |
59 Dart_FileCloseCallback file_close) { | 83 Dart_FileCloseCallback file_close) { |
60 // TODO(iposva): Fix race condition here. | 84 // TODO(iposva): Fix race condition here. |
61 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 85 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
62 return "VM already initialized."; | 86 return "VM already initialized."; |
63 } | 87 } |
64 Isolate::SetFileCallbacks(file_open, file_write, file_close); | 88 Isolate::SetFileCallbacks(file_open, file_write, file_close); |
65 OS::InitOnce(); | 89 OS::InitOnce(); |
66 VirtualMemory::InitOnce(); | 90 VirtualMemory::InitOnce(); |
67 Isolate::InitOnce(); | 91 Isolate::InitOnce(); |
68 PortMap::InitOnce(); | 92 PortMap::InitOnce(); |
69 FreeListElement::InitOnce(); | 93 FreeListElement::InitOnce(); |
70 Api::InitOnce(); | 94 Api::InitOnce(); |
71 CodeObservers::InitOnce(); | 95 CodeObservers::InitOnce(); |
| 96 // Create the read-only handles area. |
| 97 ASSERT(predefined_handles_ == NULL); |
| 98 predefined_handles_ = new ReadOnlyHandles(); |
72 // Create the VM isolate and finish the VM initialization. | 99 // Create the VM isolate and finish the VM initialization. |
73 ASSERT(thread_pool_ == NULL); | 100 ASSERT(thread_pool_ == NULL); |
74 thread_pool_ = new ThreadPool(); | 101 thread_pool_ = new ThreadPool(); |
75 { | 102 { |
76 ASSERT(vm_isolate_ == NULL); | 103 ASSERT(vm_isolate_ == NULL); |
77 ASSERT(Flags::Initialized()); | 104 ASSERT(Flags::Initialized()); |
78 vm_isolate_ = Isolate::Init("vm-isolate"); | 105 vm_isolate_ = Isolate::Init("vm-isolate"); |
79 StackZone zone(vm_isolate_); | 106 StackZone zone(vm_isolate_); |
80 HandleScope handle_scope(vm_isolate_); | 107 HandleScope handle_scope(vm_isolate_); |
81 Heap::Init(vm_isolate_); | 108 Heap::Init(vm_isolate_); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 isolate->Shutdown(); | 230 isolate->Shutdown(); |
204 delete isolate; | 231 delete isolate; |
205 | 232 |
206 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); | 233 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); |
207 if (callback != NULL) { | 234 if (callback != NULL) { |
208 (callback)(callback_data); | 235 (callback)(callback_data); |
209 } | 236 } |
210 } | 237 } |
211 | 238 |
212 | 239 |
| 240 uword Dart::AllocateReadOnlyHandle() { |
| 241 ASSERT(predefined_handles_ != NULL); |
| 242 return predefined_handles_->handles_.AllocateScopedHandle(); |
| 243 } |
| 244 |
| 245 |
| 246 bool Dart::IsReadOnlyHandle(uword address) { |
| 247 ASSERT(predefined_handles_ != NULL); |
| 248 return predefined_handles_->handles_.IsValidScopedHandle(address); |
| 249 } |
| 250 |
213 } // namespace dart | 251 } // namespace dart |
OLD | NEW |