| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 private: | 214 private: |
| 215 friend class Heap; | 215 friend class Heap; |
| 216 friend class ThreadHeap<Header>; | 216 friend class ThreadHeap<Header>; |
| 217 | 217 |
| 218 LargeHeapObject<Header>* m_next; | 218 LargeHeapObject<Header>* m_next; |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 // The BasicObjectHeader is the minimal object header. It is used when | 221 // The BasicObjectHeader is the minimal object header. It is used when |
| 222 // encountering heap space of size allocationGranularity to mark it as | 222 // encountering heap space of size allocationGranularity to mark it as |
| 223 // as freelist entry. | 223 // as freelist entry. |
| 224 class BasicObjectHeader { | 224 class HEAP_EXPORT BasicObjectHeader { |
| 225 public: | 225 public: |
| 226 NO_SANITIZE_ADDRESS | 226 NO_SANITIZE_ADDRESS |
| 227 explicit BasicObjectHeader(size_t encodedSize) | 227 explicit BasicObjectHeader(size_t encodedSize) |
| 228 : m_size(encodedSize) { } | 228 : m_size(encodedSize) { } |
| 229 | 229 |
| 230 static size_t freeListEncodedSize(size_t size) { return size | freeListMask;
} | 230 static size_t freeListEncodedSize(size_t size) { return size | freeListMask;
} |
| 231 | 231 |
| 232 NO_SANITIZE_ADDRESS | 232 NO_SANITIZE_ADDRESS |
| 233 bool isFree() { return m_size & freeListMask; } | 233 bool isFree() { return m_size & freeListMask; } |
| 234 | 234 |
| 235 NO_SANITIZE_ADDRESS | 235 NO_SANITIZE_ADDRESS |
| 236 size_t size() const { return m_size & sizeMask; } | 236 size_t size() const { return m_size & sizeMask; } |
| 237 | 237 |
| 238 protected: | 238 protected: |
| 239 size_t m_size; | 239 size_t m_size; |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 // Our heap object layout is layered with the HeapObjectHeader closest | 242 // Our heap object layout is layered with the HeapObjectHeader closest |
| 243 // to the payload, this can be wrapped in a FinalizedObjectHeader if the | 243 // to the payload, this can be wrapped in a FinalizedObjectHeader if the |
| 244 // object is on the GeneralHeap and not on a specific TypedHeap. | 244 // object is on the GeneralHeap and not on a specific TypedHeap. |
| 245 // Finally if the object is a large object (> blinkPageSize/2) then it is | 245 // Finally if the object is a large object (> blinkPageSize/2) then it is |
| 246 // wrapped with a LargeObjectHeader. | 246 // wrapped with a LargeObjectHeader. |
| 247 // | 247 // |
| 248 // Object memory layout: | 248 // Object memory layout: |
| 249 // [ LargeObjectHeader | ] [ FinalizedObjectHeader | ] HeapObjectHeader | payloa
d | 249 // [ LargeObjectHeader | ] [ FinalizedObjectHeader | ] HeapObjectHeader | payloa
d |
| 250 // The [ ] notation denotes that the LargeObjectHeader and the FinalizedObjectHe
ader | 250 // The [ ] notation denotes that the LargeObjectHeader and the FinalizedObjectHe
ader |
| 251 // are independently optional. | 251 // are independently optional. |
| 252 class HeapObjectHeader : public BasicObjectHeader { | 252 class HEAP_EXPORT HeapObjectHeader : public BasicObjectHeader { |
| 253 public: | 253 public: |
| 254 NO_SANITIZE_ADDRESS | 254 NO_SANITIZE_ADDRESS |
| 255 explicit HeapObjectHeader(size_t encodedSize) | 255 explicit HeapObjectHeader(size_t encodedSize) |
| 256 : BasicObjectHeader(encodedSize) | 256 : BasicObjectHeader(encodedSize) |
| 257 #ifndef NDEBUG | 257 #ifndef NDEBUG |
| 258 , m_magic(magic) | 258 , m_magic(magic) |
| 259 #endif | 259 #endif |
| 260 { } | 260 { } |
| 261 | 261 |
| 262 NO_SANITIZE_ADDRESS | 262 NO_SANITIZE_ADDRESS |
| (...skipping 17 matching lines...) Expand all Loading... |
| 280 inline void setDebugMark(); | 280 inline void setDebugMark(); |
| 281 inline void clearDebugMark(); | 281 inline void clearDebugMark(); |
| 282 inline bool hasDebugMark() const; | 282 inline bool hasDebugMark() const; |
| 283 | 283 |
| 284 // Zap magic number with a new magic number that means there was once an | 284 // Zap magic number with a new magic number that means there was once an |
| 285 // object allocated here, but it was freed because nobody marked it during | 285 // object allocated here, but it was freed because nobody marked it during |
| 286 // GC. | 286 // GC. |
| 287 void zapMagic(); | 287 void zapMagic(); |
| 288 | 288 |
| 289 static void finalize(const GCInfo*, Address, size_t); | 289 static void finalize(const GCInfo*, Address, size_t); |
| 290 HEAP_EXPORT static HeapObjectHeader* fromPayload(const void*); | 290 static HeapObjectHeader* fromPayload(const void*); |
| 291 | 291 |
| 292 static const intptr_t magic = 0xc0de247; | 292 static const intptr_t magic = 0xc0de247; |
| 293 static const intptr_t zappedMagic = 0xC0DEdead; | 293 static const intptr_t zappedMagic = 0xC0DEdead; |
| 294 // The zap value for vtables should be < 4K to ensure it cannot be | 294 // The zap value for vtables should be < 4K to ensure it cannot be |
| 295 // used for dispatch. | 295 // used for dispatch. |
| 296 static const intptr_t zappedVTable = 0xd0d; | 296 static const intptr_t zappedVTable = 0xd0d; |
| 297 | 297 |
| 298 private: | 298 private: |
| 299 #ifndef NDEBUG | 299 #ifndef NDEBUG |
| 300 intptr_t m_magic; | 300 intptr_t m_magic; |
| 301 #endif | 301 #endif |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 const size_t objectHeaderSize = sizeof(HeapObjectHeader); | 304 const size_t objectHeaderSize = sizeof(HeapObjectHeader); |
| 305 | 305 |
| 306 // Each object on the GeneralHeap needs to carry a pointer to its | 306 // Each object on the GeneralHeap needs to carry a pointer to its |
| 307 // own GCInfo structure for tracing and potential finalization. | 307 // own GCInfo structure for tracing and potential finalization. |
| 308 class FinalizedHeapObjectHeader : public HeapObjectHeader { | 308 class HEAP_EXPORT FinalizedHeapObjectHeader : public HeapObjectHeader { |
| 309 public: | 309 public: |
| 310 NO_SANITIZE_ADDRESS | 310 NO_SANITIZE_ADDRESS |
| 311 FinalizedHeapObjectHeader(size_t encodedSize, const GCInfo* gcInfo) | 311 FinalizedHeapObjectHeader(size_t encodedSize, const GCInfo* gcInfo) |
| 312 : HeapObjectHeader(encodedSize) | 312 : HeapObjectHeader(encodedSize) |
| 313 , m_gcInfo(gcInfo) | 313 , m_gcInfo(gcInfo) |
| 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 TraceCallback traceCallback() { return m_gcInfo->m_trace; } | 324 TraceCallback traceCallback() { return m_gcInfo->m_trace; } |
| 325 | 325 |
| 326 void finalize(); | 326 void finalize(); |
| 327 | 327 |
| 328 NO_SANITIZE_ADDRESS | 328 NO_SANITIZE_ADDRESS |
| 329 inline bool hasFinalizer() { return m_gcInfo->hasFinalizer(); } | 329 inline bool hasFinalizer() { return m_gcInfo->hasFinalizer(); } |
| 330 | 330 |
| 331 HEAP_EXPORT static FinalizedHeapObjectHeader* fromPayload(const void*); | 331 static FinalizedHeapObjectHeader* fromPayload(const void*); |
| 332 | 332 |
| 333 private: | 333 private: |
| 334 const GCInfo* m_gcInfo; | 334 const GCInfo* m_gcInfo; |
| 335 }; | 335 }; |
| 336 | 336 |
| 337 const size_t finalizedHeaderSize = sizeof(FinalizedHeapObjectHeader); | 337 const size_t finalizedHeaderSize = sizeof(FinalizedHeapObjectHeader); |
| 338 | 338 |
| 339 class FreeListEntry : public HeapObjectHeader { | 339 class FreeListEntry : public HeapObjectHeader { |
| 340 public: | 340 public: |
| 341 NO_SANITIZE_ADDRESS | 341 NO_SANITIZE_ADDRESS |
| (...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 // 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. |
| 1683 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); | 1683 template<> void ThreadHeap<FinalizedHeapObjectHeader>::addPageToHeap(const GCInf
o*); |
| 1684 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); | 1684 template<> void ThreadHeap<HeapObjectHeader>::addPageToHeap(const GCInfo*); |
| 1685 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; | 1685 extern template class HEAP_EXPORT ThreadHeap<FinalizedHeapObjectHeader>; |
| 1686 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; | 1686 extern template class HEAP_EXPORT ThreadHeap<HeapObjectHeader>; |
| 1687 #endif | 1687 #endif |
| 1688 | 1688 |
| 1689 } | 1689 } |
| 1690 | 1690 |
| 1691 #endif // Heap_h | 1691 #endif // Heap_h |
| OLD | NEW |