v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
assert-scope.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_ASSERT_SCOPE_H_
29 #define V8_ASSERT_SCOPE_H_
30 
31 #include "allocation.h"
32 #include "platform.h"
33 #include "utils.h"
34 
35 namespace v8 {
36 namespace internal {
37 
38 class Isolate;
39 
47 };
48 
49 
54 };
55 
56 
58  public:
59  PerThreadAssertData() : nesting_level_(0) {
60  for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) {
61  assert_states_[i] = true;
62  }
63  }
64 
65  void set(PerThreadAssertType type, bool allow) {
66  assert_states_[type] = allow;
67  }
68 
69  bool get(PerThreadAssertType type) const {
70  return assert_states_[type];
71  }
72 
73  void increment_level() { ++nesting_level_; }
74  bool decrement_level() { return --nesting_level_ == 0; }
75 
76  private:
77  bool assert_states_[LAST_PER_THREAD_ASSERT_TYPE];
78  int nesting_level_;
79 
80  DISALLOW_COPY_AND_ASSIGN(PerThreadAssertData);
81 };
82 
83 
85  protected:
87  data_ = GetAssertData();
88  if (data_ == NULL) {
89  data_ = new PerThreadAssertData();
90  SetThreadLocalData(data_);
91  }
93  }
94 
96  if (!data_->decrement_level()) return;
97  for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) {
98  ASSERT(data_->get(static_cast<PerThreadAssertType>(i)));
99  }
100  delete data_;
101  SetThreadLocalData(NULL);
102  }
103 
105  return reinterpret_cast<PerThreadAssertData*>(
107  }
108 
111  friend class Isolate;
112 
113  private:
114  static void SetThreadLocalData(PerThreadAssertData* data) {
116  }
117 };
118 
119 
120 template <PerThreadAssertType type, bool allow>
122  public:
124  old_state_ = data_->get(type);
125  data_->set(type, allow);
126  }
127 
128  ~PerThreadAssertScope() { data_->set(type, old_state_); }
129 
130  static bool IsAllowed() {
132  return data == NULL || data->get(type);
133  }
134 
135  private:
136  bool old_state_;
137 
138  DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope);
139 };
140 
141 
143  protected:
144  static uint32_t GetData(Isolate* isolate);
145  static void SetData(Isolate* isolate, uint32_t data);
146 };
147 
148 
149 template <PerIsolateAssertType type, bool allow>
151  public:
152  explicit PerIsolateAssertScope(Isolate* isolate) : isolate_(isolate) {
153  STATIC_ASSERT(type < 32);
154  old_data_ = GetData(isolate_);
155  SetData(isolate_, DataBit::update(old_data_, allow));
156  }
157 
159  SetData(isolate_, old_data_);
160  }
161 
162  static bool IsAllowed(Isolate* isolate) {
163  return DataBit::decode(GetData(isolate));
164  }
165 
166  private:
167  typedef BitField<bool, type, 1> DataBit;
168 
169  uint32_t old_data_;
170  Isolate* isolate_;
171 
172  DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope);
173 };
174 
175 
176 template <PerThreadAssertType type, bool allow>
177 #ifdef DEBUG
178 class PerThreadAssertScopeDebugOnly : public
179  PerThreadAssertScope<type, allow> {
180 #else
182  public:
184 #endif
185 };
186 
187 
188 template <PerIsolateAssertType type, bool allow>
189 #ifdef DEBUG
190 class PerIsolateAssertScopeDebugOnly : public
191  PerIsolateAssertScope<type, allow> {
192  public:
193  explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate)
194  : PerIsolateAssertScope<type, allow>(isolate) { }
195 #else
197  public:
199 #endif
200 };
201 
202 // Per-thread assert scopes.
203 
204 // Scope to document where we do not expect handles to be created.
205 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, false>
207 
208 // Scope to introduce an exception to DisallowHandleAllocation.
211 
212 // Scope to document where we do not expect any allocation and GC.
215 
216 // Scope to introduce an exception to DisallowHeapAllocation.
219 
220 // Scope to document where we do not expect any handle dereferences.
223 
224 // Scope to introduce an exception to DisallowHandleDereference.
227 
228 // Scope to document where we do not expect deferred handles to be dereferenced.
231 
232 // Scope to introduce an exception to DisallowDeferredHandleDereference.
235 
236 // Scope to document where we do not expect deferred handles to be dereferenced.
239 
240 // Scope to introduce an exception to DisallowDeferredHandleDereference.
243 
244 
245 // Per-isolate assert scopes.
246 
247 // Scope to document where we do not expect javascript execution.
250 
251 // Scope to introduce an exception to DisallowJavascriptExecution.
254 
255 // Scope in which javascript execution leads to exception being thrown.
258 
259 // Scope to introduce an exception to ThrowOnJavascriptExecution.
262 
263 // Scope to document where we do not expect an allocation failure.
266 
267 // Scope to introduce an exception to DisallowAllocationFailure.
270 
271 } } // namespace v8::internal
272 
273 #endif // V8_ASSERT_SCOPE_H_
PerIsolateAssertScope(Isolate *isolate)
Definition: assert-scope.h:152
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
static void * GetThreadLocal(LocalStorageKey key)
PerThreadAssertScopeDebugOnly< DEFERRED_HANDLE_DEREFERENCE_ASSERT, false > DisallowDeferredHandleDereference
Definition: assert-scope.h:230
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_ASSERT, true > AllowJavascriptExecution
Definition: assert-scope.h:253
PerThreadAssertScopeDebugOnly< HANDLE_DEREFERENCE_ASSERT, false > DisallowHandleDereference
Definition: assert-scope.h:222
#define ASSERT(condition)
Definition: checks.h:329
static bool IsAllowed(Isolate *isolate)
Definition: assert-scope.h:162
PerThreadAssertScopeDebugOnly< DEFERRED_HANDLE_DEREFERENCE_ASSERT, true > AllowDeferredHandleDereference
Definition: assert-scope.h:234
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, true > AllowHeapAllocation
Definition: assert-scope.h:218
PerThreadAssertScopeDebugOnly< CODE_DEPENDENCY_CHANGE_ASSERT, false > DisallowCodeDependencyChange
Definition: assert-scope.h:238
static uint32_t GetData(Isolate *isolate)
Definition: assert-scope.cc:12
bool get(PerThreadAssertType type) const
Definition: assert-scope.h:69
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
PerIsolateAssertScopeDebugOnly< ALLOCATION_FAILURE_ASSERT, false > DisallowAllocationFailure
Definition: assert-scope.h:265
static uint32_t update(uint32_tprevious, T value)
Definition: utils.h:296
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_THROWS, true > NoThrowOnJavascriptExecution
Definition: assert-scope.h:261
PerThreadAssertScopeDebugOnly< HANDLE_ALLOCATION_ASSERT, false > DisallowHandleAllocation
Definition: assert-scope.h:206
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_THROWS, false > ThrowOnJavascriptExecution
Definition: assert-scope.h:257
static PerThreadAssertData * GetAssertData()
Definition: assert-scope.h:104
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_ASSERT, false > DisallowJavascriptExecution
Definition: assert-scope.h:249
PerThreadAssertScopeDebugOnly< HANDLE_ALLOCATION_ASSERT, true > AllowHandleAllocation
Definition: assert-scope.h:210
static void SetThreadLocal(LocalStorageKey key, void *value)
static void SetData(Isolate *isolate, uint32_t data)
Definition: assert-scope.cc:17
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:214
PerIsolateAssertScopeDebugOnly< ALLOCATION_FAILURE_ASSERT, true > AllowAllocationFailure
Definition: assert-scope.h:269
PerThreadAssertScopeDebugOnly< CODE_DEPENDENCY_CHANGE_ASSERT, true > AllowCodeDependencyChange
Definition: assert-scope.h:242
static Thread::LocalStorageKey thread_local_key
Definition: assert-scope.h:109
PerThreadAssertScopeDebugOnly< HANDLE_DEREFERENCE_ASSERT, true > AllowHandleDereference
Definition: assert-scope.h:226
void set(PerThreadAssertType type, bool allow)
Definition: assert-scope.h:65