OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/zone.h" | 5 #include "vm/zone.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/handles_impl.h" | 10 #include "vm/handles_impl.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void Zone::DeleteAll() { | 100 void Zone::DeleteAll() { |
101 // Traverse the chained list of segments, zapping (in debug mode) | 101 // Traverse the chained list of segments, zapping (in debug mode) |
102 // and freeing every zone segment. | 102 // and freeing every zone segment. |
103 if (head_ != NULL) { | 103 if (head_ != NULL) { |
104 Segment::DeleteSegmentList(head_); | 104 Segment::DeleteSegmentList(head_); |
105 } | 105 } |
106 if (large_segments_ != NULL) { | 106 if (large_segments_ != NULL) { |
107 Segment::DeleteSegmentList(large_segments_); | 107 Segment::DeleteSegmentList(large_segments_); |
108 } | 108 } |
109 | 109 |
110 // Reset zone state. | 110 // Reset zone state. |
111 #ifdef DEBUG | 111 #ifdef DEBUG |
112 memset(initial_buffer_.pointer(), kZapDeletedByte, initial_buffer_.size()); | 112 memset(initial_buffer_.pointer(), kZapDeletedByte, initial_buffer_.size()); |
113 #endif | 113 #endif |
114 position_ = initial_buffer_.start(); | 114 position_ = initial_buffer_.start(); |
115 limit_ = initial_buffer_.end(); | 115 limit_ = initial_buffer_.end(); |
116 head_ = NULL; | 116 head_ = NULL; |
117 large_segments_ = NULL; | 117 large_segments_ = NULL; |
118 previous_ = NULL; | 118 previous_ = NULL; |
119 handles_.Reset(); | 119 handles_.Reset(); |
120 } | 120 } |
(...skipping 19 matching lines...) Expand all Loading... |
140 ASSERT(size >= 0); | 140 ASSERT(size >= 0); |
141 if (FLAG_trace_zones) { | 141 if (FLAG_trace_zones) { |
142 OS::PrintErr("*** Expanding zone 0x%" Px "\n", | 142 OS::PrintErr("*** Expanding zone 0x%" Px "\n", |
143 reinterpret_cast<intptr_t>(this)); | 143 reinterpret_cast<intptr_t>(this)); |
144 DumpZoneSizes(); | 144 DumpZoneSizes(); |
145 } | 145 } |
146 // Make sure the requested size is already properly aligned and that | 146 // Make sure the requested size is already properly aligned and that |
147 // there isn't enough room in the Zone to satisfy the request. | 147 // there isn't enough room in the Zone to satisfy the request. |
148 ASSERT(Utils::IsAligned(size, kAlignment)); | 148 ASSERT(Utils::IsAligned(size, kAlignment)); |
149 intptr_t free_size = (limit_ - position_); | 149 intptr_t free_size = (limit_ - position_); |
150 ASSERT(free_size < size); | 150 ASSERT(free_size < size); |
151 | 151 |
152 // First check to see if we should just chain it as a large segment. | 152 // First check to see if we should just chain it as a large segment. |
153 intptr_t max_size = Utils::RoundDown(kSegmentSize - sizeof(Segment), | 153 intptr_t max_size = |
154 kAlignment); | 154 Utils::RoundDown(kSegmentSize - sizeof(Segment), kAlignment); |
155 ASSERT(max_size > 0); | 155 ASSERT(max_size > 0); |
156 if (size > max_size) { | 156 if (size > max_size) { |
157 return AllocateLargeSegment(size); | 157 return AllocateLargeSegment(size); |
158 } | 158 } |
159 | 159 |
160 // Allocate another segment and chain it up. | 160 // Allocate another segment and chain it up. |
161 head_ = Segment::New(kSegmentSize, head_); | 161 head_ = Segment::New(kSegmentSize, head_); |
162 | 162 |
163 // Recompute 'position' and 'limit' based on the new head segment. | 163 // Recompute 'position' and 'limit' based on the new head segment. |
164 uword result = Utils::RoundUp(head_->start(), kAlignment); | 164 uword result = Utils::RoundUp(head_->start(), kAlignment); |
165 position_ = result + size; | 165 position_ = result + size; |
166 limit_ = head_->end(); | 166 limit_ = head_->end(); |
167 ASSERT(position_ <= limit_); | 167 ASSERT(position_ <= limit_); |
168 return result; | 168 return result; |
169 } | 169 } |
170 | 170 |
171 | 171 |
172 uword Zone::AllocateLargeSegment(intptr_t size) { | 172 uword Zone::AllocateLargeSegment(intptr_t size) { |
173 ASSERT(size >= 0); | 173 ASSERT(size >= 0); |
174 // Make sure the requested size is already properly aligned and that | 174 // Make sure the requested size is already properly aligned and that |
175 // there isn't enough room in the Zone to satisfy the request. | 175 // there isn't enough room in the Zone to satisfy the request. |
176 ASSERT(Utils::IsAligned(size, kAlignment)); | 176 ASSERT(Utils::IsAligned(size, kAlignment)); |
177 intptr_t free_size = (limit_ - position_); | 177 intptr_t free_size = (limit_ - position_); |
178 ASSERT(free_size < size); | 178 ASSERT(free_size < size); |
179 | 179 |
180 // Create a new large segment and chain it up. | 180 // Create a new large segment and chain it up. |
181 ASSERT(Utils::IsAligned(sizeof(Segment), kAlignment)); | 181 ASSERT(Utils::IsAligned(sizeof(Segment), kAlignment)); |
182 size += sizeof(Segment); // Account for book keeping fields in size. | 182 size += sizeof(Segment); // Account for book keeping fields in size. |
183 large_segments_ = Segment::New(size, large_segments_); | 183 large_segments_ = Segment::New(size, large_segments_); |
184 | 184 |
185 uword result = Utils::RoundUp(large_segments_->start(), kAlignment); | 185 uword result = Utils::RoundUp(large_segments_->start(), kAlignment); |
186 return result; | 186 return result; |
187 } | 187 } |
188 | 188 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 strncpy(©[a_len], b, b_len); | 223 strncpy(©[a_len], b, b_len); |
224 return copy; | 224 return copy; |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 void Zone::DumpZoneSizes() { | 228 void Zone::DumpZoneSizes() { |
229 intptr_t size = 0; | 229 intptr_t size = 0; |
230 for (Segment* s = large_segments_; s != NULL; s = s->next()) { | 230 for (Segment* s = large_segments_; s != NULL; s = s->next()) { |
231 size += s->size(); | 231 size += s->size(); |
232 } | 232 } |
233 OS::PrintErr("*** Zone(0x%" Px ") size in bytes," | 233 OS::PrintErr("*** Zone(0x%" Px |
| 234 ") size in bytes," |
234 " Total = %" Pd " Large Segments = %" Pd "\n", | 235 " Total = %" Pd " Large Segments = %" Pd "\n", |
235 reinterpret_cast<intptr_t>(this), SizeInBytes(), size); | 236 reinterpret_cast<intptr_t>(this), SizeInBytes(), size); |
236 } | 237 } |
237 | 238 |
238 | 239 |
239 void Zone::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 240 void Zone::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
240 Zone* zone = this; | 241 Zone* zone = this; |
241 while (zone != NULL) { | 242 while (zone != NULL) { |
242 zone->handles()->VisitObjectPointers(visitor); | 243 zone->handles()->VisitObjectPointers(visitor); |
243 zone = zone->previous_; | 244 zone = zone->previous_; |
(...skipping 30 matching lines...) Expand all Loading... |
274 ASSERT(thread()->zone() == &zone_); | 275 ASSERT(thread()->zone() == &zone_); |
275 thread()->set_zone(zone_.previous_); | 276 thread()->set_zone(zone_.previous_); |
276 if (FLAG_trace_zones) { | 277 if (FLAG_trace_zones) { |
277 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", | 278 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", |
278 reinterpret_cast<intptr_t>(this), | 279 reinterpret_cast<intptr_t>(this), |
279 reinterpret_cast<intptr_t>(&zone_)); | 280 reinterpret_cast<intptr_t>(&zone_)); |
280 } | 281 } |
281 } | 282 } |
282 | 283 |
283 } // namespace dart | 284 } // namespace dart |
OLD | NEW |