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 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 "Dart_Initialize: " | 1181 "Dart_Initialize: " |
1182 "Dart_InitializeParams is null."); | 1182 "Dart_InitializeParams is null."); |
1183 } | 1183 } |
1184 | 1184 |
1185 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { | 1185 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { |
1186 return strdup( | 1186 return strdup( |
1187 "Dart_Initialize: " | 1187 "Dart_Initialize: " |
1188 "Invalid Dart_InitializeParams version."); | 1188 "Invalid Dart_InitializeParams version."); |
1189 } | 1189 } |
1190 | 1190 |
1191 return Dart::InitOnce(params->vm_isolate_snapshot, | 1191 return Dart::InitOnce( |
1192 params->instructions_snapshot, params->data_snapshot, | 1192 params->vm_snapshot_data, params->vm_snapshot_instructions, |
1193 params->create, params->shutdown, params->thread_exit, | 1193 params->create, params->shutdown, params->thread_exit, params->file_open, |
1194 params->file_open, params->file_read, | 1194 params->file_read, params->file_write, params->file_close, |
1195 params->file_write, params->file_close, | 1195 params->entropy_source, params->get_service_assets); |
1196 params->entropy_source, params->get_service_assets); | |
1197 } | 1196 } |
1198 | 1197 |
1199 | 1198 |
1200 DART_EXPORT char* Dart_Cleanup() { | 1199 DART_EXPORT char* Dart_Cleanup() { |
1201 CHECK_NO_ISOLATE(Isolate::Current()); | 1200 CHECK_NO_ISOLATE(Isolate::Current()); |
1202 const char* err_msg = Dart::Cleanup(); | 1201 const char* err_msg = Dart::Cleanup(); |
1203 if (err_msg != NULL) { | 1202 if (err_msg != NULL) { |
1204 return strdup(err_msg); | 1203 return strdup(err_msg); |
1205 } | 1204 } |
1206 return NULL; | 1205 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 char* chars = NULL; | 1248 char* chars = NULL; |
1250 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; | 1249 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; |
1251 chars = reinterpret_cast<char*>(malloc(len)); | 1250 chars = reinterpret_cast<char*>(malloc(len)); |
1252 OS::SNPrint(chars, len, "%s$%s", script_uri, main); | 1251 OS::SNPrint(chars, len, "%s$%s", script_uri, main); |
1253 return chars; | 1252 return chars; |
1254 } | 1253 } |
1255 | 1254 |
1256 | 1255 |
1257 static Dart_Isolate CreateIsolate(const char* script_uri, | 1256 static Dart_Isolate CreateIsolate(const char* script_uri, |
1258 const char* main, | 1257 const char* main, |
1259 const uint8_t* snapshot_buffer, | 1258 const uint8_t* snapshot_data, |
| 1259 const uint8_t* snapshot_instructions, |
1260 intptr_t snapshot_length, | 1260 intptr_t snapshot_length, |
1261 kernel::Program* kernel_program, | 1261 kernel::Program* kernel_program, |
1262 Dart_IsolateFlags* flags, | 1262 Dart_IsolateFlags* flags, |
1263 void* callback_data, | 1263 void* callback_data, |
1264 char** error) { | 1264 char** error) { |
1265 CHECK_NO_ISOLATE(Isolate::Current()); | 1265 CHECK_NO_ISOLATE(Isolate::Current()); |
1266 char* isolate_name = BuildIsolateName(script_uri, main); | 1266 char* isolate_name = BuildIsolateName(script_uri, main); |
1267 | 1267 |
1268 // Setup default flags in case none were passed. | 1268 // Setup default flags in case none were passed. |
1269 Dart_IsolateFlags api_flags; | 1269 Dart_IsolateFlags api_flags; |
1270 if (flags == NULL) { | 1270 if (flags == NULL) { |
1271 Isolate::FlagsInitialize(&api_flags); | 1271 Isolate::FlagsInitialize(&api_flags); |
1272 flags = &api_flags; | 1272 flags = &api_flags; |
1273 } | 1273 } |
1274 Isolate* I = Dart::CreateIsolate(isolate_name, *flags); | 1274 Isolate* I = Dart::CreateIsolate(isolate_name, *flags); |
1275 free(isolate_name); | 1275 free(isolate_name); |
1276 if (I == NULL) { | 1276 if (I == NULL) { |
1277 *error = strdup("Isolate creation failed"); | 1277 *error = strdup("Isolate creation failed"); |
1278 return reinterpret_cast<Dart_Isolate>(NULL); | 1278 return reinterpret_cast<Dart_Isolate>(NULL); |
1279 } | 1279 } |
1280 { | 1280 { |
1281 Thread* T = Thread::Current(); | 1281 Thread* T = Thread::Current(); |
1282 StackZone zone(T); | 1282 StackZone zone(T); |
1283 HANDLESCOPE(T); | 1283 HANDLESCOPE(T); |
1284 // We enter an API scope here as InitializeIsolate could compile some | 1284 // We enter an API scope here as InitializeIsolate could compile some |
1285 // bootstrap library files which call out to a tag handler that may create | 1285 // bootstrap library files which call out to a tag handler that may create |
1286 // Api Handles when an error is encountered. | 1286 // Api Handles when an error is encountered. |
1287 Dart_EnterScope(); | 1287 Dart_EnterScope(); |
1288 const Error& error_obj = Error::Handle( | 1288 const Error& error_obj = |
1289 Z, Dart::InitializeIsolate(snapshot_buffer, snapshot_length, | 1289 Error::Handle(Z, Dart::InitializeIsolate( |
1290 kernel_program, callback_data)); | 1290 snapshot_data, snapshot_instructions, |
| 1291 snapshot_length, kernel_program, callback_data)); |
1291 if (error_obj.IsNull()) { | 1292 if (error_obj.IsNull()) { |
1292 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) | 1293 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) |
1293 if (FLAG_check_function_fingerprints && kernel_program == NULL) { | 1294 if (FLAG_check_function_fingerprints && kernel_program == NULL) { |
1294 Library::CheckFunctionFingerprints(); | 1295 Library::CheckFunctionFingerprints(); |
1295 } | 1296 } |
1296 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). | 1297 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). |
1297 // We exit the API scope entered above. | 1298 // We exit the API scope entered above. |
1298 Dart_ExitScope(); | 1299 Dart_ExitScope(); |
1299 // A Thread structure has been associated to the thread, we do the | 1300 // A Thread structure has been associated to the thread, we do the |
1300 // safepoint transition explicity here instead of using the | 1301 // safepoint transition explicity here instead of using the |
1301 // TransitionXXX scope objects as the reverse transition happens | 1302 // TransitionXXX scope objects as the reverse transition happens |
1302 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. | 1303 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. |
1303 T->set_execution_state(Thread::kThreadInNative); | 1304 T->set_execution_state(Thread::kThreadInNative); |
1304 T->EnterSafepoint(); | 1305 T->EnterSafepoint(); |
1305 return Api::CastIsolate(I); | 1306 return Api::CastIsolate(I); |
1306 } | 1307 } |
1307 *error = strdup(error_obj.ToErrorCString()); | 1308 *error = strdup(error_obj.ToErrorCString()); |
1308 // We exit the API scope entered above. | 1309 // We exit the API scope entered above. |
1309 Dart_ExitScope(); | 1310 Dart_ExitScope(); |
1310 } | 1311 } |
1311 Dart::ShutdownIsolate(); | 1312 Dart::ShutdownIsolate(); |
1312 return reinterpret_cast<Dart_Isolate>(NULL); | 1313 return reinterpret_cast<Dart_Isolate>(NULL); |
1313 } | 1314 } |
1314 | 1315 |
1315 | 1316 |
1316 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, | 1317 DART_EXPORT Dart_Isolate |
1317 const char* main, | 1318 Dart_CreateIsolate(const char* script_uri, |
1318 const uint8_t* snapshot_buffer, | 1319 const char* main, |
1319 Dart_IsolateFlags* flags, | 1320 const uint8_t* snapshot_data, |
1320 void* callback_data, | 1321 const uint8_t* snapshot_instructions, |
1321 char** error) { | 1322 Dart_IsolateFlags* flags, |
1322 return CreateIsolate(script_uri, main, snapshot_buffer, -1, NULL, flags, | 1323 void* callback_data, |
1323 callback_data, error); | 1324 char** error) { |
| 1325 return CreateIsolate(script_uri, main, snapshot_data, snapshot_instructions, |
| 1326 -1, NULL, flags, callback_data, error); |
1324 } | 1327 } |
1325 | 1328 |
1326 | 1329 |
1327 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri, | 1330 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri, |
1328 const char* main, | 1331 const char* main, |
1329 void* kernel_program, | 1332 void* kernel_program, |
1330 Dart_IsolateFlags* flags, | 1333 Dart_IsolateFlags* flags, |
1331 void* callback_data, | 1334 void* callback_data, |
1332 char** error) { | 1335 char** error) { |
1333 return CreateIsolate(script_uri, main, NULL, -1, | 1336 return CreateIsolate(script_uri, main, NULL, NULL, -1, |
1334 reinterpret_cast<kernel::Program*>(kernel_program), | 1337 reinterpret_cast<kernel::Program*>(kernel_program), |
1335 flags, callback_data, error); | 1338 flags, callback_data, error); |
1336 } | 1339 } |
1337 | 1340 |
1338 | 1341 |
1339 DART_EXPORT void Dart_ShutdownIsolate() { | 1342 DART_EXPORT void Dart_ShutdownIsolate() { |
1340 Thread* T = Thread::Current(); | 1343 Thread* T = Thread::Current(); |
1341 Isolate* I = T->isolate(); | 1344 Isolate* I = T->isolate(); |
1342 CHECK_ISOLATE(I); | 1345 CHECK_ISOLATE(I); |
1343 I->WaitForOutstandingSpawns(); | 1346 I->WaitForOutstandingSpawns(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 static uint8_t* ApiReallocate(uint8_t* ptr, | 1556 static uint8_t* ApiReallocate(uint8_t* ptr, |
1554 intptr_t old_size, | 1557 intptr_t old_size, |
1555 intptr_t new_size) { | 1558 intptr_t new_size) { |
1556 return Api::TopScope(Thread::Current()) | 1559 return Api::TopScope(Thread::Current()) |
1557 ->zone() | 1560 ->zone() |
1558 ->Realloc<uint8_t>(ptr, old_size, new_size); | 1561 ->Realloc<uint8_t>(ptr, old_size, new_size); |
1559 } | 1562 } |
1560 | 1563 |
1561 | 1564 |
1562 DART_EXPORT Dart_Handle | 1565 DART_EXPORT Dart_Handle |
1563 Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer, | 1566 Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer, |
1564 intptr_t* vm_isolate_snapshot_size, | 1567 intptr_t* vm_snapshot_data_size, |
1565 uint8_t** isolate_snapshot_buffer, | 1568 uint8_t** isolate_snapshot_data_buffer, |
1566 intptr_t* isolate_snapshot_size) { | 1569 intptr_t* isolate_snapshot_data_size) { |
1567 DARTSCOPE(Thread::Current()); | 1570 DARTSCOPE(Thread::Current()); |
1568 API_TIMELINE_DURATION; | 1571 API_TIMELINE_DURATION; |
1569 Isolate* I = T->isolate(); | 1572 Isolate* I = T->isolate(); |
1570 if (!FLAG_load_deferred_eagerly) { | 1573 if (!FLAG_load_deferred_eagerly) { |
1571 return Api::NewError( | 1574 return Api::NewError( |
1572 "Creating full snapshots requires --load_deferred_eagerly"); | 1575 "Creating full snapshots requires --load_deferred_eagerly"); |
1573 } | 1576 } |
1574 if (vm_isolate_snapshot_buffer != NULL && vm_isolate_snapshot_size == NULL) { | 1577 if (vm_snapshot_data_buffer != NULL && vm_snapshot_data_size == NULL) { |
1575 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 1578 RETURN_NULL_ERROR(vm_snapshot_data_size); |
1576 } | 1579 } |
1577 if (isolate_snapshot_buffer == NULL) { | 1580 if (isolate_snapshot_data_buffer == NULL) { |
1578 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 1581 RETURN_NULL_ERROR(isolate_snapshot_data_buffer); |
1579 } | 1582 } |
1580 if (isolate_snapshot_size == NULL) { | 1583 if (isolate_snapshot_data_size == NULL) { |
1581 RETURN_NULL_ERROR(isolate_snapshot_size); | 1584 RETURN_NULL_ERROR(isolate_snapshot_data_size); |
1582 } | 1585 } |
1583 // Finalize all classes if needed. | 1586 // Finalize all classes if needed. |
1584 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 1587 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
1585 if (::Dart_IsError(state)) { | 1588 if (::Dart_IsError(state)) { |
1586 return state; | 1589 return state; |
1587 } | 1590 } |
1588 I->StopBackgroundCompiler(); | 1591 I->StopBackgroundCompiler(); |
1589 | 1592 |
1590 #if defined(DEBUG) | 1593 #if defined(DEBUG) |
1591 I->heap()->CollectAllGarbage(); | 1594 I->heap()->CollectAllGarbage(); |
1592 CheckFunctionTypesVisitor check_canonical(T); | 1595 CheckFunctionTypesVisitor check_canonical(T); |
1593 I->heap()->IterateObjects(&check_canonical); | 1596 I->heap()->IterateObjects(&check_canonical); |
1594 #endif // #if defined(DEBUG) | 1597 #endif // #if defined(DEBUG) |
1595 | 1598 |
1596 Symbols::Compact(I); | 1599 Symbols::Compact(I); |
1597 | 1600 |
1598 FullSnapshotWriter writer(Snapshot::kCore, vm_isolate_snapshot_buffer, | 1601 FullSnapshotWriter writer(Snapshot::kCore, vm_snapshot_data_buffer, |
1599 isolate_snapshot_buffer, ApiReallocate, | 1602 isolate_snapshot_data_buffer, ApiReallocate, |
1600 NULL /* instructions_writer */); | 1603 NULL /* vm_instructions_writer */, |
| 1604 NULL /* isolate_instructions_writer */); |
1601 writer.WriteFullSnapshot(); | 1605 writer.WriteFullSnapshot(); |
1602 if (vm_isolate_snapshot_buffer != NULL) { | 1606 if (vm_snapshot_data_buffer != NULL) { |
1603 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1607 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
1604 } | 1608 } |
1605 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1609 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
1606 return Api::Success(); | 1610 return Api::Success(); |
1607 } | 1611 } |
1608 | 1612 |
1609 | 1613 |
1610 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1614 DART_EXPORT Dart_Handle |
1611 intptr_t* size) { | 1615 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer, |
| 1616 intptr_t* script_snapshot_size) { |
1612 API_TIMELINE_DURATION; | 1617 API_TIMELINE_DURATION; |
1613 DARTSCOPE(Thread::Current()); | 1618 DARTSCOPE(Thread::Current()); |
1614 Isolate* I = T->isolate(); | 1619 Isolate* I = T->isolate(); |
1615 if (buffer == NULL) { | 1620 if (script_snapshot_buffer == NULL) { |
1616 RETURN_NULL_ERROR(buffer); | 1621 RETURN_NULL_ERROR(script_snapshot_buffer); |
1617 } | 1622 } |
1618 if (size == NULL) { | 1623 if (script_snapshot_size == NULL) { |
1619 RETURN_NULL_ERROR(size); | 1624 RETURN_NULL_ERROR(script_snapshot_size); |
1620 } | 1625 } |
1621 // Finalize all classes if needed. | 1626 // Finalize all classes if needed. |
1622 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 1627 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
1623 if (::Dart_IsError(state)) { | 1628 if (::Dart_IsError(state)) { |
1624 return state; | 1629 return state; |
1625 } | 1630 } |
1626 Library& lib = Library::Handle(Z, I->object_store()->root_library()); | 1631 Library& lib = Library::Handle(Z, I->object_store()->root_library()); |
1627 | 1632 |
1628 #if defined(DEBUG) | 1633 #if defined(DEBUG) |
1629 I->heap()->CollectAllGarbage(); | 1634 I->heap()->CollectAllGarbage(); |
1630 CheckFunctionTypesVisitor check_canonical(T); | 1635 CheckFunctionTypesVisitor check_canonical(T); |
1631 I->heap()->IterateObjects(&check_canonical); | 1636 I->heap()->IterateObjects(&check_canonical); |
1632 #endif // #if defined(DEBUG) | 1637 #endif // #if defined(DEBUG) |
1633 | 1638 |
1634 ScriptSnapshotWriter writer(buffer, ApiReallocate); | 1639 ScriptSnapshotWriter writer(script_snapshot_buffer, ApiReallocate); |
1635 writer.WriteScriptSnapshot(lib); | 1640 writer.WriteScriptSnapshot(lib); |
1636 *size = writer.BytesWritten(); | 1641 *script_snapshot_size = writer.BytesWritten(); |
1637 return Api::Success(); | 1642 return Api::Success(); |
1638 } | 1643 } |
1639 | 1644 |
1640 | 1645 |
1641 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1646 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
1642 if (isolate == NULL) { | 1647 if (isolate == NULL) { |
1643 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1648 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1644 } | 1649 } |
1645 // TODO(16615): Validate isolate parameter. | 1650 // TODO(16615): Validate isolate parameter. |
1646 TransitionNativeToVM transition(Thread::Current()); | 1651 TransitionNativeToVM transition(Thread::Current()); |
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3877 redirect_type ^= redirect_type.Canonicalize(); | 3882 redirect_type ^= redirect_type.Canonicalize(); |
3878 } | 3883 } |
3879 | 3884 |
3880 type_obj = redirect_type.raw(); | 3885 type_obj = redirect_type.raw(); |
3881 type_arguments = redirect_type.arguments(); | 3886 type_arguments = redirect_type.arguments(); |
3882 | 3887 |
3883 cls = type_obj.type_class(); | 3888 cls = type_obj.type_class(); |
3884 } | 3889 } |
3885 if (constructor.IsGenerativeConstructor()) { | 3890 if (constructor.IsGenerativeConstructor()) { |
3886 #if defined(DEBUG) | 3891 #if defined(DEBUG) |
3887 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) { | 3892 if (!cls.is_allocated() && |
| 3893 (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) { |
3888 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3894 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
3889 } | 3895 } |
3890 #endif | 3896 #endif |
3891 // Create the new object. | 3897 // Create the new object. |
3892 new_object = Instance::New(cls); | 3898 new_object = Instance::New(cls); |
3893 } | 3899 } |
3894 | 3900 |
3895 // Create the argument list. | 3901 // Create the argument list. |
3896 intptr_t arg_index = 0; | 3902 intptr_t arg_index = 0; |
3897 int extra_args = 1; | 3903 int extra_args = 1; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3972 DARTSCOPE(Thread::Current()); | 3978 DARTSCOPE(Thread::Current()); |
3973 CHECK_CALLBACK_STATE(T); | 3979 CHECK_CALLBACK_STATE(T); |
3974 | 3980 |
3975 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3981 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
3976 // Get the class to instantiate. | 3982 // Get the class to instantiate. |
3977 if (type_obj.IsNull()) { | 3983 if (type_obj.IsNull()) { |
3978 RETURN_TYPE_ERROR(Z, type, Type); | 3984 RETURN_TYPE_ERROR(Z, type, Type); |
3979 } | 3985 } |
3980 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3986 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
3981 #if defined(DEBUG) | 3987 #if defined(DEBUG) |
3982 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) { | 3988 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) { |
3983 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3989 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
3984 } | 3990 } |
3985 #endif | 3991 #endif |
3986 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3992 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
3987 if (!error.IsNull()) { | 3993 if (!error.IsNull()) { |
3988 // An error occurred, return error object. | 3994 // An error occurred, return error object. |
3989 return Api::NewHandle(T, error.raw()); | 3995 return Api::NewHandle(T, error.raw()); |
3990 } | 3996 } |
3991 return Api::NewHandle(T, AllocateObject(T, cls)); | 3997 return Api::NewHandle(T, AllocateObject(T, cls)); |
3992 } | 3998 } |
3993 | 3999 |
3994 | 4000 |
3995 DART_EXPORT Dart_Handle | 4001 DART_EXPORT Dart_Handle |
3996 Dart_AllocateWithNativeFields(Dart_Handle type, | 4002 Dart_AllocateWithNativeFields(Dart_Handle type, |
3997 intptr_t num_native_fields, | 4003 intptr_t num_native_fields, |
3998 const intptr_t* native_fields) { | 4004 const intptr_t* native_fields) { |
3999 DARTSCOPE(Thread::Current()); | 4005 DARTSCOPE(Thread::Current()); |
4000 CHECK_CALLBACK_STATE(T); | 4006 CHECK_CALLBACK_STATE(T); |
4001 | 4007 |
4002 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 4008 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
4003 // Get the class to instantiate. | 4009 // Get the class to instantiate. |
4004 if (type_obj.IsNull()) { | 4010 if (type_obj.IsNull()) { |
4005 RETURN_TYPE_ERROR(Z, type, Type); | 4011 RETURN_TYPE_ERROR(Z, type, Type); |
4006 } | 4012 } |
4007 if (native_fields == NULL) { | 4013 if (native_fields == NULL) { |
4008 RETURN_NULL_ERROR(native_fields); | 4014 RETURN_NULL_ERROR(native_fields); |
4009 } | 4015 } |
4010 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 4016 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
4011 #if defined(DEBUG) | 4017 #if defined(DEBUG) |
4012 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) { | 4018 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) { |
4013 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 4019 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
4014 } | 4020 } |
4015 #endif | 4021 #endif |
4016 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 4022 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
4017 if (!error.IsNull()) { | 4023 if (!error.IsNull()) { |
4018 // An error occurred, return error object. | 4024 // An error occurred, return error object. |
4019 return Api::NewHandle(T, error.raw()); | 4025 return Api::NewHandle(T, error.raw()); |
4020 } | 4026 } |
4021 if (num_native_fields != cls.num_native_fields()) { | 4027 if (num_native_fields != cls.num_native_fields()) { |
4022 return Api::NewError( | 4028 return Api::NewError( |
(...skipping 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6647 RETURN_NULL_ERROR(assembly_buffer); | 6653 RETURN_NULL_ERROR(assembly_buffer); |
6648 } | 6654 } |
6649 if (assembly_size == NULL) { | 6655 if (assembly_size == NULL) { |
6650 RETURN_NULL_ERROR(assembly_size); | 6656 RETURN_NULL_ERROR(assembly_size); |
6651 } | 6657 } |
6652 | 6658 |
6653 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6659 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
6654 "WriteAppAOTSnapshot")); | 6660 "WriteAppAOTSnapshot")); |
6655 AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate, | 6661 AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate, |
6656 2 * MB /* initial_size */); | 6662 2 * MB /* initial_size */); |
6657 uint8_t* vm_isolate_snapshot_buffer = NULL; | 6663 uint8_t* vm_snapshot_data_buffer = NULL; |
6658 uint8_t* isolate_snapshot_buffer = NULL; | 6664 uint8_t* isolate_snapshot_data_buffer = NULL; |
6659 FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_isolate_snapshot_buffer, | 6665 FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_snapshot_data_buffer, |
6660 &isolate_snapshot_buffer, ApiReallocate, | 6666 &isolate_snapshot_data_buffer, ApiReallocate, |
6661 &instructions_writer); | 6667 &instructions_writer, &instructions_writer); |
6662 | 6668 |
6663 writer.WriteFullSnapshot(); | 6669 writer.WriteFullSnapshot(); |
6664 *assembly_size = instructions_writer.AssemblySize(); | 6670 *assembly_size = instructions_writer.AssemblySize(); |
6665 | 6671 |
6666 return Api::Success(); | 6672 return Api::Success(); |
6667 #endif | 6673 #endif |
6668 } | 6674 } |
6669 | 6675 |
6670 | 6676 |
6671 DART_EXPORT Dart_Handle | 6677 DART_EXPORT Dart_Handle |
6672 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer, | 6678 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer, |
6673 intptr_t* vm_isolate_snapshot_size, | 6679 intptr_t* vm_snapshot_data_size, |
6674 uint8_t** isolate_snapshot_buffer, | 6680 uint8_t** vm_snapshot_instructions_buffer, |
6675 intptr_t* isolate_snapshot_size, | 6681 intptr_t* vm_snapshot_instructions_size, |
6676 uint8_t** instructions_blob_buffer, | 6682 uint8_t** isolate_snapshot_data_buffer, |
6677 intptr_t* instructions_blob_size, | 6683 intptr_t* isolate_snapshot_data_size, |
6678 uint8_t** rodata_blob_buffer, | 6684 uint8_t** isolate_snapshot_instructions_buffer, |
6679 intptr_t* rodata_blob_size) { | 6685 intptr_t* isolate_snapshot_instructions_size) { |
6680 #if defined(TARGET_ARCH_IA32) | 6686 #if defined(TARGET_ARCH_IA32) |
6681 return Api::NewError("AOT compilation is not supported on IA32."); | 6687 return Api::NewError("AOT compilation is not supported on IA32."); |
6682 #elif defined(TARGET_ARCH_DBC) | 6688 #elif defined(TARGET_ARCH_DBC) |
6683 return Api::NewError("AOT compilation is not supported on DBC."); | 6689 return Api::NewError("AOT compilation is not supported on DBC."); |
6684 #elif !defined(DART_PRECOMPILER) | 6690 #elif !defined(DART_PRECOMPILER) |
6685 return Api::NewError( | 6691 return Api::NewError( |
6686 "This VM was built without support for AOT compilation."); | 6692 "This VM was built without support for AOT compilation."); |
6687 #else | 6693 #else |
6688 API_TIMELINE_DURATION; | 6694 API_TIMELINE_DURATION; |
6689 DARTSCOPE(Thread::Current()); | 6695 DARTSCOPE(Thread::Current()); |
6690 Isolate* I = T->isolate(); | 6696 Isolate* I = T->isolate(); |
6691 if (I->compilation_allowed()) { | 6697 if (I->compilation_allowed()) { |
6692 return Api::NewError( | 6698 return Api::NewError( |
6693 "Isolate is not precompiled. " | 6699 "Isolate is not precompiled. " |
6694 "Did you forget to call Dart_Precompile?"); | 6700 "Did you forget to call Dart_Precompile?"); |
6695 } | 6701 } |
6696 ASSERT(FLAG_load_deferred_eagerly); | 6702 ASSERT(FLAG_load_deferred_eagerly); |
6697 if (vm_isolate_snapshot_buffer == NULL) { | 6703 if (vm_snapshot_data_buffer == NULL) { |
6698 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6704 RETURN_NULL_ERROR(vm_snapshot_data_buffer); |
6699 } | 6705 } |
6700 if (vm_isolate_snapshot_size == NULL) { | 6706 if (vm_snapshot_data_size == NULL) { |
6701 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6707 RETURN_NULL_ERROR(vm_snapshot_data_size); |
6702 } | 6708 } |
6703 if (isolate_snapshot_buffer == NULL) { | 6709 if (vm_snapshot_instructions_buffer == NULL) { |
6704 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6710 RETURN_NULL_ERROR(vm_snapshot_instructions_buffer); |
6705 } | 6711 } |
6706 if (isolate_snapshot_size == NULL) { | 6712 if (vm_snapshot_instructions_size == NULL) { |
6707 RETURN_NULL_ERROR(isolate_snapshot_size); | 6713 RETURN_NULL_ERROR(vm_snapshot_instructions_size); |
6708 } | 6714 } |
6709 if (instructions_blob_buffer == NULL) { | 6715 if (isolate_snapshot_data_buffer == NULL) { |
6710 RETURN_NULL_ERROR(instructions_blob_buffer); | 6716 RETURN_NULL_ERROR(isolate_snapshot_data_buffer); |
6711 } | 6717 } |
6712 if (instructions_blob_size == NULL) { | 6718 if (isolate_snapshot_data_size == NULL) { |
6713 RETURN_NULL_ERROR(instructions_blob_size); | 6719 RETURN_NULL_ERROR(isolate_snapshot_data_size); |
6714 } | 6720 } |
6715 if (rodata_blob_buffer == NULL) { | 6721 if (isolate_snapshot_instructions_buffer == NULL) { |
6716 RETURN_NULL_ERROR(instructions_blob_buffer); | 6722 RETURN_NULL_ERROR(instructions_snapshot_blob_buffer); |
6717 } | 6723 } |
6718 if (rodata_blob_size == NULL) { | 6724 if (isolate_snapshot_instructions_buffer == NULL) { |
6719 RETURN_NULL_ERROR(instructions_blob_size); | 6725 RETURN_NULL_ERROR(instructions_snapshot_blob_size); |
6720 } | 6726 } |
6721 | 6727 |
6722 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6728 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
6723 "WriteAppAOTSnapshot")); | 6729 "WriteAppAOTSnapshot")); |
6724 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, | 6730 BlobInstructionsWriter vm_instructions_writer(vm_snapshot_instructions_buffer, |
6725 rodata_blob_buffer, ApiReallocate, | 6731 ApiReallocate, |
6726 2 * MB /* initial_size */); | 6732 2 * MB /* initial_size */); |
6727 FullSnapshotWriter writer(Snapshot::kAppAOT, vm_isolate_snapshot_buffer, | 6733 BlobInstructionsWriter isolate_instructions_writer( |
6728 isolate_snapshot_buffer, ApiReallocate, | 6734 isolate_snapshot_instructions_buffer, ApiReallocate, |
6729 &instructions_writer); | 6735 2 * MB /* initial_size */); |
| 6736 FullSnapshotWriter writer( |
| 6737 Snapshot::kAppAOT, vm_snapshot_data_buffer, isolate_snapshot_data_buffer, |
| 6738 ApiReallocate, &vm_instructions_writer, &isolate_instructions_writer); |
6730 | 6739 |
6731 writer.WriteFullSnapshot(); | 6740 writer.WriteFullSnapshot(); |
6732 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6741 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
6733 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6742 *vm_snapshot_instructions_size = |
6734 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); | 6743 vm_instructions_writer.InstructionsBlobSize(); |
6735 *rodata_blob_size = instructions_writer.RodataBlobSize(); | 6744 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6745 *isolate_snapshot_instructions_size = |
| 6746 isolate_instructions_writer.InstructionsBlobSize(); |
6736 | 6747 |
6737 return Api::Success(); | 6748 return Api::Success(); |
6738 #endif | 6749 #endif |
6739 } | 6750 } |
6740 | 6751 |
6741 | 6752 |
6742 DART_EXPORT Dart_Handle | 6753 DART_EXPORT Dart_Handle |
6743 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer, | 6754 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, |
6744 intptr_t* isolate_snapshot_size, | 6755 intptr_t* isolate_snapshot_data_size, |
6745 uint8_t** instructions_blob_buffer, | 6756 uint8_t** isolate_snapshot_instructions_buffer, |
6746 intptr_t* instructions_blob_size, | 6757 intptr_t* isolate_snapshot_instructions_size) { |
6747 uint8_t** rodata_blob_buffer, | |
6748 intptr_t* rodata_blob_size) { | |
6749 #if defined(TARGET_ARCH_IA32) | 6758 #if defined(TARGET_ARCH_IA32) |
6750 return Api::NewError("Snapshots with code are not supported on IA32."); | 6759 return Api::NewError("Snapshots with code are not supported on IA32."); |
6751 #elif defined(TARGET_ARCH_DBC) | 6760 #elif defined(TARGET_ARCH_DBC) |
6752 return Api::NewError("Snapshots with code are not supported on DBC."); | 6761 return Api::NewError("Snapshots with code are not supported on DBC."); |
6753 #elif defined(DART_PRECOMPILED_RUNTIME) | 6762 #elif defined(DART_PRECOMPILED_RUNTIME) |
6754 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime"); | 6763 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime"); |
6755 #else | 6764 #else |
6756 API_TIMELINE_DURATION; | 6765 API_TIMELINE_DURATION; |
6757 DARTSCOPE(Thread::Current()); | 6766 DARTSCOPE(Thread::Current()); |
6758 Isolate* I = T->isolate(); | 6767 Isolate* I = T->isolate(); |
6759 if (!FLAG_load_deferred_eagerly) { | 6768 if (!FLAG_load_deferred_eagerly) { |
6760 return Api::NewError( | 6769 return Api::NewError( |
6761 "Creating full snapshots requires --load_deferred_eagerly"); | 6770 "Creating full snapshots requires --load_deferred_eagerly"); |
6762 } | 6771 } |
6763 if (isolate_snapshot_buffer == NULL) { | 6772 if (isolate_snapshot_data_buffer == NULL) { |
6764 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6773 RETURN_NULL_ERROR(isolate_snapshot_data_buffer); |
6765 } | 6774 } |
6766 if (isolate_snapshot_size == NULL) { | 6775 if (isolate_snapshot_data_size == NULL) { |
6767 RETURN_NULL_ERROR(isolate_snapshot_size); | 6776 RETURN_NULL_ERROR(isolate_snapshot_data_size); |
6768 } | 6777 } |
6769 if (instructions_blob_buffer == NULL) { | 6778 if (isolate_snapshot_instructions_buffer == NULL) { |
6770 RETURN_NULL_ERROR(instructions_blob_buffer); | 6779 RETURN_NULL_ERROR(instructions_snapshot_blob_buffer); |
6771 } | 6780 } |
6772 if (instructions_blob_size == NULL) { | 6781 if (isolate_snapshot_instructions_buffer == NULL) { |
6773 RETURN_NULL_ERROR(instructions_blob_size); | 6782 RETURN_NULL_ERROR(instructions_snapshot_blob_size); |
6774 } | |
6775 if (rodata_blob_buffer == NULL) { | |
6776 RETURN_NULL_ERROR(instructions_blob_buffer); | |
6777 } | |
6778 if (rodata_blob_size == NULL) { | |
6779 RETURN_NULL_ERROR(instructions_blob_size); | |
6780 } | 6783 } |
6781 // Finalize all classes if needed. | 6784 // Finalize all classes if needed. |
6782 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 6785 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
6783 if (::Dart_IsError(state)) { | 6786 if (::Dart_IsError(state)) { |
6784 return state; | 6787 return state; |
6785 } | 6788 } |
6786 I->StopBackgroundCompiler(); | 6789 I->StopBackgroundCompiler(); |
6787 | 6790 |
6788 Symbols::Compact(I); | 6791 Symbols::Compact(I); |
6789 | 6792 |
6790 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6793 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
6791 "WriteAppJITSnapshot")); | 6794 "WriteAppJITSnapshot")); |
6792 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, | 6795 BlobInstructionsWriter isolate_instructions_writer( |
6793 rodata_blob_buffer, ApiReallocate, | 6796 isolate_snapshot_instructions_buffer, ApiReallocate, |
6794 2 * MB /* initial_size */); | 6797 2 * MB /* initial_size */); |
6795 FullSnapshotWriter writer(Snapshot::kAppJIT, NULL, isolate_snapshot_buffer, | 6798 FullSnapshotWriter writer(Snapshot::kAppJIT, NULL, |
6796 ApiReallocate, &instructions_writer); | 6799 isolate_snapshot_data_buffer, ApiReallocate, NULL, |
| 6800 &isolate_instructions_writer); |
6797 writer.WriteFullSnapshot(); | 6801 writer.WriteFullSnapshot(); |
6798 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6802 |
6799 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); | 6803 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
6800 *rodata_blob_size = instructions_writer.RodataBlobSize(); | 6804 *isolate_snapshot_instructions_size = |
| 6805 isolate_instructions_writer.InstructionsBlobSize(); |
6801 | 6806 |
6802 return Api::Success(); | 6807 return Api::Success(); |
6803 #endif | 6808 #endif |
6804 } | 6809 } |
6805 | 6810 |
6806 | 6811 |
6807 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6812 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
6808 #if defined(DART_PRECOMPILED_RUNTIME) | 6813 #if defined(DART_PRECOMPILED_RUNTIME) |
6809 return true; | 6814 return true; |
6810 #else | 6815 #else |
6811 return false; | 6816 return false; |
6812 #endif | 6817 #endif |
6813 } | 6818 } |
6814 | 6819 |
6815 | 6820 |
6816 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { | 6821 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { |
6817 #ifndef PRODUCT | 6822 #ifndef PRODUCT |
6818 Profiler::DumpStackTrace(context); | 6823 Profiler::DumpStackTrace(context); |
6819 #endif | 6824 #endif |
6820 } | 6825 } |
6821 | 6826 |
6822 } // namespace dart | 6827 } // namespace dart |
OLD | NEW |