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 30 matching lines...) Expand all Loading... |
41 DECLARE_FLAG(bool, pause_isolates_on_exit); | 41 DECLARE_FLAG(bool, pause_isolates_on_exit); |
42 DEFINE_FLAG(bool, keep_code, false, | 42 DEFINE_FLAG(bool, keep_code, false, |
43 "Keep deoptimized code for profiling."); | 43 "Keep deoptimized code for profiling."); |
44 DEFINE_FLAG(bool, shutdown, true, "Do a clean shutdown of the VM"); | 44 DEFINE_FLAG(bool, shutdown, true, "Do a clean shutdown of the VM"); |
45 | 45 |
46 Isolate* Dart::vm_isolate_ = NULL; | 46 Isolate* Dart::vm_isolate_ = NULL; |
47 ThreadPool* Dart::thread_pool_ = NULL; | 47 ThreadPool* Dart::thread_pool_ = NULL; |
48 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 48 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
49 ReadOnlyHandles* Dart::predefined_handles_ = NULL; | 49 ReadOnlyHandles* Dart::predefined_handles_ = NULL; |
50 const uint8_t* Dart::instructions_snapshot_buffer_ = NULL; | 50 const uint8_t* Dart::instructions_snapshot_buffer_ = NULL; |
| 51 const uint8_t* Dart::data_snapshot_buffer_ = NULL; |
51 | 52 |
52 // Structure for managing read-only global handles allocation used for | 53 // Structure for managing read-only global handles allocation used for |
53 // creating global read-only handles that are pre created and initialized | 54 // creating global read-only handles that are pre created and initialized |
54 // for use across all isolates. Having these global pre created handles | 55 // for use across all isolates. Having these global pre created handles |
55 // stored in the vm isolate ensures that we don't constantly create and | 56 // stored in the vm isolate ensures that we don't constantly create and |
56 // destroy handles for read-only objects referred in the VM code | 57 // destroy handles for read-only objects referred in the VM code |
57 // (e.g: symbols, null object, empty array etc.) | 58 // (e.g: symbols, null object, empty array etc.) |
58 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is | 59 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is |
59 // to ensure that the handles area is not trashed by automatic running of C++ | 60 // to ensure that the handles area is not trashed by automatic running of C++ |
60 // static destructors when 'exit()" is called by any isolate. There might be | 61 // static destructors when 'exit()" is called by any isolate. There might be |
61 // other isolates running at the same time and trashing the handles area will | 62 // other isolates running at the same time and trashing the handles area will |
62 // have unintended consequences. | 63 // have unintended consequences. |
63 class ReadOnlyHandles { | 64 class ReadOnlyHandles { |
64 public: | 65 public: |
65 ReadOnlyHandles() { } | 66 ReadOnlyHandles() { } |
66 | 67 |
67 private: | 68 private: |
68 VMHandles handles_; | 69 VMHandles handles_; |
69 LocalHandles api_handles_; | 70 LocalHandles api_handles_; |
70 | 71 |
71 friend class Dart; | 72 friend class Dart; |
72 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); | 73 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); |
73 }; | 74 }; |
74 | 75 |
75 | 76 |
76 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, | 77 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, |
77 const uint8_t* instructions_snapshot, | 78 const uint8_t* instructions_snapshot, |
| 79 const uint8_t* data_snapshot, |
78 Dart_IsolateCreateCallback create, | 80 Dart_IsolateCreateCallback create, |
79 Dart_IsolateShutdownCallback shutdown, | 81 Dart_IsolateShutdownCallback shutdown, |
80 Dart_FileOpenCallback file_open, | 82 Dart_FileOpenCallback file_open, |
81 Dart_FileReadCallback file_read, | 83 Dart_FileReadCallback file_read, |
82 Dart_FileWriteCallback file_write, | 84 Dart_FileWriteCallback file_write, |
83 Dart_FileCloseCallback file_close, | 85 Dart_FileCloseCallback file_close, |
84 Dart_EntropySource entropy_source, | 86 Dart_EntropySource entropy_source, |
85 Dart_GetVMServiceAssetsArchive get_service_assets) { | 87 Dart_GetVMServiceAssetsArchive get_service_assets) { |
86 // TODO(iposva): Fix race condition here. | 88 // TODO(iposva): Fix race condition here. |
87 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 89 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 Object::InitOnce(vm_isolate_); | 150 Object::InitOnce(vm_isolate_); |
149 ArgumentsDescriptor::InitOnce(); | 151 ArgumentsDescriptor::InitOnce(); |
150 ICData::InitOnce(); | 152 ICData::InitOnce(); |
151 // When precompiled the stub code is initialized from the snapshot. | 153 // When precompiled the stub code is initialized from the snapshot. |
152 if (!precompiled) { | 154 if (!precompiled) { |
153 StubCode::InitOnce(); | 155 StubCode::InitOnce(); |
154 } | 156 } |
155 if (vm_isolate_snapshot != NULL) { | 157 if (vm_isolate_snapshot != NULL) { |
156 if (instructions_snapshot != NULL) { | 158 if (instructions_snapshot != NULL) { |
157 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); | 159 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); |
| 160 ASSERT(data_snapshot != NULL); |
| 161 vm_isolate_->SetupDataSnapshotPage(data_snapshot); |
158 } | 162 } |
159 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); | 163 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); |
160 if (snapshot == NULL) { | 164 if (snapshot == NULL) { |
161 return "Invalid vm isolate snapshot seen."; | 165 return "Invalid vm isolate snapshot seen."; |
162 } | 166 } |
163 ASSERT(snapshot->kind() == Snapshot::kFull); | 167 ASSERT(snapshot->kind() == Snapshot::kFull); |
164 VmIsolateSnapshotReader reader(snapshot->content(), | 168 VmIsolateSnapshotReader reader(snapshot->content(), |
165 snapshot->length(), | 169 snapshot->length(), |
166 instructions_snapshot, | 170 instructions_snapshot, |
| 171 data_snapshot, |
167 T); | 172 T); |
168 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); | 173 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); |
169 if (!error.IsNull()) { | 174 if (!error.IsNull()) { |
170 return error.ToCString(); | 175 return error.ToCString(); |
171 } | 176 } |
172 if (FLAG_trace_isolates) { | 177 if (FLAG_trace_isolates) { |
173 OS::Print("Size of vm isolate snapshot = %" Pd "\n", | 178 OS::Print("Size of vm isolate snapshot = %" Pd "\n", |
174 snapshot->length()); | 179 snapshot->length()); |
175 vm_isolate_->heap()->PrintSizes(); | 180 vm_isolate_->heap()->PrintSizes(); |
176 MegamorphicCacheTable::PrintSizes(vm_isolate_); | 181 MegamorphicCacheTable::PrintSizes(vm_isolate_); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 String::New("Invalid snapshot.")); | 358 String::New("Invalid snapshot.")); |
354 return ApiError::New(message); | 359 return ApiError::New(message); |
355 } | 360 } |
356 ASSERT(snapshot->kind() == Snapshot::kFull); | 361 ASSERT(snapshot->kind() == Snapshot::kFull); |
357 if (FLAG_trace_isolates) { | 362 if (FLAG_trace_isolates) { |
358 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); | 363 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); |
359 } | 364 } |
360 IsolateSnapshotReader reader(snapshot->content(), | 365 IsolateSnapshotReader reader(snapshot->content(), |
361 snapshot->length(), | 366 snapshot->length(), |
362 Dart::instructions_snapshot_buffer(), | 367 Dart::instructions_snapshot_buffer(), |
| 368 Dart::data_snapshot_buffer(), |
363 T); | 369 T); |
364 const Error& error = Error::Handle(reader.ReadFullSnapshot()); | 370 const Error& error = Error::Handle(reader.ReadFullSnapshot()); |
365 if (!error.IsNull()) { | 371 if (!error.IsNull()) { |
366 return error.raw(); | 372 return error.raw(); |
367 } | 373 } |
368 if (FLAG_trace_isolates) { | 374 if (FLAG_trace_isolates) { |
369 I->heap()->PrintSizes(); | 375 I->heap()->PrintSizes(); |
370 MegamorphicCacheTable::PrintSizes(I); | 376 MegamorphicCacheTable::PrintSizes(I); |
371 } | 377 } |
372 } else { | 378 } else { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 return predefined_handles_->handles_.IsValidScopedHandle(address); | 491 return predefined_handles_->handles_.IsValidScopedHandle(address); |
486 } | 492 } |
487 | 493 |
488 | 494 |
489 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 495 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
490 ASSERT(predefined_handles_ != NULL); | 496 ASSERT(predefined_handles_ != NULL); |
491 return predefined_handles_->api_handles_.IsValidHandle(handle); | 497 return predefined_handles_->api_handles_.IsValidHandle(handle); |
492 } | 498 } |
493 | 499 |
494 } // namespace dart | 500 } // namespace dart |
OLD | NEW |