Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(785)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 2622053002: Refactor snapshots pieces to include a section for loading instructions into the heap of a regular … (Closed)
Patch Set: Restore --print-snapshot-sizes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 "Dart_Initialize: " 1165 "Dart_Initialize: "
1166 "Dart_InitializeParams is null."); 1166 "Dart_InitializeParams is null.");
1167 } 1167 }
1168 1168
1169 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { 1169 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) {
1170 return strdup( 1170 return strdup(
1171 "Dart_Initialize: " 1171 "Dart_Initialize: "
1172 "Invalid Dart_InitializeParams version."); 1172 "Invalid Dart_InitializeParams version.");
1173 } 1173 }
1174 1174
1175 return Dart::InitOnce(params->vm_isolate_snapshot, 1175 return Dart::InitOnce(
1176 params->instructions_snapshot, params->data_snapshot, 1176 params->vm_snapshot_data, params->vm_snapshot_instructions,
1177 params->create, params->shutdown, params->thread_exit, 1177 params->create, params->shutdown, params->thread_exit, params->file_open,
1178 params->file_open, params->file_read, 1178 params->file_read, params->file_write, params->file_close,
1179 params->file_write, params->file_close, 1179 params->entropy_source, params->get_service_assets);
1180 params->entropy_source, params->get_service_assets);
1181 } 1180 }
1182 1181
1183 1182
1184 DART_EXPORT char* Dart_Cleanup() { 1183 DART_EXPORT char* Dart_Cleanup() {
1185 CHECK_NO_ISOLATE(Isolate::Current()); 1184 CHECK_NO_ISOLATE(Isolate::Current());
1186 const char* err_msg = Dart::Cleanup(); 1185 const char* err_msg = Dart::Cleanup();
1187 if (err_msg != NULL) { 1186 if (err_msg != NULL) {
1188 return strdup(err_msg); 1187 return strdup(err_msg);
1189 } 1188 }
1190 return NULL; 1189 return NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 char* chars = NULL; 1232 char* chars = NULL;
1234 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; 1233 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1;
1235 chars = reinterpret_cast<char*>(malloc(len)); 1234 chars = reinterpret_cast<char*>(malloc(len));
1236 OS::SNPrint(chars, len, "%s$%s", script_uri, main); 1235 OS::SNPrint(chars, len, "%s$%s", script_uri, main);
1237 return chars; 1236 return chars;
1238 } 1237 }
1239 1238
1240 1239
1241 static Dart_Isolate CreateIsolate(const char* script_uri, 1240 static Dart_Isolate CreateIsolate(const char* script_uri,
1242 const char* main, 1241 const char* main,
1243 const uint8_t* snapshot_buffer, 1242 const uint8_t* snapshot_data,
1243 const uint8_t* snapshot_instructions,
1244 intptr_t snapshot_length, 1244 intptr_t snapshot_length,
1245 kernel::Program* kernel_program, 1245 kernel::Program* kernel_program,
1246 Dart_IsolateFlags* flags, 1246 Dart_IsolateFlags* flags,
1247 void* callback_data, 1247 void* callback_data,
1248 char** error) { 1248 char** error) {
1249 CHECK_NO_ISOLATE(Isolate::Current()); 1249 CHECK_NO_ISOLATE(Isolate::Current());
1250 char* isolate_name = BuildIsolateName(script_uri, main); 1250 char* isolate_name = BuildIsolateName(script_uri, main);
1251 1251
1252 // Setup default flags in case none were passed. 1252 // Setup default flags in case none were passed.
1253 Dart_IsolateFlags api_flags; 1253 Dart_IsolateFlags api_flags;
1254 if (flags == NULL) { 1254 if (flags == NULL) {
1255 Isolate::FlagsInitialize(&api_flags); 1255 Isolate::FlagsInitialize(&api_flags);
1256 flags = &api_flags; 1256 flags = &api_flags;
1257 } 1257 }
1258 Isolate* I = Dart::CreateIsolate(isolate_name, *flags); 1258 Isolate* I = Dart::CreateIsolate(isolate_name, *flags);
1259 free(isolate_name); 1259 free(isolate_name);
1260 if (I == NULL) { 1260 if (I == NULL) {
1261 *error = strdup("Isolate creation failed"); 1261 *error = strdup("Isolate creation failed");
1262 return reinterpret_cast<Dart_Isolate>(NULL); 1262 return reinterpret_cast<Dart_Isolate>(NULL);
1263 } 1263 }
1264 { 1264 {
1265 Thread* T = Thread::Current(); 1265 Thread* T = Thread::Current();
1266 StackZone zone(T); 1266 StackZone zone(T);
1267 HANDLESCOPE(T); 1267 HANDLESCOPE(T);
1268 // We enter an API scope here as InitializeIsolate could compile some 1268 // We enter an API scope here as InitializeIsolate could compile some
1269 // bootstrap library files which call out to a tag handler that may create 1269 // bootstrap library files which call out to a tag handler that may create
1270 // Api Handles when an error is encountered. 1270 // Api Handles when an error is encountered.
1271 Dart_EnterScope(); 1271 Dart_EnterScope();
1272 const Error& error_obj = Error::Handle( 1272 const Error& error_obj =
1273 Z, Dart::InitializeIsolate(snapshot_buffer, snapshot_length, 1273 Error::Handle(Z, Dart::InitializeIsolate(
1274 kernel_program, callback_data)); 1274 snapshot_data, snapshot_instructions,
1275 snapshot_length, kernel_program, callback_data));
1275 if (error_obj.IsNull()) { 1276 if (error_obj.IsNull()) {
1276 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) 1277 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT)
1277 if (FLAG_check_function_fingerprints && kernel_program == NULL) { 1278 if (FLAG_check_function_fingerprints && kernel_program == NULL) {
1278 Library::CheckFunctionFingerprints(); 1279 Library::CheckFunctionFingerprints();
1279 } 1280 }
1280 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). 1281 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT).
1281 // We exit the API scope entered above. 1282 // We exit the API scope entered above.
1282 Dart_ExitScope(); 1283 Dart_ExitScope();
1283 // A Thread structure has been associated to the thread, we do the 1284 // A Thread structure has been associated to the thread, we do the
1284 // safepoint transition explicity here instead of using the 1285 // safepoint transition explicity here instead of using the
1285 // TransitionXXX scope objects as the reverse transition happens 1286 // TransitionXXX scope objects as the reverse transition happens
1286 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. 1287 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate.
1287 T->set_execution_state(Thread::kThreadInNative); 1288 T->set_execution_state(Thread::kThreadInNative);
1288 T->EnterSafepoint(); 1289 T->EnterSafepoint();
1289 return Api::CastIsolate(I); 1290 return Api::CastIsolate(I);
1290 } 1291 }
1291 *error = strdup(error_obj.ToErrorCString()); 1292 *error = strdup(error_obj.ToErrorCString());
1292 // We exit the API scope entered above. 1293 // We exit the API scope entered above.
1293 Dart_ExitScope(); 1294 Dart_ExitScope();
1294 } 1295 }
1295 Dart::ShutdownIsolate(); 1296 Dart::ShutdownIsolate();
1296 return reinterpret_cast<Dart_Isolate>(NULL); 1297 return reinterpret_cast<Dart_Isolate>(NULL);
1297 } 1298 }
1298 1299
1299 1300
1300 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, 1301 DART_EXPORT Dart_Isolate
1301 const char* main, 1302 Dart_CreateIsolate(const char* script_uri,
1302 const uint8_t* snapshot_buffer, 1303 const char* main,
1303 Dart_IsolateFlags* flags, 1304 const uint8_t* snapshot_data,
1304 void* callback_data, 1305 const uint8_t* snapshot_instructions,
1305 char** error) { 1306 Dart_IsolateFlags* flags,
1306 return CreateIsolate(script_uri, main, snapshot_buffer, -1, NULL, flags, 1307 void* callback_data,
1307 callback_data, error); 1308 char** error) {
1309 return CreateIsolate(script_uri, main, snapshot_data, snapshot_instructions,
1310 -1, NULL, flags, callback_data, error);
1308 } 1311 }
1309 1312
1310 1313
1311 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri, 1314 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri,
1312 const char* main, 1315 const char* main,
1313 void* kernel_program, 1316 void* kernel_program,
1314 Dart_IsolateFlags* flags, 1317 Dart_IsolateFlags* flags,
1315 void* callback_data, 1318 void* callback_data,
1316 char** error) { 1319 char** error) {
1317 return CreateIsolate(script_uri, main, NULL, -1, 1320 return CreateIsolate(script_uri, main, NULL, NULL, -1,
1318 reinterpret_cast<kernel::Program*>(kernel_program), 1321 reinterpret_cast<kernel::Program*>(kernel_program),
1319 flags, callback_data, error); 1322 flags, callback_data, error);
1320 } 1323 }
1321 1324
1322 1325
1323 DART_EXPORT void Dart_ShutdownIsolate() { 1326 DART_EXPORT void Dart_ShutdownIsolate() {
1324 Thread* T = Thread::Current(); 1327 Thread* T = Thread::Current();
1325 Isolate* I = T->isolate(); 1328 Isolate* I = T->isolate();
1326 CHECK_ISOLATE(I); 1329 CHECK_ISOLATE(I);
1327 I->WaitForOutstandingSpawns(); 1330 I->WaitForOutstandingSpawns();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 static uint8_t* ApiReallocate(uint8_t* ptr, 1540 static uint8_t* ApiReallocate(uint8_t* ptr,
1538 intptr_t old_size, 1541 intptr_t old_size,
1539 intptr_t new_size) { 1542 intptr_t new_size) {
1540 return Api::TopScope(Thread::Current()) 1543 return Api::TopScope(Thread::Current())
1541 ->zone() 1544 ->zone()
1542 ->Realloc<uint8_t>(ptr, old_size, new_size); 1545 ->Realloc<uint8_t>(ptr, old_size, new_size);
1543 } 1546 }
1544 1547
1545 1548
1546 DART_EXPORT Dart_Handle 1549 DART_EXPORT Dart_Handle
1547 Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer, 1550 Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer,
1548 intptr_t* vm_isolate_snapshot_size, 1551 intptr_t* vm_snapshot_data_size,
1549 uint8_t** isolate_snapshot_buffer, 1552 uint8_t** isolate_snapshot_data_buffer,
1550 intptr_t* isolate_snapshot_size) { 1553 intptr_t* isolate_snapshot_data_size) {
1551 DARTSCOPE(Thread::Current()); 1554 DARTSCOPE(Thread::Current());
1552 API_TIMELINE_DURATION; 1555 API_TIMELINE_DURATION;
1553 Isolate* I = T->isolate(); 1556 Isolate* I = T->isolate();
1554 if (!FLAG_load_deferred_eagerly) { 1557 if (!FLAG_load_deferred_eagerly) {
1555 return Api::NewError( 1558 return Api::NewError(
1556 "Creating full snapshots requires --load_deferred_eagerly"); 1559 "Creating full snapshots requires --load_deferred_eagerly");
1557 } 1560 }
1558 if (vm_isolate_snapshot_buffer != NULL && vm_isolate_snapshot_size == NULL) { 1561 if (vm_snapshot_data_buffer != NULL && vm_snapshot_data_size == NULL) {
1559 RETURN_NULL_ERROR(vm_isolate_snapshot_size); 1562 RETURN_NULL_ERROR(vm_snapshot_data_size);
1560 } 1563 }
1561 if (isolate_snapshot_buffer == NULL) { 1564 if (isolate_snapshot_data_buffer == NULL) {
1562 RETURN_NULL_ERROR(isolate_snapshot_buffer); 1565 RETURN_NULL_ERROR(isolate_snapshot_data_buffer);
1563 } 1566 }
1564 if (isolate_snapshot_size == NULL) { 1567 if (isolate_snapshot_data_size == NULL) {
1565 RETURN_NULL_ERROR(isolate_snapshot_size); 1568 RETURN_NULL_ERROR(isolate_snapshot_data_size);
1566 } 1569 }
1567 // Finalize all classes if needed. 1570 // Finalize all classes if needed.
1568 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); 1571 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
1569 if (::Dart_IsError(state)) { 1572 if (::Dart_IsError(state)) {
1570 return state; 1573 return state;
1571 } 1574 }
1572 I->StopBackgroundCompiler(); 1575 I->StopBackgroundCompiler();
1573 1576
1574 #if defined(DEBUG) 1577 #if defined(DEBUG)
1575 I->heap()->CollectAllGarbage(); 1578 I->heap()->CollectAllGarbage();
1576 CheckFunctionTypesVisitor check_canonical(T); 1579 CheckFunctionTypesVisitor check_canonical(T);
1577 I->heap()->IterateObjects(&check_canonical); 1580 I->heap()->IterateObjects(&check_canonical);
1578 #endif // #if defined(DEBUG) 1581 #endif // #if defined(DEBUG)
1579 1582
1580 FullSnapshotWriter writer(Snapshot::kCore, vm_isolate_snapshot_buffer, 1583 FullSnapshotWriter writer(Snapshot::kCore, vm_snapshot_data_buffer,
1581 isolate_snapshot_buffer, ApiReallocate, 1584 isolate_snapshot_data_buffer, ApiReallocate,
1582 NULL /* instructions_writer */); 1585 NULL /* vm_instructions_writer */,
1586 NULL /* isolate_instructions_writer */);
1583 writer.WriteFullSnapshot(); 1587 writer.WriteFullSnapshot();
1584 if (vm_isolate_snapshot_buffer != NULL) { 1588 if (vm_snapshot_data_buffer != NULL) {
1585 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 1589 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize();
1586 } 1590 }
1587 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 1591 *isolate_snapshot_data_size = writer.IsolateSnapshotSize();
1588 return Api::Success(); 1592 return Api::Success();
1589 } 1593 }
1590 1594
1591 1595
1592 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, 1596 DART_EXPORT Dart_Handle
1593 intptr_t* size) { 1597 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer,
1598 intptr_t* script_snapshot_size) {
1594 API_TIMELINE_DURATION; 1599 API_TIMELINE_DURATION;
1595 DARTSCOPE(Thread::Current()); 1600 DARTSCOPE(Thread::Current());
1596 Isolate* I = T->isolate(); 1601 Isolate* I = T->isolate();
1597 if (buffer == NULL) { 1602 if (script_snapshot_buffer == NULL) {
1598 RETURN_NULL_ERROR(buffer); 1603 RETURN_NULL_ERROR(script_snapshot_buffer);
1599 } 1604 }
1600 if (size == NULL) { 1605 if (script_snapshot_size == NULL) {
1601 RETURN_NULL_ERROR(size); 1606 RETURN_NULL_ERROR(script_snapshot_size);
1602 } 1607 }
1603 // Finalize all classes if needed. 1608 // Finalize all classes if needed.
1604 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); 1609 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
1605 if (::Dart_IsError(state)) { 1610 if (::Dart_IsError(state)) {
1606 return state; 1611 return state;
1607 } 1612 }
1608 Library& lib = Library::Handle(Z, I->object_store()->root_library()); 1613 Library& lib = Library::Handle(Z, I->object_store()->root_library());
1609 1614
1610 #if defined(DEBUG) 1615 #if defined(DEBUG)
1611 I->heap()->CollectAllGarbage(); 1616 I->heap()->CollectAllGarbage();
1612 CheckFunctionTypesVisitor check_canonical(T); 1617 CheckFunctionTypesVisitor check_canonical(T);
1613 I->heap()->IterateObjects(&check_canonical); 1618 I->heap()->IterateObjects(&check_canonical);
1614 #endif // #if defined(DEBUG) 1619 #endif // #if defined(DEBUG)
1615 1620
1616 ScriptSnapshotWriter writer(buffer, ApiReallocate); 1621 ScriptSnapshotWriter writer(script_snapshot_buffer, ApiReallocate);
1617 writer.WriteScriptSnapshot(lib); 1622 writer.WriteScriptSnapshot(lib);
1618 *size = writer.BytesWritten(); 1623 *script_snapshot_size = writer.BytesWritten();
1619 return Api::Success(); 1624 return Api::Success();
1620 } 1625 }
1621 1626
1622 1627
1623 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { 1628 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) {
1624 if (isolate == NULL) { 1629 if (isolate == NULL) {
1625 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); 1630 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
1626 } 1631 }
1627 // TODO(16615): Validate isolate parameter. 1632 // TODO(16615): Validate isolate parameter.
1628 TransitionNativeToVM transition(Thread::Current()); 1633 TransitionNativeToVM transition(Thread::Current());
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after
3859 redirect_type ^= redirect_type.Canonicalize(); 3864 redirect_type ^= redirect_type.Canonicalize();
3860 } 3865 }
3861 3866
3862 type_obj = redirect_type.raw(); 3867 type_obj = redirect_type.raw();
3863 type_arguments = redirect_type.arguments(); 3868 type_arguments = redirect_type.arguments();
3864 3869
3865 cls = type_obj.type_class(); 3870 cls = type_obj.type_class();
3866 } 3871 }
3867 if (constructor.IsGenerativeConstructor()) { 3872 if (constructor.IsGenerativeConstructor()) {
3868 #if defined(DEBUG) 3873 #if defined(DEBUG)
3869 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) { 3874 if (!cls.is_allocated() &&
3875 (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) {
3870 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 3876 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3871 } 3877 }
3872 #endif 3878 #endif
3873 // Create the new object. 3879 // Create the new object.
3874 new_object = Instance::New(cls); 3880 new_object = Instance::New(cls);
3875 } 3881 }
3876 3882
3877 // Create the argument list. 3883 // Create the argument list.
3878 intptr_t arg_index = 0; 3884 intptr_t arg_index = 0;
3879 int extra_args = 1; 3885 int extra_args = 1;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 DARTSCOPE(Thread::Current()); 3960 DARTSCOPE(Thread::Current());
3955 CHECK_CALLBACK_STATE(T); 3961 CHECK_CALLBACK_STATE(T);
3956 3962
3957 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); 3963 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
3958 // Get the class to instantiate. 3964 // Get the class to instantiate.
3959 if (type_obj.IsNull()) { 3965 if (type_obj.IsNull()) {
3960 RETURN_TYPE_ERROR(Z, type, Type); 3966 RETURN_TYPE_ERROR(Z, type, Type);
3961 } 3967 }
3962 const Class& cls = Class::Handle(Z, type_obj.type_class()); 3968 const Class& cls = Class::Handle(Z, type_obj.type_class());
3963 #if defined(DEBUG) 3969 #if defined(DEBUG)
3964 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) { 3970 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) {
3965 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 3971 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3966 } 3972 }
3967 #endif 3973 #endif
3968 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); 3974 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T));
3969 if (!error.IsNull()) { 3975 if (!error.IsNull()) {
3970 // An error occurred, return error object. 3976 // An error occurred, return error object.
3971 return Api::NewHandle(T, error.raw()); 3977 return Api::NewHandle(T, error.raw());
3972 } 3978 }
3973 return Api::NewHandle(T, AllocateObject(T, cls)); 3979 return Api::NewHandle(T, AllocateObject(T, cls));
3974 } 3980 }
3975 3981
3976 3982
3977 DART_EXPORT Dart_Handle 3983 DART_EXPORT Dart_Handle
3978 Dart_AllocateWithNativeFields(Dart_Handle type, 3984 Dart_AllocateWithNativeFields(Dart_Handle type,
3979 intptr_t num_native_fields, 3985 intptr_t num_native_fields,
3980 const intptr_t* native_fields) { 3986 const intptr_t* native_fields) {
3981 DARTSCOPE(Thread::Current()); 3987 DARTSCOPE(Thread::Current());
3982 CHECK_CALLBACK_STATE(T); 3988 CHECK_CALLBACK_STATE(T);
3983 3989
3984 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); 3990 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
3985 // Get the class to instantiate. 3991 // Get the class to instantiate.
3986 if (type_obj.IsNull()) { 3992 if (type_obj.IsNull()) {
3987 RETURN_TYPE_ERROR(Z, type, Type); 3993 RETURN_TYPE_ERROR(Z, type, Type);
3988 } 3994 }
3989 if (native_fields == NULL) { 3995 if (native_fields == NULL) {
3990 RETURN_NULL_ERROR(native_fields); 3996 RETURN_NULL_ERROR(native_fields);
3991 } 3997 }
3992 const Class& cls = Class::Handle(Z, type_obj.type_class()); 3998 const Class& cls = Class::Handle(Z, type_obj.type_class());
3993 #if defined(DEBUG) 3999 #if defined(DEBUG)
3994 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppAOT)) { 4000 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kAppAOT)) {
3995 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 4001 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3996 } 4002 }
3997 #endif 4003 #endif
3998 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); 4004 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T));
3999 if (!error.IsNull()) { 4005 if (!error.IsNull()) {
4000 // An error occurred, return error object. 4006 // An error occurred, return error object.
4001 return Api::NewHandle(T, error.raw()); 4007 return Api::NewHandle(T, error.raw());
4002 } 4008 }
4003 if (num_native_fields != cls.num_native_fields()) { 4009 if (num_native_fields != cls.num_native_fields()) {
4004 return Api::NewError( 4010 return Api::NewError(
(...skipping 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after
6629 RETURN_NULL_ERROR(assembly_buffer); 6635 RETURN_NULL_ERROR(assembly_buffer);
6630 } 6636 }
6631 if (assembly_size == NULL) { 6637 if (assembly_size == NULL) {
6632 RETURN_NULL_ERROR(assembly_size); 6638 RETURN_NULL_ERROR(assembly_size);
6633 } 6639 }
6634 6640
6635 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), 6641 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
6636 "WriteAppAOTSnapshot")); 6642 "WriteAppAOTSnapshot"));
6637 AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate, 6643 AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate,
6638 2 * MB /* initial_size */); 6644 2 * MB /* initial_size */);
6639 uint8_t* vm_isolate_snapshot_buffer = NULL; 6645 uint8_t* vm_snapshot_data_buffer = NULL;
6640 uint8_t* isolate_snapshot_buffer = NULL; 6646 uint8_t* isolate_snapshot_data_buffer = NULL;
6641 FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_isolate_snapshot_buffer, 6647 FullSnapshotWriter writer(Snapshot::kAppAOT, &vm_snapshot_data_buffer,
6642 &isolate_snapshot_buffer, ApiReallocate, 6648 &isolate_snapshot_data_buffer, ApiReallocate,
6643 &instructions_writer); 6649 &instructions_writer, &instructions_writer);
6644 6650
6645 writer.WriteFullSnapshot(); 6651 writer.WriteFullSnapshot();
6646 *assembly_size = instructions_writer.AssemblySize(); 6652 *assembly_size = instructions_writer.AssemblySize();
6647 6653
6648 return Api::Success(); 6654 return Api::Success();
6649 #endif 6655 #endif
6650 } 6656 }
6651 6657
6652 6658
6653 DART_EXPORT Dart_Handle 6659 DART_EXPORT Dart_Handle
6654 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer, 6660 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer,
6655 intptr_t* vm_isolate_snapshot_size, 6661 intptr_t* vm_snapshot_data_size,
6656 uint8_t** isolate_snapshot_buffer, 6662 uint8_t** vm_snapshot_instructions_buffer,
6657 intptr_t* isolate_snapshot_size, 6663 intptr_t* vm_snapshot_instructions_size,
6658 uint8_t** instructions_blob_buffer, 6664 uint8_t** isolate_snapshot_data_buffer,
6659 intptr_t* instructions_blob_size, 6665 intptr_t* isolate_snapshot_data_size,
6660 uint8_t** rodata_blob_buffer, 6666 uint8_t** isolate_snapshot_instructions_buffer,
6661 intptr_t* rodata_blob_size) { 6667 intptr_t* isolate_snapshot_instructions_size) {
6662 #if defined(TARGET_ARCH_IA32) 6668 #if defined(TARGET_ARCH_IA32)
6663 return Api::NewError("AOT compilation is not supported on IA32."); 6669 return Api::NewError("AOT compilation is not supported on IA32.");
6664 #elif defined(TARGET_ARCH_DBC) 6670 #elif defined(TARGET_ARCH_DBC)
6665 return Api::NewError("AOT compilation is not supported on DBC."); 6671 return Api::NewError("AOT compilation is not supported on DBC.");
6666 #elif !defined(DART_PRECOMPILER) 6672 #elif !defined(DART_PRECOMPILER)
6667 return Api::NewError( 6673 return Api::NewError(
6668 "This VM was built without support for AOT compilation."); 6674 "This VM was built without support for AOT compilation.");
6669 #else 6675 #else
6670 API_TIMELINE_DURATION; 6676 API_TIMELINE_DURATION;
6671 DARTSCOPE(Thread::Current()); 6677 DARTSCOPE(Thread::Current());
6672 Isolate* I = T->isolate(); 6678 Isolate* I = T->isolate();
6673 if (I->compilation_allowed()) { 6679 if (I->compilation_allowed()) {
6674 return Api::NewError( 6680 return Api::NewError(
6675 "Isolate is not precompiled. " 6681 "Isolate is not precompiled. "
6676 "Did you forget to call Dart_Precompile?"); 6682 "Did you forget to call Dart_Precompile?");
6677 } 6683 }
6678 ASSERT(FLAG_load_deferred_eagerly); 6684 ASSERT(FLAG_load_deferred_eagerly);
6679 if (vm_isolate_snapshot_buffer == NULL) { 6685 if (vm_snapshot_data_buffer == NULL) {
6680 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); 6686 RETURN_NULL_ERROR(vm_snapshot_data_buffer);
6681 } 6687 }
6682 if (vm_isolate_snapshot_size == NULL) { 6688 if (vm_snapshot_data_size == NULL) {
6683 RETURN_NULL_ERROR(vm_isolate_snapshot_size); 6689 RETURN_NULL_ERROR(vm_snapshot_data_size);
6684 } 6690 }
6685 if (isolate_snapshot_buffer == NULL) { 6691 if (vm_snapshot_instructions_buffer == NULL) {
6686 RETURN_NULL_ERROR(isolate_snapshot_buffer); 6692 RETURN_NULL_ERROR(vm_snapshot_instructions_buffer);
6687 } 6693 }
6688 if (isolate_snapshot_size == NULL) { 6694 if (vm_snapshot_instructions_size == NULL) {
6689 RETURN_NULL_ERROR(isolate_snapshot_size); 6695 RETURN_NULL_ERROR(vm_snapshot_instructions_size);
6690 } 6696 }
6691 if (instructions_blob_buffer == NULL) { 6697 if (isolate_snapshot_data_buffer == NULL) {
6692 RETURN_NULL_ERROR(instructions_blob_buffer); 6698 RETURN_NULL_ERROR(isolate_snapshot_data_buffer);
6693 } 6699 }
6694 if (instructions_blob_size == NULL) { 6700 if (isolate_snapshot_data_size == NULL) {
6695 RETURN_NULL_ERROR(instructions_blob_size); 6701 RETURN_NULL_ERROR(isolate_snapshot_data_size);
6696 } 6702 }
6697 if (rodata_blob_buffer == NULL) { 6703 if (isolate_snapshot_instructions_buffer == NULL) {
6698 RETURN_NULL_ERROR(instructions_blob_buffer); 6704 RETURN_NULL_ERROR(instructions_snapshot_blob_buffer);
6699 } 6705 }
6700 if (rodata_blob_size == NULL) { 6706 if (isolate_snapshot_instructions_buffer == NULL) {
6701 RETURN_NULL_ERROR(instructions_blob_size); 6707 RETURN_NULL_ERROR(instructions_snapshot_blob_size);
6702 } 6708 }
6703 6709
6704 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), 6710 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
6705 "WriteAppAOTSnapshot")); 6711 "WriteAppAOTSnapshot"));
6706 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, 6712 BlobInstructionsWriter vm_instructions_writer(vm_snapshot_instructions_buffer,
6707 rodata_blob_buffer, ApiReallocate, 6713 ApiReallocate,
6708 2 * MB /* initial_size */); 6714 2 * MB /* initial_size */);
6709 FullSnapshotWriter writer(Snapshot::kAppAOT, vm_isolate_snapshot_buffer, 6715 BlobInstructionsWriter isolate_instructions_writer(
6710 isolate_snapshot_buffer, ApiReallocate, 6716 isolate_snapshot_instructions_buffer, ApiReallocate,
6711 &instructions_writer); 6717 2 * MB /* initial_size */);
6718 FullSnapshotWriter writer(
6719 Snapshot::kAppAOT, vm_snapshot_data_buffer, isolate_snapshot_data_buffer,
6720 ApiReallocate, &vm_instructions_writer, &isolate_instructions_writer);
6712 6721
6713 writer.WriteFullSnapshot(); 6722 writer.WriteFullSnapshot();
6714 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6723 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize();
6715 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6724 *vm_snapshot_instructions_size =
6716 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); 6725 vm_instructions_writer.InstructionsBlobSize();
6717 *rodata_blob_size = instructions_writer.RodataBlobSize(); 6726 *isolate_snapshot_data_size = writer.IsolateSnapshotSize();
6727 *isolate_snapshot_instructions_size =
6728 isolate_instructions_writer.InstructionsBlobSize();
6718 6729
6719 return Api::Success(); 6730 return Api::Success();
6720 #endif 6731 #endif
6721 } 6732 }
6722 6733
6723 6734
6724 DART_EXPORT Dart_Handle 6735 DART_EXPORT Dart_Handle
6725 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer, 6736 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer,
6726 intptr_t* isolate_snapshot_size, 6737 intptr_t* isolate_snapshot_data_size,
6727 uint8_t** instructions_blob_buffer, 6738 uint8_t** isolate_snapshot_instructions_buffer,
6728 intptr_t* instructions_blob_size, 6739 intptr_t* isolate_snapshot_instructions_size) {
6729 uint8_t** rodata_blob_buffer,
6730 intptr_t* rodata_blob_size) {
6731 #if defined(TARGET_ARCH_IA32) 6740 #if defined(TARGET_ARCH_IA32)
6732 return Api::NewError("Snapshots with code are not supported on IA32."); 6741 return Api::NewError("Snapshots with code are not supported on IA32.");
6733 #elif defined(TARGET_ARCH_DBC) 6742 #elif defined(TARGET_ARCH_DBC)
6734 return Api::NewError("Snapshots with code are not supported on DBC."); 6743 return Api::NewError("Snapshots with code are not supported on DBC.");
6735 #elif defined(DART_PRECOMPILED_RUNTIME) 6744 #elif defined(DART_PRECOMPILED_RUNTIME)
6736 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime"); 6745 return Api::NewError("JIT app snapshots cannot be taken from an AOT runtime");
6737 #else 6746 #else
6738 API_TIMELINE_DURATION; 6747 API_TIMELINE_DURATION;
6739 DARTSCOPE(Thread::Current()); 6748 DARTSCOPE(Thread::Current());
6740 Isolate* I = T->isolate(); 6749 Isolate* I = T->isolate();
6741 if (!FLAG_load_deferred_eagerly) { 6750 if (!FLAG_load_deferred_eagerly) {
6742 return Api::NewError( 6751 return Api::NewError(
6743 "Creating full snapshots requires --load_deferred_eagerly"); 6752 "Creating full snapshots requires --load_deferred_eagerly");
6744 } 6753 }
6745 if (isolate_snapshot_buffer == NULL) { 6754 if (isolate_snapshot_data_buffer == NULL) {
6746 RETURN_NULL_ERROR(isolate_snapshot_buffer); 6755 RETURN_NULL_ERROR(isolate_snapshot_data_buffer);
6747 } 6756 }
6748 if (isolate_snapshot_size == NULL) { 6757 if (isolate_snapshot_data_size == NULL) {
6749 RETURN_NULL_ERROR(isolate_snapshot_size); 6758 RETURN_NULL_ERROR(isolate_snapshot_data_size);
6750 } 6759 }
6751 if (instructions_blob_buffer == NULL) { 6760 if (isolate_snapshot_instructions_buffer == NULL) {
6752 RETURN_NULL_ERROR(instructions_blob_buffer); 6761 RETURN_NULL_ERROR(instructions_snapshot_blob_buffer);
6753 } 6762 }
6754 if (instructions_blob_size == NULL) { 6763 if (isolate_snapshot_instructions_buffer == NULL) {
6755 RETURN_NULL_ERROR(instructions_blob_size); 6764 RETURN_NULL_ERROR(instructions_snapshot_blob_size);
6756 }
6757 if (rodata_blob_buffer == NULL) {
6758 RETURN_NULL_ERROR(instructions_blob_buffer);
6759 }
6760 if (rodata_blob_size == NULL) {
6761 RETURN_NULL_ERROR(instructions_blob_size);
6762 } 6765 }
6763 // Finalize all classes if needed. 6766 // Finalize all classes if needed.
6764 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); 6767 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
6765 if (::Dart_IsError(state)) { 6768 if (::Dart_IsError(state)) {
6766 return state; 6769 return state;
6767 } 6770 }
6768 I->StopBackgroundCompiler(); 6771 I->StopBackgroundCompiler();
6769 6772
6770 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), 6773 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
6771 "WriteAppJITSnapshot")); 6774 "WriteAppJITSnapshot"));
6772 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, 6775 BlobInstructionsWriter isolate_instructions_writer(
6773 rodata_blob_buffer, ApiReallocate, 6776 isolate_snapshot_instructions_buffer, ApiReallocate,
6774 2 * MB /* initial_size */); 6777 2 * MB /* initial_size */);
6775 FullSnapshotWriter writer(Snapshot::kAppJIT, NULL, isolate_snapshot_buffer, 6778 FullSnapshotWriter writer(Snapshot::kAppJIT, NULL,
6776 ApiReallocate, &instructions_writer); 6779 isolate_snapshot_data_buffer, ApiReallocate, NULL,
6780 &isolate_instructions_writer);
6777 writer.WriteFullSnapshot(); 6781 writer.WriteFullSnapshot();
6778 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6782
6779 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); 6783 *isolate_snapshot_data_size = writer.IsolateSnapshotSize();
6780 *rodata_blob_size = instructions_writer.RodataBlobSize(); 6784 *isolate_snapshot_instructions_size =
6785 isolate_instructions_writer.InstructionsBlobSize();
6781 6786
6782 return Api::Success(); 6787 return Api::Success();
6783 #endif 6788 #endif
6784 } 6789 }
6785 6790
6786 6791
6787 DART_EXPORT bool Dart_IsPrecompiledRuntime() { 6792 DART_EXPORT bool Dart_IsPrecompiledRuntime() {
6788 #if defined(DART_PRECOMPILED_RUNTIME) 6793 #if defined(DART_PRECOMPILED_RUNTIME)
6789 return true; 6794 return true;
6790 #else 6795 #else
6791 return false; 6796 return false;
6792 #endif 6797 #endif
6793 } 6798 }
6794 6799
6795 6800
6796 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { 6801 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) {
6797 #ifndef PRODUCT 6802 #ifndef PRODUCT
6798 Profiler::DumpStackTrace(context); 6803 Profiler::DumpStackTrace(context);
6799 #endif 6804 #endif
6800 } 6805 }
6801 6806
6802 } // namespace dart 6807 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698