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 27 matching lines...) Expand all Loading... |
38 "e.g: --old_gen_heap_size=1024 allows up to 1024MB old gen heap"); | 38 "e.g: --old_gen_heap_size=1024 allows up to 1024MB old gen heap"); |
39 | 39 |
40 DECLARE_FLAG(bool, print_class_table); | 40 DECLARE_FLAG(bool, print_class_table); |
41 DECLARE_FLAG(bool, trace_isolates); | 41 DECLARE_FLAG(bool, trace_isolates); |
42 | 42 |
43 Isolate* Dart::vm_isolate_ = NULL; | 43 Isolate* Dart::vm_isolate_ = NULL; |
44 ThreadPool* Dart::thread_pool_ = NULL; | 44 ThreadPool* Dart::thread_pool_ = NULL; |
45 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 45 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
46 ReadOnlyHandles* Dart::predefined_handles_ = NULL; | 46 ReadOnlyHandles* Dart::predefined_handles_ = NULL; |
47 | 47 |
48 // An object visitor which will mark all visited objects. This is used to | |
49 // premark all objects in the vm_isolate_ heap. | |
50 class PremarkingVisitor : public ObjectVisitor { | |
51 public: | |
52 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} | |
53 | |
54 void VisitObject(RawObject* obj) { | |
55 // RawInstruction objects are premarked on allocation. | |
56 if (!obj->IsMarked()) { | |
57 obj->SetMarkBit(); | |
58 } | |
59 } | |
60 }; | |
61 | |
62 | |
63 // Structure for managing read-only global handles allocation used for | 48 // Structure for managing read-only global handles allocation used for |
64 // creating global read-only handles that are pre created and initialized | 49 // creating global read-only handles that are pre created and initialized |
65 // for use across all isolates. Having these global pre created handles | 50 // for use across all isolates. Having these global pre created handles |
66 // stored in the vm isolate ensures that we don't constantly create and | 51 // stored in the vm isolate ensures that we don't constantly create and |
67 // destroy handles for read-only objects referred in the VM code | 52 // destroy handles for read-only objects referred in the VM code |
68 // (e.g: symbols, null object, empty array etc.) | 53 // (e.g: symbols, null object, empty array etc.) |
69 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is | 54 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is |
70 // to ensure that the handles area is not trashed by automatic running of C++ | 55 // to ensure that the handles area is not trashed by automatic running of C++ |
71 // static destructors when 'exit()" is called by any isolate. There might be | 56 // static destructors when 'exit()" is called by any isolate. There might be |
72 // other isolates running at the same time and trashing the handles area will | 57 // other isolates running at the same time and trashing the handles area will |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 ASSERT(vm_isolate_ == NULL); | 109 ASSERT(vm_isolate_ == NULL); |
125 ASSERT(Flags::Initialized()); | 110 ASSERT(Flags::Initialized()); |
126 vm_isolate_ = Isolate::Init("vm-isolate"); | 111 vm_isolate_ = Isolate::Init("vm-isolate"); |
127 StackZone zone(vm_isolate_); | 112 StackZone zone(vm_isolate_); |
128 HandleScope handle_scope(vm_isolate_); | 113 HandleScope handle_scope(vm_isolate_); |
129 Heap::Init(vm_isolate_, | 114 Heap::Init(vm_isolate_, |
130 0, // New gen size 0; VM isolate should only allocate in old. | 115 0, // New gen size 0; VM isolate should only allocate in old. |
131 FLAG_old_gen_heap_size * MBInWords); | 116 FLAG_old_gen_heap_size * MBInWords); |
132 ObjectStore::Init(vm_isolate_); | 117 ObjectStore::Init(vm_isolate_); |
133 TargetCPUFeatures::InitOnce(); | 118 TargetCPUFeatures::InitOnce(); |
134 Object::InitOnce(); | 119 Object::InitOnce(vm_isolate_); |
135 ArgumentsDescriptor::InitOnce(); | 120 ArgumentsDescriptor::InitOnce(); |
136 StubCode::InitOnce(); | 121 StubCode::InitOnce(); |
137 Symbols::InitOnce(vm_isolate_); | 122 Symbols::InitOnce(vm_isolate_); |
138 Scanner::InitOnce(); | 123 Scanner::InitOnce(); |
139 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 124 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
140 // Dart VM requires at least SSE2. | 125 // Dart VM requires at least SSE2. |
141 if (!TargetCPUFeatures::sse2_supported()) { | 126 if (!TargetCPUFeatures::sse2_supported()) { |
142 return "SSE2 is required."; | 127 return "SSE2 is required."; |
143 } | 128 } |
144 #endif | 129 #endif |
145 PremarkingVisitor premarker(vm_isolate_); | 130 Object::FinalizeVMIsolate(vm_isolate_); |
146 vm_isolate_->heap()->WriteProtect(false); | |
147 ASSERT(vm_isolate_->heap()->UsedInWords(Heap::kNew) == 0); | |
148 vm_isolate_->heap()->IterateOldObjects(&premarker); | |
149 vm_isolate_->heap()->WriteProtect(true); | |
150 } | 131 } |
151 // There is a planned and known asymmetry here: We enter one scope for the VM | 132 // There is a planned and known asymmetry here: We enter one scope for the VM |
152 // isolate so that we can allocate the "persistent" scoped handles for the | 133 // isolate so that we can allocate the "persistent" scoped handles for the |
153 // predefined API values (such as Dart_True, Dart_False and Dart_Null). | 134 // predefined API values (such as Dart_True, Dart_False and Dart_Null). |
154 Dart_EnterScope(); | 135 Dart_EnterScope(); |
155 Api::InitHandles(); | 136 Api::InitHandles(); |
156 | 137 |
157 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. | 138 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. |
158 Isolate::SetCreateCallback(create); | 139 Isolate::SetCreateCallback(create); |
159 Isolate::SetServiceCreateCallback(service_create); | 140 Isolate::SetServiceCreateCallback(service_create); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return predefined_handles_->handles_.AllocateScopedHandle(); | 290 return predefined_handles_->handles_.AllocateScopedHandle(); |
310 } | 291 } |
311 | 292 |
312 | 293 |
313 bool Dart::IsReadOnlyHandle(uword address) { | 294 bool Dart::IsReadOnlyHandle(uword address) { |
314 ASSERT(predefined_handles_ != NULL); | 295 ASSERT(predefined_handles_ != NULL); |
315 return predefined_handles_->handles_.IsValidScopedHandle(address); | 296 return predefined_handles_->handles_.IsValidScopedHandle(address); |
316 } | 297 } |
317 | 298 |
318 } // namespace dart | 299 } // namespace dart |
OLD | NEW |