| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
| (...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 DARTSCOPE(Thread::Current()); | 1572 DARTSCOPE(Thread::Current()); |
| 1573 API_TIMELINE_DURATION; | 1573 API_TIMELINE_DURATION; |
| 1574 Isolate* I = T->isolate(); | 1574 Isolate* I = T->isolate(); |
| 1575 if (!FLAG_load_deferred_eagerly) { | 1575 if (!FLAG_load_deferred_eagerly) { |
| 1576 return Api::NewError( | 1576 return Api::NewError( |
| 1577 "Creating full snapshots requires --load_deferred_eagerly"); | 1577 "Creating full snapshots requires --load_deferred_eagerly"); |
| 1578 } | 1578 } |
| 1579 if (vm_snapshot_data_buffer != NULL && vm_snapshot_data_size == NULL) { | 1579 if (vm_snapshot_data_buffer != NULL && vm_snapshot_data_size == NULL) { |
| 1580 RETURN_NULL_ERROR(vm_snapshot_data_size); | 1580 RETURN_NULL_ERROR(vm_snapshot_data_size); |
| 1581 } | 1581 } |
| 1582 if (isolate_snapshot_data_buffer == NULL) { | 1582 CHECK_NULL(isolate_snapshot_data_buffer); |
| 1583 RETURN_NULL_ERROR(isolate_snapshot_data_buffer); | 1583 CHECK_NULL(isolate_snapshot_data_size); |
| 1584 } | |
| 1585 if (isolate_snapshot_data_size == NULL) { | |
| 1586 RETURN_NULL_ERROR(isolate_snapshot_data_size); | |
| 1587 } | |
| 1588 // Finalize all classes if needed. | 1584 // Finalize all classes if needed. |
| 1589 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 1585 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 1590 if (::Dart_IsError(state)) { | 1586 if (::Dart_IsError(state)) { |
| 1591 return state; | 1587 return state; |
| 1592 } | 1588 } |
| 1593 I->StopBackgroundCompiler(); | 1589 I->StopBackgroundCompiler(); |
| 1594 | 1590 |
| 1595 #if defined(DEBUG) | 1591 #if defined(DEBUG) |
| 1596 I->heap()->CollectAllGarbage(); | 1592 I->heap()->CollectAllGarbage(); |
| 1597 CheckFunctionTypesVisitor check_canonical(T); | 1593 CheckFunctionTypesVisitor check_canonical(T); |
| 1598 I->heap()->IterateObjects(&check_canonical); | 1594 I->heap()->IterateObjects(&check_canonical); |
| 1599 #endif // #if defined(DEBUG) | 1595 #endif // #if defined(DEBUG) |
| 1600 | 1596 |
| 1601 Symbols::Compact(I); | 1597 Symbols::Compact(I); |
| 1602 | 1598 |
| 1603 FullSnapshotWriter writer(Snapshot::kCore, vm_snapshot_data_buffer, | 1599 FullSnapshotWriter writer(Snapshot::kFull, vm_snapshot_data_buffer, |
| 1604 isolate_snapshot_data_buffer, ApiReallocate, | 1600 isolate_snapshot_data_buffer, ApiReallocate, |
| 1605 NULL /* vm_image_writer */, | 1601 NULL /* vm_image_writer */, |
| 1606 NULL /* isolate_image_writer */); | 1602 NULL /* isolate_image_writer */); |
| 1607 writer.WriteFullSnapshot(); | 1603 writer.WriteFullSnapshot(); |
| 1608 if (vm_snapshot_data_buffer != NULL) { | 1604 if (vm_snapshot_data_buffer != NULL) { |
| 1609 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); | 1605 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
| 1610 } | 1606 } |
| 1611 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 1607 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 1612 return Api::Success(); | 1608 return Api::Success(); |
| 1613 } | 1609 } |
| 1614 | 1610 |
| 1615 | 1611 |
| 1616 DART_EXPORT Dart_Handle | 1612 DART_EXPORT Dart_Handle |
| 1617 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer, | 1613 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer, |
| 1618 intptr_t* script_snapshot_size) { | 1614 intptr_t* script_snapshot_size) { |
| 1619 API_TIMELINE_DURATION; | 1615 API_TIMELINE_DURATION; |
| 1620 DARTSCOPE(Thread::Current()); | 1616 DARTSCOPE(Thread::Current()); |
| 1621 Isolate* I = T->isolate(); | 1617 Isolate* I = T->isolate(); |
| 1622 if (script_snapshot_buffer == NULL) { | 1618 CHECK_NULL(script_snapshot_buffer); |
| 1623 RETURN_NULL_ERROR(script_snapshot_buffer); | 1619 CHECK_NULL(script_snapshot_size); |
| 1624 } | |
| 1625 if (script_snapshot_size == NULL) { | |
| 1626 RETURN_NULL_ERROR(script_snapshot_size); | |
| 1627 } | |
| 1628 // Finalize all classes if needed. | 1620 // Finalize all classes if needed. |
| 1629 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 1621 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 1630 if (::Dart_IsError(state)) { | 1622 if (::Dart_IsError(state)) { |
| 1631 return state; | 1623 return state; |
| 1632 } | 1624 } |
| 1633 Library& lib = Library::Handle(Z, I->object_store()->root_library()); | 1625 Library& lib = Library::Handle(Z, I->object_store()->root_library()); |
| 1634 | 1626 |
| 1635 #if defined(DEBUG) | 1627 #if defined(DEBUG) |
| 1636 I->heap()->CollectAllGarbage(); | 1628 I->heap()->CollectAllGarbage(); |
| 1637 CheckFunctionTypesVisitor check_canonical(T); | 1629 CheckFunctionTypesVisitor check_canonical(T); |
| (...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3895 } | 3887 } |
| 3896 | 3888 |
| 3897 type_obj = redirect_type.raw(); | 3889 type_obj = redirect_type.raw(); |
| 3898 type_arguments = redirect_type.arguments(); | 3890 type_arguments = redirect_type.arguments(); |
| 3899 | 3891 |
| 3900 cls = type_obj.type_class(); | 3892 cls = type_obj.type_class(); |
| 3901 } | 3893 } |
| 3902 if (constructor.IsGenerativeConstructor()) { | 3894 if (constructor.IsGenerativeConstructor()) { |
| 3903 #if defined(DEBUG) | 3895 #if defined(DEBUG) |
| 3904 if (!cls.is_allocated() && | 3896 if (!cls.is_allocated() && |
| 3905 (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) { | 3897 (Dart::vm_snapshot_kind() == Snapshot::kFullAOT)) { |
| 3906 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3898 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 3907 } | 3899 } |
| 3908 #endif | 3900 #endif |
| 3909 // Create the new object. | 3901 // Create the new object. |
| 3910 new_object = Instance::New(cls); | 3902 new_object = Instance::New(cls); |
| 3911 } | 3903 } |
| 3912 | 3904 |
| 3913 // Create the argument list. | 3905 // Create the argument list. |
| 3914 intptr_t arg_index = 0; | 3906 intptr_t arg_index = 0; |
| 3915 int extra_args = 1; | 3907 int extra_args = 1; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3990 DARTSCOPE(Thread::Current()); | 3982 DARTSCOPE(Thread::Current()); |
| 3991 CHECK_CALLBACK_STATE(T); | 3983 CHECK_CALLBACK_STATE(T); |
| 3992 | 3984 |
| 3993 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3985 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 3994 // Get the class to instantiate. | 3986 // Get the class to instantiate. |
| 3995 if (type_obj.IsNull()) { | 3987 if (type_obj.IsNull()) { |
| 3996 RETURN_TYPE_ERROR(Z, type, Type); | 3988 RETURN_TYPE_ERROR(Z, type, Type); |
| 3997 } | 3989 } |
| 3998 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3990 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 3999 #if defined(DEBUG) | 3991 #if defined(DEBUG) |
| 4000 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) { | 3992 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kFullAOT)) { |
| 4001 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3993 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 4002 } | 3994 } |
| 4003 #endif | 3995 #endif |
| 4004 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3996 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 4005 if (!error.IsNull()) { | 3997 if (!error.IsNull()) { |
| 4006 // An error occurred, return error object. | 3998 // An error occurred, return error object. |
| 4007 return Api::NewHandle(T, error.raw()); | 3999 return Api::NewHandle(T, error.raw()); |
| 4008 } | 4000 } |
| 4009 return Api::NewHandle(T, AllocateObject(T, cls)); | 4001 return Api::NewHandle(T, AllocateObject(T, cls)); |
| 4010 } | 4002 } |
| 4011 | 4003 |
| 4012 | 4004 |
| 4013 DART_EXPORT Dart_Handle | 4005 DART_EXPORT Dart_Handle |
| 4014 Dart_AllocateWithNativeFields(Dart_Handle type, | 4006 Dart_AllocateWithNativeFields(Dart_Handle type, |
| 4015 intptr_t num_native_fields, | 4007 intptr_t num_native_fields, |
| 4016 const intptr_t* native_fields) { | 4008 const intptr_t* native_fields) { |
| 4017 DARTSCOPE(Thread::Current()); | 4009 DARTSCOPE(Thread::Current()); |
| 4018 CHECK_CALLBACK_STATE(T); | 4010 CHECK_CALLBACK_STATE(T); |
| 4019 | 4011 |
| 4020 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 4012 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 4021 // Get the class to instantiate. | 4013 // Get the class to instantiate. |
| 4022 if (type_obj.IsNull()) { | 4014 if (type_obj.IsNull()) { |
| 4023 RETURN_TYPE_ERROR(Z, type, Type); | 4015 RETURN_TYPE_ERROR(Z, type, Type); |
| 4024 } | 4016 } |
| 4025 if (native_fields == NULL) { | 4017 if (native_fields == NULL) { |
| 4026 RETURN_NULL_ERROR(native_fields); | 4018 RETURN_NULL_ERROR(native_fields); |
| 4027 } | 4019 } |
| 4028 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 4020 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 4029 #if defined(DEBUG) | 4021 #if defined(DEBUG) |
| 4030 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) { | 4022 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kFullAOT)) { |
| 4031 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 4023 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 4032 } | 4024 } |
| 4033 #endif | 4025 #endif |
| 4034 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 4026 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 4035 if (!error.IsNull()) { | 4027 if (!error.IsNull()) { |
| 4036 // An error occurred, return error object. | 4028 // An error occurred, return error object. |
| 4037 return Api::NewHandle(T, error.raw()); | 4029 return Api::NewHandle(T, error.raw()); |
| 4038 } | 4030 } |
| 4039 if (num_native_fields != cls.num_native_fields()) { | 4031 if (num_native_fields != cls.num_native_fields()) { |
| 4040 return Api::NewError( | 4032 return Api::NewError( |
| (...skipping 2604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6645 JITFeedbackFunctionVisitor visitor(&js_functions, zone); | 6637 JITFeedbackFunctionVisitor visitor(&js_functions, zone); |
| 6646 ProgramVisitor::VisitFunctions(&visitor); | 6638 ProgramVisitor::VisitFunctions(&visitor); |
| 6647 } | 6639 } |
| 6648 } | 6640 } |
| 6649 | 6641 |
| 6650 js_stream.Steal(reinterpret_cast<char**>(buffer), buffer_length); | 6642 js_stream.Steal(reinterpret_cast<char**>(buffer), buffer_length); |
| 6651 return Api::Success(); | 6643 return Api::Success(); |
| 6652 #endif | 6644 #endif |
| 6653 } | 6645 } |
| 6654 | 6646 |
| 6655 DART_EXPORT void Dart_SortClasses() { | 6647 DART_EXPORT Dart_Handle Dart_SortClasses() { |
| 6656 DARTSCOPE(Thread::Current()); | 6648 DARTSCOPE(Thread::Current()); |
| 6657 // We don't have mechanisms to change class-ids that are embedded in code and | 6649 // We don't have mechanisms to change class-ids that are embedded in code and |
| 6658 // ICData. | 6650 // ICData. |
| 6659 ClassFinalizer::ClearAllCode(); | 6651 ClassFinalizer::ClearAllCode(); |
| 6660 // Make sure that ICData etc. that have been cleared are also removed from | 6652 // Make sure that ICData etc. that have been cleared are also removed from |
| 6661 // the heap so that they are not found by the heap verifier. | 6653 // the heap so that they are not found by the heap verifier. |
| 6662 Isolate::Current()->heap()->CollectAllGarbage(); | 6654 Isolate::Current()->heap()->CollectAllGarbage(); |
| 6663 ClassFinalizer::SortClasses(); | 6655 ClassFinalizer::SortClasses(); |
| 6656 return Api::Success(); |
| 6664 } | 6657 } |
| 6665 | 6658 |
| 6666 DART_EXPORT Dart_Handle | 6659 DART_EXPORT Dart_Handle |
| 6667 Dart_Precompile(Dart_QualifiedFunctionName entry_points[], | 6660 Dart_Precompile(Dart_QualifiedFunctionName entry_points[], |
| 6668 uint8_t* jit_feedback, | 6661 uint8_t* jit_feedback, |
| 6669 intptr_t jit_feedback_length) { | 6662 intptr_t jit_feedback_length) { |
| 6670 #if defined(TARGET_ARCH_IA32) | 6663 #if defined(TARGET_ARCH_IA32) |
| 6671 return Api::NewError("AOT compilation is not supported on IA32."); | 6664 return Api::NewError("AOT compilation is not supported on IA32."); |
| 6672 #elif defined(TARGET_ARCH_DBC) | 6665 #elif defined(TARGET_ARCH_DBC) |
| 6673 return Api::NewError("AOT compilation is not supported on DBC."); | 6666 return Api::NewError("AOT compilation is not supported on DBC."); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6708 #else | 6701 #else |
| 6709 API_TIMELINE_DURATION; | 6702 API_TIMELINE_DURATION; |
| 6710 DARTSCOPE(Thread::Current()); | 6703 DARTSCOPE(Thread::Current()); |
| 6711 Isolate* I = T->isolate(); | 6704 Isolate* I = T->isolate(); |
| 6712 if (I->compilation_allowed()) { | 6705 if (I->compilation_allowed()) { |
| 6713 return Api::NewError( | 6706 return Api::NewError( |
| 6714 "Isolate is not precompiled. " | 6707 "Isolate is not precompiled. " |
| 6715 "Did you forget to call Dart_Precompile?"); | 6708 "Did you forget to call Dart_Precompile?"); |
| 6716 } | 6709 } |
| 6717 ASSERT(FLAG_load_deferred_eagerly); | 6710 ASSERT(FLAG_load_deferred_eagerly); |
| 6718 if (assembly_buffer == NULL) { | 6711 CHECK_NULL(assembly_buffer); |
| 6719 RETURN_NULL_ERROR(assembly_buffer); | 6712 CHECK_NULL(assembly_size); |
| 6720 } | |
| 6721 if (assembly_size == NULL) { | |
| 6722 RETURN_NULL_ERROR(assembly_size); | |
| 6723 } | |
| 6724 | 6713 |
| 6725 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6714 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6726 "WriteAppAOTSnapshot")); | 6715 "WriteAppAOTSnapshot")); |
| 6727 AssemblyImageWriter image_writer(assembly_buffer, ApiReallocate, | 6716 AssemblyImageWriter image_writer(assembly_buffer, ApiReallocate, |
| 6728 2 * MB /* initial_size */); | 6717 2 * MB /* initial_size */); |
| 6729 uint8_t* vm_snapshot_data_buffer = NULL; | 6718 uint8_t* vm_snapshot_data_buffer = NULL; |
| 6730 uint8_t* isolate_snapshot_data_buffer = NULL; | 6719 uint8_t* isolate_snapshot_data_buffer = NULL; |
| 6731 FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_snapshot_data_buffer, | 6720 FullSnapshotWriter writer(Snapshot::kFullAOT, &vm_snapshot_data_buffer, |
| 6732 &isolate_snapshot_data_buffer, ApiReallocate, | 6721 &isolate_snapshot_data_buffer, ApiReallocate, |
| 6733 &image_writer, &image_writer); | 6722 &image_writer, &image_writer); |
| 6734 | 6723 |
| 6735 writer.WriteFullSnapshot(); | 6724 writer.WriteFullSnapshot(); |
| 6736 image_writer.Finalize(); | 6725 image_writer.Finalize(); |
| 6737 *assembly_size = image_writer.AssemblySize(); | 6726 *assembly_size = image_writer.AssemblySize(); |
| 6738 | 6727 |
| 6739 return Api::Success(); | 6728 return Api::Success(); |
| 6740 #endif | 6729 #endif |
| 6741 } | 6730 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6763 #else | 6752 #else |
| 6764 API_TIMELINE_DURATION; | 6753 API_TIMELINE_DURATION; |
| 6765 DARTSCOPE(Thread::Current()); | 6754 DARTSCOPE(Thread::Current()); |
| 6766 Isolate* I = T->isolate(); | 6755 Isolate* I = T->isolate(); |
| 6767 if (I->compilation_allowed()) { | 6756 if (I->compilation_allowed()) { |
| 6768 return Api::NewError( | 6757 return Api::NewError( |
| 6769 "Isolate is not precompiled. " | 6758 "Isolate is not precompiled. " |
| 6770 "Did you forget to call Dart_Precompile?"); | 6759 "Did you forget to call Dart_Precompile?"); |
| 6771 } | 6760 } |
| 6772 ASSERT(FLAG_load_deferred_eagerly); | 6761 ASSERT(FLAG_load_deferred_eagerly); |
| 6773 if (vm_snapshot_data_buffer == NULL) { | 6762 CHECK_NULL(vm_snapshot_data_buffer); |
| 6774 RETURN_NULL_ERROR(vm_snapshot_data_buffer); | 6763 CHECK_NULL(vm_snapshot_data_size); |
| 6775 } | 6764 CHECK_NULL(vm_snapshot_instructions_buffer); |
| 6776 if (vm_snapshot_data_size == NULL) { | 6765 CHECK_NULL(vm_snapshot_instructions_size); |
| 6777 RETURN_NULL_ERROR(vm_snapshot_data_size); | 6766 CHECK_NULL(isolate_snapshot_data_buffer); |
| 6778 } | 6767 CHECK_NULL(isolate_snapshot_data_size); |
| 6779 if (vm_snapshot_instructions_buffer == NULL) { | 6768 CHECK_NULL(isolate_snapshot_instructions_buffer); |
| 6780 RETURN_NULL_ERROR(vm_snapshot_instructions_buffer); | 6769 CHECK_NULL(isolate_snapshot_instructions_size); |
| 6781 } | |
| 6782 if (vm_snapshot_instructions_size == NULL) { | |
| 6783 RETURN_NULL_ERROR(vm_snapshot_instructions_size); | |
| 6784 } | |
| 6785 if (isolate_snapshot_data_buffer == NULL) { | |
| 6786 RETURN_NULL_ERROR(isolate_snapshot_data_buffer); | |
| 6787 } | |
| 6788 if (isolate_snapshot_data_size == NULL) { | |
| 6789 RETURN_NULL_ERROR(isolate_snapshot_data_size); | |
| 6790 } | |
| 6791 if (isolate_snapshot_instructions_buffer == NULL) { | |
| 6792 RETURN_NULL_ERROR(instructions_snapshot_blob_buffer); | |
| 6793 } | |
| 6794 if (isolate_snapshot_instructions_buffer == NULL) { | |
| 6795 RETURN_NULL_ERROR(instructions_snapshot_blob_size); | |
| 6796 } | |
| 6797 | 6770 |
| 6798 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6771 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6799 "WriteAppAOTSnapshot")); | 6772 "WriteAppAOTSnapshot")); |
| 6800 BlobImageWriter vm_image_writer(vm_snapshot_instructions_buffer, | 6773 BlobImageWriter vm_image_writer(vm_snapshot_instructions_buffer, |
| 6801 ApiReallocate, 2 * MB /* initial_size */); | 6774 ApiReallocate, 2 * MB /* initial_size */); |
| 6802 BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, | 6775 BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, |
| 6803 ApiReallocate, | 6776 ApiReallocate, |
| 6804 2 * MB /* initial_size */); | 6777 2 * MB /* initial_size */); |
| 6805 FullSnapshotWriter writer(Snapshot::kAppAOT, vm_snapshot_data_buffer, | 6778 FullSnapshotWriter writer(Snapshot::kFullAOT, vm_snapshot_data_buffer, |
| 6806 isolate_snapshot_data_buffer, ApiReallocate, | 6779 isolate_snapshot_data_buffer, ApiReallocate, |
| 6807 &vm_image_writer, &isolate_image_writer); | 6780 &vm_image_writer, &isolate_image_writer); |
| 6808 | 6781 |
| 6809 writer.WriteFullSnapshot(); | 6782 writer.WriteFullSnapshot(); |
| 6810 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); | 6783 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
| 6811 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); | 6784 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); |
| 6812 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 6785 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6813 *isolate_snapshot_instructions_size = | 6786 *isolate_snapshot_instructions_size = |
| 6814 isolate_image_writer.InstructionsBlobSize(); | 6787 isolate_image_writer.InstructionsBlobSize(); |
| 6815 | 6788 |
| 6816 return Api::Success(); | 6789 return Api::Success(); |
| 6817 #endif | 6790 #endif |
| 6818 } | 6791 } |
| 6819 | 6792 |
| 6820 | 6793 |
| 6794 DART_EXPORT Dart_Handle Dart_CreateCoreJITSnapshotAsBlobs( |
| 6795 uint8_t** vm_snapshot_data_buffer, |
| 6796 intptr_t* vm_snapshot_data_size, |
| 6797 uint8_t** vm_snapshot_instructions_buffer, |
| 6798 intptr_t* vm_snapshot_instructions_size, |
| 6799 uint8_t** isolate_snapshot_data_buffer, |
| 6800 intptr_t* isolate_snapshot_data_size, |
| 6801 uint8_t** isolate_snapshot_instructions_buffer, |
| 6802 intptr_t* isolate_snapshot_instructions_size) { |
| 6803 #if defined(TARGET_ARCH_IA32) |
| 6804 return Api::NewError("Snapshots with code are not supported on IA32."); |
| 6805 #elif defined(TARGET_ARCH_DBC) |
| 6806 return Api::NewError("Snapshots with code are not supported on DBC."); |
| 6807 #elif defined(DART_PRECOMPILED_RUNTIME) |
| 6808 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime"); |
| 6809 #else |
| 6810 API_TIMELINE_DURATION; |
| 6811 DARTSCOPE(Thread::Current()); |
| 6812 Isolate* I = T->isolate(); |
| 6813 if (!FLAG_load_deferred_eagerly) { |
| 6814 return Api::NewError( |
| 6815 "Creating full snapshots requires --load_deferred_eagerly"); |
| 6816 } |
| 6817 CHECK_NULL(vm_snapshot_data_buffer); |
| 6818 CHECK_NULL(vm_snapshot_data_size); |
| 6819 CHECK_NULL(vm_snapshot_instructions_buffer); |
| 6820 CHECK_NULL(vm_snapshot_instructions_size); |
| 6821 CHECK_NULL(isolate_snapshot_data_buffer); |
| 6822 CHECK_NULL(isolate_snapshot_data_size); |
| 6823 CHECK_NULL(isolate_snapshot_instructions_buffer); |
| 6824 CHECK_NULL(isolate_snapshot_instructions_size); |
| 6825 // Finalize all classes if needed. |
| 6826 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 6827 if (::Dart_IsError(state)) { |
| 6828 return state; |
| 6829 } |
| 6830 I->StopBackgroundCompiler(); |
| 6831 |
| 6832 ProgramVisitor::Dedup(); |
| 6833 Symbols::Compact(I); |
| 6834 |
| 6835 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6836 "WriteCoreJITSnapshot")); |
| 6837 BlobImageWriter vm_image_writer(vm_snapshot_instructions_buffer, |
| 6838 ApiReallocate, 2 * MB /* initial_size */); |
| 6839 BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, |
| 6840 ApiReallocate, |
| 6841 2 * MB /* initial_size */); |
| 6842 FullSnapshotWriter writer(Snapshot::kFullJIT, vm_snapshot_data_buffer, |
| 6843 isolate_snapshot_data_buffer, ApiReallocate, |
| 6844 &vm_image_writer, &isolate_image_writer); |
| 6845 writer.WriteFullSnapshot(); |
| 6846 |
| 6847 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
| 6848 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); |
| 6849 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6850 *isolate_snapshot_instructions_size = |
| 6851 isolate_image_writer.InstructionsBlobSize(); |
| 6852 |
| 6853 return Api::Success(); |
| 6854 #endif |
| 6855 } |
| 6856 |
| 6857 |
| 6821 DART_EXPORT Dart_Handle | 6858 DART_EXPORT Dart_Handle |
| 6822 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, | 6859 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, |
| 6823 intptr_t* isolate_snapshot_data_size, | 6860 intptr_t* isolate_snapshot_data_size, |
| 6824 uint8_t** isolate_snapshot_instructions_buffer, | 6861 uint8_t** isolate_snapshot_instructions_buffer, |
| 6825 intptr_t* isolate_snapshot_instructions_size) { | 6862 intptr_t* isolate_snapshot_instructions_size) { |
| 6826 #if defined(TARGET_ARCH_IA32) | 6863 #if defined(TARGET_ARCH_IA32) |
| 6827 return Api::NewError("Snapshots with code are not supported on IA32."); | 6864 return Api::NewError("Snapshots with code are not supported on IA32."); |
| 6828 #elif defined(TARGET_ARCH_DBC) | 6865 #elif defined(TARGET_ARCH_DBC) |
| 6829 return Api::NewError("Snapshots with code are not supported on DBC."); | 6866 return Api::NewError("Snapshots with code are not supported on DBC."); |
| 6830 #elif defined(DART_PRECOMPILED_RUNTIME) | 6867 #elif defined(DART_PRECOMPILED_RUNTIME) |
| 6831 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime"); | 6868 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime"); |
| 6832 #else | 6869 #else |
| 6833 API_TIMELINE_DURATION; | 6870 API_TIMELINE_DURATION; |
| 6834 DARTSCOPE(Thread::Current()); | 6871 DARTSCOPE(Thread::Current()); |
| 6835 Isolate* I = T->isolate(); | 6872 Isolate* I = T->isolate(); |
| 6836 if (!FLAG_load_deferred_eagerly) { | 6873 if (!FLAG_load_deferred_eagerly) { |
| 6837 return Api::NewError( | 6874 return Api::NewError( |
| 6838 "Creating full snapshots requires --load_deferred_eagerly"); | 6875 "Creating full snapshots requires --load_deferred_eagerly"); |
| 6839 } | 6876 } |
| 6840 if (isolate_snapshot_data_buffer == NULL) { | 6877 CHECK_NULL(isolate_snapshot_data_buffer); |
| 6841 RETURN_NULL_ERROR(isolate_snapshot_data_buffer); | 6878 CHECK_NULL(isolate_snapshot_data_size); |
| 6842 } | 6879 CHECK_NULL(isolate_snapshot_instructions_buffer); |
| 6843 if (isolate_snapshot_data_size == NULL) { | 6880 CHECK_NULL(isolate_snapshot_instructions_size); |
| 6844 RETURN_NULL_ERROR(isolate_snapshot_data_size); | |
| 6845 } | |
| 6846 if (isolate_snapshot_instructions_buffer == NULL) { | |
| 6847 RETURN_NULL_ERROR(instructions_snapshot_blob_buffer); | |
| 6848 } | |
| 6849 if (isolate_snapshot_instructions_buffer == NULL) { | |
| 6850 RETURN_NULL_ERROR(instructions_snapshot_blob_size); | |
| 6851 } | |
| 6852 // Finalize all classes if needed. | 6881 // Finalize all classes if needed. |
| 6853 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 6882 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 6854 if (::Dart_IsError(state)) { | 6883 if (::Dart_IsError(state)) { |
| 6855 return state; | 6884 return state; |
| 6856 } | 6885 } |
| 6857 I->StopBackgroundCompiler(); | 6886 I->StopBackgroundCompiler(); |
| 6858 | 6887 |
| 6859 ProgramVisitor::Dedup(); | 6888 ProgramVisitor::Dedup(); |
| 6860 Symbols::Compact(I); | 6889 Symbols::Compact(I); |
| 6861 | 6890 |
| 6862 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6891 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6863 "WriteAppJITSnapshot")); | 6892 "WriteAppJITSnapshot")); |
| 6864 BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, | 6893 BlobImageWriter isolate_image_writer(isolate_snapshot_instructions_buffer, |
| 6865 ApiReallocate, | 6894 ApiReallocate, |
| 6866 2 * MB /* initial_size */); | 6895 2 * MB /* initial_size */); |
| 6867 FullSnapshotWriter writer(Snapshot::kAppJIT, NULL, | 6896 FullSnapshotWriter writer(Snapshot::kFullJIT, NULL, |
| 6868 isolate_snapshot_data_buffer, ApiReallocate, NULL, | 6897 isolate_snapshot_data_buffer, ApiReallocate, NULL, |
| 6869 &isolate_image_writer); | 6898 &isolate_image_writer); |
| 6870 writer.WriteFullSnapshot(); | 6899 writer.WriteFullSnapshot(); |
| 6871 | 6900 |
| 6872 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 6901 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6873 *isolate_snapshot_instructions_size = | 6902 *isolate_snapshot_instructions_size = |
| 6874 isolate_image_writer.InstructionsBlobSize(); | 6903 isolate_image_writer.InstructionsBlobSize(); |
| 6875 | 6904 |
| 6876 return Api::Success(); | 6905 return Api::Success(); |
| 6877 #endif | 6906 #endif |
| 6878 } | 6907 } |
| 6879 | 6908 |
| 6880 | 6909 |
| 6881 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6910 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
| 6882 #if defined(DART_PRECOMPILED_RUNTIME) | 6911 #if defined(DART_PRECOMPILED_RUNTIME) |
| 6883 return true; | 6912 return true; |
| 6884 #else | 6913 #else |
| 6885 return false; | 6914 return false; |
| 6886 #endif | 6915 #endif |
| 6887 } | 6916 } |
| 6888 | 6917 |
| 6889 | 6918 |
| 6890 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { | 6919 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { |
| 6891 #ifndef PRODUCT | 6920 #ifndef PRODUCT |
| 6892 Profiler::DumpStackTrace(context); | 6921 Profiler::DumpStackTrace(context); |
| 6893 #endif | 6922 #endif |
| 6894 } | 6923 } |
| 6895 | 6924 |
| 6896 } // namespace dart | 6925 } // namespace dart |
| OLD | NEW |