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

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

Issue 1255003004: Implement patch records to patch canonical objects. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address-code-review Created 5 years, 4 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
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | tests/language/issue21079_test.dart » ('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_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/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1013
1014 // Check if we are able to generate the source from the token stream. 1014 // Check if we are able to generate the source from the token stream.
1015 // Rescan this source and compare the token stream to see if they are 1015 // Rescan this source and compare the token stream to see if they are
1016 // the same. 1016 // the same.
1017 GenerateSourceAndCheck(serialized_script); 1017 GenerateSourceAndCheck(serialized_script);
1018 1018
1019 free(buffer); 1019 free(buffer);
1020 } 1020 }
1021 1021
1022 1022
1023 UNIT_TEST_CASE(CanonicalizationInScriptSnapshots) {
1024 const char* kScriptChars =
1025 "\n"
1026 "import 'dart:mirrors';"
1027 "import 'dart:isolate';"
1028 "void main() {"
1029 " if (reflectClass(MyException).superclass.reflectedType != "
1030 " IsolateSpawnException) {"
1031 " throw new Exception('Canonicalization failure');"
1032 " }"
1033 " if (reflectClass(IsolateSpawnException).reflectedType != "
1034 " IsolateSpawnException) {"
1035 " throw new Exception('Canonicalization failure');"
1036 " }"
1037 "}\n"
1038 "class MyException extends IsolateSpawnException {}"
1039 "\n";
1040
1041 Dart_Handle result;
1042
1043 uint8_t* buffer;
1044 intptr_t size;
1045 intptr_t vm_isolate_snapshot_size;
1046 uint8_t* isolate_snapshot = NULL;
1047 intptr_t isolate_snapshot_size;
1048 uint8_t* full_snapshot = NULL;
1049 uint8_t* script_snapshot = NULL;
1050
1051 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly;
1052 FLAG_load_deferred_eagerly = true;
1053 // Workaround until issue 21620 is fixed.
1054 // (https://github.com/dart-lang/sdk/issues/21620)
1055 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep;
1056 FLAG_concurrent_sweep = false;
1057 {
1058 // Start an Isolate, and create a full snapshot of it.
1059 TestIsolateScope __test_isolate__;
1060 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1061
1062 // Write out the script snapshot.
1063 result = Dart_CreateSnapshot(NULL,
1064 &vm_isolate_snapshot_size,
1065 &isolate_snapshot,
1066 &isolate_snapshot_size);
1067 EXPECT_VALID(result);
1068 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1069 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1070 Dart_ExitScope();
1071 }
1072 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1073 FLAG_concurrent_sweep = saved_concurrent_sweep_mode;
1074
1075 {
1076 // Now Create an Isolate using the full snapshot and load the
1077 // script and execute it.
1078 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1079 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1080
1081 // Create a test library and Load up a test script in it.
1082 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1083
1084 EXPECT_VALID(lib);
1085
1086 // Invoke a function which returns an object.
1087 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1088 EXPECT_VALID(result);
1089 Dart_ExitScope();
1090 Dart_ShutdownIsolate();
1091 }
1092
1093 {
1094 // Create an Isolate using the full snapshot, load a script and create
1095 // a script snapshot of the script.
1096 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1097 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1098
1099 // Create a test library and Load up a test script in it.
1100 TestCase::LoadTestScript(kScriptChars, NULL);
1101
1102 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Isolate::Current()));
1103
1104 // Write out the script snapshot.
1105 result = Dart_CreateScriptSnapshot(&buffer, &size);
1106 EXPECT_VALID(result);
1107 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1108 memmove(script_snapshot, buffer, size);
1109 Dart_ExitScope();
1110 Dart_ShutdownIsolate();
1111 }
1112
1113 {
1114 // Now Create an Isolate using the full snapshot and load the
1115 // script snapshot created above and execute it.
1116 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1117 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1118
1119 // Load the test library from the snapshot.
1120 EXPECT(script_snapshot != NULL);
1121 result = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1122 EXPECT_VALID(result);
1123
1124 // Invoke a function which returns an object.
1125 result = Dart_Invoke(result, NewString("main"), 0, NULL);
1126 EXPECT_VALID(result);
1127 Dart_ExitScope();
1128 Dart_ShutdownIsolate();
1129 }
1130 free(script_snapshot);
rmacnak 2015/07/30 17:07:41 missing free(full_snapshot)
siva 2015/07/30 17:17:06 Done.
1131 }
1132
1133
1023 static void IterateScripts(const Library& lib) { 1134 static void IterateScripts(const Library& lib) {
1024 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); 1135 const Array& lib_scripts = Array::Handle(lib.LoadedScripts());
1025 Script& script = Script::Handle(); 1136 Script& script = Script::Handle();
1026 String& uri = String::Handle(); 1137 String& uri = String::Handle();
1027 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { 1138 for (intptr_t i = 0; i < lib_scripts.Length(); i++) {
1028 script ^= lib_scripts.At(i); 1139 script ^= lib_scripts.At(i);
1029 EXPECT(!script.IsNull()); 1140 EXPECT(!script.IsNull());
1030 uri = script.url(); 1141 uri = script.url();
1031 OS::Print("Generating source for part: %s\n", uri.ToCString()); 1142 OS::Print("Generating source for part: %s\n", uri.ToCString());
1032 GenerateSourceAndCheck(script); 1143 GenerateSourceAndCheck(script);
(...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 StackZone zone(Isolate::Current()); 3017 StackZone zone(Isolate::Current());
2907 uint8_t* buffer; 3018 uint8_t* buffer;
2908 MessageWriter writer(&buffer, &zone_allocator, true); 3019 MessageWriter writer(&buffer, &zone_allocator, true);
2909 writer.WriteInlinedObjectHeader(kOmittedObjectId); 3020 writer.WriteInlinedObjectHeader(kOmittedObjectId);
2910 // For performance, we'd like single-byte headers when ids are omitted. 3021 // For performance, we'd like single-byte headers when ids are omitted.
2911 // If this starts failing, consider renumbering the snapshot ids. 3022 // If this starts failing, consider renumbering the snapshot ids.
2912 EXPECT_EQ(1, writer.BytesWritten()); 3023 EXPECT_EQ(1, writer.BytesWritten());
2913 } 3024 }
2914 3025
2915 } // namespace dart 3026 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | tests/language/issue21079_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698