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

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

Issue 2933223002: Update subclasses array and is_implemented bit when loading script snapshots. (Closed)
Patch Set: Created 3 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
« runtime/vm/snapshot.cc ('K') | « runtime/vm/snapshot.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_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 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 995
996 // Check if we are able to generate the source from the token stream. 996 // Check if we are able to generate the source from the token stream.
997 // Rescan this source and compare the token stream to see if they are 997 // Rescan this source and compare the token stream to see if they are
998 // the same. 998 // the same.
999 GenerateSourceAndCheck(serialized_script); 999 GenerateSourceAndCheck(serialized_script);
1000 1000
1001 free(buffer); 1001 free(buffer);
1002 } 1002 }
1003 1003
1004 1004
1005 #if !defined(PRODUCT) // Uses deferred loading.
1006 VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { 1005 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.
1007 const char* kScriptChars = 1006 const char* kScriptChars =
1008 "\n" 1007 "\n"
1009 "import 'dart:mirrors';" 1008 "import 'dart:mirrors';"
1010 "import 'dart:isolate';" 1009 "import 'dart:isolate';"
1011 "void main() {" 1010 "void main() {"
1012 " if (reflectClass(MyException).superclass.reflectedType != " 1011 " if (reflectClass(MyException).superclass.reflectedType != "
1013 " IsolateSpawnException) {" 1012 " IsolateSpawnException) {"
1014 " throw new Exception('Canonicalization failure');" 1013 " throw new Exception('Canonicalization failure');"
1015 " }" 1014 " }"
1016 " if (reflectClass(IsolateSpawnException).reflectedType != " 1015 " if (reflectClass(IsolateSpawnException).reflectedType != "
1017 " IsolateSpawnException) {" 1016 " IsolateSpawnException) {"
1018 " throw new Exception('Canonicalization failure');" 1017 " throw new Exception('Canonicalization failure');"
1019 " }" 1018 " }"
1020 "}\n" 1019 "}\n"
1021 "class MyException extends IsolateSpawnException {}" 1020 "class MyException extends IsolateSpawnException {}"
1022 "\n"; 1021 "\n";
1023 1022
1024 Dart_Handle result; 1023 Dart_Handle result;
1025 1024
1026 uint8_t* buffer; 1025 uint8_t* buffer;
1027 intptr_t size; 1026 intptr_t size;
1028 intptr_t vm_isolate_snapshot_size; 1027 intptr_t vm_isolate_snapshot_size;
1029 uint8_t* isolate_snapshot = NULL; 1028 uint8_t* isolate_snapshot = NULL;
1030 intptr_t isolate_snapshot_size; 1029 intptr_t isolate_snapshot_size;
1031 uint8_t* full_snapshot = NULL; 1030 uint8_t* full_snapshot = NULL;
1032 uint8_t* script_snapshot = NULL; 1031 uint8_t* script_snapshot = NULL;
1033 1032
1033 #if !defined(PRODUCT)
1034 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; 1034 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1035 FLAG_load_deferred_eagerly = true; 1035 FLAG_load_deferred_eagerly = true;
1036 #endif
1036 { 1037 {
1037 // Start an Isolate, and create a full snapshot of it. 1038 // Start an Isolate, and create a full snapshot of it.
1038 TestIsolateScope __test_isolate__; 1039 TestIsolateScope __test_isolate__;
1039 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1040 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1040 1041
1041 // Write out the script snapshot. 1042 // Write out the script snapshot.
1042 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, 1043 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size,
1043 &isolate_snapshot, &isolate_snapshot_size); 1044 &isolate_snapshot, &isolate_snapshot_size);
1044 EXPECT_VALID(result); 1045 EXPECT_VALID(result);
1045 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1046 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1046 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1047 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1047 Dart_ExitScope(); 1048 Dart_ExitScope();
1048 } 1049 }
1050 #if !defined(PRODUCT)
1049 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; 1051 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1052 #endif
1050 1053
1051 { 1054 {
1052 // Now Create an Isolate using the full snapshot and load the 1055 // Now Create an Isolate using the full snapshot and load the
1053 // script and execute it. 1056 // script and execute it.
1054 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1057 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1055 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1058 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1056 1059
1057 // Create a test library and Load up a test script in it. 1060 // Create a test library and Load up a test script in it.
1058 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1061 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1059 1062
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 1102
1100 // Invoke a function which returns an object. 1103 // Invoke a function which returns an object.
1101 result = Dart_Invoke(result, NewString("main"), 0, NULL); 1104 result = Dart_Invoke(result, NewString("main"), 0, NULL);
1102 EXPECT_VALID(result); 1105 EXPECT_VALID(result);
1103 Dart_ExitScope(); 1106 Dart_ExitScope();
1104 Dart_ShutdownIsolate(); 1107 Dart_ShutdownIsolate();
1105 } 1108 }
1106 free(script_snapshot); 1109 free(script_snapshot);
1107 free(full_snapshot); 1110 free(full_snapshot);
1108 } 1111 }
1112
1113
1114 VM_UNIT_TEST_CASE(ScriptSnapshotsUpdateSubclasses) {
1115 const char* kScriptChars =
1116 "class _DebugDuration extends Duration {\n"
1117 " const _DebugDuration() : super(milliseconds: 42);\n"
1118 "}\n"
1119 "foo(x, y) {\n"
1120 " for (var i = 0; i < 1000000; i++) {\n"
1121 " if (x != y) {\n"
1122 " throw 'Boom!';\n"
1123 " }\n"
1124 " }\n"
1125 "}\n"
1126 "main() {\n"
1127 " final v = const Duration(milliseconds: 42);\n"
1128 " foo(v, new _DebugDuration());\n"
1129 "}\n"
1130 "\n";
1131
1132 Dart_Handle result;
1133
1134 uint8_t* buffer;
1135 intptr_t size;
1136 intptr_t vm_isolate_snapshot_size;
1137 uint8_t* isolate_snapshot = NULL;
1138 intptr_t isolate_snapshot_size;
1139 uint8_t* full_snapshot = NULL;
1140 uint8_t* script_snapshot = NULL;
1141
1142 #if !defined(PRODUCT)
1143 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1144 FLAG_load_deferred_eagerly = true;
1109 #endif 1145 #endif
1146 intptr_t saved_max_polymorphic_checks = FLAG_max_polymorphic_checks;
1147 FLAG_max_polymorphic_checks = 0;
1148
1149 {
1150 // Start an Isolate, and create a full snapshot of it.
1151 TestIsolateScope __test_isolate__;
1152 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1153
1154 // Write out the script snapshot.
1155 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size,
1156 &isolate_snapshot, &isolate_snapshot_size);
1157 EXPECT_VALID(result);
1158 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1159 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1160 Dart_ExitScope();
1161 }
1162
1163 {
1164 // Now Create an Isolate using the full snapshot and load the
1165 // script and execute it.
1166 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1167 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1168
1169 // Create a test library and Load up a test script in it.
1170 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1171
1172 EXPECT_VALID(lib);
1173
1174 // Invoke a function which returns an object.
1175 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1176 EXPECT_VALID(result);
1177 Dart_ExitScope();
1178 Dart_ShutdownIsolate();
1179 }
1180
1181 {
1182 // Create an Isolate using the full snapshot, load a script and create
1183 // a script snapshot of the script.
1184 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1185 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1186
1187 // Create a test library and Load up a test script in it.
1188 TestCase::LoadTestScript(kScriptChars, NULL);
1189
1190 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current()));
1191
1192 // Write out the script snapshot.
1193 result = Dart_CreateScriptSnapshot(&buffer, &size);
1194 EXPECT_VALID(result);
1195 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1196 memmove(script_snapshot, buffer, size);
1197 Dart_ExitScope();
1198 Dart_ShutdownIsolate();
1199 }
1200
1201 {
1202 // Now Create an Isolate using the full snapshot and load the
1203 // script snapshot created above and execute it.
1204 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1205 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1206
1207 // Load the test library from the snapshot.
1208 EXPECT(script_snapshot != NULL);
1209 result = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1210 EXPECT_VALID(result);
1211
1212 // Invoke a function which returns an object.
1213 result = Dart_Invoke(result, NewString("main"), 0, NULL);
1214 EXPECT_VALID(result);
1215 Dart_ExitScope();
1216 Dart_ShutdownIsolate();
1217 }
1218 free(script_snapshot);
1219 free(full_snapshot);
1220
1221 FLAG_max_polymorphic_checks = saved_max_polymorphic_checks;
1222 #if !defined(PRODUCT)
1223 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1224 #endif
1225 }
1110 1226
1111 1227
1112 static void IterateScripts(const Library& lib) { 1228 static void IterateScripts(const Library& lib) {
1113 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); 1229 const Array& lib_scripts = Array::Handle(lib.LoadedScripts());
1114 Script& script = Script::Handle(); 1230 Script& script = Script::Handle();
1115 String& uri = String::Handle(); 1231 String& uri = String::Handle();
1116 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { 1232 for (intptr_t i = 0; i < lib_scripts.Length(); i++) {
1117 script ^= lib_scripts.At(i); 1233 script ^= lib_scripts.At(i);
1118 EXPECT(!script.IsNull()); 1234 EXPECT(!script.IsNull());
1119 uri = script.url(); 1235 uri = script.url();
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 StackZone zone(Thread::Current()); 3128 StackZone zone(Thread::Current());
3013 uint8_t* buffer; 3129 uint8_t* buffer;
3014 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); 3130 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true);
3015 writer.WriteInlinedObjectHeader(kOmittedObjectId); 3131 writer.WriteInlinedObjectHeader(kOmittedObjectId);
3016 // For performance, we'd like single-byte headers when ids are omitted. 3132 // For performance, we'd like single-byte headers when ids are omitted.
3017 // If this starts failing, consider renumbering the snapshot ids. 3133 // If this starts failing, consider renumbering the snapshot ids.
3018 EXPECT_EQ(1, writer.BytesWritten()); 3134 EXPECT_EQ(1, writer.BytesWritten());
3019 } 3135 }
3020 3136
3021 } // namespace dart 3137 } // namespace dart
OLDNEW
« runtime/vm/snapshot.cc ('K') | « runtime/vm/snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698