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