⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heapmanager.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef _HM
#define _HM
#include "sys_api.h"         /* for sysAssert */
#include "gc_protocol.h"
#include "finalize.h" 

/* --------- Convenience functions for accessing structures ------------- */
/* Large Objects */
//#define RegionSize(ud)   ((ud)->iRegionSize & ~0x03)
#define RegionSize(ud)   ((((ud)->iRegionSize & ~0x03)<BLOCKSIZE) ? BLOCKSIZE \
                         : ((ud)->iRegionSize & ~0x03) )
#define LeftChild(ud)    (ud)->u.udLargeObj.pLeftChild
#define RightChild(ud)   (ud)->u.udLargeObj.pRightChild
#define LLHeadOrNext(ud) (ud)->u.udLargeObj.pLLHeadOrNext
#define LLParent(ud)     RightChild(ud)
#define LLNext(ud)       LLHeadOrNext(ud)

/* Small Objects */
#define ChunkSize(ud)    ((ud)->iRegionSize & ~0x03)
#define PrevBlock(ud)    (ud)->u.udSmallObj.pPrevBlock
#define NextBlock(ud)    (ud)->u.udSmallObj.pNextBlock

#define NextChunk(iAddress) (* (long *) iAddress)
#if 0
#define SetChunkSize(ud, iSize) (ud)->iRegionSize = iSize
#endif
/* ibm.6790 */
#define SetChunkSize(ud, iSize) { \
int iSetBits=((long)(ud)->iRegionSize & 1) | iSize; \
(ud)->iRegionSize = iSetBits;  \
}

/* Write the region size into both the first and last header block associated
   with an object */
#define NUM_HDR_BLKS(iSize) ((int)((iSize + BLOCKSIZE - 1)/BLOCKSIZE))

#define GET_LAST_HDR_BLK(p, iSize) ((BlockStructPtr)((char *) p + \
                               sizeof(blockStruct)*(NUM_HDR_BLKS(iSize) - 1)))

/* define SetRegionSize(ud, iSize) (ud)->iRegionSize = iSize;*/
#define SetRegionSize(ud, iSize) { \
int iSetBits=((long)(ud)->iRegionSize & 3) | iSize; \
BlockStructPtr pLastHdr = GET_LAST_HDR_BLK((ud), iSize); \
(ud)->iRegionSize = iSetBits;  \
if (iSize > BLOCKSIZE) \
pLastHdr->iRegionSize = iSetBits; \
}


/******* Take this out on integration !!!!!! (already in gc_ibm.c) ***********/

/* Common to both small and large objects */
/* Allocated bit is LSB.  Partially filled bit is 2d bit */
#define GetAllocated(ptr)   ((ptr)->iRegionSize & 0x00000001)
/* For SetAllocated and ClearAllocated, update flags in the last header blk
   associated with an object if it is a large object with more than one hdr
   blk */
#ifdef OLD
#define SetAllocated(ptr)   ((ptr)->iRegionSize |= 0x00000001)
#define ClearAllocated(ptr) ((ptr)->iRegionSize &= 0xfffffffe)
#endif

#define SetAllocated(ptr) ((ptr)->iRegionSize |= 0x00000001); \
if ((ptr)->iRegionSize > BLOCKSIZE) \
{ int iLastHdrBlk = (int) GET_LAST_HDR_BLK((ptr), RegionSize(ptr)); \
	((BlockStructPtr)(iLastHdrBlk))->iRegionSize = \
	  (int)((BlockStructPtr)(iLastHdrBlk))->iRegionSize | 1; \
}


#define ClearAllocated(ptr) (((ptr)->iRegionSize) &= ~1); \
if ((ptr)->iRegionSize > BLOCKSIZE) \
{ int iLastHdrBlk = (int) GET_LAST_HDR_BLK((ptr), RegionSize(ptr)); \
	((BlockStructPtr)(iLastHdrBlk))->iRegionSize = \
	  (int)((BlockStructPtr)(iLastHdrBlk))->iRegionSize & ~1; \
}


#define GetInPartiallyFilledBlockBin(ptr) ((ptr)->iRegionSize &  0x00000002)
#define SetInPartiallyFilledBlockBin(ptr) ((ptr)->iRegionSize |= 0x00000002)
#define ClearInPartiallyFilledBlockBin(ptr) ((ptr)->iRegionSize &= 0xfffffffd)


/**************************************************************
 Multiple large objects of the same size will be hung off a node in the
   binary tree.  The start of this list will be pointed to by the pLLHeadOrNext
   pointer.  Elements in the link list will use this field as the next pointer.
   The strategy is as follows:
            Binary Tree Node                   Link List Node
            =====================              =========================
pLLHeadOrNext  Start of Link List or NULL       Next element in link list
pRightChild    Right Child                      Previous (parent)
pLeftChild     Left Child (or NULL)             ~0x0

***************************************************************/

#define LL_FLAG ((BlockStructPtr) ~0x0)
#define IS_REGULAR_NODE(ptr) (LLHeadOrNext(ptr) == (BlockStructPtr) NULL && \
                              LeftChild(ptr) != LL_FLAG)

#define IS_LL_NODE(ptr) (LeftChild(ptr) == LL_FLAG)

#define IS_LL_ROOT(ptr) (LLHeadOrNext(ptr) != (BlockStructPtr) NULL && \
                              LeftChild(ptr) != LL_FLAG)

/* Calculate the address of a chunk in a block of memory */
#define ChunkInBlock(pBlock, index, iSize) ((long *)((char *)(pBlock) + index*iSize))
/* Get the last chunk in a block.  The index is 1 less than the number of
   chunks which will fit into a block.  pFreeBlock is a header block. */
#define GetLastChunk(pFreeBlock) (ChunkInBlock(HEADER_TO_MEMORY(pFreeBlock), \
							 BLOCKSIZE/ChunkSize(pFreeBlock) - 1, \
							 ChunkSize(pFreeBlock)))

#define GETPARTIALBIN(iSize) (apPartiallyFilledBlockVector[(int) GetActualIndex(iSize)])

/* Routines to lock and unlock mutex associated with a bin for actual object */
/* size */
	
#define LOCK_ACTUALBIN_MUTEX(iSize) \
 (sysMonitorEnter(maActualBinMutex[(int) GetActualIndex(iSize)]))
#define UNLOCK_ACTUALBIN_MUTEX(iSize) \
  (sysMonitorExit(maActualBinMutex[(int) GetActualIndex(iSize)]))

#define LOCK_BIN(index,ee)   sysMonitorEnterQuicker(maActualBinMutex[index],SYSTHREAD(ee->thread))
#define UNLOCK_BIN(index,ee) sysMonitorExitQuicker (maActualBinMutex[index],SYSTHREAD(ee->thread))

  
	 /* TMR - mutex check*/
	 /*
#define LOCK_ACTUALBIN_MUTEX(iSize) \
 (pthread_mutex_lock(&(maActualBinMutex[(int) GetActualIndex(iSize)])) ? \
  errno : 0)

#define UNLOCK_ACTUALBIN_MUTEX(iSize) \
 (pthread_mutex_unlock(&(maActualBinMutex[(int) GetActualIndex(iSize)])) \
  ? errno :0 )
  */

     /* This may need to be updated if the bitmap or BLOCKSIZE changes */   /* Eitan */ 
#define BITMAP_BYTES_PER_BLOCK 256  
/* This is used for unrolling and scrambling in HMchunkBlock */    /* Eitan */
#define LINK_GAP 4                  
       
     /* #define BLOCKSIZE ((int) (getpagesize()))  */
#define BLOCKSIZE 4096
#define MAX_SMALL_OBJECT ((int)(BLOCKSIZE/2))

#define MAX_ALLOCATION_TRIES 3  /* Number of times to attempt synch GC */

#define NORMALIZE_HEAP(pHeapAddr) ((char *)(pHeapAddr) - (char *)heapbase)
#define NORMALIZE_HDR_BLK(pHdrBlkAddr) \
((char *)(pHdrBlkAddr) - (char *) vpHeaderBlkStart)
#define HEADER_TO_MEMORY1(pHeader) \
(void *)(((NORMALIZE_HDR_BLK(pHeader)/sizeof(blockStruct))*BLOCKSIZE) + (char *)heapbase)

#define HEADER_TO_MEMORY(pHeader) \
((void *)(((NORMALIZE_HDR_BLK(pHeader)>>4)<<12) + (char *) heapbase))

#define MEMORY_TO_HEADER1(pMem) \
((BlockStructPtr)((((char *) (pMem) - heapbase)/BLOCKSIZE)*sizeof(blockStruct) + (char *) vpHeaderBlkStart))

#define MEMORY_TO_HEADER(pMem) \
((BlockStructPtr)((((NORMALIZE_HEAP(pMem))>>12)<<4) + (char *) vpHeaderBlkStart))

//int nbrSweeps;


/* Change the definition here for MVS port */
/*
#define COMPARE_AND_SWAP(word_addr, old_val_addr, new_val) \
      (!_check_lock((atomic_p) word_addr, (int) old_val_addr, (int) new_val))
	  */
//#define ASSERT(assertion) if (assertion) ; else assert(assertion)
#define ASSERT(assertion) sysAssert(assertion)

/* Replace this with the JVM mechanism */
#define FATAL_ERROR(string) fprintf(stderr, "string\n"); \
 exit(-1)

typedef enum Childtype {SAME, LEFTCHILD, RIGHTCHILD} childtype;
#ifndef False   /*ibm.7179*/
typedef enum Boolean {False=0, True} boolean;
#endif   /*ibm.7179*/
typedef struct LargeObject *LargeObjPtr;
typedef struct SmallObject *SmallObjPtr;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -