Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
memory.c File Reference
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "defs.h"
#include "mempool.h"
#include "tracing.h"
#include "erglob.h"
Include dependency graph for memory.c:

Go to the source code of this file.

Classes

struct  mem_block
struct  mem_large_block
struct  int_list
struct  mem_stat
struct  mem_pool_blocks
struct  mem_pure_stack

Defines

#define MEM_POOL_INIT_IN_PROGRESS   (-1)
#define BLOCK_SIZE   0x2000
#define MIN_LARGE_BLOCK_SIZE   0x800
#define ZAP_ON_FREE   (1)
#define MEM_BLOCK_avail(x)   ((x)->avail)
#define MEM_BLOCK_ptr(x)   ((x)->ptr)
#define MEM_BLOCK_rest(x)   ((x)->rest)
#define MEM_BLOCK_first_ptr(x)   (MEM_PTR) (((char *) (x)) + PAD_TO_ALIGN(sizeof(MEM_BLOCK)))
#define MEM_LARGE_BLOCK_next(x)   ((x)->next)
#define MEM_LARGE_BLOCK_prev(x)   ((x)->prev)
#define MEM_LARGE_BLOCK_base(x)   ((x)->base)
#define MEM_LARGE_BLOCK_ptr(x)   ((x)->ptr)
#define MEM_LARGE_BLOCK_OVERHEAD   (PAD_TO_ALIGN(sizeof(MEM_LARGE_BLOCK)))
#define INT_LIST_first(x)   ((x)->first)
#define INT_LIST_rest(x)   ((x)->rest)
#define MEM_STAT_file(x)   ((x)->file)
#define MEM_STAT_line(x)   ((x)->line)
#define MEM_STAT_total(x)   ((x)->total)
#define MEM_STAT_current(x)   ((x)->current)
#define MEM_STAT_max_t(x)   ((x)->max_t)
#define MEM_STAT_max_s(x)   ((x)->max_s)
#define MEM_STAT_last(x)   ((x)->last)
#define MEM_STAT_last_grew(x)   ((x)->last_grew)
#define MEM_STAT_last_shrank(x)   ((x)->last_shrank)
#define MEM_STAT_count(x)   ((x)->count)
#define MEM_STAT_hash_list_rest(x)   ((x)->hash_list_rest)
#define MEM_STAT_pool_list_rest(x)   ((x)->pool_list_rest)
#define MEM_STAT_saved_current(x)   ((x)->saved_current)
#define MEM_STAT_pool(x)   ((x)->pool)
#define MEM_POOL_BLOCKS_block(x)   ((x)->block)
#define MEM_POOL_BLOCKS_large_block(x)   ((x)->large_block)
#define MEM_POOL_BLOCKS_base_block(x)   ((x)->base_block)
#define MEM_POOL_BLOCKS_base_ptr(x)   ((x)->base_ptr)
#define MEM_POOL_BLOCKS_base_avail(x)   ((x)->base_avail)
#define MEM_POOL_BLOCKS_rest(x)   ((x)->rest)
#define MEM_PURE_STACK_last_alloc(x)   ((x)->last_alloc)
#define MEM_PURE_STACK_prev_stack(x)   ((x)->prev_stack)
#define MEM_POOL_last_alloc(x)   MEM_PURE_STACK_last_alloc(MEM_POOL_pure_stack(x))
#define MEM_POOL_prev_stack(x)   MEM_PURE_STACK_prev_stack(MEM_POOL_pure_stack(x))
#define MAGIC_NUM   0xabcd
#define MEM_POOL_name(x)   ((x)->name)
#define MEM_POOL_blocks(x)   ((x)->blocks)
#define MEM_POOL_bz(x)   ((x)->bz)
#define MEM_POOL_rest(x)   ((x)->rest)
#define MEM_POOL_pure_stack(x)   ((x)->pure_stack)
#define MEM_POOL_frozen(x)   ((x)->frozen)
#define MEM_POOL_magic_num(x)   ((x)->magic_num)
#define MEM_POOL_alloc_site_list(x)   ((x)->alloc_site_list)
#define MEM_POOL_block(x)   MEM_POOL_BLOCKS_block(MEM_POOL_blocks(x))
#define MEM_POOL_large_block(x)   MEM_POOL_BLOCKS_large_block(MEM_POOL_blocks(x))
#define PAD_TO_ALIGN(size)   (((size) + 7) & (~0U << 3))
#define N_BUCKETS   503

Typedefs

typedef struct mem_large_block MEM_LARGE_BLOCK
typedef struct int_list INT_LIST
typedef INT(* QSORT_FUNC )(const void *, const void *)

Functions

static void MEM_LARGE_BLOCK_zap (MEM_LARGE_BLOCK *block)
static void MEM_LARGE_BLOCK_free (MEM_LARGE_BLOCK *block)
static MEM_LARGE_BLOCKMEM_LARGE_BLOCK_realloc (MEM_LARGE_BLOCK *old_block, INT64 new_size)
static UINT32 Hash (INT32 line, const char *file)
static MEM_STATHash_Get (UINT32 hn, MEM_POOL *pool, INT32 line, const char *file)
static void Site_Account_Alloc (MEM_POOL *pool, size_t old_size, size_t new_size)
static void Site_Account_Pop (MEM_POOL *pool)
static void Site_Account_Push (MEM_POOL *pool)
static INT32 Field_Size (INT32 i)
static INT MEM_STAT_Sort (MEM_STAT **as1p, MEM_STAT **as2p)
static BOOL MEM_STAT_In_List (MEM_POOL *list, MEM_POOL *pool)
INT32 MEM_POOL_Report (MEM_POOL *pool, INT32 used_total)
void MEM_Trace (void)
void Trace_Memory_Allocation (const INT phase, const char *const pname)
void MEM_Tracing_Enable (void)
static MEM_PTR Allocate_Block (MEM_POOL *pool)
static MEM_PTR Allocate_Large_Block (MEM_POOL *pool, INT32 size)
static MEM_PTR Raw_Allocate (MEM_POOL *pool, INT32 size)
MEM_PTR MEM_POOL_Alloc_P (MEM_POOL *pool, size_t size)
MEM_PTR MEM_POOL_Realloc_P (MEM_POOL *pool, MEM_PTR old_block, size_t old_size, size_t new_size)
void MEM_POOL_Push_P (MEM_POOL *pool)
void MEM_POOL_Push_Freeze_P (MEM_POOL *pool)
void MEM_POOL_Pop_P (MEM_POOL *pool)
void MEM_POOL_Pop_Unfreeze_P (MEM_POOL *pool)
void MEM_POOL_Set_Default (MEM_POOL *pool)
void MEM_POOL_FREE (MEM_POOL *pool, void *data)
static void trace_initialized_pool (char *msg, char *pname)
void MEM_POOL_Delete (MEM_POOL *pool)
void MEM_POOL_Initialize_P (MEM_POOL *pool, const char *name, BOOL memzero)
void MEM_Initialize (void)
MEM_PTR Realloc_Clear (MEM_PTR ptr, INT32 new_size, INT32 old_size)
MEM_PTR Re_Calloc (MEM_PTR ptr, INT32 new_nelem, INT32 elsize, INT32 old_nelem)

Variables

MEM_POOL MEM_local_pool
MEM_POOL MEM_src_pool
MEM_POOL MEM_pu_pool
MEM_POOL MEM_phase_pool
MEM_POOLMEM_local_pool_ptr = &MEM_local_pool
MEM_POOLMEM_src_pool_ptr = &MEM_src_pool
MEM_POOLMEM_pu_pool_ptr = &MEM_pu_pool
MEM_POOLMEM_phase_pool_ptr = &MEM_phase_pool
MEM_POOL MEM_local_nz_pool
MEM_POOL MEM_src_nz_pool
MEM_POOL MEM_pu_nz_pool
MEM_POOL MEM_phase_nz_pool
MEM_POOLMEM_local_nz_pool_ptr = &MEM_local_nz_pool
MEM_POOLMEM_src_nz_pool_ptr = &MEM_src_nz_pool
MEM_POOLMEM_pu_nz_pool_ptr = &MEM_pu_nz_pool
MEM_POOLMEM_phase_nz_pool_ptr = &MEM_phase_nz_pool
static INT_LISTfree_int_lists
BOOL purify_pools = FALSE
static BOOL purify_pools_trace = FALSE
static BOOL purify_pools_trace_x = FALSE
static MEM_POOL_BLOCKSfree_mem_pool_blocks_list
static MEM_POOL_BLOCKS overhead_blocks
static MEM_POOL mem_overhead_pool
static MEM_POOLThe_Default_Mem_Pool
static BOOL mem_tracing_enabled = FALSE
static MEM_POOLinitialized_pools
static MEM_STATcall_site_hash_tab [N_BUCKETS]
const char * special_address = NULL
const char * special_address_owner = "NOBODY"

Define Documentation

#define BLOCK_SIZE   0x2000

Definition at line 57 of file memory.c.

Referenced by Allocate_Block().

#define INT_LIST_first (   x)    ((x)->first)

Definition at line 204 of file memory.c.

Referenced by Site_Account_Pop(), and Site_Account_Push().

#define INT_LIST_rest (   x)    ((x)->rest)

Definition at line 205 of file memory.c.

Referenced by Site_Account_Pop(), and Site_Account_Push().

#define MEM_BLOCK_avail (   x)    ((x)->avail)

Definition at line 123 of file memory.c.

Referenced by Allocate_Block(), MEM_POOL_Pop_P(), MEM_POOL_Push_P(), and Raw_Allocate().

#define MEM_BLOCK_first_ptr (   x)    (MEM_PTR) (((char *) (x)) + PAD_TO_ALIGN(sizeof(MEM_BLOCK)))

Definition at line 127 of file memory.c.

Referenced by Allocate_Block(), and MEM_POOL_Pop_P().

#define MEM_BLOCK_ptr (   x)    ((x)->ptr)

Definition at line 124 of file memory.c.

Referenced by Allocate_Block(), MEM_POOL_Pop_P(), MEM_POOL_Push_P(), and Raw_Allocate().

#define MEM_BLOCK_rest (   x)    ((x)->rest)

Definition at line 125 of file memory.c.

Referenced by Allocate_Block(), and MEM_POOL_Pop_P().

#define MEM_LARGE_BLOCK_base (   x)    ((x)->base)
#define MEM_LARGE_BLOCK_next (   x)    ((x)->next)

Definition at line 143 of file memory.c.

Referenced by Allocate_Large_Block(), MEM_POOL_FREE(), MEM_POOL_Pop_P(), and MEM_POOL_Realloc_P().

Definition at line 147 of file memory.c.

Referenced by Allocate_Large_Block(), MEM_POOL_FREE(), and MEM_POOL_Realloc_P().

#define MEM_LARGE_BLOCK_prev (   x)    ((x)->prev)

Definition at line 144 of file memory.c.

Referenced by Allocate_Large_Block(), MEM_POOL_FREE(), and MEM_POOL_Realloc_P().

#define MEM_LARGE_BLOCK_ptr (   x)    ((x)->ptr)
#define MEM_POOL_alloc_site_list (   x)    ((x)->alloc_site_list)

Definition at line 381 of file memory.c.

Referenced by Allocate_Block(), and Raw_Allocate().

#define MEM_POOL_BLOCKS_base_avail (   x)    ((x)->base_avail)

Definition at line 305 of file memory.c.

Referenced by MEM_POOL_Pop_P(), and MEM_POOL_Push_P().

#define MEM_POOL_BLOCKS_base_block (   x)    ((x)->base_block)

Definition at line 303 of file memory.c.

Referenced by MEM_POOL_Pop_P(), and MEM_POOL_Push_P().

#define MEM_POOL_BLOCKS_base_ptr (   x)    ((x)->base_ptr)

Definition at line 304 of file memory.c.

Referenced by MEM_POOL_Pop_P(), and MEM_POOL_Push_P().

#define MEM_POOL_BLOCKS_block (   x)    ((x)->block)

Definition at line 301 of file memory.c.

Referenced by MEM_POOL_Pop_P(), and MEM_POOL_Push_P().

#define MEM_POOL_BLOCKS_large_block (   x)    ((x)->large_block)

Definition at line 302 of file memory.c.

Referenced by MEM_POOL_Pop_P(), and MEM_POOL_Push_P().

#define MEM_POOL_BLOCKS_rest (   x)    ((x)->rest)

Definition at line 306 of file memory.c.

Referenced by MEM_POOL_Delete(), MEM_POOL_Pop_P(), and MEM_POOL_Push_P().

#define MEM_POOL_bz (   x)    ((x)->bz)
#define MEM_POOL_frozen (   x)    ((x)->frozen)
#define MEM_POOL_INIT_IN_PROGRESS   (-1)

Definition at line 50 of file memory.c.

Referenced by MEM_POOL_Initialize_P(), and MEM_POOL_Push_P().

Definition at line 361 of file memory.c.

Referenced by MEM_POOL_Pop_P().

#define MEM_POOL_pure_stack (   x)    ((x)->pure_stack)
#define MEM_POOL_rest (   x)    ((x)->rest)
#define MEM_PURE_STACK_last_alloc (   x)    ((x)->last_alloc)

Definition at line 357 of file memory.c.

Referenced by MEM_POOL_FREE(), MEM_POOL_Push_P(), and MEM_POOL_Realloc_P().

#define MEM_PURE_STACK_prev_stack (   x)    ((x)->prev_stack)

Definition at line 358 of file memory.c.

Referenced by MEM_POOL_FREE(), MEM_POOL_Push_P(), and MEM_POOL_Realloc_P().

#define MEM_STAT_count (   x)    ((x)->count)

Definition at line 269 of file memory.c.

Referenced by MEM_POOL_Report(), and Site_Account_Alloc().

#define MEM_STAT_current (   x)    ((x)->current)

Definition at line 263 of file memory.c.

Referenced by MEM_POOL_Report(), Site_Account_Alloc(), Site_Account_Pop(), and Site_Account_Push().

#define MEM_STAT_file (   x)    ((x)->file)

Definition at line 260 of file memory.c.

Referenced by Hash_Get(), MEM_POOL_Report(), and Site_Account_Alloc().

#define MEM_STAT_hash_list_rest (   x)    ((x)->hash_list_rest)

Definition at line 270 of file memory.c.

Referenced by Hash_Get(), and Site_Account_Alloc().

#define MEM_STAT_last (   x)    ((x)->last)

Definition at line 266 of file memory.c.

Referenced by Site_Account_Alloc().

#define MEM_STAT_last_grew (   x)    ((x)->last_grew)

Definition at line 267 of file memory.c.

Referenced by MEM_POOL_Report(), and Site_Account_Alloc().

#define MEM_STAT_last_shrank (   x)    ((x)->last_shrank)

Definition at line 268 of file memory.c.

Referenced by MEM_POOL_Report(), and Site_Account_Alloc().

#define MEM_STAT_line (   x)    ((x)->line)

Definition at line 261 of file memory.c.

Referenced by Hash_Get(), MEM_POOL_Report(), and Site_Account_Alloc().

#define MEM_STAT_max_s (   x)    ((x)->max_s)

Definition at line 265 of file memory.c.

Referenced by MEM_POOL_Report(), and Site_Account_Alloc().

#define MEM_STAT_max_t (   x)    ((x)->max_t)

Definition at line 264 of file memory.c.

Referenced by MEM_POOL_Report(), MEM_STAT_Sort(), and Site_Account_Alloc().

#define MEM_STAT_pool (   x)    ((x)->pool)

Definition at line 273 of file memory.c.

Referenced by Hash_Get(), and Site_Account_Alloc().

#define MEM_STAT_pool_list_rest (   x)    ((x)->pool_list_rest)

Definition at line 271 of file memory.c.

Referenced by MEM_POOL_Report(), Site_Account_Alloc(), Site_Account_Pop(), and Site_Account_Push().

#define MEM_STAT_saved_current (   x)    ((x)->saved_current)

Definition at line 272 of file memory.c.

Referenced by Site_Account_Pop(), and Site_Account_Push().

#define MEM_STAT_total (   x)    ((x)->total)

Definition at line 262 of file memory.c.

Referenced by MEM_POOL_Report(), and Site_Account_Alloc().

#define MIN_LARGE_BLOCK_SIZE   0x800

Definition at line 62 of file memory.c.

Referenced by MEM_POOL_Realloc_P(), and Raw_Allocate().

#define N_BUCKETS   503

Definition at line 429 of file memory.c.

Referenced by Hash().

#define PAD_TO_ALIGN (   size)    (((size) + 7) & (~0U << 3))

Definition at line 416 of file memory.c.

Referenced by Allocate_Block(), MEM_POOL_Alloc_P(), and MEM_POOL_Realloc_P().

#define ZAP_ON_FREE   (1)

Definition at line 67 of file memory.c.


Typedef Documentation

typedef struct int_list INT_LIST

Definition at line 195 of file memory.c.

Definition at line 135 of file memory.c.

typedef INT(* QSORT_FUNC)(const void *, const void *)

Definition at line 671 of file memory.c.


Function Documentation

static MEM_PTR Allocate_Block ( MEM_POOL pool) [static]

Definition at line 948 of file memory.c.

References block, BLOCK_SIZE, EC_No_Mem, ErrMsg(), fprintf(), MEM_BLOCK_avail, MEM_BLOCK_first_ptr, MEM_BLOCK_ptr, MEM_BLOCK_rest, MEM_POOL_block, MEM_POOL_bz, MEM_POOL_name, NULL, PAD_TO_ALIGN, and TFile.

Referenced by Raw_Allocate().

Here is the call graph for this function:

static MEM_PTR Allocate_Large_Block ( MEM_POOL pool,
INT32  size 
) [static]
static INT32 Field_Size ( INT32  i) [static]

Definition at line 645 of file memory.c.

Referenced by MEM_POOL_Report().

static MEM_STAT* Hash_Get ( UINT32  hn,
MEM_POOL pool,
INT32  line,
const char *  file 
) [static]

Definition at line 479 of file memory.c.

References MEM_STAT_file, MEM_STAT_hash_list_rest, MEM_STAT_line, MEM_STAT_pool, NULL, and pool.

Referenced by Site_Account_Alloc().

void MEM_Initialize ( void  )

Definition at line 1861 of file memory.c.

References DevWarn(), FALSE, getenv(), MEM_POOL_Initialize, MEM_POOL_Push, purify_pools, purify_pools_trace, purify_pools_trace_x, and TRUE.

Referenced by main(), and sgi_cmd_line().

Here is the call graph for this function:

static void MEM_LARGE_BLOCK_free ( MEM_LARGE_BLOCK block) [static]

Definition at line 168 of file memory.c.

References free(), and MEM_LARGE_BLOCK_zap().

Referenced by MEM_POOL_FREE(), and MEM_POOL_Pop_P().

Here is the call graph for this function:

static MEM_LARGE_BLOCK* MEM_LARGE_BLOCK_realloc ( MEM_LARGE_BLOCK old_block,
INT64  new_size 
) [static]

Definition at line 175 of file memory.c.

References MEM_LARGE_BLOCK_base, MEM_LARGE_BLOCK_ptr, MEM_LARGE_BLOCK_zap(), new_block(), and NULL.

Referenced by MEM_POOL_Realloc_P().

Here is the call graph for this function:

static void MEM_LARGE_BLOCK_zap ( MEM_LARGE_BLOCK block) [static]

Definition at line 161 of file memory.c.

References MEM_LARGE_BLOCK_base, MEM_LARGE_BLOCK_ptr, and NULL.

Referenced by MEM_LARGE_BLOCK_free(), and MEM_LARGE_BLOCK_realloc().

Definition at line 1584 of file memory.c.

References FALSE, FmtAssert, Is_True, MAGIC_NUM, MEM_POOL_frozen, MEM_POOL_magic_num, MEM_POOL_name, MEM_POOL_Pop_P(), purify_pools_trace_x, and TRUE.

Here is the call graph for this function:

void MEM_POOL_Push_Freeze_P ( MEM_POOL pool)

Definition at line 1439 of file memory.c.

References FALSE, FmtAssert, Is_True, MAGIC_NUM, MEM_POOL_frozen, MEM_POOL_magic_num, MEM_POOL_name, MEM_POOL_Push_P(), purify_pools_trace_x, and TRUE.

Here is the call graph for this function:

void MEM_POOL_Set_Default ( MEM_POOL pool)

Definition at line 1600 of file memory.c.

References pool.

Referenced by BINARY_TREE< BINARY_NODE >::~BINARY_TREE().

static BOOL MEM_STAT_In_List ( MEM_POOL list,
MEM_POOL pool 
) [static]

Definition at line 695 of file memory.c.

References FALSE, MEM_POOL_rest, NULL, and TRUE.

Referenced by MEM_POOL_Delete(), and MEM_POOL_Initialize_P().

static INT MEM_STAT_Sort ( MEM_STAT **  as1p,
MEM_STAT **  as2p 
) [static]

Definition at line 674 of file memory.c.

References MEM_STAT_max_t.

Referenced by MEM_POOL_Report().

void MEM_Trace ( void  )

Definition at line 852 of file memory.c.

References fprintf(), MEM_POOL_Report(), MEM_POOL_rest, NULL, pool, and TFile.

Referenced by Ipl_Processing(), main(), and Trace_Memory_Allocation().

Here is the call graph for this function:

void MEM_Tracing_Enable ( void  )

Definition at line 922 of file memory.c.

References mem_tracing_enabled, and TRUE.

Referenced by main().

static MEM_PTR Raw_Allocate ( MEM_POOL pool,
INT32  size 
) [static]

Definition at line 1043 of file memory.c.

References Allocate_Block(), Allocate_Large_Block(), MEM_BLOCK_avail, MEM_BLOCK_ptr, MEM_POOL_block, MIN_LARGE_BLOCK_SIZE, NULL, result, and size.

Referenced by MEM_POOL_Alloc_P(), and MEM_POOL_Realloc_P().

Here is the call graph for this function:

MEM_PTR Re_Calloc ( MEM_PTR  ptr,
INT32  new_nelem,
INT32  elsize,
INT32  old_nelem 
)

Definition at line 2000 of file memory.c.

References Realloc_Clear().

Here is the call graph for this function:

MEM_PTR Realloc_Clear ( MEM_PTR  ptr,
INT32  new_size,
INT32  old_size 
)

Definition at line 1955 of file memory.c.

References EC_No_Mem, ErrMsg(), NULL, and result.

Referenced by Re_Calloc().

Here is the call graph for this function:

static void trace_initialized_pool ( char *  msg,
char *  pname 
) [static]

Definition at line 1685 of file memory.c.

References initialized_pools, MEM_POOL_name, MEM_POOL_rest, and NULL.

void Trace_Memory_Allocation ( const INT  phase,
const char *const  pname 
)

Definition at line 900 of file memory.c.

References DBar, fprintf(), Get_Trace(), MEM_Trace(), TFile, and TKIND_ALLOC.

Here is the call graph for this function:


Variable Documentation

Definition at line 431 of file memory.c.

Definition at line 207 of file memory.c.

Referenced by Site_Account_Pop(), and Site_Account_Push().

Initial value:

Definition at line 423 of file memory.c.

Referenced by MEM_POOL_Delete(), MEM_POOL_Initialize_P(), and trace_initialized_pool().

Definition at line 92 of file memory.c.

Definition at line 97 of file memory.c.

Referenced by Write_PU_Info().

Definition at line 78 of file memory.c.

Referenced by Ipl_Processing(), and IR_reader_init().

Definition at line 83 of file memory.c.

Initial value:
 
{
    "memory overhead",
    &overhead_blocks,
    NULL,
    NULL,
    TRUE,
    FALSE,
    MAGIC_NUM,
    NULL
}

Definition at line 398 of file memory.c.

Definition at line 95 of file memory.c.

Definition at line 100 of file memory.c.

Definition at line 81 of file memory.c.

Definition at line 86 of file memory.c.

Definition at line 93 of file memory.c.

Referenced by main().

Definition at line 98 of file memory.c.

Definition at line 394 of file memory.c.

Definition at line 932 of file memory.c.

const char* special_address_owner = "NOBODY"

Definition at line 933 of file memory.c.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines