| 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 // Un-poison first so the zapping doesn't trigger ASan complaints. |
| 108 ASAN_UNPOISON_MEMORY_REGION(current, size); |
| 107 // Zap the entire current segment (including the header). | 109 // Zap the entire current segment (including the header). |
| 108 memset(current, kZapDeadByte, size); | 110 memset(current, kZapDeadByte, size); |
| 109 #endif | 111 #endif |
| 110 DeleteSegment(current, size); | 112 DeleteSegment(current, size); |
| 111 } | 113 } |
| 112 current = next; | 114 current = next; |
| 113 } | 115 } |
| 114 | 116 |
| 115 // If we have found a segment we want to keep, we must recompute the | 117 // If we have found a segment we want to keep, we must recompute the |
| 116 // variables 'position' and 'limit' to prepare for future allocate | 118 // variables 'position' and 'limit' to prepare for future allocate |
| 117 // attempts. Otherwise, we must clear the position and limit to | 119 // attempts. Otherwise, we must clear the position and limit to |
| 118 // force a new segment to be allocated on demand. | 120 // force a new segment to be allocated on demand. |
| 119 if (keep != NULL) { | 121 if (keep != NULL) { |
| 120 Address start = keep->start(); | 122 Address start = keep->start(); |
| 121 position_ = RoundUp(start, kAlignment); | 123 position_ = RoundUp(start, kAlignment); |
| 122 limit_ = keep->end(); | 124 limit_ = keep->end(); |
| 125 // Un-poison so we can re-use the segment later. |
| 126 ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); |
| 123 #ifdef DEBUG | 127 #ifdef DEBUG |
| 124 // Zap the contents of the kept segment (but not the header). | 128 // Zap the contents of the kept segment (but not the header). |
| 125 memset(start, kZapDeadByte, keep->capacity()); | 129 memset(start, kZapDeadByte, keep->capacity()); |
| 126 #endif | 130 #endif |
| 127 } else { | 131 } else { |
| 128 position_ = limit_ = 0; | 132 position_ = limit_ = 0; |
| 129 } | 133 } |
| 130 | 134 |
| 131 // Update the head segment to be the kept segment (if any). | 135 // Update the head segment to be the kept segment (if any). |
| 132 segment_head_ = keep; | 136 segment_head_ = keep; |
| 133 } | 137 } |
| 134 | 138 |
| 135 | 139 |
| 136 void Zone::DeleteKeptSegment() { | 140 void Zone::DeleteKeptSegment() { |
| 137 #ifdef DEBUG | 141 #ifdef DEBUG |
| 138 // Constant byte value used for zapping dead memory in debug mode. | 142 // Constant byte value used for zapping dead memory in debug mode. |
| 139 static const unsigned char kZapDeadByte = 0xcd; | 143 static const unsigned char kZapDeadByte = 0xcd; |
| 140 #endif | 144 #endif |
| 141 | 145 |
| 142 ASSERT(segment_head_ == NULL || segment_head_->next() == NULL); | 146 ASSERT(segment_head_ == NULL || segment_head_->next() == NULL); |
| 143 if (segment_head_ != NULL) { | 147 if (segment_head_ != NULL) { |
| 144 int size = segment_head_->size(); | 148 int size = segment_head_->size(); |
| 145 #ifdef DEBUG | 149 #ifdef DEBUG |
| 150 // Un-poison first so the zapping doesn't trigger ASan complaints. |
| 151 ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); |
| 146 // Zap the entire kept segment (including the header). | 152 // Zap the entire kept segment (including the header). |
| 147 memset(segment_head_, kZapDeadByte, size); | 153 memset(segment_head_, kZapDeadByte, size); |
| 148 #endif | 154 #endif |
| 149 DeleteSegment(segment_head_, size); | 155 DeleteSegment(segment_head_, size); |
| 150 segment_head_ = NULL; | 156 segment_head_ = NULL; |
| 151 } | 157 } |
| 152 | 158 |
| 153 ASSERT(segment_bytes_allocated_ == 0); | 159 ASSERT(segment_bytes_allocated_ == 0); |
| 154 } | 160 } |
| 155 | 161 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 V8::FatalProcessOutOfMemory("Zone"); | 232 V8::FatalProcessOutOfMemory("Zone"); |
| 227 return NULL; | 233 return NULL; |
| 228 } | 234 } |
| 229 limit_ = segment->end(); | 235 limit_ = segment->end(); |
| 230 ASSERT(position_ <= limit_); | 236 ASSERT(position_ <= limit_); |
| 231 return result; | 237 return result; |
| 232 } | 238 } |
| 233 | 239 |
| 234 | 240 |
| 235 } } // namespace v8::internal | 241 } } // namespace v8::internal |
| OLD | NEW |