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 DECLARE_FLAG(bool, trace_time_all); | 38 DECLARE_FLAG(bool, trace_time_all); |
39 DEFINE_FLAG(bool, keep_code, false, | 39 DEFINE_FLAG(bool, keep_code, false, |
40 "Keep deoptimized code for profiling."); | 40 "Keep deoptimized code for profiling."); |
41 DEFINE_FLAG(bool, shutdown, true, "Do a clean shutdown of the VM"); | 41 DEFINE_FLAG(bool, shutdown, true, "Do a clean shutdown of the VM"); |
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 const uint8_t* Dart::instructions_snapshot_buffer_ = NULL; | 47 const uint8_t* Dart::instructions_snapshot_buffer_ = NULL; |
| 48 const uint8_t* Dart::data_snapshot_buffer_ = NULL; |
48 | 49 |
49 // Structure for managing read-only global handles allocation used for | 50 // Structure for managing read-only global handles allocation used for |
50 // creating global read-only handles that are pre created and initialized | 51 // creating global read-only handles that are pre created and initialized |
51 // for use across all isolates. Having these global pre created handles | 52 // for use across all isolates. Having these global pre created handles |
52 // stored in the vm isolate ensures that we don't constantly create and | 53 // stored in the vm isolate ensures that we don't constantly create and |
53 // destroy handles for read-only objects referred in the VM code | 54 // destroy handles for read-only objects referred in the VM code |
54 // (e.g: symbols, null object, empty array etc.) | 55 // (e.g: symbols, null object, empty array etc.) |
55 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is | 56 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is |
56 // to ensure that the handles area is not trashed by automatic running of C++ | 57 // to ensure that the handles area is not trashed by automatic running of C++ |
57 // static destructors when 'exit()" is called by any isolate. There might be | 58 // static destructors when 'exit()" is called by any isolate. There might be |
58 // other isolates running at the same time and trashing the handles area will | 59 // other isolates running at the same time and trashing the handles area will |
59 // have unintended consequences. | 60 // have unintended consequences. |
60 class ReadOnlyHandles { | 61 class ReadOnlyHandles { |
61 public: | 62 public: |
62 ReadOnlyHandles() { } | 63 ReadOnlyHandles() { } |
63 | 64 |
64 private: | 65 private: |
65 VMHandles handles_; | 66 VMHandles handles_; |
66 LocalHandles api_handles_; | 67 LocalHandles api_handles_; |
67 | 68 |
68 friend class Dart; | 69 friend class Dart; |
69 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); | 70 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); |
70 }; | 71 }; |
71 | 72 |
72 | 73 |
73 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, | 74 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, |
74 const uint8_t* instructions_snapshot, | 75 const uint8_t* instructions_snapshot, |
| 76 const uint8_t* data_snapshot, |
75 Dart_IsolateCreateCallback create, | 77 Dart_IsolateCreateCallback create, |
76 Dart_IsolateShutdownCallback shutdown, | 78 Dart_IsolateShutdownCallback shutdown, |
77 Dart_FileOpenCallback file_open, | 79 Dart_FileOpenCallback file_open, |
78 Dart_FileReadCallback file_read, | 80 Dart_FileReadCallback file_read, |
79 Dart_FileWriteCallback file_write, | 81 Dart_FileWriteCallback file_write, |
80 Dart_FileCloseCallback file_close, | 82 Dart_FileCloseCallback file_close, |
81 Dart_EntropySource entropy_source, | 83 Dart_EntropySource entropy_source, |
82 Dart_GetVMServiceAssetsArchive get_service_assets) { | 84 Dart_GetVMServiceAssetsArchive get_service_assets) { |
83 // TODO(iposva): Fix race condition here. | 85 // TODO(iposva): Fix race condition here. |
84 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 86 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 Object::InitOnce(vm_isolate_); | 141 Object::InitOnce(vm_isolate_); |
140 ArgumentsDescriptor::InitOnce(); | 142 ArgumentsDescriptor::InitOnce(); |
141 ICData::InitOnce(); | 143 ICData::InitOnce(); |
142 // When precompiled the stub code is initialized from the snapshot. | 144 // When precompiled the stub code is initialized from the snapshot. |
143 if (!precompiled) { | 145 if (!precompiled) { |
144 StubCode::InitOnce(); | 146 StubCode::InitOnce(); |
145 } | 147 } |
146 if (vm_isolate_snapshot != NULL) { | 148 if (vm_isolate_snapshot != NULL) { |
147 if (instructions_snapshot != NULL) { | 149 if (instructions_snapshot != NULL) { |
148 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); | 150 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); |
| 151 ASSERT(data_snapshot != NULL); |
| 152 vm_isolate_->SetupDataSnapshotPage(data_snapshot); |
149 } | 153 } |
150 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); | 154 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); |
151 if (snapshot == NULL) { | 155 if (snapshot == NULL) { |
152 return "Invalid vm isolate snapshot seen."; | 156 return "Invalid vm isolate snapshot seen."; |
153 } | 157 } |
154 ASSERT(snapshot->kind() == Snapshot::kFull); | 158 ASSERT(snapshot->kind() == Snapshot::kFull); |
155 VmIsolateSnapshotReader reader(snapshot->content(), | 159 VmIsolateSnapshotReader reader(snapshot->content(), |
156 snapshot->length(), | 160 snapshot->length(), |
157 instructions_snapshot, | 161 instructions_snapshot, |
| 162 data_snapshot, |
158 T); | 163 T); |
159 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); | 164 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); |
160 if (!error.IsNull()) { | 165 if (!error.IsNull()) { |
161 return error.ToCString(); | 166 return error.ToCString(); |
162 } | 167 } |
163 if (FLAG_trace_isolates) { | 168 if (FLAG_trace_isolates) { |
164 OS::Print("Size of vm isolate snapshot = %" Pd "\n", | 169 OS::Print("Size of vm isolate snapshot = %" Pd "\n", |
165 snapshot->length()); | 170 snapshot->length()); |
166 vm_isolate_->heap()->PrintSizes(); | 171 vm_isolate_->heap()->PrintSizes(); |
167 MegamorphicCacheTable::PrintSizes(vm_isolate_); | 172 MegamorphicCacheTable::PrintSizes(vm_isolate_); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 String::New("Invalid snapshot.")); | 336 String::New("Invalid snapshot.")); |
332 return ApiError::New(message); | 337 return ApiError::New(message); |
333 } | 338 } |
334 ASSERT(snapshot->kind() == Snapshot::kFull); | 339 ASSERT(snapshot->kind() == Snapshot::kFull); |
335 if (FLAG_trace_isolates) { | 340 if (FLAG_trace_isolates) { |
336 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); | 341 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); |
337 } | 342 } |
338 IsolateSnapshotReader reader(snapshot->content(), | 343 IsolateSnapshotReader reader(snapshot->content(), |
339 snapshot->length(), | 344 snapshot->length(), |
340 Dart::instructions_snapshot_buffer(), | 345 Dart::instructions_snapshot_buffer(), |
| 346 Dart::data_snapshot_buffer(), |
341 T); | 347 T); |
342 const Error& error = Error::Handle(reader.ReadFullSnapshot()); | 348 const Error& error = Error::Handle(reader.ReadFullSnapshot()); |
343 if (!error.IsNull()) { | 349 if (!error.IsNull()) { |
344 return error.raw(); | 350 return error.raw(); |
345 } | 351 } |
346 if (FLAG_trace_isolates) { | 352 if (FLAG_trace_isolates) { |
347 I->heap()->PrintSizes(); | 353 I->heap()->PrintSizes(); |
348 MegamorphicCacheTable::PrintSizes(I); | 354 MegamorphicCacheTable::PrintSizes(I); |
349 } | 355 } |
350 } else { | 356 } else { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 return predefined_handles_->handles_.IsValidScopedHandle(address); | 461 return predefined_handles_->handles_.IsValidScopedHandle(address); |
456 } | 462 } |
457 | 463 |
458 | 464 |
459 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 465 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
460 ASSERT(predefined_handles_ != NULL); | 466 ASSERT(predefined_handles_ != NULL); |
461 return predefined_handles_->api_handles_.IsValidHandle(handle); | 467 return predefined_handles_->api_handles_.IsValidHandle(handle); |
462 } | 468 } |
463 | 469 |
464 } // namespace dart | 470 } // namespace dart |
OLD | NEW |