OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 22 matching lines...) Expand all Loading... | |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/heap/AddressSanitizer.h" | 35 #include "platform/heap/AddressSanitizer.h" |
36 #include "platform/heap/ThreadState.h" | 36 #include "platform/heap/ThreadState.h" |
37 #include "platform/heap/Visitor.h" | 37 #include "platform/heap/Visitor.h" |
38 | 38 |
39 #include "wtf/Assertions.h" | 39 #include "wtf/Assertions.h" |
40 #include "wtf/LinkedHashSet.h" | 40 #include "wtf/LinkedHashSet.h" |
41 #include "wtf/OwnPtr.h" | 41 #include "wtf/OwnPtr.h" |
42 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.h" |
43 #include "wtf/ThreadSafeRefCounted.h" | |
43 | 44 |
44 #include <stdint.h> | 45 #include <stdint.h> |
45 | 46 |
46 namespace WebCore { | 47 namespace WebCore { |
47 | 48 |
48 const size_t blinkPageSizeLog2 = 17; | 49 const size_t blinkPageSizeLog2 = 17; |
49 const size_t blinkPageSize = 1 << blinkPageSizeLog2; | 50 const size_t blinkPageSize = 1 << blinkPageSizeLog2; |
50 const size_t blinkPageOffsetMask = blinkPageSize - 1; | 51 const size_t blinkPageOffsetMask = blinkPageSize - 1; |
51 const size_t blinkPageBaseMask = ~blinkPageOffsetMask; | 52 const size_t blinkPageBaseMask = ~blinkPageOffsetMask; |
52 // Double precision floats are more efficient when 8 byte aligned, so we 8 byte | 53 // Double precision floats are more efficient when 8 byte aligned, so we 8 byte |
53 // align all allocations even on 32 bit. | 54 // align all allocations even on 32 bit. |
54 const size_t allocationGranularity = 8; | 55 const size_t allocationGranularity = 8; |
55 const size_t allocationMask = allocationGranularity - 1; | 56 const size_t allocationMask = allocationGranularity - 1; |
56 const size_t objectStartBitMapSize = (blinkPageSize + ((8 * allocationGranularit y) - 1)) / (8 * allocationGranularity); | 57 const size_t objectStartBitMapSize = (blinkPageSize + ((8 * allocationGranularit y) - 1)) / (8 * allocationGranularity); |
57 const size_t reservedForObjectBitMap = ((objectStartBitMapSize + allocationMask) & ~allocationMask); | 58 const size_t reservedForObjectBitMap = ((objectStartBitMapSize + allocationMask) & ~allocationMask); |
58 const size_t maxHeapObjectSize = 1 << 27; | 59 const size_t maxHeapObjectSize = 1 << 27; |
59 | 60 |
60 const size_t markBitMask = 1; | 61 const size_t markBitMask = 1; |
61 const size_t freeListMask = 2; | 62 const size_t freeListMask = 2; |
62 const size_t debugBitMask = 4; | 63 const size_t debugBitMask = 4; |
63 const size_t sizeMask = ~7; | 64 const size_t sizeMask = ~7; |
64 const uint8_t freelistZapValue = 42; | 65 const uint8_t freelistZapValue = 42; |
65 const uint8_t finalizedZapValue = 24; | 66 const uint8_t finalizedZapValue = 24; |
66 | 67 |
67 class HeapStats; | 68 class HeapStats; |
68 class PageMemory; | 69 class PageMemory; |
69 template<ThreadAffinity affinity> class ThreadLocalPersistents; | 70 template<ThreadAffinity affinity> class ThreadLocalPersistents; |
70 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > > class Persistent; | 71 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > > class Persistent; |
72 template<typename T> class CrossThreadPersistent; | |
71 | 73 |
72 PLATFORM_EXPORT size_t osPageSize(); | 74 PLATFORM_EXPORT size_t osPageSize(); |
73 | 75 |
74 // Blink heap pages are set up with a guard page before and after the | 76 // Blink heap pages are set up with a guard page before and after the |
75 // payload. | 77 // payload. |
76 inline size_t blinkPagePayloadSize() | 78 inline size_t blinkPagePayloadSize() |
77 { | 79 { |
78 return blinkPageSize - 2 * osPageSize(); | 80 return blinkPageSize - 2 * osPageSize(); |
79 } | 81 } |
80 | 82 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 static const int numberOfEntriesLog2 = 12; | 535 static const int numberOfEntriesLog2 = 12; |
534 static const int numberOfEntries = 1 << numberOfEntriesLog2; | 536 static const int numberOfEntries = 1 << numberOfEntriesLog2; |
535 | 537 |
536 static size_t hash(Address); | 538 static size_t hash(Address); |
537 | 539 |
538 WTF::OwnPtr<HeapContainsCache::Entry[]> m_entries; | 540 WTF::OwnPtr<HeapContainsCache::Entry[]> m_entries; |
539 | 541 |
540 friend class ThreadState; | 542 friend class ThreadState; |
541 }; | 543 }; |
542 | 544 |
545 // FIXME: This is currently used by the WebAudio code. | |
546 // We should attempt to restructure the WebAudio code so that the main thread | |
547 // alone determines life-time and receives messages about life-time from the | |
548 // audio thread. | |
549 template<typename T> | |
550 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T> , public WTF::ThreadSafeRefCountedBase { | |
551 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected); | |
552 | |
553 public: | |
554 ThreadSafeRefCountedGarbageCollected() | |
555 { | |
556 #ifndef NDEBUG | |
557 m_threadState = ThreadState::current(); | |
Mads Ager (chromium)
2014/04/24 09:05:37
In the code on the branch I used this threadState
keishi
2014/05/06 20:00:03
Done.
| |
558 #endif | |
559 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this ))); | |
560 } | |
561 | |
562 // Override ref to deal with a case where a reference count goes up | |
563 // from 0 to 1. This can happen in the following scenario: | |
564 // (1) The reference count becomes 0, but on-stack pointers keep references to the object. | |
565 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec omes 1. | |
566 // In this case, we have to resurrect m_keepAlive. | |
567 void ref() | |
568 { | |
569 MutexLocker lock(m_mutex); | |
570 if (UNLIKELY(!refCount())) { | |
571 ASSERT(!m_keepAlive); | |
572 ASSERT(m_threadState->contains(reinterpret_cast<Address>(this))); | |
573 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>( this))); | |
574 } | |
575 WTF::ThreadSafeRefCountedBase::ref(); | |
576 } | |
577 | |
578 // Override deref to deal with our own deallocation based on ref counting. | |
579 void deref() | |
580 { | |
581 MutexLocker lock(m_mutex); | |
582 if (derefBase()) { | |
583 ASSERT(m_keepAlive); | |
584 m_keepAlive.clear(); | |
585 } | |
586 } | |
587 | |
588 using GarbageCollectedFinalized<T>::operator new; | |
589 using GarbageCollectedFinalized<T>::operator delete; | |
590 | |
591 protected: | |
592 ~ThreadSafeRefCountedGarbageCollected() { } | |
593 | |
594 private: | |
595 OwnPtr<CrossThreadPersistent<T> > m_keepAlive; | |
596 mutable Mutex m_mutex; | |
597 #ifndef NDEBUG | |
598 ThreadState* m_threadState; | |
599 #endif | |
600 }; | |
601 | |
543 // The CallbackStack contains all the visitor callbacks used to trace and mark | 602 // The CallbackStack contains all the visitor callbacks used to trace and mark |
544 // objects. A specific CallbackStack instance contains at most bufferSize elemen ts. | 603 // objects. A specific CallbackStack instance contains at most bufferSize elemen ts. |
545 // If more space is needed a new CallbackStack instance is created and chained | 604 // If more space is needed a new CallbackStack instance is created and chained |
546 // together with the former instance. I.e. a logical CallbackStack can be made o f | 605 // together with the former instance. I.e. a logical CallbackStack can be made o f |
547 // multiple chained CallbackStack object instances. | 606 // multiple chained CallbackStack object instances. |
548 // There are two logical callback stacks. One containing all the marking callbac ks and | 607 // There are two logical callback stacks. One containing all the marking callbac ks and |
549 // one containing the weak pointer callbacks. | 608 // one containing the weak pointer callbacks. |
550 class CallbackStack { | 609 class CallbackStack { |
551 public: | 610 public: |
552 CallbackStack(CallbackStack** first) | 611 CallbackStack(CallbackStack** first) |
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1937 // to export. This forces it to export all the methods from ThreadHeap. | 1996 // to export. This forces it to export all the methods from ThreadHeap. |
1938 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); | 1997 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); |
1939 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1998 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
1940 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1999 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
1941 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; | 2000 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; |
1942 #endif | 2001 #endif |
1943 | 2002 |
1944 } | 2003 } |
1945 | 2004 |
1946 #endif // Heap_h | 2005 #endif // Heap_h |
OLD | NEW |