gc_common.h
来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 670 行 · 第 1/2 页
H
670 行
/* * 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 includes functions common to all GCs. It is the interface * between a particular GC implementation and the rest of the VM. */#ifndef _INCLUDED_GC_COMMON_H#define _INCLUDED_GC_COMMON_H#include "javavm/include/defs.h"#include "javavm/include/objects.h"#include "javavm/include/classes.h"#include "javavm/include/stacks.h"#include "javavm/include/gc/gc_impl.h"#include "javavm/include/basictypes.h"#include "javavm/include/preloader.h"#include "javavm/include/weakrefs.h"#include "javavm/include/utils.h"#include "generated/offsets/java_lang_Class.h"/* * The default min and max sizes of the heap */#ifdef JAVASE#ifndef CVM_DEFAULT_MAX_HEAP_SIZE_IN_BYTES#define CVM_DEFAULT_MAX_HEAP_SIZE_IN_BYTES (32 * 1024 * 1024)#endif#ifndef CVM_DEFAULT_MIN_HEAP_SIZE_IN_BYTES#define CVM_DEFAULT_MIN_HEAP_SIZE_IN_BYTES (4 * 1024 * 1024)#endif#ifndef CVM_DEFAULT_START_HEAP_SIZE_IN_BYTES#define CVM_DEFAULT_START_HEAP_SIZE_IN_BYTES (4 * 1024 * 1024)#endif#endif#ifndef CVM_DEFAULT_MAX_HEAP_SIZE_IN_BYTES#define CVM_DEFAULT_MAX_HEAP_SIZE_IN_BYTES (5 * 1024 * 1024)#endif#ifndef CVM_DEFAULT_MIN_HEAP_SIZE_IN_BYTES#define CVM_DEFAULT_MIN_HEAP_SIZE_IN_BYTES (2 * 1024 * 1024)#endif#ifndef CVM_DEFAULT_START_HEAP_SIZE_IN_BYTES#define CVM_DEFAULT_START_HEAP_SIZE_IN_BYTES (2 * 1024 * 1024)#endiftypedef struct CVMGCCommonGlobalState CVMGCCommonGlobalState;struct CVMGCCommonGlobalState { /* * GC attributes, to be parsed by the GC implementation */ CVMParsedSubOptions gcOptions; CVMUint32 maxStackMapsMemorySize; /* Runtime state information to optimize GC scans: */ CVMBool doClassCleanup; CVMBool stringInternedSinceLastGC; CVMBool classCreatedSinceLastGC; CVMBool loaderCreatedSinceLastGC; /* Cached stackMaps */ CVMStackMaps *firstStackMaps; CVMStackMaps *lastStackMaps; CVMUint32 stackMapsTotalMemoryUsed;};#define CVM_GC_SHARED_OPTIONS "[maxStackMapsMemorySize=<size>][,stat=true]"#ifdef CVM_GCIMPL_GC_OPTIONS#define CVM_GC_OPTIONS "[-Xgc:"\ CVM_GC_SHARED_OPTIONS\ CVM_GCIMPL_GC_OPTIONS\ "] "#else#define CVM_GC_OPTIONS "[-Xgc:"\ CVM_GC_SHARED_OPTIONS\ "] "#endif/* * A structure indicating the current GC mode. This is passed around * the root scan phase. */struct CVMGCOptions { CVMBool isUpdatingObjectPointers; CVMBool discoverWeakReferences;#if defined(CVM_INSPECTOR) || defined(CVM_JVMPI) || defined(CVM_JVMTI) CVMBool isProfilingPass;#endif};#if defined(CVM_INSPECTOR) || defined(CVM_JVMPI) || defined(CVM_JVMTI)/* CVM_GC_ARENA_UNKNOWN is reserved for error conditions where the arenaID of an object is unknown. A valid arenaID should never have the same value as CVM_GC_ARENA_UNKNOWN (i.e. should never be 0): */#define CVM_GC_ARENA_UNKNOWN 0/* The following enumerates the type of GC roots that are found during a GC scan: NOTE: CVMGCRefType_INVALID is reserved for error cases. It does not correspond to any real reference types.*/enum CVMGCRefType { CVMGCRefType_INVALID = 0, CVMGCRefType_GLOBAL_ROOT, CVMGCRefType_PRELOADER_STATICS, CVMGCRefType_CLASS_STATICS, CVMGCRefType_LOCAL_ROOTS, CVMGCRefType_UNKNOWN_STACK_FRAME, CVMGCRefType_JAVA_FRAME, CVMGCRefType_JNI_FRAME, CVMGCRefType_TRANSITION_FRAME, CVMGCRefType_OBJECT_FIELD};typedef enum CVMGCRefType CVMGCRefType;/* The following structure is used to store profiling information to be passed as the data argument to a callback function during a GC root scan if the isProfilingPass flag is set to CVM_TRUE in the CVMGCOptions: */typedef struct CVMGCProfilingInfo CVMGCProfilingInfo;struct CVMGCProfilingInfo { CVMGCRefType type; void *data; union { struct { CVMClassBlock *cb; } clazz; struct { CVMExecEnv *ee; CVMInt32 frameNumber; } frame; } u;};/*================================================== CVMGCLocker mechanism ==*//* Class CVMGCLocker used for disabling GC Collection and Compaction cycles for debugging or profiling purposes: */typedef struct CVMGCLocker CVMGCLocker;struct CVMGCLocker{ volatile CVMUint32 lockCount; volatile CVMBool wasContended;};/* Purpose: Constuctor. */void CVMgcLockerInit(CVMGCLocker *self);/* Purpose: Destructor. */#define CVMgcLockerDestroy(/* CVMGCLocker * */self) ;/* Purpose: Indicates if the GC lock is activated. */#define CVMgcLockerIsActive(/* CVMGCLocker * */self) \ ((self)->lockCount > 0)/* Purpose: Gets the lockCount of the GC lock. */#define CVMgcLockerGetLockCount(/* CVMGCLocker * */self) \ ((self)->lockCount)/* Purpose: Activates the GC lock. *//* NOTE: Calls to CVMgcLockerLock() & CVMgcLockerUnlock() can be nested. */void CVMgcLockerLock(CVMGCLocker *self, CVMExecEnv *current_ee);/* Purpose: Deactivates the GC lock. *//* NOTE: Calls to CVMgcLockerLock() & CVMgcLockerUnlock() can be nested. */void CVMgcLockerUnlock(CVMGCLocker *self, CVMExecEnv *current_ee);/*===========================================================================*//* Purpose: Checks to see if the specified thread is running the GC. */#define CVMgcIsGCThread(/* CVMExecEnv * */ ee) \ (CVM_CSTATE(CVM_GC_SAFE)->requester == ee)#endif#ifdef CVM_MTASKextern CVMBoolCVMgcParseXgcOptions(CVMExecEnv* ee, const char* xgcOpts);#endif/* * Extracts 'minBytes' and 'maxBytes' from options, then * initializes a heap of at least 'minBytes' bytes, and at most 'maxBytes' * bytes. */extern CVMBool CVMgcInitHeap(CVMOptions *options);/* * Get GC attribute named 'attrName'. * Return NULL if not found. */extern char *CVMgcGetGCAttributeVal(char* attrName);/* * Allocate heap object of type 'cb'. */extern CVMObject*CVMgcAllocNewInstance(CVMExecEnv* ee, CVMClassBlock* cb);/* * Allocate java.lang.Class instance corresponding to 'cbOfJavaLangClass' */extern CVMObject*CVMgcAllocNewClassInstance(CVMExecEnv* ee, CVMClassBlock* cbOfJavaLangClass); /* * Allocate heap array of length 'len'. The type of the array is arrayCb. * The elements are basic type 'typeCode'. */extern CVMArrayOfAnyType*CVMgcAllocNewArray(CVMExecEnv* ee, CVMBasicType typeCode, CVMClassBlock* arrayCb, CVMJavaInt len);/* * Allocate heap array of length 'len'. The type of the array is arrayCb. * The total size of the array is 'instanceSize'. */extern CVMArrayOfAnyType*CVMgcAllocNewArrayWithInstanceSize(CVMExecEnv* ee, CVMJavaInt instanceSize, CVMClassBlock* arrayCb, CVMJavaInt len);/* * Return the number of bytes free in the heap */extern CVMJavaLongCVMgcFreeMemory(CVMExecEnv* ee);/* * Return the amount of total memory in the heap, in bytes */extern CVMJavaLongCVMgcTotalMemory(CVMExecEnv* ee);/* * Constants related to object reference map formats */#define CVM_GCMAP_NUM_FLAGS 2 /* the no. of flags bits in the map */#define CVM_GCMAP_NUM_WEAKREF_FIELDS 2 /* the no. of special fields in java.lang.ref.Reference */#define CVM_GCMAP_FLAGS_MASK ((1 << CVM_GCMAP_NUM_FLAGS) - 1)#define CVM_GCMAP_NOREFS 0x0 /* No references in this object */#define CVM_GCMAP_SHORTGCMAP_FLAG 0x0 /* 0 - object with inline GC map */#define CVM_GCMAP_ALLREFS_FLAG 0x1 /* 1 - array of all references */#define CVM_GCMAP_LONGGCMAP_FLAG 0x2 /* 2 - object with long GC map *//* * Walk refs of heap object 'obj' with first header word * 'firstHeaderWord', and perform refAction on each discovered object * reference field. Also scan class of object if it has not been scanned * yet. * * Within the body of refAction, CVMObject** refPtr refers to the * address of a reference typed slot (an array element, or an object * field). * * CVMscanClassIfNeeded(CVMExecEnv* ee, CVMClassBlock* cb, * CVMRefCallbackFunc callback, void* data); */#define CVMscanClassIfNeededConditional(ee, cb, cond, callback, data) \ if (!CVMcbIsInROM(cb) && !CVMcbGcScanned(cb)) { \ if (cond) { \ CVMclassScan(ee, cb, callback, data); \ CVMcbSetGcScanned(cb); \ } \ }#define CVMscanClassIfNeeded(ee, cb, callback, data) \ CVMscanClassIfNeededConditional(ee, cb, CVM_TRUE, callback, data)#if defined(CVM_INSPECTOR) || defined(CVM_JVMPI) || defined(CVM_JVMTI)#define CVMscanClassWithGCOptsIfNeeded(ee_, cb_, gcOpts_, callback_, data_) \ if (!CVMcbIsInROM(cb_) && !CVMcbGcScanned(cb_)) { \ CVMGCProfilingInfo info_; \ void *callbackData_ = data_; \ if (gcOpts_->isProfilingPass) { \ info_.type = CVMGCRefType_CLASS_STATICS; \ info_.data = data_; \ info_.u.clazz.cb = cb_; \ callbackData_ = &info_; \ } \ CVMclassScan(ee_, cb_, callback_, callbackData_); \ CVMcbSetGcScanned(cb_); \ }#else#define CVMscanClassWithGCOptsIfNeeded(ee, cb, gcOpts, callback, data) \ CVMscanClassIfNeeded(ee, cb, callback, data)#endif/* * make CVM ready to run on 64 bit platforms * * CVMobjectWalkRefsWithSpecialHandling() * * - 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 CVMobjectWalkRefsWithSpecialHandling(ee, gcOpts, obj, \ firstHeaderWord_, refAction, \ callback, data) \{ \ CVMClassBlock* cb_ = (CVMClassBlock*) \ (((CVMAddr)(firstHeaderWord_)) & CVM_OBJECT_CLASS_MASK); \ CVMscanClassWithGCOptsIfNeeded(ee, cb_, gcOpts, callback, data); \ /* \ * If we are scanning a java.lang.Class instance, scan its \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?