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

Side by Side Diff: src/zone/zone.cc

Issue 2377943003: Fixed zapping of contents (Closed)
Patch Set: Reaction to comments Created 4 years, 2 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 | « src/zone/accounting-allocator.cc ('k') | src/zone/zone-segment.h » ('j') | 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/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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 DCHECK(redzone_position + kASanRedzoneBytes == position_); 85 DCHECK(redzone_position + kASanRedzoneBytes == position_);
86 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes); 86 ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
87 87
88 // Check that the result has the proper alignment and return it. 88 // Check that the result has the proper alignment and return it.
89 DCHECK(IsAddressAligned(result, kAlignment, 0)); 89 DCHECK(IsAddressAligned(result, kAlignment, 0));
90 allocation_size_ += size; 90 allocation_size_ += size;
91 return reinterpret_cast<void*>(result); 91 return reinterpret_cast<void*>(result);
92 } 92 }
93 93
94 void Zone::DeleteAll() { 94 void Zone::DeleteAll() {
95 #ifdef DEBUG
96 // Constant byte value used for zapping dead memory in debug mode.
97 static const unsigned char kZapDeadByte = 0xcd;
98 #endif
99
100 // Find a segment with a suitable size to keep around. 95 // Find a segment with a suitable size to keep around.
101 Segment* keep = nullptr; 96 Segment* keep = nullptr;
102 // Traverse the chained list of segments, zapping (in debug mode) 97 // Traverse the chained list of segments, zapping (in debug mode)
103 // and freeing every segment except the one we wish to keep. 98 // and freeing every segment except the one we wish to keep.
104 for (Segment* current = segment_head_; current;) { 99 for (Segment* current = segment_head_; current;) {
105 Segment* next = current->next(); 100 Segment* next = current->next();
106 if (!keep && current->size() <= kMaximumKeptSegmentSize) { 101 if (!keep && current->size() <= kMaximumKeptSegmentSize) {
107 // Unlink the segment we wish to keep from the list. 102 // Unlink the segment we wish to keep from the list.
108 keep = current; 103 keep = current;
109 keep->set_next(nullptr); 104 keep->set_next(nullptr);
110 } else { 105 } else {
111 size_t size = current->size(); 106 size_t size = current->size();
112 #ifdef DEBUG 107 #ifdef DEBUG
113 // Un-poison first so the zapping doesn't trigger ASan complaints. 108 // Un-poison first so the zapping doesn't trigger ASan complaints.
114 ASAN_UNPOISON_MEMORY_REGION(current, size); 109 ASAN_UNPOISON_MEMORY_REGION(current, size);
115 // Zap the entire current segment (including the header).
116 memset(current, kZapDeadByte, size);
117 #endif 110 #endif
111 current->ZapContents();
118 segment_bytes_allocated_ -= size; 112 segment_bytes_allocated_ -= size;
119 allocator_->FreeSegment(current); 113 allocator_->FreeSegment(current);
120 } 114 }
121 current = next; 115 current = next;
122 } 116 }
123 117
124 // If we have found a segment we want to keep, we must recompute the 118 // If we have found a segment we want to keep, we must recompute the
125 // variables 'position' and 'limit' to prepare for future allocate 119 // variables 'position' and 'limit' to prepare for future allocate
126 // attempts. Otherwise, we must clear the position and limit to 120 // attempts. Otherwise, we must clear the position and limit to
127 // force a new segment to be allocated on demand. 121 // force a new segment to be allocated on demand.
128 if (keep) { 122 if (keep) {
129 Address start = keep->start(); 123 Address start = keep->start();
130 position_ = RoundUp(start, kAlignment); 124 position_ = RoundUp(start, kAlignment);
131 limit_ = keep->end(); 125 limit_ = keep->end();
132 // Un-poison so we can re-use the segment later. 126 // Un-poison so we can re-use the segment later.
133 ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); 127 ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity());
Michael Lippautz 2016/09/29 09:44:47 All other unpoison operations are within #ifdef DE
134 #ifdef DEBUG 128 keep->ZapContents();
135 // Zap the contents of the kept segment (but not the header).
136 memset(start, kZapDeadByte, keep->capacity());
137 #endif
138 } else { 129 } else {
139 position_ = limit_ = 0; 130 position_ = limit_ = 0;
140 } 131 }
141 132
142 allocation_size_ = 0; 133 allocation_size_ = 0;
143 // Update the head segment to be the kept segment (if any). 134 // Update the head segment to be the kept segment (if any).
144 segment_head_ = keep; 135 segment_head_ = keep;
145 } 136 }
146 137
147 void Zone::DeleteKeptSegment() { 138 void Zone::DeleteKeptSegment() {
148 #ifdef DEBUG
149 // Constant byte value used for zapping dead memory in debug mode.
150 static const unsigned char kZapDeadByte = 0xcd;
151 #endif
152
153 DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr); 139 DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr);
154 if (segment_head_ != nullptr) { 140 if (segment_head_ != nullptr) {
155 size_t size = segment_head_->size(); 141 size_t size = segment_head_->size();
156 #ifdef DEBUG 142 #ifdef DEBUG
157 // Un-poison first so the zapping doesn't trigger ASan complaints. 143 // Un-poison first so the zapping doesn't trigger ASan complaints.
158 ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); 144 ASAN_UNPOISON_MEMORY_REGION(segment_head_, size);
159 // Zap the entire kept segment (including the header).
160 memset(segment_head_, kZapDeadByte, size);
161 #endif 145 #endif
146 segment_head_->ZapContents();
162 segment_bytes_allocated_ -= size; 147 segment_bytes_allocated_ -= size;
163 allocator_->FreeSegment(segment_head_); 148 allocator_->FreeSegment(segment_head_);
164 segment_head_ = nullptr; 149 segment_head_ = nullptr;
165 } 150 }
166 151
167 DCHECK(segment_bytes_allocated_ == 0); 152 DCHECK(segment_bytes_allocated_ == 0);
168 } 153 }
169 154
170 // Creates a new segment, sets it size, and pushes it to the front 155 // Creates a new segment, sets it size, and pushes it to the front
171 // of the segment chain. Returns the new segment. 156 // of the segment chain. Returns the new segment.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // size bytes + header and alignment padding) 215 // size bytes + header and alignment padding)
231 DCHECK(reinterpret_cast<uintptr_t>(position_) >= 216 DCHECK(reinterpret_cast<uintptr_t>(position_) >=
232 reinterpret_cast<uintptr_t>(result)); 217 reinterpret_cast<uintptr_t>(result));
233 limit_ = segment->end(); 218 limit_ = segment->end();
234 DCHECK(position_ <= limit_); 219 DCHECK(position_ <= limit_);
235 return result; 220 return result;
236 } 221 }
237 222
238 } // namespace internal 223 } // namespace internal
239 } // namespace v8 224 } // namespace v8
OLDNEW
« no previous file with comments | « src/zone/accounting-allocator.cc ('k') | src/zone/zone-segment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698