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

Side by Side Diff: src/mark-compact.cc

Issue 3679002: [Isolates] Remove more HEAP macros from GC. (Closed)
Patch Set: Created 10 years, 2 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 | « src/mark-compact.h ('k') | no next file » | 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-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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // (ConsString::cast(object)->second() == HEAP->empty_string()) 227 // (ConsString::cast(object)->second() == HEAP->empty_string())
228 // except the maps for the object and its possible substrings might be 228 // except the maps for the object and its possible substrings might be
229 // marked. 229 // marked.
230 HeapObject* object = HeapObject::cast(*p); 230 HeapObject* object = HeapObject::cast(*p);
231 MapWord map_word = object->map_word(); 231 MapWord map_word = object->map_word();
232 map_word.ClearMark(); 232 map_word.ClearMark();
233 InstanceType type = map_word.ToMap()->instance_type(); 233 InstanceType type = map_word.ToMap()->instance_type();
234 if ((type & kShortcutTypeMask) != kShortcutTypeTag) return object; 234 if ((type & kShortcutTypeMask) != kShortcutTypeTag) return object;
235 235
236 Object* second = reinterpret_cast<ConsString*>(object)->unchecked_second(); 236 Object* second = reinterpret_cast<ConsString*>(object)->unchecked_second();
237 if (second != HEAP->raw_unchecked_empty_string()) { 237 Heap* heap = map_word.ToMap()->heap();
238 if (second != heap->raw_unchecked_empty_string()) {
238 return object; 239 return object;
239 } 240 }
240 241
241 // Since we don't have the object's start, it is impossible to update the 242 // Since we don't have the object's start, it is impossible to update the
242 // page dirty marks. Therefore, we only replace the string with its left 243 // page dirty marks. Therefore, we only replace the string with its left
243 // substring when page dirty marks do not change. 244 // substring when page dirty marks do not change.
244 Object* first = reinterpret_cast<ConsString*>(object)->unchecked_first(); 245 Object* first = reinterpret_cast<ConsString*>(object)->unchecked_first();
245 if (!HEAP->InNewSpace(object) && HEAP->InNewSpace(first)) return object; 246 if (!heap->InNewSpace(object) && heap->InNewSpace(first)) return object;
246 247
247 *p = first; 248 *p = first;
248 return HeapObject::cast(first); 249 return HeapObject::cast(first);
249 } 250 }
250 251
251 252
252 class StaticMarkingVisitor : public StaticVisitorBase { 253 class StaticMarkingVisitor : public StaticVisitorBase {
253 public: 254 public:
254 static inline void IterateBody(Map* map, HeapObject* obj) { 255 static inline void IterateBody(Map* map, HeapObject* obj) {
255 table_.GetVisitor(map)(map, obj); 256 table_.GetVisitor(map)(map, obj);
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 Memory::Address_at(free_start + offset) = kZapValue; 1258 Memory::Address_at(free_start + offset) = kZapValue;
1258 } 1259 }
1259 } 1260 }
1260 #endif 1261 #endif
1261 } 1262 }
1262 1263
1263 1264
1264 // Try to promote all objects in new space. Heap numbers and sequential 1265 // 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, 1266 // strings are promoted to the code space, large objects to large object space,
1266 // and all others to the old space. 1267 // and all others to the old space.
1267 inline Object* MCAllocateFromNewSpace(HeapObject* object, int object_size) { 1268 inline Object* MCAllocateFromNewSpace(Heap* heap,
1269 HeapObject* object,
1270 int object_size) {
1268 Object* forwarded; 1271 Object* forwarded;
1269 if (object_size > HEAP->MaxObjectSizeInPagedSpace()) { 1272 if (object_size > heap->MaxObjectSizeInPagedSpace()) {
1270 forwarded = Failure::Exception(); 1273 forwarded = Failure::Exception();
1271 } else { 1274 } else {
1272 OldSpace* target_space = HEAP->TargetSpace(object); 1275 OldSpace* target_space = heap->TargetSpace(object);
1273 ASSERT(target_space == HEAP->old_pointer_space() || 1276 ASSERT(target_space == heap->old_pointer_space() ||
1274 target_space == HEAP->old_data_space()); 1277 target_space == heap->old_data_space());
1275 forwarded = target_space->MCAllocateRaw(object_size); 1278 forwarded = target_space->MCAllocateRaw(object_size);
1276 } 1279 }
1277 if (forwarded->IsFailure()) { 1280 if (forwarded->IsFailure()) {
1278 forwarded = HEAP->new_space()->MCAllocateRaw(object_size); 1281 forwarded = heap->new_space()->MCAllocateRaw(object_size);
1279 } 1282 }
1280 return forwarded; 1283 return forwarded;
1281 } 1284 }
1282 1285
1283 1286
1284 // Allocation functions for the paged spaces call the space's MCAllocateRaw. 1287 // Allocation functions for the paged spaces call the space's MCAllocateRaw.
1285 inline Object* MCAllocateFromOldPointerSpace(HeapObject* ignore, 1288 inline Object* MCAllocateFromOldPointerSpace(Heap* heap,
1289 HeapObject* ignore,
1286 int object_size) { 1290 int object_size) {
1287 return HEAP->old_pointer_space()->MCAllocateRaw(object_size); 1291 return heap->old_pointer_space()->MCAllocateRaw(object_size);
1288 } 1292 }
1289 1293
1290 1294
1291 inline Object* MCAllocateFromOldDataSpace(HeapObject* ignore, int object_size) { 1295 inline Object* MCAllocateFromOldDataSpace(Heap* heap,
1292 return HEAP->old_data_space()->MCAllocateRaw(object_size); 1296 HeapObject* ignore,
1297 int object_size) {
1298 return heap->old_data_space()->MCAllocateRaw(object_size);
1293 } 1299 }
1294 1300
1295 1301
1296 inline Object* MCAllocateFromCodeSpace(HeapObject* ignore, int object_size) { 1302 inline Object* MCAllocateFromCodeSpace(Heap* heap,
1297 return HEAP->code_space()->MCAllocateRaw(object_size); 1303 HeapObject* ignore,
1304 int object_size) {
1305 return heap->code_space()->MCAllocateRaw(object_size);
1298 } 1306 }
1299 1307
1300 1308
1301 inline Object* MCAllocateFromMapSpace(HeapObject* ignore, int object_size) { 1309 inline Object* MCAllocateFromMapSpace(Heap* heap,
1302 return HEAP->map_space()->MCAllocateRaw(object_size); 1310 HeapObject* ignore,
1311 int object_size) {
1312 return heap->map_space()->MCAllocateRaw(object_size);
1303 } 1313 }
1304 1314
1305 1315
1306 inline Object* MCAllocateFromCellSpace(HeapObject* ignore, int object_size) { 1316 inline Object* MCAllocateFromCellSpace(Heap* heap,
1307 return HEAP->cell_space()->MCAllocateRaw(object_size); 1317 HeapObject* ignore,
1318 int object_size) {
1319 return heap->cell_space()->MCAllocateRaw(object_size);
1308 } 1320 }
1309 1321
1310 1322
1311 // The forwarding address is encoded at the same offset as the current 1323 // The forwarding address is encoded at the same offset as the current
1312 // to-space object, but in from space. 1324 // to-space object, but in from space.
1313 inline void EncodeForwardingAddressInNewSpace(HeapObject* old_object, 1325 inline void EncodeForwardingAddressInNewSpace(Heap* heap,
1326 HeapObject* old_object,
1314 int object_size, 1327 int object_size,
1315 Object* new_object, 1328 Object* new_object,
1316 int* ignored) { 1329 int* ignored) {
1317 int offset = 1330 int offset =
1318 HEAP->new_space()->ToSpaceOffsetForAddress(old_object->address()); 1331 heap->new_space()->ToSpaceOffsetForAddress(old_object->address());
1319 Memory::Address_at(HEAP->new_space()->FromSpaceLow() + offset) = 1332 Memory::Address_at(heap->new_space()->FromSpaceLow() + offset) =
1320 HeapObject::cast(new_object)->address(); 1333 HeapObject::cast(new_object)->address();
1321 } 1334 }
1322 1335
1323 1336
1324 // The forwarding address is encoded in the map pointer of the object as an 1337 // The forwarding address is encoded in the map pointer of the object as an
1325 // offset (in terms of live bytes) from the address of the first live object 1338 // offset (in terms of live bytes) from the address of the first live object
1326 // in the page. 1339 // in the page.
1327 inline void EncodeForwardingAddressInPagedSpace(HeapObject* old_object, 1340 inline void EncodeForwardingAddressInPagedSpace(Heap* heap,
1341 HeapObject* old_object,
1328 int object_size, 1342 int object_size,
1329 Object* new_object, 1343 Object* new_object,
1330 int* offset) { 1344 int* offset) {
1331 // Record the forwarding address of the first live object if necessary. 1345 // Record the forwarding address of the first live object if necessary.
1332 if (*offset == 0) { 1346 if (*offset == 0) {
1333 Page::FromAddress(old_object->address())->mc_first_forwarded = 1347 Page::FromAddress(old_object->address())->mc_first_forwarded =
1334 HeapObject::cast(new_object)->address(); 1348 HeapObject::cast(new_object)->address();
1335 } 1349 }
1336 1350
1337 MapWord encoding = 1351 MapWord encoding =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 bool is_prev_alive = true; 1388 bool is_prev_alive = true;
1375 1389
1376 int object_size; // Will be set on each iteration of the loop. 1390 int object_size; // Will be set on each iteration of the loop.
1377 for (Address current = start; current < end; current += object_size) { 1391 for (Address current = start; current < end; current += object_size) {
1378 HeapObject* object = HeapObject::FromAddress(current); 1392 HeapObject* object = HeapObject::FromAddress(current);
1379 if (object->IsMarked()) { 1393 if (object->IsMarked()) {
1380 object->ClearMark(); 1394 object->ClearMark();
1381 collector->tracer()->decrement_marked_count(); 1395 collector->tracer()->decrement_marked_count();
1382 object_size = object->Size(); 1396 object_size = object->Size();
1383 1397
1384 Object* forwarded = Alloc(object, object_size); 1398 Object* forwarded = Alloc(collector->heap(), object, object_size);
1385 // Allocation cannot fail, because we are compacting the space. 1399 // Allocation cannot fail, because we are compacting the space.
1386 ASSERT(!forwarded->IsFailure()); 1400 ASSERT(!forwarded->IsFailure());
1387 Encode(object, object_size, forwarded, offset); 1401 Encode(collector->heap(), object, object_size, forwarded, offset);
1388 1402
1389 #ifdef DEBUG 1403 #ifdef DEBUG
1390 if (FLAG_gc_verbose) { 1404 if (FLAG_gc_verbose) {
1391 PrintF("forward %p -> %p.\n", object->address(), 1405 PrintF("forward %p -> %p.\n", object->address(),
1392 HeapObject::cast(forwarded)->address()); 1406 HeapObject::cast(forwarded)->address());
1393 } 1407 }
1394 #endif 1408 #endif
1395 if (!is_prev_alive) { // Transition from non-live to live. 1409 if (!is_prev_alive) { // Transition from non-live to live.
1396 EncodeFreeRegion(free_start, static_cast<int>(current - free_start)); 1410 EncodeFreeRegion(free_start, static_cast<int>(current - free_start));
1397 is_prev_alive = true; 1411 is_prev_alive = true;
(...skipping 15 matching lines...) Expand all
1413 } 1427 }
1414 1428
1415 1429
1416 // Functions to encode the forwarding pointers in each compactable space. 1430 // Functions to encode the forwarding pointers in each compactable space.
1417 void MarkCompactCollector::EncodeForwardingAddressesInNewSpace() { 1431 void MarkCompactCollector::EncodeForwardingAddressesInNewSpace() {
1418 int ignored; 1432 int ignored;
1419 EncodeForwardingAddressesInRange<MCAllocateFromNewSpace, 1433 EncodeForwardingAddressesInRange<MCAllocateFromNewSpace,
1420 EncodeForwardingAddressInNewSpace, 1434 EncodeForwardingAddressInNewSpace,
1421 IgnoreNonLiveObject>( 1435 IgnoreNonLiveObject>(
1422 this, 1436 this,
1423 HEAP->new_space()->bottom(), 1437 heap_->new_space()->bottom(),
1424 HEAP->new_space()->top(), 1438 heap_->new_space()->top(),
1425 &ignored); 1439 &ignored);
1426 } 1440 }
1427 1441
1428 1442
1429 template<MarkCompactCollector::AllocationFunction Alloc, 1443 template<MarkCompactCollector::AllocationFunction Alloc,
1430 MarkCompactCollector::ProcessNonLiveFunction ProcessNonLive> 1444 MarkCompactCollector::ProcessNonLiveFunction ProcessNonLive>
1431 void MarkCompactCollector::EncodeForwardingAddressesInPagedSpace( 1445 void MarkCompactCollector::EncodeForwardingAddressesInPagedSpace(
1432 PagedSpace* space) { 1446 PagedSpace* space) {
1433 PageIterator it(space, PageIterator::PAGES_IN_USE); 1447 PageIterator it(space, PageIterator::PAGES_IN_USE);
1434 while (it.has_next()) { 1448 while (it.has_next()) {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 space->SetTop(new_allocation_top); 1838 space->SetTop(new_allocation_top);
1825 } 1839 }
1826 } 1840 }
1827 1841
1828 1842
1829 void MarkCompactCollector::EncodeForwardingAddresses() { 1843 void MarkCompactCollector::EncodeForwardingAddresses() {
1830 ASSERT(state_ == ENCODE_FORWARDING_ADDRESSES); 1844 ASSERT(state_ == ENCODE_FORWARDING_ADDRESSES);
1831 // Objects in the active semispace of the young generation may be 1845 // Objects in the active semispace of the young generation may be
1832 // relocated to the inactive semispace (if not promoted). Set the 1846 // relocated to the inactive semispace (if not promoted). Set the
1833 // relocation info to the beginning of the inactive semispace. 1847 // relocation info to the beginning of the inactive semispace.
1834 HEAP->new_space()->MCResetRelocationInfo(); 1848 heap_->new_space()->MCResetRelocationInfo();
1835 1849
1836 // Compute the forwarding pointers in each space. 1850 // Compute the forwarding pointers in each space.
1837 EncodeForwardingAddressesInPagedSpace<MCAllocateFromOldPointerSpace, 1851 EncodeForwardingAddressesInPagedSpace<MCAllocateFromOldPointerSpace,
1838 ReportDeleteIfNeeded>( 1852 ReportDeleteIfNeeded>(
1839 HEAP->old_pointer_space()); 1853 heap_->old_pointer_space());
1840 1854
1841 EncodeForwardingAddressesInPagedSpace<MCAllocateFromOldDataSpace, 1855 EncodeForwardingAddressesInPagedSpace<MCAllocateFromOldDataSpace,
1842 IgnoreNonLiveObject>( 1856 IgnoreNonLiveObject>(
1843 HEAP->old_data_space()); 1857 heap_->old_data_space());
1844 1858
1845 EncodeForwardingAddressesInPagedSpace<MCAllocateFromCodeSpace, 1859 EncodeForwardingAddressesInPagedSpace<MCAllocateFromCodeSpace,
1846 ReportDeleteIfNeeded>( 1860 ReportDeleteIfNeeded>(
1847 HEAP->code_space()); 1861 heap_->code_space());
1848 1862
1849 EncodeForwardingAddressesInPagedSpace<MCAllocateFromCellSpace, 1863 EncodeForwardingAddressesInPagedSpace<MCAllocateFromCellSpace,
1850 IgnoreNonLiveObject>( 1864 IgnoreNonLiveObject>(
1851 HEAP->cell_space()); 1865 heap_->cell_space());
1852 1866
1853 1867
1854 // Compute new space next to last after the old and code spaces have been 1868 // Compute new space next to last after the old and code spaces have been
1855 // compacted. Objects in new space can be promoted to old or code space. 1869 // compacted. Objects in new space can be promoted to old or code space.
1856 EncodeForwardingAddressesInNewSpace(); 1870 EncodeForwardingAddressesInNewSpace();
1857 1871
1858 // Compute map space last because computing forwarding addresses 1872 // Compute map space last because computing forwarding addresses
1859 // overwrites non-live objects. Objects in the other spaces rely on 1873 // overwrites non-live objects. Objects in the other spaces rely on
1860 // non-live map pointers to get the sizes of non-live objects. 1874 // non-live map pointers to get the sizes of non-live objects.
1861 EncodeForwardingAddressesInPagedSpace<MCAllocateFromMapSpace, 1875 EncodeForwardingAddressesInPagedSpace<MCAllocateFromMapSpace,
1862 IgnoreNonLiveObject>( 1876 IgnoreNonLiveObject>(
1863 HEAP->map_space()); 1877 heap_->map_space());
1864 1878
1865 // Write relocation info to the top page, so we can use it later. This is 1879 // Write relocation info to the top page, so we can use it later. This is
1866 // done after promoting objects from the new space so we get the correct 1880 // done after promoting objects from the new space so we get the correct
1867 // allocation top. 1881 // allocation top.
1868 HEAP->old_pointer_space()->MCWriteRelocationInfoToPage(); 1882 heap_->old_pointer_space()->MCWriteRelocationInfoToPage();
1869 HEAP->old_data_space()->MCWriteRelocationInfoToPage(); 1883 heap_->old_data_space()->MCWriteRelocationInfoToPage();
1870 HEAP->code_space()->MCWriteRelocationInfoToPage(); 1884 heap_->code_space()->MCWriteRelocationInfoToPage();
1871 HEAP->map_space()->MCWriteRelocationInfoToPage(); 1885 heap_->map_space()->MCWriteRelocationInfoToPage();
1872 HEAP->cell_space()->MCWriteRelocationInfoToPage(); 1886 heap_->cell_space()->MCWriteRelocationInfoToPage();
1873 } 1887 }
1874 1888
1875 1889
1876 class MapIterator : public HeapObjectIterator { 1890 class MapIterator : public HeapObjectIterator {
1877 public: 1891 public:
1878 MapIterator() : HeapObjectIterator(HEAP->map_space(), &SizeCallback) { } 1892 MapIterator() : HeapObjectIterator(HEAP->map_space(), &SizeCallback) { }
1879 1893
1880 explicit MapIterator(Address start) 1894 explicit MapIterator(Address start)
1881 : HeapObjectIterator(HEAP->map_space(), start, &SizeCallback) { } 1895 : HeapObjectIterator(HEAP->map_space(), start, &SizeCallback) { }
1882 1896
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 ASSERT(map->IsMap()); 2019 ASSERT(map->IsMap());
2006 return map; 2020 return map;
2007 } 2021 }
2008 2022
2009 static void EvacuateMap(Map* vacant_map, Map* map_to_evacuate) { 2023 static void EvacuateMap(Map* vacant_map, Map* map_to_evacuate) {
2010 ASSERT(FreeListNode::IsFreeListNode(vacant_map)); 2024 ASSERT(FreeListNode::IsFreeListNode(vacant_map));
2011 ASSERT(map_to_evacuate->IsMap()); 2025 ASSERT(map_to_evacuate->IsMap());
2012 2026
2013 ASSERT(Map::kSize % 4 == 0); 2027 ASSERT(Map::kSize % 4 == 0);
2014 2028
2015 HEAP->CopyBlockToOldSpaceAndUpdateRegionMarks(vacant_map->address(), 2029 map_to_evacuate->heap()->CopyBlockToOldSpaceAndUpdateRegionMarks(
2016 map_to_evacuate->address(), 2030 vacant_map->address(), map_to_evacuate->address(), Map::kSize);
2017 Map::kSize);
2018 2031
2019 ASSERT(vacant_map->IsMap()); // Due to memcpy above. 2032 ASSERT(vacant_map->IsMap()); // Due to memcpy above.
2020 2033
2021 MapWord forwarding_map_word = MapWord::FromMap(vacant_map); 2034 MapWord forwarding_map_word = MapWord::FromMap(vacant_map);
2022 forwarding_map_word.SetOverflow(); 2035 forwarding_map_word.SetOverflow();
2023 map_to_evacuate->set_map_word(forwarding_map_word); 2036 map_to_evacuate->set_map_word(forwarding_map_word);
2024 2037
2025 ASSERT(map_to_evacuate->map_word().IsOverflowed()); 2038 ASSERT(map_to_evacuate->map_word().IsOverflowed());
2026 ASSERT(GetForwardedMap(map_to_evacuate->map_word()) == vacant_map); 2039 ASSERT(GetForwardedMap(map_to_evacuate->map_word()) == vacant_map);
2027 } 2040 }
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 } 2688 }
2676 2689
2677 2690
2678 void MarkCompactCollector::Initialize() { 2691 void MarkCompactCollector::Initialize() {
2679 StaticPointersToNewGenUpdatingVisitor::Initialize(); 2692 StaticPointersToNewGenUpdatingVisitor::Initialize();
2680 StaticMarkingVisitor::Initialize(); 2693 StaticMarkingVisitor::Initialize();
2681 } 2694 }
2682 2695
2683 2696
2684 } } // namespace v8::internal 2697 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mark-compact.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698