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

Side by Side Diff: src/assert-scope.h

Issue 396923002: Reduce amount of boilerplate in assert-scope.h (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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_ASSERT_SCOPE_H_ 5 #ifndef V8_ASSERT_SCOPE_H_
6 #define V8_ASSERT_SCOPE_H_ 6 #define V8_ASSERT_SCOPE_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/utils.h" 10 #include "src/utils.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 class Isolate; 15 class Isolate;
16 16
17 #define PER_THREAD_ASSERT_LIST(V) \
18 V(HEAP_ALLOCATION_ASSERT, AllowHeapAllocation, DisallowHeapAllocation, \
19 DebugOnly) \
20 V(HANDLE_ALLOCATION_ASSERT, AllowHandleAllocation, DisallowHandleAllocation, \
21 DebugOnly) \
22 V(HANDLE_DEREFERENCE_ASSERT, AllowHandleDereference, \
23 DisallowHandleDereference, DebugOnly) \
24 V(DEFERRED_HANDLE_DEREFERENCE_ASSERT, AllowDeferredHandleDereference, \
25 DisallowDeferredHandleDereference, DebugOnly) \
26 V(CODE_DEPENDENCY_CHANGE_ASSERT, AllowCodeDependencyChange, \
27 DisallowCodeDependencyChange, DebugOnly)
28
29 #define PER_ISOLATE_ASSERT_LIST(V) \
30 V(JAVASCRIPT_EXECUTION_ASSERT, AllowJavascriptExecution, \
31 DisallowJavascriptExecution, ReleaseAndDebug) \
32 V(JAVASCRIPT_EXECUTION_THROWS, NoThrowOnJavascriptExecution, \
33 ThrowOnJavascriptExecution, ReleaseAndDebug) \
34 V(ALLOCATION_FAILURE_ASSERT, AllowAllocationFailure, \
35 DisallowAllocationFailure, DebugOnly) \
36 V(DEOPTIMIZATION_ASSERT, AllowDeoptimization, DisallowDeoptimization, \
37 DebugOnly) \
38 V(COMPILATION_ASSERT, AllowCompilation, DisallowCompilation, DebugOnly)
39
40
17 enum PerThreadAssertType { 41 enum PerThreadAssertType {
18 HEAP_ALLOCATION_ASSERT, 42 #define V(NAME, PositiveName, NegativeName, BuildMode) NAME,
19 HANDLE_ALLOCATION_ASSERT, 43 PER_THREAD_ASSERT_LIST(V)
20 HANDLE_DEREFERENCE_ASSERT, 44 #undef V
21 DEFERRED_HANDLE_DEREFERENCE_ASSERT,
22 CODE_DEPENDENCY_CHANGE_ASSERT,
23 LAST_PER_THREAD_ASSERT_TYPE 45 LAST_PER_THREAD_ASSERT_TYPE
24 }; 46 };
25 47
26 48
27 enum PerIsolateAssertType { 49 enum PerIsolateAssertType {
28 JAVASCRIPT_EXECUTION_ASSERT, 50 #define V(NAME, PositiveName, NegativeName, BuildMode) NAME,
29 JAVASCRIPT_EXECUTION_THROWS, 51 PER_ISOLATE_ASSERT_LIST(V)
30 ALLOCATION_FAILURE_ASSERT, 52 #undef V
31 DEOPTIMIZATION_ASSERT, 53 LAST_PER_ISOLATE_ASSERT_TYPE
32 COMPILATION_ASSERT
33 }; 54 };
34 55
35 56
36 class PerThreadAssertData { 57 class PerThreadAssertData {
37 public: 58 public:
38 PerThreadAssertData() : nesting_level_(0) { 59 PerThreadAssertData() : nesting_level_(0) {
39 for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) { 60 for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) {
40 assert_states_[i] = true; 61 assert_states_[i] = true;
41 } 62 }
42 } 63 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 public: 192 public:
172 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) 193 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate)
173 : PerIsolateAssertScope<type, allow>(isolate) { } 194 : PerIsolateAssertScope<type, allow>(isolate) { }
174 #else 195 #else
175 class PerIsolateAssertScopeDebugOnly { 196 class PerIsolateAssertScopeDebugOnly {
176 public: 197 public:
177 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { } 198 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { }
178 #endif 199 #endif
179 }; 200 };
180 201
181 // Per-thread assert scopes.
182 202
183 // Scope to document where we do not expect handles to be created. 203 // Define Per-thread assert scopes.
184 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, false> 204 #define PerThreadAssertScopeReleaseAndDebug PerThreadAssertScope
185 DisallowHandleAllocation; 205 #define V(NAME, PositiveName, NegativeName, BuildMode) \
206 typedef PerThreadAssertScope##BuildMode<NAME, false> NegativeName; \
207 typedef PerThreadAssertScope##BuildMode<NAME, true> PositiveName;
208 PER_THREAD_ASSERT_LIST(V)
209 #undef V
210 #undef PerThreadAssertScopeReleaseAndDebug
186 211
187 // Scope to introduce an exception to DisallowHandleAllocation. 212 // Define Per-isolate assert scopes.
188 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, true> 213 #define PerIsolateAssertScopeReleaseAndDebug PerIsolateAssertScope
189 AllowHandleAllocation; 214 #define V(NAME, PositiveName, NegativeName, BuildMode) \
190 215 typedef PerIsolateAssertScope##BuildMode<NAME, false> NegativeName; \
191 // Scope to document where we do not expect any allocation and GC. 216 typedef PerIsolateAssertScope##BuildMode<NAME, true> PositiveName;
192 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, false> 217 PER_ISOLATE_ASSERT_LIST(V)
193 DisallowHeapAllocation; 218 #undef V
194 219 #undef PerIsolateAssertScopeReleaseAndDebug
195 // Scope to introduce an exception to DisallowHeapAllocation.
196 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, true>
197 AllowHeapAllocation;
198
199 // Scope to document where we do not expect any handle dereferences.
200 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, false>
201 DisallowHandleDereference;
202
203 // Scope to introduce an exception to DisallowHandleDereference.
204 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, true>
205 AllowHandleDereference;
206
207 // Scope to document where we do not expect deferred handles to be dereferenced.
208 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false>
209 DisallowDeferredHandleDereference;
210
211 // Scope to introduce an exception to DisallowDeferredHandleDereference.
212 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true>
213 AllowDeferredHandleDereference;
214
215 // Scope to document where we do not expect deferred handles to be dereferenced.
216 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, false>
217 DisallowCodeDependencyChange;
218
219 // Scope to introduce an exception to DisallowDeferredHandleDereference.
220 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, true>
221 AllowCodeDependencyChange;
222
223
224 // Per-isolate assert scopes.
225
226 // Scope to document where we do not expect javascript execution.
227 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, false>
228 DisallowJavascriptExecution;
229
230 // Scope to introduce an exception to DisallowJavascriptExecution.
231 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true>
232 AllowJavascriptExecution;
233
234 // Scope in which javascript execution leads to exception being thrown.
235 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false>
236 ThrowOnJavascriptExecution;
237
238 // Scope to introduce an exception to ThrowOnJavascriptExecution.
239 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true>
240 NoThrowOnJavascriptExecution;
241
242 // Scope to document where we do not expect an allocation failure.
243 typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT, false>
244 DisallowAllocationFailure;
245
246 // Scope to introduce an exception to DisallowAllocationFailure.
247 typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT, true>
248 AllowAllocationFailure;
249
250 // Scope to document where we do not expect deoptimization.
251 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, false>
252 DisallowDeoptimization;
253
254 // Scope to introduce an exception to DisallowDeoptimization.
255 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, true>
256 AllowDeoptimization;
257
258 // Scope to document where we do not expect deoptimization.
259 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, false>
260 DisallowCompilation;
261
262 // Scope to introduce an exception to DisallowDeoptimization.
263 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, true>
264 AllowCompilation;
265 } } // namespace v8::internal 220 } } // namespace v8::internal
266 221
267 #endif // V8_ASSERT_SCOPE_H_ 222 #endif // V8_ASSERT_SCOPE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698