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

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: Review feedback 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
« no previous file with comments | « src/ia32/macro-assembler-ia32.h ('k') | src/macro-assembler.h » ('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 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) {
1267 ASSERT(kPointerAlignment * 2 == kDoubleAlignment);
1268 Label aligned;
1269 test(result, Immediate(kDoubleAlignmentMask));
1270 j(zero, &aligned, Label::kNear);
1271 mov(Operand(result, 0),
1272 Immediate(isolate()->factory()->one_pointer_filler_map()));
1273 add(result, Immediate(kDoubleSize / 2));
1274 bind(&aligned);
1275 }
1276
1263 Register top_reg = result_end.is_valid() ? result_end : result; 1277 Register top_reg = result_end.is_valid() ? result_end : result;
1264 1278
1265 // Calculate new top and bail out if new space is exhausted. 1279 // Calculate new top and bail out if new space is exhausted.
1266 ExternalReference new_space_allocation_limit = 1280 ExternalReference new_space_allocation_limit =
1267 ExternalReference::new_space_allocation_limit_address(isolate()); 1281 ExternalReference::new_space_allocation_limit_address(isolate());
1268 1282
1269 if (!top_reg.is(result)) { 1283 if (!top_reg.is(result)) {
1270 mov(top_reg, result); 1284 mov(top_reg, result);
1271 } 1285 }
1272 add(top_reg, Immediate(object_size)); 1286 add(top_reg, Immediate(object_size));
1273 j(carry, gc_required); 1287 j(carry, gc_required);
1274 cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit)); 1288 cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit));
1275 j(above, gc_required); 1289 j(above, gc_required);
1276 1290
1277 // Update allocation top. 1291 // Update allocation top.
1278 UpdateAllocationTopHelper(top_reg, scratch); 1292 UpdateAllocationTopHelper(top_reg, scratch);
1279 1293
1280 // Tag result if requested. 1294 // Tag result if requested.
1295 bool tag_result = (flags & TAG_OBJECT) != 0;
1281 if (top_reg.is(result)) { 1296 if (top_reg.is(result)) {
1282 if ((flags & TAG_OBJECT) != 0) { 1297 if (tag_result) {
1283 sub(result, Immediate(object_size - kHeapObjectTag)); 1298 sub(result, Immediate(object_size - kHeapObjectTag));
1284 } else { 1299 } else {
1285 sub(result, Immediate(object_size)); 1300 sub(result, Immediate(object_size));
1286 } 1301 }
1287 } else if ((flags & TAG_OBJECT) != 0) { 1302 } else if (tag_result) {
1288 add(result, Immediate(kHeapObjectTag)); 1303 ASSERT(kHeapObjectTag == 1);
1304 inc(result);
1289 } 1305 }
1290 } 1306 }
1291 1307
1292 1308
1293 void MacroAssembler::AllocateInNewSpace(int header_size, 1309 void MacroAssembler::AllocateInNewSpace(
1294 ScaleFactor element_size, 1310 int header_size,
1295 Register element_count, 1311 ScaleFactor element_size,
1296 Register result, 1312 Register element_count,
1297 Register result_end, 1313 RegisterValueType element_count_type,
1298 Register scratch, 1314 Register result,
1299 Label* gc_required, 1315 Register result_end,
1300 AllocationFlags flags) { 1316 Register scratch,
1317 Label* gc_required,
1318 AllocationFlags flags) {
1319 ASSERT((flags & SIZE_IN_WORDS) == 0);
1301 if (!FLAG_inline_new) { 1320 if (!FLAG_inline_new) {
1302 if (emit_debug_code()) { 1321 if (emit_debug_code()) {
1303 // Trash the registers to simulate an allocation failure. 1322 // Trash the registers to simulate an allocation failure.
1304 mov(result, Immediate(0x7091)); 1323 mov(result, Immediate(0x7091));
1305 mov(result_end, Immediate(0x7191)); 1324 mov(result_end, Immediate(0x7191));
1306 if (scratch.is_valid()) { 1325 if (scratch.is_valid()) {
1307 mov(scratch, Immediate(0x7291)); 1326 mov(scratch, Immediate(0x7291));
1308 } 1327 }
1309 // Register element_count is not modified by the function. 1328 // Register element_count is not modified by the function.
1310 } 1329 }
1311 jmp(gc_required); 1330 jmp(gc_required);
1312 return; 1331 return;
1313 } 1332 }
1314 ASSERT(!result.is(result_end)); 1333 ASSERT(!result.is(result_end));
1315 1334
1316 // Load address of new object into result. 1335 // Load address of new object into result.
1317 LoadAllocationTopHelper(result, scratch, flags); 1336 LoadAllocationTopHelper(result, scratch, flags);
1318 1337
1338 // Align the next allocation. Storing the filler map without checking top is
1339 // always safe because the limit of the heap is always aligned.
1340 if ((flags & DOUBLE_ALIGNMENT) != 0) {
1341 ASSERT(kPointerAlignment * 2 == kDoubleAlignment);
1342 Label aligned;
1343 test(result, Immediate(kDoubleAlignmentMask));
1344 j(zero, &aligned, Label::kNear);
1345 mov(Operand(result, 0),
1346 Immediate(isolate()->factory()->one_pointer_filler_map()));
1347 add(result, Immediate(kDoubleSize / 2));
1348 bind(&aligned);
1349 }
1350
1319 // Calculate new top and bail out if new space is exhausted. 1351 // Calculate new top and bail out if new space is exhausted.
1320 ExternalReference new_space_allocation_limit = 1352 ExternalReference new_space_allocation_limit =
1321 ExternalReference::new_space_allocation_limit_address(isolate()); 1353 ExternalReference::new_space_allocation_limit_address(isolate());
1322 1354
1323 // We assume that element_count*element_size + header_size does not 1355 // We assume that element_count*element_size + header_size does not
1324 // overflow. 1356 // overflow.
1357 if (element_count_type == REGISTER_VALUE_IS_SMI) {
1358 STATIC_ASSERT(static_cast<ScaleFactor>(times_2 - 1) == times_1);
1359 STATIC_ASSERT(static_cast<ScaleFactor>(times_4 - 1) == times_2);
1360 STATIC_ASSERT(static_cast<ScaleFactor>(times_8 - 1) == times_4);
1361 ASSERT(element_size >= times_2);
1362 ASSERT(kSmiTagSize == 1);
1363 element_size = static_cast<ScaleFactor>(element_size - 1);
1364 } else {
1365 ASSERT(element_count_type == REGISTER_VALUE_IS_INT32);
1366 }
1325 lea(result_end, Operand(element_count, element_size, header_size)); 1367 lea(result_end, Operand(element_count, element_size, header_size));
1326 add(result_end, result); 1368 add(result_end, result);
1327 j(carry, gc_required); 1369 j(carry, gc_required);
1328 cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); 1370 cmp(result_end, Operand::StaticVariable(new_space_allocation_limit));
1329 j(above, gc_required); 1371 j(above, gc_required);
1330 1372
1331 // Tag result if requested.
1332 if ((flags & TAG_OBJECT) != 0) { 1373 if ((flags & TAG_OBJECT) != 0) {
1333 lea(result, Operand(result, kHeapObjectTag)); 1374 ASSERT(kHeapObjectTag == 1);
1375 inc(result);
1334 } 1376 }
1335 1377
1336 // Update allocation top. 1378 // Update allocation top.
1337 UpdateAllocationTopHelper(result_end, scratch); 1379 UpdateAllocationTopHelper(result_end, scratch);
1338 } 1380 }
1339 1381
1340 1382
1341 void MacroAssembler::AllocateInNewSpace(Register object_size, 1383 void MacroAssembler::AllocateInNewSpace(Register object_size,
1342 Register result, 1384 Register result,
1343 Register result_end, 1385 Register result_end,
1344 Register scratch, 1386 Register scratch,
1345 Label* gc_required, 1387 Label* gc_required,
1346 AllocationFlags flags) { 1388 AllocationFlags flags) {
1389 ASSERT((flags & (DOUBLE_ALIGNMENT | RESULT_CONTAINS_TOP |
1390 SIZE_IN_WORDS)) == 0);
1347 if (!FLAG_inline_new) { 1391 if (!FLAG_inline_new) {
1348 if (emit_debug_code()) { 1392 if (emit_debug_code()) {
1349 // Trash the registers to simulate an allocation failure. 1393 // Trash the registers to simulate an allocation failure.
1350 mov(result, Immediate(0x7091)); 1394 mov(result, Immediate(0x7091));
1351 mov(result_end, Immediate(0x7191)); 1395 mov(result_end, Immediate(0x7191));
1352 if (scratch.is_valid()) { 1396 if (scratch.is_valid()) {
1353 mov(scratch, Immediate(0x7291)); 1397 mov(scratch, Immediate(0x7291));
1354 } 1398 }
1355 // object_size is left unchanged by this function. 1399 // object_size is left unchanged by this function.
1356 } 1400 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); 1470 ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
1427 ASSERT(kShortSize == 2); 1471 ASSERT(kShortSize == 2);
1428 // scratch1 = length * 2 + kObjectAlignmentMask. 1472 // scratch1 = length * 2 + kObjectAlignmentMask.
1429 lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); 1473 lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask));
1430 and_(scratch1, Immediate(~kObjectAlignmentMask)); 1474 and_(scratch1, Immediate(~kObjectAlignmentMask));
1431 1475
1432 // Allocate two byte string in new space. 1476 // Allocate two byte string in new space.
1433 AllocateInNewSpace(SeqTwoByteString::kHeaderSize, 1477 AllocateInNewSpace(SeqTwoByteString::kHeaderSize,
1434 times_1, 1478 times_1,
1435 scratch1, 1479 scratch1,
1480 REGISTER_VALUE_IS_INT32,
1436 result, 1481 result,
1437 scratch2, 1482 scratch2,
1438 scratch3, 1483 scratch3,
1439 gc_required, 1484 gc_required,
1440 TAG_OBJECT); 1485 TAG_OBJECT);
1441 1486
1442 // Set the map, length and hash field. 1487 // Set the map, length and hash field.
1443 mov(FieldOperand(result, HeapObject::kMapOffset), 1488 mov(FieldOperand(result, HeapObject::kMapOffset),
1444 Immediate(isolate()->factory()->string_map())); 1489 Immediate(isolate()->factory()->string_map()));
1445 mov(scratch1, length); 1490 mov(scratch1, length);
(...skipping 15 matching lines...) Expand all
1461 ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); 1506 ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
1462 mov(scratch1, length); 1507 mov(scratch1, length);
1463 ASSERT(kCharSize == 1); 1508 ASSERT(kCharSize == 1);
1464 add(scratch1, Immediate(kObjectAlignmentMask)); 1509 add(scratch1, Immediate(kObjectAlignmentMask));
1465 and_(scratch1, Immediate(~kObjectAlignmentMask)); 1510 and_(scratch1, Immediate(~kObjectAlignmentMask));
1466 1511
1467 // Allocate ASCII string in new space. 1512 // Allocate ASCII string in new space.
1468 AllocateInNewSpace(SeqOneByteString::kHeaderSize, 1513 AllocateInNewSpace(SeqOneByteString::kHeaderSize,
1469 times_1, 1514 times_1,
1470 scratch1, 1515 scratch1,
1516 REGISTER_VALUE_IS_INT32,
1471 result, 1517 result,
1472 scratch2, 1518 scratch2,
1473 scratch3, 1519 scratch3,
1474 gc_required, 1520 gc_required,
1475 TAG_OBJECT); 1521 TAG_OBJECT);
1476 1522
1477 // Set the map, length and hash field. 1523 // Set the map, length and hash field.
1478 mov(FieldOperand(result, HeapObject::kMapOffset), 1524 mov(FieldOperand(result, HeapObject::kMapOffset),
1479 Immediate(isolate()->factory()->ascii_string_map())); 1525 Immediate(isolate()->factory()->ascii_string_map()));
1480 mov(scratch1, length); 1526 mov(scratch1, length);
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 j(not_equal, call_runtime); 3047 j(not_equal, call_runtime);
3002 3048
3003 mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); 3049 mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset));
3004 cmp(ecx, isolate()->factory()->null_value()); 3050 cmp(ecx, isolate()->factory()->null_value());
3005 j(not_equal, &next); 3051 j(not_equal, &next);
3006 } 3052 }
3007 3053
3008 } } // namespace v8::internal 3054 } } // namespace v8::internal
3009 3055
3010 #endif // V8_TARGET_ARCH_IA32 3056 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/macro-assembler-ia32.h ('k') | src/macro-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698