Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/Source/platform/heap/Handle.h

Issue 1477023003: Refactor the Heap into ThreadHeap to prepare for per thread heaps Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 NO_LAZY_SWEEP_SANITIZE_ADDRESS 235 NO_LAZY_SWEEP_SANITIZE_ADDRESS
236 void initialize() 236 void initialize()
237 { 237 {
238 ASSERT(!m_persistentNode); 238 ASSERT(!m_persistentNode);
239 if (!m_raw) 239 if (!m_raw)
240 return; 240 return;
241 241
242 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase<T, weak nessConfiguration, crossThreadnessConfiguration>, &PersistentBase<T, weaknessCon figuration, crossThreadnessConfiguration>::trace>::trampoline; 242 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase<T, weak nessConfiguration, crossThreadnessConfiguration>, &PersistentBase<T, weaknessCon figuration, crossThreadnessConfiguration>::trace>::trampoline;
243 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { 243 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) {
244 m_persistentNode = Heap::crossThreadPersistentRegion().allocatePersi stentNode(this, traceCallback); 244 m_persistentNode = ProcessHeap::crossThreadPersistentRegion().alloca tePersistentNode(this, traceCallback);
245 } else { 245 } else {
246 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); 246 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate();
247 ASSERT(state->checkThread()); 247 ASSERT(state->checkThread());
248 m_persistentNode = state->getPersistentRegion()->allocatePersistentN ode(this, traceCallback); 248 m_persistentNode = state->getPersistentRegion()->allocatePersistentN ode(this, traceCallback);
249 #if ENABLE(ASSERT) 249 #if ENABLE(ASSERT)
250 m_state = state; 250 m_state = state;
251 #endif 251 #endif
252 } 252 }
253 } 253 }
254 254
255 void uninitialize() 255 void uninitialize()
256 { 256 {
257 if (!m_persistentNode) 257 if (!m_persistentNode)
258 return; 258 return;
259 259
260 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { 260 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) {
261 Heap::crossThreadPersistentRegion().freePersistentNode(m_persistentN ode); 261 ProcessHeap::crossThreadPersistentRegion().freePersistentNode(m_pers istentNode);
262 } else { 262 } else {
263 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); 263 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate();
264 ASSERT(state->checkThread()); 264 ASSERT(state->checkThread());
265 // Persistent handle must be created and destructed in the same thre ad. 265 // Persistent handle must be created and destructed in the same thre ad.
266 ASSERT(m_state == state); 266 ASSERT(m_state == state);
267 state->getPersistentRegion()->freePersistentNode(m_persistentNode); 267 state->getPersistentRegion()->freePersistentNode(m_persistentNode);
268 } 268 }
269 m_persistentNode = nullptr; 269 m_persistentNode = nullptr;
270 } 270 }
271 271
272 void checkPointer() 272 void checkPointer()
273 { 273 {
274 #if ENABLE(ASSERT) && defined(ADDRESS_SANITIZER) 274 #if ENABLE(ASSERT) && defined(ADDRESS_SANITIZER)
275 if (!m_raw) 275 if (!m_raw)
276 return; 276 return;
277 277
278 // Heap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable 278 // ThreadHeap::isHeapObjectAlive(m_raw) checks that m_raw is a
279 // object. In other words, it checks that the pointer is either of: 279 // traceable object. In other words, it checks that the pointer is
280 // either of:
280 // 281 //
281 // (a) a pointer to the head of an on-heap object. 282 // (a) a pointer to the head of an on-heap object.
282 // (b) a pointer to the head of an on-heap mixin object. 283 // (b) a pointer to the head of an on-heap mixin object.
283 // 284 //
284 // Otherwise, Heap::isHeapObjectAlive will crash when it calls 285 // Otherwise, ThreadHeap::isHeapObjectAlive will crash when it calls
285 // header->checkHeader(). 286 // header->checkHeader().
286 Heap::isHeapObjectAlive(m_raw); 287 ThreadHeap::isHeapObjectAlive(m_raw);
287 #endif 288 #endif
288 } 289 }
289 290
290 // m_raw is accessed most, so put it at the first field. 291 // m_raw is accessed most, so put it at the first field.
291 T* m_raw; 292 T* m_raw;
292 PersistentNode* m_persistentNode = nullptr; 293 PersistentNode* m_persistentNode = nullptr;
293 #if ENABLE(ASSERT) 294 #if ENABLE(ASSERT)
294 ThreadState* m_state = nullptr; 295 ThreadState* m_state = nullptr;
295 #endif 296 #endif
296 }; 297 };
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 // as a valid pointer. 839 // as a valid pointer.
839 if (reinterpret_cast<intptr_t>(m_raw) % allocationGranularity) 840 if (reinterpret_cast<intptr_t>(m_raw) % allocationGranularity)
840 return; 841 return;
841 842
842 // TODO(haraken): What we really want to check here is that the pointer 843 // TODO(haraken): What we really want to check here is that the pointer
843 // is a traceable object. In other words, the pointer is either of: 844 // is a traceable object. In other words, the pointer is either of:
844 // 845 //
845 // (a) a pointer to the head of an on-heap object. 846 // (a) a pointer to the head of an on-heap object.
846 // (b) a pointer to the head of an on-heap mixin object. 847 // (b) a pointer to the head of an on-heap mixin object.
847 // 848 //
848 // We can check it by calling Heap::isHeapObjectAlive(m_raw), 849 // We can check it by calling ThreadHeap::isHeapObjectAlive(m_raw),
849 // but we cannot call it here because it requires to include T.h. 850 // but we cannot call it here because it requires to include T.h.
850 // So we currently only try to implement the check for (a), but do 851 // So we currently only try to implement the check for (a), but do
851 // not insist that T's definition is in scope. 852 // not insist that T's definition is in scope.
852 if (IsFullyDefined<T>::value && !IsGarbageCollectedMixin<T>::value) 853 if (IsFullyDefined<T>::value && !IsGarbageCollectedMixin<T>::value)
853 ASSERT(HeapObjectHeader::fromPayload(m_raw)->checkHeader()); 854 ASSERT(HeapObjectHeader::fromPayload(m_raw)->checkHeader());
854 #endif 855 #endif
855 } 856 }
856 857
857 T* m_raw; 858 T* m_raw;
858 859
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 // into it. 1493 // into it.
1493 // 1494 //
1494 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty pe like 1495 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty pe like
1495 // CrossThreadWeakPersistent<>. 1496 // CrossThreadWeakPersistent<>.
1496 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR eference<T>::create(value.get())); } 1497 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR eference<T>::create(value.get())); }
1497 }; 1498 };
1498 1499
1499 } // namespace WTF 1500 } // namespace WTF
1500 1501
1501 #endif 1502 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/GarbageCollected.h ('k') | third_party/WebKit/Source/platform/heap/Heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698