| 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 RUNTIME_VM_RUNTIME_ENTRY_H_ | 5 #ifndef RUNTIME_VM_RUNTIME_ENTRY_H_ |
| 6 #define RUNTIME_VM_RUNTIME_ENTRY_H_ | 6 #define RUNTIME_VM_RUNTIME_ENTRY_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/native_arguments.h" | 10 #include "vm/native_arguments.h" |
| 11 #include "vm/runtime_entry_list.h" | 11 #include "vm/runtime_entry_list.h" |
| 12 #include "vm/safepoint.h" | 12 #include "vm/safepoint.h" |
| 13 #include "vm/tags.h" | 13 #include "vm/tags.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 class Assembler; | 17 class Assembler; |
| 18 | 18 |
| 19 DECLARE_FLAG(bool, trace_runtime_calls); | 19 DECLARE_FLAG(bool, trace_runtime_calls); |
| 20 | 20 |
| 21 typedef void (*RuntimeFunction)(NativeArguments arguments); | 21 typedef void (*RuntimeFunction)(NativeArguments arguments); |
| 22 | 22 |
| 23 enum RuntimeFunctionId { | 23 enum RuntimeFunctionId { |
| 24 kNoRuntimeFunctionId = -1, | 24 kNoRuntimeFunctionId = -1, |
| 25 #define DECLARE_ENUM_VALUE(name) \ | 25 #define DECLARE_ENUM_VALUE(name) k##name##Id, |
| 26 k##name##Id, | |
| 27 RUNTIME_ENTRY_LIST(DECLARE_ENUM_VALUE) | 26 RUNTIME_ENTRY_LIST(DECLARE_ENUM_VALUE) |
| 28 #undef DECLARE_ENUM_VALUE | 27 #undef DECLARE_ENUM_VALUE |
| 29 | 28 |
| 30 #define DECLARE_LEAF_ENUM_VALUE(type, name, ...) \ | 29 #define DECLARE_LEAF_ENUM_VALUE(type, name, ...) k##name##Id, |
| 31 k##name##Id, | 30 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_ENUM_VALUE) |
| 32 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_ENUM_VALUE) | |
| 33 #undef DECLARE_LEAF_ENUM_VALUE | 31 #undef DECLARE_LEAF_ENUM_VALUE |
| 34 }; | 32 }; |
| 35 | 33 |
| 36 // Class RuntimeEntry is used to encapsulate runtime functions, it includes | 34 // Class RuntimeEntry is used to encapsulate runtime functions, it includes |
| 37 // the entry point for the runtime function and the number of arguments expected | 35 // the entry point for the runtime function and the number of arguments expected |
| 38 // by the function. | 36 // by the function. |
| 39 class RuntimeEntry : public ValueObject { | 37 class RuntimeEntry : public ValueObject { |
| 40 public: | 38 public: |
| 41 RuntimeEntry(const char* name, RuntimeFunction function, | 39 RuntimeEntry(const char* name, |
| 42 intptr_t argument_count, bool is_leaf, bool is_float) | 40 RuntimeFunction function, |
| 41 intptr_t argument_count, |
| 42 bool is_leaf, |
| 43 bool is_float) |
| 43 : name_(name), | 44 : name_(name), |
| 44 function_(function), | 45 function_(function), |
| 45 argument_count_(argument_count), | 46 argument_count_(argument_count), |
| 46 is_leaf_(is_leaf), | 47 is_leaf_(is_leaf), |
| 47 is_float_(is_float), | 48 is_float_(is_float), |
| 48 next_(NULL) { | 49 next_(NULL) { |
| 49 VMTag::RegisterRuntimeEntry(this); | 50 VMTag::RegisterRuntimeEntry(this); |
| 50 } | 51 } |
| 51 | 52 |
| 52 const char* name() const { return name_; } | 53 const char* name() const { return name_; } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 76 DISALLOW_COPY_AND_ASSIGN(RuntimeEntry); | 77 DISALLOW_COPY_AND_ASSIGN(RuntimeEntry); |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 #ifndef PRODUCT | 80 #ifndef PRODUCT |
| 80 #define TRACE_RUNTIME_CALL(format, name) \ | 81 #define TRACE_RUNTIME_CALL(format, name) \ |
| 81 if (FLAG_trace_runtime_calls) { \ | 82 if (FLAG_trace_runtime_calls) { \ |
| 82 OS::Print("Runtime call: " format "\n", name); \ | 83 OS::Print("Runtime call: " format "\n", name); \ |
| 83 } | 84 } |
| 84 #else | 85 #else |
| 85 #define TRACE_RUNTIME_CALL(format, name) \ | 86 #define TRACE_RUNTIME_CALL(format, name) \ |
| 86 do { } while (0) | 87 do { \ |
| 88 } while (0) |
| 87 #endif | 89 #endif |
| 88 | 90 |
| 89 // Helper macros for declaring and defining runtime entries. | 91 // Helper macros for declaring and defining runtime entries. |
| 90 | 92 |
| 91 #define DEFINE_RUNTIME_ENTRY(name, argument_count) \ | 93 #define DEFINE_RUNTIME_ENTRY(name, argument_count) \ |
| 92 extern void DRT_##name(NativeArguments arguments); \ | 94 extern void DRT_##name(NativeArguments arguments); \ |
| 93 extern const RuntimeEntry k##name##RuntimeEntry( \ | 95 extern const RuntimeEntry k##name##RuntimeEntry( \ |
| 94 "DRT_"#name, &DRT_##name, argument_count, false, false); \ | 96 "DRT_" #name, &DRT_##name, argument_count, false, false); \ |
| 95 static void DRT_Helper##name(Isolate* isolate, \ | 97 static void DRT_Helper##name(Isolate* isolate, Thread* thread, Zone* zone, \ |
| 96 Thread* thread, \ | |
| 97 Zone* zone, \ | |
| 98 NativeArguments arguments); \ | 98 NativeArguments arguments); \ |
| 99 void DRT_##name(NativeArguments arguments) { \ | 99 void DRT_##name(NativeArguments arguments) { \ |
| 100 CHECK_STACK_ALIGNMENT; \ | 100 CHECK_STACK_ALIGNMENT; \ |
| 101 VERIFY_ON_TRANSITION; \ | 101 VERIFY_ON_TRANSITION; \ |
| 102 ASSERT(arguments.ArgCount() == argument_count); \ | 102 ASSERT(arguments.ArgCount() == argument_count); \ |
| 103 TRACE_RUNTIME_CALL("%s", ""#name); \ | 103 TRACE_RUNTIME_CALL("%s", "" #name); \ |
| 104 { \ | 104 { \ |
| 105 Thread* thread = arguments.thread(); \ | 105 Thread* thread = arguments.thread(); \ |
| 106 ASSERT(thread == Thread::Current()); \ | 106 ASSERT(thread == Thread::Current()); \ |
| 107 Isolate* isolate = thread->isolate(); \ | 107 Isolate* isolate = thread->isolate(); \ |
| 108 TransitionGeneratedToVM transition(thread); \ | 108 TransitionGeneratedToVM transition(thread); \ |
| 109 StackZone zone(thread); \ | 109 StackZone zone(thread); \ |
| 110 HANDLESCOPE(thread); \ | 110 HANDLESCOPE(thread); \ |
| 111 DRT_Helper##name(isolate, thread, zone.GetZone(), arguments); \ | 111 DRT_Helper##name(isolate, thread, zone.GetZone(), arguments); \ |
| 112 } \ | 112 } \ |
| 113 VERIFY_ON_TRANSITION; \ | 113 VERIFY_ON_TRANSITION; \ |
| 114 } \ | 114 } \ |
| 115 static void DRT_Helper##name(Isolate* isolate, \ | 115 static void DRT_Helper##name(Isolate* isolate, Thread* thread, Zone* zone, \ |
| 116 Thread* thread, \ | |
| 117 Zone* zone, \ | |
| 118 NativeArguments arguments) | 116 NativeArguments arguments) |
| 119 | 117 |
| 120 #define DECLARE_RUNTIME_ENTRY(name) \ | 118 #define DECLARE_RUNTIME_ENTRY(name) \ |
| 121 extern const RuntimeEntry k##name##RuntimeEntry; \ | 119 extern const RuntimeEntry k##name##RuntimeEntry; \ |
| 122 extern void DRT_##name(NativeArguments arguments); \ | 120 extern void DRT_##name(NativeArguments arguments); |
| 123 | 121 |
| 124 #define DEFINE_LEAF_RUNTIME_ENTRY(type, name, argument_count, ...) \ | 122 #define DEFINE_LEAF_RUNTIME_ENTRY(type, name, argument_count, ...) \ |
| 125 extern "C" type DLRT_##name(__VA_ARGS__); \ | 123 extern "C" type DLRT_##name(__VA_ARGS__); \ |
| 126 extern const RuntimeEntry k##name##RuntimeEntry( \ | 124 extern const RuntimeEntry k##name##RuntimeEntry( \ |
| 127 "DLRT_"#name, reinterpret_cast<RuntimeFunction>(&DLRT_##name), \ | 125 "DLRT_" #name, reinterpret_cast<RuntimeFunction>(&DLRT_##name), \ |
| 128 argument_count, true, false); \ | 126 argument_count, true, false); \ |
| 129 type DLRT_##name(__VA_ARGS__) { \ | 127 type DLRT_##name(__VA_ARGS__) { \ |
| 130 CHECK_STACK_ALIGNMENT; \ | 128 CHECK_STACK_ALIGNMENT; \ |
| 131 NoSafepointScope no_safepoint_scope; \ | 129 NoSafepointScope no_safepoint_scope; |
| 132 | 130 |
| 133 #define END_LEAF_RUNTIME_ENTRY } | 131 #define END_LEAF_RUNTIME_ENTRY } |
| 134 | 132 |
| 135 // TODO(rmacnak): Fix alignment issue on simarm and simmips and use | 133 // TODO(rmacnak): Fix alignment issue on simarm and simmips and use |
| 136 // DEFINE_LEAF_RUNTIME_ENTRY instead. | 134 // DEFINE_LEAF_RUNTIME_ENTRY instead. |
| 137 #define DEFINE_RAW_LEAF_RUNTIME_ENTRY(name, argument_count, is_float, func) \ | 135 #define DEFINE_RAW_LEAF_RUNTIME_ENTRY(name, argument_count, is_float, func) \ |
| 138 extern const RuntimeEntry k##name##RuntimeEntry( \ | 136 extern const RuntimeEntry k##name##RuntimeEntry( \ |
| 139 "DFLRT_"#name, func, argument_count, true, is_float) \ | 137 "DFLRT_" #name, func, argument_count, true, is_float) |
| 140 | 138 |
| 141 #define DECLARE_LEAF_RUNTIME_ENTRY(type, name, ...) \ | 139 #define DECLARE_LEAF_RUNTIME_ENTRY(type, name, ...) \ |
| 142 extern const RuntimeEntry k##name##RuntimeEntry; \ | 140 extern const RuntimeEntry k##name##RuntimeEntry; \ |
| 143 extern "C" type DLRT_##name(__VA_ARGS__); \ | 141 extern "C" type DLRT_##name(__VA_ARGS__); |
| 144 | 142 |
| 145 | 143 |
| 146 // Declare all runtime functions here. | 144 // Declare all runtime functions here. |
| 147 RUNTIME_ENTRY_LIST(DECLARE_RUNTIME_ENTRY) | 145 RUNTIME_ENTRY_LIST(DECLARE_RUNTIME_ENTRY) |
| 148 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_RUNTIME_ENTRY) | 146 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_RUNTIME_ENTRY) |
| 149 | 147 |
| 150 | 148 |
| 151 // Declare all runtime functions here. | 149 // Declare all runtime functions here. |
| 152 RUNTIME_ENTRY_LIST(DECLARE_RUNTIME_ENTRY) | 150 RUNTIME_ENTRY_LIST(DECLARE_RUNTIME_ENTRY) |
| 153 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_RUNTIME_ENTRY) | 151 LEAF_RUNTIME_ENTRY_LIST(DECLARE_LEAF_RUNTIME_ENTRY) |
| 154 | 152 |
| 155 | 153 |
| 156 uword RuntimeEntry::AddressFromId(RuntimeFunctionId id) { | 154 uword RuntimeEntry::AddressFromId(RuntimeFunctionId id) { |
| 157 switch (id) { | 155 switch (id) { |
| 158 #define DEFINE_RUNTIME_CASE(name) \ | 156 #define DEFINE_RUNTIME_CASE(name) \ |
| 159 case k##name##Id: return k##name##RuntimeEntry.GetEntryPoint(); | 157 case k##name##Id: \ |
| 158 return k##name##RuntimeEntry.GetEntryPoint(); |
| 160 RUNTIME_ENTRY_LIST(DEFINE_RUNTIME_CASE) | 159 RUNTIME_ENTRY_LIST(DEFINE_RUNTIME_CASE) |
| 161 #undef DEFINE_RUNTIME_CASE | 160 #undef DEFINE_RUNTIME_CASE |
| 162 | 161 |
| 163 #define DEFINE_LEAF_RUNTIME_CASE(type, name, ...) \ | 162 #define DEFINE_LEAF_RUNTIME_CASE(type, name, ...) \ |
| 164 case k##name##Id: return k##name##RuntimeEntry.GetEntryPoint(); | 163 case k##name##Id: \ |
| 164 return k##name##RuntimeEntry.GetEntryPoint(); |
| 165 LEAF_RUNTIME_ENTRY_LIST(DEFINE_LEAF_RUNTIME_CASE) | 165 LEAF_RUNTIME_ENTRY_LIST(DEFINE_LEAF_RUNTIME_CASE) |
| 166 #undef DEFINE_LEAF_RUNTIME_CASE | 166 #undef DEFINE_LEAF_RUNTIME_CASE |
| 167 default: | 167 default: |
| 168 break; | 168 break; |
| 169 } | 169 } |
| 170 return 0; | 170 return 0; |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 RuntimeFunctionId RuntimeEntry::RuntimeFunctionIdFromAddress(uword address) { | 174 RuntimeFunctionId RuntimeEntry::RuntimeFunctionIdFromAddress(uword address) { |
| 175 #define CHECK_RUNTIME_ADDRESS(name) \ | 175 #define CHECK_RUNTIME_ADDRESS(name) \ |
| 176 if (address == k##name##RuntimeEntry.GetEntryPoint()) return k##name##Id; | 176 if (address == k##name##RuntimeEntry.GetEntryPoint()) return k##name##Id; |
| 177 RUNTIME_ENTRY_LIST(CHECK_RUNTIME_ADDRESS) | 177 RUNTIME_ENTRY_LIST(CHECK_RUNTIME_ADDRESS) |
| 178 #undef CHECK_RUNTIME_ADDRESS | 178 #undef CHECK_RUNTIME_ADDRESS |
| 179 | 179 |
| 180 #define CHECK_LEAF_RUNTIME_ADDRESS(type, name, ...) \ | 180 #define CHECK_LEAF_RUNTIME_ADDRESS(type, name, ...) \ |
| 181 if (address == k##name##RuntimeEntry.GetEntryPoint()) return k##name##Id; | 181 if (address == k##name##RuntimeEntry.GetEntryPoint()) return k##name##Id; |
| 182 LEAF_RUNTIME_ENTRY_LIST(CHECK_LEAF_RUNTIME_ADDRESS) | 182 LEAF_RUNTIME_ENTRY_LIST(CHECK_LEAF_RUNTIME_ADDRESS) |
| 183 #undef CHECK_LEAF_RUNTIME_ADDRESS | 183 #undef CHECK_LEAF_RUNTIME_ADDRESS |
| 184 return kNoRuntimeFunctionId; | 184 return kNoRuntimeFunctionId; |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace dart | 187 } // namespace dart |
| 188 | 188 |
| 189 #endif // RUNTIME_VM_RUNTIME_ENTRY_H_ | 189 #endif // RUNTIME_VM_RUNTIME_ENTRY_H_ |
| OLD | NEW |