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_mock_arraybuffer_allocator_flag, \
96 : "FLAG_mock_arraybuffer_allocator") \
97 : V(address_of_one_half, "LDoubleConstant::one_half") \
98 : V(address_of_runtime_stats_flag, "TracingFlags::runtime_stats") \
99 : V(address_of_the_hole_nan, "the_hole_nan") \
100 : V(address_of_uint32_bias, "uint32_bias") \
101 : V(bytecode_size_table_address, "Bytecodes::bytecode_size_table_address") \
102 : V(check_object_type, "check_object_type") \
103 : V(compute_integer_hash, "ComputeSeededHash") \
104 : V(compute_output_frames_function, "Deoptimizer::ComputeOutputFrames()") \
105 : V(copy_fast_number_jsarray_elements_to_typed_array, \
106 : "copy_fast_number_jsarray_elements_to_typed_array") \
107 : V(copy_typed_array_elements_slice, "copy_typed_array_elements_slice") \
108 : V(copy_typed_array_elements_to_typed_array, \
109 : "copy_typed_array_elements_to_typed_array") \
110 : V(cpu_features, "cpu_features") \
111 : V(delete_handle_scope_extensions, "HandleScope::DeleteExtensions") \
112 : V(f64_acos_wrapper_function, "f64_acos_wrapper") \
113 : V(f64_asin_wrapper_function, "f64_asin_wrapper") \
114 : V(f64_mod_wrapper_function, "f64_mod_wrapper") \
115 : V(get_date_field_function, "JSDate::GetField") \
116 : V(get_or_create_hash_raw, "get_or_create_hash_raw") \
117 : V(ieee754_acos_function, "base::ieee754::acos") \
118 : V(ieee754_acosh_function, "base::ieee754::acosh") \
119 : V(ieee754_asin_function, "base::ieee754::asin") \
120 : V(ieee754_asinh_function, "base::ieee754::asinh") \
121 : V(ieee754_atan_function, "base::ieee754::atan") \
122 : V(ieee754_atan2_function, "base::ieee754::atan2") \
123 : V(ieee754_atanh_function, "base::ieee754::atanh") \
124 : V(ieee754_cbrt_function, "base::ieee754::cbrt") \
125 : V(ieee754_cos_function, "base::ieee754::cos") \
126 : V(ieee754_cosh_function, "base::ieee754::cosh") \
127 : V(ieee754_exp_function, "base::ieee754::exp") \
128 : V(ieee754_expm1_function, "base::ieee754::expm1") \
129 : V(ieee754_log_function, "base::ieee754::log") \
130 : V(ieee754_log10_function, "base::ieee754::log10") \
131 : V(ieee754_log1p_function, "base::ieee754::log1p") \
132 : V(ieee754_log2_function, "base::ieee754::log2") \
133 : V(ieee754_pow_function, "base::ieee754::pow") \
134 : V(ieee754_sin_function, "base::ieee754::sin") \
135 : V(ieee754_sinh_function, "base::ieee754::sinh") \
136 : V(ieee754_tan_function, "base::ieee754::tan") \
137 : V(ieee754_tanh_function, "base::ieee754::tanh") \
138 : V(incremental_marking_record_write_function, \
139 : "IncrementalMarking::RecordWrite") \
140 : V(invalidate_prototype_chains_function, \
141 : "JSObject::InvalidatePrototypeChains()") \
142 : V(invoke_accessor_getter_callback, "InvokeAccessorGetterCallback") \
143 : V(invoke_function_callback, "InvokeFunctionCallback") \
144 : V(jsarray_array_join_concat_to_sequential_string, \
145 : "jsarray_array_join_concat_to_sequential_string") \
146 : V(jsreceiver_create_identity_hash, "jsreceiver_create_identity_hash") \
147 : V(libc_memchr_function, "libc_memchr") \
148 : V(libc_memcpy_function, "libc_memcpy") \
149 : V(libc_memmove_function, "libc_memmove") \
150 : V(libc_memset_function, "libc_memset") \
151 : V(log_enter_external_function, "Logger::EnterExternal") \
152 : V(log_leave_external_function, "Logger::LeaveExternal") \
153 : V(mod_two_doubles_operation, "mod_two_doubles") \
154 : V(new_deoptimizer_function, "Deoptimizer::New()") \
155 : V(orderedhashmap_gethash_raw, "orderedhashmap_gethash_raw") \
156 : V(printf_function, "printf") \
157 : V(refill_math_random, "MathRandom::RefillCache") \
158 : V(search_string_raw_one_one, "search_string_raw_one_one") \
159 : V(search_string_raw_one_two, "search_string_raw_one_two") \
160 : V(search_string_raw_two_one, "search_string_raw_two_one") \
161 : V(search_string_raw_two_two, "search_string_raw_two_two") \
162 : V(smi_lexicographic_compare_function, "smi_lexicographic_compare_function") \
163 : V(store_buffer_overflow_function, "StoreBuffer::StoreBufferOverflow") \
164 : V(try_internalize_string_function, "try_internalize_string_function") \
165 : V(wasm_call_trap_callback_for_testing, \
166 : "wasm::call_trap_callback_for_testing") \
167 : V(wasm_f32_ceil, "wasm::f32_ceil_wrapper") \
168 : V(wasm_f32_floor, "wasm::f32_floor_wrapper") \
169 : V(wasm_f32_nearest_int, "wasm::f32_nearest_int_wrapper") \
170 : V(wasm_f32_trunc, "wasm::f32_trunc_wrapper") \
171 : V(wasm_f64_ceil, "wasm::f64_ceil_wrapper") \
172 : V(wasm_f64_floor, "wasm::f64_floor_wrapper") \
173 : V(wasm_f64_nearest_int, "wasm::f64_nearest_int_wrapper") \
174 : V(wasm_f64_trunc, "wasm::f64_trunc_wrapper") \
175 : V(wasm_float32_to_int64, "wasm::float32_to_int64_wrapper") \
176 : V(wasm_float32_to_uint64, "wasm::float32_to_uint64_wrapper") \
177 : V(wasm_float64_pow, "wasm::float64_pow") \
178 : V(wasm_float64_to_int64, "wasm::float64_to_int64_wrapper") \
179 : V(wasm_float64_to_uint64, "wasm::float64_to_uint64_wrapper") \
180 : V(wasm_int64_div, "wasm::int64_div") \
181 : V(wasm_int64_mod, "wasm::int64_mod") \
182 : V(wasm_int64_to_float32, "wasm::int64_to_float32_wrapper") \
183 : V(wasm_int64_to_float64, "wasm::int64_to_float64_wrapper") \
184 : V(wasm_uint64_div, "wasm::uint64_div") \
185 : V(wasm_uint64_mod, "wasm::uint64_mod") \
186 : V(wasm_uint64_to_float32, "wasm::uint64_to_float32_wrapper") \
187 : V(wasm_uint64_to_float64, "wasm::uint64_to_float64_wrapper") \
188 : V(wasm_word32_ctz, "wasm::word32_ctz") \
189 : V(wasm_word32_popcnt, "wasm::word32_popcnt") \
190 : V(wasm_word32_rol, "wasm::word32_rol") \
191 : V(wasm_word32_ror, "wasm::word32_ror") \
192 : V(wasm_word64_ctz, "wasm::word64_ctz") \
193 : V(wasm_word64_popcnt, "wasm::word64_popcnt") \
194 : V(wasm_memory_copy, "wasm::memory_copy") \
195 : V(wasm_memory_fill, "wasm::memory_fill") \
196 : V(call_enqueue_microtask_function, "MicrotaskQueue::CallEnqueueMicrotask") \
197 : V(call_enter_context_function, "call_enter_context_function") \
198 : V(atomic_pair_load_function, "atomic_pair_load_function") \
199 : V(atomic_pair_store_function, "atomic_pair_store_function") \
200 : V(atomic_pair_add_function, "atomic_pair_add_function") \
201 : V(atomic_pair_sub_function, "atomic_pair_sub_function") \
202 : V(atomic_pair_and_function, "atomic_pair_and_function") \
203 : V(atomic_pair_or_function, "atomic_pair_or_function") \
204 : V(atomic_pair_xor_function, "atomic_pair_xor_function") \
205 : V(atomic_pair_exchange_function, "atomic_pair_exchange_function") \
206 : V(atomic_pair_compare_exchange_function, \
207 : "atomic_pair_compare_exchange_function") \
208 : EXTERNAL_REFERENCE_LIST_INTL(V)
209 :
210 : #ifdef V8_INTL_SUPPORT
211 : #define EXTERNAL_REFERENCE_LIST_INTL(V) \
212 : V(intl_convert_one_byte_to_lower, "intl_convert_one_byte_to_lower") \
213 : V(intl_to_latin1_lower_table, "intl_to_latin1_lower_table")
214 : #else
215 : #define EXTERNAL_REFERENCE_LIST_INTL(V)
216 : #endif // V8_INTL_SUPPORT
217 :
218 : // An ExternalReference represents a C++ address used in the generated
219 : // code. All references to C++ functions and variables must be encapsulated
220 : // in an ExternalReference instance. This is done in order to track the
221 : // origin of all external references in the code so that they can be bound
222 : // to the correct addresses when deserializing a heap.
223 : class ExternalReference {
224 : public:
225 : // Used in the simulator to support different native api calls.
226 : enum Type {
227 : // Builtin call.
228 : // Address f(v8::internal::Arguments).
229 : BUILTIN_CALL, // default
230 :
231 : // Builtin call returning object pair.
232 : // ObjectPair f(v8::internal::Arguments).
233 : BUILTIN_CALL_PAIR,
234 :
235 : // Builtin that takes float arguments and returns an int.
236 : // int f(double, double).
237 : BUILTIN_COMPARE_CALL,
238 :
239 : // Builtin call that returns floating point.
240 : // double f(double, double).
241 : BUILTIN_FP_FP_CALL,
242 :
243 : // Builtin call that returns floating point.
244 : // double f(double).
245 : BUILTIN_FP_CALL,
246 :
247 : // Builtin call that returns floating point.
248 : // double f(double, int).
249 : BUILTIN_FP_INT_CALL,
250 :
251 : // Direct call to API function callback.
252 : // void f(v8::FunctionCallbackInfo&)
253 : DIRECT_API_CALL,
254 :
255 : // Call to function callback via InvokeFunctionCallback.
256 : // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
257 : PROFILING_API_CALL,
258 :
259 : // Direct call to accessor getter callback.
260 : // void f(Local<Name> property, PropertyCallbackInfo& info)
261 : DIRECT_GETTER_CALL,
262 :
263 : // Call to accessor getter callback via InvokeAccessorGetterCallback.
264 : // void f(Local<Name> property, PropertyCallbackInfo& info,
265 : // AccessorNameGetterCallback callback)
266 : PROFILING_GETTER_CALL
267 : };
268 :
269 : static constexpr int kExternalReferenceCount =
270 : #define COUNT_EXTERNAL_REFERENCE(name, desc) +1
271 : EXTERNAL_REFERENCE_LIST(COUNT_EXTERNAL_REFERENCE)
272 : EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(COUNT_EXTERNAL_REFERENCE);
273 : #undef COUNT_EXTERNAL_REFERENCE
274 :
275 : typedef Address ExternalReferenceRedirector(Address original, Type type);
276 :
277 5096955 : ExternalReference() : address_(kNullAddress) {}
278 : static ExternalReference Create(const SCTableReference& table_ref);
279 : static ExternalReference Create(StatsCounter* counter);
280 : static ExternalReference Create(ApiFunction* ptr, Type type);
281 : static ExternalReference Create(const Runtime::Function* f);
282 : static ExternalReference Create(IsolateAddressId id, Isolate* isolate);
283 : static ExternalReference Create(Runtime::FunctionId id);
284 : static V8_EXPORT_PRIVATE ExternalReference Create(Address address);
285 :
286 : template <typename SubjectChar, typename PatternChar>
287 : static ExternalReference search_string_raw();
288 :
289 : static ExternalReference FromRawAddress(Address address);
290 :
291 : #define DECL_EXTERNAL_REFERENCE(name, desc) static ExternalReference name();
292 : EXTERNAL_REFERENCE_LIST(DECL_EXTERNAL_REFERENCE)
293 : #undef DECL_EXTERNAL_REFERENCE
294 :
295 : #define DECL_EXTERNAL_REFERENCE(name, desc) \
296 : static V8_EXPORT_PRIVATE ExternalReference name(Isolate* isolate);
297 : EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(DECL_EXTERNAL_REFERENCE)
298 : #undef DECL_EXTERNAL_REFERENCE
299 :
300 : V8_EXPORT_PRIVATE V8_NOINLINE static ExternalReference
301 : runtime_function_table_address_for_unittests(Isolate* isolate);
302 :
303 72722365 : Address address() const { return address_; }
304 :
305 : private:
306 : explicit ExternalReference(Address address) : address_(address) {}
307 :
308 : explicit ExternalReference(void* address)
309 3620909 : : address_(reinterpret_cast<Address>(address)) {}
310 :
311 : static Address Redirect(Address address_arg,
312 : Type type = ExternalReference::BUILTIN_CALL);
313 :
314 : Address address_;
315 : };
316 : ASSERT_TRIVIALLY_COPYABLE(ExternalReference);
317 :
318 : V8_EXPORT_PRIVATE bool operator==(ExternalReference, ExternalReference);
319 : bool operator!=(ExternalReference, ExternalReference);
320 :
321 : size_t hash_value(ExternalReference);
322 :
323 : V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ExternalReference);
324 :
325 : void abort_with_reason(int reason);
326 :
327 : } // namespace internal
328 : } // namespace v8
329 :
330 : #endif // V8_EXTERNAL_REFERENCE_H_
|