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

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

Issue 1653003003: Precompilation: canonicalize Instructions in PRODUCT mode. (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
« no previous file with comments | « 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DropFunctions(); 122 DropFunctions();
123 DropFields(); 123 DropFields();
124 124
125 // TODO(rmacnak): DropEmptyClasses(); 125 // TODO(rmacnak): DropEmptyClasses();
126 126
127 BindStaticCalls(); 127 BindStaticCalls();
128 128
129 DedupStackmaps(); 129 DedupStackmaps();
130 DedupStackmapLists(); 130 DedupStackmapLists();
131 131
132 if (FLAG_dedup_instructions) {
133 // Reduces binary size but obfuscates profiler results.
134 DedupInstructions();
135 }
136
132 I->object_store()->set_compile_time_constants(Array::null_array()); 137 I->object_store()->set_compile_time_constants(Array::null_array());
133 I->object_store()->set_unique_dynamic_targets(Array::null_array()); 138 I->object_store()->set_unique_dynamic_targets(Array::null_array());
134 139
135 zone_ = NULL; 140 zone_ = NULL;
136 } 141 }
137 142
138 intptr_t dropped_symbols_count = Symbols::Compact(I); 143 intptr_t dropped_symbols_count = Symbols::Compact(I);
139 144
140 if (FLAG_trace_precompiler) { 145 if (FLAG_trace_precompiler) {
141 THR_Print("Precompiled %" Pd " functions, %" Pd " dynamic types," 146 THR_Print("Precompiled %" Pd " functions, %" Pd " dynamic types,"
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 Code& code_; 1186 Code& code_;
1182 Array& stackmaps_; 1187 Array& stackmaps_;
1183 Stackmap& stackmap_; 1188 Stackmap& stackmap_;
1184 }; 1189 };
1185 1190
1186 DedupStackmapListsVisitor visitor(Z); 1191 DedupStackmapListsVisitor visitor(Z);
1187 VisitFunctions(&visitor); 1192 VisitFunctions(&visitor);
1188 } 1193 }
1189 1194
1190 1195
1196 void Precompiler::DedupInstructions() {
1197 class DedupInstructionsVisitor : public FunctionVisitor {
1198 public:
1199 explicit DedupInstructionsVisitor(Zone* zone) :
1200 zone_(zone),
1201 canonical_instructions_set_(),
1202 code_(Code::Handle(zone)),
1203 instructions_(Instructions::Handle(zone)) {
1204 }
1205
1206 void VisitFunction(const Function& function) {
1207 if (!function.HasCode()) {
1208 ASSERT(function.HasImplicitClosureFunction());
1209 return;
1210 }
1211 code_ = function.CurrentCode();
1212 instructions_ = code_.instructions();
1213 instructions_ = DedupOneInstructions(instructions_);
1214 code_.SetActiveInstructions(instructions_.raw());
1215 code_.set_instructions(instructions_.raw());
1216 function.SetInstructions(code_); // Update cached entry point.
1217 }
1218
1219 RawInstructions* DedupOneInstructions(const Instructions& instructions) {
1220 const Instructions* canonical_instructions =
1221 canonical_instructions_set_.Lookup(&instructions);
1222 if (canonical_instructions == NULL) {
1223 canonical_instructions_set_.Insert(
1224 &Instructions::ZoneHandle(zone_, instructions.raw()));
1225 return instructions.raw();
1226 } else {
1227 return canonical_instructions->raw();
1228 }
1229 }
1230
1231 private:
1232 Zone* zone_;
1233 InstructionsSet canonical_instructions_set_;
1234 Code& code_;
1235 Instructions& instructions_;
1236 };
1237
1238 DedupInstructionsVisitor visitor(Z);
1239 VisitFunctions(&visitor);
1240 }
1241
1191 void Precompiler::VisitFunctions(FunctionVisitor* visitor) { 1242 void Precompiler::VisitFunctions(FunctionVisitor* visitor) {
1192 Library& lib = Library::Handle(Z); 1243 Library& lib = Library::Handle(Z);
1193 Class& cls = Class::Handle(Z); 1244 Class& cls = Class::Handle(Z);
1194 Array& functions = Array::Handle(Z); 1245 Array& functions = Array::Handle(Z);
1195 Object& object = Object::Handle(Z); 1246 Object& object = Object::Handle(Z);
1196 Function& function = Function::Handle(Z); 1247 Function& function = Function::Handle(Z);
1197 GrowableObjectArray& closures = GrowableObjectArray::Handle(Z); 1248 GrowableObjectArray& closures = GrowableObjectArray::Handle(Z);
1198 1249
1199 for (intptr_t i = 0; i < libraries_.Length(); i++) { 1250 for (intptr_t i = 0; i < libraries_.Length(); i++) {
1200 lib ^= libraries_.At(i); 1251 lib ^= libraries_.At(i);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 cls = it.GetNextClass(); 1336 cls = it.GetNextClass();
1286 if (cls.IsDynamicClass()) { 1337 if (cls.IsDynamicClass()) {
1287 continue; // class 'dynamic' is in the read-only VM isolate. 1338 continue; // class 'dynamic' is in the read-only VM isolate.
1288 } 1339 }
1289 cls.set_is_allocated(false); 1340 cls.set_is_allocated(false);
1290 } 1341 }
1291 } 1342 }
1292 } 1343 }
1293 1344
1294 } // namespace dart 1345 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/precompiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698