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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 return noLeaks; | 247 return noLeaks; |
248 } | 248 } |
249 | 249 |
250 static void partitionAllocBaseShutdown(PartitionRootBase* root) | 250 static void partitionAllocBaseShutdown(PartitionRootBase* root) |
251 { | 251 { |
252 ASSERT(root->initialized); | 252 ASSERT(root->initialized); |
253 root->initialized = false; | 253 root->initialized = false; |
254 | 254 |
255 // Now that we've examined all partition pages in all buckets, it's safe | 255 // Now that we've examined all partition pages in all buckets, it's safe |
256 // to free all our super pages. We first collect the super page pointers | 256 // to free all our super pages. Since the super page extent entries are |
257 // on the stack because some of them are themselves store in super pages. | 257 // stored in the super pages, we need to be careful not to access them |
258 char* superPages[kMaxPartitionSize / kSuperPageSize]; | 258 // after we've released the corresponding super page. |
259 size_t numSuperPages = 0; | |
260 PartitionSuperPageExtentEntry* entry = root->firstExtent; | 259 PartitionSuperPageExtentEntry* entry = root->firstExtent; |
261 while (entry) { | 260 while (entry) { |
| 261 PartitionSuperPageExtentEntry* nextEntry = entry->next; |
262 char* superPage = entry->superPageBase; | 262 char* superPage = entry->superPageBase; |
263 while (superPage != entry->superPagesEnd) { | 263 char* superPagesEnd = entry->superPagesEnd; |
264 superPages[numSuperPages] = superPage; | 264 while (superPage < superPagesEnd) { |
265 numSuperPages++; | 265 freePages(superPage, kSuperPageSize); |
266 superPage += kSuperPageSize; | 266 superPage += kSuperPageSize; |
267 } | 267 } |
268 entry = entry->next; | 268 entry = nextEntry; |
269 } | 269 } |
270 ASSERT(numSuperPages == root->totalSizeOfSuperPages / kSuperPageSize); | |
271 for (size_t i = 0; i < numSuperPages; ++i) | |
272 freePages(superPages[i], kSuperPageSize); | |
273 } | 270 } |
274 | 271 |
275 bool partitionAllocShutdown(PartitionRoot* root) | 272 bool partitionAllocShutdown(PartitionRoot* root) |
276 { | 273 { |
277 bool noLeaks = true; | 274 bool noLeaks = true; |
278 size_t i; | 275 size_t i; |
279 for (i = 0; i < root->numBuckets; ++i) { | 276 for (i = 0; i < root->numBuckets; ++i) { |
280 PartitionBucket* bucket = &root->buckets()[i]; | 277 PartitionBucket* bucket = &root->buckets()[i]; |
281 if (!partitionAllocShutdownBucket(bucket)) | 278 if (!partitionAllocShutdownBucket(bucket)) |
282 noLeaks = false; | 279 noLeaks = false; |
(...skipping 14 matching lines...) Expand all Loading... |
297 } | 294 } |
298 partitionAllocBaseShutdown(root); | 295 partitionAllocBaseShutdown(root); |
299 return noLeaks; | 296 return noLeaks; |
300 } | 297 } |
301 | 298 |
302 static NEVER_INLINE void partitionOutOfMemory() | 299 static NEVER_INLINE void partitionOutOfMemory() |
303 { | 300 { |
304 IMMEDIATE_CRASH(); | 301 IMMEDIATE_CRASH(); |
305 } | 302 } |
306 | 303 |
307 static NEVER_INLINE void partitionFull() | |
308 { | |
309 IMMEDIATE_CRASH(); | |
310 } | |
311 | |
312 static ALWAYS_INLINE void partitionDecommitSystemPages(PartitionRootBase* root,
void* addr, size_t len) | 304 static ALWAYS_INLINE void partitionDecommitSystemPages(PartitionRootBase* root,
void* addr, size_t len) |
313 { | 305 { |
314 decommitSystemPages(addr, len); | 306 decommitSystemPages(addr, len); |
315 ASSERT(root->totalSizeOfCommittedPages > len); | 307 ASSERT(root->totalSizeOfCommittedPages > len); |
316 root->totalSizeOfCommittedPages -= len; | 308 root->totalSizeOfCommittedPages -= len; |
317 } | 309 } |
318 | 310 |
319 static ALWAYS_INLINE void partitionRecommitSystemPages(PartitionRootBase* root,
void* addr, size_t len) | 311 static ALWAYS_INLINE void partitionRecommitSystemPages(PartitionRootBase* root,
void* addr, size_t len) |
320 { | 312 { |
321 recommitSystemPages(addr, len); | 313 recommitSystemPages(addr, len); |
(...skipping 11 matching lines...) Expand all Loading... |
333 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { | 325 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { |
334 // In this case, we can still hand out pages from the current super page | 326 // In this case, we can still hand out pages from the current super page |
335 // allocation. | 327 // allocation. |
336 char* ret = root->nextPartitionPage; | 328 char* ret = root->nextPartitionPage; |
337 root->nextPartitionPage += totalSize; | 329 root->nextPartitionPage += totalSize; |
338 return ret; | 330 return ret; |
339 } | 331 } |
340 | 332 |
341 // Need a new super page. | 333 // Need a new super page. |
342 root->totalSizeOfSuperPages += kSuperPageSize; | 334 root->totalSizeOfSuperPages += kSuperPageSize; |
343 if (root->totalSizeOfSuperPages > kMaxPartitionSize) | |
344 partitionFull(); | |
345 char* requestedAddress = root->nextSuperPage; | 335 char* requestedAddress = root->nextSuperPage; |
346 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe
rPageSize, kSuperPageSize)); | 336 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe
rPageSize, kSuperPageSize)); |
347 if (UNLIKELY(!superPage)) { | 337 if (UNLIKELY(!superPage)) { |
348 if (flags & PartitionAllocReturnNull) | 338 if (flags & PartitionAllocReturnNull) |
349 return 0; | 339 return 0; |
350 partitionOutOfMemory(); | 340 partitionOutOfMemory(); |
351 } | 341 } |
352 root->nextSuperPage = superPage + kSuperPageSize; | 342 root->nextSuperPage = superPage + kSuperPageSize; |
353 char* ret = superPage + kPartitionPageSize; | 343 char* ret = superPage + kPartitionPageSize; |
354 root->nextPartitionPage = ret + totalSize; | 344 root->nextPartitionPage = ret + totalSize; |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 printf("total live: %zu bytes\n", totalLive); | 965 printf("total live: %zu bytes\n", totalLive); |
976 printf("total resident: %zu bytes\n", totalResident); | 966 printf("total resident: %zu bytes\n", totalResident); |
977 printf("total freeable: %zu bytes\n", totalFreeable); | 967 printf("total freeable: %zu bytes\n", totalFreeable); |
978 fflush(stdout); | 968 fflush(stdout); |
979 } | 969 } |
980 | 970 |
981 #endif // !NDEBUG | 971 #endif // !NDEBUG |
982 | 972 |
983 } // namespace WTF | 973 } // namespace WTF |
984 | 974 |
OLD | NEW |