OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 rax, | 1077 rax, |
1078 rdi, | 1078 rdi, |
1079 name, | 1079 name, |
1080 &miss); | 1080 &miss); |
1081 | 1081 |
1082 if (argc == 0) { | 1082 if (argc == 0) { |
1083 // Noop, return the length. | 1083 // Noop, return the length. |
1084 __ movq(rax, FieldOperand(rdx, JSArray::kLengthOffset)); | 1084 __ movq(rax, FieldOperand(rdx, JSArray::kLengthOffset)); |
1085 __ ret((argc + 1) * kPointerSize); | 1085 __ ret((argc + 1) * kPointerSize); |
1086 } else { | 1086 } else { |
| 1087 Label call_builtin; |
| 1088 |
1087 // Get the elements array of the object. | 1089 // Get the elements array of the object. |
1088 __ movq(rbx, FieldOperand(rdx, JSArray::kElementsOffset)); | 1090 __ movq(rbx, FieldOperand(rdx, JSArray::kElementsOffset)); |
1089 | 1091 |
1090 // Check that the elements are in fast mode (not dictionary). | 1092 // Check that the elements are in fast mode and writable. |
1091 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), | 1093 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), |
1092 Factory::fixed_array_map()); | 1094 Factory::fixed_array_map()); |
1093 __ j(not_equal, &miss); | 1095 __ j(not_equal, &call_builtin); |
1094 | 1096 |
1095 if (argc == 1) { // Otherwise fall through to call builtin. | 1097 if (argc == 1) { // Otherwise fall through to call builtin. |
1096 Label call_builtin, exit, with_write_barrier, attempt_to_grow_elements; | 1098 Label exit, with_write_barrier, attempt_to_grow_elements; |
1097 | 1099 |
1098 // Get the array's length into rax and calculate new length. | 1100 // Get the array's length into rax and calculate new length. |
1099 __ SmiToInteger32(rax, FieldOperand(rdx, JSArray::kLengthOffset)); | 1101 __ SmiToInteger32(rax, FieldOperand(rdx, JSArray::kLengthOffset)); |
1100 STATIC_ASSERT(FixedArray::kMaxLength < Smi::kMaxValue); | 1102 STATIC_ASSERT(FixedArray::kMaxLength < Smi::kMaxValue); |
1101 __ addl(rax, Immediate(argc)); | 1103 __ addl(rax, Immediate(argc)); |
1102 | 1104 |
1103 // Get the element's length into rcx. | 1105 // Get the element's length into rcx. |
1104 __ SmiToInteger32(rcx, FieldOperand(rbx, FixedArray::kLengthOffset)); | 1106 __ SmiToInteger32(rcx, FieldOperand(rbx, FixedArray::kLengthOffset)); |
1105 | 1107 |
1106 // Check if we could survive without allocation. | 1108 // Check if we could survive without allocation. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 __ j(above, &call_builtin); | 1159 __ j(above, &call_builtin); |
1158 | 1160 |
1159 // We fit and could grow elements. | 1161 // We fit and could grow elements. |
1160 __ movq(kScratchRegister, new_space_allocation_top); | 1162 __ movq(kScratchRegister, new_space_allocation_top); |
1161 __ movq(Operand(kScratchRegister, 0), rcx); | 1163 __ movq(Operand(kScratchRegister, 0), rcx); |
1162 __ movq(rcx, Operand(rsp, argc * kPointerSize)); | 1164 __ movq(rcx, Operand(rsp, argc * kPointerSize)); |
1163 | 1165 |
1164 // Push the argument... | 1166 // Push the argument... |
1165 __ movq(Operand(rdx, 0), rcx); | 1167 __ movq(Operand(rdx, 0), rcx); |
1166 // ... and fill the rest with holes. | 1168 // ... and fill the rest with holes. |
1167 __ Move(kScratchRegister, Factory::the_hole_value()); | 1169 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
1168 for (int i = 1; i < kAllocationDelta; i++) { | 1170 for (int i = 1; i < kAllocationDelta; i++) { |
1169 __ movq(Operand(rdx, i * kPointerSize), kScratchRegister); | 1171 __ movq(Operand(rdx, i * kPointerSize), kScratchRegister); |
1170 } | 1172 } |
1171 | 1173 |
1172 // Restore receiver to rdx as finish sequence assumes it's here. | 1174 // Restore receiver to rdx as finish sequence assumes it's here. |
1173 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); | 1175 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); |
1174 | 1176 |
1175 // Increment element's and array's sizes. | 1177 // Increment element's and array's sizes. |
1176 __ SmiAddConstant(FieldOperand(rbx, FixedArray::kLengthOffset), | 1178 __ SmiAddConstant(FieldOperand(rbx, FixedArray::kLengthOffset), |
1177 Smi::FromInt(kAllocationDelta)); | 1179 Smi::FromInt(kAllocationDelta)); |
| 1180 |
1178 // Make new length a smi before returning it. | 1181 // Make new length a smi before returning it. |
1179 __ Integer32ToSmi(rax, rax); | 1182 __ Integer32ToSmi(rax, rax); |
1180 __ movq(FieldOperand(rdx, JSArray::kLengthOffset), rax); | 1183 __ movq(FieldOperand(rdx, JSArray::kLengthOffset), rax); |
| 1184 |
1181 // Elements are in new space, so write barrier is not required. | 1185 // Elements are in new space, so write barrier is not required. |
1182 __ ret((argc + 1) * kPointerSize); | 1186 __ ret((argc + 1) * kPointerSize); |
1183 | |
1184 __ bind(&call_builtin); | |
1185 } | 1187 } |
1186 | 1188 |
| 1189 __ bind(&call_builtin); |
1187 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush), | 1190 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush), |
1188 argc + 1, | 1191 argc + 1, |
1189 1); | 1192 1); |
1190 } | 1193 } |
1191 | 1194 |
1192 __ bind(&miss); | 1195 __ bind(&miss); |
1193 Object* obj = GenerateMissBranch(); | 1196 Object* obj = GenerateMissBranch(); |
1194 if (obj->IsFailure()) return obj; | 1197 if (obj->IsFailure()) return obj; |
1195 | 1198 |
1196 // Return the generated code. | 1199 // Return the generated code. |
1197 return GetCode(function); | 1200 return GetCode(function); |
1198 } | 1201 } |
1199 | 1202 |
1200 | 1203 |
1201 Object* CallStubCompiler::CompileArrayPopCall(Object* object, | 1204 Object* CallStubCompiler::CompileArrayPopCall(Object* object, |
1202 JSObject* holder, | 1205 JSObject* holder, |
1203 JSFunction* function, | 1206 JSFunction* function, |
1204 String* name, | 1207 String* name, |
1205 CheckType check) { | 1208 CheckType check) { |
1206 // ----------- S t a t e ------------- | 1209 // ----------- S t a t e ------------- |
1207 // -- ecx : name | 1210 // -- rcx : name |
1208 // -- esp[0] : return address | 1211 // -- rsp[0] : return address |
1209 // -- esp[(argc - n) * 4] : arg[n] (zero-based) | 1212 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) |
1210 // -- ... | 1213 // -- ... |
1211 // -- esp[(argc + 1) * 4] : receiver | 1214 // -- rsp[(argc + 1) * 8] : receiver |
1212 // ----------------------------------- | 1215 // ----------------------------------- |
1213 ASSERT(check == RECEIVER_MAP_CHECK); | 1216 ASSERT(check == RECEIVER_MAP_CHECK); |
1214 | 1217 |
1215 // If object is not an array, bail out to regular call. | 1218 // If object is not an array, bail out to regular call. |
1216 if (!object->IsJSArray()) { | 1219 if (!object->IsJSArray()) { |
1217 return Heap::undefined_value(); | 1220 return Heap::undefined_value(); |
1218 } | 1221 } |
1219 | 1222 |
1220 Label miss, return_undefined, call_builtin; | 1223 Label miss, return_undefined, call_builtin; |
1221 | 1224 |
1222 GenerateNameCheck(name, &miss); | 1225 GenerateNameCheck(name, &miss); |
1223 | 1226 |
1224 // Get the receiver from the stack. | 1227 // Get the receiver from the stack. |
1225 const int argc = arguments().immediate(); | 1228 const int argc = arguments().immediate(); |
1226 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); | 1229 __ movq(rdx, Operand(rsp, (argc + 1) * kPointerSize)); |
1227 | 1230 |
1228 // Check that the receiver isn't a smi. | 1231 // Check that the receiver isn't a smi. |
1229 __ JumpIfSmi(rdx, &miss); | 1232 __ JumpIfSmi(rdx, &miss); |
1230 | 1233 |
1231 CheckPrototypes(JSObject::cast(object), rdx, | 1234 CheckPrototypes(JSObject::cast(object), rdx, |
1232 holder, rbx, | 1235 holder, rbx, |
1233 rax, rdi, name, &miss); | 1236 rax, rdi, name, &miss); |
1234 | 1237 |
1235 // Get the elements array of the object. | 1238 // Get the elements array of the object. |
1236 __ movq(rbx, FieldOperand(rdx, JSArray::kElementsOffset)); | 1239 __ movq(rbx, FieldOperand(rdx, JSArray::kElementsOffset)); |
1237 | 1240 |
1238 // Check that the elements are in fast mode (not dictionary). | 1241 // Check that the elements are in fast mode and writable. |
1239 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), Factory::fixed_array_map()); | 1242 __ CompareRoot(FieldOperand(rbx, HeapObject::kMapOffset), |
1240 __ j(not_equal, &miss); | 1243 Heap::kFixedArrayMapRootIndex); |
| 1244 __ j(not_equal, &call_builtin); |
1241 | 1245 |
1242 // Get the array's length into rcx and calculate new length. | 1246 // Get the array's length into rcx and calculate new length. |
1243 __ SmiToInteger32(rcx, FieldOperand(rdx, JSArray::kLengthOffset)); | 1247 __ SmiToInteger32(rcx, FieldOperand(rdx, JSArray::kLengthOffset)); |
1244 __ subl(rcx, Immediate(1)); | 1248 __ subl(rcx, Immediate(1)); |
1245 __ j(negative, &return_undefined); | 1249 __ j(negative, &return_undefined); |
1246 | 1250 |
1247 // Get the last element. | 1251 // Get the last element. |
1248 __ Move(r9, Factory::the_hole_value()); | 1252 __ LoadRoot(r9, Heap::kTheHoleValueRootIndex); |
1249 __ movq(rax, FieldOperand(rbx, | 1253 __ movq(rax, FieldOperand(rbx, |
1250 rcx, times_pointer_size, | 1254 rcx, times_pointer_size, |
1251 FixedArray::kHeaderSize)); | 1255 FixedArray::kHeaderSize)); |
1252 // Check if element is already the hole. | 1256 // Check if element is already the hole. |
1253 __ cmpq(rax, r9); | 1257 __ cmpq(rax, r9); |
1254 // If so, call slow-case to also check prototypes for value. | 1258 // If so, call slow-case to also check prototypes for value. |
1255 __ j(equal, &call_builtin); | 1259 __ j(equal, &call_builtin); |
1256 | 1260 |
1257 // Set the array's length. | 1261 // Set the array's length. |
1258 __ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rcx); | 1262 __ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rcx); |
1259 | 1263 |
1260 // Fill with the hole and return original value. | 1264 // Fill with the hole and return original value. |
1261 __ movq(FieldOperand(rbx, | 1265 __ movq(FieldOperand(rbx, |
1262 rcx, times_pointer_size, | 1266 rcx, times_pointer_size, |
1263 FixedArray::kHeaderSize), | 1267 FixedArray::kHeaderSize), |
1264 r9); | 1268 r9); |
1265 __ ret((argc + 1) * kPointerSize); | 1269 __ ret((argc + 1) * kPointerSize); |
1266 | 1270 |
1267 __ bind(&return_undefined); | 1271 __ bind(&return_undefined); |
1268 | 1272 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
1269 __ Move(rax, Factory::undefined_value()); | |
1270 __ ret((argc + 1) * kPointerSize); | 1273 __ ret((argc + 1) * kPointerSize); |
1271 | 1274 |
1272 __ bind(&call_builtin); | 1275 __ bind(&call_builtin); |
1273 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop), | 1276 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPop), |
1274 argc + 1, | 1277 argc + 1, |
1275 1); | 1278 1); |
| 1279 |
1276 __ bind(&miss); | 1280 __ bind(&miss); |
1277 Object* obj = GenerateMissBranch(); | 1281 Object* obj = GenerateMissBranch(); |
1278 if (obj->IsFailure()) return obj; | 1282 if (obj->IsFailure()) return obj; |
1279 | 1283 |
1280 // Return the generated code. | 1284 // Return the generated code. |
1281 return GetCode(function); | 1285 return GetCode(function); |
1282 } | 1286 } |
1283 | 1287 |
1284 | 1288 |
1285 Object* CallStubCompiler::CompileStringCharAtCall(Object* object, | 1289 Object* CallStubCompiler::CompileStringCharAtCall(Object* object, |
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2590 // Return the generated code. | 2594 // Return the generated code. |
2591 return GetCode(); | 2595 return GetCode(); |
2592 } | 2596 } |
2593 | 2597 |
2594 | 2598 |
2595 #undef __ | 2599 #undef __ |
2596 | 2600 |
2597 } } // namespace v8::internal | 2601 } } // namespace v8::internal |
2598 | 2602 |
2599 #endif // V8_TARGET_ARCH_X64 | 2603 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |