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

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

Issue 169523004: Add partitionAllocGetSize() for determining actual size of allocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: adjust test sizes, and reword/fix comments Created 6 years, 10 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
« no previous file with comments | « no previous file | 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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 558
559 ptr = partitionCookieFreePointerAdjust(ptr); 559 ptr = partitionCookieFreePointerAdjust(ptr);
560 ASSERT(partitionPointerIsValid(ptr)); 560 ASSERT(partitionPointerIsValid(ptr));
561 PartitionPage* page = partitionPointerToPage(ptr); 561 PartitionPage* page = partitionPointerToPage(ptr);
562 spinLockLock(&root->lock); 562 spinLockLock(&root->lock);
563 partitionFreeWithPage(ptr, page); 563 partitionFreeWithPage(ptr, page);
564 spinLockUnlock(&root->lock); 564 spinLockUnlock(&root->lock);
565 #endif 565 #endif
566 } 566 }
567 567
568 ALWAYS_INLINE bool partitionAllocSupportsGetSize()
569 {
570 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
571 return false;
572 #else
573 return true;
574 #endif
575 }
576
577 ALWAYS_INLINE size_t partitionAllocGetSize(void* ptr)
578 {
579 // No need to lock here. Only 'ptr' being freed by another thread could
580 // cause trouble, and the caller is responsible for that not happening.
581 ASSERT(partitionAllocSupportsGetSize());
582 ptr = partitionCookieFreePointerAdjust(ptr);
583 ASSERT(partitionPointerIsValid(ptr));
584 PartitionPage* page = partitionPointerToPage(ptr);
585 size_t size = page->bucket->slotSize;
586 return partitionCookieSizeAdjustSubtract(size);
587 }
588
568 // N (or more accurately, N - sizeof(void*)) represents the largest size in 589 // N (or more accurately, N - sizeof(void*)) represents the largest size in
569 // bytes that will be handled by a SizeSpecificPartitionAllocator. 590 // bytes that will be handled by a SizeSpecificPartitionAllocator.
570 // Attempts to partitionAlloc() more than this amount will fail. 591 // Attempts to partitionAlloc() more than this amount will fail.
571 template <size_t N> 592 template <size_t N>
572 class SizeSpecificPartitionAllocator { 593 class SizeSpecificPartitionAllocator {
573 public: 594 public:
574 static const size_t kMaxAllocation = N - kAllocationGranularity; 595 static const size_t kMaxAllocation = N - kAllocationGranularity;
575 static const size_t kNumBuckets = N / kAllocationGranularity; 596 static const size_t kNumBuckets = N / kAllocationGranularity;
576 void init() { partitionAllocInit(&m_partitionRoot, kNumBuckets, kMaxAllocati on); } 597 void init() { partitionAllocInit(&m_partitionRoot, kNumBuckets, kMaxAllocati on); }
577 bool shutdown() { return partitionAllocShutdown(&m_partitionRoot); } 598 bool shutdown() { return partitionAllocShutdown(&m_partitionRoot); }
(...skipping 17 matching lines...) Expand all
595 using WTF::SizeSpecificPartitionAllocator; 616 using WTF::SizeSpecificPartitionAllocator;
596 using WTF::PartitionAllocatorGeneric; 617 using WTF::PartitionAllocatorGeneric;
597 using WTF::PartitionRoot; 618 using WTF::PartitionRoot;
598 using WTF::partitionAllocInit; 619 using WTF::partitionAllocInit;
599 using WTF::partitionAllocShutdown; 620 using WTF::partitionAllocShutdown;
600 using WTF::partitionAlloc; 621 using WTF::partitionAlloc;
601 using WTF::partitionFree; 622 using WTF::partitionFree;
602 using WTF::partitionAllocGeneric; 623 using WTF::partitionAllocGeneric;
603 using WTF::partitionFreeGeneric; 624 using WTF::partitionFreeGeneric;
604 using WTF::partitionReallocGeneric; 625 using WTF::partitionReallocGeneric;
626 using WTF::partitionAllocSupportsGetSize;
627 using WTF::partitionAllocGetSize;
605 628
606 #endif // WTF_PartitionAlloc_h 629 #endif // WTF_PartitionAlloc_h
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698