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

📄 gc.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)gc.h     1.10 97/01/24
 *
 * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * CopyrightVersion 1.1_beta
 *
 */

#ifndef _GC_H_
#define _GC_H_

#include "gc_md.h"
#ifdef IBM_HAIFA_GC
#include "threads.h"
#include "interpreter.h"
#include "threads_md.h"
#include "gc_protocol.h"
#endif /* IBM_HAIFA_GC */

#ifdef JMS_TRL                                                          /*ibm*/
#if defined(IBM_OS2)							/*ibm.3243*/
#include "mutex_md.h"
#include "finalize.h"							/*ibm.3363*/
#endif									/*ibm.3243*/
#define HEAP_LOCK_INIT() sysHeapLockInit()
#define HEAP_LOCK()      sysHeapLock()
#define HEAP_UNLOCK()    sysHeapUnlock()
#define HEAP_LOCKED()    sysHeapLocked()
/* [TRL] Fastpath */
#ifndef IBM_HAIFA_GC
typedef long hdr;
typedef struct chunk {
    hdr      header;
    struct chunk* next;
} Chunk;
#define MAX_FREELIST 64
#define OBJECTGRAIN     8
#define LOG_OBJECTGRAIN 3
typedef long hhdr;
#define OLINK_SIZE  sizeof(hhdr)
#define HEADER_SIZE  (OLINK_SIZE+HANDLE_SIZE)

/* mark address offset from handle */
#define MARK_OFFSET  0
#define _ALLOCED_  1
#endif /* not IBM_HAIFA_GC */

#define HASHCORE_INCREMENT  4
#if defined(IBM_FASTNEW)
typedef struct {
#if defined(IBM_AIX) || defined(IBM_4690)         /*ibm.7306*/
  sys_mon_t *      p_heap_mon;
#else                                                                   /*ibm*/
  mutex_t *        p_heap_lock;
#endif                                                                  /*ibm*/
  unsigned char ** p_heapbase;
  unsigned char ** p_heaplimit;
  Chunk **         p_freelist;
  int  *           p_heap_memory_changes;
  long *           p_FreeObjectCtr;
  unsigned int **  p_allocbits;
  long *           p_current_hashcore;
  sys_mon_t **     p_hasfinalq_lock;					/*ibm.3363*/
  JHandle **       p_HasFinalizerQ;					/*ibm.3363*/
#if defined(IBM_ALLOC_CACHE)						/*ibm.4816*/
  HObject *        (*p_FastObjAlloc)(ExecEnv*, ClassClass*, long);
  HObject *        (*p_FastArrayAlloc)(ExecEnv*, int, int);
  HObject *        (*p_cacheAlloc)(ExecEnv*, struct methodtable*, long, int);
#endif									/*ibm.4816*/
} GCLinkVector;

extern GCLinkVector p_GCLinkVector;
#endif									/*ibm.3105*/
#else                                                                   /*ibm*/
/*
 * Lock against heap modification.
 */
#if defined(IBM_OS2)                                                    /*ibm*/
#include <javaos2.h>
#include <mutex_md.h>

extern mutex_t _heap_lock;
#define HEAP_LOCK_INIT() mutexInit(&_heap_lock)
#define HEAP_LOCK() mutexLock(&_heap_lock)
#define HEAP_UNLOCK() mutexUnlock(&_heap_lock)
#define HEAP_LOCKED() mutexLocked(&_heap_lock)
#else                                                                   /*ibm*/
extern sys_mon_t *_heap_lock;
#define HEAP_LOCK_INIT()    monitorRegister(_heap_lock, "Heap lock")
#define HEAP_LOCK()         sysMonitorEnter(_heap_lock)
#define HEAP_UNLOCK()       sysMonitorExit(_heap_lock)
#define HEAP_LOCKED()       sysMonitorEntered( _heap_lock)
#endif                                                                  /*ibm*/

/*
 * Define this if you want the mark phase to detect pointers into the
 * interior of objects.
 */
/* #define CHECK_INTERIOR_POINTERS */

#define OBJECTGRAIN     8
#define HANDLEGRAIN     8
#define BITSPERCHAR     8

/*
 * Types of overflows: we might respond to an overflow of a particular
 * error differently, e.g. expanding only the overflowing area.
 */
#define OVERFLOW_NONE    0
#define OVERFLOW_OBJECTS 1
#define OVERFLOW_HANDLES 2

/*
 * Possible actions to take on overflows.  manageAllocFailure()
 * decides between these.
 */
#define OVERFLOW_ACT_FAIL       0
#define OVERFLOW_ACT_GC         1
#define OVERFLOW_ACT_FINALIZE   2
#define OVERFLOW_ACT_REFS       3
#define OVERFLOW_ACT_EXPAND     4
#define OVERFLOW_ACT_DESPERATE  5

/*
 * Memory block header (bottom three bits are flags):
 *
 * -------------------------------------------------------------
 * | <--- length --->| pinned | <- obj swapped -> | <- free -> |
 * -------------------------------------------------------------
 * 31                3        2                   1            0
 */
typedef long hdr;

#define obj_geth(p) (*((hdr *)(p)))
#define obj_seth(p, h) (*((hdr *)(p)) = (h))
#define h_len(h) ((h) & ~(OBJECTGRAIN-1))
#define h_free(h) ((h) & 1)
#define h_bumplen(h, l) ((h) += (l))

#define obj_len(p) (obj_geth(p)&~(OBJECTGRAIN-1))
#define obj_setlf(p, l, f) (obj_geth(p) = (l)|(f))
#define obj_bumplen(p, l) (obj_geth(p) += (l))
#define obj_free(p) (obj_geth(p)&1)
#define obj_setfree(p) (obj_geth(p) |= 1)
#define obj_clearfree(p) (obj_geth(p) &= ~1)
#define obj_pinned(p) (obj_geth(p) & 4)
#define obj_pin(p) (obj_geth(p) |= 4)
#define obj_unpin(p) (obj_geth(p) &= ~4)

/*
 * The marking code relies upon the values representing the three mark
 * states to be ordered numerically: NoMark < SoftMark < HardMark.
 */
#define NoMark   0
#define SoftMark 1
#define HardMark 3

#define MarkPtr(p, v) _MarkPtr(((unsigned int) (p) & ~(OBJECTGRAIN - 1)), v)
#define ClearMarkPtr(p, v) _ClearMarkPtr(((unsigned int)(p)&~(OBJECTGRAIN-1)),v)
#define IsMarked(p) _IsMarked((unsigned int) (p) & ~(OBJECTGRAIN - 1))

#define SOFTREFBAGSIZE 200  /* max number of soft refs to kill in one cycle */


#ifndef PAGED_HEAPS /************ CONTIGUOUS HEAPS: ********************/

#define ValidObject(p)  ((((int)(p)) & (OBJECTGRAIN-1)) == 0 &&         \
                         (unsigned char *)(p) >= opmin &&               \
                         (unsigned char *)(p) <  opmax)
#define ValidHandle(p)  (((int) (p) & (sizeof(JHandle)-1)) == 0 &&      \
                         (unsigned char *)(p) >= hpmin &&               \
                         (unsigned char *)(p) <= hpmax)
/* ValidHorO() assumes OBJECTGRAIN=sizeof(JHandle)... */
#define ValidHorO(p)    (((int) (p) & (OBJECTGRAIN-1)) == 0 &&          \
                         (unsigned char *)(p) >= hpmin &&               \
                         (unsigned char *)(p) <= opmax)
#define SetLimits()                                                     \
    register unsigned char *const opmin = opool,                        \
                           *const opmax = opoollimit,                   \
                           *const hpmin = hpool,                        \
                           *const hpmax = hpoollimit-sizeof(JHandle)

#define POP_FREE_HANDLE(hp)                                             \
    hp = (JHandle *)hpoolfreelist;                                      \
    if (hp) {                                                           \
        hpoolfreelist = (unsigned char *)hp->methods;                   \
    }

#define PUSH_FREE_HANDLE(hp) \
    hp->methods = (struct methodtable *)hpoolfreelist; \
    hpoolfreelist = (unsigned char *)hp;

/* Mark bit access assumes contiguity of handles and objects */
#define MARKINDEX(p)    (((unsigned char *)(p) - hpmin) >> 7)
#define BITOFFSET(p)    ((((unsigned char *)(p) - hpmin) >> 2) & 0x1e)

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

/* set the second word in an object (from ptr to header) to 0x55555555 */
#define CHECK_WORD_INDEX 1

#define MAP_OVER_HANDLES_FROM_START(MO_hp) {            \
    JHandle *MOH_limit = (JHandle *) hpmax;             \
    for (MO_hp = (JHandle *) hpool; MO_hp <= MOH_limit; MO_hp++) {

#define END_MAP_OVER_HANDLES_FROM_START                 \
    } /* end for */                                     \
} /* end MAP_OVER_HANDLES_FROM_START */

#define MAP_OVER_OBJECTS_FROM_START(p) {                \
    unsigned char *MOO_limit = opmax;                   \
    unsigned char *MOO_start = opmin;                   \
    for (p = opmin;                                     \
         p < MOO_limit;                                 \
         p += obj_len(p)) {

⌨️ 快捷键说明

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