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

Side by Side Diff: src/zone.h

Issue 2493002: - Remove [static] from methods in Zone and associated helpers. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 10 years, 6 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // allocation is attempted, a segment of memory will be requested 50 // allocation is attempted, a segment of memory will be requested
51 // through a call to malloc(). 51 // through a call to malloc().
52 52
53 // Note: The implementation is inherently not thread safe. Do not use 53 // Note: The implementation is inherently not thread safe. Do not use
54 // from multi-threaded code. 54 // from multi-threaded code.
55 55
56 class Zone { 56 class Zone {
57 public: 57 public:
58 // Allocate 'size' bytes of memory in the Zone; expands the Zone by 58 // Allocate 'size' bytes of memory in the Zone; expands the Zone by
59 // allocating new segments of memory on demand using malloc(). 59 // allocating new segments of memory on demand using malloc().
60 static inline void* New(int size); 60 inline void* New(int size);
61 61
62 template <typename T> 62 template <typename T>
63 static inline T* NewArray(int length); 63 inline T* NewArray(int length);
64 64
65 // Delete all objects and free all memory allocated in the Zone. 65 // Delete all objects and free all memory allocated in the Zone.
66 static void DeleteAll(); 66 void DeleteAll();
67 67
68 // Returns true if more memory has been allocated in zones than 68 // Returns true if more memory has been allocated in zones than
69 // the limit allows. 69 // the limit allows.
70 static inline bool excess_allocation(); 70 inline bool excess_allocation();
71 71
72 static inline void adjust_segment_bytes_allocated(int delta); 72 inline void adjust_segment_bytes_allocated(int delta);
73 73
74 private: 74 private:
75 75 friend class Isolate;
76
76 // All pointers returned from New() have this alignment. 77 // All pointers returned from New() have this alignment.
77 static const int kAlignment = kPointerSize; 78 static const int kAlignment = kPointerSize;
78 79
79 // Never allocate segments smaller than this size in bytes. 80 // Never allocate segments smaller than this size in bytes.
80 static const int kMinimumSegmentSize = 8 * KB; 81 static const int kMinimumSegmentSize = 8 * KB;
81 82
82 // Never allocate segments larger than this size in bytes. 83 // Never allocate segments larger than this size in bytes.
83 static const int kMaximumSegmentSize = 1 * MB; 84 static const int kMaximumSegmentSize = 1 * MB;
84 85
85 // Never keep segments larger than this size in bytes around. 86 // Never keep segments larger than this size in bytes around.
86 static const int kMaximumKeptSegmentSize = 64 * KB; 87 static const int kMaximumKeptSegmentSize = 64 * KB;
87 88
88 // Report zone excess when allocation exceeds this limit. 89 // Report zone excess when allocation exceeds this limit.
89 static int zone_excess_limit_; 90 int zone_excess_limit_;
90 91
91 // The number of bytes allocated in segments. Note that this number 92 // The number of bytes allocated in segments. Note that this number
92 // includes memory allocated from the OS but not yet allocated from 93 // includes memory allocated from the OS but not yet allocated from
93 // the zone. 94 // the zone.
94 static int segment_bytes_allocated_; 95 int segment_bytes_allocated_;
95 96
96 // The Zone is intentionally a singleton; you should not try to 97 // Each isolate gets its own zone.
97 // allocate instances of the class. 98 Zone();
98 Zone() { UNREACHABLE(); }
99
100 99
101 // Expand the Zone to hold at least 'size' more bytes and allocate 100 // Expand the Zone to hold at least 'size' more bytes and allocate
102 // the bytes. Returns the address of the newly allocated chunk of 101 // the bytes. Returns the address of the newly allocated chunk of
103 // memory in the Zone. Should only be called if there isn't enough 102 // memory in the Zone. Should only be called if there isn't enough
104 // room in the Zone already. 103 // room in the Zone already.
105 static Address NewExpand(int size); 104 Address NewExpand(int size);
106 105
107 106
108 // The free region in the current (front) segment is represented as 107 // The free region in the current (front) segment is represented as
109 // the half-open interval [position, limit). The 'position' variable 108 // the half-open interval [position, limit). The 'position' variable
110 // is guaranteed to be aligned as dictated by kAlignment. 109 // is guaranteed to be aligned as dictated by kAlignment.
111 static Address position_; 110 Address position_;
112 static Address limit_; 111 Address limit_;
113 }; 112 };
114 113
115 114
116 // ZoneObject is an abstraction that helps define classes of objects 115 // ZoneObject is an abstraction that helps define classes of objects
117 // allocated in the Zone. Use it as a base class; see ast.h. 116 // allocated in the Zone. Use it as a base class; see ast.h.
118 class ZoneObject { 117 class ZoneObject {
119 public: 118 public:
120 // Allocate a new ZoneObject of 'size' bytes in the Zone. 119 // Allocate a new ZoneObject of 'size' bytes in the Zone.
121 void* operator new(size_t size) { return Zone::New(static_cast<int>(size)); } 120 inline void* operator new(size_t size);
122 121
123 // Ideally, the delete operator should be private instead of 122 // Ideally, the delete operator should be private instead of
124 // public, but unfortunately the compiler sometimes synthesizes 123 // public, but unfortunately the compiler sometimes synthesizes
125 // (unused) destructors for classes derived from ZoneObject, which 124 // (unused) destructors for classes derived from ZoneObject, which
126 // require the operator to be visible. MSVC requires the delete 125 // require the operator to be visible. MSVC requires the delete
127 // operator to be public. 126 // operator to be public.
128 127
129 // ZoneObjects should never be deleted individually; use 128 // ZoneObjects should never be deleted individually; use
130 // Zone::DeleteAll() to delete all zone objects in one go. 129 // Zone::DeleteAll() to delete all zone objects in one go.
131 void operator delete(void*, size_t) { UNREACHABLE(); } 130 void operator delete(void*, size_t) { UNREACHABLE(); }
132 }; 131 };
133 132
134 133
135 class AssertNoZoneAllocation { 134 class AssertNoZoneAllocation {
136 public: 135 public:
137 AssertNoZoneAllocation() : prev_(allow_allocation_) { 136 inline AssertNoZoneAllocation();
138 allow_allocation_ = false; 137 inline ~AssertNoZoneAllocation();
139 }
140 ~AssertNoZoneAllocation() { allow_allocation_ = prev_; }
141 static bool allow_allocation() { return allow_allocation_; }
142 private: 138 private:
143 bool prev_; 139 bool prev_;
144 static bool allow_allocation_;
145 }; 140 };
146 141
147 142
148 // The ZoneListAllocationPolicy is used to specialize the GenericList 143 // The ZoneListAllocationPolicy is used to specialize the GenericList
149 // implementation to allocate ZoneLists and their elements in the 144 // implementation to allocate ZoneLists and their elements in the
150 // Zone. 145 // Zone.
151 class ZoneListAllocationPolicy { 146 class ZoneListAllocationPolicy {
152 public: 147 public:
153 // Allocate 'size' bytes of memory in the zone. 148 // Allocate 'size' bytes of memory in the zone.
154 static void* New(int size) { return Zone::New(size); } 149 static inline void* New(int size);
155 150
156 // De-allocation attempts are silently ignored. 151 // De-allocation attempts are silently ignored.
157 static void Delete(void* p) { } 152 static void Delete(void* p) { }
158 }; 153 };
159 154
160 155
161 // ZoneLists are growable lists with constant-time access to the 156 // ZoneLists are growable lists with constant-time access to the
162 // elements. The list itself and all its elements are allocated in the 157 // elements. The list itself and all its elements are allocated in the
163 // Zone. ZoneLists cannot be deleted individually; you can delete all 158 // Zone. ZoneLists cannot be deleted individually; you can delete all
164 // objects in the Zone by calling Zone::DeleteAll(). 159 // objects in the Zone by calling Zone::DeleteAll().
165 template<typename T> 160 template<typename T>
166 class ZoneList: public List<T, ZoneListAllocationPolicy> { 161 class ZoneList: public List<T, ZoneListAllocationPolicy> {
167 public: 162 public:
168 // Construct a new ZoneList with the given capacity; the length is 163 // Construct a new ZoneList with the given capacity; the length is
169 // always zero. The capacity must be non-negative. 164 // always zero. The capacity must be non-negative.
170 explicit ZoneList(int capacity) 165 explicit ZoneList(int capacity)
171 : List<T, ZoneListAllocationPolicy>(capacity) { } 166 : List<T, ZoneListAllocationPolicy>(capacity) { }
172 }; 167 };
173 168
174 169
175 // ZoneScopes keep track of the current parsing and compilation 170 // ZoneScopes keep track of the current parsing and compilation
176 // nesting and cleans up generated ASTs in the Zone when exiting the 171 // nesting and cleans up generated ASTs in the Zone when exiting the
177 // outer-most scope. 172 // outer-most scope.
178 class ZoneScope BASE_EMBEDDED { 173 class ZoneScope BASE_EMBEDDED {
179 public: 174 public:
180 explicit ZoneScope(ZoneScopeMode mode) : mode_(mode) { 175 explicit ZoneScope(ZoneScopeMode mode) : mode_(mode) {
181 nesting_++; 176 nesting_++;
182 } 177 }
183 178
184 virtual ~ZoneScope() { 179 virtual ~ZoneScope();
185 if (ShouldDeleteOnExit()) Zone::DeleteAll();
186 --nesting_;
187 }
188 180
189 bool ShouldDeleteOnExit() { 181 bool ShouldDeleteOnExit() {
190 return nesting_ == 1 && mode_ == DELETE_ON_EXIT; 182 return nesting_ == 1 && mode_ == DELETE_ON_EXIT;
191 } 183 }
192 184
193 // For ZoneScopes that do not delete on exit by default, call this 185 // For ZoneScopes that do not delete on exit by default, call this
194 // method to request deletion on exit. 186 // method to request deletion on exit.
195 void DeleteOnExit() { 187 void DeleteOnExit() {
196 mode_ = DELETE_ON_EXIT; 188 mode_ = DELETE_ON_EXIT;
197 } 189 }
(...skipping 14 matching lines...) Expand all
212 public: 204 public:
213 ZoneSplayTree() 205 ZoneSplayTree()
214 : SplayTree<Config, ZoneListAllocationPolicy>() {} 206 : SplayTree<Config, ZoneListAllocationPolicy>() {}
215 ~ZoneSplayTree(); 207 ~ZoneSplayTree();
216 }; 208 };
217 209
218 210
219 } } // namespace v8::internal 211 } } // namespace v8::internal
220 212
221 #endif // V8_ZONE_H_ 213 #endif // V8_ZONE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698