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

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

Issue 11411072: Simplify CodePatcher::GetStaticCallAt. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « no previous file | runtime/vm/code_patcher.h » ('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/code_generator.h" 5 #include "vm/code_generator.h"
6 6
7 #include "vm/assembler_macros.h" 7 #include "vm/assembler_macros.h"
8 #include "vm/ast.h" 8 #include "vm/ast.h"
9 #include "vm/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 763
764 764
765 DEFINE_RUNTIME_ENTRY(ReThrow, 2) { 765 DEFINE_RUNTIME_ENTRY(ReThrow, 2) {
766 ASSERT(arguments.ArgCount() == kReThrowRuntimeEntry.argument_count()); 766 ASSERT(arguments.ArgCount() == kReThrowRuntimeEntry.argument_count());
767 const Instance& exception = Instance::CheckedHandle(arguments.ArgAt(0)); 767 const Instance& exception = Instance::CheckedHandle(arguments.ArgAt(0));
768 const Instance& stacktrace = Instance::CheckedHandle(arguments.ArgAt(1)); 768 const Instance& stacktrace = Instance::CheckedHandle(arguments.ArgAt(1));
769 Exceptions::ReThrow(exception, stacktrace); 769 Exceptions::ReThrow(exception, stacktrace);
770 } 770 }
771 771
772 772
773 // Patches static call with the target's entry point. Compiles target if
774 // necessary.
773 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) { 775 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) {
774 // This function is called after successful resolving and compilation of 776 // This function is called after successful resolving and compilation of
775 // the target method. 777 // the target method.
regis 2012/11/19 18:35:19 The comment states "called after compilation", but
srdjan 2012/11/19 19:15:44 Removed that comment. The code is in transition.
776 ASSERT(arguments.ArgCount() == kPatchStaticCallRuntimeEntry.argument_count()); 778 ASSERT(arguments.ArgCount() == kPatchStaticCallRuntimeEntry.argument_count());
777 DartFrameIterator iterator; 779 DartFrameIterator iterator;
778 StackFrame* caller_frame = iterator.NextFrame(); 780 StackFrame* caller_frame = iterator.NextFrame();
779 ASSERT(caller_frame != NULL); 781 ASSERT(caller_frame != NULL);
780 uword target = 0; 782 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode());
781 Function& target_function = Function::Handle(); 783 ASSERT(!caller_code.IsNull());
782 CodePatcher::GetStaticCallAt(caller_frame->pc(), &target_function, &target); 784 const Function& target_function = Function::Handle(
783 ASSERT(target_function.HasCode()); 785 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc()));
786 if (!target_function.HasCode()) {
787 const Error& error =
788 Error::Handle(Compiler::CompileFunction(target_function));
789 if (!error.IsNull()) {
790 Exceptions::PropagateError(error);
791 }
792 }
784 const Code& target_code = Code::Handle(target_function.CurrentCode()); 793 const Code& target_code = Code::Handle(target_function.CurrentCode());
785 uword new_target = target_code.EntryPoint(); 794 // Before patching verify that we are not repeatedly patching to the same
786 // Verify that we are not patching repeatedly. 795 // target.
787 ASSERT(target != new_target); 796 ASSERT(target_code.EntryPoint() !=
788 CodePatcher::PatchStaticCallAt(caller_frame->pc(), new_target); 797 CodePatcher::GetStaticCallTargetAt(caller_frame->pc()));
789 const Code& code = Code::Handle(caller_frame->LookupDartCode()); 798 CodePatcher::PatchStaticCallAt(caller_frame->pc(), target_code.EntryPoint());
790 code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); 799 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code);
791 if (FLAG_trace_patching) { 800 if (FLAG_trace_patching) {
792 OS::Print("PatchStaticCall: patching from %#"Px" to '%s' %#"Px"\n", 801 OS::Print("PatchStaticCall: patching from %#"Px" to '%s' %#"Px"\n",
793 caller_frame->pc(), 802 caller_frame->pc(),
794 target_function.ToFullyQualifiedCString(), 803 target_function.ToFullyQualifiedCString(),
795 new_target); 804 target_code.EntryPoint());
796 } 805 }
797 } 806 }
798 807
799 808
800 // Resolves and compiles the target function of an instance call, updates 809 // Resolves and compiles the target function of an instance call, updates
801 // function cache of the receiver's class and returns the compiled code or null. 810 // function cache of the receiver's class and returns the compiled code or null.
802 // Only the number of named arguments is checked, but not the actual names. 811 // Only the number of named arguments is checked, but not the actual names.
803 RawCode* ResolveCompileInstanceCallTarget(Isolate* isolate, 812 RawCode* ResolveCompileInstanceCallTarget(Isolate* isolate,
804 const Instance& receiver) { 813 const Instance& receiver) {
805 int num_arguments = -1; 814 int num_arguments = -1;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 if (FLAG_trace_failed_optimization_attempts) { 1524 if (FLAG_trace_failed_optimization_attempts) {
1516 PrintCaller("Not Optimizable"); 1525 PrintCaller("Not Optimizable");
1517 } 1526 }
1518 // TODO(5442338): Abort as this should not happen. 1527 // TODO(5442338): Abort as this should not happen.
1519 function.set_usage_counter(kLowInvocationCount); 1528 function.set_usage_counter(kLowInvocationCount);
1520 } 1529 }
1521 } 1530 }
1522 1531
1523 1532
1524 // The caller must be a static call in a Dart frame, or an entry frame. 1533 // The caller must be a static call in a Dart frame, or an entry frame.
1525 // Patch static call to point to 'new_entry_point'. 1534 // Patch static call to point to 'new_entry_point'.
regis 2012/11/19 18:35:19 What is 'new_entry_point'? A comment describing th
srdjan 2012/11/19 19:15:44 new_entry_point -> "valid code's entry point" Next
1526 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 1) { 1535 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 1) {
1527 ASSERT(arguments.ArgCount() == 1536 ASSERT(arguments.ArgCount() ==
1528 kFixCallersTargetRuntimeEntry.argument_count()); 1537 kFixCallersTargetRuntimeEntry.argument_count());
1529 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); 1538 const Function& function = Function::CheckedHandle(arguments.ArgAt(0));
1530 ASSERT(!function.IsNull()); 1539 ASSERT(!function.IsNull());
1531 ASSERT(function.HasCode()); 1540 ASSERT(function.HasCode());
1532 1541
1533 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); 1542 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames);
1534 StackFrame* frame = iterator.NextFrame(); 1543 StackFrame* frame = iterator.NextFrame();
1535 while (frame != NULL && (frame->IsStubFrame() || frame->IsExitFrame())) { 1544 while (frame != NULL && (frame->IsStubFrame() || frame->IsExitFrame())) {
1536 frame = iterator.NextFrame(); 1545 frame = iterator.NextFrame();
1537 } 1546 }
1538 ASSERT(frame != NULL); 1547 ASSERT(frame != NULL);
1539 if (!frame->IsEntryFrame()) { 1548 if (!frame->IsEntryFrame()) {
1540 ASSERT(frame->IsDartFrame()); 1549 ASSERT(frame->IsDartFrame());
1541 uword target = 0; 1550 uword target = CodePatcher::GetStaticCallTargetAt(frame->pc());
1542 Function& target_function = Function::Handle();
1543 CodePatcher::GetStaticCallAt(frame->pc(), &target_function, &target);
1544 ASSERT(target_function.HasCode());
1545 ASSERT(target_function.raw() == function.raw());
1546 const Code& target_code = Code::Handle(function.CurrentCode()); 1551 const Code& target_code = Code::Handle(function.CurrentCode());
1547 const uword new_entry_point = target_code.EntryPoint(); 1552 const uword new_entry_point = target_code.EntryPoint();
1548 ASSERT(target != new_entry_point); // Why patch otherwise. 1553 ASSERT(target != new_entry_point); // Why patch otherwise.
1549 CodePatcher::PatchStaticCallAt(frame->pc(), new_entry_point); 1554 CodePatcher::PatchStaticCallAt(frame->pc(), new_entry_point);
1550 const Code& code = Code::Handle(frame->LookupDartCode()); 1555 const Code& code = Code::Handle(frame->LookupDartCode());
1551 code.SetStaticCallTargetCodeAt(frame->pc(), target_code); 1556 code.SetStaticCallTargetCodeAt(frame->pc(), target_code);
1552 if (FLAG_trace_patching) { 1557 if (FLAG_trace_patching) {
1553 OS::Print("FixCallersTarget: patching from %#"Px" to '%s' %#"Px"\n", 1558 OS::Print("FixCallersTarget: patching from %#"Px" to '%s' %#"Px"\n",
1554 frame->pc(), 1559 frame->pc(),
1555 target_function.ToFullyQualifiedCString(), 1560 Function::Handle(target_code.function()).ToFullyQualifiedCString(),
1556 new_entry_point); 1561 new_entry_point);
1557 } 1562 }
1558 } 1563 }
1559 } 1564 }
1560 1565
1561 1566
1562 const char* DeoptReasonToText(intptr_t deopt_id) { 1567 const char* DeoptReasonToText(intptr_t deopt_id) {
1563 switch (deopt_id) { 1568 switch (deopt_id) {
1564 #define DEOPT_REASON_ID_TO_TEXT(name) case kDeopt##name: return #name; 1569 #define DEOPT_REASON_ID_TO_TEXT(name) case kDeopt##name: return #name;
1565 DEOPT_REASONS(DEOPT_REASON_ID_TO_TEXT) 1570 DEOPT_REASONS(DEOPT_REASON_ID_TO_TEXT)
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 intptr_t line, column; 1903 intptr_t line, column;
1899 script.GetTokenLocation(token_pos, &line, &column); 1904 script.GetTokenLocation(token_pos, &line, &column);
1900 String& line_string = String::Handle(script.GetLine(line)); 1905 String& line_string = String::Handle(script.GetLine(line));
1901 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); 1906 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString());
1902 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); 1907 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString());
1903 } 1908 }
1904 } 1909 }
1905 1910
1906 1911
1907 } // namespace dart 1912 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/code_patcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698