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

Side by Side Diff: base/trace_event/heap_profiler_allocation_register_posix.cc

Issue 2089253002: [tracing] Optimize AllocationRegister and increase max backtrace depth. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Windows Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/heap_profiler_allocation_register.h" 5 #include "base/trace_event/heap_profiler_allocation_register.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <sys/mman.h> 8 #include <sys/mman.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include "base/bits.h" 11 #include "base/bits.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/process/process_metrics.h" 13 #include "base/process/process_metrics.h"
14 14
15 #ifndef MAP_ANONYMOUS 15 #ifndef MAP_ANONYMOUS
16 #define MAP_ANONYMOUS MAP_ANON 16 #define MAP_ANONYMOUS MAP_ANON
17 #endif 17 #endif
18 18
19 namespace base { 19 namespace base {
20 namespace trace_event { 20 namespace trace_event {
21 namespace internal {
21 22
22 namespace { 23 namespace {
23 size_t GetGuardSize() { 24 size_t GetGuardSize() {
24 return GetPageSize(); 25 return GetPageSize();
25 } 26 }
26 } 27 }
27 28
28 // static 29 void* AllocateGuardedVirtualMemory(size_t size) {
29 void* AllocationRegister::AllocateVirtualMemory(size_t size) {
30 size = bits::Align(size, GetPageSize()); 30 size = bits::Align(size, GetPageSize());
31 31
32 // Add space for a guard page at the end. 32 // Add space for a guard page at the end.
33 size_t map_size = size + GetGuardSize(); 33 size_t map_size = size + GetGuardSize();
34 34
35 void* addr = mmap(nullptr, map_size, PROT_READ | PROT_WRITE, 35 void* addr = mmap(nullptr, map_size, PROT_READ | PROT_WRITE,
36 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 36 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
37 37
38 PCHECK(addr != MAP_FAILED); 38 PCHECK(addr != MAP_FAILED);
39 39
40 // Mark the last page of the allocated address space as inaccessible 40 // Mark the last page of the allocated address space as inaccessible
41 // (PROT_NONE). The read/write accessible space is still at least |min_size| 41 // (PROT_NONE). The read/write accessible space is still at least |min_size|
42 // bytes. 42 // bytes.
43 void* guard_addr = 43 void* guard_addr =
44 reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) + size); 44 reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) + size);
45 int result = mprotect(guard_addr, GetGuardSize(), PROT_NONE); 45 int result = mprotect(guard_addr, GetGuardSize(), PROT_NONE);
46 PCHECK(result == 0); 46 PCHECK(result == 0);
47 47
48 return addr; 48 return addr;
49 } 49 }
50 50
51 // static 51 void FreeGuardedVirtualMemory(void* address, size_t allocated_size) {
52 void AllocationRegister::FreeVirtualMemory(void* address,
53 size_t allocated_size) {
54 size_t size = bits::Align(allocated_size, GetPageSize()) + GetGuardSize(); 52 size_t size = bits::Align(allocated_size, GetPageSize()) + GetGuardSize();
55 munmap(address, size); 53 munmap(address, size);
56 } 54 }
57 55
56 } // namespace internal
58 } // namespace trace_event 57 } // namespace trace_event
59 } // namespace base 58 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_register.cc ('k') | base/trace_event/heap_profiler_allocation_register_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698