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
3 // found in the LICENSE file.
5 #ifndef V8_ASSERT_SCOPE_H_
6 #define V8_ASSERT_SCOPE_H_
9 #include "src/base/macros.h"
14 // Forward declarations.
16 class PerThreadAssertData;
19 enum PerThreadAssertType {
20 HEAP_ALLOCATION_ASSERT,
21 HANDLE_ALLOCATION_ASSERT,
22 HANDLE_DEREFERENCE_ASSERT,
23 DEFERRED_HANDLE_DEREFERENCE_ASSERT,
24 CODE_DEPENDENCY_CHANGE_ASSERT,
25 LAST_PER_THREAD_ASSERT_TYPE
29 enum PerIsolateAssertType {
30 JAVASCRIPT_EXECUTION_ASSERT,
31 JAVASCRIPT_EXECUTION_THROWS,
32 ALLOCATION_FAILURE_ASSERT,
33 DEOPTIMIZATION_ASSERT,
38 template <PerThreadAssertType kType, bool kAllow>
39 class PerThreadAssertScope {
41 PerThreadAssertScope();
42 ~PerThreadAssertScope();
44 static bool IsAllowed();
47 PerThreadAssertData* data_;
50 DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope);
54 template <PerIsolateAssertType type, bool allow>
55 class PerIsolateAssertScope {
57 explicit PerIsolateAssertScope(Isolate* isolate);
58 ~PerIsolateAssertScope();
60 static bool IsAllowed(Isolate* isolate);
68 DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope);
72 template <PerThreadAssertType type, bool allow>
74 class PerThreadAssertScopeDebugOnly : public
75 PerThreadAssertScope<type, allow> {
77 class PerThreadAssertScopeDebugOnly {
79 PerThreadAssertScopeDebugOnly() { }
84 template <PerIsolateAssertType type, bool allow>
86 class PerIsolateAssertScopeDebugOnly : public
87 PerIsolateAssertScope<type, allow> {
89 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate)
90 : PerIsolateAssertScope<type, allow>(isolate) { }
92 class PerIsolateAssertScopeDebugOnly {
94 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { }
98 // Per-thread assert scopes.
100 // Scope to document where we do not expect handles to be created.
101 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, false>
102 DisallowHandleAllocation;
104 // Scope to introduce an exception to DisallowHandleAllocation.
105 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, true>
106 AllowHandleAllocation;
108 // Scope to document where we do not expect any allocation and GC.
109 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, false>
110 DisallowHeapAllocation;
112 // Scope to introduce an exception to DisallowHeapAllocation.
113 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, true>
116 // Scope to document where we do not expect any handle dereferences.
117 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, false>
118 DisallowHandleDereference;
120 // Scope to introduce an exception to DisallowHandleDereference.
121 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, true>
122 AllowHandleDereference;
124 // Scope to document where we do not expect deferred handles to be dereferenced.
125 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false>
126 DisallowDeferredHandleDereference;
128 // Scope to introduce an exception to DisallowDeferredHandleDereference.
129 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true>
130 AllowDeferredHandleDereference;
132 // Scope to document where we do not expect deferred handles to be dereferenced.
133 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, false>
134 DisallowCodeDependencyChange;
136 // Scope to introduce an exception to DisallowDeferredHandleDereference.
137 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, true>
138 AllowCodeDependencyChange;
141 // Per-isolate assert scopes.
143 // Scope to document where we do not expect javascript execution.
144 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, false>
145 DisallowJavascriptExecution;
147 // Scope to introduce an exception to DisallowJavascriptExecution.
148 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true>
149 AllowJavascriptExecution;
151 // Scope in which javascript execution leads to exception being thrown.
152 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false>
153 ThrowOnJavascriptExecution;
155 // Scope to introduce an exception to ThrowOnJavascriptExecution.
156 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true>
157 NoThrowOnJavascriptExecution;
159 // Scope to document where we do not expect an allocation failure.
160 typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT, false>
161 DisallowAllocationFailure;
163 // Scope to introduce an exception to DisallowAllocationFailure.
164 typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT, true>
165 AllowAllocationFailure;
167 // Scope to document where we do not expect deoptimization.
168 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, false>
169 DisallowDeoptimization;
171 // Scope to introduce an exception to DisallowDeoptimization.
172 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, true>
175 // Scope to document where we do not expect deoptimization.
176 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, false>
179 // Scope to introduce an exception to DisallowDeoptimization.
180 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, true>
182 } } // namespace v8::internal
184 #endif // V8_ASSERT_SCOPE_H_