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

Side by Side Diff: src/zone.h

Issue 456663002: Make Zone::New() and Zone::NewArray() usable w/o v8.h. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | « no previous file | src/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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ZONE_H_ 5 #ifndef V8_ZONE_H_
6 #define V8_ZONE_H_ 6 #define V8_ZONE_H_
7 7
8 #include <limits>
9
8 #include "src/allocation.h" 10 #include "src/allocation.h"
9 #include "src/base/logging.h" 11 #include "src/base/logging.h"
10 #include "src/globals.h" 12 #include "src/globals.h"
11 #include "src/hashmap.h" 13 #include "src/hashmap.h"
12 #include "src/list.h" 14 #include "src/list.h"
13 #include "src/splay-tree.h" 15 #include "src/splay-tree.h"
14 16
15 namespace v8 { 17 namespace v8 {
16 namespace internal { 18 namespace internal {
17 19
(...skipping 13 matching lines...) Expand all
31 33
32 // Note: The implementation is inherently not thread safe. Do not use 34 // Note: The implementation is inherently not thread safe. Do not use
33 // from multi-threaded code. 35 // from multi-threaded code.
34 36
35 class Zone { 37 class Zone {
36 public: 38 public:
37 explicit Zone(Isolate* isolate); 39 explicit Zone(Isolate* isolate);
38 ~Zone(); 40 ~Zone();
39 // Allocate 'size' bytes of memory in the Zone; expands the Zone by 41 // Allocate 'size' bytes of memory in the Zone; expands the Zone by
40 // allocating new segments of memory on demand using malloc(). 42 // allocating new segments of memory on demand using malloc().
41 inline void* New(int size); 43 void* New(int size);
42 44
43 template <typename T> 45 template <typename T>
44 inline T* NewArray(int length); 46 T* NewArray(int length) {
47 CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) >
48 length);
49 return static_cast<T*>(New(length * sizeof(T)));
50 }
45 51
46 // Deletes all objects and free all memory allocated in the Zone. Keeps one 52 // Deletes all objects and free all memory allocated in the Zone. Keeps one
47 // small (size <= kMaximumKeptSegmentSize) segment around if it finds one. 53 // small (size <= kMaximumKeptSegmentSize) segment around if it finds one.
48 void DeleteAll(); 54 void DeleteAll();
49 55
50 // Deletes the last small segment kept around by DeleteAll(). You 56 // Deletes the last small segment kept around by DeleteAll(). You
51 // may no longer allocate in the Zone after a call to this method. 57 // may no longer allocate in the Zone after a call to this method.
52 void DeleteKeptSegment(); 58 void DeleteKeptSegment();
53 59
54 // Returns true if more memory has been allocated in zones than 60 // Returns true if more memory has been allocated in zones than
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void operator delete(void* pointer) { UNREACHABLE(); } 240 void operator delete(void* pointer) { UNREACHABLE(); }
235 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 241 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
236 }; 242 };
237 243
238 244
239 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; 245 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
240 246
241 } } // namespace v8::internal 247 } } // namespace v8::internal
242 248
243 #endif // V8_ZONE_H_ 249 #endif // V8_ZONE_H_
OLDNEW
« no previous file with comments | « no previous file | src/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698