Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: Source/wtf/PartitionAlloc.cpp

Issue 21666003: Enhancements to PartitionAlloc to support threading and arbitrary allocation sizes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review comments. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 #endif 39 #endif
40 40
41 COMPILE_ASSERT(WTF::kPartitionPageSize < WTF::kSuperPageSize, ok_partition_page_ size); 41 COMPILE_ASSERT(WTF::kPartitionPageSize < WTF::kSuperPageSize, ok_partition_page_ size);
42 42
43 namespace WTF { 43 namespace WTF {
44 44
45 void partitionAllocInit(PartitionRoot* root) 45 void partitionAllocInit(PartitionRoot* root)
46 { 46 {
47 ASSERT(!root->initialized); 47 ASSERT(!root->initialized);
48 root->initialized = true; 48 root->initialized = true;
49 root->lock = 0;
49 size_t i; 50 size_t i;
50 for (i = 0; i < kNumBuckets; ++i) { 51 for (i = 0; i < kNumBuckets; ++i) {
51 PartitionBucket* bucket = &root->buckets[i]; 52 PartitionBucket* bucket = &root->buckets[i];
52 bucket->root = root; 53 bucket->root = root;
53 bucket->currPage = &root->seedPage; 54 bucket->currPage = &root->seedPage;
54 bucket->freePages = 0; 55 bucket->freePages = 0;
55 bucket->numFullPages = 0; 56 bucket->numFullPages = 0;
56 } 57 }
57 58
58 root->nextSuperPage = 0; 59 root->nextSuperPage = 0;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } else { 317 } else {
317 // Fully used page became partially used. It must be put back on the 318 // Fully used page became partially used. It must be put back on the
318 // non-full page list. 319 // non-full page list.
319 partitionLinkPage(page, bucket->currPage); 320 partitionLinkPage(page, bucket->currPage);
320 page->numAllocatedSlots = -page->numAllocatedSlots - 2; 321 page->numAllocatedSlots = -page->numAllocatedSlots - 2;
321 ASSERT(page->numAllocatedSlots == partitionBucketSlots(bucket) - 1); 322 ASSERT(page->numAllocatedSlots == partitionBucketSlots(bucket) - 1);
322 --bucket->numFullPages; 323 --bucket->numFullPages;
323 } 324 }
324 } 325 }
325 326
327 void* partitionReallocGeneric(PartitionRoot* root, void* ptr, size_t oldSize, si ze_t newSize)
328 {
329 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
330 return realloc(ptr, newSize);
331 #else
332 size_t oldIndex = oldSize >> kBucketShift;
333 if (oldIndex > kNumBuckets)
334 oldIndex = kNumBuckets;
335 size_t newIndex = newSize >> kBucketShift;
336 if (newIndex > kNumBuckets)
337 newIndex = kNumBuckets;
338
339 if (oldIndex == newIndex) {
340 // Same bucket. But kNumBuckets indicates the fastMalloc "bucket" so in
341 // that case we're not done; we have to forward to fastRealloc.
342 if (oldIndex == kNumBuckets)
343 return WTF::fastRealloc(ptr, newSize);
344 return ptr;
345 }
346 // This realloc cannot be resized in-place. Sadness.
347 void* ret = partitionAllocGeneric(root, newSize);
348 size_t copySize = oldSize;
349 if (newSize < oldSize)
350 copySize = newSize;
351 memcpy(ret, ptr, copySize);
352 partitionFreeGeneric(ptr, oldSize);
353 return ret;
354 #endif
355 }
356
326 #ifndef NDEBUG 357 #ifndef NDEBUG
327 358
328 void partitionDumpStats(const PartitionRoot& root) 359 void partitionDumpStats(const PartitionRoot& root)
329 { 360 {
330 size_t i; 361 size_t i;
331 for (i = 0; i < kNumBuckets; ++i) { 362 for (i = 0; i < kNumBuckets; ++i) {
332 const PartitionBucket& bucket = root.buckets[i]; 363 const PartitionBucket& bucket = root.buckets[i];
333 if (bucket.currPage == &bucket.root->seedPage && !bucket.freePages) { 364 if (bucket.currPage == &bucket.root->seedPage && !bucket.freePages) {
334 // Empty bucket with no freelist pages. Skip reporting it. 365 // Empty bucket with no freelist pages. Skip reporting it.
335 continue; 366 continue;
(...skipping 16 matching lines...) Expand all
352 } 383 }
353 page = page->next; 384 page = page->next;
354 } while (page != bucket.currPage); 385 } while (page != bucket.currPage);
355 printf("bucket size %ld: %ld/%ld bytes, %ld free pages\n", bucketSlotSiz e, numActiveBytes, numActivePages * kPartitionPageSize, numFreePages); 386 printf("bucket size %ld: %ld/%ld bytes, %ld free pages\n", bucketSlotSiz e, numActiveBytes, numActivePages * kPartitionPageSize, numFreePages);
356 } 387 }
357 } 388 }
358 #endif // !NDEBUG 389 #endif // !NDEBUG
359 390
360 } // namespace WTF 391 } // namespace WTF
361 392
OLDNEW
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698