~ubuntu-branches/ubuntu/jaunty/google-perftools/jaunty

« back to all changes in this revision

Viewing changes to src/system-alloc.h

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2008-06-15 23:41:36 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20080615234136-al5gawvdvt5vhdtz
Tags: 0.98-1
* New upstream release. (Closes: #425147)
* Compiled with GCC 4.3. (Closes: #454841)
* debian/watch: can now report upstream's version (Closes: #450294)
* Because of a file conflict between tau and libgoogle-perftools the
  binary pprof is renamed as google-pprof. (Closes: #404001)
  Great thanks to Michael Mende.
* debian/rules: autoconf files are now generated at the build time.
* Bumped up Standards-Version to 3.7.3, no changes are required.
* Split a new package, libtcmallc_minimal0. The upstream supports
  this module for wider platforms. So I leave its architecture to be
  `any'.
* libgoogle-perftools0's architecture is now i386. The upstream
  supports this module for x86 and x86_64. However, x86_64 requires
  libunwind's development head, which Debian does not have yet.
* Removed an unnecessary patch, debian/patches/02_profiler.cc_alpha.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
// Routine that uses sbrk/mmap to allocate memory from the system.
34
34
// Useful for implementing malloc.
35
35
 
36
 
#ifndef TCMALLOC_SYSTEM_ALLOC_H__
37
 
#define TCMALLOC_SYSTEM_ALLOC_H__
 
36
#ifndef TCMALLOC_SYSTEM_ALLOC_H_
 
37
#define TCMALLOC_SYSTEM_ALLOC_H_
 
38
 
 
39
#include "config.h"
 
40
#include "internal_logging.h"
38
41
 
39
42
// REQUIRES: "alignment" is a power of two or "0" to indicate default alignment
40
43
//
41
 
// Allocate and return "N" bytes of zeroed memory.  The returned
42
 
// pointer is a multiple of "alignment" if non-zero.  Returns NULL
43
 
// when out of memory.
44
 
extern void* TCMalloc_SystemAlloc(size_t bytes, size_t alignment = 0);
45
 
 
46
 
#endif /* TCMALLOC_SYSTEM_ALLOC_H__ */
 
44
// Allocate and return "N" bytes of zeroed memory.
 
45
//
 
46
// If actual_bytes is NULL then the returned memory is exactly the
 
47
// requested size.  If actual bytes is non-NULL then the allocator
 
48
// may optionally return more bytes than asked for (i.e. return an
 
49
// entire "huge" page if a huge page allocator is in use).
 
50
//
 
51
// The returned pointer is a multiple of "alignment" if non-zero.
 
52
//
 
53
// Returns NULL when out of memory.
 
54
extern void* TCMalloc_SystemAlloc(size_t bytes, size_t *actual_bytes,
 
55
                                  size_t alignment = 0);
 
56
 
 
57
// This call is a hint to the operating system that the pages
 
58
// contained in the specified range of memory will not be used for a
 
59
// while, and can be released for use by other processes or the OS.
 
60
// Pages which are released in this way may be destroyed (zeroed) by
 
61
// the OS.  The benefit of this function is that it frees memory for
 
62
// use by the system, the cost is that the pages are faulted back into
 
63
// the address space next time they are touched, which can impact
 
64
// performance.  (Only pages fully covered by the memory region will
 
65
// be released, partial pages will not.)
 
66
extern void TCMalloc_SystemRelease(void* start, size_t length);
 
67
 
 
68
// Interface to a pluggable system allocator.
 
69
class SysAllocator {
 
70
 public:
 
71
  SysAllocator() 
 
72
    : usable_(true), 
 
73
      failed_(false) {
 
74
  };
 
75
  virtual ~SysAllocator() {};
 
76
 
 
77
  virtual void* Alloc(size_t size, size_t *actual_size, size_t alignment) = 0;
 
78
 
 
79
  // Populate the map with whatever properties the specified allocator finds
 
80
  // useful for debugging (such as number of bytes allocated and whether the
 
81
  // allocator has failed).  The callee is responsible for any necessary
 
82
  // locking (and avoiding deadlock).
 
83
  virtual void DumpStats(TCMalloc_Printer* printer) = 0;
 
84
 
 
85
  // So the allocator can be turned off at compile time
 
86
  bool usable_;
 
87
 
 
88
  // Did this allocator fail? If so, we don't need to retry more than twice.
 
89
  bool failed_;
 
90
};
 
91
 
 
92
// Register a new system allocator. The priority determines the order in
 
93
// which the allocators will be invoked. Allocators with numerically lower
 
94
// priority are tried first. To keep things simple, the priority of various
 
95
// allocators is known at compile time.
 
96
//
 
97
// Valid range of priorities: [0, kMaxDynamicAllocators)
 
98
//
 
99
// Please note that we can't use complex data structures and cause
 
100
// recursive calls to malloc within this function. So all data structures
 
101
// are statically allocated.
 
102
//
 
103
// Returns true on success. Does nothing on failure.
 
104
extern PERFTOOLS_DLL_DECL bool RegisterSystemAllocator(SysAllocator *allocator,
 
105
                                                       int priority);
 
106
 
 
107
// Number of SysAllocators known to call RegisterSystemAllocator
 
108
static const int kMaxDynamicAllocators = 2;
 
109
 
 
110
// Retrieve the current state of various system allocators.
 
111
extern PERFTOOLS_DLL_DECL void DumpSystemAllocatorStats(TCMalloc_Printer* printer);
 
112
 
 
113
#endif /* TCMALLOC_SYSTEM_ALLOC_H_ */