00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _PROCESSHEAP_H_
00035 #define _PROCESSHEAP_H_
00036
00037 #include "config.h"
00038
00039 #include <stdio.h>
00040
00041 #include "arch-specific.h"
00042 #include "hoardheap.h"
00043 #include "threadheap.h"
00044
00045 #if HEAP_LOG
00046 #include "memstat.h"
00047 #include "log.h"
00048 #endif
00049
00050 class persistentHeap;
00051
00052 class processHeap : public hoardHeap {
00053
00054 public:
00055
00056
00057
00058 enum { REFILL_NUMBER_OF_SUPERBLOCKS = 16 };
00059
00060 processHeap (persistentHeap *persistentHeap);
00061
00062 ~processHeap (void) {
00063 #if HEAP_STATS
00064 stats();
00065 #endif
00066 }
00067
00068
00069 void free (void * ptr);
00070
00071
00072 void stats (void);
00073
00074
00075 inline int getHeapIndex (void);
00076
00077
00078 inline threadHeap& getHeap (int i);
00079
00080
00081 inline superblock * acquire (const int c,
00082 hoardHeap * dest);
00083
00084
00085 inline void release (superblock * sb);
00086
00087 #if HEAP_LOG
00088
00089 inline Log<MemoryRequest>& getLog (int i);
00090 #endif
00091
00092 #if HEAP_FRAG_STATS
00093
00094 void setAllocated (int requestedSize,
00095 int actualSize);
00096
00097
00098 void setDeallocated (int requestedSize,
00099 int actualSize);
00100
00101
00102
00103 inline int getFragmentation (void);
00104
00105 int getMaxAllocated (void) {
00106 return _maxAllocated;
00107 }
00108
00109 int getInUseAtMaxAllocated (void) {
00110 return _inUseAtMaxAllocated;
00111 }
00112
00113 int getMaxRequested (void) {
00114 return _maxRequested;
00115 }
00116
00117 #endif
00118
00119 private:
00120
00121
00122
00123 inline void lock (void) {
00124 hoardHeap::lock();
00125 }
00126
00127 inline void unlock (void) {
00128 hoardHeap::unlock();
00129 }
00130
00131
00132 processHeap (const processHeap&);
00133 const processHeap& operator= (const processHeap&);
00134
00135
00136 threadHeap theap[MAX_HEAPS];
00137
00138
00139 persistentHeap *_persistentHeap;
00140
00141 #if HEAP_FRAG_STATS
00142
00143
00144
00145
00146 int _currentAllocated;
00147 int _currentRequested;
00148 int _maxAllocated;
00149 int _maxRequested;
00150 int _inUseAtMaxAllocated;
00151 int _fragmentation;
00152
00153
00154 hoardLockType _statsLock;
00155 #endif
00156
00157 #if HEAP_LOG
00158 Log<MemoryRequest> _log[MAX_HEAPS + 1];
00159 #endif
00160
00161
00162 hoardLockType _bufferLock;
00163
00164 char * _buffer;
00165 int _bufferCount;
00166 };
00167
00168
00169 threadHeap& processHeap::getHeap (int i)
00170 {
00171 assert (i >= 0);
00172 assert (i < MAX_HEAPS);
00173 return theap[i];
00174 }
00175
00176
00177 #if HEAP_LOG
00178 Log<MemoryRequest>& processHeap::getLog (int i)
00179 {
00180 assert (i >= 0);
00181 assert (i < MAX_HEAPS + 1);
00182 return _log[i];
00183 }
00184 #endif
00185
00186
00187
00188
00189 static inline int lg (int num)
00190 {
00191 assert (num > 0);
00192 int power = 0;
00193 int n = 1;
00194
00195 while (n < num) {
00196 n <<= 1;
00197 power++;
00198 }
00199 return power;
00200 }
00201
00202
00203
00204 int processHeap::getHeapIndex (void) {
00205
00206 int tid = hoardGetThreadID() & MAX_HEAPS_MASK;
00207 assert (tid < MAX_HEAPS);
00208 return tid;
00209 }
00210
00211
00212 superblock * processHeap::acquire (const int,
00213 hoardHeap *)
00214 {
00215 assert(0);
00216 return NULL;
00217 }
00218
00219
00220
00221 void processHeap::release (superblock *)
00222 {
00223 assert(0);
00224 }
00225
00226
00227 #endif // _PROCESSHEAP_H_