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

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

Issue 11780005: Allow optimized code when debugger is active (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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/flow_graph_compiler.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 "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/code_patcher.h" 10 #include "vm/code_patcher.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 len++; // String terminator. 209 len++; // String terminator.
210 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 210 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
211 OS::SNPrint(chars, len, kFormat, 211 OS::SNPrint(chars, len, kFormat,
212 func_class.IsTopLevel() ? "" : class_name.ToCString(), 212 func_class.IsTopLevel() ? "" : class_name.ToCString(),
213 func_class.IsTopLevel() ? "" : ".", 213 func_class.IsTopLevel() ? "" : ".",
214 func_name.ToCString()); 214 func_name.ToCString());
215 return chars; 215 return chars;
216 } 216 }
217 217
218 218
219 bool Debugger::HasBreakpoint(const Function& func) {
220 if (!func.HasCode()) {
221 // If the function is not compiled yet, just check whether there
222 // is a user-defined latent breakpoint.
223 SourceBreakpoint* sbpt = src_breakpoints_;
224 while (sbpt != NULL) {
225 if (func.raw() == sbpt->function()) {
226 return true;
227 }
228 sbpt = sbpt->next_;
229 }
230 return false;
231 }
232 CodeBreakpoint* cbpt = code_breakpoints_;
233 while (cbpt != NULL) {
234 if (func.raw() == cbpt->function()) {
235 return true;
236 }
237 cbpt = cbpt->next_;
238 }
239 return false;
240 }
241
242
219 RawString* ActivationFrame::QualifiedFunctionName() { 243 RawString* ActivationFrame::QualifiedFunctionName() {
220 const Function& func = DartFunction(); 244 const Function& func = DartFunction();
221 return String::New(Debugger::QualifiedFunctionName(func)); 245 return String::New(Debugger::QualifiedFunctionName(func));
222 } 246 }
223 247
224 248
225 RawString* ActivationFrame::SourceUrl() { 249 RawString* ActivationFrame::SourceUrl() {
226 const Script& script = Script::Handle(SourceScript()); 250 const Script& script = Script::Handle(SourceScript());
227 return script.url(); 251 return script.url();
228 } 252 }
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 CodeBreakpoint* bpt = code_breakpoints_; 720 CodeBreakpoint* bpt = code_breakpoints_;
697 code_breakpoints_ = code_breakpoints_->next(); 721 code_breakpoints_ = code_breakpoints_->next();
698 bpt->Disable(); 722 bpt->Disable();
699 delete bpt; 723 delete bpt;
700 } 724 }
701 // Signal isolate shutdown event. 725 // Signal isolate shutdown event.
702 SignalIsolateEvent(Debugger::kIsolateShutdown); 726 SignalIsolateEvent(Debugger::kIsolateShutdown);
703 } 727 }
704 728
705 729
706 bool Debugger::IsActive() {
707 // TODO(hausner): The code generator uses this function to prevent
708 // generation of optimized code when Dart code is being debugged.
709 // This is probably not conservative enough (we could set the first
710 // breakpoint after optimized code has already been produced).
711 // Long-term, we need to be able to de-optimize code.
712 return (src_breakpoints_ != NULL) ||
713 (code_breakpoints_ != NULL) ||
714 (exc_pause_info_ != kNoPauseOnExceptions);
715 }
716
717
718 static RawFunction* ResolveLibraryFunction( 730 static RawFunction* ResolveLibraryFunction(
719 const Library& library, 731 const Library& library,
720 const String& fname) { 732 const String& fname) {
721 ASSERT(!library.IsNull()); 733 ASSERT(!library.IsNull());
722 const Object& object = Object::Handle(library.LookupObject(fname)); 734 const Object& object = Object::Handle(library.LookupObject(fname));
723 if (!object.IsNull() && object.IsFunction()) { 735 if (!object.IsNull() && object.IsFunction()) {
724 return Function::Cast(object).raw(); 736 return Function::Cast(object).raw();
725 } 737 }
726 return Function::null(); 738 return Function::null();
727 } 739 }
(...skipping 13 matching lines...) Expand all
741 if (!cls.IsNull()) { 753 if (!cls.IsNull()) {
742 function = cls.LookupStaticFunction(function_name); 754 function = cls.LookupStaticFunction(function_name);
743 if (function.IsNull()) { 755 if (function.IsNull()) {
744 function = cls.LookupDynamicFunction(function_name); 756 function = cls.LookupDynamicFunction(function_name);
745 } 757 }
746 } 758 }
747 return function.raw(); 759 return function.raw();
748 } 760 }
749 761
750 762
751 // Deoptimize function if necessary. Does not patch return addresses on the 763 // Deoptimize all functions in the isolate.
752 // stack. If there are activation frames of this function on the stack, 764 // TODO(hausner): Actually we only need to deoptimize those functions
753 // the optimized code will be executed when the callee returns. 765 // that inline the function that contains the newly created breakpoint.
754 void Debugger::EnsureFunctionIsDeoptimized(const Function& func) { 766 // We currently don't have this info so we deoptimize all functions.
755 if (func.HasOptimizedCode()) { 767 void Debugger::DeoptimizeWorld() {
756 if (FLAG_verbose_debug) { 768 // Deoptimize all functions in stack activation frames.
757 OS::Print("Deoptimizing function %s\n", 769 DeoptimizeAll();
758 String::Handle(func.name()).ToCString()); 770 // Iterate over all classes, deoptimize functions.
771 // TODO(hausner): Could possibly be combined with RemoveOptimizedCode()
772 const ClassTable& class_table = *isolate_->class_table();
773 Class& cls = Class::Handle();
774 Array& functions = Array::Handle();
775 Function& function = Function::Handle();
776 intptr_t num_classes = class_table.NumCids();
777 for (intptr_t i = 1; i < num_classes; i++) {
778 if (class_table.HasValidClassAt(i)) {
779 cls = class_table.At(i);
780 functions = cls.functions();
781 intptr_t num_functions = functions.IsNull() ? 0 : functions.Length();
782 for (intptr_t f = 0; f < num_functions; f++) {
783 function ^= functions.At(f);
784 ASSERT(!function.IsNull());
785 if (function.HasOptimizedCode()) {
786 function.SwitchToUnoptimizedCode();
787 }
788 }
759 } 789 }
760 func.set_usage_counter(0);
761 func.set_deoptimization_counter(func.deoptimization_counter() + 1);
762 Compiler::CompileFunction(func);
763 ASSERT(!func.HasOptimizedCode());
764 } 790 }
765 } 791 }
766 792
767 793
768 void Debugger::InstrumentForStepping(const Function& target_function) { 794 void Debugger::InstrumentForStepping(const Function& target_function) {
769 if (target_function.HasCode()) { 795 if (!target_function.HasCode()) {
770 EnsureFunctionIsDeoptimized(target_function);
771 } else {
772 Compiler::CompileFunction(target_function); 796 Compiler::CompileFunction(target_function);
773 // If there were any errors, ignore them silently and return without 797 // If there were any errors, ignore them silently and return without
774 // adding breakpoints to target. 798 // adding breakpoints to target.
775 if (!target_function.HasCode()) { 799 if (!target_function.HasCode()) {
776 return; 800 return;
777 } 801 }
778 } 802 }
803 DeoptimizeWorld();
804 ASSERT(!target_function.HasOptimizedCode());
779 Code& code = Code::Handle(target_function.unoptimized_code()); 805 Code& code = Code::Handle(target_function.unoptimized_code());
780 ASSERT(!code.IsNull()); 806 ASSERT(!code.IsNull());
781 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 807 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
782 for (int i = 0; i < desc.Length(); i++) { 808 for (int i = 0; i < desc.Length(); i++) {
783 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); 809 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i));
784 if (bpt != NULL) { 810 if (bpt != NULL) {
785 // There is already a breakpoint for this address. Make sure 811 // There is already a breakpoint for this address. Make sure
786 // it is enabled. 812 // it is enabled.
787 bpt->Enable(); 813 bpt->Enable();
788 continue; 814 continue;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 991
966 992
967 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function, 993 SourceBreakpoint* Debugger::SetBreakpoint(const Function& target_function,
968 intptr_t first_token_pos, 994 intptr_t first_token_pos,
969 intptr_t last_token_pos) { 995 intptr_t last_token_pos) {
970 if ((last_token_pos < target_function.token_pos()) || 996 if ((last_token_pos < target_function.token_pos()) ||
971 (target_function.end_token_pos() < first_token_pos)) { 997 (target_function.end_token_pos() < first_token_pos)) {
972 // The given token position is not within the target function. 998 // The given token position is not within the target function.
973 return NULL; 999 return NULL;
974 } 1000 }
975 EnsureFunctionIsDeoptimized(target_function); 1001 DeoptimizeWorld();
1002 ASSERT(!target_function.HasOptimizedCode());
976 1003
977 CodeBreakpoint* cbpt = NULL; 1004 CodeBreakpoint* cbpt = NULL;
978 SourceBreakpoint* source_bpt = NULL; 1005 SourceBreakpoint* source_bpt = NULL;
979 if (target_function.HasCode()) { 1006 if (target_function.HasCode()) {
980 cbpt = MakeCodeBreakpoint(target_function, first_token_pos, last_token_pos); 1007 cbpt = MakeCodeBreakpoint(target_function, first_token_pos, last_token_pos);
981 if (cbpt != NULL) { 1008 if (cbpt != NULL) {
982 if (cbpt->src_bpt() != NULL) { 1009 if (cbpt->src_bpt() != NULL) {
983 // There is already a source breakpoint for the location. 1010 // There is already a source breakpoint for the location.
984 ASSERT(cbpt->src_bpt() == 1011 ASSERT(cbpt->src_bpt() ==
985 GetSourceBreakpoint(target_function, cbpt->token_pos())); 1012 GetSourceBreakpoint(target_function, cbpt->token_pos()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 1047 }
1021 } 1048 }
1022 1049
1023 if (target_function.HasImplicitClosureFunction()) { 1050 if (target_function.HasImplicitClosureFunction()) {
1024 // There is a closurized version of this function. If the closure 1051 // There is a closurized version of this function. If the closure
1025 // is already compiled, we need to set a code breakpoint in its 1052 // is already compiled, we need to set a code breakpoint in its
1026 // code. 1053 // code.
1027 const Function& closure = 1054 const Function& closure =
1028 Function::Handle(target_function.ImplicitClosureFunction()); 1055 Function::Handle(target_function.ImplicitClosureFunction());
1029 if (closure.HasCode()) { 1056 if (closure.HasCode()) {
1030 EnsureFunctionIsDeoptimized(closure); 1057 ASSERT(!closure.HasOptimizedCode());
1031 CodeBreakpoint* closure_bpt = 1058 CodeBreakpoint* closure_bpt =
1032 MakeCodeBreakpoint(closure, first_token_pos, last_token_pos); 1059 MakeCodeBreakpoint(closure, first_token_pos, last_token_pos);
1033 if ((closure_bpt != NULL) && (closure_bpt->src_bpt() == NULL)) { 1060 if ((closure_bpt != NULL) && (closure_bpt->src_bpt() == NULL)) {
1034 closure_bpt->set_src_bpt(source_bpt); 1061 closure_bpt->set_src_bpt(source_bpt);
1035 } 1062 }
1036 } 1063 }
1037 } 1064 }
1038 source_bpt->Enable(); 1065 source_bpt->Enable();
1039 return source_bpt; 1066 return source_bpt;
1040 } 1067 }
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 } 1680 }
1654 1681
1655 1682
1656 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 1683 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
1657 ASSERT(bpt->next() == NULL); 1684 ASSERT(bpt->next() == NULL);
1658 bpt->set_next(code_breakpoints_); 1685 bpt->set_next(code_breakpoints_);
1659 code_breakpoints_ = bpt; 1686 code_breakpoints_ = bpt;
1660 } 1687 }
1661 1688
1662 } // namespace dart 1689 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger.h ('k') | runtime/vm/flow_graph_compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698