OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 Memory::Address_at(free_start + offset) = kZapValue; | 1257 Memory::Address_at(free_start + offset) = kZapValue; |
1258 } | 1258 } |
1259 } | 1259 } |
1260 #endif | 1260 #endif |
1261 } | 1261 } |
1262 | 1262 |
1263 | 1263 |
1264 // Try to promote all objects in new space. Heap numbers and sequential | 1264 // Try to promote all objects in new space. Heap numbers and sequential |
1265 // strings are promoted to the code space, large objects to large object space, | 1265 // strings are promoted to the code space, large objects to large object space, |
1266 // and all others to the old space. | 1266 // and all others to the old space. |
1267 inline Object* MCAllocateFromNewSpace(HeapObject* object, int object_size) { | 1267 inline MaybeObject* MCAllocateFromNewSpace(HeapObject* object, |
1268 Object* forwarded; | 1268 int object_size) { |
| 1269 MaybeObject* forwarded; |
1269 if (object_size > Heap::MaxObjectSizeInPagedSpace()) { | 1270 if (object_size > Heap::MaxObjectSizeInPagedSpace()) { |
1270 forwarded = Failure::Exception(); | 1271 forwarded = Failure::Exception(); |
1271 } else { | 1272 } else { |
1272 OldSpace* target_space = Heap::TargetSpace(object); | 1273 OldSpace* target_space = Heap::TargetSpace(object); |
1273 ASSERT(target_space == Heap::old_pointer_space() || | 1274 ASSERT(target_space == Heap::old_pointer_space() || |
1274 target_space == Heap::old_data_space()); | 1275 target_space == Heap::old_data_space()); |
1275 forwarded = target_space->MCAllocateRaw(object_size); | 1276 forwarded = target_space->MCAllocateRaw(object_size); |
1276 } | 1277 } |
1277 if (forwarded->IsFailure()) { | 1278 Object* result; |
1278 forwarded = Heap::new_space()->MCAllocateRaw(object_size); | 1279 if (!forwarded->ToObject(&result)) { |
| 1280 result = Heap::new_space()->MCAllocateRaw(object_size)->ToObjectUnchecked(); |
1279 } | 1281 } |
1280 return forwarded; | 1282 return result; |
1281 } | 1283 } |
1282 | 1284 |
1283 | 1285 |
1284 // Allocation functions for the paged spaces call the space's MCAllocateRaw. | 1286 // Allocation functions for the paged spaces call the space's MCAllocateRaw. |
1285 inline Object* MCAllocateFromOldPointerSpace(HeapObject* ignore, | 1287 MUST_USE_RESULT inline MaybeObject* MCAllocateFromOldPointerSpace( |
1286 int object_size) { | 1288 HeapObject* ignore, |
| 1289 int object_size) { |
1287 return Heap::old_pointer_space()->MCAllocateRaw(object_size); | 1290 return Heap::old_pointer_space()->MCAllocateRaw(object_size); |
1288 } | 1291 } |
1289 | 1292 |
1290 | 1293 |
1291 inline Object* MCAllocateFromOldDataSpace(HeapObject* ignore, int object_size) { | 1294 MUST_USE_RESULT inline MaybeObject* MCAllocateFromOldDataSpace( |
| 1295 HeapObject* ignore, |
| 1296 int object_size) { |
1292 return Heap::old_data_space()->MCAllocateRaw(object_size); | 1297 return Heap::old_data_space()->MCAllocateRaw(object_size); |
1293 } | 1298 } |
1294 | 1299 |
1295 | 1300 |
1296 inline Object* MCAllocateFromCodeSpace(HeapObject* ignore, int object_size) { | 1301 MUST_USE_RESULT inline MaybeObject* MCAllocateFromCodeSpace( |
| 1302 HeapObject* ignore, |
| 1303 int object_size) { |
1297 return Heap::code_space()->MCAllocateRaw(object_size); | 1304 return Heap::code_space()->MCAllocateRaw(object_size); |
1298 } | 1305 } |
1299 | 1306 |
1300 | 1307 |
1301 inline Object* MCAllocateFromMapSpace(HeapObject* ignore, int object_size) { | 1308 MUST_USE_RESULT inline MaybeObject* MCAllocateFromMapSpace( |
| 1309 HeapObject* ignore, |
| 1310 int object_size) { |
1302 return Heap::map_space()->MCAllocateRaw(object_size); | 1311 return Heap::map_space()->MCAllocateRaw(object_size); |
1303 } | 1312 } |
1304 | 1313 |
1305 | 1314 |
1306 inline Object* MCAllocateFromCellSpace(HeapObject* ignore, int object_size) { | 1315 MUST_USE_RESULT inline MaybeObject* MCAllocateFromCellSpace( |
| 1316 HeapObject* ignore, int object_size) { |
1307 return Heap::cell_space()->MCAllocateRaw(object_size); | 1317 return Heap::cell_space()->MCAllocateRaw(object_size); |
1308 } | 1318 } |
1309 | 1319 |
1310 | 1320 |
1311 // The forwarding address is encoded at the same offset as the current | 1321 // The forwarding address is encoded at the same offset as the current |
1312 // to-space object, but in from space. | 1322 // to-space object, but in from space. |
1313 inline void EncodeForwardingAddressInNewSpace(HeapObject* old_object, | 1323 inline void EncodeForwardingAddressInNewSpace(HeapObject* old_object, |
1314 int object_size, | 1324 int object_size, |
1315 Object* new_object, | 1325 Object* new_object, |
1316 int* ignored) { | 1326 int* ignored) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 bool is_prev_alive = true; | 1383 bool is_prev_alive = true; |
1374 | 1384 |
1375 int object_size; // Will be set on each iteration of the loop. | 1385 int object_size; // Will be set on each iteration of the loop. |
1376 for (Address current = start; current < end; current += object_size) { | 1386 for (Address current = start; current < end; current += object_size) { |
1377 HeapObject* object = HeapObject::FromAddress(current); | 1387 HeapObject* object = HeapObject::FromAddress(current); |
1378 if (object->IsMarked()) { | 1388 if (object->IsMarked()) { |
1379 object->ClearMark(); | 1389 object->ClearMark(); |
1380 MarkCompactCollector::tracer()->decrement_marked_count(); | 1390 MarkCompactCollector::tracer()->decrement_marked_count(); |
1381 object_size = object->Size(); | 1391 object_size = object->Size(); |
1382 | 1392 |
1383 Object* forwarded = Alloc(object, object_size); | |
1384 // Allocation cannot fail, because we are compacting the space. | 1393 // Allocation cannot fail, because we are compacting the space. |
1385 ASSERT(!forwarded->IsFailure()); | 1394 Object* forwarded = Alloc(object, object_size)->ToObjectUnchecked(); |
1386 Encode(object, object_size, forwarded, offset); | 1395 Encode(object, object_size, forwarded, offset); |
1387 | 1396 |
1388 #ifdef DEBUG | 1397 #ifdef DEBUG |
1389 if (FLAG_gc_verbose) { | 1398 if (FLAG_gc_verbose) { |
1390 PrintF("forward %p -> %p.\n", object->address(), | 1399 PrintF("forward %p -> %p.\n", object->address(), |
1391 HeapObject::cast(forwarded)->address()); | 1400 HeapObject::cast(forwarded)->address()); |
1392 } | 1401 } |
1393 #endif | 1402 #endif |
1394 if (!is_prev_alive) { // Transition from non-live to live. | 1403 if (!is_prev_alive) { // Transition from non-live to live. |
1395 EncodeFreeRegion(free_start, static_cast<int>(current - free_start)); | 1404 EncodeFreeRegion(free_start, static_cast<int>(current - free_start)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 Address old_addr = HeapObject::cast(*p)->address(); | 1553 Address old_addr = HeapObject::cast(*p)->address(); |
1545 Address new_addr = Memory::Address_at(old_addr); | 1554 Address new_addr = Memory::Address_at(old_addr); |
1546 return String::cast(HeapObject::FromAddress(new_addr)); | 1555 return String::cast(HeapObject::FromAddress(new_addr)); |
1547 } | 1556 } |
1548 | 1557 |
1549 | 1558 |
1550 static bool TryPromoteObject(HeapObject* object, int object_size) { | 1559 static bool TryPromoteObject(HeapObject* object, int object_size) { |
1551 Object* result; | 1560 Object* result; |
1552 | 1561 |
1553 if (object_size > Heap::MaxObjectSizeInPagedSpace()) { | 1562 if (object_size > Heap::MaxObjectSizeInPagedSpace()) { |
1554 result = Heap::lo_space()->AllocateRawFixedArray(object_size); | 1563 MaybeObject* maybe_result = |
1555 if (!result->IsFailure()) { | 1564 Heap::lo_space()->AllocateRawFixedArray(object_size); |
| 1565 if (maybe_result->ToObject(&result)) { |
1556 HeapObject* target = HeapObject::cast(result); | 1566 HeapObject* target = HeapObject::cast(result); |
1557 MigrateObject(target->address(), object->address(), object_size, true); | 1567 MigrateObject(target->address(), object->address(), object_size, true); |
1558 MarkCompactCollector::tracer()-> | 1568 MarkCompactCollector::tracer()-> |
1559 increment_promoted_objects_size(object_size); | 1569 increment_promoted_objects_size(object_size); |
1560 return true; | 1570 return true; |
1561 } | 1571 } |
1562 } else { | 1572 } else { |
1563 OldSpace* target_space = Heap::TargetSpace(object); | 1573 OldSpace* target_space = Heap::TargetSpace(object); |
1564 | 1574 |
1565 ASSERT(target_space == Heap::old_pointer_space() || | 1575 ASSERT(target_space == Heap::old_pointer_space() || |
1566 target_space == Heap::old_data_space()); | 1576 target_space == Heap::old_data_space()); |
1567 result = target_space->AllocateRaw(object_size); | 1577 MaybeObject* maybe_result = target_space->AllocateRaw(object_size); |
1568 if (!result->IsFailure()) { | 1578 if (maybe_result->ToObject(&result)) { |
1569 HeapObject* target = HeapObject::cast(result); | 1579 HeapObject* target = HeapObject::cast(result); |
1570 MigrateObject(target->address(), | 1580 MigrateObject(target->address(), |
1571 object->address(), | 1581 object->address(), |
1572 object_size, | 1582 object_size, |
1573 target_space == Heap::old_pointer_space()); | 1583 target_space == Heap::old_pointer_space()); |
1574 MarkCompactCollector::tracer()-> | 1584 MarkCompactCollector::tracer()-> |
1575 increment_promoted_objects_size(object_size); | 1585 increment_promoted_objects_size(object_size); |
1576 return true; | 1586 return true; |
1577 } | 1587 } |
1578 } | 1588 } |
(...skipping 27 matching lines...) Expand all Loading... |
1606 | 1616 |
1607 size = object->Size(); | 1617 size = object->Size(); |
1608 survivors_size += size; | 1618 survivors_size += size; |
1609 | 1619 |
1610 // Aggressively promote young survivors to the old space. | 1620 // Aggressively promote young survivors to the old space. |
1611 if (TryPromoteObject(object, size)) { | 1621 if (TryPromoteObject(object, size)) { |
1612 continue; | 1622 continue; |
1613 } | 1623 } |
1614 | 1624 |
1615 // Promotion failed. Just migrate object to another semispace. | 1625 // Promotion failed. Just migrate object to another semispace. |
1616 Object* target = space->AllocateRaw(size); | |
1617 | |
1618 // Allocation cannot fail at this point: semispaces are of equal size. | 1626 // Allocation cannot fail at this point: semispaces are of equal size. |
1619 ASSERT(!target->IsFailure()); | 1627 Object* target = space->AllocateRaw(size)->ToObjectUnchecked(); |
1620 | 1628 |
1621 MigrateObject(HeapObject::cast(target)->address(), | 1629 MigrateObject(HeapObject::cast(target)->address(), |
1622 current, | 1630 current, |
1623 size, | 1631 size, |
1624 false); | 1632 false); |
1625 } else { | 1633 } else { |
1626 size = object->Size(); | 1634 size = object->Size(); |
1627 Memory::Address_at(current) = NULL; | 1635 Memory::Address_at(current) = NULL; |
1628 } | 1636 } |
1629 } | 1637 } |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2665 } | 2673 } |
2666 | 2674 |
2667 | 2675 |
2668 void MarkCompactCollector::Initialize() { | 2676 void MarkCompactCollector::Initialize() { |
2669 StaticPointersToNewGenUpdatingVisitor::Initialize(); | 2677 StaticPointersToNewGenUpdatingVisitor::Initialize(); |
2670 StaticMarkingVisitor::Initialize(); | 2678 StaticMarkingVisitor::Initialize(); |
2671 } | 2679 } |
2672 | 2680 |
2673 | 2681 |
2674 } } // namespace v8::internal | 2682 } } // namespace v8::internal |
OLD | NEW |