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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 static_assert(nonLargeObjectPageSizeMax >= blinkPageSize, "max size supported by HeapObjectHeader must at least be blinkPageSize"); | 165 static_assert(nonLargeObjectPageSizeMax >= blinkPageSize, "max size supported by HeapObjectHeader must at least be blinkPageSize"); |
166 | 166 |
167 class PLATFORM_EXPORT HeapObjectHeader { | 167 class PLATFORM_EXPORT HeapObjectHeader { |
168 public: | 168 public: |
169 // If gcInfoIndex is 0, this header is interpreted as a free list header. | 169 // If gcInfoIndex is 0, this header is interpreted as a free list header. |
170 NO_SANITIZE_ADDRESS | 170 NO_SANITIZE_ADDRESS |
171 HeapObjectHeader(size_t size, size_t gcInfoIndex) | 171 HeapObjectHeader(size_t size, size_t gcInfoIndex) |
172 { | 172 { |
173 #if ENABLE(ASSERT) | 173 #if ENABLE(ASSERT) |
174 m_magic = magic; | 174 m_magic = magic; |
175 putGcGeneration(); | |
175 #endif | 176 #endif |
176 // sizeof(HeapObjectHeader) must be equal to or smaller than | 177 // sizeof(HeapObjectHeader) must be equal to or smaller than |
177 // allocationGranurarity, because HeapObjectHeader is used as a header | 178 // allocationGranurarity, because HeapObjectHeader is used as a header |
178 // for an freed entry. Given that the smallest entry size is | 179 // for an freed entry. Given that the smallest entry size is |
179 // allocationGranurarity, HeapObjectHeader must fit into the size. | 180 // allocationGranurarity, HeapObjectHeader must fit into the size. |
180 static_assert(sizeof(HeapObjectHeader) <= allocationGranularity, "size o f HeapObjectHeader must be smaller than allocationGranularity"); | 181 static_assert(sizeof(HeapObjectHeader) <= allocationGranularity, "size o f HeapObjectHeader must be smaller than allocationGranularity"); |
181 #if CPU(64BIT) | 182 #if CPU(64BIT) |
182 static_assert(sizeof(HeapObjectHeader) == 8, "size of HeapObjectHeader m ust be 8 byte aligned"); | 183 static_assert(sizeof(HeapObjectHeader) == 8, "size of HeapObjectHeader m ust be 8 byte aligned"); |
183 #endif | 184 #endif |
184 | 185 |
(...skipping 24 matching lines...) Expand all Loading... | |
209 Address payload(); | 210 Address payload(); |
210 size_t payloadSize(); | 211 size_t payloadSize(); |
211 Address payloadEnd(); | 212 Address payloadEnd(); |
212 | 213 |
213 #if ENABLE(ASSERT) | 214 #if ENABLE(ASSERT) |
214 bool checkHeader() const; | 215 bool checkHeader() const; |
215 // Zap magic number with a new magic number that means there was once an | 216 // Zap magic number with a new magic number that means there was once an |
216 // object allocated here, but it was freed because nobody marked it during | 217 // object allocated here, but it was freed because nobody marked it during |
217 // GC. | 218 // GC. |
218 void zapMagic(); | 219 void zapMagic(); |
220 | |
221 void putGcGeneration(); | |
sof
2015/11/10 16:09:24
What does this give you beyond what magic values a
peria
2015/11/10 16:45:01
They do same works to check an object is alive or
| |
222 void clearGcGeneration(); | |
223 uint16_t gcGeneration() const { return m_gcGeneration; } | |
219 #endif | 224 #endif |
220 | 225 |
221 void finalize(Address, size_t); | 226 void finalize(Address, size_t); |
222 static HeapObjectHeader* fromPayload(const void*); | 227 static HeapObjectHeader* fromPayload(const void*); |
223 | 228 |
224 static const uint16_t magic = 0xfff1; | 229 static const uint16_t magic = 0xfff1; |
225 static const uint16_t zappedMagic = 0x4321; | 230 static const uint16_t zappedMagic = 0x4321; |
226 | 231 |
227 private: | 232 private: |
228 uint32_t m_encoded; | 233 uint32_t m_encoded; |
229 #if ENABLE(ASSERT) | 234 #if ENABLE(ASSERT) |
230 uint16_t m_magic; | 235 uint16_t m_magic; |
236 uint16_t m_gcGeneration; | |
231 #endif | 237 #endif |
232 | 238 |
233 // In 64 bit architectures, we intentionally add 4 byte padding immediately | 239 // In 64 bit architectures, we intentionally add 4 byte padding immediately |
234 // after the HeapHeaderObject. This is because: | 240 // after the HeapHeaderObject. This is because: |
235 // | 241 // |
236 // | HeapHeaderObject (4 byte) | padding (4 byte) | object payload (8 * n by te) | | 242 // | HeapHeaderObject (4 byte) | padding (4 byte) | object payload (8 * n by te) | |
237 // ^8 byte aligned ^8 byte aligned | 243 // ^8 byte aligned ^8 byte aligned |
238 // | 244 // |
239 // is better than: | 245 // is better than: |
240 // | 246 // |
(...skipping 10 matching lines...) Expand all Loading... | |
251 class FreeListEntry final : public HeapObjectHeader { | 257 class FreeListEntry final : public HeapObjectHeader { |
252 public: | 258 public: |
253 NO_SANITIZE_ADDRESS | 259 NO_SANITIZE_ADDRESS |
254 explicit FreeListEntry(size_t size) | 260 explicit FreeListEntry(size_t size) |
255 : HeapObjectHeader(size, gcInfoIndexForFreeListHeader) | 261 : HeapObjectHeader(size, gcInfoIndexForFreeListHeader) |
256 , m_next(nullptr) | 262 , m_next(nullptr) |
257 { | 263 { |
258 #if ENABLE(ASSERT) | 264 #if ENABLE(ASSERT) |
259 ASSERT(size >= sizeof(HeapObjectHeader)); | 265 ASSERT(size >= sizeof(HeapObjectHeader)); |
260 zapMagic(); | 266 zapMagic(); |
267 clearGcGeneration(); | |
261 #endif | 268 #endif |
262 } | 269 } |
263 | 270 |
264 Address address() { return reinterpret_cast<Address>(this); } | 271 Address address() { return reinterpret_cast<Address>(this); } |
265 | 272 |
266 NO_SANITIZE_ADDRESS | 273 NO_SANITIZE_ADDRESS |
267 void unlink(FreeListEntry** prevNext) | 274 void unlink(FreeListEntry** prevNext) |
268 { | 275 { |
269 *prevNext = m_next; | 276 *prevNext = m_next; |
270 m_next = nullptr; | 277 m_next = nullptr; |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 SET_MEMORY_ACCESSIBLE(result, allocationSize - sizeof(HeapObjectHeader)) ; | 876 SET_MEMORY_ACCESSIBLE(result, allocationSize - sizeof(HeapObjectHeader)) ; |
870 ASSERT(findPageFromAddress(headerAddress + allocationSize - 1)); | 877 ASSERT(findPageFromAddress(headerAddress + allocationSize - 1)); |
871 return result; | 878 return result; |
872 } | 879 } |
873 return outOfLineAllocate(allocationSize, gcInfoIndex); | 880 return outOfLineAllocate(allocationSize, gcInfoIndex); |
874 } | 881 } |
875 | 882 |
876 } // namespace blink | 883 } // namespace blink |
877 | 884 |
878 #endif // HeapPage_h | 885 #endif // HeapPage_h |
OLD | NEW |