| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #ifndef Heap_h | 31 #ifndef Heap_h |
| 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/HashCountedSet.h" |
| 40 #include "wtf/LinkedHashSet.h" | 41 #include "wtf/LinkedHashSet.h" |
| 41 #include "wtf/OwnPtr.h" | 42 #include "wtf/OwnPtr.h" |
| 42 #include "wtf/PassRefPtr.h" | 43 #include "wtf/PassRefPtr.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; |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 1440 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
| 1440 typename TraitsArg = HashTraits<ValueArg> > | 1441 typename TraitsArg = HashTraits<ValueArg> > |
| 1441 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>
{ }; | 1442 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>
{ }; |
| 1442 | 1443 |
| 1443 template< | 1444 template< |
| 1444 typename ValueArg, | 1445 typename ValueArg, |
| 1445 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 1446 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
| 1446 typename TraitsArg = HashTraits<ValueArg> > | 1447 typename TraitsArg = HashTraits<ValueArg> > |
| 1447 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea
pAllocator> { }; | 1448 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea
pAllocator> { }; |
| 1448 | 1449 |
| 1450 template< |
| 1451 typename Value, |
| 1452 typename HashFunctions = typename DefaultHash<Value>::Hash, |
| 1453 typename Traits = HashTraits<Value> > |
| 1454 class HeapHashCountedSet : public HashCountedSet<Value, HashFunctions, Traits, H
eapAllocator> { }; |
| 1455 |
| 1449 template<typename T, size_t inlineCapacity = 0> | 1456 template<typename T, size_t inlineCapacity = 0> |
| 1450 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { | 1457 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { |
| 1451 public: | 1458 public: |
| 1452 HeapVector() { } | 1459 HeapVector() { } |
| 1453 | 1460 |
| 1454 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>(
size) | 1461 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>(
size) |
| 1455 { | 1462 { |
| 1456 } | 1463 } |
| 1457 | 1464 |
| 1458 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca
tor>(size, val) | 1465 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca
tor>(size, val) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 template<typename T, typename Traits> | 1570 template<typename T, typename Traits> |
| 1564 struct ThreadingTrait<HeapVectorBacking<T, Traits> > { | 1571 struct ThreadingTrait<HeapVectorBacking<T, Traits> > { |
| 1565 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1572 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1566 }; | 1573 }; |
| 1567 | 1574 |
| 1568 template<typename T, size_t inlineCapacity> | 1575 template<typename T, size_t inlineCapacity> |
| 1569 struct ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator> > { | 1576 struct ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator> > { |
| 1570 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1577 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1571 }; | 1578 }; |
| 1572 | 1579 |
| 1580 template<typename T, typename U, typename V> |
| 1581 struct ThreadingTrait<HashCountedSet<T, U, V, HeapAllocator> > { |
| 1582 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1583 }; |
| 1584 |
| 1573 template<typename Table> | 1585 template<typename Table> |
| 1574 struct ThreadingTrait<HeapHashTableBacking<Table> > { | 1586 struct ThreadingTrait<HeapHashTableBacking<Table> > { |
| 1575 typedef typename Table::KeyType Key; | 1587 typedef typename Table::KeyType Key; |
| 1576 typedef typename Table::ValueType Value; | 1588 typedef typename Table::ValueType Value; |
| 1577 static const ThreadAffinity Affinity = | 1589 static const ThreadAffinity Affinity = |
| 1578 (ThreadingTrait<Key>::Affinity == MainThreadOnly) | 1590 (ThreadingTrait<Key>::Affinity == MainThreadOnly) |
| 1579 && (ThreadingTrait<Value>::Affinity == MainThreadOnly) ? MainThreadOnly
: AnyThread; | 1591 && (ThreadingTrait<Value>::Affinity == MainThreadOnly) ? MainThreadOnly
: AnyThread; |
| 1580 }; | 1592 }; |
| 1581 | 1593 |
| 1582 template<typename T, typename U, typename V, typename W, typename X> | 1594 template<typename T, typename U, typename V, typename W, typename X> |
| 1583 struct ThreadingTrait<HeapHashMap<T, U, V, W, X> > : public ThreadingTrait<HashM
ap<T, U, V, W, X, HeapAllocator> > { }; | 1595 struct ThreadingTrait<HeapHashMap<T, U, V, W, X> > : public ThreadingTrait<HashM
ap<T, U, V, W, X, HeapAllocator> > { }; |
| 1584 | 1596 |
| 1585 template<typename T, typename U, typename V> | 1597 template<typename T, typename U, typename V> |
| 1586 struct ThreadingTrait<HeapHashSet<T, U, V> > : public ThreadingTrait<HashSet<T,
U, V, HeapAllocator> > { }; | 1598 struct ThreadingTrait<HeapHashSet<T, U, V> > : public ThreadingTrait<HashSet<T,
U, V, HeapAllocator> > { }; |
| 1587 | 1599 |
| 1588 template<typename T, size_t inlineCapacity> | 1600 template<typename T, size_t inlineCapacity> |
| 1589 struct ThreadingTrait<HeapVector<T, inlineCapacity> > : public ThreadingTrait<Ve
ctor<T, inlineCapacity, HeapAllocator> > { }; | 1601 struct ThreadingTrait<HeapVector<T, inlineCapacity> > : public ThreadingTrait<Ve
ctor<T, inlineCapacity, HeapAllocator> > { }; |
| 1590 | 1602 |
| 1591 template<typename T, size_t inlineCapacity> | 1603 template<typename T, size_t inlineCapacity> |
| 1592 struct ThreadingTrait<HeapDeque<T, inlineCapacity> > : public ThreadingTrait<Deq
ue<T, inlineCapacity, HeapAllocator> > { }; | 1604 struct ThreadingTrait<HeapDeque<T, inlineCapacity> > : public ThreadingTrait<Deq
ue<T, inlineCapacity, HeapAllocator> > { }; |
| 1593 | 1605 |
| 1606 template<typename T, typename U, typename V> |
| 1607 struct ThreadingTrait<HeapHashCountedSet<T, U, V> > : public ThreadingTrait<Hash
CountedSet<T, U, V, HeapAllocator> > { }; |
| 1608 |
| 1594 // The standard implementation of GCInfoTrait<T>::get() just returns a static | 1609 // The standard implementation of GCInfoTrait<T>::get() just returns a static |
| 1595 // from the class T, but we can't do that for HashMap, HashSet, Deque and | 1610 // from the class T, but we can't do that for HashMap, HashSet, Vector, etc. |
| 1596 // Vector because they are in WTF and know nothing of GCInfos. Instead we have | 1611 // because they are in WTF and know nothing of GCInfos. Instead we have a |
| 1597 // a specialization of GCInfoTrait for these four classes here. | 1612 // specialization of GCInfoTrait for these four classes here. |
| 1598 | 1613 |
| 1599 template<typename Key, typename Value, typename T, typename U, typename V> | 1614 template<typename Key, typename Value, typename T, typename U, typename V> |
| 1600 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { | 1615 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { |
| 1601 static const GCInfo* get() | 1616 static const GCInfo* get() |
| 1602 { | 1617 { |
| 1603 typedef HashMap<Key, Value, T, U, V, HeapAllocator> TargetType; | 1618 typedef HashMap<Key, Value, T, U, V, HeapAllocator> TargetType; |
| 1604 static const GCInfo info = { | 1619 static const GCInfo info = { |
| 1605 TraceTrait<TargetType>::trace, | 1620 TraceTrait<TargetType>::trace, |
| 1606 0, | 1621 0, |
| 1607 false, // HashMap needs no finalizer. | 1622 false, // HashMap needs no finalizer. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 VTableTrait<TargetType>::hasVTable, | 1718 VTableTrait<TargetType>::hasVTable, |
| 1704 #if ENABLE(GC_TRACING) | 1719 #if ENABLE(GC_TRACING) |
| 1705 TypenameStringTrait<TargetType>::get() | 1720 TypenameStringTrait<TargetType>::get() |
| 1706 #endif | 1721 #endif |
| 1707 }; | 1722 }; |
| 1708 return &info; | 1723 return &info; |
| 1709 } | 1724 } |
| 1710 static const GCInfo info; | 1725 static const GCInfo info; |
| 1711 }; | 1726 }; |
| 1712 | 1727 |
| 1728 template<typename T, typename U, typename V> |
| 1729 struct GCInfoTrait<HashCountedSet<T, U, V, HeapAllocator> > { |
| 1730 static const GCInfo* get() |
| 1731 { |
| 1732 typedef HashCountedSet<T, U, V, HeapAllocator> TargetType; |
| 1733 static const GCInfo info = { |
| 1734 TraceTrait<TargetType>::trace, |
| 1735 0, |
| 1736 false, // HashCountedSet is just a HashTable, and needs no finalizer
. |
| 1737 VTableTrait<TargetType>::hasVTable, |
| 1738 #if ENABLE(GC_TRACING) |
| 1739 TypenameStringTrait<TargetType>::get() |
| 1740 #endif |
| 1741 }; |
| 1742 return &info; |
| 1743 } |
| 1744 static const GCInfo info; |
| 1745 }; |
| 1746 |
| 1713 template<typename T, size_t inlineCapacity> | 1747 template<typename T, size_t inlineCapacity> |
| 1714 struct FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator> > : public Finaliz
erTraitImpl<Deque<T, inlineCapacity, HeapAllocator>, true> { }; | 1748 struct FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator> > : public Finaliz
erTraitImpl<Deque<T, inlineCapacity, HeapAllocator>, true> { }; |
| 1715 | 1749 |
| 1716 template<typename T, size_t inlineCapacity> | 1750 template<typename T, size_t inlineCapacity> |
| 1717 struct GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { | 1751 struct GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { |
| 1718 static const GCInfo* get() | 1752 static const GCInfo* get() |
| 1719 { | 1753 { |
| 1720 typedef Deque<T, inlineCapacity, HeapAllocator> TargetType; | 1754 typedef Deque<T, inlineCapacity, HeapAllocator> TargetType; |
| 1721 static const GCInfo info = { | 1755 static const GCInfo info = { |
| 1722 TraceTrait<TargetType>::trace, | 1756 TraceTrait<TargetType>::trace, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 template<typename T, typename U, typename V, typename W, typename X> | 2030 template<typename T, typename U, typename V, typename W, typename X> |
| 1997 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T,
U, V, W, X, HeapAllocator> > { }; | 2031 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T,
U, V, W, X, HeapAllocator> > { }; |
| 1998 template<typename T, typename U, typename V> | 2032 template<typename T, typename U, typename V> |
| 1999 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V,
HeapAllocator> > { }; | 2033 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V,
HeapAllocator> > { }; |
| 2000 template<typename T, typename U, typename V> | 2034 template<typename T, typename U, typename V> |
| 2001 struct GCInfoTrait<HeapLinkedHashSet<T, U, V> > : public GCInfoTrait<LinkedHashS
et<T, U, V, HeapAllocator> > { }; | 2035 struct GCInfoTrait<HeapLinkedHashSet<T, U, V> > : public GCInfoTrait<LinkedHashS
et<T, U, V, HeapAllocator> > { }; |
| 2002 template<typename T, size_t inlineCapacity> | 2036 template<typename T, size_t inlineCapacity> |
| 2003 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T
, inlineCapacity, HeapAllocator> > { }; | 2037 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T
, inlineCapacity, HeapAllocator> > { }; |
| 2004 template<typename T, size_t inlineCapacity> | 2038 template<typename T, size_t inlineCapacity> |
| 2005 struct GCInfoTrait<HeapDeque<T, inlineCapacity> > : public GCInfoTrait<Deque<T,
inlineCapacity, HeapAllocator> > { }; | 2039 struct GCInfoTrait<HeapDeque<T, inlineCapacity> > : public GCInfoTrait<Deque<T,
inlineCapacity, HeapAllocator> > { }; |
| 2040 template<typename T, typename U, typename V> |
| 2041 struct GCInfoTrait<HeapHashCountedSet<T, U, V> > : public GCInfoTrait<HashCounte
dSet<T, U, V, HeapAllocator> > { }; |
| 2006 | 2042 |
| 2007 template<typename T> | 2043 template<typename T> |
| 2008 struct IfWeakMember; | 2044 struct IfWeakMember; |
| 2009 | 2045 |
| 2010 template<typename T> | 2046 template<typename T> |
| 2011 struct IfWeakMember { | 2047 struct IfWeakMember { |
| 2012 template<typename U> | 2048 template<typename U> |
| 2013 static bool isDead(Visitor*, const U&) { return false; } | 2049 static bool isDead(Visitor*, const U&) { return false; } |
| 2014 }; | 2050 }; |
| 2015 | 2051 |
| 2016 template<typename T> | 2052 template<typename T> |
| 2017 struct IfWeakMember<WeakMember<T> > { | 2053 struct IfWeakMember<WeakMember<T> > { |
| 2018 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit
or->isAlive(t.get()); } | 2054 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit
or->isAlive(t.get()); } |
| 2019 }; | 2055 }; |
| 2020 | 2056 |
| 2021 #if COMPILER(CLANG) | 2057 #if COMPILER(CLANG) |
| 2022 // Clang does not export the symbols that we have explicitly asked it | 2058 // Clang does not export the symbols that we have explicitly asked it |
| 2023 // to export. This forces it to export all the methods from ThreadHeap. | 2059 // to export. This forces it to export all the methods from ThreadHeap. |
| 2024 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); | 2060 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); |
| 2025 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 2061 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
| 2026 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 2062 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
| 2027 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; | 2063 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; |
| 2028 #endif | 2064 #endif |
| 2029 | 2065 |
| 2030 } | 2066 } |
| 2031 | 2067 |
| 2032 #endif // Heap_h | 2068 #endif // Heap_h |
| OLD | NEW |