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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 void Zone::DeleteAll() { | 88 void Zone::DeleteAll() { |
89 #ifdef DEBUG | 89 #ifdef DEBUG |
90 // Constant byte value used for zapping dead memory in debug mode. | 90 // Constant byte value used for zapping dead memory in debug mode. |
91 static const unsigned char kZapDeadByte = 0xcd; | 91 static const unsigned char kZapDeadByte = 0xcd; |
92 #endif | 92 #endif |
93 | 93 |
94 // Find a segment with a suitable size to keep around. | 94 // Find a segment with a suitable size to keep around. |
95 Segment* keep = segment_head_; | 95 Segment* keep = NULL; |
96 while (keep != NULL && keep->size() > kMaximumKeptSegmentSize) { | |
97 keep = keep->next(); | |
98 } | |
99 | |
100 // Traverse the chained list of segments, zapping (in debug mode) | 96 // Traverse the chained list of segments, zapping (in debug mode) |
101 // and freeing every segment except the one we wish to keep. | 97 // and freeing every segment except the one we wish to keep. |
102 for (Segment* current = segment_head_; current != NULL; ) { | 98 for (Segment* current = segment_head_; current != NULL; ) { |
103 Segment* next = current->next(); | 99 Segment* next = current->next(); |
104 if (current == keep) { | 100 if (!keep && current->size() <= kMaximumKeptSegmentSize) { |
Benedikt Meurer
2013/07/05 05:50:56
Test for NULL using keep == NULL.
| |
105 // Unlink the segment we wish to keep from the list. | 101 // Unlink the segment we wish to keep from the list. |
106 current->clear_next(); | 102 keep = current; |
103 keep->clear_next(); | |
107 } else { | 104 } else { |
108 int size = current->size(); | 105 int size = current->size(); |
109 #ifdef DEBUG | 106 #ifdef DEBUG |
110 // Zap the entire current segment (including the header). | 107 // Zap the entire current segment (including the header). |
111 memset(current, kZapDeadByte, size); | 108 memset(current, kZapDeadByte, size); |
112 #endif | 109 #endif |
113 DeleteSegment(current, size); | 110 DeleteSegment(current, size); |
114 } | 111 } |
115 current = next; | 112 current = next; |
116 } | 113 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 V8::FatalProcessOutOfMemory("Zone"); | 217 V8::FatalProcessOutOfMemory("Zone"); |
221 return NULL; | 218 return NULL; |
222 } | 219 } |
223 limit_ = segment->end(); | 220 limit_ = segment->end(); |
224 ASSERT(position_ <= limit_); | 221 ASSERT(position_ <= limit_); |
225 return result; | 222 return result; |
226 } | 223 } |
227 | 224 |
228 | 225 |
229 } } // namespace v8::internal | 226 } } // namespace v8::internal |
OLD | NEW |