Path: blob/master/src/java.desktop/share/native/common/awt/debug/debug_mem.h
41171 views
/*1* Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Debug Memory Manager27*28* - inits allocated memory to predefined byte to expose uninitialized variables29* - fills freed memory with predefined byte to expose dangling pointers30* - catches under/overwrites with 'guard' bytes around allocated blocks31* - tags blocks with the file name and line number where they were allocated32* - reports unfreed blocks to help find memory leaks33*34*/3536#if !defined(_DEBUGMEM_H)37#define _DEBUGMEM_H3839#if defined(__cplusplus)40extern "C" {41#endif4243#if defined(DEBUG)4445#include "debug_util.h"4647/* prototype for allocation callback function */48typedef void * (*DMEM_ALLOCFN)(size_t size);4950/* prototype for deallocation callback function */51typedef void (*DMEM_FREEFN)(void * pointer);5253/* prototype for pointer validation function */54typedef dbool_t (*DMEM_CHECKPTRFN)(void * ptr, size_t size);5556/* Debug memory manager global state */57/* DO NOT REFERENCE this structure in code, it is only exported */58/* to ease it's use inside a source level debugger */59typedef struct DMemState {60DMEM_ALLOCFN pfnAlloc; /* block allocate callback */61DMEM_FREEFN pfnFree; /* block free callback */62DMEM_CHECKPTRFN pfnCheckPtr; /* pointer validation callback */63size_t biggestBlock; /* largest block allocated so far */64size_t maxHeap; /* maximum size of the debug heap */65size_t totalHeapUsed; /* total memory allocated so far */66dbool_t failNextAlloc; /* whether the next allocation fails (automatically resets)*/67int totalAllocs; /* total number of allocations so far */68} DMemState;6970/* Exported global var so you can view/change settings in the debugger */71extern const DMemState * DMemStatePtr;7273/* General memory manager functions */74extern void DMem_Initialize();75extern void DMem_Shutdown();76extern void * DMem_AllocateBlock(size_t size, const char * filename, int linenumber);77extern void DMem_FreeBlock(void *ptr);78extern void DMem_ReportLeaks();7980/* Routines to customize behaviour with callbacks */81extern void DMem_SetAllocCallback( DMEM_ALLOCFN pfn );82extern void DMem_SetFreeCallback( DMEM_FREEFN pfn );83extern void DMem_SetCheckPtrCallback( DMEM_CHECKPTRFN pfn );84extern void DMem_DisableMutex();8586#endif /* defined(DEBUG) */8788#if defined(__cplusplus)89} /* extern "C" */90#endif9192#endif /* _DEBUGMEM_H */939495