Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_EXTERNAL_REFERENCE_H_
6 : #define V8_EXTERNAL_REFERENCE_H_
7 :
8 : #include "src/globals.h"
9 : #include "src/runtime/runtime.h"
10 :
11 : namespace v8 {
12 :
13 : class ApiFunction;
14 :
15 : namespace internal {
16 :
17 : class Isolate;
18 : class Page;
19 : class SCTableReference;
20 : class StatsCounter;
21 :
22 : //------------------------------------------------------------------------------
23 : // External references
24 :
25 : #define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(V) \
26 : V(isolate_address, "isolate") \
27 : V(builtins_address, "builtins") \
28 : V(handle_scope_implementer_address, \
29 : "Isolate::handle_scope_implementer_address") \
30 : V(address_of_interpreter_entry_trampoline_instruction_start, \
31 : "Address of the InterpreterEntryTrampoline instruction start") \
32 : V(interpreter_dispatch_counters, "Interpreter::dispatch_counters") \
33 : V(interpreter_dispatch_table_address, "Interpreter::dispatch_table_address") \
34 : V(date_cache_stamp, "date_cache_stamp") \
35 : V(stress_deopt_count, "Isolate::stress_deopt_count_address()") \
36 : V(force_slow_path, "Isolate::force_slow_path_address()") \
37 : V(isolate_root, "Isolate::isolate_root()") \
38 : V(allocation_sites_list_address, "Heap::allocation_sites_list_address()") \
39 : V(address_of_stack_limit, "StackGuard::address_of_jslimit()") \
40 : V(address_of_real_stack_limit, "StackGuard::address_of_real_jslimit()") \
41 : V(store_buffer_top, "store_buffer_top") \
42 : V(heap_is_marking_flag_address, "heap_is_marking_flag_address") \
43 : V(new_space_allocation_top_address, "Heap::NewSpaceAllocationTopAddress()") \
44 : V(new_space_allocation_limit_address, \
45 : "Heap::NewSpaceAllocationLimitAddress()") \
46 : V(old_space_allocation_top_address, "Heap::OldSpaceAllocationTopAddress") \
47 : V(old_space_allocation_limit_address, \
48 : "Heap::OldSpaceAllocationLimitAddress") \
49 : V(handle_scope_level_address, "HandleScope::level") \
50 : V(handle_scope_next_address, "HandleScope::next") \
51 : V(handle_scope_limit_address, "HandleScope::limit") \
52 : V(scheduled_exception_address, "Isolate::scheduled_exception") \
53 : V(address_of_pending_message_obj, "address_of_pending_message_obj") \
54 : V(promise_hook_address, "Isolate::promise_hook_address()") \
55 : V(async_event_delegate_address, "Isolate::async_event_delegate_address()") \
56 : V(promise_hook_or_async_event_delegate_address, \
57 : "Isolate::promise_hook_or_async_event_delegate_address()") \
58 : V(promise_hook_or_debug_is_active_or_async_event_delegate_address, \
59 : "Isolate::promise_hook_or_debug_is_active_or_async_event_delegate_" \
60 : "address()") \
61 : V(debug_execution_mode_address, "Isolate::debug_execution_mode_address()") \
62 : V(debug_is_active_address, "Debug::is_active_address()") \
63 : V(debug_hook_on_function_call_address, \
64 : "Debug::hook_on_function_call_address()") \
65 : V(runtime_function_table_address, \
66 : "Runtime::runtime_function_table_address()") \
67 : V(is_profiling_address, "Isolate::is_profiling") \
68 : V(debug_suspended_generator_address, \
69 : "Debug::step_suspended_generator_address()") \
70 : V(debug_restart_fp_address, "Debug::restart_fp_address()") \
71 : V(fast_c_call_caller_fp_address, \
72 : "IsolateData::fast_c_call_caller_fp_address") \
73 : V(fast_c_call_caller_pc_address, \
74 : "IsolateData::fast_c_call_caller_pc_address") \
75 : V(address_of_regexp_stack_limit, "RegExpStack::limit_address()") \
76 : V(address_of_regexp_stack_memory_address, "RegExpStack::memory_address()") \
77 : V(address_of_regexp_stack_memory_size, "RegExpStack::memory_size()") \
78 : V(address_of_static_offsets_vector, "OffsetsVector::static_offsets_vector") \
79 : V(re_case_insensitive_compare_uc16, \
80 : "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()") \
81 : V(re_check_stack_guard_state, \
82 : "RegExpMacroAssembler*::CheckStackGuardState()") \
83 : V(re_grow_stack, "NativeRegExpMacroAssembler::GrowStack()") \
84 : V(re_word_character_map, "NativeRegExpMacroAssembler::word_character_map")
85 :
86 : #define EXTERNAL_REFERENCE_LIST(V) \
87 : V(abort_with_reason, "abort_with_reason") \
88 : V(address_of_double_abs_constant, "double_absolute_constant") \
89 : V(address_of_double_neg_constant, "double_negate_constant") \
90 : V(address_of_float_abs_constant, "float_absolute_constant") \
91 : V(address_of_float_neg_constant, "float_negate_constant") \
92 : V(address_of_harmony_await_optimization_flag, \
93 : "FLAG_harmony_await_optimization") \
94 : V(address_of_min_int, "LDoubleConstant::min_int") \
95 : V(address_of_one_half, "LDoubleConstant::one_half") \
96 : V(address_of_runtime_stats_flag, "FLAG_runtime_stats") \
97 : V(address_of_the_hole_nan, "the_hole_nan") \
98 : V(address_of_uint32_bias, "uint32_bias") \
99 : V(bytecode_size_table_address, "Bytecodes::bytecode_size_table_address") \
100 : V(check_object_type, "check_object_type") \
101 : V(compute_integer_hash, "ComputeSeededHash") \
102 : V(compute_output_frames_function, "Deoptimizer::ComputeOutputFrames()") \
103 : V(copy_fast_number_jsarray_elements_to_typed_array, \
104 : "copy_fast_number_jsarray_elements_to_typed_array") \
105 : V(copy_typed_array_elements_slice, "copy_typed_array_elements_slice") \
106 : V(copy_typed_array_elements_to_typed_array, \
107 : "copy_typed_array_elements_to_typed_array") \
108 : V(cpu_features, "cpu_features") \
109 : V(delete_handle_scope_extensions, "HandleScope::DeleteExtensions") \
110 : V(f64_acos_wrapper_function, "f64_acos_wrapper") \
111 : V(f64_asin_wrapper_function, "f64_asin_wrapper") \
112 : V(f64_mod_wrapper_function, "f64_mod_wrapper") \
113 : V(fixed_typed_array_base_data_offset, "fixed_typed_array_base_data_offset") \
114 : V(get_date_field_function, "JSDate::GetField") \
115 : V(get_or_create_hash_raw, "get_or_create_hash_raw") \
116 : V(ieee754_acos_function, "base::ieee754::acos") \
117 : V(ieee754_acosh_function, "base::ieee754::acosh") \
118 : V(ieee754_asin_function, "base::ieee754::asin") \
119 : V(ieee754_asinh_function, "base::ieee754::asinh") \
120 : V(ieee754_atan_function, "base::ieee754::atan") \
121 : V(ieee754_atan2_function, "base::ieee754::atan2") \
122 : V(ieee754_atanh_function, "base::ieee754::atanh") \
123 : V(ieee754_cbrt_function, "base::ieee754::cbrt") \
124 : V(ieee754_cos_function, "base::ieee754::cos") \
125 : V(ieee754_cosh_function, "base::ieee754::cosh") \
126 : V(ieee754_exp_function, "base::ieee754::exp") \
127 : V(ieee754_expm1_function, "base::ieee754::expm1") \
128 : V(ieee754_log_function, "base::ieee754::log") \
129 : V(ieee754_log10_function, "base::ieee754::log10") \
130 : V(ieee754_log1p_function, "base::ieee754::log1p") \
131 : V(ieee754_log2_function, "base::ieee754::log2") \
132 : V(ieee754_pow_function, "base::ieee754::pow") \
133 : V(ieee754_sin_function, "base::ieee754::sin") \
134 : V(ieee754_sinh_function, "base::ieee754::sinh") \
135 : V(ieee754_tan_function, "base::ieee754::tan") \
136 : V(ieee754_tanh_function, "base::ieee754::tanh") \
137 : V(incremental_marking_record_write_function, \
138 : "IncrementalMarking::RecordWrite") \
139 : V(invalidate_prototype_chains_function, \
140 : "JSObject::InvalidatePrototypeChains()") \
141 : V(invoke_accessor_getter_callback, "InvokeAccessorGetterCallback") \
142 : V(invoke_function_callback, "InvokeFunctionCallback") \
143 : V(jsarray_array_join_concat_to_sequential_string, \
144 : "jsarray_array_join_concat_to_sequential_string") \
145 : V(jsreceiver_create_identity_hash, "jsreceiver_create_identity_hash") \
146 : V(libc_memchr_function, "libc_memchr") \
147 : V(libc_memcpy_function, "libc_memcpy") \
148 : V(libc_memmove_function, "libc_memmove") \
149 : V(libc_memset_function, "libc_memset") \
150 : V(log_enter_external_function, "Logger::EnterExternal") \
151 : V(log_leave_external_function, "Logger::LeaveExternal") \
152 : V(mod_two_doubles_operation, "mod_two_doubles") \
153 : V(new_deoptimizer_function, "Deoptimizer::New()") \
154 : V(orderedhashmap_gethash_raw, "orderedhashmap_gethash_raw") \
155 : V(printf_function, "printf") \
156 : V(refill_math_random, "MathRandom::RefillCache") \
157 : V(search_string_raw_one_one, "search_string_raw_one_one") \
158 : V(search_string_raw_one_two, "search_string_raw_one_two") \
159 : V(search_string_raw_two_one, "search_string_raw_two_one") \
160 : V(search_string_raw_two_two, "search_string_raw_two_two") \
161 : V(smi_lexicographic_compare_function, "smi_lexicographic_compare_function") \
162 : V(store_buffer_overflow_function, "StoreBuffer::StoreBufferOverflow") \
163 : V(try_internalize_string_function, "try_internalize_string_function") \
164 : V(wasm_call_trap_callback_for_testing, \
165 : "wasm::call_trap_callback_for_testing") \
166 : V(wasm_f32_ceil, "wasm::f32_ceil_wrapper") \
167 : V(wasm_f32_floor, "wasm::f32_floor_wrapper") \
168 : V(wasm_f32_nearest_int, "wasm::f32_nearest_int_wrapper") \
169 : V(wasm_f32_trunc, "wasm::f32_trunc_wrapper") \
170 : V(wasm_f64_ceil, "wasm::f64_ceil_wrapper") \
171 : V(wasm_f64_floor, "wasm::f64_floor_wrapper") \
172 : V(wasm_f64_nearest_int, "wasm::f64_nearest_int_wrapper") \
173 : V(wasm_f64_trunc, "wasm::f64_trunc_wrapper") \
174 : V(wasm_float32_to_int64, "wasm::float32_to_int64_wrapper") \
175 : V(wasm_float32_to_uint64, "wasm::float32_to_uint64_wrapper") \
176 : V(wasm_float64_pow, "wasm::float64_pow") \
177 : V(wasm_float64_to_int64, "wasm::float64_to_int64_wrapper") \
178 : V(wasm_float64_to_uint64, "wasm::float64_to_uint64_wrapper") \
179 : V(wasm_int64_div, "wasm::int64_div") \
180 : V(wasm_int64_mod, "wasm::int64_mod") \
181 : V(wasm_int64_to_float32, "wasm::int64_to_float32_wrapper") \
182 : V(wasm_int64_to_float64, "wasm::int64_to_float64_wrapper") \
183 : V(wasm_uint64_div, "wasm::uint64_div") \
184 : V(wasm_uint64_mod, "wasm::uint64_mod") \
185 : V(wasm_uint64_to_float32, "wasm::uint64_to_float32_wrapper") \
186 : V(wasm_uint64_to_float64, "wasm::uint64_to_float64_wrapper") \
187 : V(wasm_word32_ctz, "wasm::word32_ctz") \
188 : V(wasm_word32_popcnt, "wasm::word32_popcnt") \
189 : V(wasm_word32_rol, "wasm::word32_rol") \
190 : V(wasm_word32_ror, "wasm::word32_ror") \
191 : V(wasm_word64_ctz, "wasm::word64_ctz") \
192 : V(wasm_word64_popcnt, "wasm::word64_popcnt") \
193 : V(wasm_memory_copy, "wasm::memory_copy") \
194 : V(wasm_memory_fill, "wasm::memory_fill") \
195 : V(call_enqueue_microtask_function, "MicrotaskQueue::CallEnqueueMicrotask") \
196 : V(call_enter_context_function, "call_enter_context_function") \
197 : V(atomic_pair_load_function, "atomic_pair_load_function") \
198 : V(atomic_pair_store_function, "atomic_pair_store_function") \
199 : V(atomic_pair_add_function, "atomic_pair_add_function") \
200 : V(atomic_pair_sub_function, "atomic_pair_sub_function") \
201 : V(atomic_pair_and_function, "atomic_pair_and_function") \
202 : V(atomic_pair_or_function, "atomic_pair_or_function") \
203 : V(atomic_pair_xor_function, "atomic_pair_xor_function") \
204 : V(atomic_pair_exchange_function, "atomic_pair_exchange_function") \
205 : V(atomic_pair_compare_exchange_function, \
206 : "atomic_pair_compare_exchange_function") \
207 : EXTERNAL_REFERENCE_LIST_INTL(V)
208 :
209 : #ifdef V8_INTL_SUPPORT
210 : #define EXTERNAL_REFERENCE_LIST_INTL(V) \
211 : V(intl_convert_one_byte_to_lower, "intl_convert_one_byte_to_lower") \
212 : V(intl_to_latin1_lower_table, "intl_to_latin1_lower_table")
213 : #else
214 : #define EXTERNAL_REFERENCE_LIST_INTL(V)
215 : #endif // V8_INTL_SUPPORT
216 :
217 : // An ExternalReference represents a C++ address used in the generated
218 : // code. All references to C++ functions and variables must be encapsulated
219 : // in an ExternalReference instance. This is done in order to track the
220 : // origin of all external references in the code so that they can be bound
221 : // to the correct addresses when deserializing a heap.
222 : class ExternalReference {
223 : public:
224 : // Used in the simulator to support different native api calls.
225 : enum Type {
226 : // Builtin call.
227 : // Address f(v8::internal::Arguments).
228 : BUILTIN_CALL, // default
229 :
230 : // Builtin call returning object pair.
231 : // ObjectPair f(v8::internal::Arguments).
232 : BUILTIN_CALL_PAIR,
233 :
234 : // Builtin that takes float arguments and returns an int.
235 : // int f(double, double).
236 : BUILTIN_COMPARE_CALL,
237 :
238 : // Builtin call that returns floating point.
239 : // double f(double, double).
240 : BUILTIN_FP_FP_CALL,
241 :
242 : // Builtin call that returns floating point.
243 : // double f(double).
244 : BUILTIN_FP_CALL,
245 :
246 : // Builtin call that returns floating point.
247 : // double f(double, int).
248 : BUILTIN_FP_INT_CALL,
249 :
250 : // Direct call to API function callback.
251 : // void f(v8::FunctionCallbackInfo&)
252 : DIRECT_API_CALL,
253 :
254 : // Call to function callback via InvokeFunctionCallback.
255 : // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
256 : PROFILING_API_CALL,
257 :
258 : // Direct call to accessor getter callback.
259 : // void f(Local<Name> property, PropertyCallbackInfo& info)
260 : DIRECT_GETTER_CALL,
261 :
262 : // Call to accessor getter callback via InvokeAccessorGetterCallback.
263 : // void f(Local<Name> property, PropertyCallbackInfo& info,
264 : // AccessorNameGetterCallback callback)
265 : PROFILING_GETTER_CALL
266 : };
267 :
268 : static constexpr int kExternalReferenceCount =
269 : #define COUNT_EXTERNAL_REFERENCE(name, desc) +1
270 : EXTERNAL_REFERENCE_LIST(COUNT_EXTERNAL_REFERENCE)
271 : EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(COUNT_EXTERNAL_REFERENCE);
272 : #undef COUNT_EXTERNAL_REFERENCE
273 :
274 : typedef Address ExternalReferenceRedirector(Address original, Type type);
275 :
276 5036634 : ExternalReference() : address_(kNullAddress) {}
277 : static ExternalReference Create(const SCTableReference& table_ref);
278 : static ExternalReference Create(StatsCounter* counter);
279 : static ExternalReference Create(ApiFunction* ptr, Type type);
280 : static ExternalReference Create(const Runtime::Function* f);
281 : static ExternalReference Create(IsolateAddressId id, Isolate* isolate);
282 : static ExternalReference Create(Runtime::FunctionId id);
283 : static V8_EXPORT_PRIVATE ExternalReference Create(Address address);
284 :
285 : template <typename SubjectChar, typename PatternChar>
286 : static ExternalReference search_string_raw();
287 :
288 : static ExternalReference FromRawAddress(Address address);
289 :
290 : #define DECL_EXTERNAL_REFERENCE(name, desc) static ExternalReference name();
291 : EXTERNAL_REFERENCE_LIST(DECL_EXTERNAL_REFERENCE)
292 : #undef DECL_EXTERNAL_REFERENCE
293 :
294 : #define DECL_EXTERNAL_REFERENCE(name, desc) \
295 : static V8_EXPORT_PRIVATE ExternalReference name(Isolate* isolate);
296 : EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(DECL_EXTERNAL_REFERENCE)
297 : #undef DECL_EXTERNAL_REFERENCE
298 :
299 : V8_EXPORT_PRIVATE V8_NOINLINE static ExternalReference
300 : runtime_function_table_address_for_unittests(Isolate* isolate);
301 :
302 70456225 : Address address() const { return address_; }
303 :
304 : private:
305 : explicit ExternalReference(Address address) : address_(address) {}
306 :
307 : explicit ExternalReference(void* address)
308 3501402 : : address_(reinterpret_cast<Address>(address)) {}
309 :
310 : static Address Redirect(Address address_arg,
311 : Type type = ExternalReference::BUILTIN_CALL);
312 :
313 : Address address_;
314 : };
315 : ASSERT_TRIVIALLY_COPYABLE(ExternalReference);
316 :
317 : V8_EXPORT_PRIVATE bool operator==(ExternalReference, ExternalReference);
318 : bool operator!=(ExternalReference, ExternalReference);
319 :
320 : size_t hash_value(ExternalReference);
321 :
322 : V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ExternalReference);
323 :
324 : void abort_with_reason(int reason);
325 :
326 : } // namespace internal
327 : } // namespace v8
328 :
329 : #endif // V8_EXTERNAL_REFERENCE_H_
|