1///-*-C++-*-////////////////////////////////////////////////////////////////// 2// 3// Hoard: A Fast, Scalable, and Memory-Efficient Allocator 4// for Shared-Memory Multiprocessors 5// Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery 6// 7// Copyright (c) 1998-2000, The University of Texas at Austin. 8// 9// This library is free software; you can redistribute it and/or modify 10// it under the terms of the GNU Library General Public License as 11// published by the Free Software Foundation, http://www.fsf.org. 12// 13// This library is distributed in the hope that it will be useful, but 14// WITHOUT ANY WARRANTY; without even the implied warranty of 15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16// Library General Public License for more details. 17// 18////////////////////////////////////////////////////////////////////////////// 19#ifndef _HEAPSTATS_H_ 20#define _HEAPSTATS_H_ 21 22#include "config.h" 23 24//#include <stdio.h> 25//#include <assert.h> 26 27 28class heapStats { 29 public: 30 heapStats(void) 31 : U(0), A(0) 32#if HEAP_STATS 33 , Umax(0), Amax(0) 34#endif 35 { 36 } 37 38 inline const heapStats & operator=(const heapStats & p); 39 40 inline void incStats(int updateU, int updateA); 41 inline void incUStats(void); 42 43 inline void decStats(int updateU, int updateA); 44 inline void decUStats(void); 45 inline void decUStats(int &Uout, int &Aout); 46 47 inline void getStats(int &Uout, int &Aout); 48 49#if HEAP_STATS 50 inline int getUmax(void); 51 inline int getAmax(void); 52#endif 53 54 private: 55 // U and A *must* be the first items in this class -- 56 // we will depend on this to atomically update them. 57 58 int U; // Memory in use. 59 int A; // Memory allocated. 60 61#if HEAP_STATS 62 int Umax; 63 int Amax; 64#endif 65}; 66 67 68inline void 69heapStats::incStats(int updateU, int updateA) 70{ 71 assert(updateU >= 0); 72 assert(updateA >= 0); 73 assert(U <= A); 74 assert(U >= 0); 75 assert(A >= 0); 76 U += updateU; 77 A += updateA; 78 79#if HEAP_STATS 80 Amax = MAX(Amax, A); 81 Umax = MAX(Umax, U); 82#endif 83 84 assert(U <= A); 85 assert(U >= 0); 86 assert(A >= 0); 87} 88 89 90inline void 91heapStats::incUStats(void) 92{ 93 assert(U < A); 94 assert(U >= 0); 95 assert(A >= 0); 96 U++; 97 98#if HEAP_STATS 99 Umax = MAX(Umax, U); 100#endif 101 102 assert(U >= 0); 103 assert(A >= 0); 104} 105 106 107inline void 108heapStats::decStats(int updateU, int updateA) 109{ 110 assert(updateU >= 0); 111 assert(updateA >= 0); 112 assert(U <= A); 113 assert(U >= updateU); 114 assert(A >= updateA); 115 U -= updateU; 116 A -= updateA; 117 assert(U <= A); 118 assert(U >= 0); 119 assert(A >= 0); 120} 121 122 123inline void 124heapStats::decUStats(int &Uout, int &Aout) 125{ 126 assert(U <= A); 127 assert(U > 0); 128 assert(A >= 0); 129 U--; 130 Uout = U; 131 Aout = A; 132 assert(U >= 0); 133 assert(A >= 0); 134} 135 136 137inline void 138heapStats::decUStats(void) 139{ 140 assert(U <= A); 141 assert(U > 0); 142 assert(A >= 0); 143 U--; 144} 145 146 147inline void 148heapStats::getStats(int &Uout, int &Aout) 149{ 150 assert(U >= 0); 151 assert(A >= 0); 152 Uout = U; 153 Aout = A; 154 assert(U <= A); 155 assert(U >= 0); 156 assert(A >= 0); 157} 158 159 160#if HEAP_STATS 161inline int 162heapStats::getUmax(void) 163{ 164 return Umax; 165} 166 167 168inline int 169heapStats::getAmax(void) 170{ 171 return Amax; 172} 173#endif // HEAP_STATS 174 175#endif // _HEAPSTATS_H_ 176