Chromium Code Reviews| 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 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1406 } | 1406 } |
| 1407 | 1407 |
| 1408 template<typename U, size_t otherCapacity> | 1408 template<typename U, size_t otherCapacity> |
| 1409 void appendVector(const HeapVector<U, otherCapacity>& other) | 1409 void appendVector(const HeapVector<U, otherCapacity>& other) |
| 1410 { | 1410 { |
| 1411 const Vector<U, otherCapacity, HeapAllocator>& otherVector = other; | 1411 const Vector<U, otherCapacity, HeapAllocator>& otherVector = other; |
| 1412 Vector<T, inlineCapacity, HeapAllocator>::appendVector(otherVector); | 1412 Vector<T, inlineCapacity, HeapAllocator>::appendVector(otherVector); |
| 1413 } | 1413 } |
| 1414 }; | 1414 }; |
| 1415 | 1415 |
| 1416 template<typename T, size_t inlineCapacity = 0> | |
| 1417 class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { | |
| 1418 public: | |
| 1419 HeapDeque() { } | |
| 1420 | |
| 1421 explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(si ze) | |
| 1422 { | |
| 1423 } | |
| 1424 | |
| 1425 HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocato r>(size, val) | |
| 1426 { | |
| 1427 } | |
| 1428 | |
| 1429 HeapDeque<T, 0>& operator=(const HeapDeque& other) | |
| 1430 { | |
| 1431 HeapDeque<T> copy(other); | |
| 1432 swap(copy); | |
| 1433 return *this; | |
| 1434 } | |
| 1435 | |
| 1436 inline void swap(HeapDeque& other) | |
| 1437 { | |
| 1438 Deque<T, inlineCapacity, HeapAllocator>::swap(other); | |
|
wibling-chromium
2014/04/08 10:49:40
NIT: Consider adding a comment about this only wor
Erik Corry
2014/04/08 11:48:53
Done.
| |
| 1439 } | |
| 1440 | |
| 1441 template<size_t otherCapacity> | |
| 1442 HeapDeque(const HeapDeque<T, otherCapacity>& other) | |
| 1443 : Deque<T, inlineCapacity, HeapAllocator>(other) | |
| 1444 { | |
| 1445 } | |
| 1446 | |
| 1447 template<typename U> | |
| 1448 void append(const U& other) | |
| 1449 { | |
| 1450 Deque<T, inlineCapacity, HeapAllocator>::append(other); | |
| 1451 } | |
| 1452 }; | |
| 1453 | |
| 1416 template<typename T> | 1454 template<typename T> |
| 1417 struct ThreadingTrait<Member<T> > { | 1455 struct ThreadingTrait<Member<T> > { |
| 1418 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1456 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1419 }; | 1457 }; |
| 1420 | 1458 |
| 1421 template<typename T> | 1459 template<typename T> |
| 1422 struct ThreadingTrait<WeakMember<T> > { | 1460 struct ThreadingTrait<WeakMember<T> > { |
| 1423 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1461 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1424 }; | 1462 }; |
| 1425 | 1463 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1446 template<typename T, size_t inlineCapacity> | 1484 template<typename T, size_t inlineCapacity> |
| 1447 struct ThreadingTrait<Vector<T, inlineCapacity, HeapAllocator> > { | 1485 struct ThreadingTrait<Vector<T, inlineCapacity, HeapAllocator> > { |
| 1448 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1486 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1449 }; | 1487 }; |
| 1450 | 1488 |
| 1451 template<typename T, typename Traits> | 1489 template<typename T, typename Traits> |
| 1452 struct ThreadingTrait<HeapVectorBacking<T, Traits> > { | 1490 struct ThreadingTrait<HeapVectorBacking<T, Traits> > { |
| 1453 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 1491 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 1454 }; | 1492 }; |
| 1455 | 1493 |
| 1494 template<typename T, size_t inlineCapacity> | |
| 1495 struct ThreadingTrait<Deque<T, inlineCapacity, HeapAllocator> > { | |
| 1496 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | |
| 1497 }; | |
| 1498 | |
| 1456 template<typename Table> | 1499 template<typename Table> |
| 1457 struct ThreadingTrait<HeapHashTableBacking<Table> > { | 1500 struct ThreadingTrait<HeapHashTableBacking<Table> > { |
| 1458 typedef typename Table::KeyType Key; | 1501 typedef typename Table::KeyType Key; |
| 1459 typedef typename Table::ValueType Value; | 1502 typedef typename Table::ValueType Value; |
| 1460 static const ThreadAffinity Affinity = | 1503 static const ThreadAffinity Affinity = |
| 1461 (ThreadingTrait<Key>::Affinity == MainThreadOnly) | 1504 (ThreadingTrait<Key>::Affinity == MainThreadOnly) |
| 1462 && (ThreadingTrait<Value>::Affinity == MainThreadOnly) ? MainThreadOnly : AnyThread; | 1505 && (ThreadingTrait<Value>::Affinity == MainThreadOnly) ? MainThreadOnly : AnyThread; |
| 1463 }; | 1506 }; |
| 1464 | 1507 |
| 1465 template<typename T, typename U, typename V, typename W, typename X> | 1508 template<typename T, typename U, typename V, typename W, typename X> |
| 1466 struct ThreadingTrait<HeapHashMap<T, U, V, W, X> > : public ThreadingTrait<HashM ap<T, U, V, W, X, HeapAllocator> > { }; | 1509 struct ThreadingTrait<HeapHashMap<T, U, V, W, X> > : public ThreadingTrait<HashM ap<T, U, V, W, X, HeapAllocator> > { }; |
| 1467 | 1510 |
| 1468 template<typename T, typename U, typename V> | 1511 template<typename T, typename U, typename V> |
| 1469 struct ThreadingTrait<HeapHashSet<T, U, V> > : public ThreadingTrait<HashSet<T, U, V, HeapAllocator> > { }; | 1512 struct ThreadingTrait<HeapHashSet<T, U, V> > : public ThreadingTrait<HashSet<T, U, V, HeapAllocator> > { }; |
| 1470 | 1513 |
| 1471 template<typename T, size_t inlineCapacity> | 1514 template<typename T, size_t inlineCapacity> |
| 1472 struct ThreadingTrait<HeapVector<T, inlineCapacity> > : public ThreadingTrait<Ve ctor<T, inlineCapacity, HeapAllocator> > { }; | 1515 struct ThreadingTrait<HeapVector<T, inlineCapacity> > : public ThreadingTrait<Ve ctor<T, inlineCapacity, HeapAllocator> > { }; |
| 1473 | 1516 |
| 1517 template<typename T, size_t inlineCapacity> | |
| 1518 struct ThreadingTrait<HeapDeque<T, inlineCapacity> > : public ThreadingTrait<Deq ue<T, inlineCapacity, HeapAllocator> > { }; | |
| 1519 | |
| 1474 // The standard implementation of GCInfoTrait<T>::get() just returns a static | 1520 // The standard implementation of GCInfoTrait<T>::get() just returns a static |
| 1475 // from the class T, but we can't do that for HashMap, HashSet and Vector | 1521 // from the class T, but we can't do that for HashMap, HashSet, Deque and |
| 1476 // because they are in WTF and know nothing of GCInfos. Instead we have a | 1522 // Vector because they are in WTF and know nothing of GCInfos. Instead we have |
| 1477 // specialization of GCInfoTrait for these three classes here. | 1523 // a specialization of GCInfoTrait for these three classes here. |
| 1478 | 1524 |
| 1479 template<typename Key, typename Value, typename T, typename U, typename V> | 1525 template<typename Key, typename Value, typename T, typename U, typename V> |
| 1480 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { | 1526 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { |
| 1481 static const GCInfo* get() { return &info; } | 1527 static const GCInfo* get() { return &info; } |
| 1482 static const GCInfo info; | 1528 static const GCInfo info; |
| 1483 }; | 1529 }; |
| 1484 | 1530 |
| 1485 template<typename Key, typename Value, typename T, typename U, typename V> | 1531 template<typename Key, typename Value, typename T, typename U, typename V> |
| 1486 const GCInfo GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::info = { | 1532 const GCInfo GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::info = { |
| 1487 TraceTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::trace, | 1533 TraceTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::trace, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1525 struct FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> > : public Finali zerTraitImpl<Vector<T, inlineCapacity, HeapAllocator>, true> { }; | 1571 struct FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> > : public Finali zerTraitImpl<Vector<T, inlineCapacity, HeapAllocator>, true> { }; |
| 1526 | 1572 |
| 1527 template<typename T, size_t inlineCapacity> | 1573 template<typename T, size_t inlineCapacity> |
| 1528 const GCInfo GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> >::info = { | 1574 const GCInfo GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> >::info = { |
| 1529 TraceTrait<Vector<T, inlineCapacity, HeapAllocator> >::trace, | 1575 TraceTrait<Vector<T, inlineCapacity, HeapAllocator> >::trace, |
| 1530 FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> >::finalize, | 1576 FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> >::finalize, |
| 1531 // Finalizer is needed to destruct things stored in the inline capacity. | 1577 // Finalizer is needed to destruct things stored in the inline capacity. |
| 1532 inlineCapacity && VectorTraits<T>::needsDestruction, | 1578 inlineCapacity && VectorTraits<T>::needsDestruction, |
| 1533 }; | 1579 }; |
| 1534 | 1580 |
| 1581 template<typename T> | |
| 1582 struct GCInfoTrait<Deque<T, 0, HeapAllocator> > { | |
| 1583 static const GCInfo* get() { return &info; } | |
| 1584 static const GCInfo info; | |
| 1585 }; | |
| 1586 | |
| 1587 template<typename T> | |
| 1588 const GCInfo GCInfoTrait<Deque<T, 0, HeapAllocator> >::info = { | |
| 1589 TraceTrait<Deque<T, 0, HeapAllocator> >::trace, | |
| 1590 0, | |
| 1591 false, // Deque needs no finalizer if it has no inline capacity. | |
| 1592 }; | |
| 1593 | |
| 1594 template<typename T, size_t inlineCapacity> | |
| 1595 struct GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { | |
| 1596 static const GCInfo* get() { return &info; } | |
| 1597 static const GCInfo info; | |
| 1598 }; | |
| 1599 | |
| 1600 template<typename T, size_t inlineCapacity> | |
| 1601 struct FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator> > : public Finaliz erTraitImpl<Deque<T, inlineCapacity, HeapAllocator>, true> { }; | |
| 1602 | |
| 1603 template<typename T, size_t inlineCapacity> | |
| 1604 const GCInfo GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> >::info = { | |
| 1605 TraceTrait<Deque<T, inlineCapacity, HeapAllocator> >::trace, | |
| 1606 FinalizerTrait<Deque<T, inlineCapacity, HeapAllocator> >::finalize, | |
| 1607 // Finalizer is needed to destruct things stored in the inline capacity. | |
| 1608 inlineCapacity && VectorTraits<T>::needsDestruction, | |
| 1609 }; | |
| 1610 | |
| 1535 template<typename T, typename Traits> | 1611 template<typename T, typename Traits> |
| 1536 struct GCInfoTrait<HeapVectorBacking<T, Traits> > { | 1612 struct GCInfoTrait<HeapVectorBacking<T, Traits> > { |
| 1537 static const GCInfo* get() { return &info; } | 1613 static const GCInfo* get() { return &info; } |
| 1538 static const GCInfo info; | 1614 static const GCInfo info; |
| 1539 }; | 1615 }; |
| 1540 | 1616 |
| 1541 template<typename T, typename Traits> | 1617 template<typename T, typename Traits> |
| 1542 const GCInfo GCInfoTrait<HeapVectorBacking<T, Traits> >::info = { | 1618 const GCInfo GCInfoTrait<HeapVectorBacking<T, Traits> >::info = { |
| 1543 TraceTrait<HeapVectorBacking<T, Traits> >::trace, | 1619 TraceTrait<HeapVectorBacking<T, Traits> >::trace, |
| 1544 FinalizerTrait<HeapVectorBacking<T, Traits> >::finalize, | 1620 FinalizerTrait<HeapVectorBacking<T, Traits> >::finalize, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1687 { | 1763 { |
| 1688 TraceTrait<T>::trace(visitor, &t); | 1764 TraceTrait<T>::trace(visitor, &t); |
| 1689 } | 1765 } |
| 1690 }; | 1766 }; |
| 1691 | 1767 |
| 1692 template<typename T, typename Traits> | 1768 template<typename T, typename Traits> |
| 1693 struct TraceTrait<HeapVectorBacking<T, Traits> > { | 1769 struct TraceTrait<HeapVectorBacking<T, Traits> > { |
| 1694 typedef HeapVectorBacking<T, Traits> Backing; | 1770 typedef HeapVectorBacking<T, Traits> Backing; |
| 1695 static void trace(WebCore::Visitor* visitor, void* self) | 1771 static void trace(WebCore::Visitor* visitor, void* self) |
| 1696 { | 1772 { |
| 1697 COMPILE_ASSERT(!Traits::isWeak, WeDontSupportWeaknessInHeapVectors); | 1773 COMPILE_ASSERT(!Traits::isWeak, WeDontSupportWeaknessInHeapVectors); // We don't support it in HeapDeques either. |
|
Mads Ager (chromium)
2014/04/08 10:46:17
Put the comment on its own line above the COMPILE_
wibling-chromium
2014/04/08 10:49:40
WeDontSupportWeaknessInHeapVectorsOrDeques?
Erik Corry
2014/04/08 11:48:53
Done.
| |
| 1698 if (WTF::ShouldBeTraced<Traits>::value) | 1774 if (WTF::ShouldBeTraced<Traits>::value) |
| 1699 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, fals e, false, HeapVectorBacking<T, Traits>, void>::mark(visitor, self); | 1775 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, fals e, false, HeapVectorBacking<T, Traits>, void>::mark(visitor, self); |
| 1700 } | 1776 } |
| 1701 static void mark(Visitor* visitor, const Backing* backing) | 1777 static void mark(Visitor* visitor, const Backing* backing) |
| 1702 { | 1778 { |
| 1703 visitor->mark(backing, &trace); | 1779 visitor->mark(backing, &trace); |
| 1704 } | 1780 } |
| 1705 static void checkGCInfo(Visitor* visitor, const Backing* backing) | 1781 static void checkGCInfo(Visitor* visitor, const Backing* backing) |
| 1706 { | 1782 { |
| 1707 #ifndef NDEBUG | 1783 #ifndef NDEBUG |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1755 table[i].~Value(); | 1831 table[i].~Value(); |
| 1756 } | 1832 } |
| 1757 } | 1833 } |
| 1758 | 1834 |
| 1759 template<typename T, typename U, typename V, typename W, typename X> | 1835 template<typename T, typename U, typename V, typename W, typename X> |
| 1760 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T, U, V, W, X, HeapAllocator> > { }; | 1836 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T, U, V, W, X, HeapAllocator> > { }; |
| 1761 template<typename T, typename U, typename V> | 1837 template<typename T, typename U, typename V> |
| 1762 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { }; | 1838 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { }; |
| 1763 template<typename T, size_t inlineCapacity> | 1839 template<typename T, size_t inlineCapacity> |
| 1764 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T , inlineCapacity, HeapAllocator> > { }; | 1840 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T , inlineCapacity, HeapAllocator> > { }; |
| 1841 template<typename T, size_t inlineCapacity> | |
| 1842 struct GCInfoTrait<HeapDeque<T, inlineCapacity> > : public GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { }; | |
| 1765 | 1843 |
| 1766 template<typename T> | 1844 template<typename T> |
| 1767 struct IfWeakMember; | 1845 struct IfWeakMember; |
| 1768 | 1846 |
| 1769 template<typename T> | 1847 template<typename T> |
| 1770 struct IfWeakMember { | 1848 struct IfWeakMember { |
| 1771 template<typename U> | 1849 template<typename U> |
| 1772 static bool isDead(Visitor*, const U&) { return false; } | 1850 static bool isDead(Visitor*, const U&) { return false; } |
| 1773 }; | 1851 }; |
| 1774 | 1852 |
| 1775 template<typename T> | 1853 template<typename T> |
| 1776 struct IfWeakMember<WeakMember<T> > { | 1854 struct IfWeakMember<WeakMember<T> > { |
| 1777 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } | 1855 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } |
| 1778 }; | 1856 }; |
| 1779 | 1857 |
| 1780 #if COMPILER(CLANG) | 1858 #if COMPILER(CLANG) |
| 1781 // Clang does not export the symbols that we have explicitly asked it | 1859 // Clang does not export the symbols that we have explicitly asked it |
| 1782 // to export. This forces it to export all the methods from ThreadHeap. | 1860 // to export. This forces it to export all the methods from ThreadHeap. |
| 1783 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); | 1861 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf o*); |
| 1784 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1862 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
| 1785 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1863 extern template class PLATFORM_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
| 1786 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; | 1864 extern template class PLATFORM_EXPORT ThreadHeap<HeapObjectHeader>; |
| 1787 #endif | 1865 #endif |
| 1788 | 1866 |
| 1789 } | 1867 } |
| 1790 | 1868 |
| 1791 #endif // Heap_h | 1869 #endif // Heap_h |
| OLD | NEW |