OLD | NEW |
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 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 #endif | 944 #endif |
945 | 945 |
946 | 946 |
947 void NewSpace::Flip() { | 947 void NewSpace::Flip() { |
948 SemiSpace tmp = from_space_; | 948 SemiSpace tmp = from_space_; |
949 from_space_ = to_space_; | 949 from_space_ = to_space_; |
950 to_space_ = tmp; | 950 to_space_ = tmp; |
951 } | 951 } |
952 | 952 |
953 | 953 |
954 bool NewSpace::Grow() { | 954 void NewSpace::Grow() { |
955 ASSERT(Capacity() < MaximumCapacity()); | 955 ASSERT(Capacity() < MaximumCapacity()); |
956 // TODO(1240712): Failure to double the from space can result in | 956 if (to_space_.Grow()) { |
957 // semispaces of different sizes. In the event of that failure, the | 957 // Only grow from space if we managed to grow to space. |
958 // to space doubling should be rolled back before returning false. | 958 if (!from_space_.Grow()) { |
959 if (!to_space_.Grow() || !from_space_.Grow()) return false; | 959 // If we managed to grow to space but couldn't grow from space, |
| 960 // attempt to shrink to space. |
| 961 if (!to_space_.ShrinkTo(from_space_.Capacity())) { |
| 962 // We are in an inconsistent state because we could not |
| 963 // commit/uncommit memory from new space. |
| 964 V8::FatalProcessOutOfMemory("Failed to grow new space."); |
| 965 } |
| 966 } |
| 967 } |
960 allocation_info_.limit = to_space_.high(); | 968 allocation_info_.limit = to_space_.high(); |
961 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 969 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
962 return true; | 970 } |
| 971 |
| 972 |
| 973 void NewSpace::Shrink() { |
| 974 int new_capacity = Max(InitialCapacity(), 2 * Size()); |
| 975 int rounded_new_capacity = RoundUp(new_capacity, OS::AllocateAlignment()); |
| 976 if (rounded_new_capacity < Capacity() && |
| 977 to_space_.ShrinkTo(rounded_new_capacity)) { |
| 978 // Only shrink from space if we managed to shrink to space. |
| 979 if (!from_space_.ShrinkTo(rounded_new_capacity)) { |
| 980 // If we managed to shrink to space but couldn't shrink from |
| 981 // space, attempt to grow to space again. |
| 982 if (!to_space_.GrowTo(from_space_.Capacity())) { |
| 983 // We are in an inconsistent state because we could not |
| 984 // commit/uncommit memory from new space. |
| 985 V8::FatalProcessOutOfMemory("Failed to shrink new space."); |
| 986 } |
| 987 } |
| 988 } |
| 989 allocation_info_.limit = to_space_.high(); |
| 990 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
963 } | 991 } |
964 | 992 |
965 | 993 |
966 void NewSpace::ResetAllocationInfo() { | 994 void NewSpace::ResetAllocationInfo() { |
967 allocation_info_.top = to_space_.low(); | 995 allocation_info_.top = to_space_.low(); |
968 allocation_info_.limit = to_space_.high(); | 996 allocation_info_.limit = to_space_.high(); |
969 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 997 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
970 } | 998 } |
971 | 999 |
972 | 1000 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 | 1079 |
1052 bool SemiSpace::Setup(Address start, | 1080 bool SemiSpace::Setup(Address start, |
1053 int initial_capacity, | 1081 int initial_capacity, |
1054 int maximum_capacity) { | 1082 int maximum_capacity) { |
1055 // Creates a space in the young generation. The constructor does not | 1083 // Creates a space in the young generation. The constructor does not |
1056 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of | 1084 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of |
1057 // memory of size 'capacity' when set up, and does not grow or shrink | 1085 // memory of size 'capacity' when set up, and does not grow or shrink |
1058 // otherwise. In the mark-compact collector, the memory region of the from | 1086 // otherwise. In the mark-compact collector, the memory region of the from |
1059 // space is used as the marking stack. It requires contiguous memory | 1087 // space is used as the marking stack. It requires contiguous memory |
1060 // addresses. | 1088 // addresses. |
| 1089 initial_capacity_ = initial_capacity; |
1061 capacity_ = initial_capacity; | 1090 capacity_ = initial_capacity; |
1062 maximum_capacity_ = maximum_capacity; | 1091 maximum_capacity_ = maximum_capacity; |
1063 committed_ = false; | 1092 committed_ = false; |
1064 | 1093 |
1065 start_ = start; | 1094 start_ = start; |
1066 address_mask_ = ~(maximum_capacity - 1); | 1095 address_mask_ = ~(maximum_capacity - 1); |
1067 object_mask_ = address_mask_ | kHeapObjectTag; | 1096 object_mask_ = address_mask_ | kHeapObjectTag; |
1068 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; | 1097 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; |
1069 age_mark_ = start_; | 1098 age_mark_ = start_; |
1070 | 1099 |
(...skipping 13 matching lines...) Expand all Loading... |
1084 int extra = Min(RoundUp(capacity_, OS::AllocateAlignment()), | 1113 int extra = Min(RoundUp(capacity_, OS::AllocateAlignment()), |
1085 maximum_extra); | 1114 maximum_extra); |
1086 if (!MemoryAllocator::CommitBlock(high(), extra, executable())) { | 1115 if (!MemoryAllocator::CommitBlock(high(), extra, executable())) { |
1087 return false; | 1116 return false; |
1088 } | 1117 } |
1089 capacity_ += extra; | 1118 capacity_ += extra; |
1090 return true; | 1119 return true; |
1091 } | 1120 } |
1092 | 1121 |
1093 | 1122 |
| 1123 bool SemiSpace::GrowTo(int new_capacity) { |
| 1124 ASSERT(new_capacity <= maximum_capacity_); |
| 1125 ASSERT(new_capacity > capacity_); |
| 1126 int delta = new_capacity - capacity_; |
| 1127 if (!MemoryAllocator::CommitBlock(high(), delta, executable())) { |
| 1128 return false; |
| 1129 } |
| 1130 capacity_ = new_capacity; |
| 1131 return true; |
| 1132 } |
| 1133 |
| 1134 |
| 1135 bool SemiSpace::ShrinkTo(int new_capacity) { |
| 1136 ASSERT(new_capacity >= initial_capacity_); |
| 1137 ASSERT(new_capacity < capacity_); |
| 1138 int delta = capacity_ - new_capacity; |
| 1139 if (!MemoryAllocator::UncommitBlock(high() - delta, delta)) { |
| 1140 return false; |
| 1141 } |
| 1142 capacity_ = new_capacity; |
| 1143 return true; |
| 1144 } |
| 1145 |
| 1146 |
1094 #ifdef DEBUG | 1147 #ifdef DEBUG |
1095 void SemiSpace::Print() { } | 1148 void SemiSpace::Print() { } |
1096 | 1149 |
1097 | 1150 |
1098 void SemiSpace::Verify() { } | 1151 void SemiSpace::Verify() { } |
1099 #endif | 1152 #endif |
1100 | 1153 |
1101 | 1154 |
1102 // ----------------------------------------------------------------------------- | 1155 // ----------------------------------------------------------------------------- |
1103 // SemiSpaceIterator implementation. | 1156 // SemiSpaceIterator implementation. |
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 reinterpret_cast<Object**>(object->address() | 2654 reinterpret_cast<Object**>(object->address() |
2602 + Page::kObjectAreaSize), | 2655 + Page::kObjectAreaSize), |
2603 allocation_top); | 2656 allocation_top); |
2604 PrintF("\n"); | 2657 PrintF("\n"); |
2605 } | 2658 } |
2606 } | 2659 } |
2607 } | 2660 } |
2608 #endif // DEBUG | 2661 #endif // DEBUG |
2609 | 2662 |
2610 } } // namespace v8::internal | 2663 } } // namespace v8::internal |
OLD | NEW |