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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 DEFINE_FLAG(bool, trace_shutdown, false, "Trace VM shutdown on stderr"); | 45 DEFINE_FLAG(bool, trace_shutdown, false, "Trace VM shutdown on stderr"); |
46 | 46 |
47 Isolate* Dart::vm_isolate_ = NULL; | 47 Isolate* Dart::vm_isolate_ = NULL; |
48 int64_t Dart::start_time_ = 0; | 48 int64_t Dart::start_time_ = 0; |
49 ThreadPool* Dart::thread_pool_ = NULL; | 49 ThreadPool* Dart::thread_pool_ = NULL; |
50 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 50 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
51 ReadOnlyHandles* Dart::predefined_handles_ = NULL; | 51 ReadOnlyHandles* Dart::predefined_handles_ = NULL; |
52 const uint8_t* Dart::instructions_snapshot_buffer_ = NULL; | 52 const uint8_t* Dart::instructions_snapshot_buffer_ = NULL; |
| 53 const uint8_t* Dart::data_snapshot_buffer_ = NULL; |
53 | 54 |
54 // Structure for managing read-only global handles allocation used for | 55 // Structure for managing read-only global handles allocation used for |
55 // creating global read-only handles that are pre created and initialized | 56 // creating global read-only handles that are pre created and initialized |
56 // for use across all isolates. Having these global pre created handles | 57 // for use across all isolates. Having these global pre created handles |
57 // stored in the vm isolate ensures that we don't constantly create and | 58 // stored in the vm isolate ensures that we don't constantly create and |
58 // destroy handles for read-only objects referred in the VM code | 59 // destroy handles for read-only objects referred in the VM code |
59 // (e.g: symbols, null object, empty array etc.) | 60 // (e.g: symbols, null object, empty array etc.) |
60 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is | 61 // The ReadOnlyHandles C++ Wrapper around VMHandles which is a ValueObject is |
61 // to ensure that the handles area is not trashed by automatic running of C++ | 62 // to ensure that the handles area is not trashed by automatic running of C++ |
62 // static destructors when 'exit()" is called by any isolate. There might be | 63 // static destructors when 'exit()" is called by any isolate. There might be |
63 // other isolates running at the same time and trashing the handles area will | 64 // other isolates running at the same time and trashing the handles area will |
64 // have unintended consequences. | 65 // have unintended consequences. |
65 class ReadOnlyHandles { | 66 class ReadOnlyHandles { |
66 public: | 67 public: |
67 ReadOnlyHandles() { } | 68 ReadOnlyHandles() { } |
68 | 69 |
69 private: | 70 private: |
70 VMHandles handles_; | 71 VMHandles handles_; |
71 LocalHandles api_handles_; | 72 LocalHandles api_handles_; |
72 | 73 |
73 friend class Dart; | 74 friend class Dart; |
74 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); | 75 DISALLOW_COPY_AND_ASSIGN(ReadOnlyHandles); |
75 }; | 76 }; |
76 | 77 |
77 | 78 |
78 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, | 79 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, |
79 const uint8_t* instructions_snapshot, | 80 const uint8_t* instructions_snapshot, |
| 81 const uint8_t* data_snapshot, |
80 Dart_IsolateCreateCallback create, | 82 Dart_IsolateCreateCallback create, |
81 Dart_IsolateShutdownCallback shutdown, | 83 Dart_IsolateShutdownCallback shutdown, |
82 Dart_FileOpenCallback file_open, | 84 Dart_FileOpenCallback file_open, |
83 Dart_FileReadCallback file_read, | 85 Dart_FileReadCallback file_read, |
84 Dart_FileWriteCallback file_write, | 86 Dart_FileWriteCallback file_write, |
85 Dart_FileCloseCallback file_close, | 87 Dart_FileCloseCallback file_close, |
86 Dart_EntropySource entropy_source, | 88 Dart_EntropySource entropy_source, |
87 Dart_GetVMServiceAssetsArchive get_service_assets) { | 89 Dart_GetVMServiceAssetsArchive get_service_assets) { |
88 // TODO(iposva): Fix race condition here. | 90 // TODO(iposva): Fix race condition here. |
89 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 91 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 Object::InitOnce(vm_isolate_); | 153 Object::InitOnce(vm_isolate_); |
152 ArgumentsDescriptor::InitOnce(); | 154 ArgumentsDescriptor::InitOnce(); |
153 ICData::InitOnce(); | 155 ICData::InitOnce(); |
154 // When precompiled the stub code is initialized from the snapshot. | 156 // When precompiled the stub code is initialized from the snapshot. |
155 if (!precompiled) { | 157 if (!precompiled) { |
156 StubCode::InitOnce(); | 158 StubCode::InitOnce(); |
157 } | 159 } |
158 if (vm_isolate_snapshot != NULL) { | 160 if (vm_isolate_snapshot != NULL) { |
159 if (instructions_snapshot != NULL) { | 161 if (instructions_snapshot != NULL) { |
160 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); | 162 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); |
| 163 ASSERT(data_snapshot != NULL); |
| 164 vm_isolate_->SetupDataSnapshotPage(data_snapshot); |
161 } | 165 } |
162 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); | 166 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); |
163 if (snapshot == NULL) { | 167 if (snapshot == NULL) { |
164 return "Invalid vm isolate snapshot seen."; | 168 return "Invalid vm isolate snapshot seen."; |
165 } | 169 } |
166 ASSERT(snapshot->kind() == Snapshot::kFull); | 170 ASSERT(snapshot->kind() == Snapshot::kFull); |
167 VmIsolateSnapshotReader reader(snapshot->content(), | 171 VmIsolateSnapshotReader reader(snapshot->content(), |
168 snapshot->length(), | 172 snapshot->length(), |
169 instructions_snapshot, | 173 instructions_snapshot, |
| 174 data_snapshot, |
170 T); | 175 T); |
171 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); | 176 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); |
172 if (!error.IsNull()) { | 177 if (!error.IsNull()) { |
173 return error.ToCString(); | 178 return error.ToCString(); |
174 } | 179 } |
175 if (FLAG_trace_isolates) { | 180 if (FLAG_trace_isolates) { |
176 OS::Print("Size of vm isolate snapshot = %" Pd "\n", | 181 OS::Print("Size of vm isolate snapshot = %" Pd "\n", |
177 snapshot->length()); | 182 snapshot->length()); |
178 vm_isolate_->heap()->PrintSizes(); | 183 vm_isolate_->heap()->PrintSizes(); |
179 MegamorphicCacheTable::PrintSizes(vm_isolate_); | 184 MegamorphicCacheTable::PrintSizes(vm_isolate_); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 String::New("Invalid snapshot.")); | 425 String::New("Invalid snapshot.")); |
421 return ApiError::New(message); | 426 return ApiError::New(message); |
422 } | 427 } |
423 ASSERT(snapshot->kind() == Snapshot::kFull); | 428 ASSERT(snapshot->kind() == Snapshot::kFull); |
424 if (FLAG_trace_isolates) { | 429 if (FLAG_trace_isolates) { |
425 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); | 430 OS::Print("Size of isolate snapshot = %" Pd "\n", snapshot->length()); |
426 } | 431 } |
427 IsolateSnapshotReader reader(snapshot->content(), | 432 IsolateSnapshotReader reader(snapshot->content(), |
428 snapshot->length(), | 433 snapshot->length(), |
429 Dart::instructions_snapshot_buffer(), | 434 Dart::instructions_snapshot_buffer(), |
| 435 Dart::data_snapshot_buffer(), |
430 T); | 436 T); |
431 const Error& error = Error::Handle(reader.ReadFullSnapshot()); | 437 const Error& error = Error::Handle(reader.ReadFullSnapshot()); |
432 if (!error.IsNull()) { | 438 if (!error.IsNull()) { |
433 return error.raw(); | 439 return error.raw(); |
434 } | 440 } |
435 if (FLAG_trace_isolates) { | 441 if (FLAG_trace_isolates) { |
436 I->heap()->PrintSizes(); | 442 I->heap()->PrintSizes(); |
437 MegamorphicCacheTable::PrintSizes(I); | 443 MegamorphicCacheTable::PrintSizes(I); |
438 } | 444 } |
439 } else { | 445 } else { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 return predefined_handles_->handles_.IsValidScopedHandle(address); | 564 return predefined_handles_->handles_.IsValidScopedHandle(address); |
559 } | 565 } |
560 | 566 |
561 | 567 |
562 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 568 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
563 ASSERT(predefined_handles_ != NULL); | 569 ASSERT(predefined_handles_ != NULL); |
564 return predefined_handles_->api_handles_.IsValidHandle(handle); | 570 return predefined_handles_->api_handles_.IsValidHandle(handle); |
565 } | 571 } |
566 | 572 |
567 } // namespace dart | 573 } // namespace dart |
OLD | NEW |