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