| 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 "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (result.IsError()) { | 225 if (result.IsError()) { |
| 226 if (result.IsLanguageError()) { | 226 if (result.IsLanguageError()) { |
| 227 Exceptions::ThrowCompileTimeError(LanguageError::Cast(result)); | 227 Exceptions::ThrowCompileTimeError(LanguageError::Cast(result)); |
| 228 UNREACHABLE(); | 228 UNREACHABLE(); |
| 229 } | 229 } |
| 230 Exceptions::PropagateError(Error::Cast(result)); | 230 Exceptions::PropagateError(Error::Cast(result)); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 bool Compiler::CanOptimizeFunction(Thread* thread, const Function& function) { | 234 bool Compiler::CanOptimizeFunction(Thread* thread, const Function& function) { |
| 235 if (FLAG_support_debugger) { | 235 #if !defined(PRODUCT) |
| 236 Isolate* isolate = thread->isolate(); | 236 Isolate* isolate = thread->isolate(); |
| 237 if (isolate->debugger()->IsStepping() || | 237 if (isolate->debugger()->IsStepping() || |
| 238 isolate->debugger()->HasBreakpoint(function, thread->zone())) { | 238 isolate->debugger()->HasBreakpoint(function, thread->zone())) { |
| 239 // We cannot set breakpoints and single step in optimized code, | 239 // We cannot set breakpoints and single step in optimized code, |
| 240 // so do not optimize the function. | 240 // so do not optimize the function. |
| 241 function.set_usage_counter(0); | 241 function.set_usage_counter(0); |
| 242 return false; | 242 return false; |
| 243 } | |
| 244 } | 243 } |
| 244 #endif |
| 245 if (function.deoptimization_counter() >= | 245 if (function.deoptimization_counter() >= |
| 246 FLAG_max_deoptimization_counter_threshold) { | 246 FLAG_max_deoptimization_counter_threshold) { |
| 247 if (FLAG_trace_failed_optimization_attempts || | 247 if (FLAG_trace_failed_optimization_attempts || |
| 248 FLAG_stop_on_excessive_deoptimization) { | 248 FLAG_stop_on_excessive_deoptimization) { |
| 249 THR_Print("Too many deoptimizations: %s\n", | 249 THR_Print("Too many deoptimizations: %s\n", |
| 250 function.ToFullyQualifiedCString()); | 250 function.ToFullyQualifiedCString()); |
| 251 if (FLAG_stop_on_excessive_deoptimization) { | 251 if (FLAG_stop_on_excessive_deoptimization) { |
| 252 FATAL("Stop on excessive deoptimization"); | 252 FATAL("Stop on excessive deoptimization"); |
| 253 } | 253 } |
| 254 } | 254 } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 Array::Handle(zone, graph_compiler->CreateDeoptInfo(assembler)); | 547 Array::Handle(zone, graph_compiler->CreateDeoptInfo(assembler)); |
| 548 INC_STAT(thread(), total_code_size, | 548 INC_STAT(thread(), total_code_size, |
| 549 deopt_info_array.Length() * sizeof(uword)); | 549 deopt_info_array.Length() * sizeof(uword)); |
| 550 // Allocates instruction object. Since this occurs only at safepoint, | 550 // Allocates instruction object. Since this occurs only at safepoint, |
| 551 // there can be no concurrent access to the instruction page. | 551 // there can be no concurrent access to the instruction page. |
| 552 Code& code = | 552 Code& code = |
| 553 Code::Handle(Code::FinalizeCode(function, assembler, optimized())); | 553 Code::Handle(Code::FinalizeCode(function, assembler, optimized())); |
| 554 code.set_is_optimized(optimized()); | 554 code.set_is_optimized(optimized()); |
| 555 code.set_owner(function); | 555 code.set_owner(function); |
| 556 #if !defined(PRODUCT) | 556 #if !defined(PRODUCT) |
| 557 if (FLAG_support_debugger) { | 557 ZoneGrowableArray<TokenPosition>* await_token_positions = |
| 558 ZoneGrowableArray<TokenPosition>* await_token_positions = | 558 flow_graph->await_token_positions(); |
| 559 flow_graph->await_token_positions(); | 559 if (await_token_positions != NULL) { |
| 560 if (await_token_positions != NULL) { | 560 Smi& token_pos_value = Smi::Handle(zone); |
| 561 Smi& token_pos_value = Smi::Handle(zone); | 561 if (await_token_positions->length() > 0) { |
| 562 if (await_token_positions->length() > 0) { | 562 const Array& await_to_token_map = Array::Handle( |
| 563 const Array& await_to_token_map = Array::Handle( | 563 zone, Array::New(await_token_positions->length(), Heap::kOld)); |
| 564 zone, Array::New(await_token_positions->length(), Heap::kOld)); | 564 ASSERT(!await_to_token_map.IsNull()); |
| 565 ASSERT(!await_to_token_map.IsNull()); | 565 for (intptr_t i = 0; i < await_token_positions->length(); i++) { |
| 566 for (intptr_t i = 0; i < await_token_positions->length(); i++) { | 566 TokenPosition token_pos = await_token_positions->At(i).FromSynthetic(); |
| 567 TokenPosition token_pos = | 567 if (!token_pos.IsReal()) { |
| 568 await_token_positions->At(i).FromSynthetic(); | 568 // Some async machinary uses sentinel values. Map them to |
| 569 if (!token_pos.IsReal()) { | 569 // no source position. |
| 570 // Some async machinary uses sentinel values. Map them to | 570 token_pos_value = Smi::New(TokenPosition::kNoSourcePos); |
| 571 // no source position. | 571 } else { |
| 572 token_pos_value = Smi::New(TokenPosition::kNoSourcePos); | 572 token_pos_value = Smi::New(token_pos.value()); |
| 573 } else { | |
| 574 token_pos_value = Smi::New(token_pos.value()); | |
| 575 } | |
| 576 await_to_token_map.SetAt(i, token_pos_value); | |
| 577 } | 573 } |
| 578 code.set_await_token_positions(await_to_token_map); | 574 await_to_token_map.SetAt(i, token_pos_value); |
| 579 } | 575 } |
| 576 code.set_await_token_positions(await_to_token_map); |
| 580 } | 577 } |
| 581 } | 578 } |
| 582 #endif // !defined(PRODUCT) | 579 #endif // !defined(PRODUCT) |
| 583 | 580 |
| 584 if (!function.IsOptimizable()) { | 581 if (!function.IsOptimizable()) { |
| 585 // A function with huge unoptimized code can become non-optimizable | 582 // A function with huge unoptimized code can become non-optimizable |
| 586 // after generating unoptimized code. | 583 // after generating unoptimized code. |
| 587 function.set_usage_counter(INT_MIN); | 584 function.set_usage_counter(INT_MIN); |
| 588 } | 585 } |
| 589 | 586 |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 per_compile_timer.Stop(); | 1340 per_compile_timer.Stop(); |
| 1344 | 1341 |
| 1345 if (trace_compiler) { | 1342 if (trace_compiler) { |
| 1346 THR_Print("--> '%s' entry: %#" Px " size: %" Pd " time: %" Pd64 " us\n", | 1343 THR_Print("--> '%s' entry: %#" Px " size: %" Pd " time: %" Pd64 " us\n", |
| 1347 function.ToFullyQualifiedCString(), | 1344 function.ToFullyQualifiedCString(), |
| 1348 Code::Handle(function.CurrentCode()).PayloadStart(), | 1345 Code::Handle(function.CurrentCode()).PayloadStart(), |
| 1349 Code::Handle(function.CurrentCode()).Size(), | 1346 Code::Handle(function.CurrentCode()).Size(), |
| 1350 per_compile_timer.TotalElapsedTime()); | 1347 per_compile_timer.TotalElapsedTime()); |
| 1351 } | 1348 } |
| 1352 | 1349 |
| 1353 if (FLAG_support_debugger) { | 1350 #if !defined(PRODUCT) |
| 1354 isolate->debugger()->NotifyCompilation(function); | 1351 isolate->debugger()->NotifyCompilation(function); |
| 1355 } | 1352 #endif |
| 1356 | 1353 |
| 1357 if (FLAG_disassemble && FlowGraphPrinter::ShouldPrint(function)) { | 1354 if (FLAG_disassemble && FlowGraphPrinter::ShouldPrint(function)) { |
| 1358 Disassembler::DisassembleCode(function, result, optimized); | 1355 Disassembler::DisassembleCode(function, result, optimized); |
| 1359 } else if (FLAG_disassemble_optimized && optimized && | 1356 } else if (FLAG_disassemble_optimized && optimized && |
| 1360 FlowGraphPrinter::ShouldPrint(function)) { | 1357 FlowGraphPrinter::ShouldPrint(function)) { |
| 1361 Disassembler::DisassembleCode(function, result, true); | 1358 Disassembler::DisassembleCode(function, result, true); |
| 1362 } | 1359 } |
| 1363 | 1360 |
| 1364 return result.raw(); | 1361 return result.raw(); |
| 1365 } else { | 1362 } else { |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2285 } | 2282 } |
| 2286 | 2283 |
| 2287 bool BackgroundCompiler::IsDisabled() { | 2284 bool BackgroundCompiler::IsDisabled() { |
| 2288 UNREACHABLE(); | 2285 UNREACHABLE(); |
| 2289 return true; | 2286 return true; |
| 2290 } | 2287 } |
| 2291 | 2288 |
| 2292 #endif // DART_PRECOMPILED_RUNTIME | 2289 #endif // DART_PRECOMPILED_RUNTIME |
| 2293 | 2290 |
| 2294 } // namespace dart | 2291 } // namespace dart |
| OLD | NEW |