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 #define CHECK_STACK_ALIGNMENT |
| 30 #elif defined(USING_SIMULATOR) |
29 #define CHECK_STACK_ALIGNMENT { \ | 31 #define CHECK_STACK_ALIGNMENT { \ |
30 uword current_sp = Simulator::Current()->get_register(SPREG); \ | 32 uword current_sp = Simulator::Current()->get_register(SPREG); \ |
31 ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ | 33 ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ |
32 } | 34 } |
33 #elif defined(TARGET_OS_WINDOWS) | 35 #elif defined(TARGET_OS_WINDOWS) |
34 // The compiler may dynamically align the stack on Windows, so do not check. | 36 // The compiler may dynamically align the stack on Windows, so do not check. |
35 #define CHECK_STACK_ALIGNMENT { } | 37 #define CHECK_STACK_ALIGNMENT { } |
36 #else | 38 #else |
37 #define CHECK_STACK_ALIGNMENT { \ | 39 #define CHECK_STACK_ALIGNMENT { \ |
38 uword (*func)() = reinterpret_cast<uword (*)()>( \ | 40 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 | 87 // 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 | 88 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a |
87 // subclass of ValueObject. | 89 // subclass of ValueObject. |
88 class NativeArguments { | 90 class NativeArguments { |
89 public: | 91 public: |
90 Thread* thread() const { return thread_; } | 92 Thread* thread() const { return thread_; } |
91 int ArgCount() const { return ArgcBits::decode(argc_tag_); } | 93 int ArgCount() const { return ArgcBits::decode(argc_tag_); } |
92 | 94 |
93 RawObject* ArgAt(int index) const { | 95 RawObject* ArgAt(int index) const { |
94 ASSERT((index >= 0) && (index < ArgCount())); | 96 ASSERT((index >= 0) && (index < ArgCount())); |
95 RawObject** arg_ptr = &((*argv_)[-index]); | 97 #if defined(TARGET_ARCH_DBC) |
| 98 RawObject** arg_ptr = &(argv_[index]); |
| 99 #else |
| 100 RawObject** arg_ptr = &(argv_[-index]); |
| 101 #endif |
96 // Tell MemorySanitizer the RawObject* was initialized (by generated code). | 102 // Tell MemorySanitizer the RawObject* was initialized (by generated code). |
97 MSAN_UNPOISON(arg_ptr, kWordSize); | 103 MSAN_UNPOISON(arg_ptr, kWordSize); |
98 return *arg_ptr; | 104 return *arg_ptr; |
99 } | 105 } |
100 | 106 |
101 bool IsNativeAutoSetupScope() const { | 107 bool IsNativeAutoSetupScope() const { |
102 return AutoSetupScopeBits::decode(argc_tag_); | 108 return AutoSetupScopeBits::decode(argc_tag_); |
103 } | 109 } |
104 | 110 |
105 int NativeArgCount() const { | 111 int NativeArgCount() const { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 }; | 203 }; |
198 class ArgcBits : public BitField<intptr_t, int32_t, kArgcBit, kArgcSize> {}; | 204 class ArgcBits : public BitField<intptr_t, int32_t, kArgcBit, kArgcSize> {}; |
199 class FunctionBits : | 205 class FunctionBits : |
200 public BitField<intptr_t, int, kFunctionBit, kFunctionSize> {}; | 206 public BitField<intptr_t, int, kFunctionBit, kFunctionSize> {}; |
201 class AutoSetupScopeBits : | 207 class AutoSetupScopeBits : |
202 public BitField<intptr_t, int, kAutoSetupScopeBit, 1> {}; | 208 public BitField<intptr_t, int, kAutoSetupScopeBit, 1> {}; |
203 friend class Api; | 209 friend class Api; |
204 friend class BootstrapNatives; | 210 friend class BootstrapNatives; |
205 friend class Simulator; | 211 friend class Simulator; |
206 | 212 |
| 213 #if defined(TARGET_ARCH_DBC) |
| 214 // Allow simulator create NativeArguments on the stack. |
| 215 NativeArguments(Thread* thread, |
| 216 int argc_tag, |
| 217 RawObject** argv, |
| 218 RawObject** retval) |
| 219 : thread_(thread), argc_tag_(argc_tag), argv_(argv), retval_(retval) { |
| 220 } |
| 221 #endif |
| 222 |
207 // Since this function is passed a RawObject directly, we need to be | 223 // 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 | 224 // 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 | 225 // effects in the statement that may cause GC, it could lead to |
210 // bugs. | 226 // bugs. |
211 void SetReturnUnsafe(RawObject* value) const { | 227 void SetReturnUnsafe(RawObject* value) const { |
212 *retval_ = value; | 228 *retval_ = value; |
213 } | 229 } |
214 | 230 |
215 // Returns true if the arguments are those of an instance function call. | 231 // Returns true if the arguments are those of an instance function call. |
216 bool ToInstanceFunction() const { | 232 bool ToInstanceFunction() const { |
(...skipping 11 matching lines...) Expand all Loading... |
228 // the context and the closure at index 0 is hidden, so the apparent | 244 // the context and the closure at index 0 is hidden, so the apparent |
229 // argument count remains unchanged. | 245 // argument count remains unchanged. |
230 if (function_bits == kClosureFunctionBit) { | 246 if (function_bits == kClosureFunctionBit) { |
231 return 1; | 247 return 1; |
232 } | 248 } |
233 return 0; | 249 return 0; |
234 } | 250 } |
235 | 251 |
236 Thread* thread_; // Current thread pointer. | 252 Thread* thread_; // Current thread pointer. |
237 intptr_t argc_tag_; // Encodes argument count and invoked native call type. | 253 intptr_t argc_tag_; // Encodes argument count and invoked native call type. |
238 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. | 254 RawObject** argv_; // Pointer to an array of arguments to runtime call. |
239 RawObject** retval_; // Pointer to the return value area. | 255 RawObject** retval_; // Pointer to the return value area. |
240 }; | 256 }; |
241 | 257 |
242 } // namespace dart | 258 } // namespace dart |
243 | 259 |
244 #endif // VM_NATIVE_ARGUMENTS_H_ | 260 #endif // VM_NATIVE_ARGUMENTS_H_ |
OLD | NEW |