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 "heap/AddressSanitizer.h" | 34 #include "heap/AddressSanitizer.h" |
35 #include "heap/HeapExport.h" | 35 #include "heap/HeapExport.h" |
36 #include "heap/ThreadState.h" | 36 #include "heap/ThreadState.h" |
37 #include "heap/Visitor.h" | 37 #include "heap/Visitor.h" |
38 | 38 |
39 #include "wtf/Assertions.h" | 39 #include "wtf/Assertions.h" |
40 #include "wtf/LinkedHashSet.h" | |
40 #include "wtf/OwnPtr.h" | 41 #include "wtf/OwnPtr.h" |
41 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.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; |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 { | 1282 { |
1282 return !visitor->isAlive(t); | 1283 return !visitor->isAlive(t); |
1283 } | 1284 } |
1284 | 1285 |
1285 template<typename T, typename U> | 1286 template<typename T, typename U> |
1286 static bool hasDeadMember(Visitor* visitor, const WTF::KeyValuePair<T, U>& t ) | 1287 static bool hasDeadMember(Visitor* visitor, const WTF::KeyValuePair<T, U>& t ) |
1287 { | 1288 { |
1288 return hasDeadMember(visitor, t.key) || hasDeadMember(visitor, t.value); | 1289 return hasDeadMember(visitor, t.key) || hasDeadMember(visitor, t.value); |
1289 } | 1290 } |
1290 | 1291 |
1292 template<typename T> | |
1293 static bool hasDeadMember(Visitor*, const WTF::LinkedHashSetNode<T>&); | |
1294 | |
1291 static void registerWeakMembers(Visitor* visitor, const void* closure, const void* object, WeakPointerCallback callback) | 1295 static void registerWeakMembers(Visitor* visitor, const void* closure, const void* object, WeakPointerCallback callback) |
1292 { | 1296 { |
1293 visitor->registerWeakMembers(closure, object, callback); | 1297 visitor->registerWeakMembers(closure, object, callback); |
1294 } | 1298 } |
1295 | 1299 |
1296 template<typename T> | 1300 template<typename T> |
1297 struct ResultType { | 1301 struct ResultType { |
1298 typedef T* Type; | 1302 typedef T* Type; |
1299 }; | 1303 }; |
1300 | 1304 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 typename KeyTraitsArg = HashTraits<KeyArg>, | 1352 typename KeyTraitsArg = HashTraits<KeyArg>, |
1349 typename MappedTraitsArg = HashTraits<MappedArg> > | 1353 typename MappedTraitsArg = HashTraits<MappedArg> > |
1350 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map pedTraitsArg, HeapAllocator> { }; | 1354 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map pedTraitsArg, HeapAllocator> { }; |
1351 | 1355 |
1352 template< | 1356 template< |
1353 typename ValueArg, | 1357 typename ValueArg, |
1354 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 1358 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
1355 typename TraitsArg = HashTraits<ValueArg> > | 1359 typename TraitsArg = HashTraits<ValueArg> > |
1356 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator> { }; | 1360 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator> { }; |
1357 | 1361 |
1362 template< | |
1363 typename ValueArg, | |
1364 typename HashArg = typename DefaultHash<ValueArg>::Hash, | |
1365 typename TraitsArg = HashTraits<ValueArg> > | |
1366 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea pAllocator> { }; | |
1367 | |
1358 template<typename T, size_t inlineCapacity = 0> | 1368 template<typename T, size_t inlineCapacity = 0> |
1359 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { | 1369 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { |
1360 public: | 1370 public: |
1361 HeapVector() { } | 1371 HeapVector() { } |
1362 | 1372 |
1363 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>( size) | 1373 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>( size) |
1364 { | 1374 { |
1365 } | 1375 } |
1366 | 1376 |
1367 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca tor>(size, val) | 1377 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca tor>(size, val) |
(...skipping 14 matching lines...) Expand all Loading... | |
1382 | 1392 |
1383 template<typename U, size_t otherCapacity> | 1393 template<typename U, size_t otherCapacity> |
1384 void appendVector(const HeapVector<U, otherCapacity>& other) | 1394 void appendVector(const HeapVector<U, otherCapacity>& other) |
1385 { | 1395 { |
1386 const Vector<U, otherCapacity, HeapAllocator>& otherVector = other; | 1396 const Vector<U, otherCapacity, HeapAllocator>& otherVector = other; |
1387 Vector<T, inlineCapacity, HeapAllocator>::appendVector(otherVector); | 1397 Vector<T, inlineCapacity, HeapAllocator>::appendVector(otherVector); |
1388 } | 1398 } |
1389 }; | 1399 }; |
1390 | 1400 |
1391 template<typename T> | 1401 template<typename T> |
1402 bool HeapAllocator::hasDeadMember(Visitor* visitor, const WTF::LinkedHashSetNode <T>& t) | |
1403 { | |
1404 return hasDeadMember(visitor, t.m_value); | |
1405 } | |
1406 | |
1407 template<typename T> | |
1392 struct ThreadingTrait<Member<T> > { | 1408 struct ThreadingTrait<Member<T> > { |
1393 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1409 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
1394 }; | 1410 }; |
1395 | 1411 |
1396 template<typename T> | 1412 template<typename T> |
1397 struct ThreadingTrait<WeakMember<T> > { | 1413 struct ThreadingTrait<WeakMember<T> > { |
1398 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1414 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
1399 }; | 1415 }; |
1400 | 1416 |
1401 template<typename Key, typename Value, typename T, typename U, typename V> | 1417 template<typename Key, typename Value, typename T, typename U, typename V> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1470 static const GCInfo info; | 1486 static const GCInfo info; |
1471 }; | 1487 }; |
1472 | 1488 |
1473 template<typename T, typename U, typename V> | 1489 template<typename T, typename U, typename V> |
1474 const GCInfo GCInfoTrait<HashSet<T, U, V, HeapAllocator> >::info = { | 1490 const GCInfo GCInfoTrait<HashSet<T, U, V, HeapAllocator> >::info = { |
1475 TraceTrait<HashSet<T, U, V, HeapAllocator> >::trace, | 1491 TraceTrait<HashSet<T, U, V, HeapAllocator> >::trace, |
1476 0, | 1492 0, |
1477 false, // HashSet needs no finalizer. | 1493 false, // HashSet needs no finalizer. |
1478 }; | 1494 }; |
1479 | 1495 |
1496 template<typename T, typename U, typename V> | |
1497 struct GCInfoTrait<LinkedHashSet<T, U, V, HeapAllocator> > { | |
1498 static const GCInfo* get() { return &info; } | |
1499 static const GCInfo info; | |
1500 }; | |
1501 | |
1502 template<typename T, typename U, typename V> | |
1503 const GCInfo GCInfoTrait<LinkedHashSet<T, U, V, HeapAllocator> >::info = { | |
1504 TraceTrait<LinkedHashSet<T, U, V, HeapAllocator> >::trace, | |
1505 LinkedHashSet<T, U, V, HeapAllocator>::finalize, | |
1506 true, // The anchor needs to unlink itself from the chain. | |
Mads Ager (chromium)
2014/04/03 09:24:35
Maybe update the comment: Needs finalization: the
Erik Corry
2014/04/10 10:47:37
Done.
| |
1507 }; | |
1508 | |
1480 template<typename T> | 1509 template<typename T> |
1481 struct GCInfoTrait<Vector<T, 0, HeapAllocator> > { | 1510 struct GCInfoTrait<Vector<T, 0, HeapAllocator> > { |
1482 static const GCInfo* get() { return &info; } | 1511 static const GCInfo* get() { return &info; } |
1483 static const GCInfo info; | 1512 static const GCInfo info; |
1484 }; | 1513 }; |
1485 | 1514 |
1486 template<typename T> | 1515 template<typename T> |
1487 const GCInfo GCInfoTrait<Vector<T, 0, HeapAllocator> >::info = { | 1516 const GCInfo GCInfoTrait<Vector<T, 0, HeapAllocator> >::info = { |
1488 TraceTrait<Vector<T, 0, HeapAllocator> >::trace, | 1517 TraceTrait<Vector<T, 0, HeapAllocator> >::trace, |
1489 0, | 1518 0, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1573 template<bool markWeakMembersStrongly, typename Key, typename Value, typename Tr aits> | 1602 template<bool markWeakMembersStrongly, typename Key, typename Value, typename Tr aits> |
1574 struct BaseVisitKeyValuePairTrait { | 1603 struct BaseVisitKeyValuePairTrait { |
1575 static void mark(WebCore::Visitor* visitor, WTF::KeyValuePair<Key, Value>& s elf) | 1604 static void mark(WebCore::Visitor* visitor, WTF::KeyValuePair<Key, Value>& s elf) |
1576 { | 1605 { |
1577 ASSERT(WTF::ShouldBeTraced<Traits>::value || (Traits::isWeak && markWeak MembersStrongly)); | 1606 ASSERT(WTF::ShouldBeTraced<Traits>::value || (Traits::isWeak && markWeak MembersStrongly)); |
1578 CollectionBackingTraceTrait<WTF::ShouldBeTraced<typename Traits::KeyTrai ts>::value, Traits::KeyTraits::isWeak, markWeakMembersStrongly, Key, typename Tr aits::KeyTraits>::mark(visitor, self.key); | 1607 CollectionBackingTraceTrait<WTF::ShouldBeTraced<typename Traits::KeyTrai ts>::value, Traits::KeyTraits::isWeak, markWeakMembersStrongly, Key, typename Tr aits::KeyTraits>::mark(visitor, self.key); |
1579 CollectionBackingTraceTrait<WTF::ShouldBeTraced<typename Traits::ValueTr aits>::value, Traits::ValueTraits::isWeak, markWeakMembersStrongly, Value, typen ame Traits::ValueTraits>::mark(visitor, self.value); | 1608 CollectionBackingTraceTrait<WTF::ShouldBeTraced<typename Traits::ValueTr aits>::value, Traits::ValueTraits::isWeak, markWeakMembersStrongly, Value, typen ame Traits::ValueTraits>::mark(visitor, self.value); |
1580 } | 1609 } |
1581 }; | 1610 }; |
1582 | 1611 |
1612 template<bool markWeakMembersStrongly, typename Value, typename Traits> | |
1613 struct BaseVisitLinkedNodeTrait { | |
1614 static void mark(WebCore::Visitor* visitor, WTF::LinkedHashSetNode<Value>& s elf) | |
1615 { | |
1616 ASSERT(WTF::ShouldBeTraced<Traits>::value || (Traits::isWeak && markWeak MembersStrongly)); | |
1617 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits:: isWeak, markWeakMembersStrongly, Value, Traits>::mark(visitor, self.m_value); | |
1618 } | |
1619 }; | |
1620 | |
1583 // FFX - Things that don't need marking and have no weak pointers. | 1621 // FFX - Things that don't need marking and have no weak pointers. |
1584 template<bool markWeakMembersStrongly, typename T, typename U> | 1622 template<bool markWeakMembersStrongly, typename T, typename U> |
1585 struct CollectionBackingTraceTrait<false, false, markWeakMembersStrongly, T, U> { | 1623 struct CollectionBackingTraceTrait<false, false, markWeakMembersStrongly, T, U> { |
1586 static void mark(Visitor*, const T&) { } | 1624 static void mark(Visitor*, const T&) { } |
1587 static void mark(Visitor*, const void*) { } | 1625 static void mark(Visitor*, const void*) { } |
1588 }; | 1626 }; |
1589 | 1627 |
1590 // FTF - Things that don't need marking. They have weak pointers, but we are | 1628 // FTF - Things that don't need marking. They have weak pointers, but we are |
1591 // not marking weak pointers in this object in this GC. | 1629 // not marking weak pointers in this object in this GC. |
1592 template<typename T, typename U> | 1630 template<typename T, typename U> |
(...skipping 30 matching lines...) Expand all Loading... | |
1623 // FTT (key value pair) | 1661 // FTT (key value pair) |
1624 template<typename Key, typename Value, typename Traits> | 1662 template<typename Key, typename Value, typename Traits> |
1625 struct CollectionBackingTraceTrait<false, true, true, WTF::KeyValuePair<Key, Val ue>, Traits> : public BaseVisitKeyValuePairTrait<true, Key, Value, Traits> { | 1663 struct CollectionBackingTraceTrait<false, true, true, WTF::KeyValuePair<Key, Val ue>, Traits> : public BaseVisitKeyValuePairTrait<true, Key, Value, Traits> { |
1626 }; | 1664 }; |
1627 | 1665 |
1628 // TXX (key value pair) | 1666 // TXX (key value pair) |
1629 template<bool isWeak, bool markWeakMembersStrongly, typename Key, typename Value , typename Traits> | 1667 template<bool isWeak, bool markWeakMembersStrongly, typename Key, typename Value , typename Traits> |
1630 struct CollectionBackingTraceTrait<true, isWeak, markWeakMembersStrongly, WTF::K eyValuePair<Key, Value>, Traits> : public BaseVisitKeyValuePairTrait<markWeakMem bersStrongly, Key, Value, Traits> { | 1668 struct CollectionBackingTraceTrait<true, isWeak, markWeakMembersStrongly, WTF::K eyValuePair<Key, Value>, Traits> : public BaseVisitKeyValuePairTrait<markWeakMem bersStrongly, Key, Value, Traits> { |
1631 }; | 1669 }; |
1632 | 1670 |
1671 // FTT (list hash set node) | |
Mads Ager (chromium)
2014/04/03 09:24:35
The bools here are still blowing my mind. Can you
Erik Corry
2014/04/10 10:47:37
I've changed the markWeakMembersStrongly to an enu
| |
1672 template<typename Value, typename Traits> | |
1673 struct CollectionBackingTraceTrait<false, true, true, WTF::LinkedHashSetNode<Val ue>, Traits> : public BaseVisitLinkedNodeTrait<true, Value, Traits> { | |
1674 }; | |
1675 | |
1676 // TXX (list hash set node) | |
1677 template<bool isWeak, bool markWeakMembersStrongly, typename Value, typename Tra its> | |
1678 struct CollectionBackingTraceTrait<true, isWeak, markWeakMembersStrongly, WTF::L inkedHashSetNode<Value>, Traits> : public BaseVisitLinkedNodeTrait<markWeakMembe rsStrongly, Value, Traits> { | |
1679 }; | |
1680 | |
1633 // TFX (member) | 1681 // TFX (member) |
1634 template<bool markWeakMembersStrongly, typename T, typename Traits> | 1682 template<bool markWeakMembersStrongly, typename T, typename Traits> |
1635 struct CollectionBackingTraceTrait<true, false, markWeakMembersStrongly, Member< T>, Traits> { | 1683 struct CollectionBackingTraceTrait<true, false, markWeakMembersStrongly, Member< T>, Traits> { |
1636 static void mark(WebCore::Visitor* visitor, Member<T> self) | 1684 static void mark(WebCore::Visitor* visitor, Member<T> self) |
1637 { | 1685 { |
1638 visitor->mark(self.get()); | 1686 visitor->mark(self.get()); |
1639 } | 1687 } |
1640 }; | 1688 }; |
1641 | 1689 |
1642 // FTT (weak member) | 1690 // FTT (weak member) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1728 for (unsigned i = 0; i < length; i++) { | 1776 for (unsigned i = 0; i < length; i++) { |
1729 if (!Table::isEmptyOrDeletedBucket(table[i])) | 1777 if (!Table::isEmptyOrDeletedBucket(table[i])) |
1730 table[i].~Value(); | 1778 table[i].~Value(); |
1731 } | 1779 } |
1732 } | 1780 } |
1733 | 1781 |
1734 template<typename T, typename U, typename V, typename W, typename X> | 1782 template<typename T, typename U, typename V, typename W, typename X> |
1735 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T, U, V, W, X, HeapAllocator> > { }; | 1783 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T, U, V, W, X, HeapAllocator> > { }; |
1736 template<typename T, typename U, typename V> | 1784 template<typename T, typename U, typename V> |
1737 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { }; | 1785 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { }; |
1786 template<typename T, typename U, typename V> | |
1787 struct GCInfoTrait<HeapLinkedHashSet<T, U, V> > : public GCInfoTrait<LinkedHashS et<T, U, V, HeapAllocator> > { }; | |
1738 template<typename T, size_t inlineCapacity> | 1788 template<typename T, size_t inlineCapacity> |
1739 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T , inlineCapacity, HeapAllocator> > { }; | 1789 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T , inlineCapacity, HeapAllocator> > { }; |
1740 | 1790 |
1741 template<typename T> | 1791 template<typename T> |
1742 struct IfWeakMember; | 1792 struct IfWeakMember; |
1743 | 1793 |
1744 template<typename T> | 1794 template<typename T> |
1745 struct IfWeakMember { | 1795 struct IfWeakMember { |
1746 template<typename U> | 1796 template<typename U> |
1747 static bool isDead(Visitor*, const U&) { return false; } | 1797 static bool isDead(Visitor*, const U&) { return false; } |
1748 }; | 1798 }; |
1749 | 1799 |
1750 template<typename T> | 1800 template<typename T> |
1751 struct IfWeakMember<WeakMember<T> > { | 1801 struct IfWeakMember<WeakMember<T> > { |
1752 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } | 1802 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } |
1753 }; | 1803 }; |
1754 | 1804 |
1755 #if COMPILER(CLANG) | 1805 #if COMPILER(CLANG) |
1756 // Clang does not export the symbols that we have explicitly asked it | 1806 // Clang does not export the symbols that we have explicitly asked it |
1757 // to export. This forces it to export all the methods from ThreadHeap. | 1807 // to export. This forces it to export all the methods from ThreadHeap. |
1758 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); | 1808 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); |
1759 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1809 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
1760 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1810 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
1761 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; | 1811 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; |
1762 #endif | 1812 #endif |
1763 | 1813 |
1764 } | 1814 } |
1765 | 1815 |
1766 #endif // Heap_h | 1816 #endif // Heap_h |
OLD | NEW |