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

Side by Side Diff: src/spaces.cc

Issue 7353017: 2011-07-13: Version 3.4.12 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 5 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/spaces.h ('k') | src/spaces-inl.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 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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } 861 }
862 862
863 863
864 void PagedSpace::TearDown() { 864 void PagedSpace::TearDown() {
865 Isolate::Current()->memory_allocator()->FreeAllPages(this); 865 Isolate::Current()->memory_allocator()->FreeAllPages(this);
866 first_page_ = NULL; 866 first_page_ = NULL;
867 accounting_stats_.Clear(); 867 accounting_stats_.Clear();
868 } 868 }
869 869
870 870
871 #ifdef ENABLE_HEAP_PROTECTION
872
873 void PagedSpace::Protect() {
874 Page* page = first_page_;
875 while (page->is_valid()) {
876 Isolate::Current()->memory_allocator()->ProtectChunkFromPage(page);
877 page = Isolate::Current()->memory_allocator()->
878 FindLastPageInSameChunk(page)->next_page();
879 }
880 }
881
882
883 void PagedSpace::Unprotect() {
884 Page* page = first_page_;
885 while (page->is_valid()) {
886 Isolate::Current()->memory_allocator()->UnprotectChunkFromPage(page);
887 page = Isolate::Current()->memory_allocator()->
888 FindLastPageInSameChunk(page)->next_page();
889 }
890 }
891
892 #endif
893
894
895 void PagedSpace::MarkAllPagesClean() { 871 void PagedSpace::MarkAllPagesClean() {
896 PageIterator it(this, PageIterator::ALL_PAGES); 872 PageIterator it(this, PageIterator::ALL_PAGES);
897 while (it.has_next()) { 873 while (it.has_next()) {
898 it.next()->SetRegionMarks(Page::kAllRegionsCleanMarks); 874 it.next()->SetRegionMarks(Page::kAllRegionsCleanMarks);
899 } 875 }
900 } 876 }
901 877
902 878
903 MaybeObject* PagedSpace::FindObject(Address addr) { 879 MaybeObject* PagedSpace::FindObject(Address addr) {
904 // Note: this function can only be called before or after mark-compact GC 880 // Note: this function can only be called before or after mark-compact GC
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // start and size. The provided space is divided into two semi-spaces. 1165 // start and size. The provided space is divided into two semi-spaces.
1190 // To support fast containment testing in the new space, the size of 1166 // To support fast containment testing in the new space, the size of
1191 // this chunk must be a power of two and it must be aligned to its size. 1167 // this chunk must be a power of two and it must be aligned to its size.
1192 int initial_semispace_capacity = heap()->InitialSemiSpaceSize(); 1168 int initial_semispace_capacity = heap()->InitialSemiSpaceSize();
1193 int maximum_semispace_capacity = heap()->MaxSemiSpaceSize(); 1169 int maximum_semispace_capacity = heap()->MaxSemiSpaceSize();
1194 1170
1195 ASSERT(initial_semispace_capacity <= maximum_semispace_capacity); 1171 ASSERT(initial_semispace_capacity <= maximum_semispace_capacity);
1196 ASSERT(IsPowerOf2(maximum_semispace_capacity)); 1172 ASSERT(IsPowerOf2(maximum_semispace_capacity));
1197 1173
1198 // Allocate and setup the histogram arrays if necessary. 1174 // Allocate and setup the histogram arrays if necessary.
1199 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1200 allocated_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1); 1175 allocated_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1);
1201 promoted_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1); 1176 promoted_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1);
1202 1177
1203 #define SET_NAME(name) allocated_histogram_[name].set_name(#name); \ 1178 #define SET_NAME(name) allocated_histogram_[name].set_name(#name); \
1204 promoted_histogram_[name].set_name(#name); 1179 promoted_histogram_[name].set_name(#name);
1205 INSTANCE_TYPE_LIST(SET_NAME) 1180 INSTANCE_TYPE_LIST(SET_NAME)
1206 #undef SET_NAME 1181 #undef SET_NAME
1207 #endif
1208 1182
1209 ASSERT(size == 2 * heap()->ReservedSemiSpaceSize()); 1183 ASSERT(size == 2 * heap()->ReservedSemiSpaceSize());
1210 ASSERT(IsAddressAligned(start, size, 0)); 1184 ASSERT(IsAddressAligned(start, size, 0));
1211 1185
1212 if (!to_space_.Setup(start, 1186 if (!to_space_.Setup(start,
1213 initial_semispace_capacity, 1187 initial_semispace_capacity,
1214 maximum_semispace_capacity)) { 1188 maximum_semispace_capacity)) {
1215 return false; 1189 return false;
1216 } 1190 }
1217 if (!from_space_.Setup(start + maximum_semispace_capacity, 1191 if (!from_space_.Setup(start + maximum_semispace_capacity,
(...skipping 11 matching lines...) Expand all
1229 allocation_info_.limit = to_space_.high(); 1203 allocation_info_.limit = to_space_.high();
1230 mc_forwarding_info_.top = NULL; 1204 mc_forwarding_info_.top = NULL;
1231 mc_forwarding_info_.limit = NULL; 1205 mc_forwarding_info_.limit = NULL;
1232 1206
1233 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); 1207 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
1234 return true; 1208 return true;
1235 } 1209 }
1236 1210
1237 1211
1238 void NewSpace::TearDown() { 1212 void NewSpace::TearDown() {
1239 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1240 if (allocated_histogram_) { 1213 if (allocated_histogram_) {
1241 DeleteArray(allocated_histogram_); 1214 DeleteArray(allocated_histogram_);
1242 allocated_histogram_ = NULL; 1215 allocated_histogram_ = NULL;
1243 } 1216 }
1244 if (promoted_histogram_) { 1217 if (promoted_histogram_) {
1245 DeleteArray(promoted_histogram_); 1218 DeleteArray(promoted_histogram_);
1246 promoted_histogram_ = NULL; 1219 promoted_histogram_ = NULL;
1247 } 1220 }
1248 #endif
1249 1221
1250 start_ = NULL; 1222 start_ = NULL;
1251 allocation_info_.top = NULL; 1223 allocation_info_.top = NULL;
1252 allocation_info_.limit = NULL; 1224 allocation_info_.limit = NULL;
1253 mc_forwarding_info_.top = NULL; 1225 mc_forwarding_info_.top = NULL;
1254 mc_forwarding_info_.limit = NULL; 1226 mc_forwarding_info_.limit = NULL;
1255 1227
1256 to_space_.TearDown(); 1228 to_space_.TearDown();
1257 from_space_.TearDown(); 1229 from_space_.TearDown();
1258 } 1230 }
1259 1231
1260 1232
1261 #ifdef ENABLE_HEAP_PROTECTION
1262
1263 void NewSpace::Protect() {
1264 heap()->isolate()->memory_allocator()->Protect(ToSpaceLow(), Capacity());
1265 heap()->isolate()->memory_allocator()->Protect(FromSpaceLow(), Capacity());
1266 }
1267
1268
1269 void NewSpace::Unprotect() {
1270 heap()->isolate()->memory_allocator()->Unprotect(ToSpaceLow(), Capacity(),
1271 to_space_.executable());
1272 heap()->isolate()->memory_allocator()->Unprotect(FromSpaceLow(), Capacity(),
1273 from_space_.executable());
1274 }
1275
1276 #endif
1277
1278
1279 void NewSpace::Flip() { 1233 void NewSpace::Flip() {
1280 SemiSpace tmp = from_space_; 1234 SemiSpace tmp = from_space_;
1281 from_space_ = to_space_; 1235 from_space_ = to_space_;
1282 to_space_ = tmp; 1236 to_space_ = tmp;
1283 } 1237 }
1284 1238
1285 1239
1286 void NewSpace::Grow() { 1240 void NewSpace::Grow() {
1287 ASSERT(Capacity() < MaximumCapacity()); 1241 ASSERT(Capacity() < MaximumCapacity());
1288 if (to_space_.Grow()) { 1242 if (to_space_.Grow()) {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 } 1585 }
1632 1586
1633 if (FLAG_collect_heap_spill_statistics && print_spill) { 1587 if (FLAG_collect_heap_spill_statistics && print_spill) {
1634 isolate->js_spill_information()->Print(); 1588 isolate->js_spill_information()->Print();
1635 } 1589 }
1636 } 1590 }
1637 #endif // DEBUG 1591 #endif // DEBUG
1638 1592
1639 1593
1640 // Support for statistics gathering for --heap-stats and --log-gc. 1594 // Support for statistics gathering for --heap-stats and --log-gc.
1641 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1642 void NewSpace::ClearHistograms() { 1595 void NewSpace::ClearHistograms() {
1643 for (int i = 0; i <= LAST_TYPE; i++) { 1596 for (int i = 0; i <= LAST_TYPE; i++) {
1644 allocated_histogram_[i].clear(); 1597 allocated_histogram_[i].clear();
1645 promoted_histogram_[i].clear(); 1598 promoted_histogram_[i].clear();
1646 } 1599 }
1647 } 1600 }
1648 1601
1649 // Because the copying collector does not touch garbage objects, we iterate 1602 // Because the copying collector does not touch garbage objects, we iterate
1650 // the new space before a collection to get a histogram of allocated objects. 1603 // the new space before a collection to get a histogram of allocated objects.
1651 // This only happens (1) when compiled with DEBUG and the --heap-stats flag is 1604 // This only happens when --log-gc flag is set.
1652 // set, or when compiled with ENABLE_LOGGING_AND_PROFILING and the --log-gc
1653 // flag is set.
1654 void NewSpace::CollectStatistics() { 1605 void NewSpace::CollectStatistics() {
1655 ClearHistograms(); 1606 ClearHistograms();
1656 SemiSpaceIterator it(this); 1607 SemiSpaceIterator it(this);
1657 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) 1608 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next())
1658 RecordAllocation(obj); 1609 RecordAllocation(obj);
1659 } 1610 }
1660 1611
1661 1612
1662 #ifdef ENABLE_LOGGING_AND_PROFILING
1663 static void DoReportStatistics(Isolate* isolate, 1613 static void DoReportStatistics(Isolate* isolate,
1664 HistogramInfo* info, const char* description) { 1614 HistogramInfo* info, const char* description) {
1665 LOG(isolate, HeapSampleBeginEvent("NewSpace", description)); 1615 LOG(isolate, HeapSampleBeginEvent("NewSpace", description));
1666 // Lump all the string types together. 1616 // Lump all the string types together.
1667 int string_number = 0; 1617 int string_number = 0;
1668 int string_bytes = 0; 1618 int string_bytes = 0;
1669 #define INCREMENT(type, size, name, camel_name) \ 1619 #define INCREMENT(type, size, name, camel_name) \
1670 string_number += info[type].number(); \ 1620 string_number += info[type].number(); \
1671 string_bytes += info[type].bytes(); 1621 string_bytes += info[type].bytes();
1672 STRING_TYPE_LIST(INCREMENT) 1622 STRING_TYPE_LIST(INCREMENT)
1673 #undef INCREMENT 1623 #undef INCREMENT
1674 if (string_number > 0) { 1624 if (string_number > 0) {
1675 LOG(isolate, 1625 LOG(isolate,
1676 HeapSampleItemEvent("STRING_TYPE", string_number, string_bytes)); 1626 HeapSampleItemEvent("STRING_TYPE", string_number, string_bytes));
1677 } 1627 }
1678 1628
1679 // Then do the other types. 1629 // Then do the other types.
1680 for (int i = FIRST_NONSTRING_TYPE; i <= LAST_TYPE; ++i) { 1630 for (int i = FIRST_NONSTRING_TYPE; i <= LAST_TYPE; ++i) {
1681 if (info[i].number() > 0) { 1631 if (info[i].number() > 0) {
1682 LOG(isolate, 1632 LOG(isolate,
1683 HeapSampleItemEvent(info[i].name(), info[i].number(), 1633 HeapSampleItemEvent(info[i].name(), info[i].number(),
1684 info[i].bytes())); 1634 info[i].bytes()));
1685 } 1635 }
1686 } 1636 }
1687 LOG(isolate, HeapSampleEndEvent("NewSpace", description)); 1637 LOG(isolate, HeapSampleEndEvent("NewSpace", description));
1688 } 1638 }
1689 #endif // ENABLE_LOGGING_AND_PROFILING
1690 1639
1691 1640
1692 void NewSpace::ReportStatistics() { 1641 void NewSpace::ReportStatistics() {
1693 #ifdef DEBUG 1642 #ifdef DEBUG
1694 if (FLAG_heap_stats) { 1643 if (FLAG_heap_stats) {
1695 float pct = static_cast<float>(Available()) / Capacity(); 1644 float pct = static_cast<float>(Available()) / Capacity();
1696 PrintF(" capacity: %" V8_PTR_PREFIX "d" 1645 PrintF(" capacity: %" V8_PTR_PREFIX "d"
1697 ", available: %" V8_PTR_PREFIX "d, %%%d\n", 1646 ", available: %" V8_PTR_PREFIX "d, %%%d\n",
1698 Capacity(), Available(), static_cast<int>(pct*100)); 1647 Capacity(), Available(), static_cast<int>(pct*100));
1699 PrintF("\n Object Histogram:\n"); 1648 PrintF("\n Object Histogram:\n");
1700 for (int i = 0; i <= LAST_TYPE; i++) { 1649 for (int i = 0; i <= LAST_TYPE; i++) {
1701 if (allocated_histogram_[i].number() > 0) { 1650 if (allocated_histogram_[i].number() > 0) {
1702 PrintF(" %-34s%10d (%10d bytes)\n", 1651 PrintF(" %-34s%10d (%10d bytes)\n",
1703 allocated_histogram_[i].name(), 1652 allocated_histogram_[i].name(),
1704 allocated_histogram_[i].number(), 1653 allocated_histogram_[i].number(),
1705 allocated_histogram_[i].bytes()); 1654 allocated_histogram_[i].bytes());
1706 } 1655 }
1707 } 1656 }
1708 PrintF("\n"); 1657 PrintF("\n");
1709 } 1658 }
1710 #endif // DEBUG 1659 #endif // DEBUG
1711 1660
1712 #ifdef ENABLE_LOGGING_AND_PROFILING
1713 if (FLAG_log_gc) { 1661 if (FLAG_log_gc) {
1714 Isolate* isolate = ISOLATE; 1662 Isolate* isolate = ISOLATE;
1715 DoReportStatistics(isolate, allocated_histogram_, "allocated"); 1663 DoReportStatistics(isolate, allocated_histogram_, "allocated");
1716 DoReportStatistics(isolate, promoted_histogram_, "promoted"); 1664 DoReportStatistics(isolate, promoted_histogram_, "promoted");
1717 } 1665 }
1718 #endif // ENABLE_LOGGING_AND_PROFILING
1719 } 1666 }
1720 1667
1721 1668
1722 void NewSpace::RecordAllocation(HeapObject* obj) { 1669 void NewSpace::RecordAllocation(HeapObject* obj) {
1723 InstanceType type = obj->map()->instance_type(); 1670 InstanceType type = obj->map()->instance_type();
1724 ASSERT(0 <= type && type <= LAST_TYPE); 1671 ASSERT(0 <= type && type <= LAST_TYPE);
1725 allocated_histogram_[type].increment_number(1); 1672 allocated_histogram_[type].increment_number(1);
1726 allocated_histogram_[type].increment_bytes(obj->Size()); 1673 allocated_histogram_[type].increment_bytes(obj->Size());
1727 } 1674 }
1728 1675
1729 1676
1730 void NewSpace::RecordPromotion(HeapObject* obj) { 1677 void NewSpace::RecordPromotion(HeapObject* obj) {
1731 InstanceType type = obj->map()->instance_type(); 1678 InstanceType type = obj->map()->instance_type();
1732 ASSERT(0 <= type && type <= LAST_TYPE); 1679 ASSERT(0 <= type && type <= LAST_TYPE);
1733 promoted_histogram_[type].increment_number(1); 1680 promoted_histogram_[type].increment_number(1);
1734 promoted_histogram_[type].increment_bytes(obj->Size()); 1681 promoted_histogram_[type].increment_bytes(obj->Size());
1735 } 1682 }
1736 #endif // defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1737 1683
1738 1684
1739 // ----------------------------------------------------------------------------- 1685 // -----------------------------------------------------------------------------
1740 // Free lists for old object spaces implementation 1686 // Free lists for old object spaces implementation
1741 1687
1742 void FreeListNode::set_size(Heap* heap, int size_in_bytes) { 1688 void FreeListNode::set_size(Heap* heap, int size_in_bytes) {
1743 ASSERT(size_in_bytes > 0); 1689 ASSERT(size_in_bytes > 0);
1744 ASSERT(IsAligned(size_in_bytes, kPointerSize)); 1690 ASSERT(IsAligned(size_in_bytes, kPointerSize));
1745 1691
1746 // We write a map and possibly size information to the block. If the block 1692 // We write a map and possibly size information to the block. If the block
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 heap()->isolate()->memory_allocator()->PerformAllocationCallback( 2748 heap()->isolate()->memory_allocator()->PerformAllocationCallback(
2803 space, kAllocationActionFree, size); 2749 space, kAllocationActionFree, size);
2804 } 2750 }
2805 2751
2806 size_ = 0; 2752 size_ = 0;
2807 page_count_ = 0; 2753 page_count_ = 0;
2808 objects_size_ = 0; 2754 objects_size_ = 0;
2809 } 2755 }
2810 2756
2811 2757
2812 #ifdef ENABLE_HEAP_PROTECTION
2813
2814 void LargeObjectSpace::Protect() {
2815 LargeObjectChunk* chunk = first_chunk_;
2816 while (chunk != NULL) {
2817 heap()->isolate()->memory_allocator()->Protect(chunk->address(),
2818 chunk->size());
2819 chunk = chunk->next();
2820 }
2821 }
2822
2823
2824 void LargeObjectSpace::Unprotect() {
2825 LargeObjectChunk* chunk = first_chunk_;
2826 while (chunk != NULL) {
2827 bool is_code = chunk->GetObject()->IsCode();
2828 heap()->isolate()->memory_allocator()->Unprotect(chunk->address(),
2829 chunk->size(), is_code ? EXECUTABLE : NOT_EXECUTABLE);
2830 chunk = chunk->next();
2831 }
2832 }
2833
2834 #endif
2835
2836
2837 MaybeObject* LargeObjectSpace::AllocateRawInternal(int requested_size, 2758 MaybeObject* LargeObjectSpace::AllocateRawInternal(int requested_size,
2838 int object_size, 2759 int object_size,
2839 Executability executable) { 2760 Executability executable) {
2840 ASSERT(0 < object_size && object_size <= requested_size); 2761 ASSERT(0 < object_size && object_size <= requested_size);
2841 2762
2842 // Check if we want to force a GC before growing the old space further. 2763 // Check if we want to force a GC before growing the old space further.
2843 // If so, fail the allocation. 2764 // If so, fail the allocation.
2844 if (!heap()->always_allocate() && 2765 if (!heap()->always_allocate() &&
2845 heap()->OldGenerationAllocationLimitReached()) { 2766 heap()->OldGenerationAllocationLimitReached()) {
2846 return Failure::RetryAfterGC(identity()); 2767 return Failure::RetryAfterGC(identity());
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
3136 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { 3057 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) {
3137 if (obj->IsCode()) { 3058 if (obj->IsCode()) {
3138 Code* code = Code::cast(obj); 3059 Code* code = Code::cast(obj);
3139 isolate->code_kind_statistics()[code->kind()] += code->Size(); 3060 isolate->code_kind_statistics()[code->kind()] += code->Size();
3140 } 3061 }
3141 } 3062 }
3142 } 3063 }
3143 #endif // DEBUG 3064 #endif // DEBUG
3144 3065
3145 } } // namespace v8::internal 3066 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/spaces.h ('k') | src/spaces-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698