30 #if defined(V8_TARGET_ARCH_IA32)
40 #define __ ACCESS_MASM(masm)
43 void Builtins::Generate_Adaptor(MacroAssembler* masm,
59 int num_extra_args = 0;
62 Register scratch =
ebx;
72 __ add(
eax, Immediate(num_extra_args + 1));
73 __ JumpToExternalReference(ExternalReference(
id, masm->isolate()));
77 static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
85 void Builtins::Generate_InRecompileQueue(MacroAssembler* masm) {
86 GenerateTailCallToSharedCode(masm);
90 void Builtins::Generate_ParallelRecompile(MacroAssembler* masm) {
100 __ CallRuntime(Runtime::kParallelRecompile, 1);
110 GenerateTailCallToSharedCode(masm);
114 static void Generate_JSConstructStubHelper(MacroAssembler* masm,
115 bool is_api_function,
116 bool count_constructions) {
123 ASSERT(!is_api_function || !count_constructions);
127 FrameScope scope(masm, StackFrame::CONSTRUCT);
138 Label rt_call, allocated;
139 if (FLAG_inline_new) {
140 Label undo_allocation;
141 #ifdef ENABLE_DEBUGGER_SUPPORT
142 ExternalReference debug_step_in_fp =
143 ExternalReference::debug_step_in_fp_address(masm->isolate());
144 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0));
153 __ JumpIfSmi(
eax, &rt_call);
167 if (count_constructions) {
180 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
193 __ AllocateInNewSpace(
200 Factory* factory = masm->isolate()->factory();
201 __ mov(
ecx, factory->empty_fixed_array());
209 __ mov(
edx, factory->undefined_value());
210 if (count_constructions) {
216 if (FLAG_debug_code) {
219 "Unexpected number of pre-allocated property fields.");
222 __ mov(
edx, factory->one_pointer_filler_map());
250 __ Assert(
positive,
"Property allocation count failed.");
271 __ mov(
eax, factory->fixed_array_map());
281 __ mov(
edx, factory->undefined_value());
308 __ bind(&undo_allocation);
309 __ UndoAllocationInNewSpace(
ebx);
318 __ CallRuntime(Runtime::kNewObject, 1);
351 if (is_api_function) {
354 masm->isolate()->builtins()->HandleApiCallConstruct();
355 ParameterCount expected(0);
356 __ InvokeCode(code, expected, expected, RelocInfo::CODE_TARGET,
359 ParameterCount actual(
eax);
365 if (!is_api_function && !count_constructions) {
366 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
375 Label use_receiver, exit;
378 __ JumpIfSmi(
eax, &use_receiver);
387 __ bind(&use_receiver);
402 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1);
407 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) {
408 Generate_JSConstructStubHelper(masm,
false,
true);
412 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
413 Generate_JSConstructStubHelper(masm,
false,
false);
417 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
418 Generate_JSConstructStubHelper(masm,
true,
false);
422 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
425 __ Set(
esi, Immediate(0));
447 __ Set(
ecx, Immediate(0));
451 __ push(Operand(
edx, 0));
466 ParameterCount actual(
eax);
479 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
480 Generate_JSEntryTrampolineHelper(masm,
false);
484 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
485 Generate_JSEntryTrampolineHelper(masm,
true);
489 void Builtins::Generate_LazyCompile(MacroAssembler* masm) {
499 __ CallRuntime(Runtime::kLazyCompile, 1);
515 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) {
525 __ CallRuntime(Runtime::kLazyRecompile, 1);
541 static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm,
548 __ CallRuntime(Runtime::kNotifyDeoptimized, 1);
558 Label not_no_registers, not_tos_eax;
563 __ bind(¬_no_registers);
569 __ bind(¬_tos_eax);
570 __ Abort(
"no cases left");
574 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) {
579 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
584 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) {
594 __ CallRuntime(Runtime::kNotifyOSR, 0);
601 void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
602 Factory* factory = masm->isolate()->factory();
609 __ push(Immediate(factory->undefined_value()));
617 Label slow, non_function;
620 __ JumpIfSmi(
edi, &non_function);
626 Label shift_arguments;
627 __ Set(
edx, Immediate(0));
628 { Label convert_to_object, use_global_receiver, patch_receiver;
648 __ JumpIfSmi(
ebx, &convert_to_object);
649 __ cmp(
ebx, factory->null_value());
650 __ j(
equal, &use_global_receiver);
651 __ cmp(
ebx, factory->undefined_value());
652 __ j(
equal, &use_global_receiver);
657 __ bind(&convert_to_object);
667 __ Set(
edx, Immediate(0));
675 __ jmp(&patch_receiver);
679 __ bind(&use_global_receiver);
680 const int kGlobalIndex =
687 __ bind(&patch_receiver);
690 __ jmp(&shift_arguments);
695 __ Set(
edx, Immediate(1));
698 __ bind(&non_function);
699 __ Set(
edx, Immediate(2));
710 __ bind(&shift_arguments);
724 { Label
function, non_proxy;
727 __ Set(
ebx, Immediate(0));
728 __ cmp(
edx, Immediate(1));
736 __ GetBuiltinEntry(
edx, Builtins::CALL_FUNCTION_PROXY);
737 __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
738 RelocInfo::CODE_TARGET);
742 __ GetBuiltinEntry(
edx, Builtins::CALL_NON_FUNCTION);
743 __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
744 RelocInfo::CODE_TARGET);
759 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline());
761 ParameterCount expected(0);
767 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
774 __ push(Operand(
ebp, kFunctionOffset));
775 __ push(Operand(
ebp, kArgumentsOffset));
782 ExternalReference real_stack_limit =
783 ExternalReference::address_of_real_stack_limit(masm->isolate());
784 __ mov(
edi, Operand::StaticVariable(real_stack_limit));
798 __ push(Operand(
ebp, 4 * kPointerSize));
805 const int kLimitOffset =
807 const int kIndexOffset = kLimitOffset - 1 *
kPointerSize;
809 __ push(Immediate(0));
812 __ mov(
ebx, Operand(
ebp, kReceiverOffset));
816 __ mov(
edi, Operand(
ebp, kFunctionOffset));
825 Label call_to_object, use_global_receiver;
831 Factory* factory = masm->isolate()->factory();
841 __ JumpIfSmi(
ebx, &call_to_object);
842 __ cmp(
ebx, factory->null_value());
843 __ j(
equal, &use_global_receiver);
844 __ cmp(
ebx, factory->undefined_value());
845 __ j(
equal, &use_global_receiver);
850 __ bind(&call_to_object);
854 __ jmp(&push_receiver);
857 __ bind(&use_global_receiver);
858 const int kGlobalOffset =
866 __ bind(&push_receiver);
871 __ mov(
ecx, Operand(
ebp, kIndexOffset));
874 __ mov(
edx, Operand(
ebp, kArgumentsOffset));
877 Handle<Code> ic = masm->isolate()->builtins()->KeyedLoadIC_Initialize();
878 __ call(ic, RelocInfo::CODE_TARGET);
888 __ mov(
ecx, Operand(
ebp, kIndexOffset));
890 __ mov(Operand(
ebp, kIndexOffset),
ecx);
893 __ cmp(
ecx, Operand(
ebp, kLimitOffset));
899 ParameterCount actual(
eax);
901 __ mov(
edi, Operand(
ebp, kFunctionOffset));
907 frame_scope.GenerateLeaveFrame();
908 __ ret(3 * kPointerSize);
911 __ bind(&call_proxy);
914 __ Set(
ebx, Immediate(0));
916 __ GetBuiltinEntry(
edx, Builtins::CALL_FUNCTION_PROXY);
917 __ call(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
918 RelocInfo::CODE_TARGET);
922 __ ret(3 * kPointerSize);
930 static void AllocateEmptyJSArray(MacroAssembler* masm,
931 Register array_function,
936 Label* gc_required) {
940 __ LoadInitialArrayMap(array_function, scratch2, scratch1,
false);
945 if (initial_capacity > 0) {
948 __ AllocateInNewSpace(size,
961 Factory* factory = masm->isolate()->factory();
963 factory->empty_fixed_array());
969 if (initial_capacity == 0) {
971 factory->empty_fixed_array());
988 factory->fixed_array_map());
994 static const int kLoopUnfoldLimit = 4;
995 if (initial_capacity <= kLoopUnfoldLimit) {
998 __ mov(scratch3, factory->the_hole_value());
999 for (
int i = 0; i < initial_capacity; i++) {
1006 __ mov(scratch2, Immediate(initial_capacity));
1013 factory->the_hole_value());
1030 static void AllocateJSArray(MacroAssembler* masm,
1031 Register array_function,
1032 Register array_size,
1034 Register elements_array,
1035 Register elements_array_end,
1037 bool fill_with_hole,
1038 Label* gc_required) {
1040 ASSERT(!fill_with_hole || array_size.is(
ecx));
1041 ASSERT(!fill_with_hole || !result.is(
eax));
1043 __ LoadInitialArrayMap(array_function, scratch,
1044 elements_array, fill_with_hole);
1065 Factory* factory = masm->isolate()->factory();
1066 __ mov(elements_array, factory->empty_fixed_array());
1085 factory->fixed_array_map());
1093 if (fill_with_hole) {
1094 __ SmiUntag(array_size);
1095 __ lea(
edi, Operand(elements_array,
1097 __ mov(
eax, factory->the_hole_value());
1101 const int kRepStosThreshold = 16;
1102 Label loop, entry, done;
1103 __ cmp(
ecx, kRepStosThreshold);
1110 __ cmp(
edi, elements_array_end);
1131 static void ArrayNativeCode(MacroAssembler* masm,
1132 bool construct_call,
1133 Label* call_generic_code) {
1134 Label argc_one_or_more, argc_two_or_more, prepare_generic_code_call,
1135 empty_array, not_empty_array, finish, cant_transition_map, not_double;
1140 if (construct_call) {
1151 __ bind(&empty_array);
1153 AllocateEmptyJSArray(masm,
1159 &prepare_generic_code_call);
1160 __ IncrementCounter(masm->isolate()->counters()->array_function_native(), 1);
1162 if (construct_call) {
1165 __ ret(kPointerSize);
1169 __ bind(&argc_one_or_more);
1173 __ mov(
ecx, Operand(
esp, (push_count + 1) * kPointerSize));
1183 for (
int i = push_count; i > 0; i--) {
1184 __ mov(
eax, Operand(
esp, i * kPointerSize));
1185 __ mov(Operand(
esp, (i + 1) * kPointerSize),
eax);
1188 __ push(Immediate(0));
1189 __ jmp(&empty_array);
1191 __ bind(¬_empty_array);
1207 AllocateJSArray(masm,
1215 &prepare_generic_code_call);
1216 Counters* counters = masm->isolate()->counters();
1217 __ IncrementCounter(counters->array_function_native(), 1);
1220 if (construct_call) {
1223 __ ret(2 * kPointerSize);
1226 __ bind(&argc_two_or_more);
1235 AllocateJSArray(masm,
1243 &prepare_generic_code_call);
1244 __ IncrementCounter(counters->array_function_native(), 1);
1246 __ mov(
ebx, Operand(
esp, kPointerSize));
1256 int last_arg_offset = (construct_call ? 4 : 3) * kPointerSize;
1257 __ lea(
edi, Operand(
esp, last_arg_offset));
1263 Label has_non_smi_element;
1278 if (FLAG_smi_only_arrays) {
1279 __ JumpIfNotSmi(
eax, &has_non_smi_element);
1282 __ add(
edx, Immediate(kPointerSize));
1295 __ mov(
ecx, Operand(
esp, last_arg_offset - kPointerSize));
1299 last_arg_offset - kPointerSize));
1302 __ bind(&has_non_smi_element);
1305 masm->isolate()->factory()->heap_number_map(),
1308 __ bind(&cant_transition_map);
1311 __ UndoAllocationInNewSpace(
eax);
1312 __ jmp(&prepare_generic_code_call);
1314 __ bind(¬_double);
1318 __ LoadTransitionedArrayMapConditional(
1323 &cant_transition_map);
1329 __ lea(
edi, Operand(
esp, last_arg_offset));
1336 __ add(
edx, Immediate(kPointerSize));
1342 __ bind(&prepare_generic_code_call);
1344 if (construct_call) {
1347 __ jmp(call_generic_code);
1351 void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
1357 Label generic_array_code;
1362 if (FLAG_debug_code) {
1367 __ Assert(
not_zero,
"Unexpected initial map for InternalArray function");
1369 __ Assert(
equal,
"Unexpected initial map for InternalArray function");
1374 ArrayNativeCode(masm,
false, &generic_array_code);
1378 __ bind(&generic_array_code);
1379 Handle<Code> array_code =
1380 masm->isolate()->builtins()->InternalArrayCodeGeneric();
1381 __ jmp(array_code, RelocInfo::CODE_TARGET);
1385 void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
1391 Label generic_array_code;
1396 if (FLAG_debug_code) {
1401 __ Assert(
not_zero,
"Unexpected initial map for Array function");
1403 __ Assert(
equal,
"Unexpected initial map for Array function");
1407 ArrayNativeCode(masm,
false, &generic_array_code);
1411 __ bind(&generic_array_code);
1412 Handle<Code> array_code =
1413 masm->isolate()->builtins()->ArrayCodeGeneric();
1414 __ jmp(array_code, RelocInfo::CODE_TARGET);
1418 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) {
1425 Label generic_constructor;
1427 if (FLAG_debug_code) {
1435 __ Assert(
not_zero,
"Unexpected initial map for Array function");
1437 __ Assert(
equal,
"Unexpected initial map for Array function");
1441 ArrayNativeCode(masm,
true, &generic_constructor);
1445 __ bind(&generic_constructor);
1446 Handle<Code> generic_construct_stub =
1447 masm->isolate()->builtins()->JSConstructStubGeneric();
1448 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET);
1452 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
1460 Counters* counters = masm->isolate()->counters();
1461 __ IncrementCounter(counters->string_ctor_calls(), 1);
1463 if (FLAG_debug_code) {
1466 __ Assert(
equal,
"Unexpected String function");
1473 __ j(
zero, &no_arguments);
1481 Label not_cached, argument_is_string;
1490 __ IncrementCounter(counters->string_ctor_cached_number(), 1);
1491 __ bind(&argument_is_string);
1508 __ LoadGlobalFunctionInitialMap(
edi,
ecx);
1509 if (FLAG_debug_code) {
1512 __ Assert(
equal,
"Unexpected string wrapper instance size");
1514 __ Assert(
equal,
"Unexpected unused properties of string wrapper");
1519 Factory* factory = masm->isolate()->factory();
1520 __ Set(
ecx, Immediate(factory->empty_fixed_array()));
1535 Label convert_argument;
1536 __ bind(¬_cached);
1538 __ JumpIfSmi(
eax, &convert_argument);
1542 __ IncrementCounter(counters->string_ctor_string_value(), 1);
1543 __ jmp(&argument_is_string);
1546 __ bind(&convert_argument);
1547 __ IncrementCounter(counters->string_ctor_conversions(), 1);
1556 __ jmp(&argument_is_string);
1560 __ bind(&no_arguments);
1561 __ Set(
ebx, Immediate(factory->empty_string()));
1563 __ lea(
esp, Operand(
esp, kPointerSize));
1565 __ jmp(&argument_is_string);
1569 __ bind(&gc_required);
1570 __ IncrementCounter(counters->string_ctor_gc_required(), 1);
1574 __ CallRuntime(Runtime::kNewStringWrapper, 1);
1580 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1599 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
1614 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
1622 Label invoke, dont_adapt_arguments;
1623 __ IncrementCounter(masm->isolate()->counters()->arguments_adaptors(), 1);
1625 Label enough, too_few;
1629 __ j(
equal, &dont_adapt_arguments);
1633 EnterArgumentsAdaptorFrame(masm);
1643 __ push(Operand(
eax, 0));
1644 __ sub(
eax, Immediate(kPointerSize));
1652 EnterArgumentsAdaptorFrame(masm);
1661 __ sub(
eax, Immediate(1));
1666 __ push(Operand(
edi, 0));
1667 __ sub(
edi, Immediate(kPointerSize));
1675 __ push(Immediate(masm->isolate()->factory()->undefined_value()));
1687 masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset());
1690 LeaveArgumentsAdaptorFrame(masm);
1696 __ bind(&dont_adapt_arguments);
1701 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1702 CpuFeatures::TryForceFeatureScope scope(
SSE2);
1704 __ Abort(
"Unreachable code: Cannot optimize without SSE2 support.");
1712 if (FLAG_debug_code) {
1714 __ Assert(
equal,
"test eax instruction not found after loop stack check");
1733 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
1746 __ bind(&stack_check);
1748 ExternalReference stack_limit =
1749 ExternalReference::address_of_stack_limit(masm->isolate());
1750 __ cmp(
esp, Operand::StaticVariable(stack_limit));
1752 StackCheckStub stub;
1753 __ TailCallStub(&stub);
1754 if (FLAG_debug_code) {
1755 __ Abort(
"Unreachable code: returned from tail call.");
1776 #endif // V8_TARGET_ARCH_IA32
static const int kLengthOffset
const intptr_t kSmiTagMask
static const int kCodeOffset
static const int kCodeEntryOffset
static const int kPrototypeOrInitialMapOffset
static const int kAllowOSRAtLoopNestingLevelOffset
static Smi * FromInt(int value)
const intptr_t kIntptrSignBit
static const int kGlobalReceiverOffset
static const int kConstructionCountOffset
static const int kNativeByteOffset
static bool IsSupported(CpuFeature f)
static const int kStrictModeBitWithinByte
static const int kCallerSPOffset
#define ASSERT(condition)
const int kPointerSizeLog2
static const int kInstanceSizeOffset
static const int kUnusedPropertyFieldsOffset
static const byte kTestAlByte
static const int kContextOffset
STATIC_ASSERT((FixedDoubleArray::kHeaderSize &kDoubleAlignmentMask)==0)
static const int kDontAdaptArgumentsSentinel
Operand FieldOperand(Register object, int offset)
static const int kExpressionsOffset
static const int kPropertiesOffset
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random generator(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer
static const int kInObjectPropertiesOffset
static const int kElementsOffset
static const int kNativeBitWithinByte
static const int kArgcOffset
static const int kFunctionArgOffset
static const int kLengthOffset
static int SizeFor(int length)
static const int kHeaderSize
static const int kMapOffset
static const int kLengthOffset
static const int kContextOffset
static const int kFunctionOffset
static const int kReceiverArgOffset
static const int kFormalParameterCountOffset
static const int kStrictModeByteOffset
static const int kHeaderSize
Condition NegateCondition(Condition cond)
static const int kArgvOffset
static const int kHeaderSize
static void GenerateLookupNumberStringCache(MacroAssembler *masm, Register object, Register result, Register scratch1, Register scratch2, Register scratch3, bool object_is_smi, Label *not_found)
static const int kPreallocatedArrayElements
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
static const int kValueOffset
static const int kNativeContextOffset
static const int kSharedFunctionInfoOffset
static const int kInitialMaxFastElementArray
static const int kPreAllocatedPropertyFieldsOffset