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

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

Issue 22307003: Rearrange some methods so that they get inlined. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/vm_sources.gypi ('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"
11 #include "vm/memory_region.h" 11 #include "vm/memory_region.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 DECLARE_DEBUG_FLAG(bool, trace_zones);
16
15 // Zones support very fast allocation of small chunks of memory. The 17 // Zones support very fast allocation of small chunks of memory. The
16 // chunks cannot be deallocated individually, but instead zones 18 // chunks cannot be deallocated individually, but instead zones
17 // support deallocating all chunks in one fast operation. 19 // support deallocating all chunks in one fast operation.
18 20
19 class Zone { 21 class Zone {
20 public: 22 public:
21 // Allocate an array sized to hold 'len' elements of type 23 // Allocate an array sized to hold 'len' elements of type
22 // 'ElementType'. Checks for integer overflow when performing the 24 // 'ElementType'. Checks for integer overflow when performing the
23 // size computation. 25 // size computation.
24 template <class ElementType> 26 template <class ElementType>
(...skipping 25 matching lines...) Expand all
50 // Compute the total size of this zone. This includes wasted space that is 52 // Compute the total size of this zone. This includes wasted space that is
51 // due to internal fragmentation in the segments. 53 // due to internal fragmentation in the segments.
52 intptr_t SizeInBytes() const; 54 intptr_t SizeInBytes() const;
53 55
54 // Structure for managing handles allocation. 56 // Structure for managing handles allocation.
55 VMHandles* handles() { return &handles_; } 57 VMHandles* handles() { return &handles_; }
56 58
57 void VisitObjectPointers(ObjectPointerVisitor* visitor); 59 void VisitObjectPointers(ObjectPointerVisitor* visitor);
58 60
59 private: 61 private:
60 Zone(); 62 Zone()
61 ~Zone(); // Delete all memory associated with the zone. 63 : initial_buffer_(buffer_, kInitialChunkSize),
64 position_(initial_buffer_.start()),
65 limit_(initial_buffer_.end()),
66 head_(NULL),
67 large_segments_(NULL),
68 handles_(),
69 previous_(NULL) {
70 #ifdef DEBUG
71 // Zap the entire initial buffer.
72 memset(initial_buffer_.pointer(), kZapUninitializedByte,
73 initial_buffer_.size());
74 #endif
75 }
76
77 ~Zone() { // Delete all memory associated with the zone.
78 #if defined(DEBUG)
79 if (FLAG_trace_zones) {
80 DumpZoneSizes();
81 }
82 #endif
83 DeleteAll();
84 }
62 85
63 // All pointers returned from AllocateUnsafe() and New() have this alignment. 86 // All pointers returned from AllocateUnsafe() and New() have this alignment.
64 static const intptr_t kAlignment = kWordSize; 87 static const intptr_t kAlignment = kWordSize;
65 88
66 // Default initial chunk size. 89 // Default initial chunk size.
67 static const intptr_t kInitialChunkSize = 1 * KB; 90 static const intptr_t kInitialChunkSize = 1 * KB;
68 91
69 // Default segment size. 92 // Default segment size.
70 static const intptr_t kSegmentSize = 64 * KB; 93 static const intptr_t kSegmentSize = 64 * KB;
71 94
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 friend class StackZone; 150 friend class StackZone;
128 friend class ApiZone; 151 friend class ApiZone;
129 template<typename T, typename B> friend class BaseGrowableArray; 152 template<typename T, typename B> friend class BaseGrowableArray;
130 DISALLOW_COPY_AND_ASSIGN(Zone); 153 DISALLOW_COPY_AND_ASSIGN(Zone);
131 }; 154 };
132 155
133 156
134 class StackZone : public StackResource { 157 class StackZone : public StackResource {
135 public: 158 public:
136 // Create an empty zone and set is at the current zone for the Isolate. 159 // Create an empty zone and set is at the current zone for the Isolate.
137 explicit StackZone(BaseIsolate* isolate); 160 explicit StackZone(BaseIsolate* isolate)
161 : StackResource(isolate),
162 zone_() {
163 #ifdef DEBUG
164 if (FLAG_trace_zones) {
165 OS::PrintErr("*** Starting a new Stack zone 0x%"Px"(0x%"Px")\n",
166 reinterpret_cast<intptr_t>(this),
167 reinterpret_cast<intptr_t>(&zone_));
168 }
169 #endif
170 zone_.Link(isolate->current_zone());
171 isolate->set_current_zone(&zone_);
172 }
138 173
139 // Delete all memory associated with the zone. 174 // Delete all memory associated with the zone.
140 ~StackZone(); 175 ~StackZone() {
176 ASSERT(isolate()->current_zone() == &zone_);
177 isolate()->set_current_zone(zone_.previous_);
178 #ifdef DEBUG
179 if (FLAG_trace_zones) {
180 OS::PrintErr("*** Deleting Stack zone 0x%"Px"(0x%"Px")\n",
181 reinterpret_cast<intptr_t>(this),
182 reinterpret_cast<intptr_t>(&zone_));
183 }
184 #endif
185 }
141 186
142 // Compute the total size of this zone. This includes wasted space that is 187 // Compute the total size of this zone. This includes wasted space that is
143 // due to internal fragmentation in the segments. 188 // due to internal fragmentation in the segments.
144 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } 189 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
145 190
146 Zone* GetZone() { return &zone_; } 191 Zone* GetZone() { return &zone_; }
147 192
148 private: 193 private:
149 Zone zone_; 194 Zone zone_;
150 195
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 reinterpret_cast<void*>(old_data), 243 reinterpret_cast<void*>(old_data),
199 Utils::Minimum(old_len * sizeof(ElementType), 244 Utils::Minimum(old_len * sizeof(ElementType),
200 new_len * sizeof(ElementType))); 245 new_len * sizeof(ElementType)));
201 } 246 }
202 return new_data; 247 return new_data;
203 } 248 }
204 249
205 } // namespace dart 250 } // namespace dart
206 251
207 #endif // VM_ZONE_H_ 252 #endif // VM_ZONE_H_
OLDNEW
« no previous file with comments | « runtime/vm/vm_sources.gypi ('k') | runtime/vm/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698