OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // and freeing every segment except the one we wish to keep. | 97 // and freeing every segment except the one we wish to keep. |
98 for (Segment* current = segment_head_; current != NULL; ) { | 98 for (Segment* current = segment_head_; current != NULL; ) { |
99 Segment* next = current->next(); | 99 Segment* next = current->next(); |
100 if (keep == NULL && current->size() <= kMaximumKeptSegmentSize) { | 100 if (keep == NULL && current->size() <= kMaximumKeptSegmentSize) { |
101 // Unlink the segment we wish to keep from the list. | 101 // Unlink the segment we wish to keep from the list. |
102 keep = current; | 102 keep = current; |
103 keep->clear_next(); | 103 keep->clear_next(); |
104 } else { | 104 } else { |
105 int size = current->size(); | 105 int size = current->size(); |
106 #ifdef DEBUG | 106 #ifdef DEBUG |
| 107 #ifdef ADDRESS_SANITIZER |
| 108 // Un-poison first so the zapping doesn't trigger ASan complaints. |
| 109 ASAN_UNPOISON_MEMORY_REGION(current, size); |
| 110 #endif // ADDRESS_SANITIZER |
107 // Zap the entire current segment (including the header). | 111 // Zap the entire current segment (including the header). |
108 memset(current, kZapDeadByte, size); | 112 memset(current, kZapDeadByte, size); |
109 #endif | 113 #endif // DEBUG |
110 DeleteSegment(current, size); | 114 DeleteSegment(current, size); |
111 } | 115 } |
112 current = next; | 116 current = next; |
113 } | 117 } |
114 | 118 |
115 // If we have found a segment we want to keep, we must recompute the | 119 // If we have found a segment we want to keep, we must recompute the |
116 // variables 'position' and 'limit' to prepare for future allocate | 120 // variables 'position' and 'limit' to prepare for future allocate |
117 // attempts. Otherwise, we must clear the position and limit to | 121 // attempts. Otherwise, we must clear the position and limit to |
118 // force a new segment to be allocated on demand. | 122 // force a new segment to be allocated on demand. |
119 if (keep != NULL) { | 123 if (keep != NULL) { |
120 Address start = keep->start(); | 124 Address start = keep->start(); |
121 position_ = RoundUp(start, kAlignment); | 125 position_ = RoundUp(start, kAlignment); |
122 limit_ = keep->end(); | 126 limit_ = keep->end(); |
| 127 #ifdef ADDRESS_SANITIZER |
| 128 // Un-poison so we can re-use the segment later. |
| 129 ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); |
| 130 #endif |
123 #ifdef DEBUG | 131 #ifdef DEBUG |
124 // Zap the contents of the kept segment (but not the header). | 132 // Zap the contents of the kept segment (but not the header). |
125 memset(start, kZapDeadByte, keep->capacity()); | 133 memset(start, kZapDeadByte, keep->capacity()); |
126 #endif | 134 #endif |
127 } else { | 135 } else { |
128 position_ = limit_ = 0; | 136 position_ = limit_ = 0; |
129 } | 137 } |
130 | 138 |
131 // Update the head segment to be the kept segment (if any). | 139 // Update the head segment to be the kept segment (if any). |
132 segment_head_ = keep; | 140 segment_head_ = keep; |
133 } | 141 } |
134 | 142 |
135 | 143 |
136 void Zone::DeleteKeptSegment() { | 144 void Zone::DeleteKeptSegment() { |
137 #ifdef DEBUG | 145 #ifdef DEBUG |
138 // Constant byte value used for zapping dead memory in debug mode. | 146 // Constant byte value used for zapping dead memory in debug mode. |
139 static const unsigned char kZapDeadByte = 0xcd; | 147 static const unsigned char kZapDeadByte = 0xcd; |
140 #endif | 148 #endif |
141 | 149 |
142 ASSERT(segment_head_ == NULL || segment_head_->next() == NULL); | 150 ASSERT(segment_head_ == NULL || segment_head_->next() == NULL); |
143 if (segment_head_ != NULL) { | 151 if (segment_head_ != NULL) { |
144 int size = segment_head_->size(); | 152 int size = segment_head_->size(); |
145 #ifdef DEBUG | 153 #ifdef DEBUG |
| 154 #ifdef ADDRESS_SANITIZER |
| 155 // Un-poison first so the zapping doesn't trigger ASan complaints. |
| 156 ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); |
| 157 #endif // ADDRESS_SANITIZER |
146 // Zap the entire kept segment (including the header). | 158 // Zap the entire kept segment (including the header). |
147 memset(segment_head_, kZapDeadByte, size); | 159 memset(segment_head_, kZapDeadByte, size); |
148 #endif | 160 #endif // DEBUG |
149 DeleteSegment(segment_head_, size); | 161 DeleteSegment(segment_head_, size); |
150 segment_head_ = NULL; | 162 segment_head_ = NULL; |
151 } | 163 } |
152 | 164 |
153 ASSERT(segment_bytes_allocated_ == 0); | 165 ASSERT(segment_bytes_allocated_ == 0); |
154 } | 166 } |
155 | 167 |
156 | 168 |
157 // Creates a new segment, sets it size, and pushes it to the front | 169 // Creates a new segment, sets it size, and pushes it to the front |
158 // of the segment chain. Returns the new segment. | 170 // of the segment chain. Returns the new segment. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 V8::FatalProcessOutOfMemory("Zone"); | 238 V8::FatalProcessOutOfMemory("Zone"); |
227 return NULL; | 239 return NULL; |
228 } | 240 } |
229 limit_ = segment->end(); | 241 limit_ = segment->end(); |
230 ASSERT(position_ <= limit_); | 242 ASSERT(position_ <= limit_); |
231 return result; | 243 return result; |
232 } | 244 } |
233 | 245 |
234 | 246 |
235 } } // namespace v8::internal | 247 } } // namespace v8::internal |
OLD | NEW |