• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CODEGEN_EXTERNAL_REFERENCE_H_
6 #define V8_CODEGEN_EXTERNAL_REFERENCE_H_
7 
8 #include "src/common/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_jslimit, "StackGuard::address_of_jslimit()")                    \
40   V(address_of_real_jslimit, "StackGuard::address_of_real_jslimit()")          \
41   V(heap_is_marking_flag_address, "heap_is_marking_flag_address")              \
42   V(new_space_allocation_top_address, "Heap::NewSpaceAllocationTopAddress()")  \
43   V(new_space_allocation_limit_address,                                        \
44     "Heap::NewSpaceAllocationLimitAddress()")                                  \
45   V(old_space_allocation_top_address, "Heap::OldSpaceAllocationTopAddress")    \
46   V(old_space_allocation_limit_address,                                        \
47     "Heap::OldSpaceAllocationLimitAddress")                                    \
48   V(handle_scope_level_address, "HandleScope::level")                          \
49   V(handle_scope_next_address, "HandleScope::next")                            \
50   V(handle_scope_limit_address, "HandleScope::limit")                          \
51   V(scheduled_exception_address, "Isolate::scheduled_exception")               \
52   V(address_of_pending_message_obj, "address_of_pending_message_obj")          \
53   V(promise_hook_address, "Isolate::promise_hook_address()")                   \
54   V(async_event_delegate_address, "Isolate::async_event_delegate_address()")   \
55   V(promise_hook_or_async_event_delegate_address,                              \
56     "Isolate::promise_hook_or_async_event_delegate_address()")                 \
57   V(promise_hook_or_debug_is_active_or_async_event_delegate_address,           \
58     "Isolate::promise_hook_or_debug_is_active_or_async_event_delegate_"        \
59     "address()")                                                               \
60   V(debug_execution_mode_address, "Isolate::debug_execution_mode_address()")   \
61   V(debug_is_active_address, "Debug::is_active_address()")                     \
62   V(debug_hook_on_function_call_address,                                       \
63     "Debug::hook_on_function_call_address()")                                  \
64   V(runtime_function_table_address,                                            \
65     "Runtime::runtime_function_table_address()")                               \
66   V(is_profiling_address, "Isolate::is_profiling")                             \
67   V(debug_suspended_generator_address,                                         \
68     "Debug::step_suspended_generator_address()")                               \
69   V(debug_restart_fp_address, "Debug::restart_fp_address()")                   \
70   V(fast_c_call_caller_fp_address,                                             \
71     "IsolateData::fast_c_call_caller_fp_address")                              \
72   V(fast_c_call_caller_pc_address,                                             \
73     "IsolateData::fast_c_call_caller_pc_address")                              \
74   V(stack_is_iterable_address, "IsolateData::stack_is_iterable_address")       \
75   V(address_of_regexp_stack_limit_address,                                     \
76     "RegExpStack::limit_address_address()")                                    \
77   V(address_of_regexp_stack_memory_top_address,                                \
78     "RegExpStack::memory_top_address_address()")                               \
79   V(address_of_static_offsets_vector, "OffsetsVector::static_offsets_vector")  \
80   V(re_case_insensitive_compare_unicode,                                       \
81     "NativeRegExpMacroAssembler::CaseInsensitiveCompareUnicode()")             \
82   V(re_case_insensitive_compare_non_unicode,                                   \
83     "NativeRegExpMacroAssembler::CaseInsensitiveCompareNonUnicode()")          \
84   V(re_check_stack_guard_state,                                                \
85     "RegExpMacroAssembler*::CheckStackGuardState()")                           \
86   V(re_grow_stack, "NativeRegExpMacroAssembler::GrowStack()")                  \
87   V(re_word_character_map, "NativeRegExpMacroAssembler::word_character_map")   \
88   EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V)
89 
90 #ifdef V8_HEAP_SANDBOX
91 #define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V) \
92   V(external_pointer_table_address,                          \
93     "Isolate::external_pointer_table_address("               \
94     ")")
95 #else
96 #define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE_HEAP_SANDBOX(V)
97 #endif  // V8_HEAP_SANDBOX
98 
99 #define EXTERNAL_REFERENCE_LIST(V)                                             \
100   V(abort_with_reason, "abort_with_reason")                                    \
101   V(address_of_double_abs_constant, "double_absolute_constant")                \
102   V(address_of_double_neg_constant, "double_negate_constant")                  \
103   V(address_of_enable_experimental_regexp_engine,                              \
104     "address_of_enable_experimental_regexp_engine")                            \
105   V(address_of_float_abs_constant, "float_absolute_constant")                  \
106   V(address_of_float_neg_constant, "float_negate_constant")                    \
107   V(address_of_min_int, "LDoubleConstant::min_int")                            \
108   V(address_of_mock_arraybuffer_allocator_flag,                                \
109     "FLAG_mock_arraybuffer_allocator")                                         \
110   V(address_of_one_half, "LDoubleConstant::one_half")                          \
111   V(address_of_runtime_stats_flag, "TracingFlags::runtime_stats")              \
112   V(address_of_the_hole_nan, "the_hole_nan")                                   \
113   V(address_of_uint32_bias, "uint32_bias")                                     \
114   V(bytecode_size_table_address, "Bytecodes::bytecode_size_table_address")     \
115   V(check_object_type, "check_object_type")                                    \
116   V(compute_integer_hash, "ComputeSeededHash")                                 \
117   V(compute_output_frames_function, "Deoptimizer::ComputeOutputFrames()")      \
118   V(copy_fast_number_jsarray_elements_to_typed_array,                          \
119     "copy_fast_number_jsarray_elements_to_typed_array")                        \
120   V(copy_typed_array_elements_slice, "copy_typed_array_elements_slice")        \
121   V(copy_typed_array_elements_to_typed_array,                                  \
122     "copy_typed_array_elements_to_typed_array")                                \
123   V(cpu_features, "cpu_features")                                              \
124   V(delete_handle_scope_extensions, "HandleScope::DeleteExtensions")           \
125   V(ephemeron_key_write_barrier_function,                                      \
126     "Heap::EphemeronKeyWriteBarrierFromCode")                                  \
127   V(f64_acos_wrapper_function, "f64_acos_wrapper")                             \
128   V(f64_asin_wrapper_function, "f64_asin_wrapper")                             \
129   V(f64_mod_wrapper_function, "f64_mod_wrapper")                               \
130   V(get_date_field_function, "JSDate::GetField")                               \
131   V(get_or_create_hash_raw, "get_or_create_hash_raw")                          \
132   V(ieee754_acos_function, "base::ieee754::acos")                              \
133   V(ieee754_acosh_function, "base::ieee754::acosh")                            \
134   V(ieee754_asin_function, "base::ieee754::asin")                              \
135   V(ieee754_asinh_function, "base::ieee754::asinh")                            \
136   V(ieee754_atan_function, "base::ieee754::atan")                              \
137   V(ieee754_atan2_function, "base::ieee754::atan2")                            \
138   V(ieee754_atanh_function, "base::ieee754::atanh")                            \
139   V(ieee754_cbrt_function, "base::ieee754::cbrt")                              \
140   V(ieee754_cos_function, "base::ieee754::cos")                                \
141   V(ieee754_cosh_function, "base::ieee754::cosh")                              \
142   V(ieee754_exp_function, "base::ieee754::exp")                                \
143   V(ieee754_expm1_function, "base::ieee754::expm1")                            \
144   V(ieee754_log_function, "base::ieee754::log")                                \
145   V(ieee754_log10_function, "base::ieee754::log10")                            \
146   V(ieee754_log1p_function, "base::ieee754::log1p")                            \
147   V(ieee754_log2_function, "base::ieee754::log2")                              \
148   V(ieee754_pow_function, "base::ieee754::pow")                                \
149   V(ieee754_sin_function, "base::ieee754::sin")                                \
150   V(ieee754_sinh_function, "base::ieee754::sinh")                              \
151   V(ieee754_tan_function, "base::ieee754::tan")                                \
152   V(ieee754_tanh_function, "base::ieee754::tanh")                              \
153   V(insert_remembered_set_function, "Heap::InsertIntoRememberedSetFromCode")   \
154   V(invalidate_prototype_chains_function,                                      \
155     "JSObject::InvalidatePrototypeChains()")                                   \
156   V(invoke_accessor_getter_callback, "InvokeAccessorGetterCallback")           \
157   V(invoke_function_callback, "InvokeFunctionCallback")                        \
158   V(jsarray_array_join_concat_to_sequential_string,                            \
159     "jsarray_array_join_concat_to_sequential_string")                          \
160   V(jsreceiver_create_identity_hash, "jsreceiver_create_identity_hash")        \
161   V(libc_memchr_function, "libc_memchr")                                       \
162   V(libc_memcpy_function, "libc_memcpy")                                       \
163   V(libc_memmove_function, "libc_memmove")                                     \
164   V(libc_memset_function, "libc_memset")                                       \
165   V(mod_two_doubles_operation, "mod_two_doubles")                              \
166   V(mutable_big_int_absolute_add_and_canonicalize_function,                    \
167     "MutableBigInt_AbsoluteAddAndCanonicalize")                                \
168   V(mutable_big_int_absolute_compare_function,                                 \
169     "MutableBigInt_AbsoluteCompare")                                           \
170   V(mutable_big_int_absolute_sub_and_canonicalize_function,                    \
171     "MutableBigInt_AbsoluteSubAndCanonicalize")                                \
172   V(new_deoptimizer_function, "Deoptimizer::New()")                            \
173   V(orderedhashmap_gethash_raw, "orderedhashmap_gethash_raw")                  \
174   V(printf_function, "printf")                                                 \
175   V(refill_math_random, "MathRandom::RefillCache")                             \
176   V(search_string_raw_one_one, "search_string_raw_one_one")                    \
177   V(search_string_raw_one_two, "search_string_raw_one_two")                    \
178   V(search_string_raw_two_one, "search_string_raw_two_one")                    \
179   V(search_string_raw_two_two, "search_string_raw_two_two")                    \
180   V(smi_lexicographic_compare_function, "smi_lexicographic_compare_function")  \
181   V(string_to_array_index_function, "String::ToArrayIndex")                    \
182   V(try_string_to_index_or_lookup_existing,                                    \
183     "try_string_to_index_or_lookup_existing")                                  \
184   V(wasm_call_trap_callback_for_testing,                                       \
185     "wasm::call_trap_callback_for_testing")                                    \
186   V(wasm_f32_ceil, "wasm::f32_ceil_wrapper")                                   \
187   V(wasm_f32_floor, "wasm::f32_floor_wrapper")                                 \
188   V(wasm_f32_nearest_int, "wasm::f32_nearest_int_wrapper")                     \
189   V(wasm_f32_trunc, "wasm::f32_trunc_wrapper")                                 \
190   V(wasm_f64_ceil, "wasm::f64_ceil_wrapper")                                   \
191   V(wasm_f64_floor, "wasm::f64_floor_wrapper")                                 \
192   V(wasm_f64_nearest_int, "wasm::f64_nearest_int_wrapper")                     \
193   V(wasm_f64_trunc, "wasm::f64_trunc_wrapper")                                 \
194   V(wasm_float32_to_int64, "wasm::float32_to_int64_wrapper")                   \
195   V(wasm_float32_to_uint64, "wasm::float32_to_uint64_wrapper")                 \
196   V(wasm_float32_to_int64_sat, "wasm::float32_to_int64_sat_wrapper")           \
197   V(wasm_float32_to_uint64_sat, "wasm::float32_to_uint64_sat_wrapper")         \
198   V(wasm_float64_pow, "wasm::float64_pow")                                     \
199   V(wasm_float64_to_int64, "wasm::float64_to_int64_wrapper")                   \
200   V(wasm_float64_to_uint64, "wasm::float64_to_uint64_wrapper")                 \
201   V(wasm_float64_to_int64_sat, "wasm::float64_to_int64_sat_wrapper")           \
202   V(wasm_float64_to_uint64_sat, "wasm::float64_to_uint64_sat_wrapper")         \
203   V(wasm_int64_div, "wasm::int64_div")                                         \
204   V(wasm_int64_mod, "wasm::int64_mod")                                         \
205   V(wasm_int64_to_float32, "wasm::int64_to_float32_wrapper")                   \
206   V(wasm_int64_to_float64, "wasm::int64_to_float64_wrapper")                   \
207   V(wasm_uint64_div, "wasm::uint64_div")                                       \
208   V(wasm_uint64_mod, "wasm::uint64_mod")                                       \
209   V(wasm_uint64_to_float32, "wasm::uint64_to_float32_wrapper")                 \
210   V(wasm_uint64_to_float64, "wasm::uint64_to_float64_wrapper")                 \
211   V(wasm_word32_ctz, "wasm::word32_ctz")                                       \
212   V(wasm_word32_popcnt, "wasm::word32_popcnt")                                 \
213   V(wasm_word32_rol, "wasm::word32_rol")                                       \
214   V(wasm_word32_ror, "wasm::word32_ror")                                       \
215   V(wasm_word64_rol, "wasm::word64_rol")                                       \
216   V(wasm_word64_ror, "wasm::word64_ror")                                       \
217   V(wasm_word64_ctz, "wasm::word64_ctz")                                       \
218   V(wasm_word64_popcnt, "wasm::word64_popcnt")                                 \
219   V(wasm_f64x2_ceil, "wasm::f64x2_ceil_wrapper")                               \
220   V(wasm_f64x2_floor, "wasm::f64x2_floor_wrapper")                             \
221   V(wasm_f64x2_trunc, "wasm::f64x2_trunc_wrapper")                             \
222   V(wasm_f64x2_nearest_int, "wasm::f64x2_nearest_int_wrapper")                 \
223   V(wasm_f32x4_ceil, "wasm::f32x4_ceil_wrapper")                               \
224   V(wasm_f32x4_floor, "wasm::f32x4_floor_wrapper")                             \
225   V(wasm_f32x4_trunc, "wasm::f32x4_trunc_wrapper")                             \
226   V(wasm_f32x4_nearest_int, "wasm::f32x4_nearest_int_wrapper")                 \
227   V(wasm_memory_init, "wasm::memory_init")                                     \
228   V(wasm_memory_copy, "wasm::memory_copy")                                     \
229   V(wasm_memory_fill, "wasm::memory_fill")                                     \
230   V(write_barrier_marking_from_code_function, "WriteBarrier::MarkingFromCode") \
231   V(call_enqueue_microtask_function, "MicrotaskQueue::CallEnqueueMicrotask")   \
232   V(call_enter_context_function, "call_enter_context_function")                \
233   V(atomic_pair_load_function, "atomic_pair_load_function")                    \
234   V(atomic_pair_store_function, "atomic_pair_store_function")                  \
235   V(atomic_pair_add_function, "atomic_pair_add_function")                      \
236   V(atomic_pair_sub_function, "atomic_pair_sub_function")                      \
237   V(atomic_pair_and_function, "atomic_pair_and_function")                      \
238   V(atomic_pair_or_function, "atomic_pair_or_function")                        \
239   V(atomic_pair_xor_function, "atomic_pair_xor_function")                      \
240   V(atomic_pair_exchange_function, "atomic_pair_exchange_function")            \
241   V(atomic_pair_compare_exchange_function,                                     \
242     "atomic_pair_compare_exchange_function")                                   \
243   V(js_finalization_registry_remove_cell_from_unregister_token_map,            \
244     "JSFinalizationRegistry::RemoveCellFromUnregisterTokenMap")                \
245   V(re_match_for_call_from_js, "IrregexpInterpreter::MatchForCallFromJs")      \
246   V(re_experimental_match_for_call_from_js,                                    \
247     "ExperimentalRegExp::MatchForCallFromJs")                                  \
248   EXTERNAL_REFERENCE_LIST_INTL(V)                                              \
249   EXTERNAL_REFERENCE_LIST_HEAP_SANDBOX(V)
250 
251 #ifdef V8_INTL_SUPPORT
252 #define EXTERNAL_REFERENCE_LIST_INTL(V)                               \
253   V(intl_convert_one_byte_to_lower, "intl_convert_one_byte_to_lower") \
254   V(intl_to_latin1_lower_table, "intl_to_latin1_lower_table")
255 #else
256 #define EXTERNAL_REFERENCE_LIST_INTL(V)
257 #endif  // V8_INTL_SUPPORT
258 
259 #ifdef V8_HEAP_SANDBOX
260 #define EXTERNAL_REFERENCE_LIST_HEAP_SANDBOX(V) \
261   V(external_pointer_table_grow_table_function, \
262     "ExternalPointerTable::GrowTable")
263 #else
264 #define EXTERNAL_REFERENCE_LIST_HEAP_SANDBOX(V)
265 #endif  // V8_HEAP_SANDBOX
266 
267 // An ExternalReference represents a C++ address used in the generated
268 // code. All references to C++ functions and variables must be encapsulated
269 // in an ExternalReference instance. This is done in order to track the
270 // origin of all external references in the code so that they can be bound
271 // to the correct addresses when deserializing a heap.
272 class ExternalReference {
273  public:
274   // Used in the simulator to support different native api calls.
275   enum Type {
276     // Builtin call.
277     // Address f(v8::internal::Arguments).
278     BUILTIN_CALL,  // default
279 
280     // Builtin call returning object pair.
281     // ObjectPair f(v8::internal::Arguments).
282     BUILTIN_CALL_PAIR,
283 
284     // Builtin that takes float arguments and returns an int.
285     // int f(double, double).
286     BUILTIN_COMPARE_CALL,
287 
288     // Builtin call that returns floating point.
289     // double f(double, double).
290     BUILTIN_FP_FP_CALL,
291 
292     // Builtin call that returns floating point.
293     // double f(double).
294     BUILTIN_FP_CALL,
295 
296     // Builtin call that returns floating point.
297     // double f(double, int).
298     BUILTIN_FP_INT_CALL,
299 
300     // Direct call to API function callback.
301     // void f(v8::FunctionCallbackInfo&)
302     DIRECT_API_CALL,
303 
304     // Call to function callback via InvokeFunctionCallback.
305     // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
306     PROFILING_API_CALL,
307 
308     // Direct call to accessor getter callback.
309     // void f(Local<Name> property, PropertyCallbackInfo& info)
310     DIRECT_GETTER_CALL,
311 
312     // Call to accessor getter callback via InvokeAccessorGetterCallback.
313     // void f(Local<Name> property, PropertyCallbackInfo& info,
314     //     AccessorNameGetterCallback callback)
315     PROFILING_GETTER_CALL
316   };
317 
318   static constexpr int kExternalReferenceCount =
319 #define COUNT_EXTERNAL_REFERENCE(name, desc) +1
320       EXTERNAL_REFERENCE_LIST(COUNT_EXTERNAL_REFERENCE)
321           EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(COUNT_EXTERNAL_REFERENCE);
322 #undef COUNT_EXTERNAL_REFERENCE
323 
ExternalReference()324   ExternalReference() : address_(kNullAddress) {}
325   static ExternalReference Create(const SCTableReference& table_ref);
326   static ExternalReference Create(StatsCounter* counter);
327   static V8_EXPORT_PRIVATE ExternalReference Create(ApiFunction* ptr,
328                                                     Type type);
329   static ExternalReference Create(const Runtime::Function* f);
330   static ExternalReference Create(IsolateAddressId id, Isolate* isolate);
331   static ExternalReference Create(Runtime::FunctionId id);
332   static V8_EXPORT_PRIVATE ExternalReference Create(Address address);
333 
334   template <typename SubjectChar, typename PatternChar>
335   static ExternalReference search_string_raw();
336 
337   V8_EXPORT_PRIVATE static ExternalReference FromRawAddress(Address address);
338 
339 #define DECL_EXTERNAL_REFERENCE(name, desc) \
340   V8_EXPORT_PRIVATE static ExternalReference name();
341   EXTERNAL_REFERENCE_LIST(DECL_EXTERNAL_REFERENCE)
342 #undef DECL_EXTERNAL_REFERENCE
343 
344 #define DECL_EXTERNAL_REFERENCE(name, desc) \
345   static V8_EXPORT_PRIVATE ExternalReference name(Isolate* isolate);
346   EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(DECL_EXTERNAL_REFERENCE)
347 #undef DECL_EXTERNAL_REFERENCE
348 
349   V8_EXPORT_PRIVATE V8_NOINLINE static ExternalReference
350   runtime_function_table_address_for_unittests(Isolate* isolate);
351 
352   static V8_EXPORT_PRIVATE ExternalReference
353   address_of_load_from_stack_count(const char* function_name);
354   static V8_EXPORT_PRIVATE ExternalReference
355   address_of_store_to_stack_count(const char* function_name);
356 
address()357   Address address() const { return address_; }
358 
359  private:
ExternalReference(Address address)360   explicit ExternalReference(Address address) : address_(address) {}
361 
ExternalReference(void * address)362   explicit ExternalReference(void* address)
363       : address_(reinterpret_cast<Address>(address)) {}
364 
365   static Address Redirect(Address address_arg,
366                           Type type = ExternalReference::BUILTIN_CALL);
367 
368   Address address_;
369 };
370 ASSERT_TRIVIALLY_COPYABLE(ExternalReference);
371 
372 V8_EXPORT_PRIVATE bool operator==(ExternalReference, ExternalReference);
373 bool operator!=(ExternalReference, ExternalReference);
374 
375 size_t hash_value(ExternalReference);
376 
377 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ExternalReference);
378 
379 void abort_with_reason(int reason);
380 
381 }  // namespace internal
382 }  // namespace v8
383 
384 #endif  // V8_CODEGEN_EXTERNAL_REFERENCE_H_
385