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

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

Issue 1155183003: Load deferred classes eagerly when generating script snapshots (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Redo disappearing CL 1155183003 (Load deferred classes eagerly when generating script snapshots) Created 5 years, 6 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
11 #include "vm/dart_api_message.h" 11 #include "vm/dart_api_message.h"
12 #include "vm/dart_api_state.h" 12 #include "vm/dart_api_state.h"
13 #include "vm/flags.h" 13 #include "vm/flags.h"
14 #include "vm/snapshot.h" 14 #include "vm/snapshot.h"
15 #include "vm/symbols.h" 15 #include "vm/symbols.h"
16 #include "vm/unicode.h" 16 #include "vm/unicode.h"
17 #include "vm/unit_test.h" 17 #include "vm/unit_test.h"
18 18
19 namespace dart { 19 namespace dart {
20 20
21 DECLARE_FLAG(bool, enable_type_checks); 21 DECLARE_FLAG(bool, enable_type_checks);
22 DECLARE_FLAG(bool, load_deferred_eagerly);
22 23
23 // Check if serialized and deserialized objects are equal. 24 // Check if serialized and deserialized objects are equal.
24 static bool Equals(const Object& expected, const Object& actual) { 25 static bool Equals(const Object& expected, const Object& actual) {
25 if (expected.IsNull()) { 26 if (expected.IsNull()) {
26 return actual.IsNull(); 27 return actual.IsNull();
27 } 28 }
28 if (expected.IsSmi()) { 29 if (expected.IsSmi()) {
29 if (actual.IsSmi()) { 30 if (actual.IsSmi()) {
30 return expected.raw() == actual.raw(); 31 return expected.raw() == actual.raw();
31 } 32 }
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 uint8_t* buffer; 1226 uint8_t* buffer;
1226 intptr_t size; 1227 intptr_t size;
1227 intptr_t vm_isolate_snapshot_size; 1228 intptr_t vm_isolate_snapshot_size;
1228 uint8_t* isolate_snapshot = NULL; 1229 uint8_t* isolate_snapshot = NULL;
1229 intptr_t isolate_snapshot_size; 1230 intptr_t isolate_snapshot_size;
1230 uint8_t* full_snapshot = NULL; 1231 uint8_t* full_snapshot = NULL;
1231 uint8_t* script_snapshot = NULL; 1232 uint8_t* script_snapshot = NULL;
1232 intptr_t expected_num_libs; 1233 intptr_t expected_num_libs;
1233 intptr_t actual_num_libs; 1234 intptr_t actual_num_libs;
1234 1235
1236 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1237 FLAG_load_deferred_eagerly = true;
1238
1235 { 1239 {
1236 // Start an Isolate, and create a full snapshot of it. 1240 // Start an Isolate, and create a full snapshot of it.
1237 TestIsolateScope __test_isolate__; 1241 TestIsolateScope __test_isolate__;
1238 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1242 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1239 1243
1240 // Write out the script snapshot. 1244 // Write out the script snapshot.
1241 result = Dart_CreateSnapshot(NULL, 1245 result = Dart_CreateSnapshot(NULL,
1242 &vm_isolate_snapshot_size, 1246 &vm_isolate_snapshot_size,
1243 &isolate_snapshot, 1247 &isolate_snapshot,
1244 &isolate_snapshot_size); 1248 &isolate_snapshot_size);
1245 EXPECT_VALID(result); 1249 EXPECT_VALID(result);
1246 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1250 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1247 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1251 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1248 Dart_ExitScope(); 1252 Dart_ExitScope();
1249 } 1253 }
1250 1254
1255 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1251 { 1256 {
1252 // Create an Isolate using the full snapshot, load a script and create 1257 // Create an Isolate using the full snapshot, load a script and create
1253 // a script snapshot of the script. 1258 // a script snapshot of the script.
1254 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1259 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1255 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1260 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1256 1261
1257 // Load the library. 1262 // Load the library.
1258 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"), 1263 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"),
1259 NewString(kLibScriptChars), 1264 NewString(kLibScriptChars),
1260 0, 0); 1265 0, 0);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 1326
1322 Dart_Handle result; 1327 Dart_Handle result;
1323 uint8_t* buffer; 1328 uint8_t* buffer;
1324 intptr_t size; 1329 intptr_t size;
1325 intptr_t vm_isolate_snapshot_size; 1330 intptr_t vm_isolate_snapshot_size;
1326 uint8_t* isolate_snapshot = NULL; 1331 uint8_t* isolate_snapshot = NULL;
1327 intptr_t isolate_snapshot_size; 1332 intptr_t isolate_snapshot_size;
1328 uint8_t* full_snapshot = NULL; 1333 uint8_t* full_snapshot = NULL;
1329 uint8_t* script_snapshot = NULL; 1334 uint8_t* script_snapshot = NULL;
1330 1335
1336 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1337 FLAG_load_deferred_eagerly = true;
1331 { 1338 {
1332 // Start an Isolate, and create a full snapshot of it. 1339 // Start an Isolate, and create a full snapshot of it.
1333 TestIsolateScope __test_isolate__; 1340 TestIsolateScope __test_isolate__;
1334 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1341 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1335 1342
1336 // Write out the script snapshot. 1343 // Write out the script snapshot.
1337 result = Dart_CreateSnapshot(NULL, 1344 result = Dart_CreateSnapshot(NULL,
1338 &vm_isolate_snapshot_size, 1345 &vm_isolate_snapshot_size,
1339 &isolate_snapshot, 1346 &isolate_snapshot,
1340 &isolate_snapshot_size); 1347 &isolate_snapshot_size);
(...skipping 25 matching lines...) Expand all
1366 // Now Create an Isolate using the full snapshot and load the 1373 // Now Create an Isolate using the full snapshot and load the
1367 // script snapshot created above and execute it. 1374 // script snapshot created above and execute it.
1368 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1375 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1369 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1376 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1370 1377
1371 // Load the test library from the snapshot. 1378 // Load the test library from the snapshot.
1372 EXPECT(script_snapshot != NULL); 1379 EXPECT(script_snapshot != NULL);
1373 result = Dart_LoadScriptFromSnapshot(script_snapshot, size); 1380 result = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1374 EXPECT_VALID(result); 1381 EXPECT_VALID(result);
1375 } 1382 }
1383
1384 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1376 Dart_ShutdownIsolate(); 1385 Dart_ShutdownIsolate();
1377 free(full_snapshot); 1386 free(full_snapshot);
1378 free(script_snapshot); 1387 free(script_snapshot);
1379 } 1388 }
1380 1389
1381 1390
1382 UNIT_TEST_CASE(ScriptSnapshot2) { 1391 UNIT_TEST_CASE(ScriptSnapshot2) {
1383 // The snapshot of this library is always created in production mode, but 1392 // The snapshot of this library is always created in production mode, but
1384 // loaded and executed in both production and checked modes. 1393 // loaded and executed in both production and checked modes.
1385 // This test verifies that type information is still contained in the snapshot 1394 // This test verifies that type information is still contained in the snapshot
(...skipping 19 matching lines...) Expand all
1405 1414
1406 uint8_t* buffer; 1415 uint8_t* buffer;
1407 intptr_t size; 1416 intptr_t size;
1408 intptr_t vm_isolate_snapshot_size; 1417 intptr_t vm_isolate_snapshot_size;
1409 uint8_t* isolate_snapshot = NULL; 1418 uint8_t* isolate_snapshot = NULL;
1410 intptr_t isolate_snapshot_size; 1419 intptr_t isolate_snapshot_size;
1411 uint8_t* full_snapshot = NULL; 1420 uint8_t* full_snapshot = NULL;
1412 uint8_t* script_snapshot = NULL; 1421 uint8_t* script_snapshot = NULL;
1413 1422
1414 // Force creation of snapshot in production mode. 1423 // Force creation of snapshot in production mode.
1415 bool saved_mode = FLAG_enable_type_checks; 1424 bool saved_enable_type_checks_mode = FLAG_enable_type_checks;
1416 FLAG_enable_type_checks = false; 1425 FLAG_enable_type_checks = false;
1426 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1427 FLAG_load_deferred_eagerly = true;
1417 1428
1418 { 1429 {
1419 // Start an Isolate, and create a full snapshot of it. 1430 // Start an Isolate, and create a full snapshot of it.
1420 TestIsolateScope __test_isolate__; 1431 TestIsolateScope __test_isolate__;
1421 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1432 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1422 1433
1423 // Write out the script snapshot. 1434 // Write out the script snapshot.
1424 result = Dart_CreateSnapshot(NULL, 1435 result = Dart_CreateSnapshot(NULL,
1425 &vm_isolate_snapshot_size, 1436 &vm_isolate_snapshot_size,
1426 &isolate_snapshot, 1437 &isolate_snapshot,
(...skipping 27 matching lines...) Expand all
1454 // Write out the script snapshot. 1465 // Write out the script snapshot.
1455 result = Dart_CreateScriptSnapshot(&buffer, &size); 1466 result = Dart_CreateScriptSnapshot(&buffer, &size);
1456 EXPECT_VALID(result); 1467 EXPECT_VALID(result);
1457 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 1468 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1458 memmove(script_snapshot, buffer, size); 1469 memmove(script_snapshot, buffer, size);
1459 Dart_ExitScope(); 1470 Dart_ExitScope();
1460 Dart_ShutdownIsolate(); 1471 Dart_ShutdownIsolate();
1461 } 1472 }
1462 1473
1463 // Continue in originally saved mode. 1474 // Continue in originally saved mode.
1464 FLAG_enable_type_checks = saved_mode; 1475 FLAG_enable_type_checks = saved_enable_type_checks_mode;
1476 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1465 1477
1466 { 1478 {
1467 // Now Create an Isolate using the full snapshot and load the 1479 // Now Create an Isolate using the full snapshot and load the
1468 // script snapshot created above and execute it. 1480 // script snapshot created above and execute it.
1469 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1481 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1470 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1482 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1471 1483
1472 // Load the test library from the snapshot. 1484 // Load the test library from the snapshot.
1473 EXPECT(script_snapshot != NULL); 1485 EXPECT(script_snapshot != NULL);
1474 Dart_Handle lib = Dart_LoadScriptFromSnapshot(script_snapshot, size); 1486 Dart_Handle lib = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1475 EXPECT_VALID(lib); 1487 EXPECT_VALID(lib);
1476 1488
1477 // Invoke the test_s function. 1489 // Invoke the test_s function.
1478 result = Dart_Invoke(lib, NewString("test_s"), 0, NULL); 1490 result = Dart_Invoke(lib, NewString("test_s"), 0, NULL);
1479 EXPECT(Dart_IsError(result) == saved_mode); 1491 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode);
1480 1492
1481 // Invoke the test_i function. 1493 // Invoke the test_i function.
1482 result = Dart_Invoke(lib, NewString("test_i"), 0, NULL); 1494 result = Dart_Invoke(lib, NewString("test_i"), 0, NULL);
1483 EXPECT(Dart_IsError(result) == saved_mode); 1495 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode);
1484 1496
1485 // Invoke the test_b function. 1497 // Invoke the test_b function.
1486 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL); 1498 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL);
1487 EXPECT(Dart_IsError(result) == saved_mode); 1499 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode);
1488 } 1500 }
1489 Dart_ShutdownIsolate(); 1501 Dart_ShutdownIsolate();
1490 free(full_snapshot); 1502 free(full_snapshot);
1491 free(script_snapshot); 1503 free(script_snapshot);
1492 } 1504 }
1493 1505
1494 1506
1495 TEST_CASE(IntArrayMessage) { 1507 TEST_CASE(IntArrayMessage) {
1496 StackZone zone(Isolate::Current()); 1508 StackZone zone(Isolate::Current());
1497 uint8_t* buffer = NULL; 1509 uint8_t* buffer = NULL;
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
2793 StackZone zone(Isolate::Current()); 2805 StackZone zone(Isolate::Current());
2794 uint8_t* buffer; 2806 uint8_t* buffer;
2795 MessageWriter writer(&buffer, &zone_allocator, true); 2807 MessageWriter writer(&buffer, &zone_allocator, true);
2796 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2808 writer.WriteInlinedObjectHeader(kOmittedObjectId);
2797 // For performance, we'd like single-byte headers when ids are omitted. 2809 // For performance, we'd like single-byte headers when ids are omitted.
2798 // If this starts failing, consider renumbering the snapshot ids. 2810 // If this starts failing, consider renumbering the snapshot ids.
2799 EXPECT_EQ(1, writer.BytesWritten()); 2811 EXPECT_EQ(1, writer.BytesWritten());
2800 } 2812 }
2801 2813
2802 } // namespace dart 2814 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698