| 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 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. | 1005 #if !defined(PRODUCT) // Uses mirrors. |
| 1006 VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { | 1006 VM_UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) { |
| 1007 const char* kScriptChars = | 1007 const char* kScriptChars = |
| 1008 "\n" | 1008 "\n" |
| 1009 "import 'dart:mirrors';" | 1009 "import 'dart:mirrors';" |
| 1010 "import 'dart:isolate';" | 1010 "import 'dart:isolate';" |
| 1011 "void main() {" | 1011 "void main() {" |
| 1012 " if (reflectClass(MyException).superclass.reflectedType != " | 1012 " if (reflectClass(MyException).superclass.reflectedType != " |
| 1013 " IsolateSpawnException) {" | 1013 " IsolateSpawnException) {" |
| 1014 " throw new Exception('Canonicalization failure');" | 1014 " throw new Exception('Canonicalization failure');" |
| 1015 " }" | 1015 " }" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 EXPECT_VALID(result); | 1102 EXPECT_VALID(result); |
| 1103 Dart_ExitScope(); | 1103 Dart_ExitScope(); |
| 1104 Dart_ShutdownIsolate(); | 1104 Dart_ShutdownIsolate(); |
| 1105 } | 1105 } |
| 1106 free(script_snapshot); | 1106 free(script_snapshot); |
| 1107 free(full_snapshot); | 1107 free(full_snapshot); |
| 1108 } | 1108 } |
| 1109 #endif | 1109 #endif |
| 1110 | 1110 |
| 1111 | 1111 |
| 1112 VM_UNIT_TEST_CASE(ScriptSnapshotsUpdateSubclasses) { |
| 1113 const char* kScriptChars = |
| 1114 "class _DebugDuration extends Duration {\n" |
| 1115 " const _DebugDuration() : super(milliseconds: 42);\n" |
| 1116 "}\n" |
| 1117 "foo(x, y) {\n" |
| 1118 " for (var i = 0; i < 1000000; i++) {\n" |
| 1119 " if (x != y) {\n" |
| 1120 " throw 'Boom!';\n" |
| 1121 " }\n" |
| 1122 " }\n" |
| 1123 "}\n" |
| 1124 "main() {\n" |
| 1125 " final v = const Duration(milliseconds: 42);\n" |
| 1126 " foo(v, new _DebugDuration());\n" |
| 1127 "}\n" |
| 1128 "\n"; |
| 1129 |
| 1130 Dart_Handle result; |
| 1131 |
| 1132 uint8_t* buffer; |
| 1133 intptr_t size; |
| 1134 intptr_t vm_isolate_snapshot_size; |
| 1135 uint8_t* isolate_snapshot = NULL; |
| 1136 intptr_t isolate_snapshot_size; |
| 1137 uint8_t* full_snapshot = NULL; |
| 1138 uint8_t* script_snapshot = NULL; |
| 1139 |
| 1140 #if !defined(PRODUCT) |
| 1141 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; |
| 1142 FLAG_load_deferred_eagerly = true; |
| 1143 #endif |
| 1144 intptr_t saved_max_polymorphic_checks = FLAG_max_polymorphic_checks; |
| 1145 FLAG_max_polymorphic_checks = 0; |
| 1146 |
| 1147 { |
| 1148 // Start an Isolate, and create a full snapshot of it. |
| 1149 TestIsolateScope __test_isolate__; |
| 1150 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1151 |
| 1152 // Write out the script snapshot. |
| 1153 result = Dart_CreateSnapshot(NULL, &vm_isolate_snapshot_size, |
| 1154 &isolate_snapshot, &isolate_snapshot_size); |
| 1155 EXPECT_VALID(result); |
| 1156 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
| 1157 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
| 1158 Dart_ExitScope(); |
| 1159 } |
| 1160 |
| 1161 { |
| 1162 // Now Create an Isolate using the full snapshot and load the |
| 1163 // script and execute it. |
| 1164 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| 1165 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1166 |
| 1167 // Create a test library and Load up a test script in it. |
| 1168 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1169 |
| 1170 EXPECT_VALID(lib); |
| 1171 |
| 1172 // Invoke a function which returns an object. |
| 1173 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1174 EXPECT_VALID(result); |
| 1175 Dart_ExitScope(); |
| 1176 Dart_ShutdownIsolate(); |
| 1177 } |
| 1178 |
| 1179 { |
| 1180 // Create an Isolate using the full snapshot, load a script and create |
| 1181 // a script snapshot of the script. |
| 1182 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| 1183 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1184 |
| 1185 // Create a test library and Load up a test script in it. |
| 1186 TestCase::LoadTestScript(kScriptChars, NULL); |
| 1187 |
| 1188 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); |
| 1189 |
| 1190 // Write out the script snapshot. |
| 1191 result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 1192 EXPECT_VALID(result); |
| 1193 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); |
| 1194 memmove(script_snapshot, buffer, size); |
| 1195 Dart_ExitScope(); |
| 1196 Dart_ShutdownIsolate(); |
| 1197 } |
| 1198 |
| 1199 { |
| 1200 // Now Create an Isolate using the full snapshot and load the |
| 1201 // script snapshot created above and execute it. |
| 1202 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| 1203 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1204 |
| 1205 // Load the test library from the snapshot. |
| 1206 EXPECT(script_snapshot != NULL); |
| 1207 result = Dart_LoadScriptFromSnapshot(script_snapshot, size); |
| 1208 EXPECT_VALID(result); |
| 1209 |
| 1210 // Invoke a function which returns an object. |
| 1211 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 1212 EXPECT_VALID(result); |
| 1213 Dart_ExitScope(); |
| 1214 Dart_ShutdownIsolate(); |
| 1215 } |
| 1216 free(script_snapshot); |
| 1217 free(full_snapshot); |
| 1218 |
| 1219 FLAG_max_polymorphic_checks = saved_max_polymorphic_checks; |
| 1220 #if !defined(PRODUCT) |
| 1221 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
| 1222 #endif |
| 1223 } |
| 1224 |
| 1225 |
| 1112 static void IterateScripts(const Library& lib) { | 1226 static void IterateScripts(const Library& lib) { |
| 1113 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); | 1227 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); |
| 1114 Script& script = Script::Handle(); | 1228 Script& script = Script::Handle(); |
| 1115 String& uri = String::Handle(); | 1229 String& uri = String::Handle(); |
| 1116 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { | 1230 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { |
| 1117 script ^= lib_scripts.At(i); | 1231 script ^= lib_scripts.At(i); |
| 1118 EXPECT(!script.IsNull()); | 1232 EXPECT(!script.IsNull()); |
| 1119 uri = script.url(); | 1233 uri = script.url(); |
| 1120 OS::Print("Generating source for part: %s\n", uri.ToCString()); | 1234 OS::Print("Generating source for part: %s\n", uri.ToCString()); |
| 1121 GenerateSourceAndCheck(script); | 1235 GenerateSourceAndCheck(script); |
| (...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3012 StackZone zone(Thread::Current()); | 3126 StackZone zone(Thread::Current()); |
| 3013 uint8_t* buffer; | 3127 uint8_t* buffer; |
| 3014 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); | 3128 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); |
| 3015 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3129 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
| 3016 // For performance, we'd like single-byte headers when ids are omitted. | 3130 // For performance, we'd like single-byte headers when ids are omitted. |
| 3017 // If this starts failing, consider renumbering the snapshot ids. | 3131 // If this starts failing, consider renumbering the snapshot ids. |
| 3018 EXPECT_EQ(1, writer.BytesWritten()); | 3132 EXPECT_EQ(1, writer.BytesWritten()); |
| 3019 } | 3133 } |
| 3020 | 3134 |
| 3021 } // namespace dart | 3135 } // namespace dart |
| OLD | NEW |