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

Side by Side Diff: src/zone.cc

Issue 1945313002: Version 5.0.71.47 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@5.0
Patch Set: Created 4 years, 7 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
« no previous file with comments | « include/v8-version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/zone.h" 5 #include "src/zone.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (kPointerSize == 4 && kAlignment == 4) { 98 if (kPointerSize == 4 && kAlignment == 4) {
99 position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4); 99 position_ += ((~size) & 4) & (reinterpret_cast<intptr_t>(position_) & 4);
100 } else { 100 } else {
101 DCHECK(kAlignment >= kPointerSize); 101 DCHECK(kAlignment >= kPointerSize);
102 } 102 }
103 103
104 // Check if the requested size is available without expanding. 104 // Check if the requested size is available without expanding.
105 Address result = position_; 105 Address result = position_;
106 106
107 const size_t size_with_redzone = size + kASanRedzoneBytes; 107 const size_t size_with_redzone = size + kASanRedzoneBytes;
108 if (limit_ < position_ + size_with_redzone) { 108 const uintptr_t limit = reinterpret_cast<uintptr_t>(limit_);
109 const uintptr_t position = reinterpret_cast<uintptr_t>(position_);
110 // position_ > limit_ can be true after the alignment correction above.
111 if (limit < position || size_with_redzone > limit - position) {
109 result = NewExpand(size_with_redzone); 112 result = NewExpand(size_with_redzone);
110 } else { 113 } else {
111 position_ += size_with_redzone; 114 position_ += size_with_redzone;
112 } 115 }
113 116
114 Address redzone_position = result + size; 117 Address redzone_position = result + size;
115 DCHECK(redzone_position + kASanRedzoneBytes == position_); 118 DCHECK(redzone_position + kASanRedzoneBytes == position_);
116 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes); 119 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
117 120
118 // Check that the result has the proper alignment and return it. 121 // Check that the result has the proper alignment and return it.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 void Zone::DeleteSegment(Segment* segment, size_t size) { 218 void Zone::DeleteSegment(Segment* segment, size_t size) {
216 segment_bytes_allocated_ -= size; 219 segment_bytes_allocated_ -= size;
217 Malloced::Delete(segment); 220 Malloced::Delete(segment);
218 } 221 }
219 222
220 223
221 Address Zone::NewExpand(size_t size) { 224 Address Zone::NewExpand(size_t size) {
222 // Make sure the requested size is already properly aligned and that 225 // Make sure the requested size is already properly aligned and that
223 // there isn't enough room in the Zone to satisfy the request. 226 // there isn't enough room in the Zone to satisfy the request.
224 DCHECK_EQ(size, RoundDown(size, kAlignment)); 227 DCHECK_EQ(size, RoundDown(size, kAlignment));
225 DCHECK_LT(limit_, position_ + size); 228 DCHECK(limit_ < position_ ||
229 reinterpret_cast<uintptr_t>(limit_) -
230 reinterpret_cast<uintptr_t>(position_) <
231 size);
226 232
227 // Compute the new segment size. We use a 'high water mark' 233 // Compute the new segment size. We use a 'high water mark'
228 // strategy, where we increase the segment size every time we expand 234 // strategy, where we increase the segment size every time we expand
229 // except that we employ a maximum segment size when we delete. This 235 // except that we employ a maximum segment size when we delete. This
230 // is to avoid excessive malloc() and free() overhead. 236 // is to avoid excessive malloc() and free() overhead.
231 Segment* head = segment_head_; 237 Segment* head = segment_head_;
232 const size_t old_size = (head == nullptr) ? 0 : head->size(); 238 const size_t old_size = (head == nullptr) ? 0 : head->size();
233 static const size_t kSegmentOverhead = sizeof(Segment) + kAlignment; 239 static const size_t kSegmentOverhead = sizeof(Segment) + kAlignment;
234 const size_t new_size_no_overhead = size + (old_size << 1); 240 const size_t new_size_no_overhead = size + (old_size << 1);
235 size_t new_size = kSegmentOverhead + new_size_no_overhead; 241 size_t new_size = kSegmentOverhead + new_size_no_overhead;
(...skipping 30 matching lines...) Expand all
266 // size bytes + header and alignment padding) 272 // size bytes + header and alignment padding)
267 DCHECK(reinterpret_cast<uintptr_t>(position_) >= 273 DCHECK(reinterpret_cast<uintptr_t>(position_) >=
268 reinterpret_cast<uintptr_t>(result)); 274 reinterpret_cast<uintptr_t>(result));
269 limit_ = segment->end(); 275 limit_ = segment->end();
270 DCHECK(position_ <= limit_); 276 DCHECK(position_ <= limit_);
271 return result; 277 return result;
272 } 278 }
273 279
274 } // namespace internal 280 } // namespace internal
275 } // namespace v8 281 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698