external-reference.h 19.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_EXTERNAL_REFERENCE_H_
#define V8_EXTERNAL_REFERENCE_H_

#include "src/globals.h"
#include "src/runtime/runtime.h"

namespace v8 {

class ApiFunction;

namespace internal {

class Isolate;
18
class Page;
19 20 21 22 23 24
class SCTableReference;
class StatsCounter;

//------------------------------------------------------------------------------
// External references

25 26
#define EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(V)                                \
  V(isolate_address, "isolate")                                                \
27 28 29
  V(builtins_address, "builtins")                                              \
  V(handle_scope_implementer_address,                                          \
    "Isolate::handle_scope_implementer_address")                               \
30 31
  V(address_of_interpreter_entry_trampoline_instruction_start,                 \
    "Address of the InterpreterEntryTrampoline instruction start")             \
32 33
  V(interpreter_dispatch_counters, "Interpreter::dispatch_counters")           \
  V(interpreter_dispatch_table_address, "Interpreter::dispatch_table_address") \
34 35 36
  V(date_cache_stamp, "date_cache_stamp")                                      \
  V(stress_deopt_count, "Isolate::stress_deopt_count_address()")               \
  V(force_slow_path, "Isolate::force_slow_path_address()")                     \
37
  V(isolate_root, "Isolate::isolate_root()")                                   \
38 39 40 41 42 43
  V(allocation_sites_list_address, "Heap::allocation_sites_list_address()")    \
  V(address_of_stack_limit, "StackGuard::address_of_jslimit()")                \
  V(address_of_real_stack_limit, "StackGuard::address_of_real_jslimit()")      \
  V(store_buffer_top, "store_buffer_top")                                      \
  V(heap_is_marking_flag_address, "heap_is_marking_flag_address")              \
  V(new_space_allocation_top_address, "Heap::NewSpaceAllocationTopAddress()")  \
44 45
  V(new_space_allocation_limit_address,                                        \
    "Heap::NewSpaceAllocationLimitAddress()")                                  \
46
  V(old_space_allocation_top_address, "Heap::OldSpaceAllocationTopAddress")    \
47 48
  V(old_space_allocation_limit_address,                                        \
    "Heap::OldSpaceAllocationLimitAddress")                                    \
49 50 51 52 53
  V(handle_scope_level_address, "HandleScope::level")                          \
  V(handle_scope_next_address, "HandleScope::next")                            \
  V(handle_scope_limit_address, "HandleScope::limit")                          \
  V(scheduled_exception_address, "Isolate::scheduled_exception")               \
  V(address_of_pending_message_obj, "address_of_pending_message_obj")          \
54 55 56 57
  V(promise_hook_address, "Isolate::promise_hook_address()")                   \
  V(async_event_delegate_address, "Isolate::async_event_delegate_address()")   \
  V(promise_hook_or_async_event_delegate_address,                              \
    "Isolate::promise_hook_or_async_event_delegate_address()")                 \
58 59 60
  V(promise_hook_or_debug_is_active_or_async_event_delegate_address,           \
    "Isolate::promise_hook_or_debug_is_active_or_async_event_delegate_"        \
    "address()")                                                               \
61
  V(debug_execution_mode_address, "Isolate::debug_execution_mode_address()")   \
62 63 64
  V(debug_is_active_address, "Debug::is_active_address()")                     \
  V(debug_hook_on_function_call_address,                                       \
    "Debug::hook_on_function_call_address()")                                  \
65 66
  V(runtime_function_table_address,                                            \
    "Runtime::runtime_function_table_address()")                               \
67 68 69 70
  V(is_profiling_address, "Isolate::is_profiling")                             \
  V(debug_suspended_generator_address,                                         \
    "Debug::step_suspended_generator_address()")                               \
  V(debug_restart_fp_address, "Debug::restart_fp_address()")                   \
71 72 73 74
  V(fast_c_call_caller_fp_address,                                             \
    "IsolateData::fast_c_call_caller_fp_address")                              \
  V(fast_c_call_caller_pc_address,                                             \
    "IsolateData::fast_c_call_caller_pc_address")                              \
75 76 77 78 79 80 81 82 83 84
  V(address_of_regexp_stack_limit, "RegExpStack::limit_address()")             \
  V(address_of_regexp_stack_memory_address, "RegExpStack::memory_address()")   \
  V(address_of_regexp_stack_memory_size, "RegExpStack::memory_size()")         \
  V(address_of_static_offsets_vector, "OffsetsVector::static_offsets_vector")  \
  V(re_case_insensitive_compare_uc16,                                          \
    "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()")                \
  V(re_check_stack_guard_state,                                                \
    "RegExpMacroAssembler*::CheckStackGuardState()")                           \
  V(re_grow_stack, "NativeRegExpMacroAssembler::GrowStack()")                  \
  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 89 90 91
  V(address_of_double_abs_constant, "double_absolute_constant")               \
  V(address_of_double_neg_constant, "double_negate_constant")                 \
  V(address_of_float_abs_constant, "float_absolute_constant")                 \
  V(address_of_float_neg_constant, "float_negate_constant")                   \
92 93
  V(address_of_harmony_await_optimization_flag,                               \
    "FLAG_harmony_await_optimization")                                        \
94
  V(address_of_min_int, "LDoubleConstant::min_int")                           \
95 96
  V(address_of_mock_arraybuffer_allocator_flag,                               \
    "FLAG_mock_arraybuffer_allocator")                                        \
97
  V(address_of_one_half, "LDoubleConstant::one_half")                         \
98
  V(address_of_runtime_stats_flag, "TracingFlags::runtime_stats")             \
99 100 101 102
  V(address_of_the_hole_nan, "the_hole_nan")                                  \
  V(address_of_uint32_bias, "uint32_bias")                                    \
  V(bytecode_size_table_address, "Bytecodes::bytecode_size_table_address")    \
  V(check_object_type, "check_object_type")                                   \
103
  V(compute_integer_hash, "ComputeSeededHash")                                \
104 105 106 107 108 109 110 111
  V(compute_output_frames_function, "Deoptimizer::ComputeOutputFrames()")     \
  V(copy_fast_number_jsarray_elements_to_typed_array,                         \
    "copy_fast_number_jsarray_elements_to_typed_array")                       \
  V(copy_typed_array_elements_slice, "copy_typed_array_elements_slice")       \
  V(copy_typed_array_elements_to_typed_array,                                 \
    "copy_typed_array_elements_to_typed_array")                               \
  V(cpu_features, "cpu_features")                                             \
  V(delete_handle_scope_extensions, "HandleScope::DeleteExtensions")          \
112 113
  V(ephemeron_key_write_barrier_function,                                     \
    "Heap::EphemeronKeyWriteBarrierFromCode")                                 \
114 115 116 117
  V(f64_acos_wrapper_function, "f64_acos_wrapper")                            \
  V(f64_asin_wrapper_function, "f64_asin_wrapper")                            \
  V(f64_mod_wrapper_function, "f64_mod_wrapper")                              \
  V(get_date_field_function, "JSDate::GetField")                              \
118
  V(get_or_create_hash_raw, "get_or_create_hash_raw")                         \
119 120 121 122 123
  V(ieee754_acos_function, "base::ieee754::acos")                             \
  V(ieee754_acosh_function, "base::ieee754::acosh")                           \
  V(ieee754_asin_function, "base::ieee754::asin")                             \
  V(ieee754_asinh_function, "base::ieee754::asinh")                           \
  V(ieee754_atan_function, "base::ieee754::atan")                             \
124
  V(ieee754_atan2_function, "base::ieee754::atan2")                           \
125 126 127 128 129 130
  V(ieee754_atanh_function, "base::ieee754::atanh")                           \
  V(ieee754_cbrt_function, "base::ieee754::cbrt")                             \
  V(ieee754_cos_function, "base::ieee754::cos")                               \
  V(ieee754_cosh_function, "base::ieee754::cosh")                             \
  V(ieee754_exp_function, "base::ieee754::exp")                               \
  V(ieee754_expm1_function, "base::ieee754::expm1")                           \
131
  V(ieee754_log_function, "base::ieee754::log")                               \
132 133 134
  V(ieee754_log10_function, "base::ieee754::log10")                           \
  V(ieee754_log1p_function, "base::ieee754::log1p")                           \
  V(ieee754_log2_function, "base::ieee754::log2")                             \
135
  V(ieee754_pow_function, "base::ieee754::pow")                               \
136 137 138 139 140 141 142 143 144 145
  V(ieee754_sin_function, "base::ieee754::sin")                               \
  V(ieee754_sinh_function, "base::ieee754::sinh")                             \
  V(ieee754_tan_function, "base::ieee754::tan")                               \
  V(ieee754_tanh_function, "base::ieee754::tanh")                             \
  V(incremental_marking_record_write_function,                                \
    "IncrementalMarking::RecordWrite")                                        \
  V(invalidate_prototype_chains_function,                                     \
    "JSObject::InvalidatePrototypeChains()")                                  \
  V(invoke_accessor_getter_callback, "InvokeAccessorGetterCallback")          \
  V(invoke_function_callback, "InvokeFunctionCallback")                       \
146 147
  V(jsarray_array_join_concat_to_sequential_string,                           \
    "jsarray_array_join_concat_to_sequential_string")                         \
148
  V(jsreceiver_create_identity_hash, "jsreceiver_create_identity_hash")       \
149 150 151 152 153 154 155 156 157 158
  V(libc_memchr_function, "libc_memchr")                                      \
  V(libc_memcpy_function, "libc_memcpy")                                      \
  V(libc_memmove_function, "libc_memmove")                                    \
  V(libc_memset_function, "libc_memset")                                      \
  V(log_enter_external_function, "Logger::EnterExternal")                     \
  V(log_leave_external_function, "Logger::LeaveExternal")                     \
  V(mod_two_doubles_operation, "mod_two_doubles")                             \
  V(new_deoptimizer_function, "Deoptimizer::New()")                           \
  V(orderedhashmap_gethash_raw, "orderedhashmap_gethash_raw")                 \
  V(printf_function, "printf")                                                \
159
  V(refill_math_random, "MathRandom::RefillCache")                            \
160 161 162 163
  V(search_string_raw_one_one, "search_string_raw_one_one")                   \
  V(search_string_raw_one_two, "search_string_raw_one_two")                   \
  V(search_string_raw_two_one, "search_string_raw_two_one")                   \
  V(search_string_raw_two_two, "search_string_raw_two_two")                   \
164
  V(smi_lexicographic_compare_function, "smi_lexicographic_compare_function") \
165 166
  V(store_buffer_overflow_function, "StoreBuffer::StoreBufferOverflow")       \
  V(try_internalize_string_function, "try_internalize_string_function")       \
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
  V(wasm_call_trap_callback_for_testing,                                      \
    "wasm::call_trap_callback_for_testing")                                   \
  V(wasm_f32_ceil, "wasm::f32_ceil_wrapper")                                  \
  V(wasm_f32_floor, "wasm::f32_floor_wrapper")                                \
  V(wasm_f32_nearest_int, "wasm::f32_nearest_int_wrapper")                    \
  V(wasm_f32_trunc, "wasm::f32_trunc_wrapper")                                \
  V(wasm_f64_ceil, "wasm::f64_ceil_wrapper")                                  \
  V(wasm_f64_floor, "wasm::f64_floor_wrapper")                                \
  V(wasm_f64_nearest_int, "wasm::f64_nearest_int_wrapper")                    \
  V(wasm_f64_trunc, "wasm::f64_trunc_wrapper")                                \
  V(wasm_float32_to_int64, "wasm::float32_to_int64_wrapper")                  \
  V(wasm_float32_to_uint64, "wasm::float32_to_uint64_wrapper")                \
  V(wasm_float64_pow, "wasm::float64_pow")                                    \
  V(wasm_float64_to_int64, "wasm::float64_to_int64_wrapper")                  \
  V(wasm_float64_to_uint64, "wasm::float64_to_uint64_wrapper")                \
  V(wasm_int64_div, "wasm::int64_div")                                        \
  V(wasm_int64_mod, "wasm::int64_mod")                                        \
  V(wasm_int64_to_float32, "wasm::int64_to_float32_wrapper")                  \
  V(wasm_int64_to_float64, "wasm::int64_to_float64_wrapper")                  \
  V(wasm_uint64_div, "wasm::uint64_div")                                      \
  V(wasm_uint64_mod, "wasm::uint64_mod")                                      \
  V(wasm_uint64_to_float32, "wasm::uint64_to_float32_wrapper")                \
  V(wasm_uint64_to_float64, "wasm::uint64_to_float64_wrapper")                \
  V(wasm_word32_ctz, "wasm::word32_ctz")                                      \
  V(wasm_word32_popcnt, "wasm::word32_popcnt")                                \
  V(wasm_word32_rol, "wasm::word32_rol")                                      \
  V(wasm_word32_ror, "wasm::word32_ror")                                      \
  V(wasm_word64_ctz, "wasm::word64_ctz")                                      \
  V(wasm_word64_popcnt, "wasm::word64_popcnt")                                \
196 197
  V(wasm_memory_copy, "wasm::memory_copy")                                    \
  V(wasm_memory_fill, "wasm::memory_fill")                                    \
198
  V(call_enqueue_microtask_function, "MicrotaskQueue::CallEnqueueMicrotask")  \
199
  V(call_enter_context_function, "call_enter_context_function")               \
200 201 202 203 204 205 206 207
  V(atomic_pair_load_function, "atomic_pair_load_function")                   \
  V(atomic_pair_store_function, "atomic_pair_store_function")                 \
  V(atomic_pair_add_function, "atomic_pair_add_function")                     \
  V(atomic_pair_sub_function, "atomic_pair_sub_function")                     \
  V(atomic_pair_and_function, "atomic_pair_and_function")                     \
  V(atomic_pair_or_function, "atomic_pair_or_function")                       \
  V(atomic_pair_xor_function, "atomic_pair_xor_function")                     \
  V(atomic_pair_exchange_function, "atomic_pair_exchange_function")           \
208 209
  V(atomic_pair_compare_exchange_function,                                    \
    "atomic_pair_compare_exchange_function")                                  \
210 211 212 213 214 215 216 217 218 219
  EXTERNAL_REFERENCE_LIST_INTL(V)

#ifdef V8_INTL_SUPPORT
#define EXTERNAL_REFERENCE_LIST_INTL(V)                               \
  V(intl_convert_one_byte_to_lower, "intl_convert_one_byte_to_lower") \
  V(intl_to_latin1_lower_table, "intl_to_latin1_lower_table")
#else
#define EXTERNAL_REFERENCE_LIST_INTL(V)
#endif  // V8_INTL_SUPPORT

220
// An ExternalReference represents a C++ address used in the generated
221 222 223 224
// code. All references to C++ functions and variables must be encapsulated
// in an ExternalReference instance. This is done in order to track the
// origin of all external references in the code so that they can be bound
// to the correct addresses when deserializing a heap.
225
class ExternalReference {
226 227 228 229
 public:
  // Used in the simulator to support different native api calls.
  enum Type {
    // Builtin call.
230
    // Address f(v8::internal::Arguments).
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
    BUILTIN_CALL,  // default

    // Builtin call returning object pair.
    // ObjectPair f(v8::internal::Arguments).
    BUILTIN_CALL_PAIR,

    // Builtin that takes float arguments and returns an int.
    // int f(double, double).
    BUILTIN_COMPARE_CALL,

    // Builtin call that returns floating point.
    // double f(double, double).
    BUILTIN_FP_FP_CALL,

    // Builtin call that returns floating point.
    // double f(double).
    BUILTIN_FP_CALL,

    // Builtin call that returns floating point.
    // double f(double, int).
    BUILTIN_FP_INT_CALL,

    // Direct call to API function callback.
    // void f(v8::FunctionCallbackInfo&)
    DIRECT_API_CALL,

    // Call to function callback via InvokeFunctionCallback.
    // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
    PROFILING_API_CALL,

    // Direct call to accessor getter callback.
    // void f(Local<Name> property, PropertyCallbackInfo& info)
    DIRECT_GETTER_CALL,

    // Call to accessor getter callback via InvokeAccessorGetterCallback.
    // void f(Local<Name> property, PropertyCallbackInfo& info,
    //     AccessorNameGetterCallback callback)
    PROFILING_GETTER_CALL
  };

271 272
  static constexpr int kExternalReferenceCount =
#define COUNT_EXTERNAL_REFERENCE(name, desc) +1
273 274
      EXTERNAL_REFERENCE_LIST(COUNT_EXTERNAL_REFERENCE)
          EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(COUNT_EXTERNAL_REFERENCE);
275 276
#undef COUNT_EXTERNAL_REFERENCE

277
  typedef Address ExternalReferenceRedirector(Address original, Type type);
278

279
  ExternalReference() : address_(kNullAddress) {}
280 281 282 283 284 285
  static ExternalReference Create(const SCTableReference& table_ref);
  static ExternalReference Create(StatsCounter* counter);
  static ExternalReference Create(ApiFunction* ptr, Type type);
  static ExternalReference Create(const Runtime::Function* f);
  static ExternalReference Create(IsolateAddressId id, Isolate* isolate);
  static ExternalReference Create(Runtime::FunctionId id);
286
  static V8_EXPORT_PRIVATE ExternalReference Create(Address address);
287 288

  template <typename SubjectChar, typename PatternChar>
289
  static ExternalReference search_string_raw();
290

291
  V8_EXPORT_PRIVATE static ExternalReference FromRawAddress(Address address);
292

293 294
#define DECL_EXTERNAL_REFERENCE(name, desc) \
  V8_EXPORT_PRIVATE static ExternalReference name();
295 296 297
  EXTERNAL_REFERENCE_LIST(DECL_EXTERNAL_REFERENCE)
#undef DECL_EXTERNAL_REFERENCE

298
#define DECL_EXTERNAL_REFERENCE(name, desc) \
299
  static V8_EXPORT_PRIVATE ExternalReference name(Isolate* isolate);
300
  EXTERNAL_REFERENCE_LIST_WITH_ISOLATE(DECL_EXTERNAL_REFERENCE)
301
#undef DECL_EXTERNAL_REFERENCE
302

303 304
  V8_EXPORT_PRIVATE V8_NOINLINE static ExternalReference
  runtime_function_table_address_for_unittests(Isolate* isolate);
305

306
  Address address() const { return address_; }
307 308

 private:
309 310
  explicit ExternalReference(Address address) : address_(address) {}

311 312
  explicit ExternalReference(void* address)
      : 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 322 323 324 325 326 327

V8_EXPORT_PRIVATE bool operator==(ExternalReference, ExternalReference);
bool operator!=(ExternalReference, ExternalReference);

size_t hash_value(ExternalReference);

V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ExternalReference);

328 329
void abort_with_reason(int reason);

330 331 332 333
}  // namespace internal
}  // namespace v8

#endif  // V8_EXTERNAL_REFERENCE_H_