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 24 matching lines...) Expand all Loading... |
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/HashCountedSet.h" | 40 #include "wtf/HashCountedSet.h" |
41 #include "wtf/LinkedHashSet.h" | 41 #include "wtf/LinkedHashSet.h" |
42 #include "wtf/ListHashSet.h" | 42 #include "wtf/ListHashSet.h" |
43 #include "wtf/OwnPtr.h" | 43 #include "wtf/OwnPtr.h" |
44 #include "wtf/PassRefPtr.h" | 44 #include "wtf/PassRefPtr.h" |
| 45 #include "wtf/ThreadSafeRefCounted.h" |
45 | 46 |
46 #include <stdint.h> | 47 #include <stdint.h> |
47 | 48 |
48 namespace WebCore { | 49 namespace WebCore { |
49 | 50 |
50 const size_t blinkPageSizeLog2 = 17; | 51 const size_t blinkPageSizeLog2 = 17; |
51 const size_t blinkPageSize = 1 << blinkPageSizeLog2; | 52 const size_t blinkPageSize = 1 << blinkPageSizeLog2; |
52 const size_t blinkPageOffsetMask = blinkPageSize - 1; | 53 const size_t blinkPageOffsetMask = blinkPageSize - 1; |
53 const size_t blinkPageBaseMask = ~blinkPageOffsetMask; | 54 const size_t blinkPageBaseMask = ~blinkPageOffsetMask; |
54 // Double precision floats are more efficient when 8 byte aligned, so we 8 byte | 55 // Double precision floats are more efficient when 8 byte aligned, so we 8 byte |
55 // align all allocations even on 32 bit. | 56 // align all allocations even on 32 bit. |
56 const size_t allocationGranularity = 8; | 57 const size_t allocationGranularity = 8; |
57 const size_t allocationMask = allocationGranularity - 1; | 58 const size_t allocationMask = allocationGranularity - 1; |
58 const size_t objectStartBitMapSize = (blinkPageSize + ((8 * allocationGranularit
y) - 1)) / (8 * allocationGranularity); | 59 const size_t objectStartBitMapSize = (blinkPageSize + ((8 * allocationGranularit
y) - 1)) / (8 * allocationGranularity); |
59 const size_t reservedForObjectBitMap = ((objectStartBitMapSize + allocationMask)
& ~allocationMask); | 60 const size_t reservedForObjectBitMap = ((objectStartBitMapSize + allocationMask)
& ~allocationMask); |
60 const size_t maxHeapObjectSize = 1 << 27; | 61 const size_t maxHeapObjectSize = 1 << 27; |
61 | 62 |
62 const size_t markBitMask = 1; | 63 const size_t markBitMask = 1; |
63 const size_t freeListMask = 2; | 64 const size_t freeListMask = 2; |
64 const size_t debugBitMask = 4; | 65 const size_t debugBitMask = 4; |
65 const size_t sizeMask = ~7; | 66 const size_t sizeMask = ~7; |
66 const uint8_t freelistZapValue = 42; | 67 const uint8_t freelistZapValue = 42; |
67 const uint8_t finalizedZapValue = 24; | 68 const uint8_t finalizedZapValue = 24; |
68 | 69 |
69 class HeapStats; | 70 class HeapStats; |
70 class PageMemory; | 71 class PageMemory; |
71 template<ThreadAffinity affinity> class ThreadLocalPersistents; | 72 template<ThreadAffinity affinity> class ThreadLocalPersistents; |
72 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr
ait<T>::Affinity > > class Persistent; | 73 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr
ait<T>::Affinity > > class Persistent; |
| 74 template<typename T> class CrossThreadPersistent; |
73 | 75 |
74 PLATFORM_EXPORT size_t osPageSize(); | 76 PLATFORM_EXPORT size_t osPageSize(); |
75 | 77 |
76 // Blink heap pages are set up with a guard page before and after the | 78 // Blink heap pages are set up with a guard page before and after the |
77 // payload. | 79 // payload. |
78 inline size_t blinkPagePayloadSize() | 80 inline size_t blinkPagePayloadSize() |
79 { | 81 { |
80 return blinkPageSize - 2 * osPageSize(); | 82 return blinkPageSize - 2 * osPageSize(); |
81 } | 83 } |
82 | 84 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 static const int numberOfEntriesLog2 = 12; | 554 static const int numberOfEntriesLog2 = 12; |
553 static const int numberOfEntries = 1 << numberOfEntriesLog2; | 555 static const int numberOfEntries = 1 << numberOfEntriesLog2; |
554 | 556 |
555 static size_t hash(Address); | 557 static size_t hash(Address); |
556 | 558 |
557 WTF::OwnPtr<HeapContainsCache::Entry[]> m_entries; | 559 WTF::OwnPtr<HeapContainsCache::Entry[]> m_entries; |
558 | 560 |
559 friend class ThreadState; | 561 friend class ThreadState; |
560 }; | 562 }; |
561 | 563 |
| 564 // FIXME: This is currently used by the WebAudio code. |
| 565 // We should attempt to restructure the WebAudio code so that the main thread |
| 566 // alone determines life-time and receives messages about life-time from the |
| 567 // audio thread. |
| 568 template<typename T> |
| 569 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T>
, public WTF::ThreadSafeRefCountedBase { |
| 570 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected); |
| 571 |
| 572 public: |
| 573 ThreadSafeRefCountedGarbageCollected() |
| 574 { |
| 575 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this
))); |
| 576 } |
| 577 |
| 578 // Override ref to deal with a case where a reference count goes up |
| 579 // from 0 to 1. This can happen in the following scenario: |
| 580 // (1) The reference count becomes 0, but on-stack pointers keep references
to the object. |
| 581 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec
omes 1. |
| 582 // In this case, we have to resurrect m_keepAlive. |
| 583 void ref() |
| 584 { |
| 585 MutexLocker lock(m_mutex); |
| 586 if (UNLIKELY(!refCount())) { |
| 587 ASSERT(!m_keepAlive); |
| 588 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(
this))); |
| 589 } |
| 590 WTF::ThreadSafeRefCountedBase::ref(); |
| 591 } |
| 592 |
| 593 // Override deref to deal with our own deallocation based on ref counting. |
| 594 void deref() |
| 595 { |
| 596 MutexLocker lock(m_mutex); |
| 597 if (derefBase()) { |
| 598 ASSERT(m_keepAlive); |
| 599 m_keepAlive.clear(); |
| 600 } |
| 601 } |
| 602 |
| 603 using GarbageCollectedFinalized<T>::operator new; |
| 604 using GarbageCollectedFinalized<T>::operator delete; |
| 605 |
| 606 protected: |
| 607 ~ThreadSafeRefCountedGarbageCollected() { } |
| 608 |
| 609 private: |
| 610 OwnPtr<CrossThreadPersistent<T> > m_keepAlive; |
| 611 mutable Mutex m_mutex; |
| 612 }; |
| 613 |
562 // The CallbackStack contains all the visitor callbacks used to trace and mark | 614 // The CallbackStack contains all the visitor callbacks used to trace and mark |
563 // objects. A specific CallbackStack instance contains at most bufferSize elemen
ts. | 615 // objects. A specific CallbackStack instance contains at most bufferSize elemen
ts. |
564 // If more space is needed a new CallbackStack instance is created and chained | 616 // If more space is needed a new CallbackStack instance is created and chained |
565 // together with the former instance. I.e. a logical CallbackStack can be made o
f | 617 // together with the former instance. I.e. a logical CallbackStack can be made o
f |
566 // multiple chained CallbackStack object instances. | 618 // multiple chained CallbackStack object instances. |
567 // There are two logical callback stacks. One containing all the marking callbac
ks and | 619 // There are two logical callback stacks. One containing all the marking callbac
ks and |
568 // one containing the weak pointer callbacks. | 620 // one containing the weak pointer callbacks. |
569 class CallbackStack { | 621 class CallbackStack { |
570 public: | 622 public: |
571 CallbackStack(CallbackStack** first) | 623 CallbackStack(CallbackStack** first) |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2203 // to export. This forces it to export all the methods from ThreadHeap. | 2255 // to export. This forces it to export all the methods from ThreadHeap. |
2204 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); | 2256 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); |
2205 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 2257 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
2206 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 2258 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
2207 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; | 2259 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; |
2208 #endif | 2260 #endif |
2209 | 2261 |
2210 } | 2262 } |
2211 | 2263 |
2212 #endif // Heap_h | 2264 #endif // Heap_h |
OLD | NEW |