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

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

Issue 1643023003: Precompilation: when removing top-level fields and functions, also remove them from the library dic… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/object.cc ('K') | « runtime/vm/precompiler.h ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 "vm/precompiler.h" 5 #include "vm/precompiler.h"
6 6
7 #include "vm/cha.h" 7 #include "vm/cha.h"
8 #include "vm/code_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/hash_table.h" 10 #include "vm/hash_table.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 function_count_(0), 62 function_count_(0),
63 class_count_(0), 63 class_count_(0),
64 selector_count_(0), 64 selector_count_(0),
65 dropped_function_count_(0), 65 dropped_function_count_(0),
66 dropped_field_count_(0), 66 dropped_field_count_(0),
67 libraries_(GrowableObjectArray::Handle(I->object_store()->libraries())), 67 libraries_(GrowableObjectArray::Handle(I->object_store()->libraries())),
68 pending_functions_( 68 pending_functions_(
69 GrowableObjectArray::Handle(GrowableObjectArray::New())), 69 GrowableObjectArray::Handle(GrowableObjectArray::New())),
70 sent_selectors_(), 70 sent_selectors_(),
71 enqueued_functions_(), 71 enqueued_functions_(),
72 fields_to_retain_(),
72 error_(Error::Handle()) { 73 error_(Error::Handle()) {
73 } 74 }
74 75
75 76
76 void Precompiler::DoCompileAll( 77 void Precompiler::DoCompileAll(
77 Dart_QualifiedFunctionName embedder_entry_points[]) { 78 Dart_QualifiedFunctionName embedder_entry_points[]) {
78 ASSERT(I->compilation_allowed()); 79 ASSERT(I->compilation_allowed());
79 80
80 { 81 {
81 StackZone stack_zone(T); 82 StackZone stack_zone(T);
(...skipping 29 matching lines...) Expand all
111 // Start with the allocations and invocations that happen from C++. 112 // Start with the allocations and invocations that happen from C++.
112 AddRoots(embedder_entry_points); 113 AddRoots(embedder_entry_points);
113 114
114 // Compile newly found targets and add their callees until we reach a 115 // Compile newly found targets and add their callees until we reach a
115 // fixed point. 116 // fixed point.
116 Iterate(); 117 Iterate();
117 } 118 }
118 119
119 I->set_compilation_allowed(false); 120 I->set_compilation_allowed(false);
120 121
121 DropUncompiledFunctions(); 122 DropFunctions();
122 DropFields(); 123 DropFields();
123 124
124 // TODO(rmacnak): DropEmptyClasses(); 125 // TODO(rmacnak): DropEmptyClasses();
125 126
126 BindStaticCalls(); 127 BindStaticCalls();
127 128
128 DedupStackmaps(); 129 DedupStackmaps();
129 DedupStackmapLists(); 130 DedupStackmapLists();
130 131
131 I->object_store()->set_compile_time_constants(Array::null_array()); 132 I->object_store()->set_compile_time_constants(Array::null_array());
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 Object* function) { 891 Object* function) {
891 UniqueFunctionsSet functions_set( 892 UniqueFunctionsSet functions_set(
892 isolate->object_store()->unique_dynamic_targets()); 893 isolate->object_store()->unique_dynamic_targets());
893 ASSERT(fname.IsSymbol()); 894 ASSERT(fname.IsSymbol());
894 *function = functions_set.GetOrNull(fname); 895 *function = functions_set.GetOrNull(fname);
895 ASSERT(functions_set.Release().raw() == 896 ASSERT(functions_set.Release().raw() ==
896 isolate->object_store()->unique_dynamic_targets()); 897 isolate->object_store()->unique_dynamic_targets());
897 } 898 }
898 899
899 900
900 void Precompiler::DropUncompiledFunctions() { 901 void Precompiler::DropFunctions() {
901 Library& lib = Library::Handle(Z); 902 Library& lib = Library::Handle(Z);
902 Class& cls = Class::Handle(Z); 903 Class& cls = Class::Handle(Z);
903 Array& functions = Array::Handle(Z); 904 Array& functions = Array::Handle(Z);
904 Function& function = Function::Handle(Z); 905 Function& function = Function::Handle(Z);
905 Function& function2 = Function::Handle(Z); 906 Function& function2 = Function::Handle(Z);
906 GrowableObjectArray& retained_functions = GrowableObjectArray::Handle(Z); 907 GrowableObjectArray& retained_functions = GrowableObjectArray::Handle(Z);
907 GrowableObjectArray& closures = GrowableObjectArray::Handle(Z); 908 GrowableObjectArray& closures = GrowableObjectArray::Handle(Z);
909 String& name = String::Handle(Z);
908 910
909 for (intptr_t i = 0; i < libraries_.Length(); i++) { 911 for (intptr_t i = 0; i < libraries_.Length(); i++) {
910 lib ^= libraries_.At(i); 912 lib ^= libraries_.At(i);
911 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); 913 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
912 while (it.HasNext()) { 914 while (it.HasNext()) {
913 cls = it.GetNextClass(); 915 cls = it.GetNextClass();
914 if (cls.IsDynamicClass()) { 916 if (cls.IsDynamicClass()) {
915 continue; // class 'dynamic' is in the read-only VM isolate. 917 continue; // class 'dynamic' is in the read-only VM isolate.
916 } 918 }
917 919
920 bool top_level = cls.IsTopLevel();
Florian Schneider 2016/02/02 21:30:20 Move this right before its use?
rmacnak 2016/02/03 01:43:39 Done.
921
918 functions = cls.functions(); 922 functions = cls.functions();
919 retained_functions = GrowableObjectArray::New(); 923 retained_functions = GrowableObjectArray::New();
920 for (intptr_t j = 0; j < functions.Length(); j++) { 924 for (intptr_t j = 0; j < functions.Length(); j++) {
921 function ^= functions.At(j); 925 function ^= functions.At(j);
922 bool retain = function.HasCode(); 926 bool retain = function.HasCode();
923 if (!retain && function.HasImplicitClosureFunction()) { 927 if (!retain && function.HasImplicitClosureFunction()) {
924 // It can happen that all uses of an implicit closure inline their 928 // It can happen that all uses of an implicit closure inline their
925 // target function, leaving the target function uncompiled. Keep 929 // target function, leaving the target function uncompiled. Keep
926 // the target function anyway so we can enumerate it to bind its 930 // the target function anyway so we can enumerate it to bind its
927 // static calls, etc. 931 // static calls, etc.
928 function2 = function.ImplicitClosureFunction(); 932 function2 = function.ImplicitClosureFunction();
929 retain = function2.HasCode(); 933 retain = function2.HasCode();
930 } 934 }
931 if (retain) { 935 if (retain) {
932 retained_functions.Add(function); 936 retained_functions.Add(function);
933 function.DropUncompiledImplicitClosureFunction(); 937 function.DropUncompiledImplicitClosureFunction();
934 } else { 938 } else {
939 if (top_level &&
940 (function.kind() != RawFunction::kImplicitStaticFinalGetter)) {
Florian Schneider 2016/02/02 21:30:20 Why not for implicit static final getters?
rmacnak 2016/02/03 01:43:40 They aren't in the library dictionary in the first
941 name = function.DictionaryName();
942 bool removed = lib.RemoveObject(function, name);
943 ASSERT(removed);
944 }
935 dropped_function_count_++; 945 dropped_function_count_++;
936 if (FLAG_trace_precompiler) { 946 if (FLAG_trace_precompiler) {
937 THR_Print("Precompilation dropping %s\n", 947 THR_Print("Precompilation dropping %s\n",
938 function.ToLibNamePrefixedQualifiedCString()); 948 function.ToLibNamePrefixedQualifiedCString());
939 } 949 }
940 } 950 }
941 } 951 }
942 952
943 if (retained_functions.Length() > 0) { 953 if (retained_functions.Length() > 0) {
944 functions = Array::MakeArray(retained_functions); 954 functions = Array::MakeArray(retained_functions);
(...skipping 21 matching lines...) Expand all
966 isolate()->object_store()->set_closure_functions(retained_functions); 976 isolate()->object_store()->set_closure_functions(retained_functions);
967 } 977 }
968 978
969 979
970 void Precompiler::DropFields() { 980 void Precompiler::DropFields() {
971 Library& lib = Library::Handle(Z); 981 Library& lib = Library::Handle(Z);
972 Class& cls = Class::Handle(Z); 982 Class& cls = Class::Handle(Z);
973 Array& fields = Array::Handle(Z); 983 Array& fields = Array::Handle(Z);
974 Field& field = Field::Handle(Z); 984 Field& field = Field::Handle(Z);
975 GrowableObjectArray& retained_fields = GrowableObjectArray::Handle(Z); 985 GrowableObjectArray& retained_fields = GrowableObjectArray::Handle(Z);
986 String& name = String::Handle(Z);
976 987
977 for (intptr_t i = 0; i < libraries_.Length(); i++) { 988 for (intptr_t i = 0; i < libraries_.Length(); i++) {
978 lib ^= libraries_.At(i); 989 lib ^= libraries_.At(i);
979 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); 990 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
980 while (it.HasNext()) { 991 while (it.HasNext()) {
981 cls = it.GetNextClass(); 992 cls = it.GetNextClass();
982 if (cls.IsDynamicClass()) { 993 if (cls.IsDynamicClass()) {
983 continue; // class 'dynamic' is in the read-only VM isolate. 994 continue; // class 'dynamic' is in the read-only VM isolate.
984 } 995 }
985 996
997 bool top_level = cls.IsTopLevel();
Florian Schneider 2016/02/02 21:30:19 Move this right before its use?
rmacnak 2016/02/03 01:43:39 Done.
998
986 fields = cls.fields(); 999 fields = cls.fields();
987 retained_fields = GrowableObjectArray::New(); 1000 retained_fields = GrowableObjectArray::New();
988 for (intptr_t j = 0; j < fields.Length(); j++) { 1001 for (intptr_t j = 0; j < fields.Length(); j++) {
989 field ^= fields.At(j); 1002 field ^= fields.At(j);
990 bool drop = fields_to_retain_.Lookup(&field) == NULL; 1003 bool retain = fields_to_retain_.Lookup(&field) != NULL;
991 if (drop) { 1004 if (retain) {
1005 retained_fields.Add(field);
1006 } else {
1007 if (top_level) {
1008 name = field.DictionaryName();
1009 bool removed = lib.RemoveObject(field, name);
1010 ASSERT(removed);
1011 }
992 dropped_field_count_++; 1012 dropped_field_count_++;
993 if (FLAG_trace_precompiler) { 1013 if (FLAG_trace_precompiler) {
994 THR_Print("Precompilation dropping %s\n", 1014 THR_Print("Precompilation dropping %s\n",
995 field.ToCString()); 1015 field.ToCString());
996 } 1016 }
997 } else {
998 retained_fields.Add(field);
999 } 1017 }
1000 } 1018 }
1001 1019
1002 if (retained_fields.Length() > 0) { 1020 if (retained_fields.Length() > 0) {
1003 fields = Array::MakeArray(retained_fields); 1021 fields = Array::MakeArray(retained_fields);
1004 cls.SetFields(fields); 1022 cls.SetFields(fields);
1005 } else { 1023 } else {
1006 cls.SetFields(Object::empty_array()); 1024 cls.SetFields(Object::empty_array());
1007 } 1025 }
1008 } 1026 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 I->set_all_classes_finalized(true); 1263 I->set_all_classes_finalized(true);
1246 } 1264 }
1247 1265
1248 1266
1249 void Precompiler::ResetPrecompilerState() { 1267 void Precompiler::ResetPrecompilerState() {
1250 changed_ = false; 1268 changed_ = false;
1251 function_count_ = 0; 1269 function_count_ = 0;
1252 class_count_ = 0; 1270 class_count_ = 0;
1253 selector_count_ = 0; 1271 selector_count_ = 0;
1254 dropped_function_count_ = 0; 1272 dropped_function_count_ = 0;
1273 dropped_field_count_ = 0;
1255 ASSERT(pending_functions_.Length() == 0); 1274 ASSERT(pending_functions_.Length() == 0);
1256 sent_selectors_.Clear(); 1275 sent_selectors_.Clear();
1257 enqueued_functions_.Clear(); 1276 enqueued_functions_.Clear();
1258 1277
1259 Library& lib = Library::Handle(Z); 1278 Library& lib = Library::Handle(Z);
1260 Class& cls = Class::Handle(Z); 1279 Class& cls = Class::Handle(Z);
1261 1280
1262 for (intptr_t i = 0; i < libraries_.Length(); i++) { 1281 for (intptr_t i = 0; i < libraries_.Length(); i++) {
1263 lib ^= libraries_.At(i); 1282 lib ^= libraries_.At(i);
1264 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); 1283 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
1265 while (it.HasNext()) { 1284 while (it.HasNext()) {
1266 cls = it.GetNextClass(); 1285 cls = it.GetNextClass();
1267 if (cls.IsDynamicClass()) { 1286 if (cls.IsDynamicClass()) {
1268 continue; // class 'dynamic' is in the read-only VM isolate. 1287 continue; // class 'dynamic' is in the read-only VM isolate.
1269 } 1288 }
1270 cls.set_is_allocated(false); 1289 cls.set_is_allocated(false);
1271 } 1290 }
1272 } 1291 }
1273 } 1292 }
1274 1293
1275 } // namespace dart 1294 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/precompiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698