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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 { | 314 { |
315 } | 315 } |
316 | 316 |
317 inline Address payload(); | 317 inline Address payload(); |
318 inline size_t payloadSize(); | 318 inline size_t payloadSize(); |
319 | 319 |
320 NO_SANITIZE_ADDRESS | 320 NO_SANITIZE_ADDRESS |
321 const GCInfo* gcInfo() { return m_gcInfo; } | 321 const GCInfo* gcInfo() { return m_gcInfo; } |
322 | 322 |
323 NO_SANITIZE_ADDRESS | 323 NO_SANITIZE_ADDRESS |
324 const char* typeMarker() { return m_gcInfo->m_typeMarker; } | |
325 | |
326 NO_SANITIZE_ADDRESS | |
327 TraceCallback traceCallback() { return m_gcInfo->m_trace; } | 324 TraceCallback traceCallback() { return m_gcInfo->m_trace; } |
328 | 325 |
329 void finalize(); | 326 void finalize(); |
330 | 327 |
331 NO_SANITIZE_ADDRESS | 328 NO_SANITIZE_ADDRESS |
332 inline bool hasFinalizer() { return m_gcInfo->hasFinalizer(); } | 329 inline bool hasFinalizer() { return m_gcInfo->hasFinalizer(); } |
333 | 330 |
334 HEAP_EXPORT static FinalizedHeapObjectHeader* fromPayload(const void*); | 331 HEAP_EXPORT static FinalizedHeapObjectHeader* fromPayload(const void*); |
335 | 332 |
336 private: | 333 private: |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 // specialization of GCInfoTrait for these three classes here. | 1396 // specialization of GCInfoTrait for these three classes here. |
1400 | 1397 |
1401 template<typename Key, typename Value, typename T, typename U, typename V> | 1398 template<typename Key, typename Value, typename T, typename U, typename V> |
1402 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { | 1399 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { |
1403 static const GCInfo* get() { return &info; } | 1400 static const GCInfo* get() { return &info; } |
1404 static const GCInfo info; | 1401 static const GCInfo info; |
1405 }; | 1402 }; |
1406 | 1403 |
1407 template<typename Key, typename Value, typename T, typename U, typename V> | 1404 template<typename Key, typename Value, typename T, typename U, typename V> |
1408 const GCInfo GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::info = { | 1405 const GCInfo GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::info = { |
1409 "HashMap", | |
1410 TraceTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::trace, | 1406 TraceTrait<HashMap<Key, Value, T, U, V, HeapAllocator> >::trace, |
1411 0, | 1407 0, |
1412 false, // HashMap needs no finalizer. | 1408 false, // HashMap needs no finalizer. |
1413 }; | 1409 }; |
1414 | 1410 |
1415 template<typename T, typename U, typename V> | 1411 template<typename T, typename U, typename V> |
1416 struct GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { | 1412 struct GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { |
1417 static const GCInfo* get() { return &info; } | 1413 static const GCInfo* get() { return &info; } |
1418 static const GCInfo info; | 1414 static const GCInfo info; |
1419 }; | 1415 }; |
1420 | 1416 |
1421 template<typename T, typename U, typename V> | 1417 template<typename T, typename U, typename V> |
1422 const GCInfo GCInfoTrait<HashSet<T, U, V, HeapAllocator> >::info = { | 1418 const GCInfo GCInfoTrait<HashSet<T, U, V, HeapAllocator> >::info = { |
1423 "HashSet", | |
1424 TraceTrait<HashSet<T, U, V, HeapAllocator> >::trace, | 1419 TraceTrait<HashSet<T, U, V, HeapAllocator> >::trace, |
1425 0, | 1420 0, |
1426 false, // HashSet needs no finalizer. | 1421 false, // HashSet needs no finalizer. |
1427 }; | 1422 }; |
1428 | 1423 |
1429 template<typename T> | 1424 template<typename T> |
1430 struct GCInfoTrait<Vector<T, 0, HeapAllocator> > { | 1425 struct GCInfoTrait<Vector<T, 0, HeapAllocator> > { |
1431 static const GCInfo* get() { return &info; } | 1426 static const GCInfo* get() { return &info; } |
1432 static const GCInfo info; | 1427 static const GCInfo info; |
1433 }; | 1428 }; |
1434 | 1429 |
1435 template<typename T> | 1430 template<typename T> |
1436 const GCInfo GCInfoTrait<Vector<T, 0, HeapAllocator> >::info = { | 1431 const GCInfo GCInfoTrait<Vector<T, 0, HeapAllocator> >::info = { |
1437 "Vector", | |
1438 TraceTrait<Vector<T, 0, HeapAllocator> >::trace, | 1432 TraceTrait<Vector<T, 0, HeapAllocator> >::trace, |
1439 0, | 1433 0, |
1440 false, // Vector needs no finalizer if it has no inline capacity. | 1434 false, // Vector needs no finalizer if it has no inline capacity. |
1441 }; | 1435 }; |
1442 | 1436 |
1443 template<typename T, size_t inlineCapacity> | 1437 template<typename T, size_t inlineCapacity> |
1444 struct GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> > { | 1438 struct GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> > { |
1445 static const GCInfo* get() { return &info; } | 1439 static const GCInfo* get() { return &info; } |
1446 static const GCInfo info; | 1440 static const GCInfo info; |
1447 }; | 1441 }; |
1448 | 1442 |
1449 template<typename T, size_t inlineCapacity> | 1443 template<typename T, size_t inlineCapacity> |
1450 struct FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> > : public Finali
zerTraitImpl<Vector<T, inlineCapacity, HeapAllocator>, true> { }; | 1444 struct FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> > : public Finali
zerTraitImpl<Vector<T, inlineCapacity, HeapAllocator>, true> { }; |
1451 | 1445 |
1452 template<typename T, size_t inlineCapacity> | 1446 template<typename T, size_t inlineCapacity> |
1453 const GCInfo GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> >::info = { | 1447 const GCInfo GCInfoTrait<Vector<T, inlineCapacity, HeapAllocator> >::info = { |
1454 "Vector", | |
1455 TraceTrait<Vector<T, inlineCapacity, HeapAllocator> >::trace, | 1448 TraceTrait<Vector<T, inlineCapacity, HeapAllocator> >::trace, |
1456 FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> >::finalize, | 1449 FinalizerTrait<Vector<T, inlineCapacity, HeapAllocator> >::finalize, |
1457 // Finalizer is needed to destruct things stored in the inline capacity. | 1450 // Finalizer is needed to destruct things stored in the inline capacity. |
1458 inlineCapacity && VectorTraits<T>::needsDestruction, | 1451 inlineCapacity && VectorTraits<T>::needsDestruction, |
1459 }; | 1452 }; |
1460 | 1453 |
1461 template<typename T, typename Traits> | 1454 template<typename T, typename Traits> |
1462 struct GCInfoTrait<HeapVectorBacking<T, Traits> > { | 1455 struct GCInfoTrait<HeapVectorBacking<T, Traits> > { |
1463 static const GCInfo* get() { return &info; } | 1456 static const GCInfo* get() { return &info; } |
1464 static const GCInfo info; | 1457 static const GCInfo info; |
1465 }; | 1458 }; |
1466 | 1459 |
1467 template<typename T, typename Traits> | 1460 template<typename T, typename Traits> |
1468 const GCInfo GCInfoTrait<HeapVectorBacking<T, Traits> >::info = { | 1461 const GCInfo GCInfoTrait<HeapVectorBacking<T, Traits> >::info = { |
1469 "VectorBacking", | |
1470 TraceTrait<HeapVectorBacking<T, Traits> >::trace, | 1462 TraceTrait<HeapVectorBacking<T, Traits> >::trace, |
1471 FinalizerTrait<HeapVectorBacking<T, Traits> >::finalize, | 1463 FinalizerTrait<HeapVectorBacking<T, Traits> >::finalize, |
1472 Traits::needsDestruction, | 1464 Traits::needsDestruction, |
1473 }; | 1465 }; |
1474 | 1466 |
1475 template<typename T, typename U, typename V, typename W, typename X> | 1467 template<typename T, typename U, typename V, typename W, typename X> |
1476 struct GCInfoTrait<HeapHashTableBacking<T, U, V, W, X> > { | 1468 struct GCInfoTrait<HeapHashTableBacking<T, U, V, W, X> > { |
1477 static const GCInfo* get() { return &info; } | 1469 static const GCInfo* get() { return &info; } |
1478 static const GCInfo info; | 1470 static const GCInfo info; |
1479 }; | 1471 }; |
1480 | 1472 |
1481 template<typename T, typename U, typename V, typename Traits, typename W> | 1473 template<typename T, typename U, typename V, typename Traits, typename W> |
1482 const GCInfo GCInfoTrait<HeapHashTableBacking<T, U, V, Traits, W> >::info = { | 1474 const GCInfo GCInfoTrait<HeapHashTableBacking<T, U, V, Traits, W> >::info = { |
1483 "HashTableBacking", | |
1484 TraceTrait<HeapHashTableBacking<T, U, V, Traits, W> >::trace, | 1475 TraceTrait<HeapHashTableBacking<T, U, V, Traits, W> >::trace, |
1485 FinalizerTrait<HeapHashTableBacking<T, U, V, Traits, W> >::finalize, | 1476 FinalizerTrait<HeapHashTableBacking<T, U, V, Traits, W> >::finalize, |
1486 Traits::needsDestruction, | 1477 Traits::needsDestruction, |
1487 }; | 1478 }; |
1488 | 1479 |
1489 template<bool markWeakMembersStrongly, typename T, typename Traits> | 1480 template<bool markWeakMembersStrongly, typename T, typename Traits> |
1490 struct BaseVisitVectorBackingTrait { | 1481 struct BaseVisitVectorBackingTrait { |
1491 static void mark(WebCore::Visitor* visitor, void* self) | 1482 static void mark(WebCore::Visitor* visitor, void* self) |
1492 { | 1483 { |
1493 // The allocator can oversize the allocation a little, according to | 1484 // The allocator can oversize the allocation a little, according to |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 static void trace(WebCore::Visitor* visitor, void* self) | 1612 static void trace(WebCore::Visitor* visitor, void* self) |
1622 { | 1613 { |
1623 COMPILE_ASSERT(!Traits::isWeak, WeDontSupportWeaknessInHeapVectors); | 1614 COMPILE_ASSERT(!Traits::isWeak, WeDontSupportWeaknessInHeapVectors); |
1624 if (WTF::ShouldBeTraced<Traits>::value) | 1615 if (WTF::ShouldBeTraced<Traits>::value) |
1625 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, fals
e, false, HeapVectorBacking<T, Traits>, void>::mark(visitor, self); | 1616 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, fals
e, false, HeapVectorBacking<T, Traits>, void>::mark(visitor, self); |
1626 } | 1617 } |
1627 static void mark(Visitor* visitor, const Backing* backing) | 1618 static void mark(Visitor* visitor, const Backing* backing) |
1628 { | 1619 { |
1629 visitor->mark(backing, &trace); | 1620 visitor->mark(backing, &trace); |
1630 } | 1621 } |
1631 static void checkTypeMarker(Visitor* visitor, const Backing* backing) | 1622 static void checkGCInfo(Visitor* visitor, const Backing* backing) |
1632 { | 1623 { |
1633 #ifndef NDEBUG | 1624 #ifndef NDEBUG |
1634 visitor->checkTypeMarker(const_cast<Backing*>(backing), getTypeMarker<Ba
cking>()); | 1625 visitor->checkGCInfo(const_cast<Backing*>(backing), GCInfoTrait<Backing>
::get()); |
1635 #endif | 1626 #endif |
1636 } | 1627 } |
1637 }; | 1628 }; |
1638 | 1629 |
1639 // The trace trait for the heap hashtable backing is used when we find a | 1630 // The trace trait for the heap hashtable backing is used when we find a |
1640 // direct pointer to the backing from the conservative stack scanner. This | 1631 // direct pointer to the backing from the conservative stack scanner. This |
1641 // normally indicates that there is an ongoing iteration over the table, and so | 1632 // normally indicates that there is an ongoing iteration over the table, and so |
1642 // we disable weak processing of table entries. When the backing is found | 1633 // we disable weak processing of table entries. When the backing is found |
1643 // through the owning hash table we mark differently, in order to do weak | 1634 // through the owning hash table we mark differently, in order to do weak |
1644 // processing. | 1635 // processing. |
1645 template<typename Key, typename Value, typename Extractor, typename Traits, type
name KeyTraits> | 1636 template<typename Key, typename Value, typename Extractor, typename Traits, type
name KeyTraits> |
1646 struct TraceTrait<HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTraits>
> { | 1637 struct TraceTrait<HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTraits>
> { |
1647 typedef HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTraits> Backi
ng; | 1638 typedef HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTraits> Backi
ng; |
1648 static void trace(WebCore::Visitor* visitor, void* self) | 1639 static void trace(WebCore::Visitor* visitor, void* self) |
1649 { | 1640 { |
1650 if (WTF::ShouldBeTraced<Traits>::value || Traits::isWeak) | 1641 if (WTF::ShouldBeTraced<Traits>::value || Traits::isWeak) |
1651 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Trai
ts::isWeak, true, HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTraits>
, void>::mark(visitor, self); | 1642 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Trai
ts::isWeak, true, HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTraits>
, void>::mark(visitor, self); |
1652 } | 1643 } |
1653 static void mark(Visitor* visitor, const Backing* backing) | 1644 static void mark(Visitor* visitor, const Backing* backing) |
1654 { | 1645 { |
1655 if (WTF::ShouldBeTraced<Traits>::value || Traits::isWeak) | 1646 if (WTF::ShouldBeTraced<Traits>::value || Traits::isWeak) |
1656 visitor->mark(backing, &trace); | 1647 visitor->mark(backing, &trace); |
1657 else | 1648 else |
1658 visitor->mark(backing, 0); | 1649 visitor->mark(backing, 0); |
1659 } | 1650 } |
1660 static void checkTypeMarker(Visitor* visitor, const Backing* backing) | 1651 static void checkGCInfo(Visitor* visitor, const Backing* backing) |
1661 { | 1652 { |
1662 #ifndef NDEBUG | 1653 #ifndef NDEBUG |
1663 visitor->checkTypeMarker(const_cast<Backing*>(backing), getTypeMarker<Ba
cking>()); | 1654 visitor->checkGCInfo(const_cast<Backing*>(backing), GCInfoTrait<Backing>
::get()); |
1664 #endif | 1655 #endif |
1665 } | 1656 } |
1666 }; | 1657 }; |
1667 | 1658 |
1668 template<typename T, typename U, typename V, typename W, typename X> | 1659 template<typename T, typename U, typename V, typename W, typename X> |
1669 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T,
U, V, W, X, HeapAllocator> > { }; | 1660 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T,
U, V, W, X, HeapAllocator> > { }; |
1670 template<typename T, typename U, typename V> | 1661 template<typename T, typename U, typename V> |
1671 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V,
HeapAllocator> > { }; | 1662 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V,
HeapAllocator> > { }; |
1672 template<typename T, size_t inlineCapacity> | 1663 template<typename T, size_t inlineCapacity> |
1673 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T
, inlineCapacity, HeapAllocator> > { }; | 1664 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T
, inlineCapacity, HeapAllocator> > { }; |
(...skipping 17 matching lines...) Expand all Loading... |
1691 // to export. This forces it to export all the methods from ThreadHeap. | 1682 // to export. This forces it to export all the methods from ThreadHeap. |
1692 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); | 1683 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); |
1693 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1684 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
1694 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1685 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
1695 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; | 1686 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; |
1696 #endif | 1687 #endif |
1697 | 1688 |
1698 } | 1689 } |
1699 | 1690 |
1700 #endif // Heap_h | 1691 #endif // Heap_h |
OLD | NEW |