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