Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/zone.h" | 5 #include "src/zone/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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 Segment* next = current->next(); | 105 Segment* next = current->next(); |
| 106 if (!keep && current->size() <= kMaximumKeptSegmentSize) { | 106 if (!keep && current->size() <= kMaximumKeptSegmentSize) { |
| 107 // Unlink the segment we wish to keep from the list. | 107 // Unlink the segment we wish to keep from the list. |
| 108 keep = current; | 108 keep = current; |
| 109 keep->set_next(nullptr); | 109 keep->set_next(nullptr); |
| 110 } else { | 110 } else { |
| 111 size_t size = current->size(); | 111 size_t size = current->size(); |
| 112 #ifdef DEBUG | 112 #ifdef DEBUG |
| 113 // Un-poison first so the zapping doesn't trigger ASan complaints. | 113 // Un-poison first so the zapping doesn't trigger ASan complaints. |
| 114 ASAN_UNPOISON_MEMORY_REGION(current, size); | 114 ASAN_UNPOISON_MEMORY_REGION(current, size); |
| 115 // Zap the entire current segment (including the header). | |
| 116 memset(current, kZapDeadByte, size); | |
| 117 #endif | 115 #endif |
| 116 current->ZapContents(); | |
| 118 segment_bytes_allocated_ -= size; | 117 segment_bytes_allocated_ -= size; |
| 119 allocator_->FreeSegment(current); | 118 allocator_->FreeSegment(current); |
| 120 } | 119 } |
| 121 current = next; | 120 current = next; |
| 122 } | 121 } |
| 123 | 122 |
| 124 // If we have found a segment we want to keep, we must recompute the | 123 // If we have found a segment we want to keep, we must recompute the |
| 125 // variables 'position' and 'limit' to prepare for future allocate | 124 // variables 'position' and 'limit' to prepare for future allocate |
| 126 // attempts. Otherwise, we must clear the position and limit to | 125 // attempts. Otherwise, we must clear the position and limit to |
| 127 // force a new segment to be allocated on demand. | 126 // force a new segment to be allocated on demand. |
| 128 if (keep) { | 127 if (keep) { |
| 129 Address start = keep->start(); | 128 Address start = keep->start(); |
| 130 position_ = RoundUp(start, kAlignment); | 129 position_ = RoundUp(start, kAlignment); |
| 131 limit_ = keep->end(); | 130 limit_ = keep->end(); |
| 132 // Un-poison so we can re-use the segment later. | 131 // Un-poison so we can re-use the segment later. |
| 133 ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); | 132 ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); |
| 134 #ifdef DEBUG | 133 keep->ZapContents(); |
| 135 // Zap the contents of the kept segment (but not the header). | |
| 136 memset(start, kZapDeadByte, keep->capacity()); | |
| 137 #endif | |
| 138 } else { | 134 } else { |
| 139 position_ = limit_ = 0; | 135 position_ = limit_ = 0; |
| 140 } | 136 } |
| 141 | 137 |
| 142 allocation_size_ = 0; | 138 allocation_size_ = 0; |
| 143 // Update the head segment to be the kept segment (if any). | 139 // Update the head segment to be the kept segment (if any). |
| 144 segment_head_ = keep; | 140 segment_head_ = keep; |
| 145 } | 141 } |
| 146 | 142 |
| 147 void Zone::DeleteKeptSegment() { | 143 void Zone::DeleteKeptSegment() { |
| 148 #ifdef DEBUG | 144 #ifdef DEBUG |
| 149 // Constant byte value used for zapping dead memory in debug mode. | 145 // Constant byte value used for zapping dead memory in debug mode. |
| 150 static const unsigned char kZapDeadByte = 0xcd; | 146 static const unsigned char kZapDeadByte = 0xcd; |
| 151 #endif | 147 #endif |
| 152 | 148 |
| 153 DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr); | 149 DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr); |
| 154 if (segment_head_ != nullptr) { | 150 if (segment_head_ != nullptr) { |
| 155 size_t size = segment_head_->size(); | 151 size_t size = segment_head_->size(); |
| 156 #ifdef DEBUG | 152 #ifdef DEBUG |
| 157 // Un-poison first so the zapping doesn't trigger ASan complaints. | 153 // Un-poison first so the zapping doesn't trigger ASan complaints. |
| 158 ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); | 154 ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); |
| 159 // Zap the entire kept segment (including the header). | 155 // Zap the entire kept segment (including the header). |
| 160 memset(segment_head_, kZapDeadByte, size); | 156 memset(segment_head_, kZapDeadByte, size); |
|
Michael Lippautz
2016/09/28 09:22:39
I guess this should also be the ZapContents?
| |
| 161 #endif | 157 #endif |
| 162 segment_bytes_allocated_ -= size; | 158 segment_bytes_allocated_ -= size; |
| 163 allocator_->FreeSegment(segment_head_); | 159 allocator_->FreeSegment(segment_head_); |
| 164 segment_head_ = nullptr; | 160 segment_head_ = nullptr; |
| 165 } | 161 } |
| 166 | 162 |
| 167 DCHECK(segment_bytes_allocated_ == 0); | 163 DCHECK(segment_bytes_allocated_ == 0); |
| 168 } | 164 } |
| 169 | 165 |
| 170 // Creates a new segment, sets it size, and pushes it to the front | 166 // Creates a new segment, sets it size, and pushes it to the front |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 // size bytes + header and alignment padding) | 226 // size bytes + header and alignment padding) |
| 231 DCHECK(reinterpret_cast<uintptr_t>(position_) >= | 227 DCHECK(reinterpret_cast<uintptr_t>(position_) >= |
| 232 reinterpret_cast<uintptr_t>(result)); | 228 reinterpret_cast<uintptr_t>(result)); |
| 233 limit_ = segment->end(); | 229 limit_ = segment->end(); |
| 234 DCHECK(position_ <= limit_); | 230 DCHECK(position_ <= limit_); |
| 235 return result; | 231 return result; |
| 236 } | 232 } |
| 237 | 233 |
| 238 } // namespace internal | 234 } // namespace internal |
| 239 } // namespace v8 | 235 } // namespace v8 |
| OLD | NEW |