| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // (compiler) and arm64 (runtime) to agree. | 108 // (compiler) and arm64 (runtime) to agree. |
| 109 CHECK_OFFSET(Heap::TopOffset(Heap::kNew), 8); | 109 CHECK_OFFSET(Heap::TopOffset(Heap::kNew), 8); |
| 110 CHECK_OFFSET(Isolate::heap_offset(), 16); | 110 CHECK_OFFSET(Isolate::heap_offset(), 16); |
| 111 CHECK_OFFSET(Thread::stack_limit_offset(), 8); | 111 CHECK_OFFSET(Thread::stack_limit_offset(), 8); |
| 112 CHECK_OFFSET(Thread::object_null_offset(), 72); | 112 CHECK_OFFSET(Thread::object_null_offset(), 72); |
| 113 #endif | 113 #endif |
| 114 #undef CHECK_OFFSET | 114 #undef CHECK_OFFSET |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 const char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, | 118 char* Dart::InitOnce(const uint8_t* vm_isolate_snapshot, |
| 119 const uint8_t* instructions_snapshot, | 119 const uint8_t* instructions_snapshot, |
| 120 const uint8_t* data_snapshot, | 120 const uint8_t* data_snapshot, |
| 121 Dart_IsolateCreateCallback create, | 121 Dart_IsolateCreateCallback create, |
| 122 Dart_IsolateShutdownCallback shutdown, | 122 Dart_IsolateShutdownCallback shutdown, |
| 123 Dart_ThreadExitCallback thread_exit, | 123 Dart_ThreadExitCallback thread_exit, |
| 124 Dart_FileOpenCallback file_open, | 124 Dart_FileOpenCallback file_open, |
| 125 Dart_FileReadCallback file_read, | 125 Dart_FileReadCallback file_read, |
| 126 Dart_FileWriteCallback file_write, | 126 Dart_FileWriteCallback file_write, |
| 127 Dart_FileCloseCallback file_close, | 127 Dart_FileCloseCallback file_close, |
| 128 Dart_EntropySource entropy_source, | 128 Dart_EntropySource entropy_source, |
| 129 Dart_GetVMServiceAssetsArchive get_service_assets) { | 129 Dart_GetVMServiceAssetsArchive get_service_assets) { |
| 130 CheckOffsets(); | 130 CheckOffsets(); |
| 131 // TODO(iposva): Fix race condition here. | 131 // TODO(iposva): Fix race condition here. |
| 132 if (vm_isolate_ != NULL || !Flags::Initialized()) { | 132 if (vm_isolate_ != NULL || !Flags::Initialized()) { |
| 133 return "VM already initialized or flags not initialized."; | 133 return strdup("VM already initialized or flags not initialized."); |
| 134 } | 134 } |
| 135 set_thread_exit_callback(thread_exit); | 135 set_thread_exit_callback(thread_exit); |
| 136 SetFileCallbacks(file_open, file_read, file_write, file_close); | 136 SetFileCallbacks(file_open, file_read, file_write, file_close); |
| 137 set_entropy_source_callback(entropy_source); | 137 set_entropy_source_callback(entropy_source); |
| 138 OS::InitOnce(); | 138 OS::InitOnce(); |
| 139 VirtualMemory::InitOnce(); | 139 VirtualMemory::InitOnce(); |
| 140 OSThread::InitOnce(); | 140 OSThread::InitOnce(); |
| 141 if (FLAG_support_timeline) { | 141 if (FLAG_support_timeline) { |
| 142 Timeline::InitOnce(); | 142 Timeline::InitOnce(); |
| 143 } | 143 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 ObjectStore::Init(vm_isolate_); | 188 ObjectStore::Init(vm_isolate_); |
| 189 TargetCPUFeatures::InitOnce(); | 189 TargetCPUFeatures::InitOnce(); |
| 190 Object::InitOnce(vm_isolate_); | 190 Object::InitOnce(vm_isolate_); |
| 191 ArgumentsDescriptor::InitOnce(); | 191 ArgumentsDescriptor::InitOnce(); |
| 192 ICData::InitOnce(); | 192 ICData::InitOnce(); |
| 193 if (vm_isolate_snapshot != NULL) { | 193 if (vm_isolate_snapshot != NULL) { |
| 194 NOT_IN_PRODUCT(TimelineDurationScope tds(Timeline::GetVMStream(), | 194 NOT_IN_PRODUCT(TimelineDurationScope tds(Timeline::GetVMStream(), |
| 195 "VMIsolateSnapshot")); | 195 "VMIsolateSnapshot")); |
| 196 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); | 196 const Snapshot* snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot); |
| 197 if (snapshot == NULL) { | 197 if (snapshot == NULL) { |
| 198 return "Invalid vm isolate snapshot seen"; | 198 return strdup("Invalid vm isolate snapshot seen"); |
| 199 } | 199 } |
| 200 snapshot_kind_ = snapshot->kind(); | 200 snapshot_kind_ = snapshot->kind(); |
| 201 |
| 201 if (Snapshot::IncludesCode(snapshot_kind_)) { | 202 if (Snapshot::IncludesCode(snapshot_kind_)) { |
| 202 if (snapshot_kind_ == Snapshot::kAppNoJIT) { | 203 if (snapshot_kind_ == Snapshot::kAppNoJIT) { |
| 203 #if defined(DART_PRECOMPILED_RUNTIME) | 204 #if defined(DART_PRECOMPILED_RUNTIME) |
| 204 vm_isolate_->set_compilation_allowed(false); | 205 vm_isolate_->set_compilation_allowed(false); |
| 205 if (!FLAG_precompiled_runtime) { | 206 if (!FLAG_precompiled_runtime) { |
| 206 return "Flag --precompilation was not specified"; | 207 return strdup("Flag --precompilation was not specified"); |
| 207 } | 208 } |
| 208 #else | 209 #else |
| 209 return "JIT runtime cannot run a precompiled snapshot"; | 210 return strdup("JIT runtime cannot run a precompiled snapshot"); |
| 210 #endif | 211 #endif |
| 211 } | 212 } |
| 212 if (instructions_snapshot == NULL) { | 213 if (instructions_snapshot == NULL) { |
| 213 return "Missing instructions snapshot"; | 214 return strdup("Missing instructions snapshot"); |
| 214 } | 215 } |
| 215 if (data_snapshot == NULL) { | 216 if (data_snapshot == NULL) { |
| 216 return "Missing rodata snapshot"; | 217 return strdup("Missing rodata snapshot"); |
| 217 } | 218 } |
| 218 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); | 219 vm_isolate_->SetupInstructionsSnapshotPage(instructions_snapshot); |
| 219 vm_isolate_->SetupDataSnapshotPage(data_snapshot); | 220 vm_isolate_->SetupDataSnapshotPage(data_snapshot); |
| 220 } else if (Snapshot::IsFull(snapshot_kind_)) { | 221 } else if (Snapshot::IsFull(snapshot_kind_)) { |
| 221 #if defined(DART_PRECOMPILED_RUNTIME) | 222 #if defined(DART_PRECOMPILED_RUNTIME) |
| 222 return "Precompiled runtime requires a precompiled snapshot"; | 223 return strdup("Precompiled runtime requires a precompiled snapshot"); |
| 223 #else | 224 #else |
| 224 if (instructions_snapshot != NULL) { | 225 if (instructions_snapshot != NULL) { |
| 225 return "Unexpected instructions snapshot"; | 226 return strdup("Unexpected instructions snapshot"); |
| 226 } | 227 } |
| 227 if (data_snapshot != NULL) { | 228 if (data_snapshot != NULL) { |
| 228 return "Unexpected rodata snapshot"; | 229 return strdup("Unexpected rodata snapshot"); |
| 229 } | 230 } |
| 230 StubCode::InitOnce(); | 231 StubCode::InitOnce(); |
| 231 #endif | 232 #endif |
| 232 } else { | 233 } else { |
| 233 return "Invalid vm isolate snapshot seen"; | 234 return strdup("Invalid vm isolate snapshot seen"); |
| 234 } | 235 } |
| 235 VmIsolateSnapshotReader reader(snapshot->kind(), | 236 VmIsolateSnapshotReader reader(snapshot->kind(), |
| 236 snapshot->content(), | 237 snapshot->content(), |
| 237 snapshot->length(), | 238 snapshot->length(), |
| 238 instructions_snapshot, | 239 instructions_snapshot, |
| 239 data_snapshot, | 240 data_snapshot, |
| 240 T); | 241 T); |
| 241 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); | 242 const Error& error = Error::Handle(reader.ReadVmIsolateSnapshot()); |
| 242 if (!error.IsNull()) { | 243 if (!error.IsNull()) { |
| 243 return error.ToErrorCString(); | 244 // Must copy before leaving the zone. |
| 245 return strdup(error.ToErrorCString()); |
| 244 } | 246 } |
| 245 NOT_IN_PRODUCT(if (tds.enabled()) { | 247 NOT_IN_PRODUCT(if (tds.enabled()) { |
| 246 tds.SetNumArguments(2); | 248 tds.SetNumArguments(2); |
| 247 tds.FormatArgument(0, "snapshotSize", "%" Pd, snapshot->length()); | 249 tds.FormatArgument(0, "snapshotSize", "%" Pd, snapshot->length()); |
| 248 tds.FormatArgument(1, "heapSize", "%" Pd64, | 250 tds.FormatArgument(1, "heapSize", "%" Pd64, |
| 249 vm_isolate_->heap()->UsedInWords(Heap::kOld) * | 251 vm_isolate_->heap()->UsedInWords(Heap::kOld) * |
| 250 kWordSize); | 252 kWordSize); |
| 251 }); | 253 }); |
| 252 if (FLAG_trace_isolates) { | 254 if (FLAG_trace_isolates) { |
| 253 OS::Print("Size of vm isolate snapshot = %" Pd "\n", | 255 OS::Print("Size of vm isolate snapshot = %" Pd "\n", |
| 254 snapshot->length()); | 256 snapshot->length()); |
| 255 vm_isolate_->heap()->PrintSizes(); | 257 vm_isolate_->heap()->PrintSizes(); |
| 256 MegamorphicCacheTable::PrintSizes(vm_isolate_); | 258 MegamorphicCacheTable::PrintSizes(vm_isolate_); |
| 257 intptr_t size; | 259 intptr_t size; |
| 258 intptr_t capacity; | 260 intptr_t capacity; |
| 259 Symbols::GetStats(vm_isolate_, &size, &capacity); | 261 Symbols::GetStats(vm_isolate_, &size, &capacity); |
| 260 OS::Print("VM Isolate: Number of symbols : %" Pd "\n", size); | 262 OS::Print("VM Isolate: Number of symbols : %" Pd "\n", size); |
| 261 OS::Print("VM Isolate: Symbol table capacity : %" Pd "\n", capacity); | 263 OS::Print("VM Isolate: Symbol table capacity : %" Pd "\n", capacity); |
| 262 } | 264 } |
| 263 } else { | 265 } else { |
| 264 #if defined(DART_PRECOMPILED_RUNTIME) | 266 #if defined(DART_PRECOMPILED_RUNTIME) |
| 265 return "Precompiled runtime requires a precompiled snapshot"; | 267 return strdup("Precompiled runtime requires a precompiled snapshot"); |
| 266 #else | 268 #else |
| 267 snapshot_kind_ = Snapshot::kNone; | 269 snapshot_kind_ = Snapshot::kNone; |
| 268 StubCode::InitOnce(); | 270 StubCode::InitOnce(); |
| 269 Symbols::InitOnce(vm_isolate_); | 271 Symbols::InitOnce(vm_isolate_); |
| 270 #endif | 272 #endif |
| 271 } | 273 } |
| 272 // We need to initialize the constants here for the vm isolate thread due to | 274 // We need to initialize the constants here for the vm isolate thread due to |
| 273 // bootstrapping issues. | 275 // bootstrapping issues. |
| 274 T->InitVMConstants(); | 276 T->InitVMConstants(); |
| 275 Scanner::InitOnce(); | 277 Scanner::InitOnce(); |
| 276 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 278 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 277 // Dart VM requires at least SSE2. | 279 // Dart VM requires at least SSE2. |
| 278 if (!TargetCPUFeatures::sse2_supported()) { | 280 if (!TargetCPUFeatures::sse2_supported()) { |
| 279 return "SSE2 is required."; | 281 return strdup("SSE2 is required."); |
| 280 } | 282 } |
| 281 #endif | 283 #endif |
| 282 { | 284 { |
| 283 NOT_IN_PRODUCT(TimelineDurationScope tds(Timeline::GetVMStream(), | 285 NOT_IN_PRODUCT(TimelineDurationScope tds(Timeline::GetVMStream(), |
| 284 "FinalizeVMIsolate")); | 286 "FinalizeVMIsolate")); |
| 285 Object::FinalizeVMIsolate(vm_isolate_); | 287 Object::FinalizeVMIsolate(vm_isolate_); |
| 286 } | 288 } |
| 287 #if defined(DEBUG) | 289 #if defined(DEBUG) |
| 288 vm_isolate_->heap()->Verify(kRequireMarked); | 290 vm_isolate_->heap()->Verify(kRequireMarked); |
| 289 #endif | 291 #endif |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 I->set_current_tag(default_tag); | 590 I->set_current_tag(default_tag); |
| 589 | 591 |
| 590 if (FLAG_keep_code) { | 592 if (FLAG_keep_code) { |
| 591 I->set_deoptimized_code_array( | 593 I->set_deoptimized_code_array( |
| 592 GrowableObjectArray::Handle(GrowableObjectArray::New())); | 594 GrowableObjectArray::Handle(GrowableObjectArray::New())); |
| 593 } | 595 } |
| 594 return Error::null(); | 596 return Error::null(); |
| 595 } | 597 } |
| 596 | 598 |
| 597 | 599 |
| 600 const char* Dart::FeaturesString(Snapshot::Kind kind) { |
| 601 TextBuffer buffer(64); |
| 602 |
| 603 // Different fields are included for DEBUG/RELEASE/PRODUCT. |
| 604 #if defined(DEBUG) |
| 605 buffer.AddString("debug"); |
| 606 #elif defined(PRODUCT) |
| 607 buffer.AddString("product"); |
| 608 #else |
| 609 buffer.AddString("release"); |
| 610 #endif |
| 611 |
| 612 if (Snapshot::IncludesCode(kind)) { |
| 613 // Checked mode affects deopt ids. |
| 614 buffer.AddString(FLAG_enable_asserts ? " asserts" : " no-asserts"); |
| 615 buffer.AddString(FLAG_enable_type_checks ? " type-checks" |
| 616 : " no-type-checks"); |
| 617 |
| 618 // Generated code must match the host architecture and ABI. |
| 619 #if defined(TARGET_ARCH_ARM) |
| 620 #if defined(TARGET_OS_MACOS) |
| 621 buffer.AddString(" arm-ios"); |
| 622 #else |
| 623 buffer.AddString(" arm-eabi"); |
| 624 #endif |
| 625 buffer.AddString(TargetCPUFeatures::hardfp_supported() ? " hardfp" |
| 626 : " softfp"); |
| 627 #elif defined(TARGET_ARCH_ARM64) |
| 628 buffer.AddString(" arm64"); |
| 629 #elif defined(TARGET_ARCH_MIPS) |
| 630 buffer.AddString(" mips"); |
| 631 #elif defined(TARGET_ARCH_IA32) |
| 632 buffer.AddString(" ia32"); |
| 633 #elif defined(TARGET_ARCH_X64) |
| 634 #if defined(_WIN64) |
| 635 buffer.AddString(" x64-win"); |
| 636 #else |
| 637 buffer.AddString(" x64-sysv"); |
| 638 #endif |
| 639 #elif defined(TARGET_ARCH_DBC) |
| 640 buffer.AddString(" dbc"); |
| 641 #elif defined(TARGET_ARCH_DBC64) |
| 642 buffer.AddString(" dbc64"); |
| 643 #endif |
| 644 } |
| 645 |
| 646 return buffer.Steal(); |
| 647 } |
| 648 |
| 649 |
| 598 void Dart::RunShutdownCallback() { | 650 void Dart::RunShutdownCallback() { |
| 599 Isolate* isolate = Isolate::Current(); | 651 Isolate* isolate = Isolate::Current(); |
| 600 void* callback_data = isolate->init_callback_data(); | 652 void* callback_data = isolate->init_callback_data(); |
| 601 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); | 653 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback(); |
| 602 ServiceIsolate::SendIsolateShutdownMessage(); | 654 ServiceIsolate::SendIsolateShutdownMessage(); |
| 603 if (callback != NULL) { | 655 if (callback != NULL) { |
| 604 (callback)(callback_data); | 656 (callback)(callback_data); |
| 605 } | 657 } |
| 606 } | 658 } |
| 607 | 659 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 return predefined_handles_->handles_.IsValidScopedHandle(address); | 702 return predefined_handles_->handles_.IsValidScopedHandle(address); |
| 651 } | 703 } |
| 652 | 704 |
| 653 | 705 |
| 654 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { | 706 bool Dart::IsReadOnlyApiHandle(Dart_Handle handle) { |
| 655 ASSERT(predefined_handles_ != NULL); | 707 ASSERT(predefined_handles_ != NULL); |
| 656 return predefined_handles_->api_handles_.IsValidHandle(handle); | 708 return predefined_handles_->api_handles_.IsValidHandle(handle); |
| 657 } | 709 } |
| 658 | 710 |
| 659 } // namespace dart | 711 } // namespace dart |
| OLD | NEW |