📄 garbage.h
字号:
/*0154*//* int markBit :1; */
/*0155*//* int staticBit :1; */
/*0156*//* }; */
/*0157*/
/*0158*//* The amount of bits that will have to be shifted away
/*0159./ * in order to read the object length correctly
/*0160./ */
/*0161*/
/*0162*/#define inAnyHeap(ptr) \
/*0163*/ (((cell *)ptr >= AllHeapStart) && ((cell *)ptr < AllHeapEnd))
/*0164*/
/*0165*/#define inCurrentHeap(ptr) \
/*0166*/ (((cell *)ptr >= CurrentHeap) && ((cell *)ptr < CurrentHeapEnd))
/*0167*/
/*0168*/#define TYPEBITS 8
/*0169*/
/*0170*//* The number of bits that we have to shift to get the type */
/*0171*/#define TYPE_SHIFT 2
/*0172*/
/*0173*//*=========================================================================
/*0174./ * Operations on header words
/*0175./ *=======================================================================*/
/*0176*/
/*0177*/#define ISMARKED(n) ((n) & MARKBIT)
/*0178*/#define ISSTATIC(n) ((n) & STATICBIT)
/*0179*/#define SIZE(n) (((cell)(n)) >> TYPEBITS)
/*0180*/#define TYPE(n) (GCT_ObjectType)(((n) & TYPEMASK) >> TYPE_SHIFT)
/*0181*/#define ISFREECHUNK(n) (((n) & (TYPEMASK | MARKBIT | STATICBIT)) == 0)
/*0182*/
/*0183*//* Header is 1 word long */
/*0184*/#define HEADERSIZE 1
/*0185*/
/*0186*//*=========================================================================
/*0187./ * FREE LIST STRUCTURES:
/*0188./ * The garbage collector maintains a free list of available memory.
/*0189./ * Every available memory chunk is preceded by a free list header with
/*0190./ * the following information:
/*0191./ *
/*0192./ * +--------------+
/*0193./ * ! size ! (the amount of memory in this chunk)
/*0194./ * +--------------+
/*0195./ * ! next ! (pointer to the next chunk in the free list)
/*0196./ * +--------------+
/*0197./ *
/*0198./ * The size information is stored in cells (32 bit words). The size
/*0199./ * information is stored in the same format as in regular object headers,
/*0200./ * i.e., only the highest 24 bits are used (see above). The 6 low bits
/*0201./ * must all be zero for a word to be recognized as a chunk header. The size
/*0202./ * excludes the size field (HEADERSIZE) itself, i.e., if the physical
/*0203./ * size of the chunk is 3 words, the size field actually contains 2.
/*0204./ *
/*0205./ * As obvious, the next field is NIL (0) if this is the last
/*0206./ * free chunk in memory.
/*0207./ *
/*0208./ * Chunks are always at least 2 words (64 bits) long, because this
/*0209./ * is the minimum size needed for allocating new objects. Free memory
/*0210./ * areas smaller than this are automatically merged with other objects
/*0211./ * (thus creating permanent garbage). In practice this happens rarely,
/*0212./ * though.
/*0213./ *=======================================================================*/
/*0214*/
/*0215*//* CHUNK */
/*0216*/struct chunkStruct {
/*0217*/ long size; /* The size of the chunk in words (including the header) */
/*0218*/ CHUNK next; /* Pointer to the next chunk (NIL if none) */
/*0219*/};
/*0220*/
/*0221*//*=========================================================================
/*0222./ * As a Palm specific option, the static portion of a Palm device's memory
/*0223./ * can be used to store relatively static structures such as the constant
/*0224./ * pool and code of a class. By storing these structures in static memory
/*0225./ * a substantial amount of room is freed up for use by the garbage
/*0226./ * collected heap. Given that we expect anything put into static memory to
/*0227./ * live for the lifetime of a VM execution, we can implement the management
/*0228./ * of any static memory chunks simply as a list of chunks that are all
/*0229./ * freed upon the end of execution. As such the basic structure of a
/*0230./ * statically allocated chunk will be as follows:
/*0231./ *
/*0232./ * +---------------+
/*0233./ * ! prev chunk ptr! (bit 0: bump bit)
/*0234./ * +---------------+
/*0235./ * Object pointer -> ! ! ^
/*0236./ * +---------------+ !
/*0237./ * . . !
/*0238./ * . . data
/*0239./ * . . !
/*0240./ * ! ! !
/*0241./ * +---------------+ !
/*0242./ * ! ! v
/*0243./ * +---------------+
/*0244./ *
/*0245./ * These chunks are allocated via the mallocStaticBytes operation and are
/*0246./ * all collected at once by the FinalizeStaticMemory operation.
/*0247./ *=======================================================================*/
/*0248*/
/*0249*//* Since the PalmOS memory returns two-byte aligned addresses, */
/*0250*//* we must occasionally bump the statically allocated object */
/*0251*//* addresses upwards in the memory (by two bytes). This is */
/*0252*//* indicated by raising a special "bump bit" stored in the */
/*0253*//* least significant bit in the previous chunk pointer field */
/*0254*//* (shown above). */
/*0255*/
/*0256*/#define STATICBUMPBIT 0x00000001
/*0257*/#define STATICBUMPMASK 0xFFFFFFFE
/*0258*/
/*0259*//*=========================================================================
/*0260./ * Garbage collection types of objects (GCT_* types)
/*0261./ *=========================================================================
/*0262./ * These types are used for instructing the garbage collector to
/*0263./ * scan the data fields of objects correctly upon garbage collection.
/*0264./ * Since two low-end bits of the first header field are used for
/*0265./ * flags, we don't use these in type declarations.
/*0266./ *=======================================================================*/
/*0267*/
/*0268*/typedef enum {
/*0269*/ GCT_FREE = 0,
/*0270*/ /* Objects which have no pointers inside them */
/*0271*/ /* (can be ignored safely during garbage collection) */
/*0272*/ GCT_NOPOINTERS,
/*0273*/
/*0274*/ /* Java-level objects which may have mutable pointers inside them */
/*0275*/ GCT_INSTANCE,
/*0276*/ GCT_ARRAY,
/*0277*/ GCT_OBJECTARRAY,
/*0278*/
/*0279*/ /* Only if we have static roots */
/*0280*/ GCT_METHODTABLE ,
/*0281*/
/*0282*/ /* Internal VM objects which may have mutable pointers inside them */
/*0283*/ GCT_POINTERLIST,
/*0284*/ GCT_EXECSTACK,
/*0285*/ GCT_THREAD,
/*0286*/ GCT_MONITOR,
/*0287*/ /* A weak pointer list gets marked/copied after all other objects */
/*0288*/ GCT_WEAKPOINTERLIST
/*0289*/} GCT_ObjectType;
/*0290*/
/*0291*/#define GCT_FIRSTVALIDTAG GCT_NOPOINTERS
/*0292*/#define GCT_LASTVALIDTAG GCT_WEAKPOINTERLIST
/*0293*/
/*0294*/#define GCT_TYPENAMES { \
/*0295*/ "FREE", \
/*0296*/ "NOPOINTERS", \
/*0297*/ "INSTANCE", \
/*0298*/ "ARRAY", \
/*0299*/ "OBJECTARRAY", \
/*0300*/ "METHODTABLE", \
/*0301*/ "POINTERLIST", \
/*0302*/ "EXECSTACK", \
/*0303*/ "THREAD", \
/*0304*/ "MONITOR", \
/*0305*/ "WEAK POINTERLIST", \
/*0306*/ }
/*0307*/
/*0308*//*=========================================================================
/*0309./ * Dynamic heap variables
/*0310./ *=======================================================================*/
/*0311*/
/*0312*/extern cell* AllHeapStart; /* Lower limits of any heap space */ //\\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -