home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / j2sdk / files / linux / j2sdklin.bin / jdk1.3.1 / include-old / oobj.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-06  |  16.2 KB  |  493 lines

  1. /*
  2.  * @(#)oobj.h    1.119 00/02/02
  3.  *
  4.  * Copyright 1994-2000 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the proprietary information of Sun Microsystems, Inc.  
  7.  * Use is subject to license terms.
  8.  * 
  9.  */
  10. /*
  11.  * Java object header format
  12.  */
  13.  
  14. #ifndef _JAVASOFT_OOBJ_H_
  15. #define _JAVASOFT_OOBJ_H_
  16.  
  17. #ifndef JAVA_CLASSFILE_MAGIC
  18.  
  19. #include <stddef.h>
  20.  
  21. #include "typedefs.h"
  22. #include "debug.h"
  23. #include "bool.h"
  24. #include "signature.h"
  25. #include "util.h"
  26.  
  27. #define JAVA_CLASSFILE_MAGIC              0xCafeBabe
  28.  
  29. #define JAVASRCEXT "java"
  30. #define JAVASRCEXTLEN 4
  31. #define JAVAOBJEXT "class"
  32. #define JAVAOBJEXTLEN 5
  33.  
  34. #define JAVA_VERSION     47
  35. #define JAVA_MINOR_VERSION 0
  36.  
  37. #define HandleTo(T) typedef struct H##T { Class##T *obj; struct methodtable *methods;} H##T
  38.  
  39.  
  40. typedef unsigned long OBJECT;
  41. typedef OBJECT Classjava_lang_Object;
  42. typedef OBJECT ClassObject;
  43. HandleTo(java_lang_Object);
  44. typedef Hjava_lang_Object JHandle;
  45. typedef Hjava_lang_Object HObject;
  46.  
  47. typedef unsigned short unicode;
  48.  
  49. extern unicode    *str2unicode(char *, unicode *, long);
  50. extern char    *int642CString(int64_t number, char *buf, int buflen);
  51.  
  52. #define UCALIGN(n) ((unsigned char *)ALIGN_UP((intptr_t)(n),sizeof(int)))
  53.  
  54. struct Hjava_lang_Class;    /* forward reference for some compilers */
  55. struct Classjava_lang_Class;    /* forward reference for some compilers */
  56.  
  57. typedef struct Classjava_lang_Class Classjava_lang_Class;
  58.  
  59. HandleTo(java_lang_Class);
  60. typedef struct Hjava_lang_Class ClassClass;
  61.  
  62.  
  63. struct fieldblock {
  64.     ClassClass *clazz;
  65.     char *signature;
  66.     char *name;
  67.     unsigned short access;
  68.     /* two bytes wasted here */
  69.     union {
  70.     unsigned int offset;    /* info of data */    
  71.     OBJECT static_value;
  72.     void *static_address;
  73.     } u;
  74. };
  75.  
  76. #define fieldname(fb)    ((fb)->name)
  77. #define fieldsig(fb)     ((fb)->signature)
  78. #define fieldIsArray(fb) (fieldsig(fb)[0] == SIGNATURE_ARRAY)
  79. #define fieldIsClass(fb) (fieldsig(fb)[0] == SIGNATURE_CLASS)
  80. #define    fieldclass(fb)   ((fb)->clazz)
  81.  
  82. struct execenv;
  83. struct methodblock;
  84.  
  85. typedef bool_t (*Invoker)(JHandle *, struct methodblock *, int, struct execenv *);
  86.  
  87. struct methodblock {
  88.     struct fieldblock fb;
  89.     /* For efficient JNI calls. */
  90.     char                *terse_signature;
  91.  
  92.     unsigned char       *code;    /* the code */
  93.     struct CatchFrame   *exception_table;
  94.     struct lineno       *line_number_table;
  95.     struct localvar     *localvar_table;
  96.  
  97.     unsigned short       code_length;
  98.     unsigned short       exception_table_length;
  99.     uint32_t             line_number_table_length;
  100.     uint32_t             localvar_table_length;
  101.  
  102.     Invoker              invoker;
  103.  
  104.     unsigned short       args_size;    /* total size of all arguments */
  105.     unsigned short       maxstack;    /* maximum stack usage */
  106.     unsigned short       nlocals;    /* maximum number of locals */
  107.     unsigned short       nexceptions;   /* number of checked exceptions */
  108.  
  109.     unsigned short      *exceptions;    /* constant pool indices */
  110.     void                *CompiledCode; /* it's type is machine dependent */
  111.     void                *CompiledCodeInfo; /* it's type is machine dependent */
  112.     long                 CompiledCodeFlags; /* machine dependent bits */
  113.     unsigned long        inlining;      /* possible inlining of code */
  114. #ifdef DEBUG
  115.     void                *UNUSED1;
  116.     unsigned long        UNUSED2;
  117. #endif
  118. };
  119.  
  120. #define methodTerseSig(mb) ((mb)->terse_signature)
  121.  
  122. struct methodtable {
  123.     ClassClass *classdescriptor;
  124.     struct methodblock *methods[1];
  125. };
  126.  
  127. struct imethodtable { 
  128.     int icount;            /* number of interfaces to follow */
  129.     struct { 
  130.     ClassClass *classdescriptor;
  131.     unsigned long *offsets;    /* info of data */    
  132.     } itable[1];
  133. };
  134.  
  135. typedef struct {
  136.     int8_t body[1];
  137. } ArrayOfByte;
  138. typedef ArrayOfByte ClassArrayOfByte;
  139. HandleTo(ArrayOfByte);
  140.  
  141. typedef struct {
  142.     unicode body[1];
  143. } ArrayOfChar;
  144. typedef ArrayOfChar ClassArrayOfChar;
  145. HandleTo(ArrayOfChar);
  146.  
  147. typedef struct {
  148.     signed short body[1];
  149. } ArrayOfShort;
  150. typedef ArrayOfShort ClassArrayOfShort;
  151. HandleTo(ArrayOfShort);
  152.  
  153. typedef struct {
  154.     int32_t        body[1];
  155. } ArrayOfInt;
  156. typedef ArrayOfInt ClassArrayOfInt;
  157. HandleTo(ArrayOfInt);
  158.  
  159. typedef struct {
  160.     int64_t        body[1];
  161. } ArrayOfLong;
  162. typedef ArrayOfLong ClassArrayOfLong;
  163. HandleTo(ArrayOfLong);
  164.  
  165. typedef struct {
  166.     float       body[1];
  167. } ArrayOfFloat;
  168. typedef ArrayOfFloat ClassArrayOfFloat;
  169. HandleTo(ArrayOfFloat);
  170.  
  171. typedef struct {
  172.     double       body[1];
  173. } ArrayOfDouble;
  174. typedef ArrayOfDouble ClassArrayOfDouble;
  175. HandleTo(ArrayOfDouble);
  176.  
  177. typedef struct {
  178.     JHandle *(body[1]);
  179. } ArrayOfArray;
  180. typedef ArrayOfArray ClassArrayOfArray;
  181. HandleTo(ArrayOfArray);
  182.  
  183. typedef struct {
  184.     HObject *(body[1]);
  185. } ArrayOfObject;
  186. typedef ArrayOfObject ClassArrayOfObject;
  187. HandleTo(ArrayOfObject);
  188.  
  189. typedef struct Hjava_lang_String HString;
  190.  
  191. typedef struct {
  192.     HString  *(body[1]);
  193. } ArrayOfString;
  194. typedef ArrayOfString ClassArrayOfString;
  195. HandleTo(ArrayOfString);
  196.  
  197. /* Note: any handles in this structure must also have explicit
  198.    code in the ScanClasses() routine of the garbage collector
  199.    to mark the handle. */
  200. struct Classjava_lang_Class {
  201.     /* Things following here are saved in the .class file */
  202.     unsigned short         major_version;
  203.     unsigned short         minor_version;
  204.     char                    *name;
  205.     char                    *super_name;
  206.     char                    *source_name;
  207.     ClassClass              *superclass;
  208.     ClassClass              *HandleToSelf;
  209.     struct Hjava_lang_ClassLoader *loader;
  210.     struct methodblock        *finalizer;
  211.  
  212.     union cp_item_type      *constantpool;
  213.     struct methodblock      *methods;
  214.     struct fieldblock       *fields;
  215.     unsigned short          *implements;
  216.  
  217.     struct methodtable      *methodtable;
  218.     struct methodtable        *methodtable_mem;
  219.  
  220.     struct methodblock      *miranda_methods;
  221.  
  222.     HString            *classname;
  223.  
  224.     struct {
  225.     unsigned char    typecode;      /* VM typecode */
  226.     char        typesig;      /* signature constant */
  227.     unsigned char    slotsize;      /* (bytes) in slot */
  228.     unsigned char    elementsize;      /* (bytes) in array */
  229.     } cbtypeinfo;
  230.     unsigned long         crc32;      /* Computed by the VM before
  231.                          JIT is loaded. After JIT
  232.                          is loaded, this field is
  233.                          no longer set. */
  234.  
  235.     unsigned short           constantpool_count;  /* number of items in pool */
  236.     unsigned short           methods_count;       /* number of methods */
  237.     unsigned short           fields_count;        /* number of fields */
  238.     unsigned short           implements_count;    /* number of protocols */
  239.  
  240.     unsigned short           methodtable_size;    /* size of method table */
  241.     unsigned short           instance_size;       /* (bytes) of an instance */
  242.  
  243.     unsigned short access;           /* how this class can be accesses */
  244.     unsigned short flags;         /* see the CCF_* macros */
  245.     struct HArrayOfObject   *signers;
  246.     HObject                 *protection_domain; /* ProtectionDomain */
  247.     struct   imethodtable   *imethodtable;
  248.     void                    *init_thread; /* EE of initializing thread */
  249.     unsigned short          *object_offsets; /* offsets of objects in this 
  250.                         class */
  251.     struct {                /* allocated by classload */
  252.     unsigned char        *clinit;    /* <clinit> */
  253.     unsigned char        *main;    /* other stuff, incl. constant pool */
  254.     } classload_space;
  255.  
  256.     unsigned short          n_miranda_methods;
  257.     unsigned short          UNUSED1;
  258.     void                    *reserved_for_jit;
  259.     ClassClass            *last_subclass_of;
  260.  
  261.     unsigned short innerclass_count; /* # records in InnerClasses attribute */
  262.     struct innerclass_info {
  263.     unsigned short inner_class_info_index;
  264.     unsigned short outer_class_info_index;
  265.     unsigned short inner_name_index;
  266.     unsigned short inner_class_access_flags;
  267.     } *innerclasses;
  268.  
  269.     void                    *UNUSED2;
  270.  
  271. #ifdef DEBUG
  272.     char                    *UNUSED3;
  273.     int64_t                UNUSED4;
  274. #endif
  275.  
  276. };
  277.  
  278. extern void FreeClass(ClassClass *cb);
  279. extern void MakeClassSticky(ClassClass *cb);
  280.  
  281. #define cbAccess(cb)          ((unhand(cb))->access)
  282. #define cbClassname(cb)       ((unhand(cb))->classname)
  283. #define cbConstantPool(cb)    ((unhand(cb))->constantpool)
  284. #define cbConstantPoolCount(cb) ((unhand(cb))->constantpool_count)
  285. #define    cbFields(cb)          ((unhand(cb))->fields)
  286. #define    cbFieldsCount(cb)     ((unhand(cb))->fields_count)
  287. #define cbFinalizer(cb)       ((unhand(cb))->finalizer)
  288. #define cbFlags(cb)           ((unhand(cb))->flags)
  289. #define cbHandle(cb)          (cb)
  290. #define cbImplements(cb)      ((unhand(cb))->implements)
  291. #define cbImplementsCount(cb) ((unhand(cb))->implements_count)
  292. #define cbInstanceSize(cb)    ((unhand(cb))->instance_size)
  293. #define cbIntfMethodTable(cb) ((unhand(cb))->imethodtable)
  294. #define cbLastSubclassOf(cb)  ((unhand(cb))->last_subclass_of)
  295. #define    cbLoader(cb)          ((unhand(cb))->loader)
  296. #define cbMajorVersion(cb)    ((unhand(cb))->major_version)
  297. #define    cbMethods(cb)         ((unhand(cb))->methods)
  298. #define    cbMethodsCount(cb)    ((unhand(cb))->methods_count)
  299. #define cbMethodTable(cb)     ((unhand(cb))->methodtable)
  300. #define cbMethodTableMem(cb)  ((unhand(cb))->methodtable_mem)
  301. #define cbMethodTableSize(cb) ((unhand(cb))->methodtable_size)
  302. #define cbMinorVersion(cb)    ((unhand(cb))->minor_version)
  303. #define cbName(cb)            ((unhand(cb))->name)
  304. #define cbProtectionDomain(cb)         ((unhand(cb))->protection_domain)
  305. #define cbSigners(cb)         ((unhand(cb))->signers)
  306. #define cbSourceName(cb)      ((unhand(cb))->source_name)
  307. #define cbSuperclass(cb)      ((unhand(cb))->superclass)
  308. #define cbSuperName(cb)       ((unhand(cb))->super_name)
  309. #define cbInitThread(cb)      ((unhand(cb))->init_thread)
  310. #define cbObjectOffsets(cb)   ((unhand(cb))->object_offsets)
  311. #define cbThisHash(cb)        ((unhand(cb))->hashinfo.cbhash.thishash)
  312. #define cbTotalHash(cb)       ((unhand(cb))->hashinfo.cbhash.totalhash)
  313. #define cbClinitSpace(cb)     ((unhand(cb))->classload_space.clinit)
  314. #define cbMainSpace(cb)       ((unhand(cb))->classload_space.main)
  315. #define cbConstraintsCapacity(cb)  ((unhand(cb))->constraints_capacity)
  316. #define cbConstraintsCount(cb)     ((unhand(cb))->constraints_count)
  317. #define cbConstraints(cb)          ((unhand(cb))->constraints)
  318. #define cbMirandaMethods(cb)       ((unhand(cb))->miranda_methods)
  319. #define cbMirandaMethodsCount(cb)  ((unhand(cb))->n_miranda_methods)
  320. #define cbInnerClassesCount(cb)    ((unhand(cb))->innerclass_count)
  321. #define cbInnerClasses(cb)         ((unhand(cb))->innerclasses)
  322. #define cbIsInterface(cb)     ((cbAccess(cb) & ACC_INTERFACE) != 0)
  323.  
  324. /* These are currently only valid for primitive types */
  325. #define    cbIsPrimitive(cb)      (CCIs(cb, Primitive))
  326. #define cbTypeCode(cb)           ((unhand(cb))->cbtypeinfo.typecode)
  327. #define cbTypeSig(cb)           ((unhand(cb))->cbtypeinfo.typesig)
  328. #define cbSlotSize(cb)           ((unhand(cb))->cbtypeinfo.slotsize)
  329. #define cbElementSize(cb)      ((unhand(cb))->cbtypeinfo.elementsize)
  330.  
  331. extern char *classname2string(char *str, char *dst, int size);
  332.  
  333. #define twoword_static_address(fb) ((fb)->u.static_address)
  334. #define normal_static_address(fb)  (&(fb)->u.static_value)
  335.  
  336. /* ClassClass flags */
  337. #define CCF_IsLinked       0x02    /* been linked yet? */
  338. #define CCF_IsError       0x04    /* <clinit> caused an error */
  339. #define CCF_IsReference       0x08    /* this is class Reference or a subclass */
  340. #define CCF_IsInitialized  0x10    /* whether the class is initialized */
  341. #define CCF_IsLoaded       0x20    /* Is the class loaded (but not necessary
  342.                    linked and initialized) */
  343. #define CCF_IsVerified     0x40    /* has the verifier run on this class */
  344.  
  345. #define CCF_IsPrimitive   0x100    /* if pseudo-class for a primitive type */
  346.  
  347. #define CCF_IsSticky      0x400 /* Don't unload this class */
  348.  
  349. #define CCF_IsFieldPrepared       0x800 /* Are fields prepared */
  350. #define CCF_IsMethodPrepared     0x1000 /* Are methods prepared */
  351. #define CCF_IsInterfacePrepared  0x2000 /* Are interfaces prepared */
  352.  
  353. #define CCF_IsCached             0x4000 /* cached in the per-loader table */
  354.  
  355. #define CCIs(cb,flag) (((unhand(cb))->flags & CCF_Is##flag) != 0)
  356. #define CCSet(cb,flag) \
  357. if (1) { \
  358.   sysStoreBarrier(); \
  359.   (unhand(cb))->flags |= CCF_Is##flag; \
  360. } else ((void) 0)
  361.  
  362. #define CCClear(cb,flag) \
  363. if (1) { \
  364.   sysStoreBarrier(); \
  365.   (unhand(cb))->flags &= ~CCF_Is##flag; \
  366. } else ((void) 0)
  367.  
  368.  
  369. /* map from pc to line number */
  370. struct lineno {
  371.     unsigned short pc; 
  372.     unsigned short line_number;
  373. };
  374.  
  375. /* Symbol table entry for local variables and parameters.
  376.    pc0/length defines the range that the variable is valid, slot
  377.    is the position in the local variable array in ExecEnv.
  378.    nameoff and sigoff are offsets into the string table for the
  379.    variable name and type signature.  A variable is defined with
  380.    DefineVariable, and at that time, the node for that name is
  381.    stored in the localvar entry.  When code generate is completed
  382.    for a particular scope, a second pass it made to replace the
  383.    src node entry with the correct length. */
  384.  
  385. struct localvar {
  386.     unsigned short pc0;        /* starting pc for this variable */
  387.     unsigned short length;    /*  */
  388.     unsigned short nameoff;    /* offset into string table */
  389.     unsigned short sigoff;    /* offset into string table */
  390.     unsigned short slot;    /* local variable slot */
  391. };
  392.  
  393. /* Try/catch is implemented as follows.  On a per class basis,
  394.    there is a catch frame handler (below) for each catch frame
  395.    that appears in the source.  It contains the pc range of the
  396.    corresponding try body, a pc to jump to in the event that that
  397.    handler is chosen, and a catchType which must match the object
  398.    being thrown if that catch handler is to be taken.
  399.  
  400.    The list of catch frames are sorted by pc.  If one range is
  401.    inside another, then outer most range (the one that encompasses
  402.    the other) appears last in the list.  Therefore, it is possible
  403.    to search forward, and the first one that matches is the
  404.    innermost one.
  405.  
  406.    Methods with catch handlers will layout the code without the
  407.    catch frames.  After all the code is generated, the catch
  408.    clauses are generated and table entries are created.
  409.  
  410.    When the class is complete, the table entries are dumped along
  411.    with the rest of the class. */
  412.  
  413. struct CatchFrame {
  414.     unsigned short  start_pc, end_pc;/* pc range of corresponding try block */
  415.     unsigned short  handler_pc;    /* pc of catch handler */
  416.     void*   compiled_CatchFrame; /* space to be used by machine code */
  417.     unsigned short   catchType;            /* type of catch parameter */
  418. };
  419.  
  420. enum {
  421.     CONSTANT_Utf8 = 1,
  422.     CONSTANT_Unicode,        /* unused */
  423.     CONSTANT_Integer,
  424.     CONSTANT_Float,
  425.     CONSTANT_Long,      
  426.     CONSTANT_Double,
  427.     CONSTANT_Class,
  428.     CONSTANT_String,
  429.     CONSTANT_Fieldref,
  430.     CONSTANT_Methodref,
  431.     CONSTANT_InterfaceMethodref,
  432.     CONSTANT_NameAndType
  433. };
  434.  
  435. union cp_item_type {
  436.     unsigned int i;
  437.     float f;
  438.     char *cp;
  439.     unsigned char *type;        /* for type table */
  440.     ClassClass *clazz;
  441.     struct methodblock *mb;
  442.     struct fieldblock *fb;
  443.     struct Hjava_lang_String *str;
  444.     void *p;                    /* for very rare occassions */
  445. };
  446.  
  447. typedef union cp_item_type cp_item_type;
  448.  
  449. #define CONSTANT_POOL_ENTRY_RESOLVED 0x80
  450. #define CONSTANT_POOL_ENTRY_TYPEMASK 0x7F
  451. #define CONSTANT_POOL_TYPE_TABLE_GET(cp,i) (((unsigned char *)(cp))[i])
  452. #define CONSTANT_POOL_TYPE_TABLE_PUT(cp,i,v) \
  453. if (1) { \
  454.     sysAssert(cp != 0 && i >=0 && i <= 0xFFFF); \
  455.     sysStoreBarrier(); \
  456.     CONSTANT_POOL_TYPE_TABLE_GET(cp,i) = (v); \
  457. } else ((void) 0)
  458.  
  459. #define CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(cp,i) \
  460. if (1) { \
  461.     sysAssert(cp != 0 && i >=0 && i <= 0xFFFF); \
  462.     sysStoreBarrier(); \
  463.     CONSTANT_POOL_TYPE_TABLE_GET(cp,i) |= CONSTANT_POOL_ENTRY_RESOLVED; \
  464. } else ((void) 0)
  465.  
  466. #define CONSTANT_POOL_TYPE_TABLE_IS_RESOLVED(cp,i) \
  467.     ((CONSTANT_POOL_TYPE_TABLE_GET(cp,i) & CONSTANT_POOL_ENTRY_RESOLVED) != 0)
  468. #define CONSTANT_POOL_TYPE_TABLE_GET_TYPE(cp,i) \
  469.         (CONSTANT_POOL_TYPE_TABLE_GET(cp,i) & CONSTANT_POOL_ENTRY_TYPEMASK)
  470.  
  471. #define CONSTANT_POOL_TYPE_TABLE_INDEX 0
  472. #define CONSTANT_POOL_UNUSED_INDEX 1
  473.  
  474. /* The following are used by the constant pool of "array" classes. */
  475.  
  476. #define CONSTANT_POOL_ARRAY_DEPTH_INDEX 1
  477. #define CONSTANT_POOL_ARRAY_TYPE_INDEX 2
  478. #define CONSTANT_POOL_ARRAY_CLASS_INDEX 3
  479. #define CONSTANT_POOL_ARRAY_CLASSNAME_INDEX 4
  480. #define CONSTANT_POOL_ARRAY_SUPERNAME_INDEX 5
  481. #define CONSTANT_POOL_ARRAY_LENGTH 6
  482.  
  483. /* 
  484.  * Package shorthand: this isn't obviously the correct place.
  485.  */
  486. #define JAVAPKG         "java/lang/"
  487. #define JAVAIOPKG       "java/io/"
  488. #define JAVANETPKG      "java/net/"
  489.  
  490. #endif
  491.  
  492. #endif /* !_JAVASOFT_OOBJ_H_ */
  493.