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 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 | 1494 |
1495 if (UNLIKELY(isUrgentGCRequested())) | 1495 if (UNLIKELY(isUrgentGCRequested())) |
1496 return; | 1496 return; |
1497 | 1497 |
1498 size_t externalBytesAliveAtLastGC = externallyAllocatedBytesAlive(); | 1498 size_t externalBytesAliveAtLastGC = externallyAllocatedBytesAlive(); |
1499 if (UNLIKELY(externalBytesAllocatedSinceLastGC > externalBytesAliveAtLastGC
/ 2)) | 1499 if (UNLIKELY(externalBytesAllocatedSinceLastGC > externalBytesAliveAtLastGC
/ 2)) |
1500 Heap::requestUrgentGC(); | 1500 Heap::requestUrgentGC(); |
1501 } | 1501 } |
1502 | 1502 |
1503 template<bool needsTracing, WTF::WeakHandlingFlag weakHandlingFlag, WTF::ShouldW
eakPointersBeMarkedStrongly strongify, typename T, typename Traits> struct Colle
ctionBackingTraceTrait; | 1503 template<bool needsTracing, WTF::WeakHandlingFlag weakHandlingFlag, WTF::ShouldW
eakPointersBeMarkedStrongly strongify, typename T, typename Traits> struct Colle
ctionBackingTraceTrait; |
1504 template<typename T, typename Traits = WTF::VectorTraits<T>> class HeapVectorBac
king; | 1504 template<typename T, typename Traits = WTF::VectorTraits<T>> class HeapVectorBac
king { |
| 1505 public: |
| 1506 static void finalize(void* pointer); |
| 1507 void finalizeGarbageCollectedObject() { finalize(this); } |
| 1508 }; |
1505 template<typename Table> class HeapHashTableBacking { | 1509 template<typename Table> class HeapHashTableBacking { |
1506 public: | 1510 public: |
1507 static void finalize(void* pointer); | 1511 static void finalize(void* pointer); |
1508 void finalizeGarbageCollectedObject() { finalize(this); } | 1512 void finalizeGarbageCollectedObject() { finalize(this); } |
1509 }; | 1513 }; |
1510 | 1514 |
1511 class HeapAllocatorQuantizer { | 1515 class HeapAllocatorQuantizer { |
1512 public: | 1516 public: |
1513 template<typename T> | 1517 template<typename T> |
1514 static size_t quantizedSize(size_t count) | 1518 static size_t quantizedSize(size_t count) |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 visitor->markNoTracing(backing); // If we know the trace function wi
ll do nothing there is no need to call it. | 2208 visitor->markNoTracing(backing); // If we know the trace function wi
ll do nothing there is no need to call it. |
2205 } | 2209 } |
2206 static void checkGCInfo(Visitor* visitor, const Backing* backing) | 2210 static void checkGCInfo(Visitor* visitor, const Backing* backing) |
2207 { | 2211 { |
2208 #if ENABLE(ASSERT) | 2212 #if ENABLE(ASSERT) |
2209 assertObjectHasGCInfo(const_cast<Backing*>(backing), GCInfoTrait<Backing
>::index()); | 2213 assertObjectHasGCInfo(const_cast<Backing*>(backing), GCInfoTrait<Backing
>::index()); |
2210 #endif | 2214 #endif |
2211 } | 2215 } |
2212 }; | 2216 }; |
2213 | 2217 |
| 2218 template<typename T, typename Traits> |
| 2219 void HeapVectorBacking<T, Traits>::finalize(void* pointer) |
| 2220 { |
| 2221 ASSERT(!WTF::IsTriviallyDestructible<T>::value); |
| 2222 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
| 2223 // Use the payload size as recorded by the heap to determine how many |
| 2224 // elements to finalize. |
| 2225 size_t length = header->payloadSize() / sizeof(T); |
| 2226 T* array = reinterpret_cast<T*>(pointer); |
| 2227 for (unsigned i = 0; i < length; ++i) { |
| 2228 array[i].~T(); |
| 2229 } |
| 2230 } |
| 2231 |
2214 template<typename Table> | 2232 template<typename Table> |
2215 void HeapHashTableBacking<Table>::finalize(void* pointer) | 2233 void HeapHashTableBacking<Table>::finalize(void* pointer) |
2216 { | 2234 { |
2217 using Value = typename Table::ValueType; | 2235 using Value = typename Table::ValueType; |
2218 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); | 2236 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); |
2219 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 2237 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
2220 // Use the payload size as recorded by the heap to determine how many | 2238 // Use the payload size as recorded by the heap to determine how many |
2221 // elements to finalize. | 2239 // elements to finalize. |
2222 size_t length = header->payloadSize() / sizeof(Value); | 2240 size_t length = header->payloadSize() / sizeof(Value); |
2223 Value* table = reinterpret_cast<Value*>(pointer); | 2241 Value* table = reinterpret_cast<Value*>(pointer); |
2224 for (unsigned i = 0; i < length; ++i) { | 2242 for (unsigned i = 0; i < length; ++i) { |
2225 if (!Table::isEmptyOrDeletedBucket(table[i])) | 2243 if (!Table::isEmptyOrDeletedBucket(table[i])) |
2226 table[i].~Value(); | 2244 table[i].~Value(); |
2227 } | 2245 } |
2228 } | 2246 } |
2229 | 2247 |
2230 } // namespace blink | 2248 } // namespace blink |
2231 | 2249 |
2232 #endif // Heap_h | 2250 #endif // Heap_h |
OLD | NEW |