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

Unified Diff: third_party/tcmalloc/chromium/src/tcmalloc.cc

Issue 12572005: Reorder checks in tcmalloc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added an ASSERT. Removed Jim's TODO. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/tcmalloc/chromium/src/tcmalloc.cc
diff --git a/third_party/tcmalloc/chromium/src/tcmalloc.cc b/third_party/tcmalloc/chromium/src/tcmalloc.cc
index 48e71c228ba4feb3396d9aefc0fa14bba4a65ebd..1a56a3adbf5049d2f69f4fbd8780b877bbd69498 100644
--- a/third_party/tcmalloc/chromium/src/tcmalloc.cc
+++ b/third_party/tcmalloc/chromium/src/tcmalloc.cc
@@ -1062,7 +1062,10 @@ inline void* do_malloc_pages(ThreadCache* heap, size_t size) {
Length num_pages = tcmalloc::pages(size);
size = num_pages << kPageShift;
- heap->AddToByteAllocatedTotal(size); // Chromium profiling.
+ // Chromium profiling. Measurements in March 2013 suggest this
+ // imposes a small enough runtime cost that there's no reason to
+ // try to optimize it.
+ heap->AddToByteAllocatedTotal(size);
if ((FLAGS_tcmalloc_sample_parameter > 0) && heap->SampleAllocation(size)) {
result = DoSampledAllocation(size);
@@ -1089,33 +1092,30 @@ inline void* do_malloc(size_t size) {
// The following call forces module initialization
ThreadCache* heap = ThreadCache::GetCache();
- // First, check if our security policy allows this size.
- if (IsAllocSizePermitted(size)) {
- if (size <= kMaxSize) {
- size_t cl = Static::sizemap()->SizeClass(size);
- size = Static::sizemap()->class_to_size(cl);
-
- // TODO(jar): If this has any detectable performance impact, it can be
- // optimized by only tallying sizes if the profiler was activated to
- // recall these tallies. I don't think this is performance critical, but
- // we really should measure it.
- heap->AddToByteAllocatedTotal(size); // Chromium profiling.
-
- if ((FLAGS_tcmalloc_sample_parameter > 0) &&
- heap->SampleAllocation(size)) {
- ret = DoSampledAllocation(size);
- MarkAllocatedRegion(ret);
- } else {
- // The common case, and also the simplest. This just pops the
- // size-appropriate freelist, after replenishing it if it's empty.
- ret = CheckMallocResult(heap->Allocate(size, cl));
- }
- } else {
- ret = do_malloc_pages(heap, size);
+ if (size <= kMaxSize && IsAllocSizePermitted(size)) {
+ size_t cl = Static::sizemap()->SizeClass(size);
+ size = Static::sizemap()->class_to_size(cl);
+
+ // Chromium profiling. Measurements in March 2013 suggest this
+ // imposes a small enough runtime cost that there's no reason to
+ // try to optimize it.
+ heap->AddToByteAllocatedTotal(size);
+
+ if ((FLAGS_tcmalloc_sample_parameter > 0) &&
+ heap->SampleAllocation(size)) {
+ ret = DoSampledAllocation(size);
MarkAllocatedRegion(ret);
+ } else {
+ // The common case, and also the simplest. This just pops the
+ // size-appropriate freelist, after replenishing it if it's empty.
+ ret = CheckMallocResult(heap->Allocate(size, cl));
}
+ } else if (IsAllocSizePermitted(size)) {
+ ret = do_malloc_pages(heap, size);
+ MarkAllocatedRegion(ret);
}
if (ret == NULL) errno = ENOMEM;
+ ASSERT(IsAllocSizePermitted(size) || ret == NULL);
return ret;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698