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

📄 objects.h

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 H
字号:
/* * @(#)objects.h	1.92 06/10/10 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved.   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER   *    * This program is free software; you can redistribute it and/or   * modify it under the terms of the GNU General Public License version   * 2 only, as published by the Free Software Foundation.    *    * This program is distributed in the hope that it will be useful, but   * WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * General Public License version 2 for more details (a copy is   * included at /legal/license.txt).    *    * You should have received a copy of the GNU General Public License   * version 2 along with this work; if not, write to the Free Software   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA   * 02110-1301 USA    *    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa   * Clara, CA 95054 or visit www.sun.com if you need additional   * information or have any questions.  * *//* * This file gives some core type definitions for Java objects in * CVM. The "bottom of the world" if you will. * * All forward declarations and typedef's are done in defs.h */#ifndef _INCLUDED_OBJECTS_H#define _INCLUDED_OBJECTS_H#include "javavm/include/defs.h"#include "javavm/include/signature.h"#include "javavm/include/basictypes.h"#include "javavm/include/sync.h"#ifdef CVM_JIT#include "javavm/include/porting/jit/jit.h"#endif#ifndef CVM_GC_SPECIFIC_WORDS#define CVM_GC_SPECIFIC_WORDS#endif/* * The following definitions make up a Java object header, to be found * in all arrays and objects. * * The first two words are common to all possible GC's. There is * enough "room" in these two words for supporting non-incremental * collectors, like generational collectors. * * More words may be added to the header as needed by a given GC * algorithm. * * The first word: * * This is a pointer to the ClassBlock of an object, 'clas', with the * lower two bits serving special purpose.  * * The lowest bit of the 'clas' word indicates the locking type for * this object. For registered real-time objects, locking must be * deterministic, performing priority inheritance or priority ceiling, * etc. For others, locking may use a fast average case user-level * scheme, which would work great for uncontended objects. * * The second lower bit of the 'clas' word indicates whether this * object is in the heap or in ROM. This indication is necessary for * GC to know that it is now looking at a non-GCable object. It still * has to scan such an object's fields for discovering reachability of * others, but it can't move the object around, nor reclaim its space. * * The second word: * * Includes a "VariousBits" word, used for synchronization, GC, and * object hashcodes. Depending on the synchronization state of this * object, the bits may be there, or may have been evacuated to some * sort of "lock record". *//* * The widths of the bitfields of the "various" header word */#define CVM_SYNC_BITS  2#define CVM_HASH_BITS  24#define CVM_GC_BITS (32 - CVM_SYNC_BITS - CVM_HASH_BITS)#define CVM_GC_SHIFT	(CVM_SYNC_BITS + CVM_HASH_BITS)#define CVM_SYNC_MASK	((1 << CVM_SYNC_BITS) - 1)#define CVM_HASH_MASK	((1 << CVM_HASH_BITS) - 1)#define CVMhdrBitsSync(h)	((h) & CVM_SYNC_MASK)#define CVMhdrBitsPtr(h)	((h) & ~CVM_SYNC_MASK)/*  * The argument to CVMhdrBitsHashCode() is a CVMAddr but * java.lang.Object.hashCode is a jint so cast it here. */#define CVMhdrBitsHashCode(h)   ((CVMInt32)((h) >> CVM_SYNC_BITS) & CVM_HASH_MASK)#define CVMhdrBitsGc(h)		((h) >> CVM_GC_SHIFT)#define CVMhdrSetHashCode(hdr, hc)				\    {								\	CVMassert((hc & ~((1 << CVM_HASH_BITS) - 1)) == 0);	\	(hdr) |= (hc << CVM_SYNC_BITS);			\    }#define CVMhdrSetSync(hdr, s)					\    {								\	CVMassert(((s) & ~3) == 0);				\	(hdr) = CVMhdrBitsPtr((hdr)) | (s);			\    }/*  * various32 is casted to a pointer * (see CVMobjectVariousWord() in CVMobjGcBitsPlusPlusCompare()) * therefore the type has to be CVMAddr which is 4 byte on * 32 bit platforms and 8 byte on 64 bit platforms */struct CVMObjectHeader {    volatile CVMClassBlock   *clas;    volatile CVMAddr         various32;    CVM_GC_SPECIFIC_WORDS};#define CVMobjectVariousWord(obj)  ((obj)->hdr.various32)enum {    CVM_LOCKSTATE_LOCKED = 0,    CVM_LOCKSTATE_MONITOR = 1,    CVM_LOCKSTATE_UNLOCKED = 2};/* * Hash for the object has not been computed yet */#define CVM_OBJECT_NO_HASH 0/* * The default "empty" various header word */#define CVM_OBJECT_DEFAULT_VARIOUS_WORD \     (((CVM_OBJECT_NO_HASH) << CVM_SYNC_BITS) | CVM_LOCKSTATE_UNLOCKED)/* For use only during GC. Is the hash state and lock state of the current   header word "trivial" (GC bits don't matter here). */#define CVMobjectTrivialHeaderWord(word)			\    (((word) & ((1 << (CVM_SYNC_BITS + CVM_HASH_BITS)) - 1))	\    == CVM_OBJECT_DEFAULT_VARIOUS_WORD)/* * The mask for a computed hash to make it fit in the hashCode field * of CVMVariousBitsData  */#define CVM_OBJECT_HASH_MASK ((1 << CVM_HASH_BITS) - 1)/* * Get the hash value, setting it first if necessary */extern CVMInt32CVMobjectGetHashSafe(CVMExecEnv *ee, CVMObjectICell* indirectObj);/* * Get the hash value, but only if it has already been set */extern CVMInt32CVMobjectGetHashNoSet(CVMExecEnv *ee, CVMObject* directObj);    #define CVMobjMonitorState(obj)				\	CVMhdrBitsSync(CVMobjectVariousWord((obj)))/*  * CVMobjMonitorSet() * f and m must be able to hold a native pointer because it is used * to used the variousWord value (struct CVMObjectHeader various32) * therefore the cast has to be CVMAddr which is 4 byte on * 32 bit platforms and 8 byte on 64 bit platforms */#define CVMobjMonitorSet(obj, m, t)			\    {							\	CVMAddr f;					\	f = (CVMAddr)(m);				\	CVMassert(CVMhdrBitsSync(f) == 0);		\	f |= t;						\	CVMassert(CVMhdrBitsPtr(f) == (CVMAddr)m);	\	CVMobjectVariousWord((obj)) = f;		\    }#define CVMobjMonitor(obj)				\    ((CVMObjMonitor *)CVMhdrBitsPtr(CVMobjectVariousWord((obj))))#define CVMobjectSyncKind(obj)   (CVMobjMonitorState((obj)) & 0x1)/* * Use of the GC bits. The only operation supported for now: * increment and get value.   * %comment rt002 */#define CVMobjGcBitsPlusPlusCompare(obj, limit)			\    (CVMobjMonitorState(obj) == CVM_LOCKSTATE_UNLOCKED ?	\        ((CVMobjectVariousWord((obj)) += (1 << CVM_GC_SHIFT)) & ~((1<<CVM_GC_SHIFT)-1)) < ((limit) << CVM_GC_SHIFT) :	\    (CVMobjMonitorState(obj) == CVM_LOCKSTATE_MONITOR ?		\        ((CVMobjMonitor(obj)->bits += (1 << CVM_GC_SHIFT)) & ~((1<<CVM_GC_SHIFT)-1)) < ((limit) << CVM_GC_SHIFT) : 	\        ((((CVMOwnedMonitor *)CVMhdrBitsPtr(CVMobjectVariousWord((obj))))->u.fast.bits \	     += (1 << CVM_GC_SHIFT)) & ~((1<<CVM_GC_SHIFT)-1)) < ((limit) << CVM_GC_SHIFT)))/* * The definition of an Object is somewhat circular. An Object is made * up of Object references. When accessed from C code, these slots are * defined to be of type ObjectICell for GC-safe access. So we give * the definition of an indirection cell, ICell, before we give the * definition of an Object. */#define CVM_ICELL_DECL(typename)                          \struct CVM ## typename ## ICell {	                      \    CVM ## typename * volatile ref_DONT_ACCESS_DIRECTLY;     \}CVM_ICELL_DECL(java_lang_Object);CVM_ICELL_DECL(Object); /* * Size of object and offsets of fields. * These are used in preloaded code to initialize the  * ClassBlock, FieldBlock and MethodBlock structures. * They are also used in JCC-generated header files to define * field offsets, as used in native code as arguments to the direct * and indirect memory-access functions. *//*  * For calculating the instance size it is required to * use sizeof(CVMAddr) instead of sizeof(CVMUint32) which * is only correct on 32 bit platforms. * * If we really want to get cleaner it's probably best to go all the way * and do object size calculations based on the real thing: CVMJavaVal32 */#define OBJ_SIZE(nwords) (sizeof(CVMObjectHeader)+(nwords)*sizeof(CVMJavaVal32))#define CVM_FIELD_OFFSET(nword) ((sizeof(CVMObjectHeader)/sizeof(CVMJavaVal32))+(nword))#define CVM_STATIC_OFFSET(nword) (nword)/* * Object monitors */enum {    CVM_OBJMON_OWNED_NEXT,	/* per-thread owned list */    CVM_OBJMON_SCAN_NEXT,	/* GC scan linked list */    CVM_OBJMON_NUM_LISTS};#define CVM_OBJMON_MAGIC 0xaa55a55a#if CVM_FASTLOCK_TYPE != CVM_FASTLOCK_NONE#if defined(CVM_ADV_THREAD_BOOST) && !defined(CVM_ADV_MUTEX_SET_OWNER)#define CVM_THREAD_BOOST#endif#endiftypedef enum {    CVM_OBJMON_FREE = 0,	/* on free list */    CVM_OBJMON_BOUND = 1,	/* on bound list */    CVM_OBJMON_OWNED = 2,	/* and on owned list */    CVM_OBJMON_BUSY = 0x4	/* is referenced by a ee->objLockCurrent */} CVMObjMonitorState;#ifdef __cplusplusstatic inline CVMObjMonitorState    operator|=(CVMObjMonitorState &lhs, const CVMObjMonitorState rhs){    return lhs = (CVMObjMonitorState)(lhs | rhs);}static inline CVMObjMonitorState    operator&=(CVMObjMonitorState &lhs, int rhs){    return lhs = (CVMObjMonitorState)(lhs & rhs);}#endifstruct CVMObjMonitor {    /*      * 'bits' is used as temporary storage for the member 'various32'     * of the struct 'CVMObjectHeader'. Since 'various32' is a CVMAddr     * 'bits' has to be a CVMAddr as well.     */    CVMAddr bits;    CVMProfiledMonitor mon;#ifdef CVM_DEBUG    CVMUint32 magic;    CVMOwnedMonitor *owner;#endif    CVMBool sticky;             /* keep around */    CVMObject *obj;		/* direct pointer */    CVMObjMonitorState state;    CVMObjMonitor *next;#ifdef CVM_THREAD_BOOST    CVMBool boost;#ifdef CVM_DEBUG    CVMExecEnv *boostThread;#endif    CVMThreadBoostRecord boostInfo;#endif};extern CVMBoolCVMobjMonitorInit(CVMExecEnv *ee, CVMObjMonitor *, CVMExecEnv *owner,    CVMUint32 count);extern voidCVMobjMonitorDestroy(CVMObjMonitor *m);extern CVMObjMonitor *CVMobjectInflatePermanently(CVMExecEnv *ee, CVMObjectICell* indirectObj);#define CVMobjMonitorOwner(m) CVMprofiledMonitorGetOwner(&(m)->mon)#define CVMobjMonitorCount(m) CVMprofiledMonitorGetCount(&(m)->mon)/* Purpose: Gets the CVMObject that this monitor corresponds to. */#define CVMobjMonitorDirectObject(m) ((m)->obj)/* Purpose: Casts a CVMProfiledMonitor into a CVMObjMonitor. *//* NOTE: The specified CVMProfiledMonitor must have already been determined to         be an instance of CVMObjMonitor.  This is possible because         CVMObjMonitor is actually a subclass of CVMProfiledMonitor. */#define CVMcastProfiledMonitor2ObjMonitor(self)    \    ((CVMObjMonitor *)(((CVMUint8 *)(self)) -      \                       CVMoffsetof(CVMObjMonitor, mon)))/* Purpose: Casts a CVMObjMonitor into a CVMProfiledMonitor. *//* NOTE: This is possible because CVMObjMonitor is a subclass of         CVMProfiledMonitor. */#define CVMcastObjMonitor2ProfiledMonitor(self) \    ((CVMProfiledMonitor *)(&(self)->mon))#define CVM_OWNEDMON_MAGIC 0xbaddabff/* special values for CVMOwnedMonitor.count */#define CVM_INVALID_REENTRY_COUNT ((CVMAddr)-1)#define CVM_MAX_REENTRY_COUNT	  ((CVMAddr)-256)typedef enum {    CVM_OWNEDMON_FAST = 0,	/* CVMProfiledMonitor not initialized */    CVM_OWNEDMON_HEAVY = 1	/* CVMProfiledMonitor initialized */} CVMOwnedMonitorType;#ifdef CVM_DEBUGtypedef enum {    CVM_OWNEDMON_FREE = 0,	/* on free list */    CVM_OWNEDMON_OWNED = 1	/* on owned list */} CVMOwnedMonitorState;#endifstruct CVMOwnedMonitor {    CVMExecEnv *owner;    CVMOwnedMonitorType type;    CVMObject *object;          /* direct pointer */    union {	/* for fast locks */	struct {	    CVMAddr bits;	} fast;	/* for heavy-weight monitor */	struct {	    CVMObjMonitor *mon;	} heavy;    } u;    CVMOwnedMonitor *next;#ifdef CVM_DEBUG    CVMUint32 magic;    CVMOwnedMonitorState state;#endif#if CVM_FASTLOCK_TYPE != CVM_FASTLOCK_NONE    /*      * The address of count is used as argument in      * CVMatomicCompareAndSwap() which expects      * the type volatile CVMAddr *     * (see objsync.c, CVMfastReentryTryLock())     * therefore the type has to be CVMAddr which is 4 byte on     * 32 bit platforms and 8 byte on 64 bit platforms     */    volatile CVMAddr count;   /* Lock re-entry count. */#endif};/* Purpose: Run all monitor scavengers. *//* NOTE: This function should only be called after all threads are consistent         i.e. GC safe. *//* NOTE: ee->objLocksOwned, and ee->objLocksFreeOwned may be changed by         CVMsyncGCSafeAllMonitorScavenge().  Do not cache these values across         a call to this function. */voidCVMsyncGCSafeAllMonitorScavenge(CVMExecEnv *ee);/* * So an object field is either an untyped 32-bit "slot", or a GC-safe * object reference  *//* * Generic 32-bit wide "Java slot" definition. This type occurs * in operand stacks, Java locals, object fields, constant pools. *//* * The field 'raw' is used to access the complete content of * union CVMJavaVal32 (for example for copying the whole union) * Because CVMObjectICell is a native pointer, the datatype of * raw requires to be CVMAddr which is 8 byte on 64 bit platforms * and 4 byte on 32 bit platforms. */union CVMJavaVal32 {    CVMJavaInt     i;    CVMJavaFloat   f;    CVMObjectICell r;    CVMAddr	   raw;};/* * Generic 64-bit Java value definition *//*  * CVMmemCopy64Stub is used for copying the 'raw' * field of struct JavaVal32 into v. * Because the raw field has been changed into type CVMAddr, * the type has to be changed accordingly.*/union CVMJavaVal64 {    CVMJavaLong   l;    CVMJavaDouble d;    CVMAddr	  v[2];};/* * The following two may appear in arrays */union CVMJavaVal16 {    CVMJavaShort   s;    CVMJavaChar    c;};union CVMJavaVal8 {    CVMJavaByte    b;    CVMJavaBoolean z;};/* * The "C superclass" of all Java objects. Arrays and all types of * Java objects may be cast to java_lang_Object* for uniform access to * the header. Also, all object fields can be accessed in a type-less * manner using this typedef.   */struct CVMjava_lang_Object {    volatile CVMObjectHeader         hdr;    volatile CVMJavaVal32            fields[1];};/* * Getting the first word of the object as an integer *//*  * CVMobjectGetClassWord() * - obj is CVMObject*,  * - hdr is CVMObjectHeader (preloader_impl.h) *

⌨️ 快捷键说明

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