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...) 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 ASSERT(static_cast<size_t>(Page::kPageSize) > OS::AllocateAlignment()); |
Vyacheslav Egorov (Chromium)
2011/09/20 14:26:40
I don't think we really need this assert here. The
Michael Starzinger
2011/09/20 15:29:03
Done.
| |
930 int new_capacity = Min(MaximumCapacity(), 2 * static_cast<int>(Capacity())); | |
Vyacheslav Egorov (Chromium)
2011/09/20 14:26:40
We should ensure that MaxCapacity & Capacity is _a
Michael Starzinger
2011/09/20 15:29:03
Done. I just checked that it is only modified in a
| |
931 int rounded_new_capacity = RoundUp(new_capacity, Page::kPageSize); | |
932 if (to_space_.GrowTo(rounded_new_capacity)) { | |
929 // Only grow from space if we managed to grow to-space. | 933 // Only grow from space if we managed to grow to-space. |
930 if (!from_space_.Grow()) { | 934 if (!from_space_.GrowTo(rounded_new_capacity)) { |
931 // If we managed to grow to-space but couldn't grow from-space, | 935 // If we managed to grow to-space but couldn't grow from-space, |
932 // attempt to shrink to-space. | 936 // attempt to shrink to-space. |
933 if (!to_space_.ShrinkTo(from_space_.Capacity())) { | 937 if (!to_space_.ShrinkTo(from_space_.Capacity())) { |
934 // We are in an inconsistent state because we could not | 938 // We are in an inconsistent state because we could not |
935 // commit/uncommit memory from new space. | 939 // commit/uncommit memory from new space. |
936 V8::FatalProcessOutOfMemory("Failed to grow new space."); | 940 V8::FatalProcessOutOfMemory("Failed to grow new space."); |
937 } | 941 } |
938 } | 942 } |
939 } | 943 } |
940 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 944 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
941 } | 945 } |
942 | 946 |
943 | 947 |
944 void NewSpace::Shrink() { | 948 void NewSpace::Shrink() { |
949 ASSERT(static_cast<size_t>(Page::kPageSize) > OS::AllocateAlignment()); | |
Vyacheslav Egorov (Chromium)
2011/09/20 14:26:40
I don't think we really need this assert here. The
Michael Starzinger
2011/09/20 15:29:03
Done.
| |
945 int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt()); | 950 int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt()); |
946 int rounded_new_capacity = | 951 int rounded_new_capacity = RoundUp(new_capacity, Page::kPageSize); |
947 RoundUp(new_capacity, static_cast<int>(OS::AllocateAlignment())); | |
948 if (rounded_new_capacity < Capacity() && | 952 if (rounded_new_capacity < Capacity() && |
949 to_space_.ShrinkTo(rounded_new_capacity)) { | 953 to_space_.ShrinkTo(rounded_new_capacity)) { |
950 // Only shrink from-space if we managed to shrink to-space. | 954 // Only shrink from-space if we managed to shrink to-space. |
951 from_space_.Reset(); | 955 from_space_.Reset(); |
952 if (!from_space_.ShrinkTo(rounded_new_capacity)) { | 956 if (!from_space_.ShrinkTo(rounded_new_capacity)) { |
953 // If we managed to shrink to-space but couldn't shrink from | 957 // If we managed to shrink to-space but couldn't shrink from |
954 // space, attempt to grow to-space again. | 958 // space, attempt to grow to-space again. |
955 if (!to_space_.GrowTo(from_space_.Capacity())) { | 959 if (!to_space_.GrowTo(from_space_.Capacity())) { |
956 // We are in an inconsistent state because we could not | 960 // We are in an inconsistent state because we could not |
957 // commit/uncommit memory from new space. | 961 // commit/uncommit memory from new space. |
(...skipping 179 matching lines...) Loading... | |
1137 return false; | 1141 return false; |
1138 } | 1142 } |
1139 anchor()->set_next_page(anchor()); | 1143 anchor()->set_next_page(anchor()); |
1140 anchor()->set_prev_page(anchor()); | 1144 anchor()->set_prev_page(anchor()); |
1141 | 1145 |
1142 committed_ = false; | 1146 committed_ = false; |
1143 return true; | 1147 return true; |
1144 } | 1148 } |
1145 | 1149 |
1146 | 1150 |
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) { | 1151 bool SemiSpace::GrowTo(int new_capacity) { |
1157 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); | 1152 ASSERT((new_capacity & Page::kPageAlignmentMask) == 0); |
1158 ASSERT(new_capacity <= maximum_capacity_); | 1153 ASSERT(new_capacity <= maximum_capacity_); |
1159 ASSERT(new_capacity > capacity_); | 1154 ASSERT(new_capacity > capacity_); |
1160 int pages_before = capacity_ / Page::kPageSize; | 1155 int pages_before = capacity_ / Page::kPageSize; |
1161 int pages_after = new_capacity / Page::kPageSize; | 1156 int pages_after = new_capacity / Page::kPageSize; |
1162 | 1157 |
1163 Address end = start_ + maximum_capacity_; | 1158 Address end = start_ + maximum_capacity_; |
1164 Address start = end - new_capacity; | 1159 Address start = end - new_capacity; |
1165 size_t delta = new_capacity - capacity_; | 1160 size_t delta = new_capacity - capacity_; |
(...skipping 1361 matching lines...) Loading... | |
2527 object->ShortPrint(); | 2522 object->ShortPrint(); |
2528 PrintF("\n"); | 2523 PrintF("\n"); |
2529 } | 2524 } |
2530 printf(" --------------------------------------\n"); | 2525 printf(" --------------------------------------\n"); |
2531 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 2526 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
2532 } | 2527 } |
2533 | 2528 |
2534 #endif // DEBUG | 2529 #endif // DEBUG |
2535 | 2530 |
2536 } } // namespace v8::internal | 2531 } } // namespace v8::internal |
OLD | NEW |