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

📄 gc_protocol.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
📖 第 1 页 / 共 2 页
字号:
/*ibm.5833*/
#define local_updateobjectarray_ee(ee,                       \
				   dest_value,               \ 
				   source_value,             \
				   count,object)             \ 
{                                                            \
    JHandle **source=(JHandle**)(source_value);              \
    JHandle **dest=(JHandle**)(dest_value);                  \
    GC_TRACE("Entering updateobjectarray\n");                \
    GCCheckValidState(ee,GCstatus);                          \
    sysAssert(ValidHandle(object) &&                         \
      GetAllocated(MEMORY_TO_HEADER(object)));               \
    ee->cantCooperate=TRUE;                                  \
    if (ee->dirty)                                           \
       markDirtyBit_ee(object,ee);                           \
    if(ee->update)                                           \
    {                                                        \
      if(ee->status!=GCASYNC)                                \
      {                                                      \
	int i;                                               \
        JHandle *dold,*dnew;                                 \
        for(i=0;i<count;i++)                                 \
        {                                                    \
            dnew=source[i];                                  \
            dold=dest[i];                                    \
            if(dnew)    /*ibm.6565 ibm.5832 ibm.5833*/       \
              GCmarkGray(&(ee->pMarkStack),dnew,ee->status); \
            if(dold)    /*ibm.6565 ibm.5832 ibm.5833*/       \
              GCmarkGray(&(ee->pMarkStack),dold,ee->status); \
        } /*ibm.8378*/                                       \
      }                                                      \
     else if (GCstage==GCTRACING )                           \
      {                                                      \
	int i;                                               \        
        JHandle *dold;                                       \
        for(i=0;i<count;i++)                                 \
        {                                                    \
          dold=dest[i];                                      \
          if(dold)   /*ibm.6565 ibm.5832 ibm.5833*/          \
            GCmarkGray(&(ee->pMarkStack),dest[i],ee->status);\
        } /*ibm.8378*/                                       \
      }                                                      \
      else                                                   \
        ee->update=FALSE;                                    \ 
    }                                                        \
    memmove(dest,source,count*sizeof(JHandle*)); /*ibm.8378 end*/  \
    ee->cantCooperate=FALSE;                                 \
    GC_TRACE("Leaving updateobjectarray\n");                 \
}

/*ibm.6565 - start*/
/* Color bitmap: 4 bits for every 8 Bytes of heap  */
#define BLUE                0x00
#define PURPLE              0x02
#define SPECIAL             0x08

#define WHITE               0x01
#define GRAY                0x05
#define BLACK               0x03
/* 
 * ibm.5833 Sticky Bits - New color for a new object. In order not to create a new 
 * object in black. Black object become "old" generation at the end of a GC cycle.
 */
#define YELLOW              0x07	      

extern volatile unsigned char allocationColor;	    /*ibm.5833*/
extern volatile unsigned char  clearColor;	    /*ibm.5833*/

extern volatile int collectionType;		    /*ibm.5833*/
#define UNKNOWNCOLLECTION      0		    /*ibm.5833*/
#define FULLCOLLECTION         1		    /*ibm.5833*/
#define PARTCOLLECTION         2		    /*ibm.5833*/

/*ibm.5833*/
#define SwitchAllocationClearColor                    \
{                                                     \
     unsigned char  temp;                             \
     temp = clearColor;                               \
     clearColor =  allocationColor;                   \
     allocationColor = temp;                          \
}

#define VALID_COLOR_MASK    0x01

extern bool_t IsValidHandleColorTable[];

#ifdef DEBUG
#define IsValidHandleColor(p) ( IsValidHandleColorTable[GET_COLOR(p)]&& \
                                ( ((((int)(p)) ^ GET_NEXT_COLOR(p) ) & SPECIAL)==0) )
#else
#define IsValidHandleColor(p) ( (GET_COLOR(p)&VALID_COLOR_MASK) &&   \
                                ( ((((int)(p)) ^ GET_NEXT_COLOR(p) ) & SPECIAL)==0) )
#endif
#define GET_COLOR(p) markbitsCompensated[(int)(p)>>0x04]

#define GET_NEXT_COLOR(p) markbitsCompensated[((int)(p)>>0x04)+1]

#define SET_COLOR(p,c)                                          \
{                                                               \
  GET_COLOR(p)=c;                                               \
}

#define SET_NEXT_COLOR(p,c)                                     \
{                                                               \
  GET_NEXT_COLOR(p)=c;                                          \
}
/*ibm.6565 - end*/

/* The extent of the mapped memory */
extern void *heapbase, *heaplimit;
extern unsigned char *real_heapbase, *real_heaplimit, *real_heaptop;
extern void * volatile pWildernessStart;  /* Start of wilderness area */     /*ibm.504*/

/* Effective start of wilderness area - meaningfull only during sweep */
extern void * volatile pWildernessStartEffective;                       /*ibm.504*/


extern unsigned char *markbits; /*ibm.6565*/
extern unsigned char *volatile markbitsCompensated; /*ibm.6565*/

extern long marksize;
extern long markmax;

extern long nfreedSmall;		/* For -verbosegc */
extern long nfreedLarge;		/* For -verbosegc */
extern long bytesfreed;	           	/* For -verbosegc */
extern long nAllocateSmall;
extern long nAllocateLarge;
extern long nAllocateBytes;		/*ibm.5833*/

#define FreeObjectCtr  ((char *)heaplimit - (char *)pWildernessStart)
#define TotalObjectCtr ((char *)heaplimit - (char *)heapbase)

#define ValidObject(p)	(IsObjectGrained(p) && 	                         \
		 (unsigned char *)(p) >= ((unsigned char *)(heapbase)+HEADER_SIZE) && \
		 (unsigned char *)(p) <  (unsigned char *)(pWildernessStart) && \
                         IsValidHandleColor(obj2mark(p)))   

#define ValidHandle(p)	(IsObjectGrained(unhand((JHandle*)p)) &&         \
		 (unsigned char *)(p) >= (unsigned char *)(heapbase) &&  \
		 (unsigned char *)(p) < (unsigned char *)(pWildernessStart)&&  \
                         IsValidHandleColor(hand2mark(p)))

#define MaybeValidHandle(p) (IsObjectGrained(unhand((JHandle*)p)) &&     \
		(unsigned char *)(p) >= (unsigned char *)(heapbase) &&   \
		(unsigned char *)(p))

#define sysThread2EE(pSysThread) (((NULL!=pSysThread)&&(pSysThread->cookie))?((ExecEnv *)THREAD((TID)pSysThread->cookie)->eetop):((ExecEnv *)NULL))

extern MarkStackPtr GCGetAvailableMarkStack();      /* ibm.5832 */


/********************* GCEmptyCollectorStack() ********************************
 * Called by the collector in order to trace elements in the stack that is
 * currently used by the collector, i.e., is pointed by pGCMarkStack.  If the
 * stack fills up, and another one is used instead, the later is scanned instead
 * of the former.
 *
 * INPUT: None (uses pGCMarkStack)
 * OUTPUT: Sets iWasEmptied:
 *    0 - stack was empty.
 *    1 - stack was emptied.
 ***************************************************************************/
#define GCEmptyCollectorStack(iWasEmptied)     \
do {                                                             \
  JHandle *pCurr;                                                \
  MarkStackPtr pMarkStack = pGCMarkStack;                        \
  if (!pMarkStack || pMarkStack->nextWriteIndex == 0)            \
    iWasEmptied =  0; /* stack was empty */ /* ETN */            \
  else {                                                         \
    iWasEmptied = 1;                                             \
    for(;;) {                                                    \
      if (pMarkStack->nextWriteIndex == 0) { /* stack is empty */  \
	pMarkStack->lastReadIndex= -1; /* should be redundant */   \
        break;                                                     \
      }                                                            \
      pMarkStack->nextWriteIndex--;                       /* pop */\
      pCurr = pMarkStack->objectPtrs[pMarkStack->nextWriteIndex ]; \
      scanHandle( pCurr );                      /* ETN *//* push */\ 
	  SET_COLOR(pCurr,BLACK); /*ibm.5833*/                         \
      if (pMarkStack->status == FULL) {                            \
        if (pGCMarkStack)      /* pGCMarkStack was updated in scanHandle */  \
		  pMarkStack = pGCMarkStack;                               \
        else                                                       \
	  break;          					   \
      }                                                            \
    }  /* else */                                                            \
  } /* forever */                                                  \
} while(0)

#define GCmarkGrayByGC(pObject,status)  GCmarkGray(&pGCMarkStack,pObject,status) /*ibm.5833*/

/********************* GCmarkGray ******************************************
 * Checks to see if a mark stack exists.  If not, it attempts to obtain a
 * new mark stack.  Adds the object
 * to the mark stack.
 * INPUT:   ppMarkStack - Ptr to a ptr to the current mark stack
 *          pObject     - Ptr to object to be grayed
 * OUTPUT:  None
 * RETURN:  None
 ****************************************************************************/
#define GCmarkGray(ppMarkStack, pObject,status)                               \
do {                                                                          \
  sysAssert(ValidHandle(pObject));                                            \
  sysAssert(ppMarkStack);		                                      \
  if((GET_COLOR(hand2mark(pObject)) == clearColor ||                          \    
    (GET_COLOR(hand2mark(pObject)) == allocationColor && status != GCASYNC))){\
    if (*(ppMarkStack) == NULL)                                               \
      *(ppMarkStack) = GCGetAvailableMarkStack();                             \
    SET_COLOR (pObject, GRAY);    /*ibm.5833*/                                \
    GCPushStack(ppMarkStack, pObject);                                        \
  }                                                                           \
} while(0)


#define GCmarkGrayAlways(ppMarkStack, pObject)                        \
do {                                                                  \
  sysAssert(ppMarkStack);		                              \
  if (*(ppMarkStack) == NULL)                                         \
      *(ppMarkStack) = GCGetAvailableMarkStack();                     \
  SET_COLOR (pObject, GRAY);    /*ibm.5833*/                          \
  GCPushStack(ppMarkStack, pObject);                                  \
} while(0)

/************************* GCPushStack ************************************
 * Pushes an element on a mark stack.  Updates the lastWrite field.  If
 * the mark stacks fills up on the write, changes the status to FULL
 * INPUT:  pMarkStack      - Ptr to the mark stack for the push
 *         pObject         - Object reference to go on stack
 * OUTPUT: None
 * RETURN: None
 ***************************************************************************/
#define GCPushStack(ppMarkStack, pObject)                                  \
do {                                                                       \
  ((*(ppMarkStack))->objectPtrs)[(*(ppMarkStack))->nextWriteIndex] =       \
    pObject;                                                               \
  (*(ppMarkStack))->nextWriteIndex += 1;                                   \
  sysAssert(((*(ppMarkStack))->nextWriteIndex) <= MAX_MARK_ENTRIES);       \
  if (((*(ppMarkStack))->nextWriteIndex) == MAX_MARK_ENTRIES) {            \
    int old = IN_USE;                                                      \
    CMP_AND_SWP (& ((*(ppMarkStack))->status), old, FULL);                 \
    *(ppMarkStack) = (MarkStackPtr) NULL;                                  \
  }                                                                        \
  /* end ibm.5832 */                                                       \
} while(0)

/*ibm.6197  A macro to find SMCB address by r12 that points to CAA */
#define get_SMCB_address(psmcb)       \
{ \
  jmp_buf buf; \
  void ** p2; \
  setjmp (buf);            /* get registers values  */ \
  p2 = (void **) buf[12];  /* get r12 (pointer to CAA) value from buffer  */ \
  p2 = (void **)((char *)p2 + 0x3d4); /* advance to offset 0x3d4 (address of SMC
B) in CAA */ \
  psmcb = (struct smcb *) *p2;    /* load this address to pointer to SMCB  */ \
}

#endif /* _GC_PROTOCOL_H_ */

 

⌨️ 快捷键说明

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