Chromium Code Reviews| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 // there isn't enough room in the Zone to satisfy the request. | 156 // there isn't enough room in the Zone to satisfy the request. |
| 157 ASSERT(size == RoundDown(size, kAlignment)); | 157 ASSERT(size == RoundDown(size, kAlignment)); |
| 158 ASSERT(position_ + size > limit_); | 158 ASSERT(position_ + size > limit_); |
| 159 | 159 |
| 160 // Compute the new segment size. We use a 'high water mark' | 160 // Compute the new segment size. We use a 'high water mark' |
| 161 // strategy, where we increase the segment size every time we expand | 161 // strategy, where we increase the segment size every time we expand |
| 162 // except that we employ a maximum segment size when we delete. This | 162 // except that we employ a maximum segment size when we delete. This |
| 163 // is to avoid excessive malloc() and free() overhead. | 163 // is to avoid excessive malloc() and free() overhead. |
| 164 Segment* head = Segment::head(); | 164 Segment* head = Segment::head(); |
| 165 int old_size = (head == NULL) ? 0 : head->size(); | 165 int old_size = (head == NULL) ? 0 : head->size(); |
| 166 int new_size = sizeof(Segment) + kAlignment + size + (old_size << 1); | 166 int segment_overhead = sizeof(Segment) + kAlignment; |
|
Kasper Lund
2008/12/05 08:36:49
This is a constant, right? Maybe make it 'static c
iposva
2008/12/05 17:25:13
Done.
| |
| 167 if (new_size < kMinimumSegmentSize) new_size = kMinimumSegmentSize; | 167 int new_size = segment_overhead + size + (old_size << 1); |
| 168 if (new_size < kMinimumSegmentSize) { | |
| 169 new_size = kMinimumSegmentSize; | |
| 170 } else if (new_size > kMaximumSegmentSize) { | |
| 171 // Limit the size of new segments to avoid growing the segment size | |
| 172 // exponentially, thus putting pressure on contiguous virtual address | |
| 173 // space. | |
| 174 if (size > (kMaximumSegmentSize - segment_overhead)) { | |
| 175 // Make sure to allocate a segment at least large enough to hold the | |
| 176 // requested size. | |
| 177 new_size = RoundUp(size + segment_overhead, kMinimumSegmentSize); | |
|
Kasper Lund
2008/12/05 08:36:49
Why do you round the result up? If it's a feature
iposva
2008/12/05 17:25:13
The idea was to round up to a size that is likely
| |
| 178 } else { | |
| 179 // Allocate a new segment of maximum size. | |
| 180 new_size = kMaximumSegmentSize; | |
| 181 } | |
| 182 } | |
| 168 Segment* segment = Segment::New(new_size); | 183 Segment* segment = Segment::New(new_size); |
| 169 if (segment == NULL) V8::FatalProcessOutOfMemory("Zone"); | 184 if (segment == NULL) V8::FatalProcessOutOfMemory("Zone"); |
| 170 | 185 |
| 171 // Recompute 'top' and 'limit' based on the new segment. | 186 // Recompute 'top' and 'limit' based on the new segment. |
| 172 Address result = RoundUp(segment->start(), kAlignment); | 187 Address result = RoundUp(segment->start(), kAlignment); |
| 173 position_ = result + size; | 188 position_ = result + size; |
| 174 limit_ = segment->end(); | 189 limit_ = segment->end(); |
| 175 ASSERT(position_ <= limit_); | 190 ASSERT(position_ <= limit_); |
| 176 return result; | 191 return result; |
| 177 } | 192 } |
| 178 | 193 |
| 179 | 194 |
| 180 } } // namespace v8::internal | 195 } } // namespace v8::internal |
| OLD | NEW |