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

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

Issue 11360116: Pass closure object as first implicit argument to closure functions. (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 | « runtime/vm/stub_code_ia32.cc ('k') | runtime/vm/symbols.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/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/assembler_macros.h" 9 #include "vm/assembler_macros.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
11 #include "vm/flow_graph_compiler.h" 11 #include "vm/flow_graph_compiler.h"
12 #include "vm/instructions.h" 12 #include "vm/instructions.h"
13 #include "vm/object_store.h" 13 #include "vm/object_store.h"
14 #include "vm/pages.h" 14 #include "vm/pages.h"
15 #include "vm/resolver.h" 15 #include "vm/resolver.h"
16 #include "vm/scavenger.h" 16 #include "vm/scavenger.h"
17 #include "vm/stub_code.h" 17 #include "vm/stub_code.h"
18 18
19 19
20 #define __ assembler-> 20 #define __ assembler->
21 21
22 namespace dart { 22 namespace dart {
23 23
24 DEFINE_FLAG(bool, inline_alloc, true, "Inline allocation of objects."); 24 DEFINE_FLAG(bool, inline_alloc, true, "Inline allocation of objects.");
25 DEFINE_FLAG(bool, use_slow_path, false, 25 DEFINE_FLAG(bool, use_slow_path, false,
26 "Set to true for debugging & verifying the slow paths."); 26 "Set to true for debugging & verifying the slow paths.");
27 DECLARE_FLAG(int, optimization_counter_threshold); 27 DECLARE_FLAG(int, optimization_counter_threshold);
28 28
29
30 // Input parameters: 29 // Input parameters:
31 // RSP : points to return address. 30 // RSP : points to return address.
32 // RSP + 8 : address of last argument in argument array. 31 // RSP + 8 : address of last argument in argument array.
33 // RSP + 8*R10 : address of first argument in argument array. 32 // RSP + 8*R10 : address of first argument in argument array.
34 // RSP + 8*R10 + 8 : address of return value. 33 // RSP + 8*R10 + 8 : address of return value.
35 // RBX : address of the runtime function to call. 34 // RBX : address of the runtime function to call.
36 // R10 : number of arguments to the call. 35 // R10 : number of arguments to the call.
37 // Must preserve callee saved registers R12 and R13. 36 // Must preserve callee saved registers R12 and R13.
38 void StubCode::GenerateCallToRuntimeStub(Assembler* assembler) { 37 void StubCode::GenerateCallToRuntimeStub(Assembler* assembler) {
39 ASSERT((R12 != CTX) && (R13 != CTX)); 38 ASSERT((R12 != CTX) && (R13 != CTX));
40 const intptr_t isolate_offset = NativeArguments::isolate_offset(); 39 const intptr_t isolate_offset = NativeArguments::isolate_offset();
41 const intptr_t argc_offset = NativeArguments::argc_offset(); 40 const intptr_t argc_tag_offset = NativeArguments::argc_tag_offset();
42 const intptr_t argv_offset = NativeArguments::argv_offset(); 41 const intptr_t argv_offset = NativeArguments::argv_offset();
43 const intptr_t retval_offset = NativeArguments::retval_offset(); 42 const intptr_t retval_offset = NativeArguments::retval_offset();
44 43
45 __ EnterFrame(0); 44 __ EnterFrame(0);
46 45
47 // Load current Isolate pointer from Context structure into RAX. 46 // Load current Isolate pointer from Context structure into RAX.
48 __ movq(RAX, FieldAddress(CTX, Context::isolate_offset())); 47 __ movq(RAX, FieldAddress(CTX, Context::isolate_offset()));
49 48
50 // Save exit frame information to enable stack walking as we are about 49 // Save exit frame information to enable stack walking as we are about
51 // to transition to Dart VM C++ code. 50 // to transition to Dart VM C++ code.
52 __ movq(Address(RAX, Isolate::top_exit_frame_info_offset()), RSP); 51 __ movq(Address(RAX, Isolate::top_exit_frame_info_offset()), RSP);
53 52
54 // Save current Context pointer into Isolate structure. 53 // Save current Context pointer into Isolate structure.
55 __ movq(Address(RAX, Isolate::top_context_offset()), CTX); 54 __ movq(Address(RAX, Isolate::top_context_offset()), CTX);
56 55
57 // Cache Isolate pointer into CTX while executing runtime code. 56 // Cache Isolate pointer into CTX while executing runtime code.
58 __ movq(CTX, RAX); 57 __ movq(CTX, RAX);
59 58
60 // Reserve space for arguments and align frame before entering C++ world. 59 // Reserve space for arguments and align frame before entering C++ world.
61 __ AddImmediate(RSP, Immediate(-sizeof(NativeArguments))); 60 __ AddImmediate(RSP, Immediate(-sizeof(NativeArguments)));
62 if (OS::ActivationFrameAlignment() > 0) { 61 if (OS::ActivationFrameAlignment() > 0) {
63 __ andq(RSP, Immediate(~(OS::ActivationFrameAlignment() - 1))); 62 __ andq(RSP, Immediate(~(OS::ActivationFrameAlignment() - 1)));
64 } 63 }
65 64
66 // Pass NativeArguments structure by value and call runtime. 65 // Pass NativeArguments structure by value and call runtime.
67 __ movq(Address(RSP, isolate_offset), CTX); // Set isolate in NativeArgs. 66 __ movq(Address(RSP, isolate_offset), CTX); // Set isolate in NativeArgs.
68 __ movq(Address(RSP, argc_offset), R10); // Set argc in NativeArguments. 67 // There are no runtime calls to closures, so we do not need to set the tag
68 // bits kClosureFunctionBit and kInstanceFunctionBit in argc_tag_.
69 __ movq(Address(RSP, argc_tag_offset), R10); // Set argc in NativeArguments.
69 __ leaq(RAX, Address(RBP, R10, TIMES_8, 1 * kWordSize)); // Compute argv. 70 __ leaq(RAX, Address(RBP, R10, TIMES_8, 1 * kWordSize)); // Compute argv.
70 __ movq(Address(RSP, argv_offset), RAX); // Set argv in NativeArguments. 71 __ movq(Address(RSP, argv_offset), RAX); // Set argv in NativeArguments.
71 __ addq(RAX, Immediate(1 * kWordSize)); // Retval is next to 1st argument. 72 __ addq(RAX, Immediate(1 * kWordSize)); // Retval is next to 1st argument.
72 __ movq(Address(RSP, retval_offset), RAX); // Set retval in NativeArguments. 73 __ movq(Address(RSP, retval_offset), RAX); // Set retval in NativeArguments.
73 __ call(RBX); 74 __ call(RBX);
74 75
75 // Reset exit frame information in Isolate structure. 76 // Reset exit frame information in Isolate structure.
76 __ movq(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0)); 77 __ movq(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0));
77 78
78 // Load Context pointer from Isolate structure into RBX. 79 // Load Context pointer from Isolate structure into RBX.
(...skipping 29 matching lines...) Expand all
108 __ CallRuntime(kPrintStopMessageRuntimeEntry); 109 __ CallRuntime(kPrintStopMessageRuntimeEntry);
109 __ LeaveCallRuntimeFrame(); 110 __ LeaveCallRuntimeFrame();
110 __ ret(); 111 __ ret();
111 } 112 }
112 113
113 114
114 // Input parameters: 115 // Input parameters:
115 // RSP : points to return address. 116 // RSP : points to return address.
116 // RSP + 8 : address of return value. 117 // RSP + 8 : address of return value.
117 // RAX : address of first argument in argument array. 118 // RAX : address of first argument in argument array.
118 // RAX - 8*R10 + 8 : address of last argument in argument array.
119 // RBX : address of the native function to call. 119 // RBX : address of the native function to call.
120 // R10 : number of arguments to the call. 120 // R10 : argc_tag including number of arguments and function kind.
121 void StubCode::GenerateCallNativeCFunctionStub(Assembler* assembler) { 121 void StubCode::GenerateCallNativeCFunctionStub(Assembler* assembler) {
122 const intptr_t native_args_struct_offset = 0; 122 const intptr_t native_args_struct_offset = 0;
123 const intptr_t isolate_offset = 123 const intptr_t isolate_offset =
124 NativeArguments::isolate_offset() + native_args_struct_offset; 124 NativeArguments::isolate_offset() + native_args_struct_offset;
125 const intptr_t argc_offset = 125 const intptr_t argc_tag_offset =
126 NativeArguments::argc_offset() + native_args_struct_offset; 126 NativeArguments::argc_tag_offset() + native_args_struct_offset;
127 const intptr_t argv_offset = 127 const intptr_t argv_offset =
128 NativeArguments::argv_offset() + native_args_struct_offset; 128 NativeArguments::argv_offset() + native_args_struct_offset;
129 const intptr_t retval_offset = 129 const intptr_t retval_offset =
130 NativeArguments::retval_offset() + native_args_struct_offset; 130 NativeArguments::retval_offset() + native_args_struct_offset;
131 131
132 __ EnterFrame(0); 132 __ EnterFrame(0);
133 133
134 // Load current Isolate pointer from Context structure into R8. 134 // Load current Isolate pointer from Context structure into R8.
135 __ movq(R8, FieldAddress(CTX, Context::isolate_offset())); 135 __ movq(R8, FieldAddress(CTX, Context::isolate_offset()));
136 136
(...skipping 10 matching lines...) Expand all
147 // Reserve space for the native arguments structure passed on the stack (the 147 // Reserve space for the native arguments structure passed on the stack (the
148 // outgoing pointer parameter to the native arguments structure is passed in 148 // outgoing pointer parameter to the native arguments structure is passed in
149 // RDI) and align frame before entering the C++ world. 149 // RDI) and align frame before entering the C++ world.
150 __ AddImmediate(RSP, Immediate(-sizeof(NativeArguments))); 150 __ AddImmediate(RSP, Immediate(-sizeof(NativeArguments)));
151 if (OS::ActivationFrameAlignment() > 0) { 151 if (OS::ActivationFrameAlignment() > 0) {
152 __ andq(RSP, Immediate(~(OS::ActivationFrameAlignment() - 1))); 152 __ andq(RSP, Immediate(~(OS::ActivationFrameAlignment() - 1)));
153 } 153 }
154 154
155 // Pass NativeArguments structure by value and call native function. 155 // Pass NativeArguments structure by value and call native function.
156 __ movq(Address(RSP, isolate_offset), CTX); // Set isolate in NativeArgs. 156 __ movq(Address(RSP, isolate_offset), CTX); // Set isolate in NativeArgs.
157 __ movq(Address(RSP, argc_offset), R10); // Set argc in NativeArguments. 157 __ movq(Address(RSP, argc_tag_offset), R10); // Set argc in NativeArguments.
158 __ movq(Address(RSP, argv_offset), RAX); // Set argv in NativeArguments. 158 __ movq(Address(RSP, argv_offset), RAX); // Set argv in NativeArguments.
159 __ leaq(RAX, Address(RBP, 2 * kWordSize)); // Compute return value addr. 159 __ leaq(RAX, Address(RBP, 2 * kWordSize)); // Compute return value addr.
160 __ movq(Address(RSP, retval_offset), RAX); // Set retval in NativeArguments. 160 __ movq(Address(RSP, retval_offset), RAX); // Set retval in NativeArguments.
161 __ movq(RDI, RSP); // Pass the pointer to the NativeArguments. 161 __ movq(RDI, RSP); // Pass the pointer to the NativeArguments.
162 __ call(RBX); 162 __ call(RBX);
163 163
164 // Reset exit frame information in Isolate structure. 164 // Reset exit frame information in Isolate structure.
165 __ movq(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0)); 165 __ movq(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0));
166 166
167 // Load Context pointer from Isolate structure into R8. 167 // Load Context pointer from Isolate structure into R8.
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 __ popq(RAX); // Pop element type argument. 711 __ popq(RAX); // Pop element type argument.
712 __ popq(R10); // Pop array length argument. 712 __ popq(R10); // Pop array length argument.
713 __ popq(RAX); // Pop return value from return slot. 713 __ popq(RAX); // Pop return value from return slot.
714 __ LeaveFrame(); 714 __ LeaveFrame();
715 __ ret(); 715 __ ret();
716 } 716 }
717 717
718 718
719 // Input parameters: 719 // Input parameters:
720 // R10: Arguments descriptor array (num_args is first Smi element, closure 720 // R10: Arguments descriptor array (num_args is first Smi element, closure
721 // object is not included in num_args). 721 // object is included in num_args and is first argument).
722 // Note: The closure object is pushed before the first argument to the function 722 // Note: The closure object is the first argument to the function being
723 // being called, the stub accesses the closure from this location directly 723 // called, the stub accesses the closure from this location directly
724 // when setting up the context and resolving the entry point. 724 // when trying to resolve the call.
725 void StubCode::GenerateCallClosureFunctionStub(Assembler* assembler) { 725 void StubCode::GenerateCallClosureFunctionStub(Assembler* assembler) {
726 const Immediate raw_null = 726 const Immediate raw_null =
727 Immediate(reinterpret_cast<intptr_t>(Object::null())); 727 Immediate(reinterpret_cast<intptr_t>(Object::null()));
728 728
729 // Total number of args is the first Smi in args descriptor array (R10). 729 // Total number of args is the first Smi in args descriptor array (R10).
730 __ movq(RAX, FieldAddress(R10, Array::data_offset())); // Load num_args. 730 __ movq(RAX, FieldAddress(R10, Array::data_offset())); // Load num_args.
731 // Load closure object in R13. 731 // Load closure object in R13.
732 __ movq(R13, Address(RSP, RAX, TIMES_4, kWordSize)); // RAX is a Smi. 732 __ movq(R13, Address(RSP, RAX, TIMES_4, 0)); // RAX is a Smi.
733 733
734 // Verify that R13 is a closure by checking its class. 734 // Verify that R13 is a closure by checking its class.
735 Label not_closure; 735 Label not_closure;
736 __ cmpq(R13, raw_null); 736 __ cmpq(R13, raw_null);
737 // Not a closure, but null object. 737 // Not a closure, but null object.
738 __ j(EQUAL, &not_closure); 738 __ j(EQUAL, &not_closure);
739 __ testq(R13, Immediate(kSmiTagMask)); 739 __ testq(R13, Immediate(kSmiTagMask));
740 __ j(ZERO, &not_closure); // Not a closure, but a smi. 740 __ j(ZERO, &not_closure); // Not a closure, but a smi.
741 // Verify that the class of the object is a closure class by checking that 741 // Verify that the class of the object is a closure class by checking that
742 // class.signature_function() is not null. 742 // class.signature_function() is not null.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 780
781 __ movq(RBX, FieldAddress(RAX, Code::instructions_offset())); 781 __ movq(RBX, FieldAddress(RAX, Code::instructions_offset()));
782 __ addq(RBX, Immediate(Instructions::HeaderSize() - kHeapObjectTag)); 782 __ addq(RBX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
783 __ jmp(RBX); 783 __ jmp(RBX);
784 784
785 __ Bind(&not_closure); 785 __ Bind(&not_closure);
786 // Call runtime to report that a closure call was attempted on a non-closure 786 // Call runtime to report that a closure call was attempted on a non-closure
787 // object, passing the non-closure object and its arguments array. 787 // object, passing the non-closure object and its arguments array.
788 // R13: non-closure object. 788 // R13: non-closure object.
789 // R10: arguments descriptor array (num_args is first Smi element, closure 789 // R10: arguments descriptor array (num_args is first Smi element, closure
790 // object is not included in num_args). 790 // object is included in num_args).
791 791
792 // Create a stub frame as we are pushing some objects on the stack before 792 // Create a stub frame as we are pushing some objects on the stack before
793 // calling into the runtime. 793 // calling into the runtime.
794 AssemblerMacros::EnterStubFrame(assembler); 794 AssemblerMacros::EnterStubFrame(assembler);
795 795
796 __ pushq(raw_null); // Setup space on stack for result from error reporting. 796 __ pushq(raw_null); // Setup space on stack for result from error reporting.
797 __ pushq(R13); // Non-closure object. 797 __ pushq(R13); // Non-closure object.
798 // Total number of args is the first Smi in args descriptor array (R10). 798 // Total number of args is the first Smi in args descriptor array (R10).
799 __ movq(R13, FieldAddress(R10, Array::data_offset())); // Load num_args. 799 __ movq(R13, FieldAddress(R10, Array::data_offset())); // Load num_args.
800 __ SmiUntag(R13); 800 __ SmiUntag(R13);
801 __ subq(R13, Immediate(1)); // Arguments array length, minus the closure.
801 // See stack layout below explaining "wordSize * 5" offset. 802 // See stack layout below explaining "wordSize * 5" offset.
802 PushArgumentsArray(assembler, (kWordSize * 5)); 803 PushArgumentsArray(assembler, (kWordSize * 5));
803 804
804 // Stack: 805 // Stack:
805 // TOS + 0: Argument array. 806 // TOS + 0: Argument array.
806 // TOS + 1: Non-closure object. 807 // TOS + 1: Non-closure object.
807 // TOS + 2: Place for result from reporting the error. 808 // TOS + 2: Place for result from reporting the error.
808 // TOS + 3: PC marker => RawInstruction object. 809 // TOS + 3: PC marker => RawInstruction object.
809 // TOS + 4: Saved RBP of previous frame. <== RBP 810 // TOS + 4: Saved RBP of previous frame. <== RBP
810 // TOS + 5: Dart code return address 811 // TOS + 5: Dart code return address
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 __ CallRuntime(kUpdateICDataTwoArgsRuntimeEntry); 2026 __ CallRuntime(kUpdateICDataTwoArgsRuntimeEntry);
2026 __ Drop(4); 2027 __ Drop(4);
2027 __ LeaveFrame(); 2028 __ LeaveFrame();
2028 2029
2029 __ jmp(&compute_result, Assembler::kNearJump); 2030 __ jmp(&compute_result, Assembler::kNearJump);
2030 } 2031 }
2031 2032
2032 } // namespace dart 2033 } // namespace dart
2033 2034
2034 #endif // defined TARGET_ARCH_X64 2035 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/stub_code_ia32.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698