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

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

Issue 25640003: Optimize test for pointer being in a partition on 32-bit. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixes. Created 7 years, 2 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
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // - No double-free detection (tcmalloc has some but it may be only a detection 81 // - No double-free detection (tcmalloc has some but it may be only a detection
82 // and not a defense). 82 // and not a defense).
83 // - No randomness in freelist pointers. 83 // - No randomness in freelist pointers.
84 // - Per-object bucketing (instead of per-size) is mostly available at the API, 84 // - Per-object bucketing (instead of per-size) is mostly available at the API,
85 // but not used yet. 85 // but not used yet.
86 // - No randomness of freelist entries or bucket position. 86 // - No randomness of freelist entries or bucket position.
87 // - No specific protection against corruption of page header metadata. 87 // - No specific protection against corruption of page header metadata.
88 88
89 #include "wtf/Assertions.h" 89 #include "wtf/Assertions.h"
90 #include "wtf/FastMalloc.h" 90 #include "wtf/FastMalloc.h"
91 #include "wtf/PageAllocator.h"
91 #include "wtf/SpinLock.h" 92 #include "wtf/SpinLock.h"
93 #include "wtf/UnusedParam.h"
92 94
93 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 95 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
94 #include <stdlib.h> 96 #include <stdlib.h>
95 #endif 97 #endif
96 98
97 namespace WTF { 99 namespace WTF {
98 100
99 // Allocation granularity of sizeof(void*) bytes. 101 // Allocation granularity of sizeof(void*) bytes.
100 static const size_t kAllocationGranularity = sizeof(void*); 102 static const size_t kAllocationGranularity = sizeof(void*);
101 static const size_t kAllocationGranularityMask = kAllocationGranularity - 1; 103 static const size_t kAllocationGranularityMask = kAllocationGranularity - 1;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 PartitionFreelistEntry* entry = static_cast<PartitionFreelistEntry*>(ptr); 261 PartitionFreelistEntry* entry = static_cast<PartitionFreelistEntry*>(ptr);
260 entry->next = partitionFreelistMask(page->freelistHead); 262 entry->next = partitionFreelistMask(page->freelistHead);
261 page->freelistHead = entry; 263 page->freelistHead = entry;
262 --page->numAllocatedSlots; 264 --page->numAllocatedSlots;
263 if (UNLIKELY(page->numAllocatedSlots <= 0)) 265 if (UNLIKELY(page->numAllocatedSlots <= 0))
264 partitionFreeSlowPath(page); 266 partitionFreeSlowPath(page);
265 } 267 }
266 268
267 ALWAYS_INLINE bool partitionPointerIsValid(PartitionRoot* root, void* ptr) 269 ALWAYS_INLINE bool partitionPointerIsValid(PartitionRoot* root, void* ptr)
268 { 270 {
271 #if CPU(32BIT)
272 // On 32-bit systems, we have an optimization where we have a bitmap that
273 // can instantly tell us if a pointer is in a super page or not.
274 // It is a global bitmap instead of a per-partition bitmap but this is a
275 // reasonable space vs. accuracy trade off.
276 UNUSED_PARAM(root);
277 return SuperPageBitmap::isPointerInSuperPage(ptr);
278 #else
279 // On 64-bit systems, we check the list of super page extents. Due to the
280 // massive address space, we typically have a single extent.
269 // Dominant case: the pointer is in the first extent, which grew without any collision. 281 // Dominant case: the pointer is in the first extent, which grew without any collision.
270 if (LIKELY(ptr >= root->firstExtent.superPageBase) && LIKELY(ptr < root->fir stExtent.superPagesEnd)) 282 if (LIKELY(ptr >= root->firstExtent.superPageBase) && LIKELY(ptr < root->fir stExtent.superPagesEnd))
271 return true; 283 return true;
272 284
273 // Otherwise, scan through the extent list. 285 // Otherwise, scan through the extent list.
274 PartitionSuperPageExtentEntry* entry = root->firstExtent.next; 286 PartitionSuperPageExtentEntry* entry = root->firstExtent.next;
275 while (UNLIKELY(entry != 0)) { 287 while (UNLIKELY(entry != 0)) {
276 if (ptr >= entry->superPageBase && ptr < entry->superPagesEnd) 288 if (ptr >= entry->superPageBase && ptr < entry->superPagesEnd)
277 return true; 289 return true;
278 entry = entry->next; 290 entry = entry->next;
279 } 291 }
280 292
281 return false; 293 return false;
294 #endif
282 } 295 }
283 296
284 ALWAYS_INLINE void partitionFree(void* ptr) 297 ALWAYS_INLINE void partitionFree(void* ptr)
285 { 298 {
286 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 299 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
287 free(ptr); 300 free(ptr);
288 #else 301 #else
289 PartitionPageHeader* page = partitionPointerToPage(ptr); 302 PartitionPageHeader* page = partitionPointerToPage(ptr);
290 ASSERT(partitionPointerIsValid(page->bucket->root, ptr)); 303 ASSERT(partitionPointerIsValid(page->bucket->root, ptr));
291 partitionFreeWithPage(ptr, page); 304 partitionFreeWithPage(ptr, page);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 using WTF::PartitionRoot; 369 using WTF::PartitionRoot;
357 using WTF::partitionAllocInit; 370 using WTF::partitionAllocInit;
358 using WTF::partitionAllocShutdown; 371 using WTF::partitionAllocShutdown;
359 using WTF::partitionAlloc; 372 using WTF::partitionAlloc;
360 using WTF::partitionFree; 373 using WTF::partitionFree;
361 using WTF::partitionAllocGeneric; 374 using WTF::partitionAllocGeneric;
362 using WTF::partitionFreeGeneric; 375 using WTF::partitionFreeGeneric;
363 using WTF::partitionReallocGeneric; 376 using WTF::partitionReallocGeneric;
364 377
365 #endif // WTF_PartitionAlloc_h 378 #endif // WTF_PartitionAlloc_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698