📄 class.h
字号:
/* * Copyright (c) 1998-2002 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. * * Use is subject to license terms. *//*========================================================================= * SYSTEM: KVM * SUBSYSTEM: Internal runtime structures * FILE: class.h * OVERVIEW: Internal runtime class structures. * AUTHOR: Antero Taivalsaari, Sun Labs * Edited by Doug Simon 11/1998 (added the string pool) * Frank Yellin *=======================================================================*//*========================================================================= * COMMENTS: * This file defines the VM-specific internal runtime structures * needed for representing classes and their instances in the system. *=======================================================================*//*========================================================================= * Include files *=======================================================================*//*========================================================================= * Global definitions *=======================================================================*//* Class status flags */#define CLASS_RAW 0 /* this value must be 0 */#define CLASS_LOADING 1#define CLASS_LOADED 2#define CLASS_LINKED 3#define CLASS_VERIFIED 4#define CLASS_READY 5#define CLASS_ERROR -1/* A class is considered initialized if it's ready or being initialized * by the current thread. */#define CLASS_INITIALIZED(c) \ ((c)->status == CLASS_READY || (c)->initThread == CurrentThread)#define IS_ARRAY_CLASS(c) (( ((CLASS)(c))->accessFlags & ACC_ARRAY_CLASS) != 0)/* Use the 13th bit to indicate whether a class instance has been * initialized. */#define ITEM_NewObject_Flag 0x1000#define ITEM_NewObject_Mask 0x0FFF#define ENCODE_NEWOBJECT(pc) ((((pc) & 0x7000)<<1) | 0x1000 | ((pc) & 0x0FFF)) #define DECODE_NEWOBJECT(no) ((((no) & 0xE000)>>1) | ((no) & 0x0FFF))/* Abstract types used by the byte code verifier. */enum { ITEM_Bogus, /* Unused */ ITEM_Integer, ITEM_Float, ITEM_Double, ITEM_Long, ITEM_Null, /* Result of aconst_null */ ITEM_InitObject, /* "this" is in <init> method, before call to super() */ ITEM_Object, /* Extra info field gives name. */ ITEM_NewObject, /* Like object, but uninitialized. */ /* The following codes are used by the verifier but don't actually occur in * class files. */ ITEM_Long_2, /* 2nd word of long in register */ ITEM_Double_2, /* 2nd word of double in register */ ITEM_Category1, ITEM_Category2, ITEM_DoubleWord, ITEM_Reference};/*========================================================================= * Internal runtime class and instance data structures *=======================================================================*//*========================================================================= * Every object in KVM looks roughly like this: * * +--------------------------+ * | GC header word (32 bits) | * +==========================+ * object ptr -> | class pointer | * +--------------------------+ * | monitorOrHashCode field | * +--------------------------+ * | ... the rest of the | * . data ... . * . . * * The data type declarations below define the various * class and instance data structures that the KVM uses * internally at runtime. * * The "real" (upper-caps) names for these data types * are defined in file 'global.h'. * * IMPORTANT: If you change the order of any of the data elements * in these data structures, make sure that the order matches * with the corresponding data structures in 'rom.h'. *=======================================================================*//** * The low two bits of the monitorOrHashCode (mhc) field of an object * say what it is. See thread.h for more information. */typedef union monitorOrHashCode { void *address; /* low 2 bits MHC_MONITOR, MHC_SIMPLE_LOCK, MHC_EXTENDED_LOCK */ long hashCode; /* low 2 bits MHC_UNLOCKED */} monitorOrHashCode;/* Macro that defines the most common part of the objects */#define COMMON_OBJECT_INFO(_type_) \ _type_ ofClass; /* Pointer to the class of the instance */ \ monitorOrHashCode mhc;/* CLASS */struct classStruct { COMMON_OBJECT_INFO(INSTANCE_CLASS) /* Note that arrays classes have the same packageName as their base * class. the baseName for arrays is [...[L<className>; or * [...[<primitive type>, where [...[ indicates the appropriate * number of left brackets for the depth */ UString packageName; /* Everything before the final '/' */ UString baseName; /* Everything after the final '/' */ CLASS next; /* Next item in this hash table bucket */ unsigned short accessFlags; /* Access information */ unsigned short key; /* Class key */};/* INSTANCE_CLASS */struct instanceClassStruct { struct classStruct clazz; /* common info */ /* And specific to instance classes */ INSTANCE_CLASS superClass; /* Superclass, unless java.lang.Object */ CONSTANTPOOL constPool; /* Pointer to constant pool */ FIELDTABLE fieldTable; /* Pointer to instance variable table */ METHODTABLE methodTable; /* Pointer to virtual method table */ unsigned short* ifaceTable; /* Pointer to interface table */ POINTERLIST staticFields; /* Holds static fields of the class */ short instSize; /* The size of class instances */ short status; /* Class readiness status */ THREAD initThread; /* Thread performing class initialization */};/* ARRAY_CLASS */struct arrayClassStruct { struct classStruct clazz; /* Common info */ /* And stuff specific to an array class */ union { CLASS elemClass; /* Element class of object arrays */ long primType; /* Element type for primitive arrays */ } u; long itemSize; /* Size (bytes) of individual elements */ /* wants to be GCT_ObjectType rather than */ /* an int. But the Palm makes enumerations*/ /* into "short" */ long gcType; /* GCT_ARRAY or GCT_OBJECTARRAY */ long flags; /* */};#define ARRAY_FLAG_BASE_NOT_LOADED 1/* OBJECT (Generic Java object) */struct objectStruct { COMMON_OBJECT_INFO(CLASS)};/* INSTANCE */struct instanceStruct { COMMON_OBJECT_INFO(INSTANCE_CLASS) union { cell *cellp; cell cell; } data[1];};/* These are never created directly. *//* It's what a java.lang.String looks like *//* STRING_INSTANCE */struct stringInstanceStruct { COMMON_OBJECT_INFO(INSTANCE_CLASS) SHORTARRAY array; cell offset; cell length;};/* INTERNED_STRING_INSTANCE */struct internedStringInstanceStruct { COMMON_OBJECT_INFO(INSTANCE_CLASS) SHORTARRAY array; cell offset; cell length; struct internedStringInstanceStruct *next;};struct throwableInstanceStruct { COMMON_OBJECT_INFO(INSTANCE_CLASS) STRING_INSTANCE message; ARRAY backtrace;};typedef union cellOrPointer { cell cell; cell *cellp; cell **cellpp; /* For global roots */ /* Occasionally needed by GC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -