| OLD | NEW |
| 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_tools_api.h" | 7 #include "include/dart_tools_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/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 "class FieldsTest {\n" | 1157 "class FieldsTest {\n" |
| 1158 " static Fields testMain() {\n" | 1158 " static Fields testMain() {\n" |
| 1159 " Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n" | 1159 " Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n" |
| 1160 " Fields obj = new Fields(10, 20);\n" | 1160 " Fields obj = new Fields(10, 20);\n" |
| 1161 " Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n" | 1161 " Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n" |
| 1162 " return obj;\n" | 1162 " return obj;\n" |
| 1163 " }\n" | 1163 " }\n" |
| 1164 "}\n"; | 1164 "}\n"; |
| 1165 Dart_Handle result; | 1165 Dart_Handle result; |
| 1166 | 1166 |
| 1167 uint8_t* isolate_snapshot_buffer; | 1167 uint8_t* isolate_snapshot_data_buffer; |
| 1168 | 1168 |
| 1169 // Start an Isolate, load a script and create a full snapshot. | 1169 // Start an Isolate, load a script and create a full snapshot. |
| 1170 Timer timer1(true, "Snapshot_test"); | 1170 Timer timer1(true, "Snapshot_test"); |
| 1171 timer1.Start(); | 1171 timer1.Start(); |
| 1172 { | 1172 { |
| 1173 TestIsolateScope __test_isolate__; | 1173 TestIsolateScope __test_isolate__; |
| 1174 | 1174 |
| 1175 Thread* thread = Thread::Current(); | 1175 Thread* thread = Thread::Current(); |
| 1176 StackZone zone(thread); | 1176 StackZone zone(thread); |
| 1177 HandleScope scope(thread); | 1177 HandleScope scope(thread); |
| 1178 | 1178 |
| 1179 // Create a test library and Load up a test script in it. | 1179 // Create a test library and Load up a test script in it. |
| 1180 TestCase::LoadTestScript(kScriptChars, NULL); | 1180 TestCase::LoadTestScript(kScriptChars, NULL); |
| 1181 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread)); | 1181 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread)); |
| 1182 timer1.Stop(); | 1182 timer1.Stop(); |
| 1183 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); | 1183 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); |
| 1184 | 1184 |
| 1185 // Write snapshot with object content. | 1185 // Write snapshot with object content. |
| 1186 { | 1186 { |
| 1187 FullSnapshotWriter writer(Snapshot::kCore, NULL, &isolate_snapshot_buffer, | 1187 FullSnapshotWriter writer( |
| 1188 &malloc_allocator, | 1188 Snapshot::kCore, NULL, &isolate_snapshot_data_buffer, |
| 1189 NULL /* instructions_writer */); | 1189 &malloc_allocator, NULL, NULL /* instructions_writer */); |
| 1190 writer.WriteFullSnapshot(); | 1190 writer.WriteFullSnapshot(); |
| 1191 } | 1191 } |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 // Now Create another isolate using the snapshot and execute a method | 1194 // Now Create another isolate using the snapshot and execute a method |
| 1195 // from the script. | 1195 // from the script. |
| 1196 Timer timer2(true, "Snapshot_test"); | 1196 Timer timer2(true, "Snapshot_test"); |
| 1197 timer2.Start(); | 1197 timer2.Start(); |
| 1198 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer); | 1198 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_data_buffer); |
| 1199 { | 1199 { |
| 1200 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1200 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1201 timer2.Stop(); | 1201 timer2.Stop(); |
| 1202 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); | 1202 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); |
| 1203 | 1203 |
| 1204 // Invoke a function which returns an object. | 1204 // Invoke a function which returns an object. |
| 1205 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); | 1205 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); |
| 1206 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1206 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
| 1207 EXPECT_VALID(result); | 1207 EXPECT_VALID(result); |
| 1208 Dart_ExitScope(); | 1208 Dart_ExitScope(); |
| 1209 } | 1209 } |
| 1210 Dart_ShutdownIsolate(); | 1210 Dart_ShutdownIsolate(); |
| 1211 free(isolate_snapshot_buffer); | 1211 free(isolate_snapshot_data_buffer); |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 | 1214 |
| 1215 UNIT_TEST_CASE(FullSnapshot1) { | 1215 UNIT_TEST_CASE(FullSnapshot1) { |
| 1216 // This buffer has to be static for this to compile with Visual Studio. | 1216 // This buffer has to be static for this to compile with Visual Studio. |
| 1217 // If it is not static compilation of this file with Visual Studio takes | 1217 // If it is not static compilation of this file with Visual Studio takes |
| 1218 // more than 30 minutes! | 1218 // more than 30 minutes! |
| 1219 static const char kFullSnapshotScriptChars[] = { | 1219 static const char kFullSnapshotScriptChars[] = { |
| 1220 #include "snapshot_test.dat" | 1220 #include "snapshot_test.dat" |
| 1221 }; | 1221 }; |
| 1222 const char* kScriptChars = kFullSnapshotScriptChars; | 1222 const char* kScriptChars = kFullSnapshotScriptChars; |
| 1223 | 1223 |
| 1224 uint8_t* isolate_snapshot_buffer; | 1224 uint8_t* isolate_snapshot_data_buffer; |
| 1225 | 1225 |
| 1226 // Start an Isolate, load a script and create a full snapshot. | 1226 // Start an Isolate, load a script and create a full snapshot. |
| 1227 Timer timer1(true, "Snapshot_test"); | 1227 Timer timer1(true, "Snapshot_test"); |
| 1228 timer1.Start(); | 1228 timer1.Start(); |
| 1229 { | 1229 { |
| 1230 TestIsolateScope __test_isolate__; | 1230 TestIsolateScope __test_isolate__; |
| 1231 | 1231 |
| 1232 Thread* thread = Thread::Current(); | 1232 Thread* thread = Thread::Current(); |
| 1233 StackZone zone(thread); | 1233 StackZone zone(thread); |
| 1234 HandleScope scope(thread); | 1234 HandleScope scope(thread); |
| 1235 | 1235 |
| 1236 // Create a test library and Load up a test script in it. | 1236 // Create a test library and Load up a test script in it. |
| 1237 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1237 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1238 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread)); | 1238 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(thread)); |
| 1239 timer1.Stop(); | 1239 timer1.Stop(); |
| 1240 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); | 1240 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); |
| 1241 | 1241 |
| 1242 // Write snapshot with object content. | 1242 // Write snapshot with object content. |
| 1243 { | 1243 { |
| 1244 FullSnapshotWriter writer(Snapshot::kCore, NULL, &isolate_snapshot_buffer, | 1244 FullSnapshotWriter writer( |
| 1245 &malloc_allocator, | 1245 Snapshot::kCore, NULL, &isolate_snapshot_data_buffer, |
| 1246 NULL /* instructions_writer */); | 1246 &malloc_allocator, NULL, NULL /* instructions_writer */); |
| 1247 writer.WriteFullSnapshot(); | 1247 writer.WriteFullSnapshot(); |
| 1248 } | 1248 } |
| 1249 | 1249 |
| 1250 // Invoke a function which returns an object. | 1250 // Invoke a function which returns an object. |
| 1251 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); | 1251 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); |
| 1252 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1252 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
| 1253 EXPECT_VALID(result); | 1253 EXPECT_VALID(result); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 // Now Create another isolate using the snapshot and execute a method | 1256 // Now Create another isolate using the snapshot and execute a method |
| 1257 // from the script. | 1257 // from the script. |
| 1258 Timer timer2(true, "Snapshot_test"); | 1258 Timer timer2(true, "Snapshot_test"); |
| 1259 timer2.Start(); | 1259 timer2.Start(); |
| 1260 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer); | 1260 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_data_buffer); |
| 1261 { | 1261 { |
| 1262 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1262 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1263 timer2.Stop(); | 1263 timer2.Stop(); |
| 1264 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); | 1264 OS::PrintErr("From Snapshot: %" Pd64 "us\n", timer2.TotalElapsedTime()); |
| 1265 | 1265 |
| 1266 // Invoke a function which returns an object. | 1266 // Invoke a function which returns an object. |
| 1267 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); | 1267 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); |
| 1268 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1268 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
| 1269 if (Dart_IsError(result)) { | 1269 if (Dart_IsError(result)) { |
| 1270 // Print the error. It is probably an unhandled exception. | 1270 // Print the error. It is probably an unhandled exception. |
| 1271 fprintf(stderr, "%s\n", Dart_GetError(result)); | 1271 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 1272 } | 1272 } |
| 1273 EXPECT_VALID(result); | 1273 EXPECT_VALID(result); |
| 1274 Dart_ExitScope(); | 1274 Dart_ExitScope(); |
| 1275 } | 1275 } |
| 1276 Dart_ShutdownIsolate(); | 1276 Dart_ShutdownIsolate(); |
| 1277 free(isolate_snapshot_buffer); | 1277 free(isolate_snapshot_data_buffer); |
| 1278 } | 1278 } |
| 1279 | 1279 |
| 1280 | 1280 |
| 1281 #ifndef PRODUCT | 1281 #ifndef PRODUCT |
| 1282 | 1282 |
| 1283 | 1283 |
| 1284 UNIT_TEST_CASE(ScriptSnapshot) { | 1284 UNIT_TEST_CASE(ScriptSnapshot) { |
| 1285 const char* kLibScriptChars = | 1285 const char* kLibScriptChars = |
| 1286 "library dart_import_lib;" | 1286 "library dart_import_lib;" |
| 1287 "class LibFields {" | 1287 "class LibFields {" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); | 1654 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); |
| 1655 memmove(script_snapshot, buffer, size); | 1655 memmove(script_snapshot, buffer, size); |
| 1656 Dart_ExitScope(); | 1656 Dart_ExitScope(); |
| 1657 Dart_ShutdownIsolate(); | 1657 Dart_ShutdownIsolate(); |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 { | 1660 { |
| 1661 // Use a script snapshot where a full snapshot is expected. | 1661 // Use a script snapshot where a full snapshot is expected. |
| 1662 char* error = NULL; | 1662 char* error = NULL; |
| 1663 Dart_Isolate isolate = Dart_CreateIsolate( | 1663 Dart_Isolate isolate = Dart_CreateIsolate( |
| 1664 "script-uri", "main", script_snapshot, NULL, NULL, &error); | 1664 "script-uri", "main", script_snapshot, NULL, NULL, NULL, &error); |
| 1665 EXPECT(isolate == NULL); | 1665 EXPECT(isolate == NULL); |
| 1666 EXPECT(error != NULL); | 1666 EXPECT(error != NULL); |
| 1667 EXPECT_SUBSTRING("got 'script', expected 'core'", error); | 1667 EXPECT_SUBSTRING( |
| 1668 "Incompatible snapshot kinds:" |
| 1669 " vm 'core', isolate 'script'", |
| 1670 error); |
| 1668 free(error); | 1671 free(error); |
| 1669 } | 1672 } |
| 1670 | 1673 |
| 1671 { | 1674 { |
| 1672 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); | 1675 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| 1673 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1676 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1674 | 1677 |
| 1675 // Use a full snapshot where a script snapshot is expected. | 1678 // Use a full snapshot where a script snapshot is expected. |
| 1676 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); | 1679 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); |
| 1677 EXPECT_ERROR(result, | 1680 EXPECT_ERROR(result, |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3000 StackZone zone(Thread::Current()); | 3003 StackZone zone(Thread::Current()); |
| 3001 uint8_t* buffer; | 3004 uint8_t* buffer; |
| 3002 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 3005 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
| 3003 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3006 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
| 3004 // For performance, we'd like single-byte headers when ids are omitted. | 3007 // For performance, we'd like single-byte headers when ids are omitted. |
| 3005 // If this starts failing, consider renumbering the snapshot ids. | 3008 // If this starts failing, consider renumbering the snapshot ids. |
| 3006 EXPECT_EQ(1, writer.BytesWritten()); | 3009 EXPECT_EQ(1, writer.BytesWritten()); |
| 3007 } | 3010 } |
| 3008 | 3011 |
| 3009 } // namespace dart | 3012 } // namespace dart |
| OLD | NEW |