OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_RUNTIME_ENTRY_H_ | 5 #ifndef VM_RUNTIME_ENTRY_H_ |
6 #define VM_RUNTIME_ENTRY_H_ | 6 #define VM_RUNTIME_ENTRY_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/assembler.h" | |
10 #include "vm/flags.h" | 9 #include "vm/flags.h" |
11 #include "vm/native_arguments.h" | 10 #include "vm/native_arguments.h" |
12 #include "vm/tags.h" | 11 #include "vm/tags.h" |
13 | 12 |
14 namespace dart { | 13 namespace dart { |
15 | 14 |
15 class Assembler; | |
16 | |
16 DECLARE_FLAG(bool, trace_runtime_calls); | 17 DECLARE_FLAG(bool, trace_runtime_calls); |
17 | 18 |
18 typedef void (*RuntimeFunction)(NativeArguments arguments); | 19 typedef void (*RuntimeFunction)(NativeArguments arguments); |
19 | 20 |
21 #define RUNTIME_ENTRY_LIST(V) \ | |
22 V(AllocateArray) \ | |
23 V(AllocateContext) \ | |
24 V(AllocateObject) \ | |
25 V(BreakpointRuntimeHandler) \ | |
26 V(SingleStepHandler) \ | |
27 V(CloneContext) \ | |
28 V(Deoptimize) \ | |
29 V(FixCallersTarget) \ | |
30 V(FixAllocationStubTarget) \ | |
31 V(InlineCacheMissHandlerOneArg) \ | |
32 V(InlineCacheMissHandlerTwoArgs) \ | |
33 V(InlineCacheMissHandlerThreeArgs) \ | |
34 V(StaticCallMissHandlerOneArg) \ | |
35 V(StaticCallMissHandlerTwoArgs) \ | |
36 V(Instanceof) \ | |
37 V(TypeCheck) \ | |
38 V(BadTypeError) \ | |
39 V(NonBoolTypeError) \ | |
40 V(InstantiateType) \ | |
41 V(InstantiateTypeArguments) \ | |
42 V(InvokeClosureNoSuchMethod) \ | |
43 V(InvokeNoSuchMethodDispatcher) \ | |
44 V(MegamorphicCacheMissHandler) \ | |
45 V(OptimizeInvokedFunction) \ | |
46 V(TraceICCall) \ | |
47 V(PatchStaticCall) \ | |
48 V(ReThrow) \ | |
49 V(StackOverflow) \ | |
50 V(Throw) \ | |
51 V(TraceFunctionEntry) \ | |
52 V(TraceFunctionExit) \ | |
53 V(DeoptimizeMaterialize) \ | |
54 V(UpdateFieldCid) \ | |
55 V(InitStaticField) \ | |
56 V(GrowRegExpStack) \ | |
57 V(CompileFunction) \ | |
58 V(TestSmiSub) \ | |
59 | |
60 #define LEAF_RUNTIME_ENTRY_LIST(V) \ | |
61 V(void, PrintStopMessage, const char*) \ | |
62 V(intptr_t, DeoptimizeCopyFrame, uword) \ | |
63 V(void, DeoptimizeFillFrame, uword) \ | |
64 V(void, StoreBufferBlockProcess, Thread*) \ | |
65 V(intptr_t, BigintCompare, RawBigint*, RawBigint*) \ | |
66 V(RawObject*, TestLeafSmiAdd, RawObject*, RawObject*) \ | |
Florian Schneider
2015/08/14 07:25:52
Please move declaration of test routines to runtim
| |
67 | |
68 | |
69 enum RuntimeFunctionId { | |
70 kNoRuntimeFunctionId = -1, | |
71 #define DECLARE_ENUM_VALUE(name) \ | |
72 k##name##Id, | |
73 RUNTIME_ENTRY_LIST(DECLARE_ENUM_VALUE) | |
74 #undef DECLARE_ENUM_VALUE | |
75 | |
76 #define DECLARE_LEAF_ENUM_VALUE(type, name, ...) \ | |
77 k##name##Id, | |
78 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_ENUM_VALUE) | |
79 #undef DECLARE_LEAF_ENUM_VALUE | |
80 }; | |
20 | 81 |
21 // Class RuntimeEntry is used to encapsulate runtime functions, it includes | 82 // Class RuntimeEntry is used to encapsulate runtime functions, it includes |
22 // the entry point for the runtime function and the number of arguments expected | 83 // the entry point for the runtime function and the number of arguments expected |
23 // by the function. | 84 // by the function. |
24 class RuntimeEntry : public ValueObject { | 85 class RuntimeEntry : public ValueObject { |
25 public: | 86 public: |
26 RuntimeEntry(const char* name, RuntimeFunction function, | 87 RuntimeEntry(const char* name, RuntimeFunction function, |
27 intptr_t argument_count, bool is_leaf, bool is_float) | 88 intptr_t argument_count, bool is_leaf, bool is_float) |
28 : name_(name), | 89 : name_(name), |
29 function_(function), | 90 function_(function), |
(...skipping 12 matching lines...) Expand all Loading... | |
42 bool is_leaf() const { return is_leaf_; } | 103 bool is_leaf() const { return is_leaf_; } |
43 bool is_float() const { return is_float_; } | 104 bool is_float() const { return is_float_; } |
44 uword GetEntryPoint() const { return reinterpret_cast<uword>(function()); } | 105 uword GetEntryPoint() const { return reinterpret_cast<uword>(function()); } |
45 | 106 |
46 // Generate code to call the runtime entry. | 107 // Generate code to call the runtime entry. |
47 void Call(Assembler* assembler, intptr_t argument_count) const; | 108 void Call(Assembler* assembler, intptr_t argument_count) const; |
48 | 109 |
49 void set_next(const RuntimeEntry* next) { next_ = next; } | 110 void set_next(const RuntimeEntry* next) { next_ = next; } |
50 const RuntimeEntry* next() const { return next_; } | 111 const RuntimeEntry* next() const { return next_; } |
51 | 112 |
113 static inline uword AddressFromId(RuntimeFunctionId id); | |
114 static inline RuntimeFunctionId RuntimeFunctionIdFromAddress(uword address); | |
115 | |
52 private: | 116 private: |
53 const char* name_; | 117 const char* name_; |
54 const RuntimeFunction function_; | 118 const RuntimeFunction function_; |
55 const intptr_t argument_count_; | 119 const intptr_t argument_count_; |
56 const bool is_leaf_; | 120 const bool is_leaf_; |
57 const bool is_float_; | 121 const bool is_float_; |
58 const RuntimeEntry* next_; | 122 const RuntimeEntry* next_; |
59 | 123 |
60 DISALLOW_COPY_AND_ASSIGN(RuntimeEntry); | 124 DISALLOW_COPY_AND_ASSIGN(RuntimeEntry); |
61 }; | 125 }; |
(...skipping 23 matching lines...) Expand all Loading... | |
85 DRT_Helper##name(isolate, thread, zone.GetZone(), arguments); \ | 149 DRT_Helper##name(isolate, thread, zone.GetZone(), arguments); \ |
86 } \ | 150 } \ |
87 VERIFY_ON_TRANSITION; \ | 151 VERIFY_ON_TRANSITION; \ |
88 } \ | 152 } \ |
89 static void DRT_Helper##name(Isolate* isolate, \ | 153 static void DRT_Helper##name(Isolate* isolate, \ |
90 Thread* thread, \ | 154 Thread* thread, \ |
91 Zone* zone, \ | 155 Zone* zone, \ |
92 NativeArguments arguments) | 156 NativeArguments arguments) |
93 | 157 |
94 #define DECLARE_RUNTIME_ENTRY(name) \ | 158 #define DECLARE_RUNTIME_ENTRY(name) \ |
95 extern const RuntimeEntry k##name##RuntimeEntry | 159 extern const RuntimeEntry k##name##RuntimeEntry; \ |
160 extern void DRT_##name(NativeArguments arguments); \ | |
96 | 161 |
97 #define DEFINE_LEAF_RUNTIME_ENTRY(type, name, argument_count, ...) \ | 162 #define DEFINE_LEAF_RUNTIME_ENTRY(type, name, argument_count, ...) \ |
98 extern "C" type DLRT_##name(__VA_ARGS__); \ | 163 extern "C" type DLRT_##name(__VA_ARGS__); \ |
99 extern const RuntimeEntry k##name##RuntimeEntry( \ | 164 extern const RuntimeEntry k##name##RuntimeEntry( \ |
100 "DLRT_"#name, reinterpret_cast<RuntimeFunction>(&DLRT_##name), \ | 165 "DLRT_"#name, reinterpret_cast<RuntimeFunction>(&DLRT_##name), \ |
101 argument_count, true, false); \ | 166 argument_count, true, false); \ |
102 type DLRT_##name(__VA_ARGS__) { \ | 167 type DLRT_##name(__VA_ARGS__) { \ |
103 CHECK_STACK_ALIGNMENT; \ | 168 CHECK_STACK_ALIGNMENT; \ |
104 NoSafepointScope no_safepoint_scope; \ | 169 NoSafepointScope no_safepoint_scope; \ |
105 | 170 |
106 #define END_LEAF_RUNTIME_ENTRY } | 171 #define END_LEAF_RUNTIME_ENTRY } |
107 | 172 |
108 #define DECLARE_LEAF_RUNTIME_ENTRY(type, name, ...) \ | 173 #define DECLARE_LEAF_RUNTIME_ENTRY(type, name, ...) \ |
109 extern const RuntimeEntry k##name##RuntimeEntry; \ | 174 extern const RuntimeEntry k##name##RuntimeEntry; \ |
110 extern "C" type DLRT_##name(__VA_ARGS__) | 175 extern "C" type DLRT_##name(__VA_ARGS__); \ |
176 | |
177 | |
178 // Declare all runtime functions here. | |
179 RUNTIME_ENTRY_LIST(DECLARE_RUNTIME_ENTRY) | |
180 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_RUNTIME_ENTRY) | |
181 | |
182 | |
183 // Declare all runtime functions here. | |
184 RUNTIME_ENTRY_LIST(DECLARE_RUNTIME_ENTRY) | |
185 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_RUNTIME_ENTRY) | |
186 | |
187 | |
188 uword RuntimeEntry::AddressFromId(RuntimeFunctionId id) { | |
189 switch (id) { | |
190 #define DEFINE_RUNTIME_CASE(name) \ | |
191 case k##name##Id: return reinterpret_cast<uword>(&DRT_##name); | |
192 RUNTIME_ENTRY_LIST(DEFINE_RUNTIME_CASE) | |
193 #undef DEFINE_RUNTIME_CASE | |
194 | |
195 #define DEFINE_LEAF_RUNTIME_CASE(type, name, ...) \ | |
196 case k##name##Id: return reinterpret_cast<uword>(&DLRT_##name); | |
197 LEAF_RUNTIME_ENTRY_LIST(DEFINE_LEAF_RUNTIME_CASE) | |
198 #undef DEFINE_LEAF_RUNTIME_CASE | |
199 default: | |
200 break; | |
201 } | |
202 return 0; | |
203 } | |
204 | |
205 | |
206 RuntimeFunctionId RuntimeEntry::RuntimeFunctionIdFromAddress(uword address) { | |
207 #define CHECK_RUNTIME_ADDRESS(name) \ | |
208 if (address == reinterpret_cast<uword>(&DRT_##name)) return k##name##Id; | |
209 RUNTIME_ENTRY_LIST(CHECK_RUNTIME_ADDRESS) | |
210 #undef CHECK_RUNTIME_ADDRESS | |
211 | |
212 #define CHECK_LEAF_RUNTIME_ADDRESS(type, name, ...) \ | |
213 if (address == reinterpret_cast<uword>(&DLRT_##name)) return k##name##Id; | |
214 LEAF_RUNTIME_ENTRY_LIST(CHECK_LEAF_RUNTIME_ADDRESS) | |
215 #undef CHECK_LEAF_RUNTIME_ADDRESS | |
216 return kNoRuntimeFunctionId; | |
217 } | |
111 | 218 |
112 } // namespace dart | 219 } // namespace dart |
113 | 220 |
114 #endif // VM_RUNTIME_ENTRY_H_ | 221 #endif // VM_RUNTIME_ENTRY_H_ |
OLD | NEW |