OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 DISALLOW_COPY_AND_ASSIGN(PerThreadAssertData); | 72 DISALLOW_COPY_AND_ASSIGN(PerThreadAssertData); |
73 }; | 73 }; |
74 #endif // DEBUG | 74 #endif // DEBUG |
75 | 75 |
76 | 76 |
77 class PerThreadAssertScopeBase { | 77 class PerThreadAssertScopeBase { |
78 #ifdef DEBUG | 78 #ifdef DEBUG |
79 | 79 |
80 protected: | 80 protected: |
81 PerThreadAssertScopeBase() { | 81 PerThreadAssertScopeBase() { |
82 data_ = AssertData(); | 82 data_ = GetAssertData(); |
83 if (data_ == NULL) { | |
84 data_ = new PerThreadAssertData(); | |
85 SetThreadLocalData(data_); | |
86 } | |
83 data_->increment_level(); | 87 data_->increment_level(); |
84 } | 88 } |
85 | 89 |
86 ~PerThreadAssertScopeBase() { | 90 ~PerThreadAssertScopeBase() { |
87 if (!data_->decrement_level()) return; | 91 if (!data_->decrement_level()) return; |
88 for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) { | 92 for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) { |
89 ASSERT(data_->get(static_cast<PerThreadAssertType>(i))); | 93 ASSERT(data_->get(static_cast<PerThreadAssertType>(i))); |
90 } | 94 } |
91 delete data_; | 95 delete data_; |
92 Thread::SetThreadLocal(thread_local_key, NULL); | 96 SetThreadLocalData(NULL); |
93 } | 97 } |
94 | 98 |
95 static PerThreadAssertData* AssertData() { | 99 static PerThreadAssertData* GetAssertData() { |
96 PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>( | 100 return reinterpret_cast<PerThreadAssertData*>( |
97 Thread::GetThreadLocal(thread_local_key)); | 101 Thread::GetThreadLocal(thread_local_key)); |
98 if (data == NULL) { | |
99 data = new PerThreadAssertData(); | |
100 Thread::SetThreadLocal(thread_local_key, data); | |
101 } | |
102 return data; | |
103 } | 102 } |
104 | 103 |
105 static Thread::LocalStorageKey thread_local_key; | 104 static Thread::LocalStorageKey thread_local_key; |
106 PerThreadAssertData* data_; | 105 PerThreadAssertData* data_; |
107 friend class Isolate; | 106 friend class Isolate; |
107 | |
108 private: | |
109 void SetThreadLocalData(PerThreadAssertData* data) { | |
Sven Panne
2013/06/13 06:11:38
nit: add "static"
| |
110 Thread::SetThreadLocal(thread_local_key, data); | |
111 } | |
108 #endif // DEBUG | 112 #endif // DEBUG |
109 }; | 113 }; |
110 | 114 |
111 | 115 |
112 | 116 |
113 template <PerThreadAssertType type, bool allow> | 117 template <PerThreadAssertType type, bool allow> |
114 class PerThreadAssertScope : public PerThreadAssertScopeBase { | 118 class PerThreadAssertScope : public PerThreadAssertScopeBase { |
115 public: | 119 public: |
116 #ifndef DEBUG | 120 #ifndef DEBUG |
117 PerThreadAssertScope() { } | 121 PerThreadAssertScope() { } |
118 static void SetIsAllowed(bool is_allowed) { } | 122 static void SetIsAllowed(bool is_allowed) { } |
119 #else | 123 #else |
120 PerThreadAssertScope() { | 124 PerThreadAssertScope() { |
121 old_state_ = data_->get(type); | 125 old_state_ = data_->get(type); |
122 data_->set(type, allow); | 126 data_->set(type, allow); |
123 } | 127 } |
124 | 128 |
125 ~PerThreadAssertScope() { data_->set(type, old_state_); } | 129 ~PerThreadAssertScope() { data_->set(type, old_state_); } |
126 | 130 |
127 static bool IsAllowed() { return AssertData()->get(type); } | 131 static bool IsAllowed() { |
132 PerThreadAssertData* data = GetAssertData(); | |
133 return data == NULL || data->get(type); | |
134 } | |
128 | 135 |
129 private: | 136 private: |
130 bool old_state_; | 137 bool old_state_; |
131 #endif | 138 #endif |
132 }; | 139 }; |
133 | 140 |
134 // Scope to document where we do not expect handles to be created. | 141 // Scope to document where we do not expect handles to be created. |
135 typedef PerThreadAssertScope<HANDLE_ALLOCATION_ASSERT, false> | 142 typedef PerThreadAssertScope<HANDLE_ALLOCATION_ASSERT, false> |
136 DisallowHandleAllocation; | 143 DisallowHandleAllocation; |
137 | 144 |
(...skipping 21 matching lines...) Expand all Loading... | |
159 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false> | 166 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false> |
160 DisallowDeferredHandleDereference; | 167 DisallowDeferredHandleDereference; |
161 | 168 |
162 // Scope to introduce an exception to DisallowDeferredHandleDereference. | 169 // Scope to introduce an exception to DisallowDeferredHandleDereference. |
163 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true> | 170 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true> |
164 AllowDeferredHandleDereference; | 171 AllowDeferredHandleDereference; |
165 | 172 |
166 } } // namespace v8::internal | 173 } } // namespace v8::internal |
167 | 174 |
168 #endif // V8_ASSERT_SCOPE_H_ | 175 #endif // V8_ASSERT_SCOPE_H_ |
OLD | NEW |