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

📄 interpreter.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
📖 第 1 页 / 共 3 页
字号:
/*
 * @(#)interpreter.h    1.121 98/07/14
 *
 * Copyright 1995-1998 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * 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.
 */

/*
 * Definitions for the interpreter      6/27/91
 */

#ifndef _INTERPRETER_H_
#define _INTERPRETER_H_

#ifndef IBM4690_INCLUDES_P5                     /*ibm.7717*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif //!IBM4690_INCLUDES_P5           /*ibm.7717*/

#include "bool.h"
#include "config.h"
#include "jni.h"
#include "alloc_cache.h"

extern char *progname;
extern bool_t debugging;
extern bool_t verbose;
extern bool_t verbosegc;
#ifdef JMS_TRL
extern bool_t verbosemongc;
extern bool_t compactgc;
#endif
extern bool_t noasyncgc;
extern bool_t classgc;

extern ClassClass *classJavaLangClass;     /* class java/lang/Class */
extern ClassClass *classJavaLangObject;    /* class java/lang/Object */
extern ClassClass *classJavaLangString;    /* class java/lang/String */

extern ClassClass *classJavaLangThrowable;
extern ClassClass *classJavaLangException;
extern ClassClass *classJavaLangError;
extern ClassClass *classJavaLangRuntimeException;
extern ClassClass *classJavaLangThreadDeath;

extern ClassClass *interfaceJavaLangCloneable; /* class java/lang/Cloneable */
extern ClassClass *interfaceJavaIoSerializable; /* class java/io/Serializable */

enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL };

extern int verifyclasses;

#define FINALIZER_METHOD_NAME "finalize"
#define FINALIZER_METHOD_SIGNATURE "()V"

#ifdef TRACING
  extern int trace;
  extern int tracem;
  extern void trace_method(struct execenv*, struct methodblock*, int, int);
  enum { TRACE_METHOD_ENTER, TRACE_METHOD_RETURN, TRACE_METHOD_NATIVE_RETURN };

#ifdef JOVATION                                                         /*ibm.6780*/
  extern bool_t javation;
# define TRACE_METHOD(ee, mb, args_size, type) \
      if (tracem && !javation) trace_method(ee, mb, args_size, type); else
# define TRACE_ENTER(ee, mb, o) \
        if (tracem && javation) trace_enter(ee, mb, o); else
# define TRACE_LEAVE(ee, mb, o) \
        if (tracem && javation) trace_leave(ee, mb, o); else
  extern void trace_enter(struct execenv*, struct methodblock*, HObject*);
  extern void trace_leave(struct execenv*, struct methodblock*, HObject*);

# define TRACE_GC(o) ( (tracem && javation) ? trace_gc(o) : 0)
# define TRACE_CLASS(db) ( (tracem && javation) ? trace_class(db) :0)

#else                                                                   /*ibm.6780*/
# define TRACE_METHOD(ee, mb, args_size, type) \
      if (tracem) trace_method(ee, mb, args_size, type); else
#endif                                                                  /*ibm.6780*/

#else
# define trace  0
# define tracem 0
# define TRACE_METHOD(ee, mb, args_size, type)
#endif

extern char * const opnames[];

/* Get a constant pool index, from a pc */
#define GET_INDEX(ptr) (((int)((ptr)[0]) << 8) | (ptr)[1])

extern char *Object2CString(JHandle *);

#ifdef JMS_TRL
/*
 * [TRL] TRL Java Memory System
 */
#define METHOD_FLAG_BITS 5
#define FLAG_MASK       ((1<<METHOD_FLAG_BITS)-1)  /* valid flag bits */
#define METHOD_MASK     (~FLAG_MASK)  /* valid mtable ptr bits */
#define LENGTH_MASK     METHOD_MASK

/*
       10987654321098765432109876543210
       ttttthhhhhhhhhhhhhhhhhhhhhhhhN-H

        ttttt                      typecode
        hhhhhhhhhhhhhhhhhhhhhhhh   hashcore
        A                          array or normal
        -
        H                          hash or monitor pointer
 */


#define obj_length(o)   ((unsigned long) (o)->methods)

#define OBJ_TYPECODE         5
#ifdef MON_FLAT
#define OBJ_TYPECODE_SHIFT  (8-OBJ_TYPECODE)
#define OBJ_TYPECODE_MASK ((1<<OBJ_TYPECODE)-1)
#else
#define OBJ_TYPECODE_SHIFT  (32-OBJ_TYPECODE)
#define OBJ_TYPEMASK        ((1<<OBJ_TYPECODE_SHIFT)-1)
#endif


#define OBJ_IsArray  0x02 /* Whether it is an array */
#ifndef MON_FLAT /* ibm.3740 */
#define OBJ_MONMASK  0x03
#define OBJ_IsHash   0x01 /* Whether it is a hash value or a monitor pointer */
#endif /* ibm.3740 */

#ifdef MON_FLAT
#define OBJ_HashedAndMoved 0x04 /* The object has been hashed, and moved */
#define OBJ_Hashed   0x01 /* Whether the object has been hashed-upon */
#define is_normal_object(o)     (((o)->locknflags & OBJ_IsArray)==0)

#define obj_flags(o)    (((o)->locknflags >> OBJ_TYPECODE_SHIFT) & OBJ_TYPECODE_MASK)
#define obj_array_flags(o)    obj_flags(o)
#define obj_makelocknflags(type,array) \
         ((((type)&OBJ_TYPECODE_MASK)<<OBJ_TYPECODE_SHIFT) | (array))
#else
#define is_normal_object(o)     (((o)->hash & OBJ_IsArray)==0)

#define obj_flags(o)    ((o)->hash >> OBJ_TYPECODE_SHIFT)
#define obj_array_flags(o)    obj_flags(o)
#endif /* MON_FLAT */

#ifdef IBM_HAIFA_GC                                             /*ibm.4860*/
#define jms_ee2thr(ee) \
     ((ee)->thread ? (sys_thread_t*)(THREAD((ee)->thread)->PrivateInfo) : 0)
#endif /* IBM_HAIFA_GC */                                       /*ibm.4860*/

#define obj_makehash(type,hash,array) \
         (((type)<<OBJ_TYPECODE_SHIFT) | ((hash) & OBJ_TYPEMASK) | (array))

#define obj_methodtable(obj) ((obj)->methods)
#define obj_classblock(obj) ((obj)->methods->classdescriptor)

#define obj_array_methodtable(obj) \
    (is_normal_object(obj) ? obj_methodtable(obj)      \
                           : cbMethodTable(classJavaLangObject))
#define obj_array_classblock(obj) \
    (is_normal_object(obj) ? (obj)->methods->classdescriptor \
                           : classJavaLangObject)

#ifdef MON_FLAT
#define IntrinsicSize(__obj,__rv__)                                                             \
        do {                                                                                        \
      JHandle *__obj__ = (__obj);                                                               \
      if (is_normal_object (__obj__)) {                                                         \
                ClassClass *__cb__ = obj_classblock (__obj__);                                          \
        (__rv__) = cbInstanceSize(__cb__) + (cbFinalizer(__cb__) ? sizeof(finalizer_t) : 0);    \
          } else {                                                                                  \
                unsigned int __tc__ = obj_flags (__obj__);                                              \
                if (__tc__ == T_CLASS) {                                                                \
                  (__rv__) = sizearray (__tc__,(int) obj_methodtable (__obj__)) + sizeof (OBJECT);            \
                } else {                                                                                \
                  (__rv__) = sizearray (__tc__,(int) obj_methodtable (__obj__));                              \
                }                                                                                       \
          }                                                                                         \
        } while (0)

#define InitialSize(__obj,__rv__)                                                               \
        do {                                                                                        \
      int __intrinsicsize__;                                                                    \
          IntrinsicSize (__obj,__intrinsicsize__);                                                  \
          (__rv__) = (__intrinsicsize__ + HEADER_SIZE + (OBJECTGRAIN - 1)) & ~(OBJECTGRAIN - 1);    \
        } while (0)

#define HashedMovedSize(__obj,__rv__)                                                           \
        do {                                                                                        \
      int __intrinsicsize__;                                                                    \
          IntrinsicSize (__obj,__intrinsicsize__);                                                  \
          __intrinsicsize__ += sizeof (unsigned long);                                              \
          (__rv__) = (__intrinsicsize__ + HEADER_SIZE + (OBJECTGRAIN - 1)) & ~(OBJECTGRAIN - 1);    \
        } while (0)
#endif /* MON_FLAT */

#else /* SUN JDK */
#define METHOD_FLAG_BITS 5
#define FLAG_MASK       ((1<<METHOD_FLAG_BITS)-1)  /* valid flag bits */
#define METHOD_MASK     (~FLAG_MASK)  /* valid mtable ptr bits */
#define LENGTH_MASK     METHOD_MASK

#define obj_flags(o) \
    (((unsigned long) (o)->methods) & FLAG_MASK)
#define obj_length(o)   \
    (((unsigned long) (o)->methods) >> METHOD_FLAG_BITS)

#define mkatype(t,l) ((struct methodtable *) (((l) << METHOD_FLAG_BITS)|(t)))
#define atype(m) ((m) & FLAG_MASK)


#define obj_methodtable(obj) ((obj)->methods)
#define obj_classblock(obj) ((obj)->methods->classdescriptor)

#define obj_array_methodtable(obj) \
    ((obj_flags((obj)) == T_NORMAL_OBJECT) ? obj_methodtable((obj))      \
                                           : cbMethodTable(classJavaLangObject))
#define obj_array_classblock(obj) \
    ((obj_flags((obj)) == T_NORMAL_OBJECT) ? (obj)->methods->classdescriptor \
                                           : classJavaLangObject)

#endif /* JMS_TRL */

#define mt_slot(methodtable, slot) (methodtable)->methods[slot]

#define uobj_getslot(o, slot) (o)[slot]
#define uobj_setslot(o, slot, v) (uobj_getslot(o, slot) = (v))

#define obj_getslot(o, slot) uobj_getslot(unhand(o), slot)
#define obj_setslot(o, slot, v) (obj_getslot(o, slot) = (v))

#ifdef MON_FLAT
#define obj_monitor(handlep) ((struct Hjava_lang_Object *) handlep)     /*ibm.4317*/
#else
#define obj_monitor(handlep) ((int) handlep)
#endif


struct arrayinfo {
    int index;
    char sig;      /* type signature. */
    char *name;
    int factor;
};

typedef union stack_item {
    /* Non pointer items */
    int            i;
    float_t        f;                                           /*ibm01229*/
    OBJECT         o;
    /* Pointer items */
    JHandle       *h;
    void          *p;
    unsigned char *addr;
} stack_item;

/* ibm.5832 */
/* ELS 6/98      Multiple mark stack implementation */

#define  MAX_MARK_ENTRIES 5000 /* Depth of mark stack */
typedef enum {AVAILABLE, IN_USE, FULL} Stackstatus;
typedef struct MarkStack *MarkStackPtr;
typedef struct MarkStack {
  MarkStackPtr volatile next;        /* Next mark stack in link list */
  volatile int nextWriteIndex;     /* Next slot free */
  int lastReadIndex;       /* Last slot read by tracing collector */
  volatile int status;     /* Status of mark stack */
  JHandle *objectPtrs[MAX_MARK_ENTRIES];  /* Ptrs to queued objects */
} MarkStack;

/* ELS ibm.5832 */

struct execenv {
    struct javastack  *initial_stack;
    struct javaframe  *current_frame;
    JHandle           *thread;      /* vague type to avoid include files */
    char              exceptionKind;
    union {
        JHandle       *exc;         /* holds exception object */
        unsigned char *addr;        /* holds pc for stack overflow */
    } exception;

    /* Stuff for the JNI: */
    struct JNIEnv_    nativeInterface;

    /* Detecting class circularities */
    struct seenclass {
        ClassClass    *cb;
        struct seenclass *next;
    } seenclasses;

#ifdef JIT_TRL
    /* Stuff For JIT implementation of Frame Access Abstraction */
    struct jit_execenv {
        int    exec_mode;
        void*  last_frame;
        void*  privateInfo;
    } jit_ee;
#endif

#ifdef MON_FLAT
  long tindex; /* stuff for fast monitors */
#endif

    /* Per-thread allocation cache */
    struct alloc_cache alloc_cache;
#ifdef IBM_HAIFA_GC                                             /*ibm.5023*/
  /* IGOR & TMR 28/7/97 */
  volatile int    status;        /* The synchronization status of the thread */
  volatile int    allocatedInCycle; /* The number of bytes allocated during the current GC cycle */
  volatile bool_t cantCooperate;
  volatile bool_t notified; /* holds true if the thread has been notified for
                                                         the need of its cooperation */
  volatile int    numGCcycles;
  volatile bool_t update;   /* Whether update has to be invoked in the current
                                                           state */
  volatile int    AllocVecNum;  /* Allocation Vector Number for small
                                                                   objects*/
  MarkStackPtr pMarkStack;  /* Mark stack for thread's use - ibm.5832  */
  volatile bool_t dirty;   /*ibm.5833*/
  void   *compensatedBlockHeaders; /*ibm.5833*/
  /* pointer to the current bin for small object sizes, for the current thread */
  JHandle  (* volatile  (*pBin)); /*ibm.6565*/
  /* Current allocation color */
  char            allocationColor;
  /* Pointer to compensated markbits */
  unsigned char  *volatile compensatedMarkbits;
  unsigned char  clearColor,markColor;
#endif                                                          /*ibm.5023*/

#if defined(IBM_MIXED_MODE)						/*ibm.8789*/
    /* per thread debug and stats info */
    int stopped_at_single_step;
    int breakpoint_last_time;

⌨️ 快捷键说明

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