Line data Source code
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 : #include "src/external-reference.h"
6 :
7 : #include "src/api.h"
8 : #include "src/base/ieee754.h"
9 : #include "src/compiler/code-assembler.h"
10 : #include "src/counters.h"
11 : #include "src/cpu-features.h"
12 : #include "src/date.h"
13 : #include "src/debug/debug.h"
14 : #include "src/deoptimizer.h"
15 : #include "src/elements.h"
16 : #include "src/hash-seed-inl.h"
17 : #include "src/heap/heap.h"
18 : // For IncrementalMarking::RecordWriteFromCode. TODO(jkummerow): Drop.
19 : #include "src/heap/heap-inl.h"
20 : #include "src/ic/stub-cache.h"
21 : #include "src/interpreter/interpreter.h"
22 : #include "src/isolate.h"
23 : #include "src/log.h"
24 : #include "src/math-random.h"
25 : #include "src/microtask-queue.h"
26 : #include "src/objects-inl.h"
27 : #include "src/regexp/regexp-stack.h"
28 : #include "src/simulator-base.h"
29 : #include "src/string-search.h"
30 : #include "src/wasm/wasm-external-refs.h"
31 :
32 : // Include native regexp-macro-assembler.
33 : #if V8_TARGET_ARCH_IA32
34 : #include "src/regexp/ia32/regexp-macro-assembler-ia32.h" // NOLINT
35 : #elif V8_TARGET_ARCH_X64
36 : #include "src/regexp/x64/regexp-macro-assembler-x64.h" // NOLINT
37 : #elif V8_TARGET_ARCH_ARM64
38 : #include "src/regexp/arm64/regexp-macro-assembler-arm64.h" // NOLINT
39 : #elif V8_TARGET_ARCH_ARM
40 : #include "src/regexp/arm/regexp-macro-assembler-arm.h" // NOLINT
41 : #elif V8_TARGET_ARCH_PPC
42 : #include "src/regexp/ppc/regexp-macro-assembler-ppc.h" // NOLINT
43 : #elif V8_TARGET_ARCH_MIPS
44 : #include "src/regexp/mips/regexp-macro-assembler-mips.h" // NOLINT
45 : #elif V8_TARGET_ARCH_MIPS64
46 : #include "src/regexp/mips64/regexp-macro-assembler-mips64.h" // NOLINT
47 : #elif V8_TARGET_ARCH_S390
48 : #include "src/regexp/s390/regexp-macro-assembler-s390.h" // NOLINT
49 : #else // Unknown architecture.
50 : #error "Unknown architecture."
51 : #endif // Target architecture.
52 :
53 : #ifdef V8_INTL_SUPPORT
54 : #include "src/objects/intl-objects.h"
55 : #endif // V8_INTL_SUPPORT
56 :
57 : namespace v8 {
58 : namespace internal {
59 :
60 : // -----------------------------------------------------------------------------
61 : // Common double constants.
62 :
63 : constexpr double double_min_int_constant = kMinInt;
64 : constexpr double double_one_half_constant = 0.5;
65 : constexpr uint64_t double_the_hole_nan_constant = kHoleNanInt64;
66 : constexpr double double_uint32_bias_constant =
67 : static_cast<double>(kMaxUInt32) + 1;
68 :
69 : constexpr struct alignas(16) {
70 : uint32_t a;
71 : uint32_t b;
72 : uint32_t c;
73 : uint32_t d;
74 : } float_absolute_constant = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
75 :
76 : constexpr struct alignas(16) {
77 : uint32_t a;
78 : uint32_t b;
79 : uint32_t c;
80 : uint32_t d;
81 : } float_negate_constant = {0x80000000, 0x80000000, 0x80000000, 0x80000000};
82 :
83 : constexpr struct alignas(16) {
84 : uint64_t a;
85 : uint64_t b;
86 : } double_absolute_constant = {uint64_t{0x7FFFFFFFFFFFFFFF},
87 : uint64_t{0x7FFFFFFFFFFFFFFF}};
88 :
89 : constexpr struct alignas(16) {
90 : uint64_t a;
91 : uint64_t b;
92 : } double_negate_constant = {uint64_t{0x8000000000000000},
93 : uint64_t{0x8000000000000000}};
94 :
95 : // Implementation of ExternalReference
96 :
97 28804154 : static ExternalReference::Type BuiltinCallTypeForResultSize(int result_size) {
98 28804154 : switch (result_size) {
99 : case 1:
100 : return ExternalReference::BUILTIN_CALL;
101 : case 2:
102 124212 : return ExternalReference::BUILTIN_CALL_PAIR;
103 : }
104 0 : UNREACHABLE();
105 : }
106 :
107 : // static
108 3494921 : ExternalReference ExternalReference::Create(
109 : ApiFunction* fun, Type type = ExternalReference::BUILTIN_CALL) {
110 3494921 : return ExternalReference(Redirect(fun->address(), type));
111 : }
112 :
113 : // static
114 28802078 : ExternalReference ExternalReference::Create(Runtime::FunctionId id) {
115 57604189 : return Create(Runtime::FunctionForId(id));
116 : }
117 :
118 : // static
119 2064 : ExternalReference ExternalReference::Create(const Runtime::Function* f) {
120 : return ExternalReference(
121 28804156 : Redirect(f->entry, BuiltinCallTypeForResultSize(f->result_size)));
122 : }
123 :
124 : // static
125 16866984 : ExternalReference ExternalReference::Create(Address address) {
126 16866984 : return ExternalReference(Redirect(address));
127 : }
128 :
129 237435 : ExternalReference ExternalReference::isolate_address(Isolate* isolate) {
130 237435 : return ExternalReference(isolate);
131 : }
132 :
133 63412 : ExternalReference ExternalReference::builtins_address(Isolate* isolate) {
134 63412 : return ExternalReference(isolate->heap()->builtin_address(0));
135 : }
136 :
137 61720 : ExternalReference ExternalReference::handle_scope_implementer_address(
138 : Isolate* isolate) {
139 61720 : return ExternalReference(isolate->handle_scope_implementer_address());
140 : }
141 :
142 62729 : ExternalReference ExternalReference::interpreter_dispatch_table_address(
143 62729 : Isolate* isolate) {
144 62729 : return ExternalReference(isolate->interpreter()->dispatch_table_address());
145 : }
146 :
147 61049 : ExternalReference ExternalReference::interpreter_dispatch_counters(
148 61049 : Isolate* isolate) {
149 : return ExternalReference(
150 61049 : isolate->interpreter()->bytecode_dispatch_counters_table());
151 : }
152 :
153 : ExternalReference
154 61161 : ExternalReference::address_of_interpreter_entry_trampoline_instruction_start(
155 61161 : Isolate* isolate) {
156 : return ExternalReference(
157 : isolate->interpreter()
158 61161 : ->address_of_interpreter_entry_trampoline_instruction_start());
159 : }
160 :
161 61161 : ExternalReference ExternalReference::bytecode_size_table_address() {
162 : return ExternalReference(
163 61161 : interpreter::Bytecodes::bytecode_size_table_address());
164 : }
165 :
166 : // static
167 0 : ExternalReference ExternalReference::Create(StatsCounter* counter) {
168 : return ExternalReference(
169 0 : reinterpret_cast<Address>(counter->GetInternalPointer()));
170 : }
171 :
172 : // static
173 51321 : ExternalReference ExternalReference::Create(IsolateAddressId id,
174 : Isolate* isolate) {
175 51321 : return ExternalReference(isolate->get_address_from_id(id));
176 : }
177 :
178 : // static
179 568 : ExternalReference ExternalReference::Create(const SCTableReference& table_ref) {
180 568 : return ExternalReference(table_ref.address());
181 : }
182 :
183 : namespace {
184 :
185 : // Helper function to verify that all types in a list of types are scalar.
186 : // This includes primitive types (int, Address) and pointer types. We also
187 : // allow void.
188 : template <typename T>
189 : constexpr bool AllScalar() {
190 : return std::is_scalar<T>::value || std::is_void<T>::value;
191 : }
192 :
193 : template <typename T1, typename T2, typename... Rest>
194 : constexpr bool AllScalar() {
195 : return AllScalar<T1>() && AllScalar<T2, Rest...>();
196 : }
197 :
198 : // Checks a function pointer's type for compatibility with the
199 : // ExternalReference calling mechanism. Specifically, all arguments
200 : // as well as the result type must pass the AllScalar check above,
201 : // because we expect each item to fit into one register or stack slot.
202 : template <typename T>
203 : struct IsValidExternalReferenceType;
204 :
205 : template <typename Result, typename... Args>
206 : struct IsValidExternalReferenceType<Result (*)(Args...)> {
207 : static const bool value = AllScalar<Result, Args...>();
208 : };
209 :
210 : template <typename Result, typename Class, typename... Args>
211 : struct IsValidExternalReferenceType<Result (Class::*)(Args...)> {
212 : static const bool value = AllScalar<Result, Args...>();
213 : };
214 :
215 : } // namespace
216 :
217 : #define FUNCTION_REFERENCE(Name, Target) \
218 : ExternalReference ExternalReference::Name() { \
219 : STATIC_ASSERT(IsValidExternalReferenceType<decltype(&Target)>::value); \
220 : return ExternalReference(Redirect(FUNCTION_ADDR(Target))); \
221 : }
222 :
223 : #define FUNCTION_REFERENCE_WITH_ISOLATE(Name, Target) \
224 : ExternalReference ExternalReference::Name(Isolate* isolate) { \
225 : STATIC_ASSERT(IsValidExternalReferenceType<decltype(&Target)>::value); \
226 : return ExternalReference(Redirect(FUNCTION_ADDR(Target))); \
227 : }
228 :
229 : #define FUNCTION_REFERENCE_WITH_TYPE(Name, Target, Type) \
230 : ExternalReference ExternalReference::Name() { \
231 : STATIC_ASSERT(IsValidExternalReferenceType<decltype(&Target)>::value); \
232 : return ExternalReference(Redirect(FUNCTION_ADDR(Target), Type)); \
233 : }
234 :
235 61105 : FUNCTION_REFERENCE(incremental_marking_record_write_function,
236 : IncrementalMarking::RecordWriteFromCode)
237 :
238 61161 : ExternalReference ExternalReference::store_buffer_overflow_function() {
239 : return ExternalReference(
240 61161 : Redirect(Heap::store_buffer_overflow_function_address()));
241 : }
242 :
243 61161 : FUNCTION_REFERENCE(delete_handle_scope_extensions,
244 : HandleScope::DeleteExtensions)
245 :
246 62001 : FUNCTION_REFERENCE(get_date_field_function, JSDate::GetField)
247 :
248 61441 : ExternalReference ExternalReference::date_cache_stamp(Isolate* isolate) {
249 122882 : return ExternalReference(isolate->date_cache()->stamp_address());
250 : }
251 :
252 : // static
253 : ExternalReference
254 6 : ExternalReference::runtime_function_table_address_for_unittests(
255 : Isolate* isolate) {
256 6 : return runtime_function_table_address(isolate);
257 : }
258 :
259 : // static
260 0 : Address ExternalReference::Redirect(Address address, Type type) {
261 : #ifdef USE_SIMULATOR
262 : return SimulatorBase::RedirectExternalReference(address, type);
263 : #else
264 0 : return address;
265 : #endif
266 : }
267 :
268 61337 : ExternalReference ExternalReference::stress_deopt_count(Isolate* isolate) {
269 122674 : return ExternalReference(isolate->stress_deopt_count_address());
270 : }
271 :
272 61049 : ExternalReference ExternalReference::force_slow_path(Isolate* isolate) {
273 122098 : return ExternalReference(isolate->force_slow_path_address());
274 : }
275 :
276 104978 : FUNCTION_REFERENCE(new_deoptimizer_function, Deoptimizer::New)
277 :
278 104978 : FUNCTION_REFERENCE(compute_output_frames_function,
279 : Deoptimizer::ComputeOutputFrames)
280 :
281 61053 : FUNCTION_REFERENCE(wasm_f32_trunc, wasm::f32_trunc_wrapper)
282 61053 : FUNCTION_REFERENCE(wasm_f32_floor, wasm::f32_floor_wrapper)
283 61053 : FUNCTION_REFERENCE(wasm_f32_ceil, wasm::f32_ceil_wrapper)
284 61053 : FUNCTION_REFERENCE(wasm_f32_nearest_int, wasm::f32_nearest_int_wrapper)
285 61053 : FUNCTION_REFERENCE(wasm_f64_trunc, wasm::f64_trunc_wrapper)
286 61053 : FUNCTION_REFERENCE(wasm_f64_floor, wasm::f64_floor_wrapper)
287 61053 : FUNCTION_REFERENCE(wasm_f64_ceil, wasm::f64_ceil_wrapper)
288 61053 : FUNCTION_REFERENCE(wasm_f64_nearest_int, wasm::f64_nearest_int_wrapper)
289 61053 : FUNCTION_REFERENCE(wasm_int64_to_float32, wasm::int64_to_float32_wrapper)
290 61053 : FUNCTION_REFERENCE(wasm_uint64_to_float32, wasm::uint64_to_float32_wrapper)
291 61053 : FUNCTION_REFERENCE(wasm_int64_to_float64, wasm::int64_to_float64_wrapper)
292 61053 : FUNCTION_REFERENCE(wasm_uint64_to_float64, wasm::uint64_to_float64_wrapper)
293 61053 : FUNCTION_REFERENCE(wasm_float32_to_int64, wasm::float32_to_int64_wrapper)
294 61053 : FUNCTION_REFERENCE(wasm_float32_to_uint64, wasm::float32_to_uint64_wrapper)
295 61053 : FUNCTION_REFERENCE(wasm_float64_to_int64, wasm::float64_to_int64_wrapper)
296 61053 : FUNCTION_REFERENCE(wasm_float64_to_uint64, wasm::float64_to_uint64_wrapper)
297 61053 : FUNCTION_REFERENCE(wasm_int64_div, wasm::int64_div_wrapper)
298 61053 : FUNCTION_REFERENCE(wasm_int64_mod, wasm::int64_mod_wrapper)
299 61053 : FUNCTION_REFERENCE(wasm_uint64_div, wasm::uint64_div_wrapper)
300 61053 : FUNCTION_REFERENCE(wasm_uint64_mod, wasm::uint64_mod_wrapper)
301 61053 : FUNCTION_REFERENCE(wasm_word32_ctz, wasm::word32_ctz_wrapper)
302 61053 : FUNCTION_REFERENCE(wasm_word64_ctz, wasm::word64_ctz_wrapper)
303 61053 : FUNCTION_REFERENCE(wasm_word32_popcnt, wasm::word32_popcnt_wrapper)
304 61052 : FUNCTION_REFERENCE(wasm_word64_popcnt, wasm::word64_popcnt_wrapper)
305 74533 : FUNCTION_REFERENCE(wasm_word32_rol, wasm::word32_rol_wrapper)
306 74517 : FUNCTION_REFERENCE(wasm_word32_ror, wasm::word32_ror_wrapper)
307 61112 : FUNCTION_REFERENCE(wasm_memory_copy, wasm::memory_copy_wrapper)
308 61072 : FUNCTION_REFERENCE(wasm_memory_fill, wasm::memory_fill_wrapper)
309 :
310 4328 : static void f64_acos_wrapper(Address data) {
311 : double input = ReadUnalignedValue<double>(data);
312 4328 : WriteUnalignedValue(data, base::ieee754::acos(input));
313 4328 : }
314 :
315 61070 : FUNCTION_REFERENCE(f64_acos_wrapper_function, f64_acos_wrapper)
316 :
317 4328 : static void f64_asin_wrapper(Address data) {
318 : double input = ReadUnalignedValue<double>(data);
319 4328 : WriteUnalignedValue<double>(data, base::ieee754::asin(input));
320 4328 : }
321 :
322 61070 : FUNCTION_REFERENCE(f64_asin_wrapper_function, f64_asin_wrapper)
323 :
324 61062 : FUNCTION_REFERENCE(wasm_float64_pow, wasm::float64_pow_wrapper)
325 :
326 32 : static void f64_mod_wrapper(Address data) {
327 : double dividend = ReadUnalignedValue<double>(data);
328 32 : double divisor = ReadUnalignedValue<double>(data + sizeof(dividend));
329 : WriteUnalignedValue<double>(data, Modulo(dividend, divisor));
330 32 : }
331 :
332 61069 : FUNCTION_REFERENCE(f64_mod_wrapper_function, f64_mod_wrapper)
333 :
334 431865 : FUNCTION_REFERENCE(wasm_call_trap_callback_for_testing,
335 : wasm::call_trap_callback_for_testing)
336 :
337 61049 : FUNCTION_REFERENCE(log_enter_external_function, Logger::EnterExternal)
338 61049 : FUNCTION_REFERENCE(log_leave_external_function, Logger::LeaveExternal)
339 :
340 949877 : ExternalReference ExternalReference::isolate_root(Isolate* isolate) {
341 949877 : return ExternalReference(isolate->isolate_root());
342 : }
343 :
344 61441 : ExternalReference ExternalReference::allocation_sites_list_address(
345 : Isolate* isolate) {
346 61441 : return ExternalReference(isolate->heap()->allocation_sites_list_address());
347 : }
348 :
349 1443374 : ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
350 1443374 : return ExternalReference(isolate->stack_guard()->address_of_jslimit());
351 : }
352 :
353 61049 : ExternalReference ExternalReference::address_of_real_stack_limit(
354 : Isolate* isolate) {
355 61049 : return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
356 : }
357 :
358 61161 : ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) {
359 122322 : return ExternalReference(isolate->heap()->store_buffer_top_address());
360 : }
361 :
362 61105 : ExternalReference ExternalReference::heap_is_marking_flag_address(
363 : Isolate* isolate) {
364 122210 : return ExternalReference(isolate->heap()->IsMarkingFlagAddress());
365 : }
366 :
367 307436 : ExternalReference ExternalReference::new_space_allocation_top_address(
368 : Isolate* isolate) {
369 614872 : return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
370 : }
371 :
372 296884 : ExternalReference ExternalReference::new_space_allocation_limit_address(
373 : Isolate* isolate) {
374 593768 : return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
375 : }
376 :
377 61644 : ExternalReference ExternalReference::old_space_allocation_top_address(
378 : Isolate* isolate) {
379 123288 : return ExternalReference(isolate->heap()->OldSpaceAllocationTopAddress());
380 : }
381 :
382 61644 : ExternalReference ExternalReference::old_space_allocation_limit_address(
383 : Isolate* isolate) {
384 123288 : return ExternalReference(isolate->heap()->OldSpaceAllocationLimitAddress());
385 : }
386 :
387 61160 : ExternalReference ExternalReference::handle_scope_level_address(
388 : Isolate* isolate) {
389 61160 : return ExternalReference(HandleScope::current_level_address(isolate));
390 : }
391 :
392 61161 : ExternalReference ExternalReference::handle_scope_next_address(
393 : Isolate* isolate) {
394 61161 : return ExternalReference(HandleScope::current_next_address(isolate));
395 : }
396 :
397 61161 : ExternalReference ExternalReference::handle_scope_limit_address(
398 : Isolate* isolate) {
399 61161 : return ExternalReference(HandleScope::current_limit_address(isolate));
400 : }
401 :
402 61161 : ExternalReference ExternalReference::scheduled_exception_address(
403 : Isolate* isolate) {
404 122322 : return ExternalReference(isolate->scheduled_exception_address());
405 : }
406 :
407 120091 : ExternalReference ExternalReference::address_of_pending_message_obj(
408 : Isolate* isolate) {
409 120091 : return ExternalReference(isolate->pending_message_obj_address());
410 : }
411 :
412 61059 : FUNCTION_REFERENCE(abort_with_reason, i::abort_with_reason)
413 :
414 : ExternalReference
415 61385 : ExternalReference::address_of_harmony_await_optimization_flag() {
416 61385 : return ExternalReference(&FLAG_harmony_await_optimization);
417 : }
418 :
419 61069 : ExternalReference ExternalReference::address_of_min_int() {
420 61069 : return ExternalReference(reinterpret_cast<Address>(&double_min_int_constant));
421 : }
422 :
423 63625 : ExternalReference ExternalReference::address_of_runtime_stats_flag() {
424 63625 : return ExternalReference(&FLAG_runtime_stats);
425 : }
426 :
427 61069 : ExternalReference ExternalReference::address_of_one_half() {
428 : return ExternalReference(
429 61069 : reinterpret_cast<Address>(&double_one_half_constant));
430 : }
431 :
432 61054 : ExternalReference ExternalReference::address_of_the_hole_nan() {
433 : return ExternalReference(
434 61054 : reinterpret_cast<Address>(&double_the_hole_nan_constant));
435 : }
436 :
437 61049 : ExternalReference ExternalReference::address_of_uint32_bias() {
438 : return ExternalReference(
439 61049 : reinterpret_cast<Address>(&double_uint32_bias_constant));
440 : }
441 :
442 61054 : ExternalReference ExternalReference::address_of_float_abs_constant() {
443 61054 : return ExternalReference(reinterpret_cast<Address>(&float_absolute_constant));
444 : }
445 :
446 61054 : ExternalReference ExternalReference::address_of_float_neg_constant() {
447 61054 : return ExternalReference(reinterpret_cast<Address>(&float_negate_constant));
448 : }
449 :
450 61054 : ExternalReference ExternalReference::address_of_double_abs_constant() {
451 : return ExternalReference(
452 61054 : reinterpret_cast<Address>(&double_absolute_constant));
453 : }
454 :
455 61054 : ExternalReference ExternalReference::address_of_double_neg_constant() {
456 61054 : return ExternalReference(reinterpret_cast<Address>(&double_negate_constant));
457 : }
458 :
459 61161 : ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) {
460 122322 : return ExternalReference(isolate->is_profiling_address());
461 : }
462 :
463 61105 : ExternalReference ExternalReference::invoke_function_callback() {
464 61105 : Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
465 : ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
466 : ApiFunction thunk_fun(thunk_address);
467 61105 : return ExternalReference::Create(&thunk_fun, thunk_type);
468 : }
469 :
470 61105 : ExternalReference ExternalReference::invoke_accessor_getter_callback() {
471 61105 : Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
472 : ExternalReference::Type thunk_type = ExternalReference::PROFILING_GETTER_CALL;
473 : ApiFunction thunk_fun(thunk_address);
474 61105 : return ExternalReference::Create(&thunk_fun, thunk_type);
475 : }
476 :
477 : #if V8_TARGET_ARCH_X64
478 : #define re_stack_check_func RegExpMacroAssemblerX64::CheckStackGuardState
479 : #elif V8_TARGET_ARCH_IA32
480 : #define re_stack_check_func RegExpMacroAssemblerIA32::CheckStackGuardState
481 : #elif V8_TARGET_ARCH_ARM64
482 : #define re_stack_check_func RegExpMacroAssemblerARM64::CheckStackGuardState
483 : #elif V8_TARGET_ARCH_ARM
484 : #define re_stack_check_func RegExpMacroAssemblerARM::CheckStackGuardState
485 : #elif V8_TARGET_ARCH_PPC
486 : #define re_stack_check_func RegExpMacroAssemblerPPC::CheckStackGuardState
487 : #elif V8_TARGET_ARCH_MIPS
488 : #define re_stack_check_func RegExpMacroAssemblerMIPS::CheckStackGuardState
489 : #elif V8_TARGET_ARCH_MIPS64
490 : #define re_stack_check_func RegExpMacroAssemblerMIPS::CheckStackGuardState
491 : #elif V8_TARGET_ARCH_S390
492 : #define re_stack_check_func RegExpMacroAssemblerS390::CheckStackGuardState
493 : #else
494 : UNREACHABLE();
495 : #endif
496 :
497 225081 : FUNCTION_REFERENCE_WITH_ISOLATE(re_check_stack_guard_state, re_stack_check_func)
498 : #undef re_stack_check_func
499 :
500 143055 : FUNCTION_REFERENCE_WITH_ISOLATE(re_grow_stack,
501 : NativeRegExpMacroAssembler::GrowStack)
502 :
503 61246 : FUNCTION_REFERENCE_WITH_ISOLATE(
504 : re_case_insensitive_compare_uc16,
505 : NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)
506 :
507 63073 : ExternalReference ExternalReference::re_word_character_map(Isolate* isolate) {
508 : return ExternalReference(
509 63073 : NativeRegExpMacroAssembler::word_character_map_address());
510 : }
511 :
512 61609 : ExternalReference ExternalReference::address_of_static_offsets_vector(
513 : Isolate* isolate) {
514 : return ExternalReference(
515 61609 : reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector()));
516 : }
517 :
518 586546 : ExternalReference ExternalReference::address_of_regexp_stack_limit(
519 586546 : Isolate* isolate) {
520 1173092 : return ExternalReference(isolate->regexp_stack()->limit_address());
521 : }
522 :
523 61609 : ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
524 61609 : Isolate* isolate) {
525 61609 : return ExternalReference(isolate->regexp_stack()->memory_address());
526 : }
527 :
528 61609 : ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
529 61609 : Isolate* isolate) {
530 61609 : return ExternalReference(isolate->regexp_stack()->memory_size_address());
531 : }
532 :
533 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_acos_function, base::ieee754::acos,
534 : BUILTIN_FP_CALL)
535 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_acosh_function, base::ieee754::acosh,
536 : BUILTIN_FP_FP_CALL)
537 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_asin_function, base::ieee754::asin,
538 : BUILTIN_FP_CALL)
539 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_asinh_function, base::ieee754::asinh,
540 : BUILTIN_FP_FP_CALL)
541 61182 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_atan_function, base::ieee754::atan,
542 : BUILTIN_FP_CALL)
543 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_atanh_function, base::ieee754::atanh,
544 : BUILTIN_FP_FP_CALL)
545 61178 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_atan2_function, base::ieee754::atan2,
546 : BUILTIN_FP_FP_CALL)
547 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_cbrt_function, base::ieee754::cbrt,
548 : BUILTIN_FP_FP_CALL)
549 61314 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_cos_function, base::ieee754::cos,
550 : BUILTIN_FP_CALL)
551 61172 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_cosh_function, base::ieee754::cosh,
552 : BUILTIN_FP_CALL)
553 61197 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_exp_function, base::ieee754::exp,
554 : BUILTIN_FP_CALL)
555 61172 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_expm1_function, base::ieee754::expm1,
556 : BUILTIN_FP_FP_CALL)
557 61333 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_log_function, base::ieee754::log,
558 : BUILTIN_FP_CALL)
559 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_log1p_function, base::ieee754::log1p,
560 : BUILTIN_FP_CALL)
561 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_log10_function, base::ieee754::log10,
562 : BUILTIN_FP_CALL)
563 61165 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_log2_function, base::ieee754::log2,
564 : BUILTIN_FP_CALL)
565 61317 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_sin_function, base::ieee754::sin,
566 : BUILTIN_FP_CALL)
567 61172 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_sinh_function, base::ieee754::sinh,
568 : BUILTIN_FP_CALL)
569 61217 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_tan_function, base::ieee754::tan,
570 : BUILTIN_FP_CALL)
571 61172 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_tanh_function, base::ieee754::tanh,
572 : BUILTIN_FP_CALL)
573 61385 : FUNCTION_REFERENCE_WITH_TYPE(ieee754_pow_function, base::ieee754::pow,
574 : BUILTIN_FP_FP_CALL)
575 :
576 2965570 : void* libc_memchr(void* string, int character, size_t search_length) {
577 2965570 : return memchr(string, character, search_length);
578 : }
579 :
580 61217 : FUNCTION_REFERENCE(libc_memchr_function, libc_memchr)
581 :
582 2254033 : void* libc_memcpy(void* dest, const void* src, size_t n) {
583 2254033 : return memcpy(dest, src, n);
584 : }
585 :
586 65093 : FUNCTION_REFERENCE(libc_memcpy_function, libc_memcpy)
587 :
588 18807 : void* libc_memmove(void* dest, const void* src, size_t n) {
589 18807 : return memmove(dest, src, n);
590 : }
591 :
592 61553 : FUNCTION_REFERENCE(libc_memmove_function, libc_memmove)
593 :
594 559241 : void* libc_memset(void* dest, int value, size_t n) {
595 : DCHECK_EQ(static_cast<byte>(value), value);
596 559241 : return memset(dest, value, n);
597 : }
598 :
599 62469 : FUNCTION_REFERENCE(libc_memset_function, libc_memset)
600 :
601 61049 : ExternalReference ExternalReference::printf_function() {
602 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(std::printf)));
603 : }
604 :
605 61105 : FUNCTION_REFERENCE(refill_math_random, MathRandom::RefillCache)
606 :
607 : template <typename SubjectChar, typename PatternChar>
608 244868 : ExternalReference ExternalReference::search_string_raw() {
609 : auto f = SearchStringRaw<SubjectChar, PatternChar>;
610 244868 : return ExternalReference(Redirect(FUNCTION_ADDR(f)));
611 : }
612 :
613 61273 : FUNCTION_REFERENCE(jsarray_array_join_concat_to_sequential_string,
614 : JSArray::ArrayJoinConcatToSequentialString)
615 :
616 61049 : ExternalReference ExternalReference::search_string_raw_one_one() {
617 61049 : return search_string_raw<const uint8_t, const uint8_t>();
618 : }
619 :
620 61049 : ExternalReference ExternalReference::search_string_raw_one_two() {
621 61049 : return search_string_raw<const uint8_t, const uc16>();
622 : }
623 :
624 61049 : ExternalReference ExternalReference::search_string_raw_two_one() {
625 61049 : return search_string_raw<const uc16, const uint8_t>();
626 : }
627 :
628 61049 : ExternalReference ExternalReference::search_string_raw_two_two() {
629 61049 : return search_string_raw<const uc16, const uc16>();
630 : }
631 :
632 62393 : FUNCTION_REFERENCE(orderedhashmap_gethash_raw, OrderedHashMap::GetHash)
633 :
634 18367 : Address GetOrCreateHash(Isolate* isolate, Address raw_key) {
635 : DisallowHeapAllocation no_gc;
636 36734 : return Object(raw_key)->GetOrCreateHash(isolate).ptr();
637 : }
638 :
639 61161 : FUNCTION_REFERENCE(get_or_create_hash_raw, GetOrCreateHash)
640 :
641 12738 : static Address JSReceiverCreateIdentityHash(Isolate* isolate, Address raw_key) {
642 12738 : JSReceiver key = JSReceiver::cast(Object(raw_key));
643 25476 : return JSReceiver::CreateIdentityHash(isolate, key).ptr();
644 : }
645 :
646 61105 : FUNCTION_REFERENCE(jsreceiver_create_identity_hash,
647 : JSReceiverCreateIdentityHash)
648 :
649 42200037 : static uint32_t ComputeSeededIntegerHash(Isolate* isolate, uint32_t key) {
650 : DisallowHeapAllocation no_gc;
651 84400074 : return ComputeSeededHash(key, HashSeed(isolate));
652 : }
653 :
654 62237 : FUNCTION_REFERENCE(compute_integer_hash, ComputeSeededIntegerHash)
655 61105 : FUNCTION_REFERENCE(copy_fast_number_jsarray_elements_to_typed_array,
656 : CopyFastNumberJSArrayElementsToTypedArray)
657 61105 : FUNCTION_REFERENCE(copy_typed_array_elements_to_typed_array,
658 : CopyTypedArrayElementsToTypedArray)
659 61105 : FUNCTION_REFERENCE(copy_typed_array_elements_slice, CopyTypedArrayElementsSlice)
660 61551 : FUNCTION_REFERENCE(try_internalize_string_function,
661 : StringTable::LookupStringIfExists_NoAllocate)
662 :
663 1816500 : static Address LexicographicCompareWrapper(Isolate* isolate, Address smi_x,
664 : Address smi_y) {
665 : Smi x(smi_x);
666 : Smi y(smi_y);
667 1816500 : return Smi::LexicographicCompare(isolate, x, y);
668 : }
669 :
670 61105 : FUNCTION_REFERENCE(smi_lexicographic_compare_function,
671 : LexicographicCompareWrapper)
672 :
673 61049 : FUNCTION_REFERENCE(check_object_type, CheckObjectType)
674 :
675 : #ifdef V8_INTL_SUPPORT
676 :
677 811 : static Address ConvertOneByteToLower(Address raw_src, Address raw_dst) {
678 811 : String src = String::cast(Object(raw_src));
679 811 : String dst = String::cast(Object(raw_dst));
680 1622 : return Intl::ConvertOneByteToLower(src, dst).ptr();
681 : }
682 61105 : FUNCTION_REFERENCE(intl_convert_one_byte_to_lower, ConvertOneByteToLower)
683 :
684 61105 : ExternalReference ExternalReference::intl_to_latin1_lower_table() {
685 61105 : uint8_t* ptr = const_cast<uint8_t*>(Intl::ToLatin1LowerTable());
686 61104 : return ExternalReference(reinterpret_cast<Address>(ptr));
687 : }
688 : #endif // V8_INTL_SUPPORT
689 :
690 : // Explicit instantiations for all combinations of 1- and 2-byte strings.
691 : template ExternalReference
692 : ExternalReference::search_string_raw<const uint8_t, const uint8_t>();
693 : template ExternalReference
694 : ExternalReference::search_string_raw<const uint8_t, const uc16>();
695 : template ExternalReference
696 : ExternalReference::search_string_raw<const uc16, const uint8_t>();
697 : template ExternalReference
698 : ExternalReference::search_string_raw<const uc16, const uc16>();
699 :
700 11632022 : ExternalReference ExternalReference::FromRawAddress(Address address) {
701 11632022 : return ExternalReference(address);
702 : }
703 :
704 61049 : ExternalReference ExternalReference::cpu_features() {
705 : DCHECK(CpuFeatures::initialized_);
706 61049 : return ExternalReference(&CpuFeatures::supported_);
707 : }
708 :
709 61105 : ExternalReference ExternalReference::promise_hook_address(Isolate* isolate) {
710 61105 : return ExternalReference(isolate->promise_hook_address());
711 : }
712 :
713 61273 : ExternalReference ExternalReference::async_event_delegate_address(
714 : Isolate* isolate) {
715 61273 : return ExternalReference(isolate->async_event_delegate_address());
716 : }
717 :
718 : ExternalReference
719 61973 : ExternalReference::promise_hook_or_async_event_delegate_address(
720 : Isolate* isolate) {
721 : return ExternalReference(
722 61973 : isolate->promise_hook_or_async_event_delegate_address());
723 : }
724 :
725 62225 : ExternalReference ExternalReference::
726 : promise_hook_or_debug_is_active_or_async_event_delegate_address(
727 : Isolate* isolate) {
728 : return ExternalReference(
729 : isolate
730 62225 : ->promise_hook_or_debug_is_active_or_async_event_delegate_address());
731 : }
732 :
733 61053 : ExternalReference ExternalReference::debug_execution_mode_address(
734 : Isolate* isolate) {
735 122106 : return ExternalReference(isolate->debug_execution_mode_address());
736 : }
737 :
738 61449 : ExternalReference ExternalReference::debug_is_active_address(Isolate* isolate) {
739 61449 : return ExternalReference(isolate->debug()->is_active_address());
740 : }
741 :
742 61441 : ExternalReference ExternalReference::debug_hook_on_function_call_address(
743 61441 : Isolate* isolate) {
744 61441 : return ExternalReference(isolate->debug()->hook_on_function_call_address());
745 : }
746 :
747 61391 : ExternalReference ExternalReference::runtime_function_table_address(
748 : Isolate* isolate) {
749 : return ExternalReference(
750 122788 : const_cast<Runtime::Function*>(Runtime::RuntimeFunctionTable(isolate)));
751 : }
752 :
753 130867 : static Address InvalidatePrototypeChainsWrapper(Address raw_map) {
754 130867 : Map map = Map::cast(Object(raw_map));
755 261734 : return JSObject::InvalidatePrototypeChains(map).ptr();
756 : }
757 :
758 61553 : FUNCTION_REFERENCE(invalidate_prototype_chains_function,
759 : InvalidatePrototypeChainsWrapper)
760 :
761 0 : double modulo_double_double(double x, double y) { return Modulo(x, y); }
762 :
763 61049 : FUNCTION_REFERENCE_WITH_TYPE(mod_two_doubles_operation, modulo_double_double,
764 : BUILTIN_FP_FP_CALL)
765 :
766 61105 : ExternalReference ExternalReference::debug_suspended_generator_address(
767 61105 : Isolate* isolate) {
768 61105 : return ExternalReference(isolate->debug()->suspended_generator_address());
769 : }
770 :
771 62281 : ExternalReference ExternalReference::debug_restart_fp_address(
772 62281 : Isolate* isolate) {
773 62281 : return ExternalReference(isolate->debug()->restart_fp_address());
774 : }
775 :
776 788243 : ExternalReference ExternalReference::fast_c_call_caller_fp_address(
777 : Isolate* isolate) {
778 : return ExternalReference(
779 1576486 : isolate->isolate_data()->fast_c_call_caller_fp_address());
780 : }
781 :
782 424646 : ExternalReference ExternalReference::fast_c_call_caller_pc_address(
783 : Isolate* isolate) {
784 : return ExternalReference(
785 849292 : isolate->isolate_data()->fast_c_call_caller_pc_address());
786 : }
787 :
788 61723 : ExternalReference ExternalReference::fixed_typed_array_base_data_offset() {
789 : return ExternalReference(reinterpret_cast<void*>(
790 61723 : FixedTypedArrayBase::kDataOffset - kHeapObjectTag));
791 : }
792 :
793 61104 : FUNCTION_REFERENCE(call_enqueue_microtask_function,
794 : MicrotaskQueue::CallEnqueueMicrotask)
795 :
796 0 : static int64_t atomic_pair_load(intptr_t address) {
797 0 : return std::atomic_load(reinterpret_cast<std::atomic<int64_t>*>(address));
798 : }
799 :
800 61049 : ExternalReference ExternalReference::atomic_pair_load_function() {
801 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_load)));
802 : }
803 :
804 0 : static void atomic_pair_store(intptr_t address, int value_low, int value_high) {
805 : int64_t value =
806 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
807 0 : std::atomic_store(reinterpret_cast<std::atomic<int64_t>*>(address), value);
808 0 : }
809 :
810 61049 : ExternalReference ExternalReference::atomic_pair_store_function() {
811 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_store)));
812 : }
813 :
814 0 : static int64_t atomic_pair_add(intptr_t address, int value_low,
815 : int value_high) {
816 : int64_t value =
817 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
818 : return std::atomic_fetch_add(reinterpret_cast<std::atomic<int64_t>*>(address),
819 0 : value);
820 : }
821 :
822 61049 : ExternalReference ExternalReference::atomic_pair_add_function() {
823 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_add)));
824 : }
825 :
826 0 : static int64_t atomic_pair_sub(intptr_t address, int value_low,
827 : int value_high) {
828 : int64_t value =
829 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
830 : return std::atomic_fetch_sub(reinterpret_cast<std::atomic<int64_t>*>(address),
831 0 : value);
832 : }
833 :
834 61049 : ExternalReference ExternalReference::atomic_pair_sub_function() {
835 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_sub)));
836 : }
837 :
838 0 : static int64_t atomic_pair_and(intptr_t address, int value_low,
839 : int value_high) {
840 : int64_t value =
841 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
842 : return std::atomic_fetch_and(reinterpret_cast<std::atomic<int64_t>*>(address),
843 0 : value);
844 : }
845 :
846 61049 : ExternalReference ExternalReference::atomic_pair_and_function() {
847 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_and)));
848 : }
849 :
850 0 : static int64_t atomic_pair_or(intptr_t address, int value_low, int value_high) {
851 : int64_t value =
852 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
853 : return std::atomic_fetch_or(reinterpret_cast<std::atomic<int64_t>*>(address),
854 0 : value);
855 : }
856 :
857 61049 : ExternalReference ExternalReference::atomic_pair_or_function() {
858 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_or)));
859 : }
860 :
861 0 : static int64_t atomic_pair_xor(intptr_t address, int value_low,
862 : int value_high) {
863 : int64_t value =
864 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
865 : return std::atomic_fetch_xor(reinterpret_cast<std::atomic<int64_t>*>(address),
866 0 : value);
867 : }
868 :
869 61049 : ExternalReference ExternalReference::atomic_pair_xor_function() {
870 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_xor)));
871 : }
872 :
873 0 : static int64_t atomic_pair_exchange(intptr_t address, int value_low,
874 : int value_high) {
875 : int64_t value =
876 0 : static_cast<int64_t>(value_high) << 32 | (value_low & 0xFFFFFFFF);
877 : return std::atomic_exchange(reinterpret_cast<std::atomic<int64_t>*>(address),
878 0 : value);
879 : }
880 :
881 61049 : ExternalReference ExternalReference::atomic_pair_exchange_function() {
882 61049 : return ExternalReference(Redirect(FUNCTION_ADDR(atomic_pair_exchange)));
883 : }
884 :
885 0 : static uint64_t atomic_pair_compare_exchange(intptr_t address,
886 : int old_value_low,
887 : int old_value_high,
888 : int new_value_low,
889 : int new_value_high) {
890 0 : uint64_t old_value = static_cast<uint64_t>(old_value_high) << 32 |
891 0 : (old_value_low & 0xFFFFFFFF);
892 0 : uint64_t new_value = static_cast<uint64_t>(new_value_high) << 32 |
893 0 : (new_value_low & 0xFFFFFFFF);
894 : std::atomic_compare_exchange_strong(
895 0 : reinterpret_cast<std::atomic<uint64_t>*>(address), &old_value, new_value);
896 0 : return old_value;
897 : }
898 :
899 61049 : FUNCTION_REFERENCE(atomic_pair_compare_exchange_function,
900 : atomic_pair_compare_exchange)
901 :
902 0 : static int EnterMicrotaskContextWrapper(HandleScopeImplementer* hsi,
903 : Address raw_context) {
904 0 : Context context = Context::cast(Object(raw_context));
905 0 : hsi->EnterMicrotaskContext(context);
906 0 : return 0;
907 : }
908 :
909 61328 : FUNCTION_REFERENCE(call_enter_context_function, EnterMicrotaskContextWrapper)
910 :
911 572428 : bool operator==(ExternalReference lhs, ExternalReference rhs) {
912 572428 : return lhs.address() == rhs.address();
913 : }
914 :
915 0 : bool operator!=(ExternalReference lhs, ExternalReference rhs) {
916 0 : return !(lhs == rhs);
917 : }
918 :
919 2614032 : size_t hash_value(ExternalReference reference) {
920 2614045 : return base::hash<Address>()(reference.address());
921 : }
922 :
923 58 : std::ostream& operator<<(std::ostream& os, ExternalReference reference) {
924 58 : os << reinterpret_cast<const void*>(reference.address());
925 58 : const Runtime::Function* fn = Runtime::FunctionForEntry(reference.address());
926 58 : if (fn) os << "<" << fn->name << ".entry>";
927 58 : return os;
928 : }
929 :
930 0 : void abort_with_reason(int reason) {
931 0 : if (IsValidAbortReason(reason)) {
932 0 : const char* message = GetAbortReason(static_cast<AbortReason>(reason));
933 0 : base::OS::PrintError("abort: %s\n", message);
934 : } else {
935 0 : base::OS::PrintError("abort: <unknown reason: %d>\n", reason);
936 : }
937 0 : base::OS::Abort();
938 : UNREACHABLE();
939 : }
940 :
941 : #undef FUNCTION_REFERENCE
942 : #undef FUNCTION_REFERENCE_WITH_ISOLATE
943 : #undef FUNCTION_REFERENCE_WITH_TYPE
944 :
945 : } // namespace internal
946 178779 : } // namespace v8
|