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

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

Issue 200693002: Set VMTag from stubs when transitioning between Dart and Native (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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/stack_frame_ia32.h ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.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/heap.h" 13 #include "vm/heap.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/resolver.h" 15 #include "vm/resolver.h"
16 #include "vm/scavenger.h" 16 #include "vm/scavenger.h"
17 #include "vm/stack_frame.h" 17 #include "vm/stack_frame.h"
18 #include "vm/stub_code.h" 18 #include "vm/stub_code.h"
19 #include "vm/tags.h"
19 20
20 21
21 #define __ assembler-> 22 #define __ assembler->
22 23
23 namespace dart { 24 namespace dart {
24 25
25 DEFINE_FLAG(bool, inline_alloc, true, "Inline allocation of objects."); 26 DEFINE_FLAG(bool, inline_alloc, true, "Inline allocation of objects.");
26 DEFINE_FLAG(bool, use_slow_path, false, 27 DEFINE_FLAG(bool, use_slow_path, false,
27 "Set to true for debugging & verifying the slow paths."); 28 "Set to true for debugging & verifying the slow paths.");
28 DECLARE_FLAG(bool, trace_optimized_ic_calls); 29 DECLARE_FLAG(bool, trace_optimized_ic_calls);
(...skipping 22 matching lines...) Expand all
51 // Save exit frame information to enable stack walking as we are about 52 // Save exit frame information to enable stack walking as we are about
52 // to transition to Dart VM C++ code. 53 // to transition to Dart VM C++ code.
53 __ movl(Address(EAX, Isolate::top_exit_frame_info_offset()), ESP); 54 __ movl(Address(EAX, Isolate::top_exit_frame_info_offset()), ESP);
54 55
55 // Save current Context pointer into Isolate structure. 56 // Save current Context pointer into Isolate structure.
56 __ movl(Address(EAX, Isolate::top_context_offset()), CTX); 57 __ movl(Address(EAX, Isolate::top_context_offset()), CTX);
57 58
58 // Cache Isolate pointer into CTX while executing runtime code. 59 // Cache Isolate pointer into CTX while executing runtime code.
59 __ movl(CTX, EAX); 60 __ movl(CTX, EAX);
60 61
62 // Mark that the isolate is executing VM code.
siva 2014/03/14 20:45:39 #if defined(DEBUG) check that the vm_tag was kSc
63 __ movl(Address(CTX, Isolate::vm_tag_offset()), Immediate(VMTag::kVMTagId));
64
61 // Reserve space for arguments and align frame before entering C++ world. 65 // Reserve space for arguments and align frame before entering C++ world.
62 __ AddImmediate(ESP, Immediate(-sizeof(NativeArguments))); 66 __ AddImmediate(ESP, Immediate(-sizeof(NativeArguments)));
63 if (OS::ActivationFrameAlignment() > 1) { 67 if (OS::ActivationFrameAlignment() > 1) {
64 __ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1))); 68 __ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1)));
65 } 69 }
66 70
67 // Pass NativeArguments structure by value and call runtime. 71 // Pass NativeArguments structure by value and call runtime.
68 __ movl(Address(ESP, isolate_offset), CTX); // Set isolate in NativeArgs. 72 __ movl(Address(ESP, isolate_offset), CTX); // Set isolate in NativeArgs.
69 // There are no runtime calls to closures, so we do not need to set the tag 73 // There are no runtime calls to closures, so we do not need to set the tag
70 // bits kClosureFunctionBit and kInstanceFunctionBit in argc_tag_. 74 // bits kClosureFunctionBit and kInstanceFunctionBit in argc_tag_.
71 __ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments. 75 __ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments.
72 __ leal(EAX, Address(EBP, EDX, TIMES_4, 1 * kWordSize)); // Compute argv. 76 __ leal(EAX, Address(EBP, EDX, TIMES_4, 1 * kWordSize)); // Compute argv.
73 __ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments. 77 __ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments.
74 __ addl(EAX, Immediate(1 * kWordSize)); // Retval is next to 1st argument. 78 __ addl(EAX, Immediate(1 * kWordSize)); // Retval is next to 1st argument.
75 __ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments. 79 __ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments.
76 __ call(ECX); 80 __ call(ECX);
77 81
82 // Mark that the isolate is executing Dart code.
83 __ movl(Address(CTX, Isolate::vm_tag_offset()),
84 Immediate(VMTag::kScriptTagId));
85
78 // Reset exit frame information in Isolate structure. 86 // Reset exit frame information in Isolate structure.
79 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0)); 87 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0));
80 88
81 // Load Context pointer from Isolate structure into ECX. 89 // Load Context pointer from Isolate structure into ECX.
82 __ movl(ECX, Address(CTX, Isolate::top_context_offset())); 90 __ movl(ECX, Address(CTX, Isolate::top_context_offset()));
83 91
84 // Reset Context pointer in Isolate structure. 92 // Reset Context pointer in Isolate structure.
85 const Immediate& raw_null = 93 const Immediate& raw_null =
86 Immediate(reinterpret_cast<intptr_t>(Object::null())); 94 Immediate(reinterpret_cast<intptr_t>(Object::null()));
87 __ movl(Address(CTX, Isolate::top_context_offset()), raw_null); 95 __ movl(Address(CTX, Isolate::top_context_offset()), raw_null);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Save exit frame information to enable stack walking as we are about 149 // Save exit frame information to enable stack walking as we are about
142 // to transition to dart VM code. 150 // to transition to dart VM code.
143 __ movl(Address(EDI, Isolate::top_exit_frame_info_offset()), ESP); 151 __ movl(Address(EDI, Isolate::top_exit_frame_info_offset()), ESP);
144 152
145 // Save current Context pointer into Isolate structure. 153 // Save current Context pointer into Isolate structure.
146 __ movl(Address(EDI, Isolate::top_context_offset()), CTX); 154 __ movl(Address(EDI, Isolate::top_context_offset()), CTX);
147 155
148 // Cache Isolate pointer into CTX while executing native code. 156 // Cache Isolate pointer into CTX while executing native code.
149 __ movl(CTX, EDI); 157 __ movl(CTX, EDI);
150 158
159 // Mark that the isolate is executing Native code.
siva 2014/03/14 20:45:39 Ditto debug assertion here.
160 __ movl(Address(CTX, Isolate::vm_tag_offset()),
161 Immediate(VMTag::kRuntimeNativeTagId));
162
151 // Reserve space for the native arguments structure, the outgoing parameters 163 // Reserve space for the native arguments structure, the outgoing parameters
152 // (pointer to the native arguments structure, the C function entry point) 164 // (pointer to the native arguments structure, the C function entry point)
153 // and align frame before entering the C++ world. 165 // and align frame before entering the C++ world.
154 __ AddImmediate(ESP, Immediate(-sizeof(NativeArguments) - (2 * kWordSize))); 166 __ AddImmediate(ESP, Immediate(-sizeof(NativeArguments) - (2 * kWordSize)));
155 if (OS::ActivationFrameAlignment() > 1) { 167 if (OS::ActivationFrameAlignment() > 1) {
156 __ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1))); 168 __ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1)));
157 } 169 }
158 170
159 // Pass NativeArguments structure by value and call native function. 171 // Pass NativeArguments structure by value and call native function.
160 __ movl(Address(ESP, isolate_offset), CTX); // Set isolate in NativeArgs. 172 __ movl(Address(ESP, isolate_offset), CTX); // Set isolate in NativeArgs.
161 __ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments. 173 __ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments.
162 __ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments. 174 __ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments.
163 __ leal(EAX, Address(EBP, 2 * kWordSize)); // Compute return value addr. 175 __ leal(EAX, Address(EBP, 2 * kWordSize)); // Compute return value addr.
164 __ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments. 176 __ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments.
165 __ leal(EAX, Address(ESP, 2 * kWordSize)); // Pointer to the NativeArguments. 177 __ leal(EAX, Address(ESP, 2 * kWordSize)); // Pointer to the NativeArguments.
166 __ movl(Address(ESP, 0), EAX); // Pass the pointer to the NativeArguments. 178 __ movl(Address(ESP, 0), EAX); // Pass the pointer to the NativeArguments.
167 179
168 // Call native function (setsup scope if not leaf function). 180 // Call native function (setsup scope if not leaf function).
169 Label leaf_call; 181 Label leaf_call;
170 Label done; 182 Label done;
171 __ testl(EDX, Immediate(NativeArguments::AutoSetupScopeMask())); 183 __ testl(EDX, Immediate(NativeArguments::AutoSetupScopeMask()));
172 __ j(ZERO, &leaf_call, Assembler::kNearJump); 184 __ j(ZERO, &leaf_call, Assembler::kNearJump);
173 __ movl(Address(ESP, kWordSize), ECX); // Function to call. 185 __ movl(Address(ESP, kWordSize), ECX); // Function to call.
174 __ call(&NativeEntry::NativeCallWrapperLabel()); 186 __ call(&NativeEntry::NativeCallWrapperLabel());
175 __ jmp(&done); 187 __ jmp(&done);
176 __ Bind(&leaf_call); 188 __ Bind(&leaf_call);
177 __ call(ECX); 189 __ call(ECX);
178 __ Bind(&done); 190 __ Bind(&done);
179 191
192 // Mark that the isolate is executing Dart code.
193 __ movl(Address(CTX, Isolate::vm_tag_offset()),
194 Immediate(VMTag::kScriptTagId));
195
180 // Reset exit frame information in Isolate structure. 196 // Reset exit frame information in Isolate structure.
181 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0)); 197 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0));
182 198
183 // Load Context pointer from Isolate structure into EDI. 199 // Load Context pointer from Isolate structure into EDI.
184 __ movl(EDI, Address(CTX, Isolate::top_context_offset())); 200 __ movl(EDI, Address(CTX, Isolate::top_context_offset()));
185 201
186 // Reset Context pointer in Isolate structure. 202 // Reset Context pointer in Isolate structure.
187 const Immediate& raw_null = 203 const Immediate& raw_null =
188 Immediate(reinterpret_cast<intptr_t>(Object::null())); 204 Immediate(reinterpret_cast<intptr_t>(Object::null()));
189 __ movl(Address(CTX, Isolate::top_context_offset()), raw_null); 205 __ movl(Address(CTX, Isolate::top_context_offset()), raw_null);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // Save exit frame information to enable stack walking as we are about 238 // Save exit frame information to enable stack walking as we are about
223 // to transition to dart VM code. 239 // to transition to dart VM code.
224 __ movl(Address(EDI, Isolate::top_exit_frame_info_offset()), ESP); 240 __ movl(Address(EDI, Isolate::top_exit_frame_info_offset()), ESP);
225 241
226 // Save current Context pointer into Isolate structure. 242 // Save current Context pointer into Isolate structure.
227 __ movl(Address(EDI, Isolate::top_context_offset()), CTX); 243 __ movl(Address(EDI, Isolate::top_context_offset()), CTX);
228 244
229 // Cache Isolate pointer into CTX while executing native code. 245 // Cache Isolate pointer into CTX while executing native code.
230 __ movl(CTX, EDI); 246 __ movl(CTX, EDI);
231 247
248 // Mark that the isolate is executing Native code.
siva 2014/03/14 20:45:39 Ditto debug assertion here.
249 __ movl(Address(CTX, Isolate::vm_tag_offset()),
250 Immediate(VMTag::kRuntimeNativeTagId));
251
232 // Reserve space for the native arguments structure, the outgoing parameter 252 // Reserve space for the native arguments structure, the outgoing parameter
233 // (pointer to the native arguments structure) and align frame before 253 // (pointer to the native arguments structure) and align frame before
234 // entering the C++ world. 254 // entering the C++ world.
235 __ AddImmediate(ESP, Immediate(-sizeof(NativeArguments) - kWordSize)); 255 __ AddImmediate(ESP, Immediate(-sizeof(NativeArguments) - kWordSize));
236 if (OS::ActivationFrameAlignment() > 1) { 256 if (OS::ActivationFrameAlignment() > 1) {
237 __ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1))); 257 __ andl(ESP, Immediate(~(OS::ActivationFrameAlignment() - 1)));
238 } 258 }
239 259
240 // Pass NativeArguments structure by value and call native function. 260 // Pass NativeArguments structure by value and call native function.
241 __ movl(Address(ESP, isolate_offset), CTX); // Set isolate in NativeArgs. 261 __ movl(Address(ESP, isolate_offset), CTX); // Set isolate in NativeArgs.
242 __ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments. 262 __ movl(Address(ESP, argc_tag_offset), EDX); // Set argc in NativeArguments.
243 __ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments. 263 __ movl(Address(ESP, argv_offset), EAX); // Set argv in NativeArguments.
244 __ leal(EAX, Address(EBP, 2 * kWordSize)); // Compute return value addr. 264 __ leal(EAX, Address(EBP, 2 * kWordSize)); // Compute return value addr.
245 __ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments. 265 __ movl(Address(ESP, retval_offset), EAX); // Set retval in NativeArguments.
246 __ leal(EAX, Address(ESP, kWordSize)); // Pointer to the NativeArguments. 266 __ leal(EAX, Address(ESP, kWordSize)); // Pointer to the NativeArguments.
247 __ movl(Address(ESP, 0), EAX); // Pass the pointer to the NativeArguments. 267 __ movl(Address(ESP, 0), EAX); // Pass the pointer to the NativeArguments.
248 __ call(ECX); 268 __ call(ECX);
249 269
270 // Mark that the isolate is executing Dart code.
271 __ movl(Address(CTX, Isolate::vm_tag_offset()),
272 Immediate(VMTag::kScriptTagId));
273
250 // Reset exit frame information in Isolate structure. 274 // Reset exit frame information in Isolate structure.
251 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0)); 275 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), Immediate(0));
252 276
253 // Load Context pointer from Isolate structure into EDI. 277 // Load Context pointer from Isolate structure into EDI.
254 __ movl(EDI, Address(CTX, Isolate::top_context_offset())); 278 __ movl(EDI, Address(CTX, Isolate::top_context_offset()));
255 279
256 // Reset Context pointer in Isolate structure. 280 // Reset Context pointer in Isolate structure.
257 const Immediate& raw_null = 281 const Immediate& raw_null =
258 Immediate(reinterpret_cast<intptr_t>(Object::null())); 282 Immediate(reinterpret_cast<intptr_t>(Object::null()));
259 __ movl(Address(CTX, Isolate::top_context_offset()), raw_null); 283 __ movl(Address(CTX, Isolate::top_context_offset()), raw_null);
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 // Note that VisitObjectPointers will find this saved Context pointer during 853 // Note that VisitObjectPointers will find this saved Context pointer during
830 // GC marking, since it traverses any information between SP and 854 // GC marking, since it traverses any information between SP and
831 // FP - kExitLinkSlotFromEntryFp. 855 // FP - kExitLinkSlotFromEntryFp.
832 // EntryFrame::SavedContext reads the context saved in this frame. 856 // EntryFrame::SavedContext reads the context saved in this frame.
833 // The constant kSavedContextSlotFromEntryFp must be kept in sync with 857 // The constant kSavedContextSlotFromEntryFp must be kept in sync with
834 // the code below. 858 // the code below.
835 ASSERT(kSavedContextSlotFromEntryFp == -5); 859 ASSERT(kSavedContextSlotFromEntryFp == -5);
836 __ movl(ECX, Address(EDI, Isolate::top_context_offset())); 860 __ movl(ECX, Address(EDI, Isolate::top_context_offset()));
837 __ pushl(ECX); 861 __ pushl(ECX);
838 862
863 // Save the current VMTag on the stack.
864 ASSERT(kSavedVMTagSlotFromEntryFp == -6);
865 __ movl(ECX, Address(EDI, Isolate::vm_tag_offset()));
866 __ pushl(ECX);
siva 2014/03/14 20:45:39 As discussed offline you would have to flip this s
Cutch 2014/03/17 15:46:01 Done. We now push in the following order: vmtag
867
868 // Mark that the isolate is executing Dart code.
869 __ movl(Address(EDI, Isolate::vm_tag_offset()),
870 Immediate(VMTag::kScriptTagId));
871
839 // Load arguments descriptor array into EDX. 872 // Load arguments descriptor array into EDX.
840 __ movl(EDX, Address(EBP, kArgumentsDescOffset)); 873 __ movl(EDX, Address(EBP, kArgumentsDescOffset));
841 __ movl(EDX, Address(EDX, VMHandles::kOffsetOfRawPtrInHandle)); 874 __ movl(EDX, Address(EDX, VMHandles::kOffsetOfRawPtrInHandle));
842 875
843 // Load number of arguments into EBX. 876 // Load number of arguments into EBX.
844 __ movl(EBX, FieldAddress(EDX, ArgumentsDescriptor::count_offset())); 877 __ movl(EBX, FieldAddress(EDX, ArgumentsDescriptor::count_offset()));
845 __ SmiUntag(EBX); 878 __ SmiUntag(EBX);
846 879
847 // Set up arguments for the dart call. 880 // Set up arguments for the dart call.
848 Label push_arguments; 881 Label push_arguments;
(...skipping 26 matching lines...) Expand all
875 // arguments. 908 // arguments.
876 __ movl(EDX, Address(EBP, kArgumentsDescOffset)); 909 __ movl(EDX, Address(EBP, kArgumentsDescOffset));
877 __ movl(EDX, Address(EDX, VMHandles::kOffsetOfRawPtrInHandle)); 910 __ movl(EDX, Address(EDX, VMHandles::kOffsetOfRawPtrInHandle));
878 __ movl(EDX, FieldAddress(EDX, ArgumentsDescriptor::count_offset())); 911 __ movl(EDX, FieldAddress(EDX, ArgumentsDescriptor::count_offset()));
879 // Get rid of arguments pushed on the stack. 912 // Get rid of arguments pushed on the stack.
880 __ leal(ESP, Address(ESP, EDX, TIMES_2, 0)); // EDX is a Smi. 913 __ leal(ESP, Address(ESP, EDX, TIMES_2, 0)); // EDX is a Smi.
881 914
882 // Load Isolate pointer from Context structure into CTX. Drop Context. 915 // Load Isolate pointer from Context structure into CTX. Drop Context.
883 __ movl(CTX, FieldAddress(CTX, Context::isolate_offset())); 916 __ movl(CTX, FieldAddress(CTX, Context::isolate_offset()));
884 917
918 // Restore the current VMTag from the stack.
919 __ popl(ECX);
920 __ movl(Address(CTX, Isolate::vm_tag_offset()), ECX);
921
885 // Restore the saved Context pointer into the Isolate structure. 922 // Restore the saved Context pointer into the Isolate structure.
886 // Uses ECX as a temporary register for this. 923 // Uses ECX as a temporary register for this.
887 __ popl(ECX); 924 __ popl(ECX);
888 __ movl(Address(CTX, Isolate::top_context_offset()), ECX); 925 __ movl(Address(CTX, Isolate::top_context_offset()), ECX);
889 926
890 // Restore the saved top exit frame info back into the Isolate structure. 927 // Restore the saved top exit frame info back into the Isolate structure.
891 // Uses EDX as a temporary register for this. 928 // Uses EDX as a temporary register for this.
892 __ popl(EDX); 929 __ popl(EDX);
893 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), EDX); 930 __ movl(Address(CTX, Isolate::top_exit_frame_info_offset()), EDX);
894 931
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 const Register temp = ECX; 2003 const Register temp = ECX;
1967 __ movl(left, Address(ESP, 2 * kWordSize)); 2004 __ movl(left, Address(ESP, 2 * kWordSize));
1968 __ movl(right, Address(ESP, 1 * kWordSize)); 2005 __ movl(right, Address(ESP, 1 * kWordSize));
1969 GenerateIdenticalWithNumberCheckStub(assembler, left, right, temp); 2006 GenerateIdenticalWithNumberCheckStub(assembler, left, right, temp);
1970 __ ret(); 2007 __ ret();
1971 } 2008 }
1972 2009
1973 } // namespace dart 2010 } // namespace dart
1974 2011
1975 #endif // defined TARGET_ARCH_IA32 2012 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/stack_frame_ia32.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698