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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 | 71 |
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 enum AcquireAssertDataMode { CREATE_IF_ABSENT, NULL_IF_ABSENT }; | |
Sven Panne
2013/06/12 06:57:37
This is getting a little bit confusing... I think
| |
82 | |
81 PerThreadAssertScopeBase() { | 83 PerThreadAssertScopeBase() { |
82 data_ = AssertData(); | 84 data_ = AssertData(CREATE_IF_ABSENT); |
83 data_->increment_level(); | 85 data_->increment_level(); |
84 } | 86 } |
85 | 87 |
86 ~PerThreadAssertScopeBase() { | 88 ~PerThreadAssertScopeBase() { |
87 if (!data_->decrement_level()) return; | 89 if (!data_->decrement_level()) return; |
88 for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) { | 90 for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) { |
89 ASSERT(data_->get(static_cast<PerThreadAssertType>(i))); | 91 ASSERT(data_->get(static_cast<PerThreadAssertType>(i))); |
90 } | 92 } |
91 delete data_; | 93 delete data_; |
92 Thread::SetThreadLocal(thread_local_key, NULL); | 94 Thread::SetThreadLocal(thread_local_key, NULL); |
93 } | 95 } |
94 | 96 |
95 static PerThreadAssertData* AssertData() { | 97 static PerThreadAssertData* AssertData(AcquireAssertDataMode mode) { |
96 PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>( | 98 PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>( |
97 Thread::GetThreadLocal(thread_local_key)); | 99 Thread::GetThreadLocal(thread_local_key)); |
98 if (data == NULL) { | 100 if (data == NULL && mode == CREATE_IF_ABSENT) { |
99 data = new PerThreadAssertData(); | 101 data = new PerThreadAssertData(); |
100 Thread::SetThreadLocal(thread_local_key, data); | 102 Thread::SetThreadLocal(thread_local_key, data); |
101 } | 103 } |
102 return data; | 104 return data; |
103 } | 105 } |
104 | 106 |
105 static Thread::LocalStorageKey thread_local_key; | 107 static Thread::LocalStorageKey thread_local_key; |
106 PerThreadAssertData* data_; | 108 PerThreadAssertData* data_; |
107 friend class Isolate; | 109 friend class Isolate; |
108 #endif // DEBUG | 110 #endif // DEBUG |
109 }; | 111 }; |
110 | 112 |
111 | 113 |
112 | 114 |
113 template <PerThreadAssertType type, bool allow> | 115 template <PerThreadAssertType type, bool allow> |
114 class PerThreadAssertScope : public PerThreadAssertScopeBase { | 116 class PerThreadAssertScope : public PerThreadAssertScopeBase { |
115 public: | 117 public: |
116 #ifndef DEBUG | 118 #ifndef DEBUG |
117 PerThreadAssertScope() { } | 119 PerThreadAssertScope() { } |
118 static void SetIsAllowed(bool is_allowed) { } | 120 static void SetIsAllowed(bool is_allowed) { } |
119 #else | 121 #else |
120 PerThreadAssertScope() { | 122 PerThreadAssertScope() { |
121 old_state_ = data_->get(type); | 123 old_state_ = data_->get(type); |
122 data_->set(type, allow); | 124 data_->set(type, allow); |
123 } | 125 } |
124 | 126 |
125 ~PerThreadAssertScope() { data_->set(type, old_state_); } | 127 ~PerThreadAssertScope() { data_->set(type, old_state_); } |
126 | 128 |
127 static bool IsAllowed() { return AssertData()->get(type); } | 129 static bool IsAllowed() { |
130 PerThreadAssertData* data = AssertData(NULL_IF_ABSENT); | |
131 return data == NULL || data->get(type); | |
132 } | |
128 | 133 |
129 private: | 134 private: |
130 bool old_state_; | 135 bool old_state_; |
131 #endif | 136 #endif |
132 }; | 137 }; |
133 | 138 |
134 // Scope to document where we do not expect handles to be created. | 139 // Scope to document where we do not expect handles to be created. |
135 typedef PerThreadAssertScope<HANDLE_ALLOCATION_ASSERT, false> | 140 typedef PerThreadAssertScope<HANDLE_ALLOCATION_ASSERT, false> |
136 DisallowHandleAllocation; | 141 DisallowHandleAllocation; |
137 | 142 |
(...skipping 21 matching lines...) Expand all Loading... | |
159 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false> | 164 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false> |
160 DisallowDeferredHandleDereference; | 165 DisallowDeferredHandleDereference; |
161 | 166 |
162 // Scope to introduce an exception to DisallowDeferredHandleDereference. | 167 // Scope to introduce an exception to DisallowDeferredHandleDereference. |
163 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true> | 168 typedef PerThreadAssertScope<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true> |
164 AllowDeferredHandleDereference; | 169 AllowDeferredHandleDereference; |
165 | 170 |
166 } } // namespace v8::internal | 171 } } // namespace v8::internal |
167 | 172 |
168 #endif // V8_ASSERT_SCOPE_H_ | 173 #endif // V8_ASSERT_SCOPE_H_ |
OLD | NEW |