Chromium Code Reviews| Index: runtime/vm/snapshot_test.cc |
| diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc |
| index 510e1eb5d7084bf8ca26fedca1ed149fdbcc469d..a06759cd1acc622215fcc6dabd4d9379699bb255 100644 |
| --- a/runtime/vm/snapshot_test.cc |
| +++ b/runtime/vm/snapshot_test.cc |
| @@ -1002,7 +1002,6 @@ TEST_CASE(SerializeScript) { |
| } |
| -#if !defined(PRODUCT) // Uses deferred loading. |
| VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { |
|
siva
2017/06/12 22:59:42
The comment for !defined(PRODUCT) is incorrect, I
rmacnak
2017/06/12 23:37:42
It uses reflectClass. Updated comment instead.
|
| const char* kScriptChars = |
| "\n" |
| @@ -1031,8 +1030,10 @@ VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { |
| uint8_t* full_snapshot = NULL; |
| uint8_t* script_snapshot = NULL; |
| +#if !defined(PRODUCT) |
| bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; |
| FLAG_load_deferred_eagerly = true; |
| +#endif |
| { |
| // Start an Isolate, and create a full snapshot of it. |
| TestIsolateScope __test_isolate__; |
| @@ -1046,7 +1047,9 @@ VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { |
| memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
| Dart_ExitScope(); |
| } |
| +#if !defined(PRODUCT) |
| FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
| +#endif |
| { |
| // Now Create an Isolate using the full snapshot and load the |
| @@ -1106,7 +1109,120 @@ VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { |
| free(script_snapshot); |
| free(full_snapshot); |
| } |
| + |
| + |
| +VM_UNIT_TEST_CASE(ScriptSnapshotsUpdateSubclasses) { |
| + const char* kScriptChars = |
| + "class _DebugDuration extends Duration {\n" |
| + " const _DebugDuration() : super(milliseconds: 42);\n" |
| + "}\n" |
| + "foo(x, y) {\n" |
| + " for (var i = 0; i < 1000000; i++) {\n" |
| + " if (x != y) {\n" |
| + " throw 'Boom!';\n" |
| + " }\n" |
| + " }\n" |
| + "}\n" |
| + "main() {\n" |
| + " final v = const Duration(milliseconds: 42);\n" |
| + " foo(v, new _DebugDuration());\n" |
| + "}\n" |
| + "\n"; |
| + |
| + Dart_Handle result; |
| + |
| + uint8_t* buffer; |
| + intptr_t size; |
| + intptr_t vm_isolate_snapshot_size; |
| + uint8_t* isolate_snapshot = NULL; |
| + intptr_t isolate_snapshot_size; |
| + uint8_t* full_snapshot = NULL; |
| + uint8_t* script_snapshot = NULL; |
| + |
| +#if !defined(PRODUCT) |
| + bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; |
| + FLAG_load_deferred_eagerly = true; |
| #endif |
| + intptr_t saved_max_polymorphic_checks = FLAG_max_polymorphic_checks; |
| + FLAG_max_polymorphic_checks = 0; |
| + |
| + { |
| + // Start an Isolate, and create a full snapshot of it. |
| + TestIsolateScope __test_isolate__; |
| + Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| + |
| + // Write out the script snapshot. |
| + result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, |
| + &isolate_snapshot, &isolate_snapshot_size); |
| + EXPECT_VALID(result); |
| + full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
| + memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
| + Dart_ExitScope(); |
| + } |
| + |
| + { |
| + // Now Create an Isolate using the full snapshot and load the |
| + // script and execute it. |
| + TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| + Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| + |
| + // Create a test library and Load up a test script in it. |
| + Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| + |
| + EXPECT_VALID(lib); |
| + |
| + // Invoke a function which returns an object. |
| + result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| + EXPECT_VALID(result); |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + } |
| + |
| + { |
| + // Create an Isolate using the full snapshot, load a script and create |
| + // a script snapshot of the script. |
| + TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| + Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| + |
| + // Create a test library and Load up a test script in it. |
| + TestCase::LoadTestScript(kScriptChars, NULL); |
| + |
| + EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); |
| + |
| + // Write out the script snapshot. |
| + result = Dart_CreateScriptSnapshot(&buffer, &size); |
| + EXPECT_VALID(result); |
| + script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); |
| + memmove(script_snapshot, buffer, size); |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + } |
| + |
| + { |
| + // Now Create an Isolate using the full snapshot and load the |
| + // script snapshot created above and execute it. |
| + TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| + Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| + |
| + // Load the test library from the snapshot. |
| + EXPECT(script_snapshot != NULL); |
| + result = Dart_LoadScriptFromSnapshot(script_snapshot, size); |
| + EXPECT_VALID(result); |
| + |
| + // Invoke a function which returns an object. |
| + result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| + EXPECT_VALID(result); |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + } |
| + free(script_snapshot); |
| + free(full_snapshot); |
| + |
| + FLAG_max_polymorphic_checks = saved_max_polymorphic_checks; |
| +#if !defined(PRODUCT) |
| + FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
| +#endif |
| +} |
| static void IterateScripts(const Library& lib) { |