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

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

Issue 1023753006: First step towards splitting a full snapshot into a vm isolate snapshot and a (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/unit_test.h » ('j') | 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"
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 "class FieldsTest {\n" 1022 "class FieldsTest {\n"
1023 " static Fields testMain() {\n" 1023 " static Fields testMain() {\n"
1024 " Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n" 1024 " Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n"
1025 " Fields obj = new Fields(10, 20);\n" 1025 " Fields obj = new Fields(10, 20);\n"
1026 " Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n" 1026 " Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n"
1027 " return obj;\n" 1027 " return obj;\n"
1028 " }\n" 1028 " }\n"
1029 "}\n"; 1029 "}\n";
1030 Dart_Handle result; 1030 Dart_Handle result;
1031 1031
1032 uint8_t* buffer; 1032 uint8_t* vm_isolate_snapshot_buffer;
1033 uint8_t* isolate_snapshot_buffer;
1033 1034
1034 // Start an Isolate, load a script and create a full snapshot. 1035 // Start an Isolate, load a script and create a full snapshot.
1035 Timer timer1(true, "Snapshot_test"); 1036 Timer timer1(true, "Snapshot_test");
1036 timer1.Start(); 1037 timer1.Start();
1037 { 1038 {
1038 TestIsolateScope __test_isolate__; 1039 TestIsolateScope __test_isolate__;
1039 1040
1040 Isolate* isolate = Isolate::Current(); 1041 Isolate* isolate = Isolate::Current();
1041 StackZone zone(isolate); 1042 StackZone zone(isolate);
1042 HandleScope scope(isolate); 1043 HandleScope scope(isolate);
1043 1044
1044 // Create a test library and Load up a test script in it. 1045 // Create a test library and Load up a test script in it.
1045 TestCase::LoadTestScript(kScriptChars, NULL); 1046 TestCase::LoadTestScript(kScriptChars, NULL);
1046 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); 1047 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate));
1047 timer1.Stop(); 1048 timer1.Stop();
1048 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1049 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1049 1050
1050 // Write snapshot with object content. 1051 // Write snapshot with object content.
1051 FullSnapshotWriter writer(&buffer, &malloc_allocator); 1052 FullSnapshotWriter writer(&vm_isolate_snapshot_buffer,
1053 &isolate_snapshot_buffer,
1054 &malloc_allocator);
1052 writer.WriteFullSnapshot(); 1055 writer.WriteFullSnapshot();
1053 } 1056 }
1054 1057
1055 // Now Create another isolate using the snapshot and execute a method 1058 // Now Create another isolate using the snapshot and execute a method
1056 // from the script. 1059 // from the script.
1057 Timer timer2(true, "Snapshot_test"); 1060 Timer timer2(true, "Snapshot_test");
1058 timer2.Start(); 1061 timer2.Start();
1059 TestCase::CreateTestIsolateFromSnapshot(buffer); 1062 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer);
1060 { 1063 {
1061 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1064 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1062 timer2.Stop(); 1065 timer2.Stop();
1063 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); 1066 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime());
1064 1067
1065 // Invoke a function which returns an object. 1068 // Invoke a function which returns an object.
1066 Dart_Handle cls = 1069 Dart_Handle cls =
1067 Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); 1070 Dart_GetClass(TestCase::lib(), NewString("FieldsTest"));
1068 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1071 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1069 EXPECT_VALID(result); 1072 EXPECT_VALID(result);
1070 Dart_ExitScope(); 1073 Dart_ExitScope();
1071 } 1074 }
1072 Dart_ShutdownIsolate(); 1075 Dart_ShutdownIsolate();
1073 free(buffer); 1076 free(isolate_snapshot_buffer);
1074 } 1077 }
1075 1078
1076 1079
1077 UNIT_TEST_CASE(FullSnapshot1) { 1080 UNIT_TEST_CASE(FullSnapshot1) {
1078 // This buffer has to be static for this to compile with Visual Studio. 1081 // This buffer has to be static for this to compile with Visual Studio.
1079 // If it is not static compilation of this file with Visual Studio takes 1082 // If it is not static compilation of this file with Visual Studio takes
1080 // more than 30 minutes! 1083 // more than 30 minutes!
1081 static const char kFullSnapshotScriptChars[] = { 1084 static const char kFullSnapshotScriptChars[] = {
1082 #include "snapshot_test.dat" 1085 #include "snapshot_test.dat"
1083 }; 1086 };
1084 const char* kScriptChars = kFullSnapshotScriptChars; 1087 const char* kScriptChars = kFullSnapshotScriptChars;
1085 1088
1086 uint8_t* buffer; 1089 uint8_t* vm_isolate_snapshot_buffer;
1090 uint8_t* isolate_snapshot_buffer;
1087 1091
1088 // Start an Isolate, load a script and create a full snapshot. 1092 // Start an Isolate, load a script and create a full snapshot.
1089 Timer timer1(true, "Snapshot_test"); 1093 Timer timer1(true, "Snapshot_test");
1090 timer1.Start(); 1094 timer1.Start();
1091 { 1095 {
1092 TestIsolateScope __test_isolate__; 1096 TestIsolateScope __test_isolate__;
1093 1097
1094 Isolate* isolate = Isolate::Current(); 1098 Isolate* isolate = Isolate::Current();
1095 StackZone zone(isolate); 1099 StackZone zone(isolate);
1096 HandleScope scope(isolate); 1100 HandleScope scope(isolate);
1097 1101
1098 // Create a test library and Load up a test script in it. 1102 // Create a test library and Load up a test script in it.
1099 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1103 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1100 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); 1104 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate));
1101 timer1.Stop(); 1105 timer1.Stop();
1102 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1106 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1103 1107
1104 // Write snapshot with object content. 1108 // Write snapshot with object content.
1105 FullSnapshotWriter writer(&buffer, &malloc_allocator); 1109 FullSnapshotWriter writer(&vm_isolate_snapshot_buffer,
1110 &isolate_snapshot_buffer,
1111 &malloc_allocator);
1106 writer.WriteFullSnapshot(); 1112 writer.WriteFullSnapshot();
1107 1113
1108 // Invoke a function which returns an object. 1114 // Invoke a function which returns an object.
1109 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); 1115 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest"));
1110 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1116 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1111 EXPECT_VALID(result); 1117 EXPECT_VALID(result);
1112 } 1118 }
1113 1119
1114 // Now Create another isolate using the snapshot and execute a method 1120 // Now Create another isolate using the snapshot and execute a method
1115 // from the script. 1121 // from the script.
1116 Timer timer2(true, "Snapshot_test"); 1122 Timer timer2(true, "Snapshot_test");
1117 timer2.Start(); 1123 timer2.Start();
1118 TestCase::CreateTestIsolateFromSnapshot(buffer); 1124 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer);
1119 { 1125 {
1120 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1126 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1121 timer2.Stop(); 1127 timer2.Stop();
1122 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); 1128 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime());
1123 1129
1124 // Invoke a function which returns an object. 1130 // Invoke a function which returns an object.
1125 Dart_Handle cls = Dart_GetClass(TestCase::lib(), 1131 Dart_Handle cls = Dart_GetClass(TestCase::lib(),
1126 NewString("FieldsTest")); 1132 NewString("FieldsTest"));
1127 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1133 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1128 if (Dart_IsError(result)) { 1134 if (Dart_IsError(result)) {
1129 // Print the error. It is probably an unhandled exception. 1135 // Print the error. It is probably an unhandled exception.
1130 fprintf(stderr, "%s\n", Dart_GetError(result)); 1136 fprintf(stderr, "%s\n", Dart_GetError(result));
1131 } 1137 }
1132 EXPECT_VALID(result); 1138 EXPECT_VALID(result);
1133 Dart_ExitScope(); 1139 Dart_ExitScope();
1134 } 1140 }
1135 Dart_ShutdownIsolate(); 1141 Dart_ShutdownIsolate();
1136 free(buffer); 1142 free(isolate_snapshot_buffer);
1137 } 1143 }
1138 1144
1139 1145
1140 UNIT_TEST_CASE(ScriptSnapshot) { 1146 UNIT_TEST_CASE(ScriptSnapshot) {
1141 const char* kLibScriptChars = 1147 const char* kLibScriptChars =
1142 "library dart_import_lib;" 1148 "library dart_import_lib;"
1143 "class LibFields {" 1149 "class LibFields {"
1144 " LibFields(int i, int j) : fld1 = i, fld2 = j {}" 1150 " LibFields(int i, int j) : fld1 = i, fld2 = j {}"
1145 " int fld1;" 1151 " int fld1;"
1146 " final int fld2;" 1152 " final int fld2;"
(...skipping 29 matching lines...) Expand all
1176 " if (Fields.fld4 != 10) {" 1182 " if (Fields.fld4 != 10) {"
1177 " throw new Exception('Fields.fld4 needs to be 10');" 1183 " throw new Exception('Fields.fld4 needs to be 10');"
1178 " }" 1184 " }"
1179 " return obj;" 1185 " return obj;"
1180 " }" 1186 " }"
1181 "}"; 1187 "}";
1182 Dart_Handle result; 1188 Dart_Handle result;
1183 1189
1184 uint8_t* buffer; 1190 uint8_t* buffer;
1185 intptr_t size; 1191 intptr_t size;
1192 uint8_t* vm_isolate_snapshot = NULL;
1193 intptr_t vm_isolate_snapshot_size;
1194 uint8_t* isolate_snapshot = NULL;
1195 intptr_t isolate_snapshot_size;
1186 uint8_t* full_snapshot = NULL; 1196 uint8_t* full_snapshot = NULL;
1187 uint8_t* script_snapshot = NULL; 1197 uint8_t* script_snapshot = NULL;
1188 intptr_t expected_num_libs; 1198 intptr_t expected_num_libs;
1189 intptr_t actual_num_libs; 1199 intptr_t actual_num_libs;
1190 1200
1191 { 1201 {
1192 // Start an Isolate, and create a full snapshot of it. 1202 // Start an Isolate, and create a full snapshot of it.
1193 TestIsolateScope __test_isolate__; 1203 TestIsolateScope __test_isolate__;
1194 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1204 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1195 1205
1196 // Write out the script snapshot. 1206 // Write out the script snapshot.
1197 result = Dart_CreateSnapshot(&buffer, &size); 1207 result = Dart_CreateSnapshot(&vm_isolate_snapshot,
1208 &vm_isolate_snapshot_size,
1209 &isolate_snapshot,
1210 &isolate_snapshot_size);
1198 EXPECT_VALID(result); 1211 EXPECT_VALID(result);
1199 full_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 1212 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1200 memmove(full_snapshot, buffer, size); 1213 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1201 Dart_ExitScope(); 1214 Dart_ExitScope();
1202 } 1215 }
1203 1216
1204 { 1217 {
1205 // Create an Isolate using the full snapshot, load a script and create 1218 // Create an Isolate using the full snapshot, load a script and create
1206 // a script snapshot of the script. 1219 // a script snapshot of the script.
1207 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1220 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1208 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1221 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1209 1222
1210 // Load the library. 1223 // Load the library.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 UNIT_TEST_CASE(ScriptSnapshot1) { 1281 UNIT_TEST_CASE(ScriptSnapshot1) {
1269 const char* kScriptChars = 1282 const char* kScriptChars =
1270 "class _SimpleNumEnumerable<T extends num> {" 1283 "class _SimpleNumEnumerable<T extends num> {"
1271 "final Iterable<T> _source;" 1284 "final Iterable<T> _source;"
1272 "const _SimpleNumEnumerable(this._source) : super();" 1285 "const _SimpleNumEnumerable(this._source) : super();"
1273 "}"; 1286 "}";
1274 1287
1275 Dart_Handle result; 1288 Dart_Handle result;
1276 uint8_t* buffer; 1289 uint8_t* buffer;
1277 intptr_t size; 1290 intptr_t size;
1291 uint8_t* vm_isolate_snapshot = NULL;
1292 intptr_t vm_isolate_snapshot_size;
1293 uint8_t* isolate_snapshot = NULL;
1294 intptr_t isolate_snapshot_size;
1278 uint8_t* full_snapshot = NULL; 1295 uint8_t* full_snapshot = NULL;
1279 uint8_t* script_snapshot = NULL; 1296 uint8_t* script_snapshot = NULL;
1280 1297
1281 { 1298 {
1282 // Start an Isolate, and create a full snapshot of it. 1299 // Start an Isolate, and create a full snapshot of it.
1283 TestIsolateScope __test_isolate__; 1300 TestIsolateScope __test_isolate__;
1284 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1301 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1285 1302
1286 // Write out the script snapshot. 1303 // Write out the script snapshot.
1287 result = Dart_CreateSnapshot(&buffer, &size); 1304 result = Dart_CreateSnapshot(&vm_isolate_snapshot,
1305 &vm_isolate_snapshot_size,
1306 &isolate_snapshot,
1307 &isolate_snapshot_size);
1288 EXPECT_VALID(result); 1308 EXPECT_VALID(result);
1289 full_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 1309 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1290 memmove(full_snapshot, buffer, size); 1310 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1291 Dart_ExitScope(); 1311 Dart_ExitScope();
1292 } 1312 }
1293 1313
1294 { 1314 {
1295 // Create an Isolate using the full snapshot, load a script and create 1315 // Create an Isolate using the full snapshot, load a script and create
1296 // a script snapshot of the script. 1316 // a script snapshot of the script.
1297 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1317 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1298 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1318 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1299 1319
1300 // Create a test library and Load up a test script in it. 1320 // Create a test library and Load up a test script in it.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 "test_i() {" 1365 "test_i() {"
1346 " i;" 1366 " i;"
1347 "}" 1367 "}"
1348 "test_b() {" 1368 "test_b() {"
1349 " b = 0;" 1369 " b = 0;"
1350 "}"; 1370 "}";
1351 Dart_Handle result; 1371 Dart_Handle result;
1352 1372
1353 uint8_t* buffer; 1373 uint8_t* buffer;
1354 intptr_t size; 1374 intptr_t size;
1375 uint8_t* vm_isolate_snapshot = NULL;
1376 intptr_t vm_isolate_snapshot_size;
1377 uint8_t* isolate_snapshot = NULL;
1378 intptr_t isolate_snapshot_size;
1355 uint8_t* full_snapshot = NULL; 1379 uint8_t* full_snapshot = NULL;
1356 uint8_t* script_snapshot = NULL; 1380 uint8_t* script_snapshot = NULL;
1357 1381
1358 // Force creation of snapshot in production mode. 1382 // Force creation of snapshot in production mode.
1359 bool saved_mode = FLAG_enable_type_checks; 1383 bool saved_mode = FLAG_enable_type_checks;
1360 FLAG_enable_type_checks = false; 1384 FLAG_enable_type_checks = false;
1361 1385
1362 { 1386 {
1363 // Start an Isolate, and create a full snapshot of it. 1387 // Start an Isolate, and create a full snapshot of it.
1364 TestIsolateScope __test_isolate__; 1388 TestIsolateScope __test_isolate__;
1365 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1389 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1366 1390
1367 // Write out the script snapshot. 1391 // Write out the script snapshot.
1368 result = Dart_CreateSnapshot(&buffer, &size); 1392 result = Dart_CreateSnapshot(&vm_isolate_snapshot,
1393 &vm_isolate_snapshot_size,
1394 &isolate_snapshot,
1395 &isolate_snapshot_size);
1369 EXPECT_VALID(result); 1396 EXPECT_VALID(result);
1370 full_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 1397 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1371 memmove(full_snapshot, buffer, size); 1398 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1372 Dart_ExitScope(); 1399 Dart_ExitScope();
1373 } 1400 }
1374 1401
1375 { 1402 {
1376 // Create an Isolate using the full snapshot, load a script and create 1403 // Create an Isolate using the full snapshot, load a script and create
1377 // a script snapshot of the script. 1404 // a script snapshot of the script.
1378 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1405 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1379 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1406 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1380 1407
1381 // Load the library. 1408 // Load the library.
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 StackZone zone(Isolate::Current()); 2758 StackZone zone(Isolate::Current());
2732 uint8_t* buffer; 2759 uint8_t* buffer;
2733 MessageWriter writer(&buffer, &zone_allocator, true); 2760 MessageWriter writer(&buffer, &zone_allocator, true);
2734 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2761 writer.WriteInlinedObjectHeader(kOmittedObjectId);
2735 // For performance, we'd like single-byte headers when ids are omitted. 2762 // For performance, we'd like single-byte headers when ids are omitted.
2736 // If this starts failing, consider renumbering the snapshot ids. 2763 // If this starts failing, consider renumbering the snapshot ids.
2737 EXPECT_EQ(1, writer.BytesWritten()); 2764 EXPECT_EQ(1, writer.BytesWritten());
2738 } 2765 }
2739 2766
2740 } // namespace dart 2767 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698