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

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

Issue 9696020: Deoptimize functions before setting breakpoints (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/debugger.h ('k') | runtime/vm/debugger_api_impl_test.cc » ('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 "vm/debugger.h" 5 #include "vm/debugger.h"
6 6
7 #include "vm/code_index_table.h" 7 #include "vm/code_index_table.h"
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 #include "vm/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 if (!cls.IsNull()) { 478 if (!cls.IsNull()) {
479 function = cls.LookupStaticFunction(function_name); 479 function = cls.LookupStaticFunction(function_name);
480 if (function.IsNull()) { 480 if (function.IsNull()) {
481 function = cls.LookupDynamicFunction(function_name); 481 function = cls.LookupDynamicFunction(function_name);
482 } 482 }
483 } 483 }
484 return function.raw(); 484 return function.raw();
485 } 485 }
486 486
487 487
488 void Debugger::InstrumentForStepping(const Function &target_function) { 488 // Deoptimize function if necessary. Does not patch return addresses on the
489 if (!target_function.HasCode()) { 489 // stack. If there are activation frames of this function on the stack,
490 // the optimized code will be executed when the callee returns.
491 void Debugger::EnsureFunctionIsDeoptimized(const Function& func) {
492 if (func.HasOptimizedCode()) {
493 if (verbose) {
494 OS::Print("Deoptimizing function %s\n",
495 String::Handle(func.name()).ToCString());
496 }
497 func.set_usage_counter(0);
498 func.set_deoptimization_counter(func.deoptimization_counter() + 1);
499 Compiler::CompileFunction(func);
500 ASSERT(!func.HasOptimizedCode());
501 }
502 }
503
504
505 void Debugger::InstrumentForStepping(const Function& target_function) {
506 if (target_function.HasCode()) {
507 EnsureFunctionIsDeoptimized(target_function);
508 } else {
490 Compiler::CompileFunction(target_function); 509 Compiler::CompileFunction(target_function);
491 // If there were any errors, ignore them silently and return without 510 // If there were any errors, ignore them silently and return without
492 // adding breakpoints to target. 511 // adding breakpoints to target.
493 if (!target_function.HasCode()) { 512 if (!target_function.HasCode()) {
494 return; 513 return;
495 } 514 }
496 } 515 }
497 ASSERT(!target_function.HasOptimizedCode());
498 Code& code = Code::Handle(target_function.unoptimized_code()); 516 Code& code = Code::Handle(target_function.unoptimized_code());
499 ASSERT(!code.IsNull()); 517 ASSERT(!code.IsNull());
500 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 518 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
501 for (int i = 0; i < desc.Length(); i++) { 519 for (int i = 0; i < desc.Length(); i++) {
502 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); 520 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i));
503 if (bpt != NULL) { 521 if (bpt != NULL) {
504 // There is already a breakpoint for this address. Leave it alone. 522 // There is already a breakpoint for this address. Leave it alone.
505 continue; 523 continue;
506 } 524 }
507 PcDescriptors::Kind kind = desc.DescriptorKind(i); 525 PcDescriptors::Kind kind = desc.DescriptorKind(i);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 574 }
557 575
558 576
559 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function, 577 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function,
560 intptr_t token_index) { 578 intptr_t token_index) {
561 if ((token_index < target_function.token_index()) || 579 if ((token_index < target_function.token_index()) ||
562 (target_function.end_token_index() <= token_index)) { 580 (target_function.end_token_index() <= token_index)) {
563 // The given token position is not within the target function. 581 // The given token position is not within the target function.
564 return NULL; 582 return NULL;
565 } 583 }
584 EnsureFunctionIsDeoptimized(target_function);
566 SourceBreakpoint* bpt = GetSourceBreakpoint(target_function, token_index); 585 SourceBreakpoint* bpt = GetSourceBreakpoint(target_function, token_index);
567 if (bpt != NULL) { 586 if (bpt != NULL) {
568 // A breakpoint for this location already exists, return it. 587 // A breakpoint for this location already exists, return it.
569 return bpt; 588 return bpt;
570 } 589 }
571 bpt = new SourceBreakpoint(target_function, token_index); 590 bpt = new SourceBreakpoint(target_function, token_index);
572 RegisterSourceBreakpoint(bpt); 591 RegisterSourceBreakpoint(bpt);
573 if (verbose && !target_function.HasCode()) { 592 if (verbose && !target_function.HasCode()) {
574 OS::Print("Registering breakpoint for uncompiled function '%s'" 593 OS::Print("Registering breakpoint for uncompiled function '%s'"
575 " (%s:%d)\n", 594 " (%s:%d)\n",
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 1040 }
1022 1041
1023 1042
1024 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 1043 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
1025 ASSERT(bpt->next() == NULL); 1044 ASSERT(bpt->next() == NULL);
1026 bpt->set_next(code_breakpoints_); 1045 bpt->set_next(code_breakpoints_);
1027 code_breakpoints_ = bpt; 1046 code_breakpoints_ = bpt;
1028 } 1047 }
1029 1048
1030 } // namespace dart 1049 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger.h ('k') | runtime/vm/debugger_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698