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

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

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 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/weak_table.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 RUNTIME_VM_ZONE_H_ 5 #ifndef RUNTIME_VM_ZONE_H_
6 #define RUNTIME_VM_ZONE_H_ 6 #define RUNTIME_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/json_stream.h" 11 #include "vm/json_stream.h"
12 #include "vm/memory_region.h"
12 #include "vm/thread.h" 13 #include "vm/thread.h"
13 #include "vm/memory_region.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 // Zones support very fast allocation of small chunks of memory. The 17 // Zones support very fast allocation of small chunks of memory. The
18 // chunks cannot be deallocated individually, but instead zones 18 // chunks cannot be deallocated individually, but instead zones
19 // support deallocating all chunks in one fast operation. 19 // support deallocating all chunks in one fast operation.
20 20
21 class Zone { 21 class Zone {
22 public: 22 public:
23 // Allocate an array sized to hold 'len' elements of type 23 // Allocate an array sized to hold 'len' elements of type
(...skipping 11 matching lines...) Expand all
35 intptr_t new_len); 35 intptr_t new_len);
36 36
37 // Allocates 'size' bytes of memory in the zone; expands the zone by 37 // Allocates 'size' bytes of memory in the zone; expands the zone by
38 // allocating new segments of memory on demand using 'new'. 38 // allocating new segments of memory on demand using 'new'.
39 // 39 //
40 // It is preferred to use Alloc<T>() instead, as that function can 40 // It is preferred to use Alloc<T>() instead, as that function can
41 // check for integer overflow. If you use AllocUnsafe, you are 41 // check for integer overflow. If you use AllocUnsafe, you are
42 // responsible for avoiding integer overflow yourself. 42 // responsible for avoiding integer overflow yourself.
43 inline uword AllocUnsafe(intptr_t size); 43 inline uword AllocUnsafe(intptr_t size);
44 44
45
46 // Make a copy of the string in the zone allocated area. 45 // Make a copy of the string in the zone allocated area.
47 char* MakeCopyOfString(const char* str); 46 char* MakeCopyOfString(const char* str);
48 47
49 // Make a copy of the first n characters of a string in the zone 48 // Make a copy of the first n characters of a string in the zone
50 // allocated area. 49 // allocated area.
51 char* MakeCopyOfStringN(const char* str, intptr_t len); 50 char* MakeCopyOfStringN(const char* str, intptr_t len);
52 51
53 // Concatenate strings |a| and |b|. |a| may be NULL. If |a| is not NULL, 52 // Concatenate strings |a| and |b|. |a| may be NULL. If |a| is not NULL,
54 // |join| will be inserted between |a| and |b|. 53 // |join| will be inserted between |a| and |b|.
55 char* ConcatStrings(const char* a, const char* b, char join = ','); 54 char* ConcatStrings(const char* a, const char* b, char join = ',');
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 157
159 friend class StackZone; 158 friend class StackZone;
160 friend class ApiZone; 159 friend class ApiZone;
161 template <typename T, typename B, typename Allocator> 160 template <typename T, typename B, typename Allocator>
162 friend class BaseGrowableArray; 161 friend class BaseGrowableArray;
163 template <typename T, typename B, typename Allocator> 162 template <typename T, typename B, typename Allocator>
164 friend class BaseDirectChainedHashMap; 163 friend class BaseDirectChainedHashMap;
165 DISALLOW_COPY_AND_ASSIGN(Zone); 164 DISALLOW_COPY_AND_ASSIGN(Zone);
166 }; 165 };
167 166
168
169 class StackZone : public StackResource { 167 class StackZone : public StackResource {
170 public: 168 public:
171 // Create an empty zone and set is at the current zone for the Thread. 169 // Create an empty zone and set is at the current zone for the Thread.
172 explicit StackZone(Thread* thread); 170 explicit StackZone(Thread* thread);
173 171
174 // Delete all memory associated with the zone. 172 // Delete all memory associated with the zone.
175 ~StackZone(); 173 ~StackZone();
176 174
177 // Compute the total size of this zone. This includes wasted space that is 175 // Compute the total size of this zone. This includes wasted space that is
178 // due to internal fragmentation in the segments. 176 // due to internal fragmentation in the segments.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 position_ += size; 208 position_ += size;
211 } else { 209 } else {
212 result = AllocateExpand(size); 210 result = AllocateExpand(size);
213 } 211 }
214 212
215 // Check that the result has the proper alignment and return it. 213 // Check that the result has the proper alignment and return it.
216 ASSERT(Utils::IsAligned(result, kAlignment)); 214 ASSERT(Utils::IsAligned(result, kAlignment));
217 return result; 215 return result;
218 } 216 }
219 217
220
221 template <class ElementType> 218 template <class ElementType>
222 inline void Zone::CheckLength(intptr_t len) { 219 inline void Zone::CheckLength(intptr_t len) {
223 const intptr_t kElementSize = sizeof(ElementType); 220 const intptr_t kElementSize = sizeof(ElementType);
224 if (len > (kIntptrMax / kElementSize)) { 221 if (len > (kIntptrMax / kElementSize)) {
225 FATAL2("Zone::Alloc: 'len' is too large: len=%" Pd ", kElementSize=%" Pd, 222 FATAL2("Zone::Alloc: 'len' is too large: len=%" Pd ", kElementSize=%" Pd,
226 len, kElementSize); 223 len, kElementSize);
227 } 224 }
228 } 225 }
229 226
230
231 template <class ElementType> 227 template <class ElementType>
232 inline ElementType* Zone::Alloc(intptr_t len) { 228 inline ElementType* Zone::Alloc(intptr_t len) {
233 CheckLength<ElementType>(len); 229 CheckLength<ElementType>(len);
234 return reinterpret_cast<ElementType*>(AllocUnsafe(len * sizeof(ElementType))); 230 return reinterpret_cast<ElementType*>(AllocUnsafe(len * sizeof(ElementType)));
235 } 231 }
236 232
237 template <class ElementType> 233 template <class ElementType>
238 inline ElementType* Zone::Realloc(ElementType* old_data, 234 inline ElementType* Zone::Realloc(ElementType* old_data,
239 intptr_t old_len, 235 intptr_t old_len,
240 intptr_t new_len) { 236 intptr_t new_len) {
(...skipping 18 matching lines...) Expand all
259 if (old_data != 0) { 255 if (old_data != 0) {
260 memmove(reinterpret_cast<void*>(new_data), 256 memmove(reinterpret_cast<void*>(new_data),
261 reinterpret_cast<void*>(old_data), old_len * kElementSize); 257 reinterpret_cast<void*>(old_data), old_len * kElementSize);
262 } 258 }
263 return new_data; 259 return new_data;
264 } 260 }
265 261
266 } // namespace dart 262 } // namespace dart
267 263
268 #endif // RUNTIME_VM_ZONE_H_ 264 #endif // RUNTIME_VM_ZONE_H_
OLDNEW
« no previous file with comments | « runtime/vm/weak_table.cc ('k') | runtime/vm/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698