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