3030
3131#include " allocation.h"
3232#include " platform.h"
33+ #include " utils.h"
3334
3435namespace v8 {
3536namespace internal {
@@ -46,7 +47,12 @@ enum PerThreadAssertType {
4647};
4748
4849
49- #ifdef DEBUG
50+ enum PerIsolateAssertType {
51+ JAVASCRIPT_EXECUTION_ASSERT ,
52+ ALLOCATION_FAILURE_ASSERT
53+ };
54+
55+
5056class PerThreadAssertData {
5157 public:
5258 PerThreadAssertData () : nesting_level_(0 ) {
@@ -72,12 +78,9 @@ class PerThreadAssertData {
7278
7379 DISALLOW_COPY_AND_ASSIGN (PerThreadAssertData);
7480};
75- #endif // DEBUG
7681
7782
7883class PerThreadAssertScopeBase {
79- #ifdef DEBUG
80-
8184 protected:
8285 PerThreadAssertScopeBase () {
8386 data_ = GetAssertData ();
@@ -110,18 +113,12 @@ class PerThreadAssertScopeBase {
110113 static void SetThreadLocalData (PerThreadAssertData* data) {
111114 Thread::SetThreadLocal (thread_local_key, data);
112115 }
113- #endif // DEBUG
114116};
115117
116118
117-
118119template <PerThreadAssertType type, bool allow>
119120class PerThreadAssertScope : public PerThreadAssertScopeBase {
120121 public:
121- #ifndef DEBUG
122- PerThreadAssertScope () { }
123- static void SetIsAllowed (bool is_allowed) { }
124- #else
125122 PerThreadAssertScope () {
126123 old_state_ = data_->get (type);
127124 data_->set (type, allow);
@@ -136,49 +133,132 @@ class PerThreadAssertScope : public PerThreadAssertScopeBase {
136133
137134 private:
138135 bool old_state_;
136+
137+ DISALLOW_COPY_AND_ASSIGN (PerThreadAssertScope);
138+ };
139+
140+
141+ class PerIsolateAssertBase {
142+ protected:
143+ static uint32_t GetData (Isolate* isolate);
144+ static void SetData (Isolate* isolate, uint32_t data);
145+ };
146+
147+
148+ template <PerIsolateAssertType type, bool allow>
149+ class PerIsolateAssertScope : public PerIsolateAssertBase {
150+ public:
151+ explicit PerIsolateAssertScope (Isolate* isolate) : isolate_(isolate) {
152+ STATIC_ASSERT (type < 32 );
153+ old_data_ = GetData (isolate_);
154+ SetData (isolate_, DataBit::update (old_data_, allow));
155+ }
156+
157+ ~PerIsolateAssertScope () {
158+ SetData (isolate_, old_data_);
159+ }
160+
161+ static bool IsAllowed (Isolate* isolate) {
162+ return DataBit::decode (GetData (isolate));
163+ }
164+
165+ private:
166+ typedef BitField<bool , type, 1 > DataBit;
167+
168+ uint32_t old_data_;
169+ Isolate* isolate_;
170+
171+ DISALLOW_COPY_AND_ASSIGN (PerIsolateAssertScope);
172+ };
173+
174+
175+ template <PerThreadAssertType type, bool allow>
176+ #ifdef DEBUG
177+ class PerThreadAssertScopeDebugOnly : public
178+ PerThreadAssertScope<type, allow> {
179+ #else
180+ class PerThreadAssertScopeDebugOnly {
181+ public:
182+ PerThreadAssertScopeDebugOnly () { }
183+ #endif
184+ };
185+
186+
187+ template <PerIsolateAssertType type, bool allow>
188+ #ifdef DEBUG
189+ class PerIsolateAssertScopeDebugOnly : public
190+ PerIsolateAssertScope<type, allow> {
191+ public:
192+ explicit PerIsolateAssertScopeDebugOnly (Isolate* isolate)
193+ : PerIsolateAssertScope<type, allow>(isolate) { }
194+ #else
195+ class PerIsolateAssertScopeDebugOnly {
196+ public:
197+ explicit PerIsolateAssertScopeDebugOnly (Isolate* isolate) { }
139198#endif
140199};
141200
201+ // Per-thread assert scopes.
202+
142203// Scope to document where we do not expect handles to be created.
143- typedef PerThreadAssertScope <HANDLE_ALLOCATION_ASSERT , false >
204+ typedef PerThreadAssertScopeDebugOnly <HANDLE_ALLOCATION_ASSERT , false >
144205 DisallowHandleAllocation;
145206
146207// Scope to introduce an exception to DisallowHandleAllocation.
147- typedef PerThreadAssertScope <HANDLE_ALLOCATION_ASSERT , true >
208+ typedef PerThreadAssertScopeDebugOnly <HANDLE_ALLOCATION_ASSERT , true >
148209 AllowHandleAllocation;
149210
150211// Scope to document where we do not expect any allocation and GC.
151- typedef PerThreadAssertScope <HEAP_ALLOCATION_ASSERT , false >
212+ typedef PerThreadAssertScopeDebugOnly <HEAP_ALLOCATION_ASSERT , false >
152213 DisallowHeapAllocation;
153214
154215// Scope to introduce an exception to DisallowHeapAllocation.
155- typedef PerThreadAssertScope <HEAP_ALLOCATION_ASSERT , true >
216+ typedef PerThreadAssertScopeDebugOnly <HEAP_ALLOCATION_ASSERT , true >
156217 AllowHeapAllocation;
157218
158219// Scope to document where we do not expect any handle dereferences.
159- typedef PerThreadAssertScope <HANDLE_DEREFERENCE_ASSERT , false >
220+ typedef PerThreadAssertScopeDebugOnly <HANDLE_DEREFERENCE_ASSERT , false >
160221 DisallowHandleDereference;
161222
162223// Scope to introduce an exception to DisallowHandleDereference.
163- typedef PerThreadAssertScope <HANDLE_DEREFERENCE_ASSERT , true >
224+ typedef PerThreadAssertScopeDebugOnly <HANDLE_DEREFERENCE_ASSERT , true >
164225 AllowHandleDereference;
165226
166227// Scope to document where we do not expect deferred handles to be dereferenced.
167- typedef PerThreadAssertScope <DEFERRED_HANDLE_DEREFERENCE_ASSERT , false >
228+ typedef PerThreadAssertScopeDebugOnly <DEFERRED_HANDLE_DEREFERENCE_ASSERT , false >
168229 DisallowDeferredHandleDereference;
169230
170231// Scope to introduce an exception to DisallowDeferredHandleDereference.
171- typedef PerThreadAssertScope <DEFERRED_HANDLE_DEREFERENCE_ASSERT , true >
232+ typedef PerThreadAssertScopeDebugOnly <DEFERRED_HANDLE_DEREFERENCE_ASSERT , true >
172233 AllowDeferredHandleDereference;
173234
174235// Scope to document where we do not expect deferred handles to be dereferenced.
175- typedef PerThreadAssertScope <CODE_DEPENDENCY_CHANGE_ASSERT , false >
236+ typedef PerThreadAssertScopeDebugOnly <CODE_DEPENDENCY_CHANGE_ASSERT , false >
176237 DisallowCodeDependencyChange;
177238
178239// Scope to introduce an exception to DisallowDeferredHandleDereference.
179- typedef PerThreadAssertScope <CODE_DEPENDENCY_CHANGE_ASSERT , true >
240+ typedef PerThreadAssertScopeDebugOnly <CODE_DEPENDENCY_CHANGE_ASSERT , true >
180241 AllowCodeDependencyChange;
181242
243+
244+ // Per-isolate assert scopes.
245+
246+ // Scope to document where we do not expect javascript execution.
247+ typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT , false >
248+ DisallowJavascriptExecution;
249+
250+ // Scope to introduce an exception to DisallowJavascriptExecution.
251+ typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT , true >
252+ AllowJavascriptExecution;
253+
254+ // Scope to document where we do not expect an allocation failure.
255+ typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT , false >
256+ DisallowAllocationFailure;
257+
258+ // Scope to introduce an exception to DisallowAllocationFailure.
259+ typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT , true >
260+ AllowAllocationFailure;
261+
182262} } // namespace v8::internal
183263
184264#endif // V8_ASSERT_SCOPE_H_
0 commit comments