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