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 21 matching lines...) Expand all Loading... | |
32 #define Heap_h | 32 #define Heap_h |
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/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
41 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
42 #include "wtf/ThreadSafeRefCounted.h" | |
42 | 43 |
43 #include <stdint.h> | 44 #include <stdint.h> |
44 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 const size_t blinkPageSizeLog2 = 17; | 48 const size_t blinkPageSizeLog2 = 17; |
48 const size_t blinkPageSize = 1 << blinkPageSizeLog2; | 49 const size_t blinkPageSize = 1 << blinkPageSizeLog2; |
49 const size_t blinkPageOffsetMask = blinkPageSize - 1; | 50 const size_t blinkPageOffsetMask = blinkPageSize - 1; |
50 const size_t blinkPageBaseMask = ~blinkPageOffsetMask; | 51 const size_t blinkPageBaseMask = ~blinkPageOffsetMask; |
51 // Double precision floats are more efficient when 8 byte aligned, so we 8 byte | 52 // Double precision floats are more efficient when 8 byte aligned, so we 8 byte |
52 // align all allocations even on 32 bit. | 53 // align all allocations even on 32 bit. |
53 const size_t allocationGranularity = 8; | 54 const size_t allocationGranularity = 8; |
54 const size_t allocationMask = allocationGranularity - 1; | 55 const size_t allocationMask = allocationGranularity - 1; |
55 const size_t objectStartBitMapSize = (blinkPageSize + ((8 * allocationGranularit y) - 1)) / (8 * allocationGranularity); | 56 const size_t objectStartBitMapSize = (blinkPageSize + ((8 * allocationGranularit y) - 1)) / (8 * allocationGranularity); |
56 const size_t reservedForObjectBitMap = ((objectStartBitMapSize + allocationMask) & ~allocationMask); | 57 const size_t reservedForObjectBitMap = ((objectStartBitMapSize + allocationMask) & ~allocationMask); |
57 const size_t maxHeapObjectSize = 1 << 27; | 58 const size_t maxHeapObjectSize = 1 << 27; |
58 | 59 |
59 const size_t markBitMask = 1; | 60 const size_t markBitMask = 1; |
60 const size_t freeListMask = 2; | 61 const size_t freeListMask = 2; |
61 const size_t debugBitMask = 4; | 62 const size_t debugBitMask = 4; |
62 const size_t sizeMask = ~7; | 63 const size_t sizeMask = ~7; |
63 const uint8_t freelistZapValue = 42; | 64 const uint8_t freelistZapValue = 42; |
64 const uint8_t finalizedZapValue = 24; | 65 const uint8_t finalizedZapValue = 24; |
65 | 66 |
66 class HeapStats; | 67 class HeapStats; |
67 class PageMemory; | 68 class PageMemory; |
68 template<ThreadAffinity affinity> class ThreadLocalPersistents; | 69 template<ThreadAffinity affinity> class ThreadLocalPersistents; |
69 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > > class Persistent; | 70 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > > class Persistent; |
71 template<typename T> class CrossThreadPersistent; | |
70 | 72 |
71 PLATFORM_EXPORT size_t osPageSize(); | 73 PLATFORM_EXPORT size_t osPageSize(); |
72 | 74 |
73 // Blink heap pages are set up with a guard page before and after the | 75 // Blink heap pages are set up with a guard page before and after the |
74 // payload. | 76 // payload. |
75 inline size_t blinkPagePayloadSize() | 77 inline size_t blinkPagePayloadSize() |
76 { | 78 { |
77 return blinkPageSize - 2 * osPageSize(); | 79 return blinkPageSize - 2 * osPageSize(); |
78 } | 80 } |
79 | 81 |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 static const int numberOfEntriesLog2 = 12; | 530 static const int numberOfEntriesLog2 = 12; |
529 static const int numberOfEntries = 1 << numberOfEntriesLog2; | 531 static const int numberOfEntries = 1 << numberOfEntriesLog2; |
530 | 532 |
531 static size_t hash(Address); | 533 static size_t hash(Address); |
532 | 534 |
533 WTF::OwnPtr<HeapContainsCache::Entry[]> m_entries; | 535 WTF::OwnPtr<HeapContainsCache::Entry[]> m_entries; |
534 | 536 |
535 friend class ThreadState; | 537 friend class ThreadState; |
536 }; | 538 }; |
537 | 539 |
540 // FIXME(oilpan): The current implementation requires the deallocating | |
haraken
2014/04/08 06:02:08
FIXME: oilpan:
keishi
2014/04/21 17:10:11
Done.
| |
541 // thread to be the same as the thread on which this instance was first | |
542 // allocated. Only the refs/derefs that are not 0 -> 1 or 1 -> 0 are | |
543 // thread safe. | |
haraken
2014/04/08 06:02:08
Do we still have this restriction? I guess that th
keishi
2014/04/21 17:10:11
Done.
| |
544 // This is currently used by the WebAudio code. | |
545 // We should attempt to restructure the WebAudio code so that the main thread | |
546 // alone determines life-time and receives messages about life-time from the | |
547 // audio thread. | |
548 template<typename T> | |
549 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T> , public WTF::ThreadSafeRefCountedBase { | |
550 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected); | |
551 | |
552 public: | |
553 ThreadSafeRefCountedGarbageCollected() | |
554 { | |
555 #ifndef NDEBUG | |
556 m_threadState = ThreadState::current(); | |
557 #endif | |
558 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this ))); | |
559 } | |
560 | |
561 // Override ref to deal with a case where a reference count goes up | |
562 // from 0 to 1. This can happen in the following scenario: | |
563 // (1) The reference count becomes 0, but on-stack pointers keep references to the object. | |
564 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec omes 1. | |
565 // In this case, we have to resurrect m_keepAlive. | |
566 void ref() | |
567 { | |
568 MutexLocker lock(m_mutex); | |
569 if (UNLIKELY(!refCount())) { | |
570 ASSERT(!m_keepAlive); | |
571 ASSERT(m_threadState->contains(reinterpret_cast<Address>(this))); | |
572 // ASSERT(m_threadState == ThreadState::current()); | |
haraken
2014/04/08 06:02:08
Do we need this ASSERT?
keishi
2014/04/21 17:10:11
This was in the branch but I don't think we should
| |
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_threadState == ThreadState::current()); | |
haraken
2014/04/08 06:02:08
Do we need this ASSERT?
haraken
2014/04/08 06:02:08
Add ASSERT(m_keepAlive).
keishi
2014/04/21 17:10:11
Done.
keishi
2014/04/21 17:10:11
Removed.
| |
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 | |
538 // 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 |
539 // objects. A specific CallbackStack instance contains at most bufferSize elemen ts. | 603 // objects. A specific CallbackStack instance contains at most bufferSize elemen ts. |
540 // 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 |
541 // 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 |
542 // multiple chained CallbackStack object instances. | 606 // multiple chained CallbackStack object instances. |
543 // 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 |
544 // one containing the weak pointer callbacks. | 608 // one containing the weak pointer callbacks. |
545 class CallbackStack { | 609 class CallbackStack { |
546 public: | 610 public: |
547 CallbackStack(CallbackStack** first) | 611 CallbackStack(CallbackStack** first) |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1782 // to export. This forces it to export all the methods from ThreadHeap. | 1846 // to export. This forces it to export all the methods from ThreadHeap. |
1783 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); | 1847 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); |
1784 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1848 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
1785 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1849 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
1786 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; | 1850 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; |
1787 #endif | 1851 #endif |
1788 | 1852 |
1789 } | 1853 } |
1790 | 1854 |
1791 #endif // Heap_h | 1855 #endif // Heap_h |
OLD | NEW |