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

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: 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') | Source/wtf/PartitionAllocTest.cpp » ('J')
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 size_t partitionAllocGetSize(PartitionRootGeneric* root, void* ptr )
569 {
570 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
571 ASSERT_NOT_REACHED();
Chris Evans 2014/02/18 22:19:59 I think this definitely will be reached. We want t
572 #else
573 ASSERT(root->initialized);
574 if (UNLIKELY(!ptr))
575 return 0;
Chris Evans 2014/02/18 22:19:59 For simplicity, maybe try not supporting passing i
576 ptr = partitionCookieFreePointerAdjust(ptr);
577 ASSERT(partitionPointerIsValid(ptr));
578 PartitionPage* page = partitionPointerToPage(ptr);
579 spinLockLock(&root->lock);
Chris Evans 2014/02/18 22:19:59 No need for locking, as covered separately. But de
580 size_t size = page->bucket->slotSize;
581 spinLockUnlock(&root->lock);
582 return partitionCookieSizeAdjustSubtract(size);
583 #endif
584 }
585
568 // N (or more accurately, N - sizeof(void*)) represents the largest size in 586 // N (or more accurately, N - sizeof(void*)) represents the largest size in
569 // bytes that will be handled by a SizeSpecificPartitionAllocator. 587 // bytes that will be handled by a SizeSpecificPartitionAllocator.
570 // Attempts to partitionAlloc() more than this amount will fail. 588 // Attempts to partitionAlloc() more than this amount will fail.
571 template <size_t N> 589 template <size_t N>
572 class SizeSpecificPartitionAllocator { 590 class SizeSpecificPartitionAllocator {
573 public: 591 public:
574 static const size_t kMaxAllocation = N - kAllocationGranularity; 592 static const size_t kMaxAllocation = N - kAllocationGranularity;
575 static const size_t kNumBuckets = N / kAllocationGranularity; 593 static const size_t kNumBuckets = N / kAllocationGranularity;
576 void init() { partitionAllocInit(&m_partitionRoot, kNumBuckets, kMaxAllocati on); } 594 void init() { partitionAllocInit(&m_partitionRoot, kNumBuckets, kMaxAllocati on); }
577 bool shutdown() { return partitionAllocShutdown(&m_partitionRoot); } 595 bool shutdown() { return partitionAllocShutdown(&m_partitionRoot); }
(...skipping 19 matching lines...) Expand all
597 using WTF::PartitionRoot; 615 using WTF::PartitionRoot;
598 using WTF::partitionAllocInit; 616 using WTF::partitionAllocInit;
599 using WTF::partitionAllocShutdown; 617 using WTF::partitionAllocShutdown;
600 using WTF::partitionAlloc; 618 using WTF::partitionAlloc;
601 using WTF::partitionFree; 619 using WTF::partitionFree;
602 using WTF::partitionAllocGeneric; 620 using WTF::partitionAllocGeneric;
603 using WTF::partitionFreeGeneric; 621 using WTF::partitionFreeGeneric;
604 using WTF::partitionReallocGeneric; 622 using WTF::partitionReallocGeneric;
605 623
606 #endif // WTF_PartitionAlloc_h 624 #endif // WTF_PartitionAlloc_h
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | Source/wtf/PartitionAllocTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698