gc_common.h
来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 670 行 · 第 1/2 页
H
670 行
* corresponding CVMClassBlock. \ */ \ if (cb_ == CVMsystemClass(java_lang_Class)) { \ CVMClassBlock* classBlockPtr = \ *((CVMClassBlock**)(obj) + \ CVMoffsetOfjava_lang_Class_classBlockPointer); \ CVMscanClassWithGCOptsIfNeeded(ee, classBlockPtr, gcOpts, \ callback, data); \ } \ CVMobjectWalkRefsAux(ee, gcOpts, obj, firstHeaderWord_, \ CVM_TRUE, refAction); \}#define CVMobjectWalkRefs(ee, gcOpts, obj, firstHeaderWord_, refAction) \ CVMobjectWalkRefsAux(ee, gcOpts, obj, firstHeaderWord_, CVM_FALSE, refAction)/* * Walk refs of heap object 'obj' with first header word * 'firstHeaderWord', and perform refAction on each discovered object * reference field. * * Within the body of refAction, CVMObject** refPtr refers to the * address of a reference typed slot (an array element, or an object * field). *//* * make CVM ready to run on 64 bit platforms * * CVMobjectWalkRefsAux() * * - firstHeaderWord_ is CVMClassBlock* * therefore the cast has to be CVMAddr which is 4 byte on * 32 bit platforms and 8 byte on 64 bit platforms * */#define CVMobjectWalkRefsAux(ee, gcOpts, obj, firstHeaderWord_, \ handleWeakReferences, refAction) \{ \ CVMClassBlock* cb_ = (CVMClassBlock*) \ (((CVMAddr)(firstHeaderWord_)) & CVM_OBJECT_CLASS_MASK); \ /* * Make 'map' the same type as 'map' in 'CVMGCBitMap'. \ */ \ CVMAddr map = CVMcbGcMap(cb_).map; \ CVMObject** refPtr; \ \ if (map != CVM_GCMAP_NOREFS) { \ /* * Make 'flags' the same type as 'map' in 'CVMGCBitMap'. \ */ \ CVMAddr flags = map & CVM_GCMAP_FLAGS_MASK; \ refPtr = (CVMObject**)&(obj)->fields[0]; \ \ if (flags == CVM_GCMAP_SHORTGCMAP_FLAG) { \ /* object with inline GC map: the most common case */ \ \ /* First skip the flags */ \ map >>= CVM_GCMAP_NUM_FLAGS; \ \ if (handleWeakReferences && \ (gcOpts)->discoverWeakReferences) { \ if (CVMcbIs(cb_, REFERENCE)) { \ /* Skip referent, next in case we just discovered \ a new active weak reference object. */ \ if (CVMweakrefField(obj, next) == NULL) { \ CVMweakrefDiscover(ee, obj); \ map >>= CVM_GCMAP_NUM_WEAKREF_FIELDS; \ refPtr += CVM_GCMAP_NUM_WEAKREF_FIELDS; \ } \ } \ } \ /* Now get through all the references in the object */ \ while (map != 0) { \ if ((map & 0x1) != 0) { \ refAction; \ } \ map >>= 1; \ refPtr++; \ } \ } else if (flags == CVM_GCMAP_ALLREFS_FLAG) { \ /* an array of all refs. Scan each and every one. */ \ CVMArrayOfRef* arrRefs = (CVMArrayOfRef*)(obj); \ CVMJavaInt arrLen = CVMD_arrayGetLength(arrRefs); \ \ /* \ * Address of the first element of the array \ * (skip the length field) \ */ \ /* * refPtr += 1 would work on 32-bit platforms. * But refPtr +1 does not fit on 64 bit platforms because the \ * length field is an int (4 byte) and a native pointer is \ * 8 byte on 64 bit platforms \ * Therefore get the start address of the elems array \ * instead of doing address calculations. \ */ \ refPtr = (CVMObject**) &arrRefs->elems[0]; \ while (arrLen-- > 0) { \ refAction; \ refPtr++; \ } \ } else { \ /* object with "big" GC map */ \ /* \ * CVMGCBitMap is a union of the scalar 'map' and the \ * pointer 'bigmap'. So it's best to \ * use the pointer if we need the pointer \ */ \ CVMBigGCBitMap* bigmap = (CVMBigGCBitMap*) \ ((CVMAddr)(CVMcbGcMap(cb_).bigmap) \ & ~CVM_GCMAP_FLAGS_MASK); \ CVMUint32 mapLen = bigmap->maplen; \ /* \ * Make 'mapPtr' and 'mapEnd' pointers to the type of 'map' \ * in 'CVMBigGCBitMap'. \ */ \ CVMAddr* mapPtr = bigmap->map; \ CVMAddr* mapEnd = mapPtr + mapLen; \ CVMObject** otherRefPtr = refPtr; \ \ CVMassert(flags == CVM_GCMAP_LONGGCMAP_FLAG); \ /* Make sure there is something to do */ \ CVMassert(mapPtr < mapEnd); \ map = *mapPtr; \ if (handleWeakReferences && \ (gcOpts)->discoverWeakReferences) { \ if (CVMcbIs(cb_, REFERENCE)) { \ /* Skip referent, next in case we just discovered \ a new active weak reference object. */ \ if (CVMweakrefField(obj, next) == NULL) { \ CVMweakrefDiscover(ee, obj); \ map >>= CVM_GCMAP_NUM_WEAKREF_FIELDS; \ refPtr += CVM_GCMAP_NUM_WEAKREF_FIELDS; \ } \ } \ } \ while (mapPtr < mapEnd) { \ while (map != 0) { \ if ((map & 0x1) != 0) { \ refAction; \ } \ map >>= 1; \ refPtr++; \ } \ mapPtr++; \ /* This may be a redundant read that may fall off the \ edge of the world. To prevent this case, \ we've left an extra \ safety word in the big map. */ \ map = *mapPtr; \ /* Advance the object pointer to the next group of 32 \ * fields, in case map becomes 0 before we iterate \ * through all the fields in group *mapPtr \ */ \ otherRefPtr += 32; \ refPtr = otherRefPtr; \ } \ } \ } \}/* * Initiate a GC. Acquire all GC locks, stop all threads, and then * call back to the particular GC to do the work. When the particular * GC is done, resume. * * Called with heap locked and while GC-unsafe. * return CVM_TRUE on success, CVM_FALSE if GC could not be run. */extern CVMBoolCVMgcStopTheWorldAndGC(CVMExecEnv* ee, CVMUint32 numBytes);#ifdef CVM_INSPECTOR/* Purpose: Synchronizes all threads on a consistent state in preparation for a GC or similar cycles. */extern CVMBoolCVMgcStopTheWorldAndDoAction(CVMExecEnv *ee, void *data, CVMUint32 (*preActionCallback)(CVMExecEnv *ee, void *data), CVMBool (*actionCallback)(CVMExecEnv *ee, void *data), void (*postActionCallback)(CVMExecEnv *ee, void *data, CVMBool actionSuccess, CVMUint32 preActionStatus), void (*retryAfterActionCallback)(CVMExecEnv *ee, void *data), void* retryData);#endif/* * Start a GC cycle. Will clear class marks if necessary. */extern voidCVMgcStartGC(CVMExecEnv* ee);/* * Clear the class GC_SCANNED marks for dynamically loaded classes. */extern voidCVMgcClearClassMarks(CVMExecEnv* ee, CVMGCOptions* gcOpts);/* * End a GC cycle. */extern voidCVMgcEndGC(CVMExecEnv* ee);/* * Like above, but called without heap locked and while GC-safe. */extern voidCVMgcRunGC(CVMExecEnv* ee);/* * The null CVMFrameGCScannerFunc that doesn't do anything */extern voidCVMnullFrameScanner(CVMFrame* frame, CVMStackChunk* chunk, CVMRefCallbackFunc callback, void* data);/* * Process special objects with liveness info from a particular GC * implementation. This covers special scans like string intern table, * weak references and monitor structures. * * isLive - a predicate that returns true if an object is strongly referenced * transitiveScanner - a callback that marks an object and all its children */extern voidCVMgcProcessSpecialWithLivenessInfo(CVMExecEnv* ee, CVMGCOptions* gcOpts, CVMRefLivenessQueryFunc isLive, void* isLiveData, CVMRefCallbackFunc transitiveScanner, void* transitiveScannerData);/* Process weak references with liveness info from a particular GC * implementation. * isLive - a predicate that returns true if an object is strongly referenced * transitiveScanner - a callback that marks an object and all its children */voidCVMgcProcessWeakrefWithLivenessInfo(CVMExecEnv* ee, CVMGCOptions* gcOpts, CVMRefLivenessQueryFunc isLive, void* isLiveData, CVMRefCallbackFunc transitiveScanner, void* transitiveScannerData);/* Process interned strings with liveness info from a particular GC * implementation. * isLive - a predicate that returns true if an object is strongly referenced * transitiveScanner - a callback that marks an object and all its children */voidCVMgcProcessInternedStringsWithLivenessInfo(CVMExecEnv* ee, CVMGCOptions* gcOpts, CVMRefLivenessQueryFunc isLive, void* isLiveData, CVMRefCallbackFunc transitiveScanner, void* transitiveScannerData);/* * Process special objects with liveness info from a particular GC * implementation. This covers special scans like string intern table, * and monitor structures. * * This purposefully leaves out weak references for the rare GC that * wants to treat weak references specially. * * isLive - a predicate that returns true if an object is strongly referenced * transitiveScanner - a callback that marks an object and all its children */extern voidCVMgcProcessSpecialWithLivenessInfoWithoutWeakRefs( CVMExecEnv* ee, CVMGCOptions* gcOpts, CVMRefLivenessQueryFunc isLive, void* isLiveData, CVMRefCallbackFunc transitiveScanner, void* transitiveScannerData);/* * Scan and optionally update special objects. This covers special * scans like string intern table, weak references and monitor * structures. */extern voidCVMgcScanSpecial(CVMExecEnv* ee, CVMGCOptions* gcOpts, CVMRefCallbackFunc callback, void* data);/* * Scan the root set of collection */extern voidCVMgcScanRoots(CVMExecEnv* ee, CVMGCOptions* gcOpts, CVMRefCallbackFunc callback, void* data);/* Purpose: Attempts to compute stackmaps for all the GC's root scan. *//* Returns: CVM_TRUE if successful, else returns CVM_FALSE. */extern CVMBoolCVMgcEnsureStackmapsForRootScans(CVMExecEnv *ee);/* * Destroy the heap */extern CVMBool CVMgcDestroyHeap();#if defined(CVM_INSPECTOR) || defined(CVM_JVMPI) || defined(CVM_JVMTI)/* Purpose: Scans objects in the specified memory range and invoke the callback function on each object. */extern CVMBoolCVMgcScanObjectRange(CVMExecEnv* ee, CVMUint32* base, CVMUint32* top, CVMObjectCallbackFunc callback, void* callbackData);#endif#ifdef CVM_JVMPI/* Purpose: Posts the JVMPI_EVENT_ARENA_NEW events. *//* NOTE: This function is necessary to compensate for the fact that this event has already transpired by the time that JVMPI is initialized. */void CVMgcPostJVMPIArenaNewEvent(void);/* Purpose: Gets the last shared arena ID that is used by shared code. GC specific implementations should start their arena ID after the last shared arena ID returned by this function. */extern CVMUint32 CVMgcGetLastSharedArenaID(void);/* Purpose: Gets the arena ID for the specified object. */extern CVMUint32 CVMgcGetArenaID(CVMObject *obj);#endif#define CVMgcIsInSafeAllState() \ (CVM_CSTATE(CVM_GC_SAFE)->reached)#if defined(CVM_DEBUG) || defined(CVM_INSPECTOR)/* Dumps info about the configuration of the GC. */#define CVMgcDumpSysInfo() CVMgcimplDumpSysInfo()#endif#endif /* _INCLUDED_GC_COMMON_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?