| 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 chunk_size_ = 0; | 917 chunk_size_ = 0; |
| 918 } | 918 } |
| 919 | 919 |
| 920 | 920 |
| 921 void NewSpace::Flip() { | 921 void NewSpace::Flip() { |
| 922 SemiSpace::Swap(&from_space_, &to_space_); | 922 SemiSpace::Swap(&from_space_, &to_space_); |
| 923 } | 923 } |
| 924 | 924 |
| 925 | 925 |
| 926 void NewSpace::Grow() { | 926 void NewSpace::Grow() { |
| 927 // Double the semispace size but only up to maximum capacity. |
| 927 ASSERT(Capacity() < MaximumCapacity()); | 928 ASSERT(Capacity() < MaximumCapacity()); |
| 928 if (to_space_.Grow()) { | 929 int new_capacity = Min(MaximumCapacity(), 2 * static_cast<int>(Capacity())); |
| 930 if (to_space_.GrowTo(new_capacity)) { |
| 929 // Only grow from space if we managed to grow to-space. | 931 // Only grow from space if we managed to grow to-space. |
| 930 if (!from_space_.Grow()) { | 932 if (!from_space_.GrowTo(new_capacity)) { |
| 931 // If we managed to grow to-space but couldn't grow from-space, | 933 // If we managed to grow to-space but couldn't grow from-space, |
| 932 // attempt to shrink to-space. | 934 // attempt to shrink to-space. |
| 933 if (!to_space_.ShrinkTo(from_space_.Capacity())) { | 935 if (!to_space_.ShrinkTo(from_space_.Capacity())) { |
| 934 // We are in an inconsistent state because we could not | 936 // We are in an inconsistent state because we could not |
| 935 // commit/uncommit memory from new space. | 937 // commit/uncommit memory from new space. |
| 936 V8::FatalProcessOutOfMemory("Failed to grow new space."); | 938 V8::FatalProcessOutOfMemory("Failed to grow new space."); |
| 937 } | 939 } |
| 938 } | 940 } |
| 939 } | 941 } |
| 940 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 942 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
| 941 } | 943 } |
| 942 | 944 |
| 943 | 945 |
| 944 void NewSpace::Shrink() { | 946 void NewSpace::Shrink() { |
| 945 int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt()); | 947 int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt()); |
| 946 int rounded_new_capacity = | 948 int rounded_new_capacity = RoundUp(new_capacity, Page::kPageSize); |
| 947 RoundUp(new_capacity, static_cast<int>(OS::AllocateAlignment())); | |
| 948 if (rounded_new_capacity < Capacity() && | 949 if (rounded_new_capacity < Capacity() && |
| 949 to_space_.ShrinkTo(rounded_new_capacity)) { | 950 to_space_.ShrinkTo(rounded_new_capacity)) { |
| 950 // Only shrink from-space if we managed to shrink to-space. | 951 // Only shrink from-space if we managed to shrink to-space. |
| 951 from_space_.Reset(); | 952 from_space_.Reset(); |
| 952 if (!from_space_.ShrinkTo(rounded_new_capacity)) { | 953 if (!from_space_.ShrinkTo(rounded_new_capacity)) { |
| 953 // If we managed to shrink to-space but couldn't shrink from | 954 // If we managed to shrink to-space but couldn't shrink from |
| 954 // space, attempt to grow to-space again. | 955 // space, attempt to grow to-space again. |
| 955 if (!to_space_.GrowTo(from_space_.Capacity())) { | 956 if (!to_space_.GrowTo(from_space_.Capacity())) { |
| 956 // We are in an inconsistent state because we could not | 957 // We are in an inconsistent state because we could not |
| 957 // commit/uncommit memory from new space. | 958 // commit/uncommit memory from new space. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 return false; | 1138 return false; |
| 1138 } | 1139 } |
| 1139 anchor()->set_next_page(anchor()); | 1140 anchor()->set_next_page(anchor()); |
| 1140 anchor()->set_prev_page(anchor()); | 1141 anchor()->set_prev_page(anchor()); |
| 1141 | 1142 |
| 1142 committed_ = false; | 1143 committed_ = false; |
| 1143 return true; | 1144 return true; |
| 1144 } | 1145 } |
| 1145 | 1146 |
| 1146 | 1147 |
| 1147 bool SemiSpace::Grow() { | |
| 1148 // Double the semispace size but only up to maximum capacity. | |
| 1149 ASSERT(static_cast<size_t>(Page::kPageSize) > OS::AllocateAlignment()); | |
| 1150 int new_capacity = Min(maximum_capacity_, | |
| 1151 RoundUp(capacity_ * 2, static_cast<int>(Page::kPageSize))); | |
| 1152 return GrowTo(new_capacity); | |
| 1153 } | |
| 1154 | |
| 1155 | |
| 1156 bool SemiSpace::GrowTo(int new_capacity) { | 1148 bool SemiSpace::GrowTo(int new_capacity) { |
| 1157 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); | 1149 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); |
| 1158 ASSERT(new_capacity <= maximum_capacity_); | 1150 ASSERT(new_capacity <= maximum_capacity_); |
| 1159 ASSERT(new_capacity > capacity_); | 1151 ASSERT(new_capacity > capacity_); |
| 1160 int pages_before = capacity_ / Page::kPageSize; | 1152 int pages_before = capacity_ / Page::kPageSize; |
| 1161 int pages_after = new_capacity / Page::kPageSize; | 1153 int pages_after = new_capacity / Page::kPageSize; |
| 1162 | 1154 |
| 1163 Address end = start_ + maximum_capacity_; | 1155 Address end = start_ + maximum_capacity_; |
| 1164 Address start = end - new_capacity; | 1156 Address start = end - new_capacity; |
| 1165 size_t delta = new_capacity - capacity_; | 1157 size_t delta = new_capacity - capacity_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 if (!heap()->isolate()->memory_allocator()->UncommitBlock(old_start, delta)) { | 1194 if (!heap()->isolate()->memory_allocator()->UncommitBlock(old_start, delta)) { |
| 1203 return false; | 1195 return false; |
| 1204 } | 1196 } |
| 1205 capacity_ = new_capacity; | 1197 capacity_ = new_capacity; |
| 1206 | 1198 |
| 1207 int pages_after = capacity_ / Page::kPageSize; | 1199 int pages_after = capacity_ / Page::kPageSize; |
| 1208 NewSpacePage* new_last_page = | 1200 NewSpacePage* new_last_page = |
| 1209 NewSpacePage::FromAddress(space_end - pages_after * Page::kPageSize); | 1201 NewSpacePage::FromAddress(space_end - pages_after * Page::kPageSize); |
| 1210 new_last_page->set_next_page(anchor()); | 1202 new_last_page->set_next_page(anchor()); |
| 1211 anchor()->set_prev_page(new_last_page); | 1203 anchor()->set_prev_page(new_last_page); |
| 1212 ASSERT(current_page_ == first_page()); | 1204 ASSERT((current_page_ <= first_page()) && (current_page_ >= new_last_page)); |
| 1213 | 1205 |
| 1214 return true; | 1206 return true; |
| 1215 } | 1207 } |
| 1216 | 1208 |
| 1217 | 1209 |
| 1218 void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) { | 1210 void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) { |
| 1219 anchor_.set_owner(this); | 1211 anchor_.set_owner(this); |
| 1220 // Fixup back-pointers to anchor. Address of anchor changes | 1212 // Fixup back-pointers to anchor. Address of anchor changes |
| 1221 // when we swap. | 1213 // when we swap. |
| 1222 anchor_.prev_page()->set_next_page(&anchor_); | 1214 anchor_.prev_page()->set_next_page(&anchor_); |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2527 object->ShortPrint(); | 2519 object->ShortPrint(); |
| 2528 PrintF("\n"); | 2520 PrintF("\n"); |
| 2529 } | 2521 } |
| 2530 printf(" --------------------------------------\n"); | 2522 printf(" --------------------------------------\n"); |
| 2531 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 2523 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 2532 } | 2524 } |
| 2533 | 2525 |
| 2534 #endif // DEBUG | 2526 #endif // DEBUG |
| 2535 | 2527 |
| 2536 } } // namespace v8::internal | 2528 } } // namespace v8::internal |
| OLD | NEW |