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, deoptimize_alot); | 17 DECLARE_FLAG(bool, deoptimize_alot); |
18 DECLARE_FLAG(bool, trace_natives); | 18 DECLARE_FLAG(bool, trace_natives); |
19 DECLARE_FLAG(bool, verify_on_transition); | 19 DECLARE_FLAG(bool, verify_on_transition); |
20 | 20 |
21 // Forward declarations. | 21 // Forward declarations. |
22 class BootstrapNatives; | 22 class BootstrapNatives; |
23 class Isolate; | |
24 class Object; | 23 class Object; |
25 class RawObject; | 24 class RawObject; |
26 class Simulator; | 25 class Simulator; |
| 26 class Thread; |
27 | 27 |
28 #if defined(TESTING) || defined(DEBUG) | 28 #if defined(TESTING) || defined(DEBUG) |
29 | 29 |
30 #if defined(USING_SIMULATOR) | 30 #if defined(USING_SIMULATOR) |
31 #define CHECK_STACK_ALIGNMENT { \ | 31 #define CHECK_STACK_ALIGNMENT { \ |
32 uword current_sp = Simulator::Current()->get_register(SPREG); \ | 32 uword current_sp = Simulator::Current()->get_register(SPREG); \ |
33 ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ | 33 ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ |
34 } | 34 } |
35 #elif defined(TARGET_OS_WINDOWS) | 35 #elif defined(TARGET_OS_WINDOWS) |
36 // 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. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Inside the function, arguments are accessed as follows: | 78 // Inside the function, arguments are accessed as follows: |
79 // const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); | 79 // const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); |
80 // const Smi& arg1 = Smi::CheckedHandle(arguments.ArgAt(1)); | 80 // const Smi& arg1 = Smi::CheckedHandle(arguments.ArgAt(1)); |
81 // The return value is set as follows: | 81 // The return value is set as follows: |
82 // arguments.SetReturn(result); | 82 // arguments.SetReturn(result); |
83 // NOTE: Since we pass 'this' as a pass-by-value argument in the stubs we don't | 83 // NOTE: Since we pass 'this' as a pass-by-value argument in the stubs we don't |
84 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a | 84 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a |
85 // subclass of ValueObject. | 85 // subclass of ValueObject. |
86 class NativeArguments { | 86 class NativeArguments { |
87 public: | 87 public: |
88 Isolate* isolate() const { return isolate_; } | 88 Thread* thread() const { return thread_; } |
89 int ArgCount() const { return ArgcBits::decode(argc_tag_); } | 89 int ArgCount() const { return ArgcBits::decode(argc_tag_); } |
90 | 90 |
91 RawObject* ArgAt(int index) const { | 91 RawObject* ArgAt(int index) const { |
92 ASSERT((index >= 0) && (index < ArgCount())); | 92 ASSERT((index >= 0) && (index < ArgCount())); |
93 RawObject** arg_ptr = &((*argv_)[-index]); | 93 RawObject** arg_ptr = &((*argv_)[-index]); |
94 // Tell MemorySanitizer the RawObject* was initialized (by generated code). | 94 // Tell MemorySanitizer the RawObject* was initialized (by generated code). |
95 MSAN_UNPOISON(arg_ptr, kWordSize); | 95 MSAN_UNPOISON(arg_ptr, kWordSize); |
96 return *arg_ptr; | 96 return *arg_ptr; |
97 } | 97 } |
98 | 98 |
(...skipping 21 matching lines...) Expand all Loading... |
120 } | 120 } |
121 int function_bits = FunctionBits::decode(argc_tag_); | 121 int function_bits = FunctionBits::decode(argc_tag_); |
122 const int actual_index = index + NumHiddenArgs(function_bits); | 122 const int actual_index = index + NumHiddenArgs(function_bits); |
123 return ArgAt(actual_index); | 123 return ArgAt(actual_index); |
124 } | 124 } |
125 | 125 |
126 void SetReturn(const Object& value) const { | 126 void SetReturn(const Object& value) const { |
127 *retval_ = value.raw(); | 127 *retval_ = value.raw(); |
128 } | 128 } |
129 | 129 |
130 static intptr_t isolate_offset() { | 130 static intptr_t thread_offset() { |
131 return OFFSET_OF(NativeArguments, isolate_); | 131 return OFFSET_OF(NativeArguments, thread_); |
132 } | 132 } |
133 static intptr_t argc_tag_offset() { | 133 static intptr_t argc_tag_offset() { |
134 return OFFSET_OF(NativeArguments, argc_tag_); | 134 return OFFSET_OF(NativeArguments, argc_tag_); |
135 } | 135 } |
136 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } | 136 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } |
137 static intptr_t retval_offset() { | 137 static intptr_t retval_offset() { |
138 return OFFSET_OF(NativeArguments, retval_); | 138 return OFFSET_OF(NativeArguments, retval_); |
139 } | 139 } |
140 static intptr_t AutoSetupScopeMask() { | 140 static intptr_t AutoSetupScopeMask() { |
141 return AutoSetupScopeBits::mask_in_place(); | 141 return AutoSetupScopeBits::mask_in_place(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // For static closure functions, the closure at index 0 is hidden. | 214 // For static closure functions, the closure at index 0 is hidden. |
215 // In the instance closure function case, the receiver is accessed from | 215 // In the instance closure function case, the receiver is accessed from |
216 // the context and the closure at index 0 is hidden, so the apparent | 216 // the context and the closure at index 0 is hidden, so the apparent |
217 // argument count remains unchanged. | 217 // argument count remains unchanged. |
218 if (function_bits == kClosureFunctionBit) { | 218 if (function_bits == kClosureFunctionBit) { |
219 return 1; | 219 return 1; |
220 } | 220 } |
221 return 0; | 221 return 0; |
222 } | 222 } |
223 | 223 |
224 Isolate* isolate_; // Current isolate pointer. | 224 Thread* thread_; // Current thread pointer. |
225 int argc_tag_; // Encodes argument count and invoked native call type. | 225 int argc_tag_; // Encodes argument count and invoked native call type. |
226 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. | 226 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. |
227 RawObject** retval_; // Pointer to the return value area. | 227 RawObject** retval_; // Pointer to the return value area. |
228 }; | 228 }; |
229 | 229 |
230 } // namespace dart | 230 } // namespace dart |
231 | 231 |
232 #endif // VM_NATIVE_ARGUMENTS_H_ | 232 #endif // VM_NATIVE_ARGUMENTS_H_ |
OLD | NEW |