OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // rsp[n]: Argument 1 | 663 // rsp[n]: Argument 1 |
664 // rsp[n+1]: Receiver (function to call) | 664 // rsp[n+1]: Receiver (function to call) |
665 // | 665 // |
666 // rax contains the number of arguments, n, not counting the receiver. | 666 // rax contains the number of arguments, n, not counting the receiver. |
667 // | 667 // |
668 // 1. Make sure we have at least one argument. | 668 // 1. Make sure we have at least one argument. |
669 { Label done; | 669 { Label done; |
670 __ testq(rax, rax); | 670 __ testq(rax, rax); |
671 __ j(not_zero, &done); | 671 __ j(not_zero, &done); |
672 __ pop(rbx); | 672 __ pop(rbx); |
673 __ Push(FACTORY->undefined_value()); | 673 __ Push(masm->isolate()->factory()->undefined_value()); |
674 __ push(rbx); | 674 __ push(rbx); |
675 __ incq(rax); | 675 __ incq(rax); |
676 __ bind(&done); | 676 __ bind(&done); |
677 } | 677 } |
678 | 678 |
679 // 2. Get the function to call (passed as receiver) from the stack, check | 679 // 2. Get the function to call (passed as receiver) from the stack, check |
680 // if it is a function. | 680 // if it is a function. |
681 Label slow, non_function; | 681 Label slow, non_function; |
682 // The function to call is at position n+1 on the stack. | 682 // The function to call is at position n+1 on the stack. |
683 __ movq(rdi, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize)); | 683 __ movq(rdi, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize)); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 // register. If the parameter initial_capacity is larger than zero an elements | 997 // register. If the parameter initial_capacity is larger than zero an elements |
998 // backing store is allocated with this size and filled with the hole values. | 998 // backing store is allocated with this size and filled with the hole values. |
999 // Otherwise the elements backing store is set to the empty FixedArray. | 999 // Otherwise the elements backing store is set to the empty FixedArray. |
1000 static void AllocateEmptyJSArray(MacroAssembler* masm, | 1000 static void AllocateEmptyJSArray(MacroAssembler* masm, |
1001 Register array_function, | 1001 Register array_function, |
1002 Register result, | 1002 Register result, |
1003 Register scratch1, | 1003 Register scratch1, |
1004 Register scratch2, | 1004 Register scratch2, |
1005 Register scratch3, | 1005 Register scratch3, |
1006 Label* gc_required) { | 1006 Label* gc_required) { |
1007 int initial_capacity = JSArray::kPreallocatedArrayElements; | 1007 const int initial_capacity = JSArray::kPreallocatedArrayElements; |
1008 ASSERT(initial_capacity >= 0); | 1008 STATIC_ASSERT(initial_capacity >= 0); |
1009 | 1009 |
1010 // Load the initial map from the array function. | 1010 // Load the initial map from the array function. |
1011 __ movq(scratch1, FieldOperand(array_function, | 1011 __ movq(scratch1, FieldOperand(array_function, |
1012 JSFunction::kPrototypeOrInitialMapOffset)); | 1012 JSFunction::kPrototypeOrInitialMapOffset)); |
1013 | 1013 |
1014 // Allocate the JSArray object together with space for a fixed array with the | 1014 // Allocate the JSArray object together with space for a fixed array with the |
1015 // requested elements. | 1015 // requested elements. |
1016 int size = JSArray::kSize; | 1016 int size = JSArray::kSize; |
1017 if (initial_capacity > 0) { | 1017 if (initial_capacity > 0) { |
1018 size += FixedArray::SizeFor(initial_capacity); | 1018 size += FixedArray::SizeFor(initial_capacity); |
1019 } | 1019 } |
1020 __ AllocateInNewSpace(size, | 1020 __ AllocateInNewSpace(size, |
1021 result, | 1021 result, |
1022 scratch2, | 1022 scratch2, |
1023 scratch3, | 1023 scratch3, |
1024 gc_required, | 1024 gc_required, |
1025 TAG_OBJECT); | 1025 TAG_OBJECT); |
1026 | 1026 |
1027 // Allocated the JSArray. Now initialize the fields except for the elements | 1027 // Allocated the JSArray. Now initialize the fields except for the elements |
1028 // array. | 1028 // array. |
1029 // result: JSObject | 1029 // result: JSObject |
1030 // scratch1: initial map | 1030 // scratch1: initial map |
1031 // scratch2: start of next object | 1031 // scratch2: start of next object |
| 1032 Factory* factory = masm->isolate()->factory(); |
1032 __ movq(FieldOperand(result, JSObject::kMapOffset), scratch1); | 1033 __ movq(FieldOperand(result, JSObject::kMapOffset), scratch1); |
1033 __ Move(FieldOperand(result, JSArray::kPropertiesOffset), | 1034 __ Move(FieldOperand(result, JSArray::kPropertiesOffset), |
1034 FACTORY->empty_fixed_array()); | 1035 factory->empty_fixed_array()); |
1035 // Field JSArray::kElementsOffset is initialized later. | 1036 // Field JSArray::kElementsOffset is initialized later. |
1036 __ Move(FieldOperand(result, JSArray::kLengthOffset), Smi::FromInt(0)); | 1037 __ Move(FieldOperand(result, JSArray::kLengthOffset), Smi::FromInt(0)); |
1037 | 1038 |
1038 // If no storage is requested for the elements array just set the empty | 1039 // If no storage is requested for the elements array just set the empty |
1039 // fixed array. | 1040 // fixed array. |
1040 if (initial_capacity == 0) { | 1041 if (initial_capacity == 0) { |
1041 __ Move(FieldOperand(result, JSArray::kElementsOffset), | 1042 __ Move(FieldOperand(result, JSArray::kElementsOffset), |
1042 FACTORY->empty_fixed_array()); | 1043 factory->empty_fixed_array()); |
1043 return; | 1044 return; |
1044 } | 1045 } |
1045 | 1046 |
1046 // Calculate the location of the elements array and set elements array member | 1047 // Calculate the location of the elements array and set elements array member |
1047 // of the JSArray. | 1048 // of the JSArray. |
1048 // result: JSObject | 1049 // result: JSObject |
1049 // scratch2: start of next object | 1050 // scratch2: start of next object |
1050 __ lea(scratch1, Operand(result, JSArray::kSize)); | 1051 __ lea(scratch1, Operand(result, JSArray::kSize)); |
1051 __ movq(FieldOperand(result, JSArray::kElementsOffset), scratch1); | 1052 __ movq(FieldOperand(result, JSArray::kElementsOffset), scratch1); |
1052 | 1053 |
1053 // Initialize the FixedArray and fill it with holes. FixedArray length is | 1054 // Initialize the FixedArray and fill it with holes. FixedArray length is |
1054 // stored as a smi. | 1055 // stored as a smi. |
1055 // result: JSObject | 1056 // result: JSObject |
1056 // scratch1: elements array | 1057 // scratch1: elements array |
1057 // scratch2: start of next object | 1058 // scratch2: start of next object |
1058 __ Move(FieldOperand(scratch1, HeapObject::kMapOffset), | 1059 __ Move(FieldOperand(scratch1, HeapObject::kMapOffset), |
1059 FACTORY->fixed_array_map()); | 1060 factory->fixed_array_map()); |
1060 __ Move(FieldOperand(scratch1, FixedArray::kLengthOffset), | 1061 __ Move(FieldOperand(scratch1, FixedArray::kLengthOffset), |
1061 Smi::FromInt(initial_capacity)); | 1062 Smi::FromInt(initial_capacity)); |
1062 | 1063 |
1063 // Fill the FixedArray with the hole value. Inline the code if short. | 1064 // Fill the FixedArray with the hole value. Inline the code if short. |
1064 // Reconsider loop unfolding if kPreallocatedArrayElements gets changed. | 1065 // Reconsider loop unfolding if kPreallocatedArrayElements gets changed. |
1065 static const int kLoopUnfoldLimit = 4; | 1066 static const int kLoopUnfoldLimit = 4; |
1066 __ Move(scratch3, FACTORY->the_hole_value()); | 1067 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); |
1067 if (initial_capacity <= kLoopUnfoldLimit) { | 1068 if (initial_capacity <= kLoopUnfoldLimit) { |
1068 // Use a scratch register here to have only one reloc info when unfolding | 1069 // Use a scratch register here to have only one reloc info when unfolding |
1069 // the loop. | 1070 // the loop. |
1070 for (int i = 0; i < initial_capacity; i++) { | 1071 for (int i = 0; i < initial_capacity; i++) { |
1071 __ movq(FieldOperand(scratch1, | 1072 __ movq(FieldOperand(scratch1, |
1072 FixedArray::kHeaderSize + i * kPointerSize), | 1073 FixedArray::kHeaderSize + i * kPointerSize), |
1073 scratch3); | 1074 scratch3); |
1074 } | 1075 } |
1075 } else { | 1076 } else { |
1076 Label loop, entry; | 1077 Label loop, entry; |
(...skipping 25 matching lines...) Expand all Loading... |
1102 Register elements_array_end, | 1103 Register elements_array_end, |
1103 Register scratch, | 1104 Register scratch, |
1104 bool fill_with_hole, | 1105 bool fill_with_hole, |
1105 Label* gc_required) { | 1106 Label* gc_required) { |
1106 // Load the initial map from the array function. | 1107 // Load the initial map from the array function. |
1107 __ movq(elements_array, | 1108 __ movq(elements_array, |
1108 FieldOperand(array_function, | 1109 FieldOperand(array_function, |
1109 JSFunction::kPrototypeOrInitialMapOffset)); | 1110 JSFunction::kPrototypeOrInitialMapOffset)); |
1110 | 1111 |
1111 if (FLAG_debug_code) { // Assert that array size is not zero. | 1112 if (FLAG_debug_code) { // Assert that array size is not zero. |
1112 Label not_empty; | |
1113 __ testq(array_size, array_size); | 1113 __ testq(array_size, array_size); |
1114 __ j(not_zero, ¬_empty); | 1114 __ Assert(not_zero, "array size is unexpectedly 0"); |
1115 __ int3(); | |
1116 __ bind(¬_empty); | |
1117 } | 1115 } |
1118 | 1116 |
1119 // Allocate the JSArray object together with space for a FixedArray with the | 1117 // Allocate the JSArray object together with space for a FixedArray with the |
1120 // requested elements. | 1118 // requested elements. |
1121 SmiIndex index = | 1119 SmiIndex index = |
1122 masm->SmiToIndex(kScratchRegister, array_size, kPointerSizeLog2); | 1120 masm->SmiToIndex(kScratchRegister, array_size, kPointerSizeLog2); |
1123 __ AllocateInNewSpace(JSArray::kSize + FixedArray::kHeaderSize, | 1121 __ AllocateInNewSpace(JSArray::kSize + FixedArray::kHeaderSize, |
1124 index.scale, | 1122 index.scale, |
1125 index.reg, | 1123 index.reg, |
1126 result, | 1124 result, |
1127 elements_array_end, | 1125 elements_array_end, |
1128 scratch, | 1126 scratch, |
1129 gc_required, | 1127 gc_required, |
1130 TAG_OBJECT); | 1128 TAG_OBJECT); |
1131 | 1129 |
1132 // Allocated the JSArray. Now initialize the fields except for the elements | 1130 // Allocated the JSArray. Now initialize the fields except for the elements |
1133 // array. | 1131 // array. |
1134 // result: JSObject | 1132 // result: JSObject |
1135 // elements_array: initial map | 1133 // elements_array: initial map |
1136 // elements_array_end: start of next object | 1134 // elements_array_end: start of next object |
1137 // array_size: size of array (smi) | 1135 // array_size: size of array (smi) |
| 1136 Factory* factory = masm->isolate()->factory(); |
1138 __ movq(FieldOperand(result, JSObject::kMapOffset), elements_array); | 1137 __ movq(FieldOperand(result, JSObject::kMapOffset), elements_array); |
1139 __ Move(elements_array, FACTORY->empty_fixed_array()); | 1138 __ Move(elements_array, factory->empty_fixed_array()); |
1140 __ movq(FieldOperand(result, JSArray::kPropertiesOffset), elements_array); | 1139 __ movq(FieldOperand(result, JSArray::kPropertiesOffset), elements_array); |
1141 // Field JSArray::kElementsOffset is initialized later. | 1140 // Field JSArray::kElementsOffset is initialized later. |
1142 __ movq(FieldOperand(result, JSArray::kLengthOffset), array_size); | 1141 __ movq(FieldOperand(result, JSArray::kLengthOffset), array_size); |
1143 | 1142 |
1144 // Calculate the location of the elements array and set elements array member | 1143 // Calculate the location of the elements array and set elements array member |
1145 // of the JSArray. | 1144 // of the JSArray. |
1146 // result: JSObject | 1145 // result: JSObject |
1147 // elements_array_end: start of next object | 1146 // elements_array_end: start of next object |
1148 // array_size: size of array (smi) | 1147 // array_size: size of array (smi) |
1149 __ lea(elements_array, Operand(result, JSArray::kSize)); | 1148 __ lea(elements_array, Operand(result, JSArray::kSize)); |
1150 __ movq(FieldOperand(result, JSArray::kElementsOffset), elements_array); | 1149 __ movq(FieldOperand(result, JSArray::kElementsOffset), elements_array); |
1151 | 1150 |
1152 // Initialize the fixed array. FixedArray length is stored as a smi. | 1151 // Initialize the fixed array. FixedArray length is stored as a smi. |
1153 // result: JSObject | 1152 // result: JSObject |
1154 // elements_array: elements array | 1153 // elements_array: elements array |
1155 // elements_array_end: start of next object | 1154 // elements_array_end: start of next object |
1156 // array_size: size of array (smi) | 1155 // array_size: size of array (smi) |
1157 __ Move(FieldOperand(elements_array, JSObject::kMapOffset), | 1156 __ Move(FieldOperand(elements_array, JSObject::kMapOffset), |
1158 FACTORY->fixed_array_map()); | 1157 factory->fixed_array_map()); |
1159 // For non-empty JSArrays the length of the FixedArray and the JSArray is the | 1158 // For non-empty JSArrays the length of the FixedArray and the JSArray is the |
1160 // same. | 1159 // same. |
1161 __ movq(FieldOperand(elements_array, FixedArray::kLengthOffset), array_size); | 1160 __ movq(FieldOperand(elements_array, FixedArray::kLengthOffset), array_size); |
1162 | 1161 |
1163 // Fill the allocated FixedArray with the hole value if requested. | 1162 // Fill the allocated FixedArray with the hole value if requested. |
1164 // result: JSObject | 1163 // result: JSObject |
1165 // elements_array: elements array | 1164 // elements_array: elements array |
1166 // elements_array_end: start of next object | 1165 // elements_array_end: start of next object |
1167 if (fill_with_hole) { | 1166 if (fill_with_hole) { |
1168 Label loop, entry; | 1167 Label loop, entry; |
1169 __ Move(scratch, FACTORY->the_hole_value()); | 1168 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
1170 __ lea(elements_array, Operand(elements_array, | 1169 __ lea(elements_array, Operand(elements_array, |
1171 FixedArray::kHeaderSize - kHeapObjectTag)); | 1170 FixedArray::kHeaderSize - kHeapObjectTag)); |
1172 __ jmp(&entry); | 1171 __ jmp(&entry); |
1173 __ bind(&loop); | 1172 __ bind(&loop); |
1174 __ movq(Operand(elements_array, 0), scratch); | 1173 __ movq(Operand(elements_array, 0), scratch); |
1175 __ addq(elements_array, Immediate(kPointerSize)); | 1174 __ addq(elements_array, Immediate(kPointerSize)); |
1176 __ bind(&entry); | 1175 __ bind(&entry); |
1177 __ cmpq(elements_array, elements_array_end); | 1176 __ cmpq(elements_array, elements_array_end); |
1178 __ j(below, &loop); | 1177 __ j(below, &loop); |
1179 } | 1178 } |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); | 1569 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); |
1571 generator.Generate(); | 1570 generator.Generate(); |
1572 } | 1571 } |
1573 | 1572 |
1574 | 1573 |
1575 #undef __ | 1574 #undef __ |
1576 | 1575 |
1577 } } // namespace v8::internal | 1576 } } // namespace v8::internal |
1578 | 1577 |
1579 #endif // V8_TARGET_ARCH_X64 | 1578 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |