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

Side by Side Diff: src/ia32/macro-assembler-ia32.cc

Issue 11684005: Refactor and improve inlined double-aligned allocations (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Ready for review Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 } 1234 }
1235 } 1235 }
1236 1236
1237 1237
1238 void MacroAssembler::AllocateInNewSpace(int object_size, 1238 void MacroAssembler::AllocateInNewSpace(int object_size,
1239 Register result, 1239 Register result,
1240 Register result_end, 1240 Register result_end,
1241 Register scratch, 1241 Register scratch,
1242 Label* gc_required, 1242 Label* gc_required,
1243 AllocationFlags flags) { 1243 AllocationFlags flags) {
1244 ASSERT((flags & (RESULT_CONTAINS_TOP | SIZE_IN_WORDS)) == 0);
1244 if (!FLAG_inline_new) { 1245 if (!FLAG_inline_new) {
1245 if (emit_debug_code()) { 1246 if (emit_debug_code()) {
1246 // Trash the registers to simulate an allocation failure. 1247 // Trash the registers to simulate an allocation failure.
1247 mov(result, Immediate(0x7091)); 1248 mov(result, Immediate(0x7091));
1248 if (result_end.is_valid()) { 1249 if (result_end.is_valid()) {
1249 mov(result_end, Immediate(0x7191)); 1250 mov(result_end, Immediate(0x7191));
1250 } 1251 }
1251 if (scratch.is_valid()) { 1252 if (scratch.is_valid()) {
1252 mov(scratch, Immediate(0x7291)); 1253 mov(scratch, Immediate(0x7291));
1253 } 1254 }
1254 } 1255 }
1255 jmp(gc_required); 1256 jmp(gc_required);
1256 return; 1257 return;
1257 } 1258 }
1258 ASSERT(!result.is(result_end)); 1259 ASSERT(!result.is(result_end));
1259 1260
1260 // Load address of new object into result. 1261 // Load address of new object into result.
1261 LoadAllocationTopHelper(result, scratch, flags); 1262 LoadAllocationTopHelper(result, scratch, flags);
1262 1263
1264 // Align the next allocation. Storing the filler map without checking top is
1265 // always safe because the limit of the heap is always aligned.
1266 if ((flags & DOUBLE_ALIGNMENT) != 0) {
Yang 2012/12/28 10:03:48 Maybe add an assert saying that this works because
danno 2012/12/28 15:44:55 Done.
1267 Label aligned;
1268 test(result, Immediate(kDoubleAlignmentMask));
1269 j(zero, &aligned, Label::kNear);
1270 mov(Operand(result, 0),
1271 Immediate(isolate()->factory()->one_pointer_filler_map()));
1272 add(result, Immediate(kDoubleSize / 2));
1273 bind(&aligned);
1274 }
1275
1263 Register top_reg = result_end.is_valid() ? result_end : result; 1276 Register top_reg = result_end.is_valid() ? result_end : result;
1264 1277
1265 // Calculate new top and bail out if new space is exhausted. 1278 // Calculate new top and bail out if new space is exhausted.
1266 ExternalReference new_space_allocation_limit = 1279 ExternalReference new_space_allocation_limit =
1267 ExternalReference::new_space_allocation_limit_address(isolate()); 1280 ExternalReference::new_space_allocation_limit_address(isolate());
1268 1281
1269 if (!top_reg.is(result)) { 1282 if (!top_reg.is(result)) {
1270 mov(top_reg, result); 1283 mov(top_reg, result);
1271 } 1284 }
1272 add(top_reg, Immediate(object_size)); 1285 add(top_reg, Immediate(object_size));
1273 j(carry, gc_required); 1286 j(carry, gc_required);
1274 cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit)); 1287 cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit));
1275 j(above, gc_required); 1288 j(above, gc_required);
1276 1289
1277 // Update allocation top. 1290 // Update allocation top.
1278 UpdateAllocationTopHelper(top_reg, scratch); 1291 UpdateAllocationTopHelper(top_reg, scratch);
1279 1292
1280 // Tag result if requested. 1293 // Tag result if requested.
1294 bool tag_result = (flags & TAG_OBJECT) != 0;
1281 if (top_reg.is(result)) { 1295 if (top_reg.is(result)) {
1282 if ((flags & TAG_OBJECT) != 0) { 1296 if (tag_result) {
1283 sub(result, Immediate(object_size - kHeapObjectTag)); 1297 sub(result, Immediate(object_size - kHeapObjectTag));
1284 } else { 1298 } else {
1285 sub(result, Immediate(object_size)); 1299 sub(result, Immediate(object_size));
1286 } 1300 }
1287 } else if ((flags & TAG_OBJECT) != 0) { 1301 } else if (tag_result) {
1288 add(result, Immediate(kHeapObjectTag)); 1302 ASSERT(kHeapObjectTag == 1);
1303 inc(result);
1289 } 1304 }
1290 } 1305 }
1291 1306
1292 1307
1293 void MacroAssembler::AllocateInNewSpace(int header_size, 1308 void MacroAssembler::AllocateInNewSpace(
1294 ScaleFactor element_size, 1309 int header_size,
1295 Register element_count, 1310 ScaleFactor element_size,
1296 Register result, 1311 Register element_count,
1297 Register result_end, 1312 RegisterValueType element_count_type,
1298 Register scratch, 1313 Register result,
1299 Label* gc_required, 1314 Register result_end,
1300 AllocationFlags flags) { 1315 Register scratch,
1316 Label* gc_required,
1317 AllocationFlags flags) {
1318 ASSERT((flags & SIZE_IN_WORDS) == 0);
1301 if (!FLAG_inline_new) { 1319 if (!FLAG_inline_new) {
1302 if (emit_debug_code()) { 1320 if (emit_debug_code()) {
1303 // Trash the registers to simulate an allocation failure. 1321 // Trash the registers to simulate an allocation failure.
1304 mov(result, Immediate(0x7091)); 1322 mov(result, Immediate(0x7091));
1305 mov(result_end, Immediate(0x7191)); 1323 mov(result_end, Immediate(0x7191));
1306 if (scratch.is_valid()) { 1324 if (scratch.is_valid()) {
1307 mov(scratch, Immediate(0x7291)); 1325 mov(scratch, Immediate(0x7291));
1308 } 1326 }
1309 // Register element_count is not modified by the function. 1327 // Register element_count is not modified by the function.
1310 } 1328 }
1311 jmp(gc_required); 1329 jmp(gc_required);
1312 return; 1330 return;
1313 } 1331 }
1314 ASSERT(!result.is(result_end)); 1332 ASSERT(!result.is(result_end));
1315 1333
1316 // Load address of new object into result. 1334 // Load address of new object into result.
1317 LoadAllocationTopHelper(result, scratch, flags); 1335 LoadAllocationTopHelper(result, scratch, flags);
1318 1336
1337 // Align the next allocation. Storing the filler map without checking top is
1338 // always safe because the limit of the heap is always aligned.
1339 if ((flags & DOUBLE_ALIGNMENT) != 0) {
1340 Label aligned;
1341 test(result, Immediate(kDoubleAlignmentMask));
1342 j(zero, &aligned, Label::kNear);
1343 mov(Operand(result, 0),
1344 Immediate(isolate()->factory()->one_pointer_filler_map()));
1345 add(result, Immediate(kDoubleSize / 2));
1346 bind(&aligned);
1347 }
1348
1319 // Calculate new top and bail out if new space is exhausted. 1349 // Calculate new top and bail out if new space is exhausted.
1320 ExternalReference new_space_allocation_limit = 1350 ExternalReference new_space_allocation_limit =
1321 ExternalReference::new_space_allocation_limit_address(isolate()); 1351 ExternalReference::new_space_allocation_limit_address(isolate());
1322 1352
1323 // We assume that element_count*element_size + header_size does not 1353 // We assume that element_count*element_size + header_size does not
1324 // overflow. 1354 // overflow.
1355 if (element_count_type == REGISTER_VALUE_IS_SMI) {
1356 STATIC_ASSERT(static_cast<ScaleFactor>(times_2 - 1) == times_1);
1357 STATIC_ASSERT(static_cast<ScaleFactor>(times_4 - 1) == times_2);
1358 STATIC_ASSERT(static_cast<ScaleFactor>(times_8 - 1) == times_4);
Yang 2012/12/28 10:03:48 Also assert that kSmiTagSize == 1.
danno 2012/12/28 15:44:55 Done.
1359 ASSERT(element_size >= times_2);
1360 element_size = static_cast<ScaleFactor>(element_size - 1);
1361 } else {
1362 ASSERT(element_count_type == REGISTER_VALUE_IS_INT32);
1363 }
1325 lea(result_end, Operand(element_count, element_size, header_size)); 1364 lea(result_end, Operand(element_count, element_size, header_size));
1326 add(result_end, result); 1365 add(result_end, result);
1327 j(carry, gc_required); 1366 j(carry, gc_required);
1328 cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); 1367 cmp(result_end, Operand::StaticVariable(new_space_allocation_limit));
1329 j(above, gc_required); 1368 j(above, gc_required);
1330 1369
1331 // Tag result if requested.
1332 if ((flags & TAG_OBJECT) != 0) { 1370 if ((flags & TAG_OBJECT) != 0) {
1333 lea(result, Operand(result, kHeapObjectTag)); 1371 ASSERT(kHeapObjectTag == 1);
1372 inc(result);
1334 } 1373 }
1335 1374
1336 // Update allocation top. 1375 // Update allocation top.
1337 UpdateAllocationTopHelper(result_end, scratch); 1376 UpdateAllocationTopHelper(result_end, scratch);
1338 } 1377 }
1339 1378
1340 1379
1341 void MacroAssembler::AllocateInNewSpace(Register object_size, 1380 void MacroAssembler::AllocateInNewSpace(Register object_size,
1342 Register result, 1381 Register result,
1343 Register result_end, 1382 Register result_end,
1344 Register scratch, 1383 Register scratch,
1345 Label* gc_required, 1384 Label* gc_required,
1346 AllocationFlags flags) { 1385 AllocationFlags flags) {
1386 ASSERT((flags & (DOUBLE_ALIGNMENT | RESULT_CONTAINS_TOP |
1387 SIZE_IN_WORDS)) == 0);
1347 if (!FLAG_inline_new) { 1388 if (!FLAG_inline_new) {
1348 if (emit_debug_code()) { 1389 if (emit_debug_code()) {
1349 // Trash the registers to simulate an allocation failure. 1390 // Trash the registers to simulate an allocation failure.
1350 mov(result, Immediate(0x7091)); 1391 mov(result, Immediate(0x7091));
1351 mov(result_end, Immediate(0x7191)); 1392 mov(result_end, Immediate(0x7191));
1352 if (scratch.is_valid()) { 1393 if (scratch.is_valid()) {
1353 mov(scratch, Immediate(0x7291)); 1394 mov(scratch, Immediate(0x7291));
1354 } 1395 }
1355 // object_size is left unchanged by this function. 1396 // object_size is left unchanged by this function.
1356 } 1397 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); 1467 ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
1427 ASSERT(kShortSize == 2); 1468 ASSERT(kShortSize == 2);
1428 // scratch1 = length * 2 + kObjectAlignmentMask. 1469 // scratch1 = length * 2 + kObjectAlignmentMask.
1429 lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); 1470 lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask));
1430 and_(scratch1, Immediate(~kObjectAlignmentMask)); 1471 and_(scratch1, Immediate(~kObjectAlignmentMask));
1431 1472
1432 // Allocate two byte string in new space. 1473 // Allocate two byte string in new space.
1433 AllocateInNewSpace(SeqTwoByteString::kHeaderSize, 1474 AllocateInNewSpace(SeqTwoByteString::kHeaderSize,
1434 times_1, 1475 times_1,
1435 scratch1, 1476 scratch1,
1477 REGISTER_VALUE_IS_INT32,
1436 result, 1478 result,
1437 scratch2, 1479 scratch2,
1438 scratch3, 1480 scratch3,
1439 gc_required, 1481 gc_required,
1440 TAG_OBJECT); 1482 TAG_OBJECT);
1441 1483
1442 // Set the map, length and hash field. 1484 // Set the map, length and hash field.
1443 mov(FieldOperand(result, HeapObject::kMapOffset), 1485 mov(FieldOperand(result, HeapObject::kMapOffset),
1444 Immediate(isolate()->factory()->string_map())); 1486 Immediate(isolate()->factory()->string_map()));
1445 mov(scratch1, length); 1487 mov(scratch1, length);
(...skipping 15 matching lines...) Expand all
1461 ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); 1503 ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
1462 mov(scratch1, length); 1504 mov(scratch1, length);
1463 ASSERT(kCharSize == 1); 1505 ASSERT(kCharSize == 1);
1464 add(scratch1, Immediate(kObjectAlignmentMask)); 1506 add(scratch1, Immediate(kObjectAlignmentMask));
1465 and_(scratch1, Immediate(~kObjectAlignmentMask)); 1507 and_(scratch1, Immediate(~kObjectAlignmentMask));
1466 1508
1467 // Allocate ASCII string in new space. 1509 // Allocate ASCII string in new space.
1468 AllocateInNewSpace(SeqOneByteString::kHeaderSize, 1510 AllocateInNewSpace(SeqOneByteString::kHeaderSize,
1469 times_1, 1511 times_1,
1470 scratch1, 1512 scratch1,
1513 REGISTER_VALUE_IS_INT32,
1471 result, 1514 result,
1472 scratch2, 1515 scratch2,
1473 scratch3, 1516 scratch3,
1474 gc_required, 1517 gc_required,
1475 TAG_OBJECT); 1518 TAG_OBJECT);
1476 1519
1477 // Set the map, length and hash field. 1520 // Set the map, length and hash field.
1478 mov(FieldOperand(result, HeapObject::kMapOffset), 1521 mov(FieldOperand(result, HeapObject::kMapOffset),
1479 Immediate(isolate()->factory()->ascii_string_map())); 1522 Immediate(isolate()->factory()->ascii_string_map()));
1480 mov(scratch1, length); 1523 mov(scratch1, length);
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 j(not_equal, call_runtime); 3044 j(not_equal, call_runtime);
3002 3045
3003 mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); 3046 mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset));
3004 cmp(ecx, isolate()->factory()->null_value()); 3047 cmp(ecx, isolate()->factory()->null_value());
3005 j(not_equal, &next); 3048 j(not_equal, &next);
3006 } 3049 }
3007 3050
3008 } } // namespace v8::internal 3051 } } // namespace v8::internal
3009 3052
3010 #endif // V8_TARGET_ARCH_IA32 3053 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698