Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/ia32/stub-cache-ia32.cc

Issue 945002: Just grow elements if they happen to be at the edge of new space. (Closed)
Patch Set: First round of Mads' comments Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/array-push.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 } else { 1244 } else {
1245 // Get the elements array of the object. 1245 // Get the elements array of the object.
1246 __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); 1246 __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset));
1247 1247
1248 // Check that the elements are in fast mode (not dictionary). 1248 // Check that the elements are in fast mode (not dictionary).
1249 __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), 1249 __ cmp(FieldOperand(ebx, HeapObject::kMapOffset),
1250 Immediate(Factory::fixed_array_map())); 1250 Immediate(Factory::fixed_array_map()));
1251 __ j(not_equal, &miss); 1251 __ j(not_equal, &miss);
1252 1252
1253 if (argc == 1) { // Otherwise fall through to call builtin. 1253 if (argc == 1) { // Otherwise fall through to call builtin.
1254 Label call_builtin, exit, with_rset_update; 1254 Label call_builtin, exit, with_rset_update,
1255 attempt_to_grow_elements, finish_push;
1255 1256
1256 // Get the array's length into eax and calculate new length. 1257 // Get the array's length into eax and calculate new length.
1257 __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); 1258 __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset));
1258 STATIC_ASSERT(kSmiTagSize == 1); 1259 STATIC_ASSERT(kSmiTagSize == 1);
1259 STATIC_ASSERT(kSmiTag == 0); 1260 STATIC_ASSERT(kSmiTag == 0);
1260 __ add(Operand(eax), Immediate(argc << 1)); 1261 __ add(Operand(eax), Immediate(argc << 1));
1261 1262
1262 // Get the element's length into ecx. 1263 // Get the element's length into ecx.
1263 __ mov(ecx, FieldOperand(ebx, FixedArray::kLengthOffset)); 1264 __ mov(ecx, FieldOperand(ebx, FixedArray::kLengthOffset));
1264 __ SmiTag(ecx); 1265 __ SmiTag(ecx);
1265 1266
1266 // Check if we could survive without allocation, go to builtin otherwise. 1267 // Check if we could survive without allocation.
1267 __ cmp(eax, Operand(ecx)); 1268 __ cmp(eax, Operand(ecx));
1268 __ j(greater, &call_builtin); 1269 __ j(greater, &attempt_to_grow_elements);
1269 1270
1270 // Save new length. 1271 // Save new length.
1271 __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); 1272 __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax);
1272 1273
1273 // Push the element. 1274 // Push the element.
1274 __ lea(edx, FieldOperand(ebx, 1275 __ lea(edx, FieldOperand(ebx,
1275 eax, times_half_pointer_size, 1276 eax, times_half_pointer_size,
1276 FixedArray::kHeaderSize - argc * kPointerSize)); 1277 FixedArray::kHeaderSize - argc * kPointerSize));
1277 __ mov(ecx, Operand(esp, argc * kPointerSize)); 1278 __ mov(ecx, Operand(esp, argc * kPointerSize));
1278 __ mov(Operand(edx, 0), ecx); 1279 __ mov(Operand(edx, 0), ecx);
1279 1280
1281 __ bind(&finish_push);
1282
1280 // Check if value is a smi. 1283 // Check if value is a smi.
1281 __ test(ecx, Immediate(kSmiTagMask)); 1284 __ test(ecx, Immediate(kSmiTagMask));
1282 __ j(not_zero, &with_rset_update); 1285 __ j(not_zero, &with_rset_update);
1283 1286
1284 __ bind(&exit); 1287 __ bind(&exit);
1285 __ ret((argc + 1) * kPointerSize); 1288 __ ret((argc + 1) * kPointerSize);
1286 1289
1287 __ bind(&with_rset_update); 1290 __ bind(&with_rset_update);
1288 1291
1289 __ InNewSpace(ebx, ecx, equal, &exit); 1292 __ InNewSpace(ebx, ecx, equal, &exit);
1290 1293
1291 RecordWriteStub stub(ebx, edx, ecx); 1294 RecordWriteStub stub(ebx, edx, ecx);
1292 __ CallStub(&stub); 1295 __ CallStub(&stub);
1293 __ ret((argc + 1) * kPointerSize); 1296 __ ret((argc + 1) * kPointerSize);
1294 1297
1298 __ bind(&attempt_to_grow_elements);
1299 ExternalReference new_space_allocation_top =
1300 ExternalReference::new_space_allocation_top_address();
1301 ExternalReference new_space_allocation_limit =
1302 ExternalReference::new_space_allocation_limit_address();
1303
1304 const int kAllocationDelta = 4;
1305 // Load top.
1306 __ mov(ecx, Operand::StaticVariable(new_space_allocation_top));
1307
1308 // Check if it's the end of elements.
1309 __ lea(edx, FieldOperand(ebx,
1310 eax, times_half_pointer_size,
1311 FixedArray::kHeaderSize - argc * kPointerSize));
1312 __ cmp(edx, Operand(ecx));
1313 __ j(not_equal, &call_builtin);
1314 __ add(Operand(ecx), Immediate(kAllocationDelta * kPointerSize));
1315 __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit));
1316 __ j(greater, &call_builtin);
1317
1318 // We fit and could grow elements.
1319 __ mov(Operand::StaticVariable(new_space_allocation_top), ecx);
1320 __ mov(ecx, Operand(esp, argc * kPointerSize));
1321 __ mov(Operand(edx, 0), ecx);
1322 for (int i = 1; i < kAllocationDelta; i++) {
1323 __ mov(Operand(edx, i * kPointerSize),
1324 Immediate(Factory::undefined_value()));
1325 }
1326
1327 // Restore receiver to edx as finish sequence assumes it's here.
1328 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1329
1330 // Increment element's and array's sizes.
1331 __ add(FieldOperand(ebx, FixedArray::kLengthOffset),
1332 Immediate(kAllocationDelta));
1333 __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax);
1334
1335 __ jmp(&finish_push);
1336
1295 __ bind(&call_builtin); 1337 __ bind(&call_builtin);
1296 } 1338 }
1297 1339
1298 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush), 1340 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush),
1299 argc + 1, 1341 argc + 1,
1300 1); 1342 1);
1301 } 1343 }
1302 1344
1303 __ bind(&miss); 1345 __ bind(&miss);
1304 1346
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); 2424 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET);
2383 2425
2384 // Return the generated code. 2426 // Return the generated code.
2385 return GetCode(); 2427 return GetCode();
2386 } 2428 }
2387 2429
2388 2430
2389 #undef __ 2431 #undef __
2390 2432
2391 } } // namespace v8::internal 2433 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/array-push.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698