Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Side by Side Diff: runtime/vm/zone.h

Issue 2362573002: Move Zone's destructor out of a header file. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/symbols.cc ('k') | runtime/vm/zone.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Compute the total size of this zone. This includes wasted space that is 64 // Compute the total size of this zone. This includes wasted space that is
65 // due to internal fragmentation in the segments. 65 // due to internal fragmentation in the segments.
66 intptr_t SizeInBytes() const; 66 intptr_t SizeInBytes() const;
67 67
68 // Structure for managing handles allocation. 68 // Structure for managing handles allocation.
69 VMHandles* handles() { return &handles_; } 69 VMHandles* handles() { return &handles_; }
70 70
71 void VisitObjectPointers(ObjectPointerVisitor* visitor); 71 void VisitObjectPointers(ObjectPointerVisitor* visitor);
72 72
73 private: 73 private:
74 Zone() 74 Zone();
75 : initial_buffer_(buffer_, kInitialChunkSize), 75 ~Zone(); // Delete all memory associated with the zone.
76 position_(initial_buffer_.start()),
77 limit_(initial_buffer_.end()),
78 head_(NULL),
79 large_segments_(NULL),
80 handles_(),
81 previous_(NULL) {
82 ASSERT(Utils::IsAligned(position_, kAlignment));
83 #ifdef DEBUG
84 // Zap the entire initial buffer.
85 memset(initial_buffer_.pointer(), kZapUninitializedByte,
86 initial_buffer_.size());
87 #endif
88 }
89
90 ~Zone() { // Delete all memory associated with the zone.
91 if (FLAG_trace_zones) {
92 DumpZoneSizes();
93 }
94 DeleteAll();
95 }
96 76
97 // All pointers returned from AllocateUnsafe() and New() have this alignment. 77 // All pointers returned from AllocateUnsafe() and New() have this alignment.
98 static const intptr_t kAlignment = kDoubleSize; 78 static const intptr_t kAlignment = kDoubleSize;
99 79
100 // Default initial chunk size. 80 // Default initial chunk size.
101 static const intptr_t kInitialChunkSize = 1 * KB; 81 static const intptr_t kInitialChunkSize = 1 * KB;
102 82
103 // Default segment size. 83 // Default segment size.
104 static const intptr_t kSegmentSize = 64 * KB; 84 static const intptr_t kSegmentSize = 64 * KB;
105 85
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 friend class BaseGrowableArray; 158 friend class BaseGrowableArray;
179 template<typename T, typename B, typename Allocator> 159 template<typename T, typename B, typename Allocator>
180 friend class BaseDirectChainedHashMap; 160 friend class BaseDirectChainedHashMap;
181 DISALLOW_COPY_AND_ASSIGN(Zone); 161 DISALLOW_COPY_AND_ASSIGN(Zone);
182 }; 162 };
183 163
184 164
185 class StackZone : public StackResource { 165 class StackZone : public StackResource {
186 public: 166 public:
187 // Create an empty zone and set is at the current zone for the Thread. 167 // Create an empty zone and set is at the current zone for the Thread.
188 explicit StackZone(Thread* thread) : StackResource(thread), zone_() { 168 explicit StackZone(Thread* thread);
189 if (FLAG_trace_zones) {
190 OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n",
191 reinterpret_cast<intptr_t>(this),
192 reinterpret_cast<intptr_t>(&zone_));
193 }
194 zone_.Link(thread->zone());
195 thread->set_zone(&zone_);
196 }
197 169
198 // Delete all memory associated with the zone. 170 // Delete all memory associated with the zone.
199 ~StackZone() { 171 ~StackZone();
200 ASSERT(thread()->zone() == &zone_);
201 thread()->set_zone(zone_.previous_);
202 if (FLAG_trace_zones) {
203 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n",
204 reinterpret_cast<intptr_t>(this),
205 reinterpret_cast<intptr_t>(&zone_));
206 }
207 }
208 172
209 // Compute the total size of this zone. This includes wasted space that is 173 // Compute the total size of this zone. This includes wasted space that is
210 // due to internal fragmentation in the segments. 174 // due to internal fragmentation in the segments.
211 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } 175 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
212 176
213 Zone* GetZone() { return &zone_; } 177 Zone* GetZone() { return &zone_; }
214 178
215 private: 179 private:
216 Zone zone_; 180 Zone zone_;
217 181
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 memmove(reinterpret_cast<void*>(new_data), 251 memmove(reinterpret_cast<void*>(new_data),
288 reinterpret_cast<void*>(old_data), 252 reinterpret_cast<void*>(old_data),
289 old_len * kElementSize); 253 old_len * kElementSize);
290 } 254 }
291 return new_data; 255 return new_data;
292 } 256 }
293 257
294 } // namespace dart 258 } // namespace dart
295 259
296 #endif // VM_ZONE_H_ 260 #endif // VM_ZONE_H_
OLDNEW
« no previous file with comments | « runtime/vm/symbols.cc ('k') | runtime/vm/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698