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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool isMarked() const; | 177 bool isMarked() const; |
178 void mark(); | 178 void mark(); |
179 void unmark(); | 179 void unmark(); |
180 void markDead(); | 180 void markDead(); |
181 bool isDead() const; | 181 bool isDead() const; |
182 | 182 |
183 Address payload(); | 183 Address payload(); |
184 size_t payloadSize(); | 184 size_t payloadSize(); |
185 Address payloadEnd(); | 185 Address payloadEnd(); |
186 | 186 |
187 void checkHeader() const; | |
188 #if ENABLE(ASSERT) | 187 #if ENABLE(ASSERT) |
| 188 bool checkHeader() const; |
189 // Zap magic number with a new magic number that means there was once an | 189 // Zap magic number with a new magic number that means there was once an |
190 // object allocated here, but it was freed because nobody marked it during | 190 // object allocated here, but it was freed because nobody marked it during |
191 // GC. | 191 // GC. |
192 void zapMagic(); | 192 void zapMagic(); |
193 #endif | 193 #endif |
194 | 194 |
195 void finalize(Address, size_t); | 195 void finalize(Address, size_t); |
196 static HeapObjectHeader* fromPayload(const void*); | 196 static HeapObjectHeader* fromPayload(const void*); |
197 | 197 |
198 static const uint16_t magic = 0xfff1; | 198 static const uint16_t magic = 0xfff1; |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 { | 1237 { |
1238 size_t result = m_encoded & headerSizeMask; | 1238 size_t result = m_encoded & headerSizeMask; |
1239 // Large objects should not refer to header->size(). | 1239 // Large objects should not refer to header->size(). |
1240 // The actual size of a large object is stored in | 1240 // The actual size of a large object is stored in |
1241 // LargeObjectPage::m_payloadSize. | 1241 // LargeObjectPage::m_payloadSize. |
1242 ASSERT(result != largeObjectSizeInHeader); | 1242 ASSERT(result != largeObjectSizeInHeader); |
1243 ASSERT(!pageFromObject(this)->isLargeObjectPage()); | 1243 ASSERT(!pageFromObject(this)->isLargeObjectPage()); |
1244 return result; | 1244 return result; |
1245 } | 1245 } |
1246 | 1246 |
| 1247 #if ENABLE(ASSERT) |
1247 NO_SANITIZE_ADDRESS inline | 1248 NO_SANITIZE_ADDRESS inline |
1248 void HeapObjectHeader::checkHeader() const | 1249 bool HeapObjectHeader::checkHeader() const |
1249 { | 1250 { |
1250 ASSERT(!pageFromObject(this)->orphaned()); | 1251 return !pageFromObject(this)->orphaned() && m_magic == magic; |
1251 ASSERT(m_magic == magic); | |
1252 } | 1252 } |
| 1253 #endif |
1253 | 1254 |
1254 inline Address HeapObjectHeader::payload() | 1255 inline Address HeapObjectHeader::payload() |
1255 { | 1256 { |
1256 return reinterpret_cast<Address>(this) + sizeof(HeapObjectHeader); | 1257 return reinterpret_cast<Address>(this) + sizeof(HeapObjectHeader); |
1257 } | 1258 } |
1258 | 1259 |
1259 inline Address HeapObjectHeader::payloadEnd() | 1260 inline Address HeapObjectHeader::payloadEnd() |
1260 { | 1261 { |
1261 return reinterpret_cast<Address>(this) + size(); | 1262 return reinterpret_cast<Address>(this) + size(); |
1262 } | 1263 } |
1263 | 1264 |
1264 NO_SANITIZE_ADDRESS inline | 1265 NO_SANITIZE_ADDRESS inline |
1265 size_t HeapObjectHeader::payloadSize() | 1266 size_t HeapObjectHeader::payloadSize() |
1266 { | 1267 { |
1267 size_t size = m_encoded & headerSizeMask; | 1268 size_t size = m_encoded & headerSizeMask; |
1268 if (UNLIKELY(size == largeObjectSizeInHeader)) { | 1269 if (UNLIKELY(size == largeObjectSizeInHeader)) { |
1269 ASSERT(pageFromObject(this)->isLargeObjectPage()); | 1270 ASSERT(pageFromObject(this)->isLargeObjectPage()); |
1270 return static_cast<LargeObjectPage*>(pageFromObject(this))->payloadSize(
); | 1271 return static_cast<LargeObjectPage*>(pageFromObject(this))->payloadSize(
); |
1271 } | 1272 } |
1272 ASSERT(!pageFromObject(this)->isLargeObjectPage()); | 1273 ASSERT(!pageFromObject(this)->isLargeObjectPage()); |
1273 return size - sizeof(HeapObjectHeader); | 1274 return size - sizeof(HeapObjectHeader); |
1274 } | 1275 } |
1275 | 1276 |
1276 inline HeapObjectHeader* HeapObjectHeader::fromPayload(const void* payload) | 1277 inline HeapObjectHeader* HeapObjectHeader::fromPayload(const void* payload) |
1277 { | 1278 { |
1278 Address addr = reinterpret_cast<Address>(const_cast<void*>(payload)); | 1279 Address addr = reinterpret_cast<Address>(const_cast<void*>(payload)); |
1279 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(addr - sizeof
(HeapObjectHeader)); | 1280 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(addr - sizeof
(HeapObjectHeader)); |
1280 header->checkHeader(); | 1281 ASSERT(header->checkHeader()); |
1281 return header; | 1282 return header; |
1282 } | 1283 } |
1283 | 1284 |
1284 NO_SANITIZE_ADDRESS inline | 1285 NO_SANITIZE_ADDRESS inline |
1285 bool HeapObjectHeader::isMarked() const | 1286 bool HeapObjectHeader::isMarked() const |
1286 { | 1287 { |
1287 checkHeader(); | 1288 ASSERT(checkHeader()); |
1288 return m_encoded & headerMarkBitMask; | 1289 return m_encoded & headerMarkBitMask; |
1289 } | 1290 } |
1290 | 1291 |
1291 NO_SANITIZE_ADDRESS inline | 1292 NO_SANITIZE_ADDRESS inline |
1292 void HeapObjectHeader::mark() | 1293 void HeapObjectHeader::mark() |
1293 { | 1294 { |
1294 checkHeader(); | 1295 ASSERT(checkHeader()); |
1295 ASSERT(!isMarked()); | 1296 ASSERT(!isMarked()); |
1296 m_encoded = m_encoded | headerMarkBitMask; | 1297 m_encoded = m_encoded | headerMarkBitMask; |
1297 } | 1298 } |
1298 | 1299 |
1299 NO_SANITIZE_ADDRESS inline | 1300 NO_SANITIZE_ADDRESS inline |
1300 void HeapObjectHeader::unmark() | 1301 void HeapObjectHeader::unmark() |
1301 { | 1302 { |
1302 checkHeader(); | 1303 ASSERT(checkHeader()); |
1303 ASSERT(isMarked()); | 1304 ASSERT(isMarked()); |
1304 m_encoded &= ~headerMarkBitMask; | 1305 m_encoded &= ~headerMarkBitMask; |
1305 } | 1306 } |
1306 | 1307 |
1307 NO_SANITIZE_ADDRESS inline | 1308 NO_SANITIZE_ADDRESS inline |
1308 bool HeapObjectHeader::isDead() const | 1309 bool HeapObjectHeader::isDead() const |
1309 { | 1310 { |
1310 checkHeader(); | 1311 ASSERT(checkHeader()); |
1311 return m_encoded & headerDeadBitMask; | 1312 return m_encoded & headerDeadBitMask; |
1312 } | 1313 } |
1313 | 1314 |
1314 NO_SANITIZE_ADDRESS inline | 1315 NO_SANITIZE_ADDRESS inline |
1315 void HeapObjectHeader::markDead() | 1316 void HeapObjectHeader::markDead() |
1316 { | 1317 { |
1317 checkHeader(); | 1318 ASSERT(checkHeader()); |
1318 ASSERT(!isMarked()); | 1319 ASSERT(!isMarked()); |
1319 m_encoded |= headerDeadBitMask; | 1320 m_encoded |= headerDeadBitMask; |
1320 } | 1321 } |
1321 | 1322 |
1322 inline Address NormalPageHeap::allocateObject(size_t allocationSize, size_t gcIn
foIndex) | 1323 inline Address NormalPageHeap::allocateObject(size_t allocationSize, size_t gcIn
foIndex) |
1323 { | 1324 { |
1324 #if ENABLE(GC_PROFILING) | 1325 #if ENABLE(GC_PROFILING) |
1325 m_cumulativeAllocationSize += allocationSize; | 1326 m_cumulativeAllocationSize += allocationSize; |
1326 ++m_allocationCount; | 1327 ++m_allocationCount; |
1327 #endif | 1328 #endif |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 size_t copySize = previousHeader->payloadSize(); | 1401 size_t copySize = previousHeader->payloadSize(); |
1401 if (copySize > size) | 1402 if (copySize > size) |
1402 copySize = size; | 1403 copySize = size; |
1403 memcpy(address, previous, copySize); | 1404 memcpy(address, previous, copySize); |
1404 return address; | 1405 return address; |
1405 } | 1406 } |
1406 | 1407 |
1407 } // namespace blink | 1408 } // namespace blink |
1408 | 1409 |
1409 #endif // Heap_h | 1410 #endif // Heap_h |
OLD | NEW |