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

📄 gc.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
📖 第 1 页 / 共 2 页
字号:

#define END_MAP_OVER_OBJECTS_FROM_START                 \
    } /* end for */                                     \
} /* end END_MAP_OVER_OBJECTS_FROM_START */


#else /************ PAGED HEAPS: ********************/

/* gc philosophy makes it necessary to detect if an arbitrary int is
 * (possibly) a handle or object ref.
 * A value is (possibly) valid if it is properly aligned, and it
 * points into a page that has a page map entry of the proper type.
 */
/* assumes ValidHorO already */
#define GetPageMapEntry(p)                                              \
             (page_map[((int)(p) - (int)mem_base) >> PTR_2_PAGE_SHIFT])

#define ValidObject(p)  ((((int)(p)) & (OBJECTGRAIN-1)) == 0 &&         \
             (void *)(p) >= mem_base &&                                 \
             (void *)(p) <  mem_top &&                                  \
             (GetPageMapEntry((p)).chunk_size > 0))
#define ValidHandle(p)  (((((int)(p)) & (HANDLEGRAIN-1)) == 0) &&       \
             ((void *)(p) >= mem_base) &&                               \
             ((void *)(p) <  mem_top) &&                                \
             (GetPageMapEntry((p)).chunk_size < 0))
/* ValidHorO() assumes OBJECTGRAIN == HANDLEGRAIN... */
#define ValidHorO(p)    ((((int)(p)) & (HANDLEGRAIN-1)) == 0 &&         \
             (void *)(p) >= mem_base &&                                 \
             (void *)(p) <  mem_top &&                                  \
             (GetPageMapEntry((p)).chunk_size != 0))

#define SetLimits() int SL_dufus = 0

/* assumes ValidHorO already */
#define ChunkBase(p)    (void *)                                        \
             (((int)(p) & ~(PAGE_ALIGNMENT - 1)) -                      \
              (GetPageMapEntry((p)).page_number << PTR_2_PAGE_SHIFT))

/* curHanBlkP must be set in advance!!! */
#define POP_FREE_HANDLE(hp)                                             \
    hp = (JHandle *)curHanBlkP->freePtr;                                \
    if (hp) {                                                           \
        curHanBlkP->freePtr = (unsigned char *)hp->methods;             \
    }

/* Can only be called within a MAP_OVER_HANDLES_FROM_START loop
 * - uses MOH_chunk instead of curHanBlkP for efficiency.
 */
#define PUSH_FREE_HANDLE(hp) \
    hp->methods = (struct methodtable *)MOH_chunk->freePtr; \
    MOH_chunk->freePtr = (unsigned char *)hp;

#define MARKINDEX(p)    (((int)(p) & (PAGE_ALIGNMENT - 1)) >> 7)
#define BITOFFSET(p)    ((((int)(p) & (PAGE_ALIGNMENT - 1)) >> 2) & 0x1e)

#define _MarkPtr(p, v)  (GetPageMapEntry(p).mark_bits[MARKINDEX(p)] |=     \
                         (v) << BITOFFSET(p))
#define _ClearMarkPtr(p, v) (GetPageMapEntry(p).mark_bits[MARKINDEX(p)] &= \
                             ~((v) << BITOFFSET(p)))
#define _IsMarked(p)    ((GetPageMapEntry(p).mark_bits[MARKINDEX(p)]       \
                          >> BITOFFSET(p)) & 3)

/* # of bytes of markbits we need per page: */
#define MARK_BITS_SIZE      ((PAGE_ALIGNMENT / (OBJECTGRAIN * BITSPERCHAR)) * 2)

/*
 * Part of Java memory management and garbage collection.
 *
 * This supports a discontiguous gcable heap, which is useful for the
 * Mac OS, or other platforms without good memory mapping support.
 *
 * CHUNKS:
 * Memory is requested from the OS in "Chunks" of n pages, which are
 * PAGE_ALIGNMENT aligned and sized. Handles and objects are allocated out of
 * different chunks.  When more memory is needed, additional chunks can be
 * allocated.  When chunks are free, they may be returned to  the OS.  Chunks
 * don't need to be contiguous.  Handle chunks and object chunks are linked
 * into seperate, doubly linked lists, which are sorted by chunk address.  On
 * platforms without real "memalign" support, there may be unaligned (wasted)
 * space that precedes the true chunk that we can use for something else
 * (markbits come to mind).
 */

/* fields marked ### MUST BE OBJECT AND/OR HANDLE GRAIN ALIGNED */
typedef struct CHUNK_BLK {      /* a chunk of pages */
    void* chunkHandle;          /* OS handle to this chunk */
    struct CHUNK_BLK *nextPtr;  /* ptr to next chunk header */
    struct CHUNK_BLK *prevPtr;  /* ptr to previous chunk header */
    long chunkFlags;            /* misc flags */
    long allocSize;             /* == (endPtr - startPtr)### */
    long freeCnt;               /* # of free bytes in this chunk */
    unsigned char *startPtr;    /* ptr to starting byte### */
    unsigned char *endPtr;      /* ptr past last byte### */
    unsigned char *freePtr;     /* ptr to first free space CANDIDATE
        * (may not really be free), or it might be a ptr to a free list
        * of objects, depending on phase of the moon.
        */
        /* users may modify start and end ptrs, but not this one: */
    unsigned char *physEndPtr;
#ifdef WASTED_SPACE_IN_LEADER
        /* WARNING:  clearLocalMarkBits assumes that only markbits are stored
         * in the waste !!!
         */
    unsigned char *wasteStartPtr; /* ptr to starting wasted byte */
    unsigned char *wasteFreePtr;  /* ptr to first free wasted byte */
                                  /* wasteEndPtr == the ChunkBlk pointer */
#endif /* WASTED_SPACE_IN_LEADER*/
} ChunkBlk, *ChunkBlkP;

/* CHUNK_BLK->chunkFlags bits: */
     /* set this bit in chunkFlags if any objects in the chunk are pinned */
#define CHUNK_PINNED 1

/* doubly-linked list of handle chunks, in address order: */
extern ChunkBlkP firstHanBlkP;
extern ChunkBlkP lastHanBlkP;
extern ChunkBlkP curHanBlkP;
/* doubly-linked list of object chunks, in address order: */
extern ChunkBlkP firstObjBlkP;
extern ChunkBlkP lastObjBlkP;
extern ChunkBlkP curObjBlkP;

/* store this into the last two words of the chunk to detect overwrites */
/* Odd to make a poor pointer, 111 in the low bits looks like a swapped
 * free block if a header! */
#define ALMOST_WORD    0x77777777
#define ULTIMATE_WORD  0xBAADDEED  /* Why not. */
/* set the third word in an object (from ptr to header) to 0x55555555 */
#define CHECK_WORD_INDEX 2

/* Macros to abstract out looping over all handles or objects.
 * Note that you can't "break" out of this loop. Use goto or return instead.
 */
#define MAP_OVER_HANDLES_FROM_START(MO_hp) {            \
    ChunkBlkP MOH_chunk = firstHanBlkP;                 \
    JHandle *MOH_limit;                                 \
    do {                                                \
        for (MO_hp = (JHandle *)MOH_chunk->startPtr,    \
             MOH_limit = (JHandle *)MOH_chunk->endPtr;  \
             MO_hp < MOH_limit; MO_hp++) {

#define END_MAP_OVER_HANDLES_FROM_START                 \
        }  /* end for */                                \
        MOH_chunk = MOH_chunk->nextPtr;                 \
    } while (MOH_chunk != firstHanBlkP);                \
} /* end MAP_OVER_HANDLES_FROM_START */

#define MAP_OVER_OBJECTS_FROM_START(MO_p)   {           \
    ChunkBlkP MOO_chunk = firstObjBlkP;                 \
    unsigned char *MOO_limit;                           \
    unsigned char *MOO_start;                           \
    do {                                                \
        for ((MO_p) = MOO_chunk->startPtr,              \
             MOO_start = MOO_chunk->startPtr,           \
             MOO_limit = MOO_chunk->endPtr;             \
             (MO_p) < MOO_limit;                        \
             (MO_p) += obj_len(MO_p)) {

#define END_MAP_OVER_OBJECTS_FROM_START                 \
        }  /* end for */                                \
        MOO_chunk = MOO_chunk->nextPtr;                 \
    } while (MOO_chunk != firstObjBlkP);                \
} /* end END_MAP_OVER_OBJECTS_FROM_START */

#endif /************ END PAGED HEAPS ********************/


#ifdef WASTED_SPACE_IN_LEADER
/* following functions defined in gc_md.c: */
void initWastedSpaceInChunk(ChunkBlkP chunk);
void sysCheckWastedSpace(ChunkBlkP chunk);
void clearLocalMarkBits(void);
void* allocMarkBitsLocally(ChunkBlkP blkP);
#else
#define initWastedSpaceInChunk(xxx) 0
#define sysCheckWastedSpace(xxx) 0
#define clearLocalMarkBits() 0
#define allocMarkBitsLocally(xxx) 0
#endif

#endif

#ifdef IBM_HAIFA_GC

/**********************************************************************
 *
 * FUNCTION NAME: markBlack
 * Description: Finds the object's sons (scanHandle) and mark them gray
 *              and then mark the object Black
 *
 * INPUT: JHandle * h - a pointer to the object on the heap.
 * OUTPUT: The object turn black and its sons gray.
 * RETURN: None
 *
 **********************************************************************/
#define markBlack(h)                          \
{                                             \
  if (!(GET_COLOR(hand2mark(h))==BLACK)) {    \
    scanHandle(h);                            \
    SET_COLOR(hand2mark(h),BLACK);            \
  }                                           \
}

/**********************************************************************
 *
 * FUNCTION NAME: postHandshake
 * Description: Sets the global collector status which should be checked by
 *              the mutators.
 * INPUT: status - the status to change to ( SYNC1, SYNC2, ASYNC )
 * OUTPUT: GCstatus
 * RETURN: None
 *
 **********************************************************************/
#define postHandshake(stat) (GCstatus = stat)

/* Tuning parameters */
#define WAITTIME             1      /* The total time to wait until sending interupt */
#define MAXWAITTOFIN         500      /* if there is more then MAXWAITTOFIN objects
				       waiting for finalization run sync finalization                                        from gc treade after async gc call */
#define MIN_FREE_BYTES 	((int)(TotalObjectCtr*0.5))
#define HIGHWATER_MARK ((char *)(TotalObjectCtr*0.8))
#define THRESHOLD_ADD 0.2*iFreeBytes
#define THRESHOLD_MAX ((int)(TotalObjectCtr*0.9))
extern  int MaxAllocToGC, MaxAllocToFullGC;                /*ibm.5833*/

#define ALLOC_TO_PART_COLLECT     1000000                  /*ibm.5833*/
#define ALLOC_TO_FULL_COLLECT     ((int)(TotalObjectCtr*0.5))    /*ibm.5833*/
#endif /* IBM_HAIFA_GC */
                                                           /*ibm*/
#endif /* !_GC_H_ */

⌨️ 快捷键说明

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