27 #ifndef DUMPMEMORY_HPP_
28 #define DUMPMEMORY_HPP_ 1
42 class DumpMemoryAllocation;
52 void*
operator new(
size_t size);
53 void operator delete(
void* p);
80 static void*
reallocate(
void* src,
size_t len1,
size_t len2);
95 #if defined(ENABLE_MEMCHECK)
96 std::vector<DumpMemoryAllocation*> _allocs;
112 #if defined(ENABLE_MEMCHECK)
114 void check_canaries();
184 new ((
void*) p) T(value);
204 #if defined(ENABLE_MEMCHECK)
205 class DumpMemoryAllocation {
211 DumpMemoryAllocation() : _size(0), _mem(NULL) {}
212 DumpMemoryAllocation(
size_t size,
void* mem) : _size(size), _mem(mem) {}
213 ~DumpMemoryAllocation() {};
215 inline size_t get_size()
const {
return _size; }
216 inline void* get_mem()
const {
return _mem; }
228 inline void* DumpClass::operator
new(
size_t size)
233 inline void DumpClass::operator
delete(
void* p)
256 size_t alignedsize =
size;
258 #if defined(ENABLE_MEMCHECK)
259 alignedsize += 2 * MEMORY_CANARY_SIZE;
265 void* p = dma->
allocate(alignedsize);
268 dm->
_used += alignedsize;
284 if (dmb == NULL || size > dmb->
get_free()) {
296 #if defined(ENABLE_MEMCHECK)
298 size_t origsize = size - 2 * MEMORY_CANARY_SIZE;
302 p = ((uint8_t *) p) + MEMORY_CANARY_SIZE;
306 DumpMemoryAllocation* dma =
new DumpMemoryAllocation(origsize, p);
308 _allocs.push_back(dma);
312 pm = ((uint8_t *) p) - MEMORY_CANARY_SIZE;
314 for (
int i = 0;
i < MEMORY_CANARY_SIZE; ++
i)
315 pm[
i] =
i + MEMORY_CANARY_FIRST_BYTE;
317 pm = ((uint8_t *) p) + dma->get_size();
319 for (
int i = 0;
i < MEMORY_CANARY_SIZE; ++
i)
320 pm[
i] =
i + MEMORY_CANARY_FIRST_BYTE;
370 #define DNEW(type) ((type*) DumpMemory::allocate(sizeof(type)))
371 #define DMNEW(type,num) ((type*) DumpMemory::allocate(sizeof(type) * (num)))
372 #define DMREALLOC(ptr,type,num1,num2) ((type*) DumpMemory::reallocate((ptr), sizeof(type) * (num1), sizeof(type) * (num2)))
374 #endif // DUMPMEMORY_HPP_
pointer allocate(size_type n, void *=0)
DumpMemoryArea(size_t size=0)
Allocate a new dump memory area.
All classes intended to be allocated on dump memory should extend this base class to inherit the appr...
static void * memset(void *s, int c, size_t n)
std::vector< DumpMemoryBlock * > _blocks
List of memory blocks in this area.
DumpMemoryAllocator< U > other
void remove_area(DumpMemoryArea *dma)
Remove the given dump area from the area list.
void construct(pointer p, const T &value)
std::ptrdiff_t difference_type
Allocator for the dump memory.
DumpMemoryArea * get_current_area() const
DumpMemoryAllocator(const DumpMemoryAllocator &)
void deallocate(pointer p, size_type n)
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
void * allocate(size_t size)
DumpMemoryBlock(size_t size=0)
Checks canaries in this dump memory area.
pointer reallocate(pointer p, size_type old_sz, size_type new_sz)
const T & const_reference
size_t _used
Used memory in the current memory block.
JNIEnv jthread jobject jclass jlong size
size_t _size
Size of the current memory block.
~DumpMemoryArea()
Release all dump memory blocks in the current dump area.
size_t _size
Size of the dump areas in this dump memory.
DumpMemoryBlock * get_current_block() const
size_t _size
Size of the current memory block.
This file contains the statistics framework.
static void * reallocate(void *src, size_t len1, size_t len2)
Stupid realloc implementation for dump memory.
void add_size(size_t size)
size_t _used
Used memory in this dump memory.
size_t _used
Used memory in the current memory block.
~DumpMemoryBlock()
Release the memory block for the dump memory block.
static threadobject * thread_get_current()
Return the threadobject for the current thread.
void * _block
List of memory blocks in this area.
DumpMemoryAllocator(const DumpMemoryAllocator< U > &)
static void * allocate(size_t size)
std::list< DumpMemoryArea * > _areas
Pointer to the current dump area.
#define MEMORY_ALIGN(pos, size)
DumpMemory()
Allocate a new thread-local dump memory structure.
DumpMemoryBlock * allocate_new_block(size_t size)
Allocate a dump memory block for the current dump memory area.
DumpMemory * _dumpmemory
Dump memory structure.
Thread-local dump memory structure.
void * allocate(size_t size)
Allocate memory in the current dump memory area.
static const size_t DEFAULT_SIZE
void add_area(DumpMemoryArea *dma)
Add the given dump area to the area list.
static DumpMemory * get_current()