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 #ifndef VM_ZONE_H_ | 5 #ifndef VM_ZONE_H_ |
6 #define VM_ZONE_H_ | 6 #define VM_ZONE_H_ |
7 | 7 |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/handles.h" | 10 #include "vm/handles.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 private: | 61 private: |
62 Zone() | 62 Zone() |
63 : initial_buffer_(buffer_, kInitialChunkSize), | 63 : initial_buffer_(buffer_, kInitialChunkSize), |
64 position_(initial_buffer_.start()), | 64 position_(initial_buffer_.start()), |
65 limit_(initial_buffer_.end()), | 65 limit_(initial_buffer_.end()), |
66 head_(NULL), | 66 head_(NULL), |
67 large_segments_(NULL), | 67 large_segments_(NULL), |
68 handles_(), | 68 handles_(), |
69 previous_(NULL) { | 69 previous_(NULL) { |
| 70 ASSERT(Utils::IsAligned(position_, kAlignment)); |
70 #ifdef DEBUG | 71 #ifdef DEBUG |
71 // Zap the entire initial buffer. | 72 // Zap the entire initial buffer. |
72 memset(initial_buffer_.pointer(), kZapUninitializedByte, | 73 memset(initial_buffer_.pointer(), kZapUninitializedByte, |
73 initial_buffer_.size()); | 74 initial_buffer_.size()); |
74 #endif | 75 #endif |
75 } | 76 } |
76 | 77 |
77 ~Zone() { // Delete all memory associated with the zone. | 78 ~Zone() { // Delete all memory associated with the zone. |
78 #if defined(DEBUG) | 79 #if defined(DEBUG) |
79 if (FLAG_trace_zones) { | 80 if (FLAG_trace_zones) { |
80 DumpZoneSizes(); | 81 DumpZoneSizes(); |
81 } | 82 } |
82 #endif | 83 #endif |
83 DeleteAll(); | 84 DeleteAll(); |
84 } | 85 } |
85 | 86 |
86 // All pointers returned from AllocateUnsafe() and New() have this alignment. | 87 // All pointers returned from AllocateUnsafe() and New() have this alignment. |
87 static const intptr_t kAlignment = kWordSize; | 88 static const intptr_t kAlignment = kDoubleSize; |
88 | 89 |
89 // Default initial chunk size. | 90 // Default initial chunk size. |
90 static const intptr_t kInitialChunkSize = 1 * KB; | 91 static const intptr_t kInitialChunkSize = 1 * KB; |
91 | 92 |
92 // Default segment size. | 93 // Default segment size. |
93 static const intptr_t kSegmentSize = 64 * KB; | 94 static const intptr_t kSegmentSize = 64 * KB; |
94 | 95 |
95 // Zap value used to indicate deleted zone area (debug purposes). | 96 // Zap value used to indicate deleted zone area (debug purposes). |
96 static const unsigned char kZapDeletedByte = 0x42; | 97 static const unsigned char kZapDeletedByte = 0x42; |
97 | 98 |
(...skipping 16 matching lines...) Expand all Loading... |
114 | 115 |
115 #if defined(DEBUG) | 116 #if defined(DEBUG) |
116 // Dump the current allocated sizes in the zone object. | 117 // Dump the current allocated sizes in the zone object. |
117 void DumpZoneSizes(); | 118 void DumpZoneSizes(); |
118 #endif | 119 #endif |
119 | 120 |
120 // This buffer is used for allocation before any segments. | 121 // This buffer is used for allocation before any segments. |
121 // This would act as the initial stack allocated chunk so that we don't | 122 // This would act as the initial stack allocated chunk so that we don't |
122 // end up calling malloc/free on zone scopes that allocate less than | 123 // end up calling malloc/free on zone scopes that allocate less than |
123 // kChunkSize | 124 // kChunkSize |
124 uint8_t buffer_[kInitialChunkSize]; | 125 COMPILE_ASSERT(kAlignment <= 8); |
| 126 ALIGN8 uint8_t buffer_[kInitialChunkSize]; |
125 MemoryRegion initial_buffer_; | 127 MemoryRegion initial_buffer_; |
126 | 128 |
127 // The free region in the current (head) segment or the initial buffer is | 129 // The free region in the current (head) segment or the initial buffer is |
128 // represented as the half-open interval [position, limit). The 'position' | 130 // represented as the half-open interval [position, limit). The 'position' |
129 // variable is guaranteed to be aligned as dictated by kAlignment. | 131 // variable is guaranteed to be aligned as dictated by kAlignment. |
130 uword position_; | 132 uword position_; |
131 uword limit_; | 133 uword limit_; |
132 | 134 |
133 // Zone segments are internal data structures used to hold information | 135 // Zone segments are internal data structures used to hold information |
134 // about the memory segmentations that constitute a zone. The entire | 136 // about the memory segmentations that constitute a zone. The entire |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 reinterpret_cast<void*>(old_data), | 247 reinterpret_cast<void*>(old_data), |
246 Utils::Minimum(old_len * sizeof(ElementType), | 248 Utils::Minimum(old_len * sizeof(ElementType), |
247 new_len * sizeof(ElementType))); | 249 new_len * sizeof(ElementType))); |
248 } | 250 } |
249 return new_data; | 251 return new_data; |
250 } | 252 } |
251 | 253 |
252 } // namespace dart | 254 } // namespace dart |
253 | 255 |
254 #endif // VM_ZONE_H_ | 256 #endif // VM_ZONE_H_ |
OLD | NEW |