OLD | NEW |
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/aot_optimizer.h" | 7 #include "vm/aot_optimizer.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/branch_optimizer.h" | 10 #include "vm/branch_optimizer.h" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 I->object_store()->set_completer_class(null_class); | 389 I->object_store()->set_completer_class(null_class); |
390 I->object_store()->set_stream_iterator_class(null_class); | 390 I->object_store()->set_stream_iterator_class(null_class); |
391 I->object_store()->set_symbol_class(null_class); | 391 I->object_store()->set_symbol_class(null_class); |
392 } | 392 } |
393 DropClasses(); | 393 DropClasses(); |
394 DropLibraries(); | 394 DropLibraries(); |
395 | 395 |
396 BindStaticCalls(); | 396 BindStaticCalls(); |
397 SwitchICCalls(); | 397 SwitchICCalls(); |
398 | 398 |
| 399 ShareMegamorphicBuckets(); |
399 DedupStackmaps(); | 400 DedupStackmaps(); |
400 DedupStackmapLists(); | 401 DedupLists(); |
401 | 402 |
402 if (FLAG_dedup_instructions) { | 403 if (FLAG_dedup_instructions) { |
403 // Reduces binary size but obfuscates profiler results. | 404 // Reduces binary size but obfuscates profiler results. |
404 DedupInstructions(); | 405 DedupInstructions(); |
405 } | 406 } |
406 | 407 |
407 zone_ = NULL; | 408 zone_ = NULL; |
408 } | 409 } |
409 | 410 |
410 intptr_t symbols_before = -1; | 411 intptr_t symbols_before = -1; |
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2145 Code& target_code_; | 2146 Code& target_code_; |
2146 }; | 2147 }; |
2147 | 2148 |
2148 ASSERT(!I->compilation_allowed()); | 2149 ASSERT(!I->compilation_allowed()); |
2149 SwitchICCallsVisitor visitor(Z); | 2150 SwitchICCallsVisitor visitor(Z); |
2150 VisitFunctions(&visitor); | 2151 VisitFunctions(&visitor); |
2151 #endif | 2152 #endif |
2152 } | 2153 } |
2153 | 2154 |
2154 | 2155 |
| 2156 void Precompiler::ShareMegamorphicBuckets() { |
| 2157 const GrowableObjectArray& table = GrowableObjectArray::Handle(Z, |
| 2158 I->object_store()->megamorphic_cache_table()); |
| 2159 if (table.IsNull()) return; |
| 2160 MegamorphicCache& cache = MegamorphicCache::Handle(Z); |
| 2161 |
| 2162 const intptr_t capacity = 1; |
| 2163 const Array& buckets = Array::Handle(Z, |
| 2164 Array::New(MegamorphicCache::kEntryLength * capacity, Heap::kOld)); |
| 2165 const Function& handler = |
| 2166 Function::Handle(Z, MegamorphicCacheTable::miss_handler(I)); |
| 2167 MegamorphicCache::SetEntry(buckets, 0, |
| 2168 MegamorphicCache::smi_illegal_cid(), handler); |
| 2169 |
| 2170 for (intptr_t i = 0; i < table.Length(); i++) { |
| 2171 cache ^= table.At(i); |
| 2172 cache.set_buckets(buckets); |
| 2173 cache.set_mask(capacity - 1); |
| 2174 cache.set_filled_entry_count(0); |
| 2175 } |
| 2176 } |
| 2177 |
| 2178 |
2155 void Precompiler::DedupStackmaps() { | 2179 void Precompiler::DedupStackmaps() { |
2156 class DedupStackmapsVisitor : public FunctionVisitor { | 2180 class DedupStackmapsVisitor : public FunctionVisitor { |
2157 public: | 2181 public: |
2158 explicit DedupStackmapsVisitor(Zone* zone) : | 2182 explicit DedupStackmapsVisitor(Zone* zone) : |
2159 zone_(zone), | 2183 zone_(zone), |
2160 canonical_stackmaps_(), | 2184 canonical_stackmaps_(), |
2161 code_(Code::Handle(zone)), | 2185 code_(Code::Handle(zone)), |
2162 stackmaps_(Array::Handle(zone)), | 2186 stackmaps_(Array::Handle(zone)), |
2163 stackmap_(Stackmap::Handle(zone)) { | 2187 stackmap_(Stackmap::Handle(zone)) { |
2164 } | 2188 } |
(...skipping 30 matching lines...) Expand all Loading... |
2195 Code& code_; | 2219 Code& code_; |
2196 Array& stackmaps_; | 2220 Array& stackmaps_; |
2197 Stackmap& stackmap_; | 2221 Stackmap& stackmap_; |
2198 }; | 2222 }; |
2199 | 2223 |
2200 DedupStackmapsVisitor visitor(Z); | 2224 DedupStackmapsVisitor visitor(Z); |
2201 VisitFunctions(&visitor); | 2225 VisitFunctions(&visitor); |
2202 } | 2226 } |
2203 | 2227 |
2204 | 2228 |
2205 void Precompiler::DedupStackmapLists() { | 2229 void Precompiler::DedupLists() { |
2206 class DedupStackmapListsVisitor : public FunctionVisitor { | 2230 class DedupListsVisitor : public FunctionVisitor { |
2207 public: | 2231 public: |
2208 explicit DedupStackmapListsVisitor(Zone* zone) : | 2232 explicit DedupListsVisitor(Zone* zone) : |
2209 zone_(zone), | 2233 zone_(zone), |
2210 canonical_stackmap_lists_(), | 2234 canonical_lists_(), |
2211 code_(Code::Handle(zone)), | 2235 code_(Code::Handle(zone)), |
2212 stackmaps_(Array::Handle(zone)), | 2236 list_(Array::Handle(zone)) { |
2213 stackmap_(Stackmap::Handle(zone)) { | |
2214 } | 2237 } |
2215 | 2238 |
2216 void Visit(const Function& function) { | 2239 void Visit(const Function& function) { |
2217 if (!function.HasCode()) { | 2240 code_ = function.CurrentCode(); |
2218 return; | 2241 if (!code_.IsNull()) { |
| 2242 list_ = code_.stackmaps(); |
| 2243 if (!list_.IsNull()) { |
| 2244 list_ = DedupList(list_); |
| 2245 code_.set_stackmaps(list_); |
| 2246 } |
2219 } | 2247 } |
2220 code_ = function.CurrentCode(); | |
2221 stackmaps_ = code_.stackmaps(); | |
2222 if (stackmaps_.IsNull()) return; | |
2223 | 2248 |
2224 stackmaps_ = DedupStackmapList(stackmaps_); | 2249 list_ = function.parameter_types(); |
2225 code_.set_stackmaps(stackmaps_); | 2250 if (!list_.IsNull()) { |
| 2251 if (!function.IsSignatureFunction() && |
| 2252 !function.IsClosureFunction() && |
| 2253 (function.name() != Symbols::Call().raw()) && |
| 2254 !list_.InVMHeap()) { |
| 2255 // Parameter types not needed for function type tests. |
| 2256 for (intptr_t i = 0; i < list_.Length(); i++) { |
| 2257 list_.SetAt(i, Object::dynamic_type()); |
| 2258 } |
| 2259 } |
| 2260 list_ = DedupList(list_); |
| 2261 function.set_parameter_types(list_); |
| 2262 } |
| 2263 |
| 2264 list_ = function.parameter_names(); |
| 2265 if (!list_.IsNull()) { |
| 2266 if (!function.HasOptionalNamedParameters() && |
| 2267 !list_.InVMHeap()) { |
| 2268 // Parameter names not needed for resolution. |
| 2269 for (intptr_t i = 0; i < list_.Length(); i++) { |
| 2270 list_.SetAt(i, Symbols::OptimizedOut()); |
| 2271 } |
| 2272 } |
| 2273 list_ = DedupList(list_); |
| 2274 function.set_parameter_names(list_); |
| 2275 } |
2226 } | 2276 } |
2227 | 2277 |
2228 RawArray* DedupStackmapList(const Array& stackmaps) { | 2278 RawArray* DedupList(const Array& list) { |
2229 const Array* canonical_stackmap_list = | 2279 const Array* canonical_list = canonical_lists_.LookupValue(&list); |
2230 canonical_stackmap_lists_.LookupValue(&stackmaps); | 2280 if (canonical_list == NULL) { |
2231 if (canonical_stackmap_list == NULL) { | 2281 canonical_lists_.Insert(&Array::ZoneHandle(zone_, list.raw())); |
2232 canonical_stackmap_lists_.Insert( | 2282 return list.raw(); |
2233 &Array::ZoneHandle(zone_, stackmaps.raw())); | |
2234 return stackmaps.raw(); | |
2235 } else { | 2283 } else { |
2236 return canonical_stackmap_list->raw(); | 2284 return canonical_list->raw(); |
2237 } | 2285 } |
2238 } | 2286 } |
2239 | 2287 |
2240 private: | 2288 private: |
2241 Zone* zone_; | 2289 Zone* zone_; |
2242 ArraySet canonical_stackmap_lists_; | 2290 ArraySet canonical_lists_; |
2243 Code& code_; | 2291 Code& code_; |
2244 Array& stackmaps_; | 2292 Array& list_; |
2245 Stackmap& stackmap_; | |
2246 }; | 2293 }; |
2247 | 2294 |
2248 DedupStackmapListsVisitor visitor(Z); | 2295 DedupListsVisitor visitor(Z); |
2249 VisitFunctions(&visitor); | 2296 VisitFunctions(&visitor); |
2250 } | 2297 } |
2251 | 2298 |
2252 | 2299 |
2253 void Precompiler::DedupInstructions() { | 2300 void Precompiler::DedupInstructions() { |
2254 class DedupInstructionsVisitor : public FunctionVisitor { | 2301 class DedupInstructionsVisitor : public FunctionVisitor { |
2255 public: | 2302 public: |
2256 explicit DedupInstructionsVisitor(Zone* zone) : | 2303 explicit DedupInstructionsVisitor(Zone* zone) : |
2257 zone_(zone), | 2304 zone_(zone), |
2258 canonical_instructions_set_(), | 2305 canonical_instructions_set_(), |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3266 | 3313 |
3267 ASSERT(FLAG_precompiled_mode); | 3314 ASSERT(FLAG_precompiled_mode); |
3268 const bool optimized = function.IsOptimizable(); // False for natives. | 3315 const bool optimized = function.IsOptimizable(); // False for natives. |
3269 DartPrecompilationPipeline pipeline(zone, field_type_map); | 3316 DartPrecompilationPipeline pipeline(zone, field_type_map); |
3270 return PrecompileFunctionHelper(&pipeline, function, optimized); | 3317 return PrecompileFunctionHelper(&pipeline, function, optimized); |
3271 } | 3318 } |
3272 | 3319 |
3273 #endif // DART_PRECOMPILER | 3320 #endif // DART_PRECOMPILER |
3274 | 3321 |
3275 } // namespace dart | 3322 } // namespace dart |
OLD | NEW |