// Copyright 2013 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_ASSERT_SCOPE_H_ #define V8_ASSERT_SCOPE_H_ #include #include "src/base/macros.h" #include "src/globals.h" namespace v8 { namespace internal { // Forward declarations. class Isolate; class PerThreadAssertData; enum PerThreadAssertType { HEAP_ALLOCATION_ASSERT, HANDLE_ALLOCATION_ASSERT, HANDLE_DEREFERENCE_ASSERT, DEFERRED_HANDLE_DEREFERENCE_ASSERT, CODE_DEPENDENCY_CHANGE_ASSERT, LAST_PER_THREAD_ASSERT_TYPE }; enum PerIsolateAssertType { JAVASCRIPT_EXECUTION_ASSERT, JAVASCRIPT_EXECUTION_THROWS, DEOPTIMIZATION_ASSERT, COMPILATION_ASSERT }; template class PerThreadAssertScope { public: V8_EXPORT_PRIVATE PerThreadAssertScope(); V8_EXPORT_PRIVATE ~PerThreadAssertScope(); V8_EXPORT_PRIVATE static bool IsAllowed(); void Release(); private: PerThreadAssertData* data_; bool old_state_; DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope); }; template class PerIsolateAssertScope { public: explicit PerIsolateAssertScope(Isolate* isolate); ~PerIsolateAssertScope(); static bool IsAllowed(Isolate* isolate); private: class DataBit; Isolate* isolate_; uint32_t old_data_; DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope); }; template #ifdef DEBUG class PerThreadAssertScopeDebugOnly : public PerThreadAssertScope { #else class PerThreadAssertScopeDebugOnly { public: PerThreadAssertScopeDebugOnly() { } void Release() {} #endif }; template #ifdef DEBUG class PerIsolateAssertScopeDebugOnly : public PerIsolateAssertScope { public: explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) : PerIsolateAssertScope(isolate) { } #else class PerIsolateAssertScopeDebugOnly { public: explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { } #endif }; // Per-thread assert scopes. // Scope to document where we do not expect handles to be created. typedef PerThreadAssertScopeDebugOnly DisallowHandleAllocation; // Scope to introduce an exception to DisallowHandleAllocation. typedef PerThreadAssertScopeDebugOnly AllowHandleAllocation; // Scope to document where we do not expect any allocation and GC. typedef PerThreadAssertScopeDebugOnly DisallowHeapAllocation; // Scope to introduce an exception to DisallowHeapAllocation. typedef PerThreadAssertScopeDebugOnly AllowHeapAllocation; // Scope to document where we do not expect any handle dereferences. typedef PerThreadAssertScopeDebugOnly DisallowHandleDereference; // Scope to introduce an exception to DisallowHandleDereference. typedef PerThreadAssertScopeDebugOnly AllowHandleDereference; // Scope to document where we do not expect deferred handles to be dereferenced. typedef PerThreadAssertScopeDebugOnly DisallowDeferredHandleDereference; // Scope to introduce an exception to DisallowDeferredHandleDereference. typedef PerThreadAssertScopeDebugOnly AllowDeferredHandleDereference; // Scope to document where we do not expect deferred handles to be dereferenced. typedef PerThreadAssertScopeDebugOnly DisallowCodeDependencyChange; // Scope to introduce an exception to DisallowDeferredHandleDereference. typedef PerThreadAssertScopeDebugOnly AllowCodeDependencyChange; // Per-isolate assert scopes. // Scope to document where we do not expect javascript execution. typedef PerIsolateAssertScope DisallowJavascriptExecution; // Scope to introduce an exception to DisallowJavascriptExecution. typedef PerIsolateAssertScope AllowJavascriptExecution; // Scope in which javascript execution leads to exception being thrown. typedef PerIsolateAssertScope ThrowOnJavascriptExecution; // Scope to introduce an exception to ThrowOnJavascriptExecution. typedef PerIsolateAssertScope NoThrowOnJavascriptExecution; // Scope to document where we do not expect deoptimization. typedef PerIsolateAssertScopeDebugOnly DisallowDeoptimization; // Scope to introduce an exception to DisallowDeoptimization. typedef PerIsolateAssertScopeDebugOnly AllowDeoptimization; // Scope to document where we do not expect deoptimization. typedef PerIsolateAssertScopeDebugOnly DisallowCompilation; // Scope to introduce an exception to DisallowDeoptimization. typedef PerIsolateAssertScopeDebugOnly AllowCompilation; } // namespace internal } // namespace v8 #endif // V8_ASSERT_SCOPE_H_