OLD | NEW |
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 #ifndef VM_NATIVE_ARGUMENTS_H_ | 5 #ifndef VM_NATIVE_ARGUMENTS_H_ |
6 #define VM_NATIVE_ARGUMENTS_H_ | 6 #define VM_NATIVE_ARGUMENTS_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "platform/memory_sanitizer.h" | 9 #include "platform/memory_sanitizer.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
11 #include "vm/handles_impl.h" | 11 #include "vm/handles_impl.h" |
12 #include "vm/simulator.h" | 12 #include "vm/simulator.h" |
13 #include "vm/stub_code.h" | 13 #include "vm/stub_code.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 DECLARE_FLAG(bool, trace_natives); | 17 DECLARE_FLAG(bool, trace_natives); |
18 | 18 |
19 // Forward declarations. | 19 // Forward declarations. |
20 class BootstrapNatives; | 20 class BootstrapNatives; |
21 class Object; | 21 class Object; |
22 class RawObject; | 22 class RawObject; |
23 class Simulator; | 23 class Simulator; |
24 class Thread; | 24 class Thread; |
25 | 25 |
26 #if defined(TESTING) || defined(DEBUG) | 26 #if defined(TESTING) || defined(DEBUG) |
27 | 27 |
28 #if defined(USING_SIMULATOR) | 28 #if defined(TARGET_ARCH_DBC) |
| 29 // C-stack is always aligned on DBC because we don't have any native code. |
| 30 #define CHECK_STACK_ALIGNMENT |
| 31 #elif defined(USING_SIMULATOR) |
29 #define CHECK_STACK_ALIGNMENT { \ | 32 #define CHECK_STACK_ALIGNMENT { \ |
30 uword current_sp = Simulator::Current()->get_register(SPREG); \ | 33 uword current_sp = Simulator::Current()->get_register(SPREG); \ |
31 ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ | 34 ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ |
32 } | 35 } |
33 #elif defined(TARGET_OS_WINDOWS) | 36 #elif defined(TARGET_OS_WINDOWS) |
34 // The compiler may dynamically align the stack on Windows, so do not check. | 37 // The compiler may dynamically align the stack on Windows, so do not check. |
35 #define CHECK_STACK_ALIGNMENT { } | 38 #define CHECK_STACK_ALIGNMENT { } |
36 #else | 39 #else |
37 #define CHECK_STACK_ALIGNMENT { \ | 40 #define CHECK_STACK_ALIGNMENT { \ |
38 uword (*func)() = reinterpret_cast<uword (*)()>( \ | 41 uword (*func)() = reinterpret_cast<uword (*)()>( \ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // NOTE: Since we pass 'this' as a pass-by-value argument in the stubs we don't | 88 // NOTE: Since we pass 'this' as a pass-by-value argument in the stubs we don't |
86 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a | 89 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a |
87 // subclass of ValueObject. | 90 // subclass of ValueObject. |
88 class NativeArguments { | 91 class NativeArguments { |
89 public: | 92 public: |
90 Thread* thread() const { return thread_; } | 93 Thread* thread() const { return thread_; } |
91 int ArgCount() const { return ArgcBits::decode(argc_tag_); } | 94 int ArgCount() const { return ArgcBits::decode(argc_tag_); } |
92 | 95 |
93 RawObject* ArgAt(int index) const { | 96 RawObject* ArgAt(int index) const { |
94 ASSERT((index >= 0) && (index < ArgCount())); | 97 ASSERT((index >= 0) && (index < ArgCount())); |
95 RawObject** arg_ptr = &((*argv_)[-index]); | 98 #if defined(TARGET_ARCH_DBC) |
| 99 // On DBC stack is growing upwards, in reverse direction from all other |
| 100 // architectures. |
| 101 RawObject** arg_ptr = &(argv_[index]); |
| 102 #else |
| 103 RawObject** arg_ptr = &(argv_[-index]); |
| 104 #endif |
96 // Tell MemorySanitizer the RawObject* was initialized (by generated code). | 105 // Tell MemorySanitizer the RawObject* was initialized (by generated code). |
97 MSAN_UNPOISON(arg_ptr, kWordSize); | 106 MSAN_UNPOISON(arg_ptr, kWordSize); |
98 return *arg_ptr; | 107 return *arg_ptr; |
99 } | 108 } |
100 | 109 |
101 bool IsNativeAutoSetupScope() const { | 110 bool IsNativeAutoSetupScope() const { |
102 return AutoSetupScopeBits::decode(argc_tag_); | 111 return AutoSetupScopeBits::decode(argc_tag_); |
103 } | 112 } |
104 | 113 |
105 int NativeArgCount() const { | 114 int NativeArgCount() const { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 }; | 206 }; |
198 class ArgcBits : public BitField<intptr_t, int32_t, kArgcBit, kArgcSize> {}; | 207 class ArgcBits : public BitField<intptr_t, int32_t, kArgcBit, kArgcSize> {}; |
199 class FunctionBits : | 208 class FunctionBits : |
200 public BitField<intptr_t, int, kFunctionBit, kFunctionSize> {}; | 209 public BitField<intptr_t, int, kFunctionBit, kFunctionSize> {}; |
201 class AutoSetupScopeBits : | 210 class AutoSetupScopeBits : |
202 public BitField<intptr_t, int, kAutoSetupScopeBit, 1> {}; | 211 public BitField<intptr_t, int, kAutoSetupScopeBit, 1> {}; |
203 friend class Api; | 212 friend class Api; |
204 friend class BootstrapNatives; | 213 friend class BootstrapNatives; |
205 friend class Simulator; | 214 friend class Simulator; |
206 | 215 |
| 216 #if defined(TARGET_ARCH_DBC) |
| 217 // Allow simulator to create NativeArguments on the stack. |
| 218 NativeArguments(Thread* thread, |
| 219 int argc_tag, |
| 220 RawObject** argv, |
| 221 RawObject** retval) |
| 222 : thread_(thread), argc_tag_(argc_tag), argv_(argv), retval_(retval) { |
| 223 } |
| 224 #endif |
| 225 |
207 // Since this function is passed a RawObject directly, we need to be | 226 // Since this function is passed a RawObject directly, we need to be |
208 // exceedingly careful when we use it. If there are any other side | 227 // exceedingly careful when we use it. If there are any other side |
209 // effects in the statement that may cause GC, it could lead to | 228 // effects in the statement that may cause GC, it could lead to |
210 // bugs. | 229 // bugs. |
211 void SetReturnUnsafe(RawObject* value) const { | 230 void SetReturnUnsafe(RawObject* value) const { |
212 *retval_ = value; | 231 *retval_ = value; |
213 } | 232 } |
214 | 233 |
215 // Returns true if the arguments are those of an instance function call. | 234 // Returns true if the arguments are those of an instance function call. |
216 bool ToInstanceFunction() const { | 235 bool ToInstanceFunction() const { |
(...skipping 11 matching lines...) Expand all Loading... |
228 // the context and the closure at index 0 is hidden, so the apparent | 247 // the context and the closure at index 0 is hidden, so the apparent |
229 // argument count remains unchanged. | 248 // argument count remains unchanged. |
230 if (function_bits == kClosureFunctionBit) { | 249 if (function_bits == kClosureFunctionBit) { |
231 return 1; | 250 return 1; |
232 } | 251 } |
233 return 0; | 252 return 0; |
234 } | 253 } |
235 | 254 |
236 Thread* thread_; // Current thread pointer. | 255 Thread* thread_; // Current thread pointer. |
237 intptr_t argc_tag_; // Encodes argument count and invoked native call type. | 256 intptr_t argc_tag_; // Encodes argument count and invoked native call type. |
238 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. | 257 RawObject** argv_; // Pointer to an array of arguments to runtime call. |
239 RawObject** retval_; // Pointer to the return value area. | 258 RawObject** retval_; // Pointer to the return value area. |
240 }; | 259 }; |
241 | 260 |
242 } // namespace dart | 261 } // namespace dart |
243 | 262 |
244 #endif // VM_NATIVE_ARGUMENTS_H_ | 263 #endif // VM_NATIVE_ARGUMENTS_H_ |
OLD | NEW |