| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Parts of this module come from: | 5 // Parts of this module come from: |
| 6 // http://www.codeproject.com/KB/applications/visualleakdetector.aspx | 6 // http://www.codeproject.com/KB/applications/visualleakdetector.aspx |
| 7 // by Dan Moulding. | 7 // by Dan Moulding. |
| 8 // http://www.codeproject.com/KB/threads/StackWalker.aspx | 8 // http://www.codeproject.com/KB/threads/StackWalker.aspx |
| 9 // by Jochen Kalmbach | 9 // by Jochen Kalmbach |
| 10 | 10 |
| 11 #ifndef MEMORY_WATCHER_CALL_STACK_H_ | 11 #ifndef MEMORY_WATCHER_CALL_STACK_H_ |
| 12 #define MEMORY_WATCHER_CALL_STACK_H_ | 12 #define MEMORY_WATCHER_CALL_STACK_H_ |
| 13 | 13 |
| 14 #include <windows.h> | 14 #include <windows.h> |
| 15 #include <dbghelp.h> | 15 #include <dbghelp.h> |
| 16 #include <functional> | 16 #include <functional> |
| 17 #include <map> | 17 #include <map> |
| 18 #include <string> |
| 18 | 19 |
| 19 #include "memory_watcher.h" | 20 #include "memory_watcher.h" |
| 20 #include "base/lock.h" | 21 #include "base/lock.h" |
| 21 #include "base/logging.h" | 22 #include "base/logging.h" |
| 22 | 23 |
| 23 // The CallStack Class | 24 // The CallStack Class |
| 24 // A stack where memory has been allocated. | 25 // A stack where memory has been allocated. |
| 25 class CallStack { | 26 class CallStack { |
| 26 public: | 27 public: |
| 27 // Initialize for tracing CallStacks. | 28 // Initialize for tracing CallStacks. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 75 |
| 75 // Cache ProgramCounter -> Symbol lookups. | 76 // Cache ProgramCounter -> Symbol lookups. |
| 76 // This cache is not thread safe. | 77 // This cache is not thread safe. |
| 77 typedef std::map<int32, std::string, std::less<int32>, | 78 typedef std::map<int32, std::string, std::less<int32>, |
| 78 PrivateHookAllocator<int32> > SymbolCache; | 79 PrivateHookAllocator<int32> > SymbolCache; |
| 79 static SymbolCache* symbol_cache_; | 80 static SymbolCache* symbol_cache_; |
| 80 | 81 |
| 81 DISALLOW_EVIL_CONSTRUCTORS(CallStack); | 82 DISALLOW_EVIL_CONSTRUCTORS(CallStack); |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 // An AllocationStack is a type of CallStack which represents | 85 // An AllocationStack is a type of CallStack which represents a CallStack where |
| 85 // a CallStack where memory has been allocated. As such, in | 86 // memory has been allocated. This class is also a list item, so that it can |
| 86 // addition to the CallStack information, it also tracks the | 87 // be easilly allocated and deallocated from its static singly-linked-list of |
| 87 // amount of memory allocated. | 88 // free instances. |
| 88 class AllocationStack : public CallStack { | 89 class AllocationStack : public CallStack { |
| 89 public: | 90 public: |
| 90 explicit AllocationStack(int32 alloc_size) | 91 AllocationStack() : next_(NULL), CallStack() {} |
| 91 : allocation_size_(alloc_size), | |
| 92 next_(NULL), | |
| 93 CallStack() { | |
| 94 } | |
| 95 | |
| 96 // The size of the allocation. | |
| 97 int32 allocation_size() { return allocation_size_; } | |
| 98 | 92 |
| 99 // We maintain a freelist of the AllocationStacks. | 93 // We maintain a freelist of the AllocationStacks. |
| 100 void* operator new(size_t s); | 94 void* operator new(size_t s); |
| 101 void operator delete(void*p); | 95 void operator delete(void*p); |
| 102 | 96 |
| 103 private: | 97 private: |
| 104 int32 allocation_size_; // The size of the allocation | |
| 105 | |
| 106 AllocationStack* next_; // Pointer used when on the freelist. | 98 AllocationStack* next_; // Pointer used when on the freelist. |
| 107 static AllocationStack* freelist_; | 99 static AllocationStack* freelist_; |
| 108 static Lock freelist_lock_; | 100 static Lock freelist_lock_; |
| 109 | 101 |
| 110 DISALLOW_EVIL_CONSTRUCTORS(AllocationStack); | 102 DISALLOW_EVIL_CONSTRUCTORS(AllocationStack); |
| 111 }; | 103 }; |
| 112 | 104 |
| 113 #endif // MEMORY_WATCHER_CALL_STACK_H_ | 105 #endif // MEMORY_WATCHER_CALL_STACK_H_ |
| OLD | NEW |