| 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 "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "vm/verifier.h" | 45 #include "vm/verifier.h" |
| 46 #include "vm/version.h" | 46 #include "vm/version.h" |
| 47 | 47 |
| 48 namespace dart { | 48 namespace dart { |
| 49 | 49 |
| 50 // Facilitate quick access to the current zone once we have the curren thread. | 50 // Facilitate quick access to the current zone once we have the curren thread. |
| 51 #define Z (T->zone()) | 51 #define Z (T->zone()) |
| 52 | 52 |
| 53 | 53 |
| 54 DECLARE_FLAG(bool, load_deferred_eagerly); | 54 DECLARE_FLAG(bool, load_deferred_eagerly); |
| 55 DECLARE_FLAG(bool, precompilation); |
| 55 DECLARE_FLAG(bool, print_class_table); | 56 DECLARE_FLAG(bool, print_class_table); |
| 56 DECLARE_FLAG(bool, verify_handles); | 57 DECLARE_FLAG(bool, verify_handles); |
| 57 #if defined(DART_NO_SNAPSHOT) | 58 #if defined(DART_NO_SNAPSHOT) |
| 58 DEFINE_FLAG(bool, check_function_fingerprints, true, | 59 DEFINE_FLAG(bool, check_function_fingerprints, true, |
| 59 "Check function fingerprints"); | 60 "Check function fingerprints"); |
| 60 #endif // defined(DART_NO_SNAPSHOT). | 61 #endif // defined(DART_NO_SNAPSHOT). |
| 61 DEFINE_FLAG(bool, trace_api, false, | 62 DEFINE_FLAG(bool, trace_api, false, |
| 62 "Trace invocation of API calls (debug mode only)"); | 63 "Trace invocation of API calls (debug mode only)"); |
| 63 DEFINE_FLAG(bool, verify_acquired_data, false, | 64 DEFINE_FLAG(bool, verify_acquired_data, false, |
| 64 "Verify correct API acquire/release of typed data."); | 65 "Verify correct API acquire/release of typed data."); |
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 const uint8_t* instructions_snapshot, | 1274 const uint8_t* instructions_snapshot, |
| 1274 Dart_IsolateCreateCallback create, | 1275 Dart_IsolateCreateCallback create, |
| 1275 Dart_IsolateInterruptCallback interrupt, | 1276 Dart_IsolateInterruptCallback interrupt, |
| 1276 Dart_IsolateUnhandledExceptionCallback unhandled, | 1277 Dart_IsolateUnhandledExceptionCallback unhandled, |
| 1277 Dart_IsolateShutdownCallback shutdown, | 1278 Dart_IsolateShutdownCallback shutdown, |
| 1278 Dart_FileOpenCallback file_open, | 1279 Dart_FileOpenCallback file_open, |
| 1279 Dart_FileReadCallback file_read, | 1280 Dart_FileReadCallback file_read, |
| 1280 Dart_FileWriteCallback file_write, | 1281 Dart_FileWriteCallback file_write, |
| 1281 Dart_FileCloseCallback file_close, | 1282 Dart_FileCloseCallback file_close, |
| 1282 Dart_EntropySource entropy_source) { | 1283 Dart_EntropySource entropy_source) { |
| 1284 if ((instructions_snapshot != NULL) && !FLAG_precompilation) { |
| 1285 return strdup("Flag --precompilation was not specified."); |
| 1286 } |
| 1283 const char* err_msg = Dart::InitOnce(vm_isolate_snapshot, | 1287 const char* err_msg = Dart::InitOnce(vm_isolate_snapshot, |
| 1284 instructions_snapshot, | 1288 instructions_snapshot, |
| 1285 create, interrupt, unhandled, shutdown, | 1289 create, interrupt, unhandled, shutdown, |
| 1286 file_open, file_read, file_write, | 1290 file_open, file_read, file_write, |
| 1287 file_close, entropy_source); | 1291 file_close, entropy_source); |
| 1288 if (err_msg != NULL) { | 1292 if (err_msg != NULL) { |
| 1289 return strdup(err_msg); | 1293 return strdup(err_msg); |
| 1290 } | 1294 } |
| 1291 return NULL; | 1295 return NULL; |
| 1292 } | 1296 } |
| (...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3773 RETURN_TYPE_ERROR(Z, type, Type); | 3777 RETURN_TYPE_ERROR(Z, type, Type); |
| 3774 } | 3778 } |
| 3775 Type& type_obj = Type::Handle(); | 3779 Type& type_obj = Type::Handle(); |
| 3776 type_obj ^= unchecked_type.raw(); | 3780 type_obj ^= unchecked_type.raw(); |
| 3777 if (!type_obj.IsFinalized()) { | 3781 if (!type_obj.IsFinalized()) { |
| 3778 return Api::NewError( | 3782 return Api::NewError( |
| 3779 "%s expects argument 'type' to be a fully resolved type.", | 3783 "%s expects argument 'type' to be a fully resolved type.", |
| 3780 CURRENT_FUNC); | 3784 CURRENT_FUNC); |
| 3781 } | 3785 } |
| 3782 Class& cls = Class::Handle(Z, type_obj.type_class()); | 3786 Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 3787 #if defined(DEBUG) |
| 3788 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { |
| 3789 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 3790 } |
| 3791 #endif |
| 3783 TypeArguments& type_arguments = | 3792 TypeArguments& type_arguments = |
| 3784 TypeArguments::Handle(Z, type_obj.arguments()); | 3793 TypeArguments::Handle(Z, type_obj.arguments()); |
| 3785 | 3794 |
| 3786 const String& base_constructor_name = String::Handle(Z, cls.Name()); | 3795 const String& base_constructor_name = String::Handle(Z, cls.Name()); |
| 3787 | 3796 |
| 3788 // And get the name of the constructor to invoke. | 3797 // And get the name of the constructor to invoke. |
| 3789 String& dot_name = String::Handle(Z); | 3798 String& dot_name = String::Handle(Z); |
| 3790 result = Api::UnwrapHandle(constructor_name); | 3799 result = Api::UnwrapHandle(constructor_name); |
| 3791 if (result.IsNull()) { | 3800 if (result.IsNull()) { |
| 3792 dot_name = Symbols::Dot().raw(); | 3801 dot_name = Symbols::Dot().raw(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3923 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { | 3932 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { |
| 3924 DARTSCOPE(Thread::Current()); | 3933 DARTSCOPE(Thread::Current()); |
| 3925 CHECK_CALLBACK_STATE(T); | 3934 CHECK_CALLBACK_STATE(T); |
| 3926 | 3935 |
| 3927 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3936 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 3928 // Get the class to instantiate. | 3937 // Get the class to instantiate. |
| 3929 if (type_obj.IsNull()) { | 3938 if (type_obj.IsNull()) { |
| 3930 RETURN_TYPE_ERROR(Z, type, Type); | 3939 RETURN_TYPE_ERROR(Z, type, Type); |
| 3931 } | 3940 } |
| 3932 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3941 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 3942 #if defined(DEBUG) |
| 3943 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { |
| 3944 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 3945 } |
| 3946 #endif |
| 3933 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3947 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 3934 if (!error.IsNull()) { | 3948 if (!error.IsNull()) { |
| 3935 // An error occurred, return error object. | 3949 // An error occurred, return error object. |
| 3936 return Api::NewHandle(I, error.raw()); | 3950 return Api::NewHandle(I, error.raw()); |
| 3937 } | 3951 } |
| 3938 return Api::NewHandle(I, AllocateObject(T, cls)); | 3952 return Api::NewHandle(I, AllocateObject(T, cls)); |
| 3939 } | 3953 } |
| 3940 | 3954 |
| 3941 | 3955 |
| 3942 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( | 3956 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( |
| 3943 Dart_Handle type, | 3957 Dart_Handle type, |
| 3944 intptr_t num_native_fields, | 3958 intptr_t num_native_fields, |
| 3945 const intptr_t* native_fields) { | 3959 const intptr_t* native_fields) { |
| 3946 DARTSCOPE(Thread::Current()); | 3960 DARTSCOPE(Thread::Current()); |
| 3947 CHECK_CALLBACK_STATE(T); | 3961 CHECK_CALLBACK_STATE(T); |
| 3948 | 3962 |
| 3949 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3963 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 3950 // Get the class to instantiate. | 3964 // Get the class to instantiate. |
| 3951 if (type_obj.IsNull()) { | 3965 if (type_obj.IsNull()) { |
| 3952 RETURN_TYPE_ERROR(Z, type, Type); | 3966 RETURN_TYPE_ERROR(Z, type, Type); |
| 3953 } | 3967 } |
| 3954 if (native_fields == NULL) { | 3968 if (native_fields == NULL) { |
| 3955 RETURN_NULL_ERROR(native_fields); | 3969 RETURN_NULL_ERROR(native_fields); |
| 3956 } | 3970 } |
| 3957 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3971 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 3972 #if defined(DEBUG) |
| 3973 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { |
| 3974 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 3975 } |
| 3976 #endif |
| 3958 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3977 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 3959 if (!error.IsNull()) { | 3978 if (!error.IsNull()) { |
| 3960 // An error occurred, return error object. | 3979 // An error occurred, return error object. |
| 3961 return Api::NewHandle(I, error.raw()); | 3980 return Api::NewHandle(I, error.raw()); |
| 3962 } | 3981 } |
| 3963 if (num_native_fields != cls.num_native_fields()) { | 3982 if (num_native_fields != cls.num_native_fields()) { |
| 3964 return Api::NewError( | 3983 return Api::NewError( |
| 3965 "%s: invalid number of native fields %" Pd " passed in, expected %d", | 3984 "%s: invalid number of native fields %" Pd " passed in, expected %d", |
| 3966 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); | 3985 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); |
| 3967 } | 3986 } |
| (...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5984 event->Complete(); | 6003 event->Complete(); |
| 5985 } | 6004 } |
| 5986 return Api::Success(); | 6005 return Api::Success(); |
| 5987 } | 6006 } |
| 5988 | 6007 |
| 5989 | 6008 |
| 5990 DART_EXPORT Dart_Handle Dart_Precompile( | 6009 DART_EXPORT Dart_Handle Dart_Precompile( |
| 5991 Dart_QualifiedFunctionName entry_points[], | 6010 Dart_QualifiedFunctionName entry_points[], |
| 5992 bool reset_fields) { | 6011 bool reset_fields) { |
| 5993 DARTSCOPE(Thread::Current()); | 6012 DARTSCOPE(Thread::Current()); |
| 6013 if (!FLAG_precompilation) { |
| 6014 return Dart_NewApiError("Flag --precompilation was not specified."); |
| 6015 } |
| 5994 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); | 6016 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); |
| 5995 if (::Dart_IsError(result)) { | 6017 if (::Dart_IsError(result)) { |
| 5996 return result; | 6018 return result; |
| 5997 } | 6019 } |
| 5998 CHECK_CALLBACK_STATE(T); | 6020 CHECK_CALLBACK_STATE(T); |
| 5999 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, | 6021 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, |
| 6000 reset_fields)); | 6022 reset_fields)); |
| 6001 if (!error.IsNull()) { | 6023 if (!error.IsNull()) { |
| 6002 return Api::NewHandle(I, error.raw()); | 6024 return Api::NewHandle(I, error.raw()); |
| 6003 } | 6025 } |
| 6004 return Api::Success(); | 6026 return Api::Success(); |
| 6005 } | 6027 } |
| 6006 | 6028 |
| 6007 | 6029 |
| 6008 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( | 6030 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
| 6009 uint8_t** vm_isolate_snapshot_buffer, | 6031 uint8_t** vm_isolate_snapshot_buffer, |
| 6010 intptr_t* vm_isolate_snapshot_size, | 6032 intptr_t* vm_isolate_snapshot_size, |
| 6011 uint8_t** isolate_snapshot_buffer, | 6033 uint8_t** isolate_snapshot_buffer, |
| 6012 intptr_t* isolate_snapshot_size, | 6034 intptr_t* isolate_snapshot_size, |
| 6013 uint8_t** instructions_snapshot_buffer, | 6035 uint8_t** instructions_snapshot_buffer, |
| 6014 intptr_t* instructions_snapshot_size) { | 6036 intptr_t* instructions_snapshot_size) { |
| 6015 ASSERT(FLAG_load_deferred_eagerly); | 6037 ASSERT(FLAG_load_deferred_eagerly); |
| 6016 DARTSCOPE(Thread::Current()); | 6038 DARTSCOPE(Thread::Current()); |
| 6039 if (I->compilation_allowed()) { |
| 6040 return Dart_NewApiError("Isolate is not precompiled. " |
| 6041 "Did you forget to call Dart_Precompile?"); |
| 6042 } |
| 6017 if (vm_isolate_snapshot_buffer == NULL) { | 6043 if (vm_isolate_snapshot_buffer == NULL) { |
| 6018 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6044 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 6019 } | 6045 } |
| 6020 if (vm_isolate_snapshot_size == NULL) { | 6046 if (vm_isolate_snapshot_size == NULL) { |
| 6021 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6047 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 6022 } | 6048 } |
| 6023 if (isolate_snapshot_buffer == NULL) { | 6049 if (isolate_snapshot_buffer == NULL) { |
| 6024 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6050 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 6025 } | 6051 } |
| 6026 if (isolate_snapshot_size == NULL) { | 6052 if (isolate_snapshot_size == NULL) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6044 ApiReallocate); | 6070 ApiReallocate); |
| 6045 writer.WriteFullSnapshot(); | 6071 writer.WriteFullSnapshot(); |
| 6046 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6072 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 6047 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6073 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 6048 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 6074 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 6049 | 6075 |
| 6050 return Api::Success(); | 6076 return Api::Success(); |
| 6051 } | 6077 } |
| 6052 | 6078 |
| 6053 } // namespace dart | 6079 } // namespace dart |
| OLD | NEW |