| Index: src/x64/builtins-x64.cc
|
| diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc
|
| index 2a01b0b24cdc4589a4b105be307a7ca73ba624bb..89ae74d7e7717d8a6dd576029a22301e59dbabc1 100644
|
| --- a/src/x64/builtins-x64.cc
|
| +++ b/src/x64/builtins-x64.cc
|
| @@ -1093,366 +1093,6 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
|
| }
|
|
|
|
|
| -// Allocate an empty JSArray. The allocated array is put into the result
|
| -// register. If the parameter initial_capacity is larger than zero an elements
|
| -// backing store is allocated with this size and filled with the hole values.
|
| -// Otherwise the elements backing store is set to the empty FixedArray.
|
| -static void AllocateEmptyJSArray(MacroAssembler* masm,
|
| - Register array_function,
|
| - Register result,
|
| - Register scratch1,
|
| - Register scratch2,
|
| - Register scratch3,
|
| - Label* gc_required) {
|
| - const int initial_capacity = JSArray::kPreallocatedArrayElements;
|
| - STATIC_ASSERT(initial_capacity >= 0);
|
| -
|
| - __ LoadInitialArrayMap(array_function, scratch2, scratch1, false);
|
| -
|
| - // Allocate the JSArray object together with space for a fixed array with the
|
| - // requested elements.
|
| - int size = JSArray::kSize;
|
| - if (initial_capacity > 0) {
|
| - size += FixedArray::SizeFor(initial_capacity);
|
| - }
|
| - __ Allocate(size, result, scratch2, scratch3, gc_required, TAG_OBJECT);
|
| -
|
| - // Allocated the JSArray. Now initialize the fields except for the elements
|
| - // array.
|
| - // result: JSObject
|
| - // scratch1: initial map
|
| - // scratch2: start of next object
|
| - Factory* factory = masm->isolate()->factory();
|
| - __ movq(FieldOperand(result, JSObject::kMapOffset), scratch1);
|
| - __ Move(FieldOperand(result, JSArray::kPropertiesOffset),
|
| - factory->empty_fixed_array());
|
| - // Field JSArray::kElementsOffset is initialized later.
|
| - __ Move(FieldOperand(result, JSArray::kLengthOffset), Smi::FromInt(0));
|
| -
|
| - // If no storage is requested for the elements array just set the empty
|
| - // fixed array.
|
| - if (initial_capacity == 0) {
|
| - __ Move(FieldOperand(result, JSArray::kElementsOffset),
|
| - factory->empty_fixed_array());
|
| - return;
|
| - }
|
| -
|
| - // Calculate the location of the elements array and set elements array member
|
| - // of the JSArray.
|
| - // result: JSObject
|
| - // scratch2: start of next object
|
| - __ lea(scratch1, Operand(result, JSArray::kSize));
|
| - __ movq(FieldOperand(result, JSArray::kElementsOffset), scratch1);
|
| -
|
| - // Initialize the FixedArray and fill it with holes. FixedArray length is
|
| - // stored as a smi.
|
| - // result: JSObject
|
| - // scratch1: elements array
|
| - // scratch2: start of next object
|
| - __ Move(FieldOperand(scratch1, HeapObject::kMapOffset),
|
| - factory->fixed_array_map());
|
| - __ Move(FieldOperand(scratch1, FixedArray::kLengthOffset),
|
| - Smi::FromInt(initial_capacity));
|
| -
|
| - // Fill the FixedArray with the hole value. Inline the code if short.
|
| - // Reconsider loop unfolding if kPreallocatedArrayElements gets changed.
|
| - static const int kLoopUnfoldLimit = 4;
|
| - __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex);
|
| - if (initial_capacity <= kLoopUnfoldLimit) {
|
| - // Use a scratch register here to have only one reloc info when unfolding
|
| - // the loop.
|
| - for (int i = 0; i < initial_capacity; i++) {
|
| - __ movq(FieldOperand(scratch1,
|
| - FixedArray::kHeaderSize + i * kPointerSize),
|
| - scratch3);
|
| - }
|
| - } else {
|
| - Label loop, entry;
|
| - __ movq(scratch2, Immediate(initial_capacity));
|
| - __ jmp(&entry);
|
| - __ bind(&loop);
|
| - __ movq(FieldOperand(scratch1,
|
| - scratch2,
|
| - times_pointer_size,
|
| - FixedArray::kHeaderSize),
|
| - scratch3);
|
| - __ bind(&entry);
|
| - __ decq(scratch2);
|
| - __ j(not_sign, &loop);
|
| - }
|
| -}
|
| -
|
| -
|
| -// Allocate a JSArray with the number of elements stored in a register. The
|
| -// register array_function holds the built-in Array function and the register
|
| -// array_size holds the size of the array as a smi. The allocated array is put
|
| -// into the result register and beginning and end of the FixedArray elements
|
| -// storage is put into registers elements_array and elements_array_end (see
|
| -// below for when that is not the case). If the parameter fill_with_holes is
|
| -// true the allocated elements backing store is filled with the hole values
|
| -// otherwise it is left uninitialized. When the backing store is filled the
|
| -// register elements_array is scratched.
|
| -static void AllocateJSArray(MacroAssembler* masm,
|
| - Register array_function, // Array function.
|
| - Register array_size, // As a smi, cannot be 0.
|
| - Register result,
|
| - Register elements_array,
|
| - Register elements_array_end,
|
| - Register scratch,
|
| - bool fill_with_hole,
|
| - Label* gc_required) {
|
| - __ LoadInitialArrayMap(array_function, scratch,
|
| - elements_array, fill_with_hole);
|
| -
|
| - if (FLAG_debug_code) { // Assert that array size is not zero.
|
| - __ testq(array_size, array_size);
|
| - __ Assert(not_zero, "array size is unexpectedly 0");
|
| - }
|
| -
|
| - // Allocate the JSArray object together with space for a FixedArray with the
|
| - // requested elements.
|
| - SmiIndex index =
|
| - masm->SmiToIndex(kScratchRegister, array_size, kPointerSizeLog2);
|
| - __ Allocate(JSArray::kSize + FixedArray::kHeaderSize,
|
| - index.scale,
|
| - index.reg,
|
| - result,
|
| - elements_array_end,
|
| - scratch,
|
| - gc_required,
|
| - TAG_OBJECT);
|
| -
|
| - // Allocated the JSArray. Now initialize the fields except for the elements
|
| - // array.
|
| - // result: JSObject
|
| - // elements_array: initial map
|
| - // elements_array_end: start of next object
|
| - // array_size: size of array (smi)
|
| - Factory* factory = masm->isolate()->factory();
|
| - __ movq(FieldOperand(result, JSObject::kMapOffset), elements_array);
|
| - __ Move(elements_array, factory->empty_fixed_array());
|
| - __ movq(FieldOperand(result, JSArray::kPropertiesOffset), elements_array);
|
| - // Field JSArray::kElementsOffset is initialized later.
|
| - __ movq(FieldOperand(result, JSArray::kLengthOffset), array_size);
|
| -
|
| - // Calculate the location of the elements array and set elements array member
|
| - // of the JSArray.
|
| - // result: JSObject
|
| - // elements_array_end: start of next object
|
| - // array_size: size of array (smi)
|
| - __ lea(elements_array, Operand(result, JSArray::kSize));
|
| - __ movq(FieldOperand(result, JSArray::kElementsOffset), elements_array);
|
| -
|
| - // Initialize the fixed array. FixedArray length is stored as a smi.
|
| - // result: JSObject
|
| - // elements_array: elements array
|
| - // elements_array_end: start of next object
|
| - // array_size: size of array (smi)
|
| - __ Move(FieldOperand(elements_array, JSObject::kMapOffset),
|
| - factory->fixed_array_map());
|
| - // For non-empty JSArrays the length of the FixedArray and the JSArray is the
|
| - // same.
|
| - __ movq(FieldOperand(elements_array, FixedArray::kLengthOffset), array_size);
|
| -
|
| - // Fill the allocated FixedArray with the hole value if requested.
|
| - // result: JSObject
|
| - // elements_array: elements array
|
| - // elements_array_end: start of next object
|
| - if (fill_with_hole) {
|
| - Label loop, entry;
|
| - __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
|
| - __ lea(elements_array, Operand(elements_array,
|
| - FixedArray::kHeaderSize - kHeapObjectTag));
|
| - __ jmp(&entry);
|
| - __ bind(&loop);
|
| - __ movq(Operand(elements_array, 0), scratch);
|
| - __ addq(elements_array, Immediate(kPointerSize));
|
| - __ bind(&entry);
|
| - __ cmpq(elements_array, elements_array_end);
|
| - __ j(below, &loop);
|
| - }
|
| -}
|
| -
|
| -
|
| -// Create a new array for the built-in Array function. This function allocates
|
| -// the JSArray object and the FixedArray elements array and initializes these.
|
| -// If the Array cannot be constructed in native code the runtime is called. This
|
| -// function assumes the following state:
|
| -// rdi: constructor (built-in Array function)
|
| -// rax: argc
|
| -// rsp[0]: return address
|
| -// rsp[8]: last argument
|
| -// This function is used for both construct and normal calls of Array. The only
|
| -// difference between handling a construct call and a normal call is that for a
|
| -// construct call the constructor function in rdi needs to be preserved for
|
| -// entering the generic code. In both cases argc in rax needs to be preserved.
|
| -// Both registers are preserved by this code so no need to differentiate between
|
| -// a construct call and a normal call.
|
| -void ArrayNativeCode(MacroAssembler* masm, Label* call_generic_code) {
|
| - Label argc_one_or_more, argc_two_or_more, empty_array, not_empty_array,
|
| - has_non_smi_element, finish, cant_transition_map, not_double;
|
| -
|
| - // Check for array construction with zero arguments.
|
| - __ testq(rax, rax);
|
| - __ j(not_zero, &argc_one_or_more);
|
| -
|
| - __ bind(&empty_array);
|
| - // Handle construction of an empty array.
|
| - AllocateEmptyJSArray(masm,
|
| - rdi,
|
| - rbx,
|
| - rcx,
|
| - rdx,
|
| - r8,
|
| - call_generic_code);
|
| - Counters* counters = masm->isolate()->counters();
|
| - __ IncrementCounter(counters->array_function_native(), 1);
|
| - __ movq(rax, rbx);
|
| - __ ret(kPointerSize);
|
| -
|
| - // Check for one argument. Bail out if argument is not smi or if it is
|
| - // negative.
|
| - __ bind(&argc_one_or_more);
|
| - __ cmpq(rax, Immediate(1));
|
| - __ j(not_equal, &argc_two_or_more);
|
| - __ movq(rdx, Operand(rsp, kPointerSize)); // Get the argument from the stack.
|
| -
|
| - __ SmiTest(rdx);
|
| - __ j(not_zero, ¬_empty_array);
|
| - __ pop(r8); // Adjust stack.
|
| - __ Drop(1);
|
| - __ push(r8);
|
| - __ movq(rax, Immediate(0)); // Treat this as a call with argc of zero.
|
| - __ jmp(&empty_array);
|
| -
|
| - __ bind(¬_empty_array);
|
| - __ JumpUnlessNonNegativeSmi(rdx, call_generic_code);
|
| -
|
| - // Handle construction of an empty array of a certain size. Bail out if size
|
| - // is to large to actually allocate an elements array.
|
| - __ SmiCompare(rdx, Smi::FromInt(JSObject::kInitialMaxFastElementArray));
|
| - __ j(greater_equal, call_generic_code);
|
| -
|
| - // rax: argc
|
| - // rdx: array_size (smi)
|
| - // rdi: constructor
|
| - // esp[0]: return address
|
| - // esp[8]: argument
|
| - AllocateJSArray(masm,
|
| - rdi,
|
| - rdx,
|
| - rbx,
|
| - rcx,
|
| - r8,
|
| - r9,
|
| - true,
|
| - call_generic_code);
|
| - __ IncrementCounter(counters->array_function_native(), 1);
|
| - __ movq(rax, rbx);
|
| - __ ret(2 * kPointerSize);
|
| -
|
| - // Handle construction of an array from a list of arguments.
|
| - __ bind(&argc_two_or_more);
|
| - __ movq(rdx, rax);
|
| - __ Integer32ToSmi(rdx, rdx); // Convet argc to a smi.
|
| - // rax: argc
|
| - // rdx: array_size (smi)
|
| - // rdi: constructor
|
| - // esp[0] : return address
|
| - // esp[8] : last argument
|
| - AllocateJSArray(masm,
|
| - rdi,
|
| - rdx,
|
| - rbx,
|
| - rcx,
|
| - r8,
|
| - r9,
|
| - false,
|
| - call_generic_code);
|
| - __ IncrementCounter(counters->array_function_native(), 1);
|
| -
|
| - // rax: argc
|
| - // rbx: JSArray
|
| - // rcx: elements_array
|
| - // r8: elements_array_end (untagged)
|
| - // esp[0]: return address
|
| - // esp[8]: last argument
|
| -
|
| - // Location of the last argument
|
| - __ lea(r9, Operand(rsp, kPointerSize));
|
| -
|
| - // Location of the first array element (Parameter fill_with_holes to
|
| - // AllocateJSArrayis false, so the FixedArray is returned in rcx).
|
| - __ lea(rdx, Operand(rcx, FixedArray::kHeaderSize - kHeapObjectTag));
|
| -
|
| - // rax: argc
|
| - // rbx: JSArray
|
| - // rdx: location of the first array element
|
| - // r9: location of the last argument
|
| - // esp[0]: return address
|
| - // esp[8]: last argument
|
| - Label loop, entry;
|
| - __ movq(rcx, rax);
|
| - __ jmp(&entry);
|
| - __ bind(&loop);
|
| - __ movq(r8, Operand(r9, rcx, times_pointer_size, 0));
|
| - if (FLAG_smi_only_arrays) {
|
| - __ JumpIfNotSmi(r8, &has_non_smi_element);
|
| - }
|
| - __ movq(Operand(rdx, 0), r8);
|
| - __ addq(rdx, Immediate(kPointerSize));
|
| - __ bind(&entry);
|
| - __ decq(rcx);
|
| - __ j(greater_equal, &loop);
|
| -
|
| - // Remove caller arguments from the stack and return.
|
| - // rax: argc
|
| - // rbx: JSArray
|
| - // esp[0]: return address
|
| - // esp[8]: last argument
|
| - __ bind(&finish);
|
| - __ pop(rcx);
|
| - __ lea(rsp, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize));
|
| - __ push(rcx);
|
| - __ movq(rax, rbx);
|
| - __ ret(0);
|
| -
|
| - __ bind(&has_non_smi_element);
|
| - // Double values are handled by the runtime.
|
| - __ CheckMap(r8,
|
| - masm->isolate()->factory()->heap_number_map(),
|
| - ¬_double,
|
| - DONT_DO_SMI_CHECK);
|
| - __ bind(&cant_transition_map);
|
| - __ UndoAllocationInNewSpace(rbx);
|
| - __ jmp(call_generic_code);
|
| -
|
| - __ bind(¬_double);
|
| - // Transition FAST_SMI_ELEMENTS to FAST_ELEMENTS.
|
| - // rbx: JSArray
|
| - __ movq(r11, FieldOperand(rbx, HeapObject::kMapOffset));
|
| - __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
|
| - FAST_ELEMENTS,
|
| - r11,
|
| - kScratchRegister,
|
| - &cant_transition_map);
|
| -
|
| - __ movq(FieldOperand(rbx, HeapObject::kMapOffset), r11);
|
| - __ RecordWriteField(rbx, HeapObject::kMapOffset, r11, r8,
|
| - kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
| -
|
| - // Finish the array initialization loop.
|
| - Label loop2;
|
| - __ bind(&loop2);
|
| - __ movq(r8, Operand(r9, rcx, times_pointer_size, 0));
|
| - __ movq(Operand(rdx, 0), r8);
|
| - __ addq(rdx, Immediate(kPointerSize));
|
| - __ decq(rcx);
|
| - __ j(greater_equal, &loop2);
|
| - __ jmp(&finish);
|
| -}
|
| -
|
| -
|
| void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
|
| // ----------- S t a t e -------------
|
| // -- rax : argc
|
| @@ -1477,20 +1117,9 @@ void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
|
|
|
| // Run the native code for the InternalArray function called as a normal
|
| // function.
|
| - if (FLAG_optimize_constructed_arrays) {
|
| - // tail call a stub
|
| - InternalArrayConstructorStub stub(masm->isolate());
|
| - __ TailCallStub(&stub);
|
| - } else {
|
| - ArrayNativeCode(masm, &generic_array_code);
|
| -
|
| - // Jump to the generic array code in case the specialized code cannot handle
|
| - // the construction.
|
| - __ bind(&generic_array_code);
|
| - Handle<Code> array_code =
|
| - masm->isolate()->builtins()->InternalArrayCodeGeneric();
|
| - __ Jump(array_code, RelocInfo::CODE_TARGET);
|
| - }
|
| + // tail call a stub
|
| + InternalArrayConstructorStub stub(masm->isolate());
|
| + __ TailCallStub(&stub);
|
| }
|
|
|
|
|
| @@ -1517,61 +1146,16 @@ void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
|
| }
|
|
|
| // Run the native code for the Array function called as a normal function.
|
| - if (FLAG_optimize_constructed_arrays) {
|
| - // tail call a stub
|
| - Handle<Object> undefined_sentinel(
|
| - masm->isolate()->heap()->undefined_value(),
|
| - masm->isolate());
|
| - __ Move(rbx, undefined_sentinel);
|
| - ArrayConstructorStub stub(masm->isolate());
|
| - __ TailCallStub(&stub);
|
| - } else {
|
| - ArrayNativeCode(masm, &generic_array_code);
|
| -
|
| - // Jump to the generic array code in case the specialized code cannot handle
|
| - // the construction.
|
| - __ bind(&generic_array_code);
|
| - Handle<Code> array_code =
|
| - masm->isolate()->builtins()->ArrayCodeGeneric();
|
| - __ Jump(array_code, RelocInfo::CODE_TARGET);
|
| - }
|
| + // tail call a stub
|
| + Handle<Object> undefined_sentinel(
|
| + masm->isolate()->heap()->undefined_value(),
|
| + masm->isolate());
|
| + __ Move(rbx, undefined_sentinel);
|
| + ArrayConstructorStub stub(masm->isolate());
|
| + __ TailCallStub(&stub);
|
| }
|
|
|
|
|
| -void Builtins::Generate_CommonArrayConstructCode(MacroAssembler* masm) {
|
| - // ----------- S t a t e -------------
|
| - // -- rax : argc
|
| - // -- rdi : constructor
|
| - // -- rsp[0] : return address
|
| - // -- rsp[8] : last argument
|
| - // -----------------------------------
|
| - if (FLAG_debug_code) {
|
| - // The array construct code is only set for the builtin and internal
|
| - // Array functions which always have a map.
|
| -
|
| - // Initial map for the builtin Array function should be a map.
|
| - __ movq(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
|
| - // Will both indicate a NULL and a Smi.
|
| - STATIC_ASSERT(kSmiTag == 0);
|
| - Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
|
| - __ Check(not_smi, "Unexpected initial map for Array function");
|
| - __ CmpObjectType(rcx, MAP_TYPE, rcx);
|
| - __ Check(equal, "Unexpected initial map for Array function");
|
| - }
|
| -
|
| - Label generic_constructor;
|
| - // Run the native code for the Array function called as constructor.
|
| - ArrayNativeCode(masm, &generic_constructor);
|
| - // Jump to the generic construct code in case the specialized code cannot
|
| - // handle the construction.
|
| - __ bind(&generic_constructor);
|
| - Handle<Code> generic_construct_stub =
|
| - masm->isolate()->builtins()->JSConstructStubGeneric();
|
| - __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
|
| -}
|
| -
|
| -
|
| -
|
| void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
|
| // ----------- S t a t e -------------
|
| // -- rax : number of arguments
|
|
|