1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file. 4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifndef V8_ASSERT_SCOPE_H_ 6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V8_ASSERT_SCOPE_H_ 7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 8958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier#include <stdint.h> 9958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier#include "src/base/macros.h" 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace v8 { 12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace internal { 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 14958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Forward declarations. 15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass Isolate; 16958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierclass PerThreadAssertData; 17958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochenum PerThreadAssertType { 20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch HEAP_ALLOCATION_ASSERT, 21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch HANDLE_ALLOCATION_ASSERT, 22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch HANDLE_DEREFERENCE_ASSERT, 23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DEFERRED_HANDLE_DEREFERENCE_ASSERT, 24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch CODE_DEPENDENCY_CHANGE_ASSERT, 25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch LAST_PER_THREAD_ASSERT_TYPE 26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochenum PerIsolateAssertType { 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch JAVASCRIPT_EXECUTION_ASSERT, 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch JAVASCRIPT_EXECUTION_THROWS, 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DEOPTIMIZATION_ASSERT, 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch COMPILATION_ASSERT 34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 37958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertemplate <PerThreadAssertType kType, bool kAllow> 38958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierclass PerThreadAssertScope { 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 40958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier PerThreadAssertScope(); 41958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier ~PerThreadAssertScope(); 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 43958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier static bool IsAllowed(); 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch private: 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch PerThreadAssertData* data_; 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool old_state_; 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope); 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtemplate <PerIsolateAssertType type, bool allow> 54958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierclass PerIsolateAssertScope { 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 56958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier explicit PerIsolateAssertScope(Isolate* isolate); 57958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier ~PerIsolateAssertScope(); 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 59958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier static bool IsAllowed(Isolate* isolate); 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch private: 62958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier class DataBit; 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Isolate* isolate_; 65958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier uint32_t old_data_; 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope); 68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtemplate <PerThreadAssertType type, bool allow> 72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifdef DEBUG 73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass PerThreadAssertScopeDebugOnly : public 74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch PerThreadAssertScope<type, allow> { 75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#else 76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass PerThreadAssertScopeDebugOnly { 77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch PerThreadAssertScopeDebugOnly() { } 79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif 80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtemplate <PerIsolateAssertType type, bool allow> 84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifdef DEBUG 85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass PerIsolateAssertScopeDebugOnly : public 86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch PerIsolateAssertScope<type, allow> { 87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) 89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch : PerIsolateAssertScope<type, allow>(isolate) { } 90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#else 91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass PerIsolateAssertScopeDebugOnly { 92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { } 94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif 95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Per-thread assert scopes. 98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect handles to be created. 100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, false> 101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowHandleAllocation; 102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowHandleAllocation. 104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, true> 105b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowHandleAllocation; 106b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 107b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect any allocation and GC. 108b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, false> 109b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowHeapAllocation; 110b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 111b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowHeapAllocation. 112b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, true> 113b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowHeapAllocation; 114b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 115b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect any handle dereferences. 116b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, false> 117b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowHandleDereference; 118b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 119b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowHandleDereference. 120b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, true> 121b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowHandleDereference; 122b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 123b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect deferred handles to be dereferenced. 124b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false> 125b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowDeferredHandleDereference; 126b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 127b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowDeferredHandleDereference. 128b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true> 129b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowDeferredHandleDereference; 130b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 131b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect deferred handles to be dereferenced. 132b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, false> 133b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowCodeDependencyChange; 134b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 135b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowDeferredHandleDereference. 136b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, true> 137b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowCodeDependencyChange; 138b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 139b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 140b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Per-isolate assert scopes. 141b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 142b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect javascript execution. 143b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, false> 144b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowJavascriptExecution; 145b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 146b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowJavascriptExecution. 147b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true> 148b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowJavascriptExecution; 149b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 150b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope in which javascript execution leads to exception being thrown. 151b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false> 152b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ThrowOnJavascriptExecution; 153b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 154b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to ThrowOnJavascriptExecution. 155b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true> 156b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch NoThrowOnJavascriptExecution; 157b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 158b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect deoptimization. 159b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, false> 160b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowDeoptimization; 161b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 162b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowDeoptimization. 163b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, true> 164b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowDeoptimization; 165b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 166b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to document where we do not expect deoptimization. 167b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, false> 168b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DisallowCompilation; 169b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 170b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Scope to introduce an exception to DisallowDeoptimization. 171b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtypedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, true> 172b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AllowCompilation; 173014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace internal 174014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace v8 175b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 176b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif // V8_ASSERT_SCOPE_H_ 177