Chromium Code Reviews| 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. | |
|
Ivan Posva
2012/12/20 23:43:52
Maybe explain why this is wrapped in an object in
siva
2012/12/21 02:28:06
Done.
| |
| 59 class ReadOnlyHandles { | |
| 60 public: | |
| 61 ReadOnlyHandles() { } | |
| 62 | |
| 63 private: | |
| 64 VMHandles handles_; | |
| 65 | |
| 66 friend class Dart; | |
| 67 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); | |
| 68 }; | |
| 69 | |
| 70 | |
| 52 // TODO(turnidge): We should add a corresponding Dart::Cleanup. | 71 // TODO(turnidge): We should add a corresponding Dart::Cleanup. |
| 53 const char* Dart::InitOnce(Dart_IsolateCreateCallback create, | 72 const char* Dart::InitOnce(Dart_IsolateCreateCallback create, |
| 54 Dart_IsolateInterruptCallback interrupt, | 73 Dart_IsolateInterruptCallback interrupt, |
| 55 Dart_IsolateUnhandledExceptionCallback unhandled, | 74 Dart_IsolateUnhandledExceptionCallback unhandled, |
| 56 Dart_IsolateShutdownCallback shutdown, | 75 Dart_IsolateShutdownCallback shutdown, |
| 57 Dart_FileOpenCallback file_open, | 76 Dart_FileOpenCallback file_open, |
| 58 Dart_FileWriteCallback file_write, | 77 Dart_FileWriteCallback file_write, |
| 59 Dart_FileCloseCallback file_close) { | 78 Dart_FileCloseCallback file_close) { |
| 60 // TODO(iposva): Fix race condition here. | 79 // TODO(iposva): Fix race condition here. |
| 61 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 80 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
| 62 return "VM already initialized."; | 81 return "VM already initialized."; |
| 63 } | 82 } |
| 64 Isolate::SetFileCallbacks(file_open, file_write, file_close); | 83 Isolate::SetFileCallbacks(file_open, file_write, file_close); |
| 65 OS::InitOnce(); | 84 OS::InitOnce(); |
| 66 VirtualMemory::InitOnce(); | 85 VirtualMemory::InitOnce(); |
| 67 Isolate::InitOnce(); | 86 Isolate::InitOnce(); |
| 68 PortMap::InitOnce(); | 87 PortMap::InitOnce(); |
| 69 FreeListElement::InitOnce(); | 88 FreeListElement::InitOnce(); |
| 70 Api::InitOnce(); | 89 Api::InitOnce(); |
| 71 CodeObservers::InitOnce(); | 90 CodeObservers::InitOnce(); |
| 91 // Create the read only handles area. | |
| 92 ASSERT(predefined_handles_ == NULL); | |
| 93 predefined_handles_ = new ReadOnlyHandles(); | |
| 72 // Create the VM isolate and finish the VM initialization. | 94 // Create the VM isolate and finish the VM initialization. |
| 73 ASSERT(thread_pool_ == NULL); | 95 ASSERT(thread_pool_ == NULL); |
| 74 thread_pool_ = new ThreadPool(); | 96 thread_pool_ = new ThreadPool(); |
| 75 { | 97 { |
| 76 ASSERT(vm_isolate_ == NULL); | 98 ASSERT(vm_isolate_ == NULL); |
| 77 ASSERT(Flags::Initialized()); | 99 ASSERT(Flags::Initialized()); |
| 78 vm_isolate_ = Isolate::Init("vm-isolate"); | 100 vm_isolate_ = Isolate::Init("vm-isolate"); |
| 79 StackZone zone(vm_isolate_); | 101 StackZone zone(vm_isolate_); |
| 80 HandleScope handle_scope(vm_isolate_); | 102 HandleScope handle_scope(vm_isolate_); |
| 81 Heap::Init(vm_isolate_); | 103 Heap::Init(vm_isolate_); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 isolate->Shutdown(); | 225 isolate->Shutdown(); |
| 204 delete isolate; | 226 delete isolate; |
| 205 | 227 |
| 206 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); | 228 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); |
| 207 if (callback != NULL) { | 229 if (callback != NULL) { |
| 208 (callback)(callback_data); | 230 (callback)(callback_data); |
| 209 } | 231 } |
| 210 } | 232 } |
| 211 | 233 |
| 212 | 234 |
| 235 uword Dart::AllocateReadOnlyHandle() { | |
| 236 ASSERT(predefined_handles_ != NULL); | |
| 237 return predefined_handles_->handles_.AllocateScopedHandle(); | |
| 238 } | |
| 239 | |
| 240 | |
| 241 bool Dart::IsReadOnlyHandle(uword address) { | |
| 242 ASSERT(predefined_handles_ != NULL); | |
| 243 return predefined_handles_->handles_.IsValidScopedHandle(address); | |
| 244 } | |
| 245 | |
| 213 } // namespace dart | 246 } // namespace dart |
| OLD | NEW |