| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 441   chunk->heap_ = heap; | 441   chunk->heap_ = heap; | 
| 442   chunk->size_ = size; | 442   chunk->size_ = size; | 
| 443   chunk->area_start_ = area_start; | 443   chunk->area_start_ = area_start; | 
| 444   chunk->area_end_ = area_end; | 444   chunk->area_end_ = area_end; | 
| 445   chunk->flags_ = 0; | 445   chunk->flags_ = 0; | 
| 446   chunk->set_owner(owner); | 446   chunk->set_owner(owner); | 
| 447   chunk->InitializeReservedMemory(); | 447   chunk->InitializeReservedMemory(); | 
| 448   chunk->slots_buffer_ = NULL; | 448   chunk->slots_buffer_ = NULL; | 
| 449   chunk->skip_list_ = NULL; | 449   chunk->skip_list_ = NULL; | 
| 450   chunk->write_barrier_counter_ = kWriteBarrierCounterGranularity; | 450   chunk->write_barrier_counter_ = kWriteBarrierCounterGranularity; | 
|  | 451   chunk->high_water_mark_ = area_start - base; | 
| 451   chunk->ResetLiveBytes(); | 452   chunk->ResetLiveBytes(); | 
| 452   Bitmap::Clear(chunk); | 453   Bitmap::Clear(chunk); | 
| 453   chunk->initialize_scan_on_scavenge(false); | 454   chunk->initialize_scan_on_scavenge(false); | 
| 454   chunk->SetFlag(WAS_SWEPT_PRECISELY); | 455   chunk->SetFlag(WAS_SWEPT_PRECISELY); | 
| 455 | 456 | 
| 456   ASSERT(OFFSET_OF(MemoryChunk, flags_) == kFlagsOffset); | 457   ASSERT(OFFSET_OF(MemoryChunk, flags_) == kFlagsOffset); | 
| 457   ASSERT(OFFSET_OF(MemoryChunk, live_byte_count_) == kLiveBytesOffset); | 458   ASSERT(OFFSET_OF(MemoryChunk, live_byte_count_) == kLiveBytesOffset); | 
| 458 | 459 | 
| 459   if (executable == EXECUTABLE) { | 460   if (executable == EXECUTABLE) { | 
| 460     chunk->SetFlag(IS_EXECUTABLE); | 461     chunk->SetFlag(IS_EXECUTABLE); | 
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 813   PageIterator iterator(this); | 814   PageIterator iterator(this); | 
| 814   while (iterator.has_next()) { | 815   while (iterator.has_next()) { | 
| 815     heap()->isolate()->memory_allocator()->Free(iterator.next()); | 816     heap()->isolate()->memory_allocator()->Free(iterator.next()); | 
| 816   } | 817   } | 
| 817   anchor_.set_next_page(&anchor_); | 818   anchor_.set_next_page(&anchor_); | 
| 818   anchor_.set_prev_page(&anchor_); | 819   anchor_.set_prev_page(&anchor_); | 
| 819   accounting_stats_.Clear(); | 820   accounting_stats_.Clear(); | 
| 820 } | 821 } | 
| 821 | 822 | 
| 822 | 823 | 
|  | 824 size_t PagedSpace::CommittedPhysicalMemory() { | 
|  | 825   if (!VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 
|  | 826   MemoryChunk::UpdateHighWaterMark(allocation_info_.top); | 
|  | 827   size_t size = 0; | 
|  | 828   PageIterator it(this); | 
|  | 829   while (it.has_next()) { | 
|  | 830     size += it.next()->CommittedPhysicalMemory(); | 
|  | 831   } | 
|  | 832   return size; | 
|  | 833 } | 
|  | 834 | 
|  | 835 | 
| 823 MaybeObject* PagedSpace::FindObject(Address addr) { | 836 MaybeObject* PagedSpace::FindObject(Address addr) { | 
| 824   // Note: this function can only be called on precisely swept spaces. | 837   // Note: this function can only be called on precisely swept spaces. | 
| 825   ASSERT(!heap()->mark_compact_collector()->in_use()); | 838   ASSERT(!heap()->mark_compact_collector()->in_use()); | 
| 826 | 839 | 
| 827   if (!Contains(addr)) return Failure::Exception(); | 840   if (!Contains(addr)) return Failure::Exception(); | 
| 828 | 841 | 
| 829   Page* p = Page::FromAddress(addr); | 842   Page* p = Page::FromAddress(addr); | 
| 830   HeapObjectIterator it(p, NULL); | 843   HeapObjectIterator it(p, NULL); | 
| 831   for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 844   for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 
| 832     Address cur = obj->address(); | 845     Address cur = obj->address(); | 
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1166         V8::FatalProcessOutOfMemory("Failed to shrink new space."); | 1179         V8::FatalProcessOutOfMemory("Failed to shrink new space."); | 
| 1167       } | 1180       } | 
| 1168     } | 1181     } | 
| 1169   } | 1182   } | 
| 1170   allocation_info_.limit = to_space_.page_high(); | 1183   allocation_info_.limit = to_space_.page_high(); | 
| 1171   ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1184   ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 
| 1172 } | 1185 } | 
| 1173 | 1186 | 
| 1174 | 1187 | 
| 1175 void NewSpace::UpdateAllocationInfo() { | 1188 void NewSpace::UpdateAllocationInfo() { | 
|  | 1189   MemoryChunk::UpdateHighWaterMark(allocation_info_.top); | 
| 1176   allocation_info_.top = to_space_.page_low(); | 1190   allocation_info_.top = to_space_.page_low(); | 
| 1177   allocation_info_.limit = to_space_.page_high(); | 1191   allocation_info_.limit = to_space_.page_high(); | 
| 1178 | 1192 | 
| 1179   // Lower limit during incremental marking. | 1193   // Lower limit during incremental marking. | 
| 1180   if (heap()->incremental_marking()->IsMarking() && | 1194   if (heap()->incremental_marking()->IsMarking() && | 
| 1181       inline_allocation_limit_step() != 0) { | 1195       inline_allocation_limit_step() != 0) { | 
| 1182     Address new_limit = | 1196     Address new_limit = | 
| 1183         allocation_info_.top + inline_allocation_limit_step(); | 1197         allocation_info_.top + inline_allocation_limit_step(); | 
| 1184     allocation_info_.limit = Min(new_limit, allocation_info_.limit); | 1198     allocation_info_.limit = Min(new_limit, allocation_info_.limit); | 
| 1185   } | 1199   } | 
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1378     return false; | 1392     return false; | 
| 1379   } | 1393   } | 
| 1380   anchor()->set_next_page(anchor()); | 1394   anchor()->set_next_page(anchor()); | 
| 1381   anchor()->set_prev_page(anchor()); | 1395   anchor()->set_prev_page(anchor()); | 
| 1382 | 1396 | 
| 1383   committed_ = false; | 1397   committed_ = false; | 
| 1384   return true; | 1398   return true; | 
| 1385 } | 1399 } | 
| 1386 | 1400 | 
| 1387 | 1401 | 
|  | 1402 size_t SemiSpace::CommittedPhysicalMemory() { | 
|  | 1403   if (!is_committed()) return 0; | 
|  | 1404   size_t size = 0; | 
|  | 1405   NewSpacePageIterator it(this); | 
|  | 1406   while (it.has_next()) { | 
|  | 1407     size += it.next()->CommittedPhysicalMemory(); | 
|  | 1408   } | 
|  | 1409   return size; | 
|  | 1410 } | 
|  | 1411 | 
|  | 1412 | 
| 1388 bool SemiSpace::GrowTo(int new_capacity) { | 1413 bool SemiSpace::GrowTo(int new_capacity) { | 
| 1389   if (!is_committed()) { | 1414   if (!is_committed()) { | 
| 1390     if (!Commit()) return false; | 1415     if (!Commit()) return false; | 
| 1391   } | 1416   } | 
| 1392   ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); | 1417   ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); | 
| 1393   ASSERT(new_capacity <= maximum_capacity_); | 1418   ASSERT(new_capacity <= maximum_capacity_); | 
| 1394   ASSERT(new_capacity > capacity_); | 1419   ASSERT(new_capacity > capacity_); | 
| 1395   int pages_before = capacity_ / Page::kPageSize; | 1420   int pages_before = capacity_ / Page::kPageSize; | 
| 1396   int pages_after = new_capacity / Page::kPageSize; | 1421   int pages_after = new_capacity / Page::kPageSize; | 
| 1397 | 1422 | 
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1810 } | 1835 } | 
| 1811 | 1836 | 
| 1812 | 1837 | 
| 1813 void NewSpace::RecordPromotion(HeapObject* obj) { | 1838 void NewSpace::RecordPromotion(HeapObject* obj) { | 
| 1814   InstanceType type = obj->map()->instance_type(); | 1839   InstanceType type = obj->map()->instance_type(); | 
| 1815   ASSERT(0 <= type && type <= LAST_TYPE); | 1840   ASSERT(0 <= type && type <= LAST_TYPE); | 
| 1816   promoted_histogram_[type].increment_number(1); | 1841   promoted_histogram_[type].increment_number(1); | 
| 1817   promoted_histogram_[type].increment_bytes(obj->Size()); | 1842   promoted_histogram_[type].increment_bytes(obj->Size()); | 
| 1818 } | 1843 } | 
| 1819 | 1844 | 
|  | 1845 | 
|  | 1846 size_t NewSpace::CommittedPhysicalMemory() { | 
|  | 1847   if (!VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 
|  | 1848   MemoryChunk::UpdateHighWaterMark(allocation_info_.top); | 
|  | 1849   size_t size = to_space_.CommittedPhysicalMemory(); | 
|  | 1850   if (from_space_.is_committed()) { | 
|  | 1851     size += from_space_.CommittedPhysicalMemory(); | 
|  | 1852   } | 
|  | 1853   return size; | 
|  | 1854 } | 
|  | 1855 | 
| 1820 // ----------------------------------------------------------------------------- | 1856 // ----------------------------------------------------------------------------- | 
| 1821 // Free lists for old object spaces implementation | 1857 // Free lists for old object spaces implementation | 
| 1822 | 1858 | 
| 1823 void FreeListNode::set_size(Heap* heap, int size_in_bytes) { | 1859 void FreeListNode::set_size(Heap* heap, int size_in_bytes) { | 
| 1824   ASSERT(size_in_bytes > 0); | 1860   ASSERT(size_in_bytes > 0); | 
| 1825   ASSERT(IsAligned(size_in_bytes, kPointerSize)); | 1861   ASSERT(IsAligned(size_in_bytes, kPointerSize)); | 
| 1826 | 1862 | 
| 1827   // We write a map and possibly size information to the block.  If the block | 1863   // We write a map and possibly size information to the block.  If the block | 
| 1828   // is big enough to be a FreeSpace with at least one extra word (the next | 1864   // is big enough to be a FreeSpace with at least one extra word (the next | 
| 1829   // pointer), we set its map to be the free space map and its size to an | 1865   // pointer), we set its map to be the free space map and its size to an | 
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2684   reinterpret_cast<Object**>(object->address())[0] = | 2720   reinterpret_cast<Object**>(object->address())[0] = | 
| 2685       heap()->fixed_array_map(); | 2721       heap()->fixed_array_map(); | 
| 2686   reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 2722   reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 
| 2687 #endif | 2723 #endif | 
| 2688 | 2724 | 
| 2689   heap()->incremental_marking()->OldSpaceStep(object_size); | 2725   heap()->incremental_marking()->OldSpaceStep(object_size); | 
| 2690   return object; | 2726   return object; | 
| 2691 } | 2727 } | 
| 2692 | 2728 | 
| 2693 | 2729 | 
|  | 2730 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 
|  | 2731   if (!VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 
|  | 2732   size_t size = 0; | 
|  | 2733   LargePage* current = first_page_; | 
|  | 2734   while (current != NULL) { | 
|  | 2735     size += current->CommittedPhysicalMemory(); | 
|  | 2736     current = current->next_page(); | 
|  | 2737   } | 
|  | 2738   return size; | 
|  | 2739 } | 
|  | 2740 | 
|  | 2741 | 
| 2694 // GC support | 2742 // GC support | 
| 2695 MaybeObject* LargeObjectSpace::FindObject(Address a) { | 2743 MaybeObject* LargeObjectSpace::FindObject(Address a) { | 
| 2696   LargePage* page = FindPage(a); | 2744   LargePage* page = FindPage(a); | 
| 2697   if (page != NULL) { | 2745   if (page != NULL) { | 
| 2698     return page->GetObject(); | 2746     return page->GetObject(); | 
| 2699   } | 2747   } | 
| 2700   return Failure::Exception(); | 2748   return Failure::Exception(); | 
| 2701 } | 2749 } | 
| 2702 | 2750 | 
| 2703 | 2751 | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2888     object->ShortPrint(); | 2936     object->ShortPrint(); | 
| 2889     PrintF("\n"); | 2937     PrintF("\n"); | 
| 2890   } | 2938   } | 
| 2891   printf(" --------------------------------------\n"); | 2939   printf(" --------------------------------------\n"); | 
| 2892   printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 2940   printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 
| 2893 } | 2941 } | 
| 2894 | 2942 | 
| 2895 #endif  // DEBUG | 2943 #endif  // DEBUG | 
| 2896 | 2944 | 
| 2897 } }  // namespace v8::internal | 2945 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|