Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / src / assert-scope.h
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.
4
5 #ifndef V8_ASSERT_SCOPE_H_
6 #define V8_ASSERT_SCOPE_H_
7
8 #include <stdint.h>
9 #include "src/base/macros.h"
10
11 namespace v8 {
12 namespace internal {
13
14 // Forward declarations.
15 class Isolate;
16 class PerThreadAssertData;
17
18
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
26 };
27
28
29 enum PerIsolateAssertType {
30   JAVASCRIPT_EXECUTION_ASSERT,
31   JAVASCRIPT_EXECUTION_THROWS,
32   ALLOCATION_FAILURE_ASSERT,
33   DEOPTIMIZATION_ASSERT,
34   COMPILATION_ASSERT
35 };
36
37
38 template <PerThreadAssertType kType, bool kAllow>
39 class PerThreadAssertScope {
40  public:
41   PerThreadAssertScope();
42   ~PerThreadAssertScope();
43
44   static bool IsAllowed();
45
46  private:
47   PerThreadAssertData* data_;
48   bool old_state_;
49
50   DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope);
51 };
52
53
54 template <PerIsolateAssertType type, bool allow>
55 class PerIsolateAssertScope {
56  public:
57   explicit PerIsolateAssertScope(Isolate* isolate);
58   ~PerIsolateAssertScope();
59
60   static bool IsAllowed(Isolate* isolate);
61
62  private:
63   class DataBit;
64
65   Isolate* isolate_;
66   uint32_t old_data_;
67
68   DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope);
69 };
70
71
72 template <PerThreadAssertType type, bool allow>
73 #ifdef DEBUG
74 class PerThreadAssertScopeDebugOnly : public
75     PerThreadAssertScope<type, allow> {
76 #else
77 class PerThreadAssertScopeDebugOnly {
78  public:
79   PerThreadAssertScopeDebugOnly() { }
80 #endif
81 };
82
83
84 template <PerIsolateAssertType type, bool allow>
85 #ifdef DEBUG
86 class PerIsolateAssertScopeDebugOnly : public
87     PerIsolateAssertScope<type, allow> {
88  public:
89   explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate)
90       : PerIsolateAssertScope<type, allow>(isolate) { }
91 #else
92 class PerIsolateAssertScopeDebugOnly {
93  public:
94   explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { }
95 #endif
96 };
97
98 // Per-thread assert scopes.
99
100 // Scope to document where we do not expect handles to be created.
101 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, false>
102     DisallowHandleAllocation;
103
104 // Scope to introduce an exception to DisallowHandleAllocation.
105 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, true>
106     AllowHandleAllocation;
107
108 // Scope to document where we do not expect any allocation and GC.
109 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, false>
110     DisallowHeapAllocation;
111
112 // Scope to introduce an exception to DisallowHeapAllocation.
113 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, true>
114     AllowHeapAllocation;
115
116 // Scope to document where we do not expect any handle dereferences.
117 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, false>
118     DisallowHandleDereference;
119
120 // Scope to introduce an exception to DisallowHandleDereference.
121 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, true>
122     AllowHandleDereference;
123
124 // Scope to document where we do not expect deferred handles to be dereferenced.
125 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false>
126     DisallowDeferredHandleDereference;
127
128 // Scope to introduce an exception to DisallowDeferredHandleDereference.
129 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true>
130     AllowDeferredHandleDereference;
131
132 // Scope to document where we do not expect deferred handles to be dereferenced.
133 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, false>
134     DisallowCodeDependencyChange;
135
136 // Scope to introduce an exception to DisallowDeferredHandleDereference.
137 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, true>
138     AllowCodeDependencyChange;
139
140
141 // Per-isolate assert scopes.
142
143 // Scope to document where we do not expect javascript execution.
144 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, false>
145     DisallowJavascriptExecution;
146
147 // Scope to introduce an exception to DisallowJavascriptExecution.
148 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true>
149     AllowJavascriptExecution;
150
151 // Scope in which javascript execution leads to exception being thrown.
152 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false>
153     ThrowOnJavascriptExecution;
154
155 // Scope to introduce an exception to ThrowOnJavascriptExecution.
156 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true>
157     NoThrowOnJavascriptExecution;
158
159 // Scope to document where we do not expect an allocation failure.
160 typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT, false>
161     DisallowAllocationFailure;
162
163 // Scope to introduce an exception to DisallowAllocationFailure.
164 typedef PerIsolateAssertScopeDebugOnly<ALLOCATION_FAILURE_ASSERT, true>
165     AllowAllocationFailure;
166
167 // Scope to document where we do not expect deoptimization.
168 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, false>
169     DisallowDeoptimization;
170
171 // Scope to introduce an exception to DisallowDeoptimization.
172 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, true>
173     AllowDeoptimization;
174
175 // Scope to document where we do not expect deoptimization.
176 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, false>
177     DisallowCompilation;
178
179 // Scope to introduce an exception to DisallowDeoptimization.
180 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, true>
181     AllowCompilation;
182 } }  // namespace v8::internal
183
184 #endif  // V8_ASSERT_SCOPE_H_