interpreter.h
来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 1,552 行 · 第 1/4 页
H
1,552 行
/* * 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. * */#ifndef _INCLUDED_INTERPRETER_H#define _INCLUDED_INTERPRETER_H#include "javavm/include/defs.h"#include "javavm/include/cni.h"#include "javavm/include/stacks.h"#include "javavm/include/sync.h"#include "javavm/include/cstates.h"#include "javavm/include/jni_impl.h"#include "javavm/include/gc_common.h"#include "javavm/include/porting/threads.h"#include "javavm/include/porting/vm-defs.h"#ifdef CVM_JIT#include "javavm/include/jit_common.h"#include "javavm/include/porting/jit/jit.h"#endif#ifdef CVM_LVM /* %begin lvm */#include "javavm/include/lvm/lvm.h"#endif /* %end lvm */#ifdef CVM_JVMTI#include "javavm/include/jvmtiExport.h"#endif#define CVMJAVAPKG "java/lang/"/* * Conveniently, these bits correspond to JVMTI_THREAD_STATE_XXX bits */typedef enum { CVM_THREAD_RUNNING = 0x0, CVM_THREAD_TERMINATED = 0x2, CVM_THREAD_WAITING_INDEFINITE = 0x10, CVM_THREAD_WAITING_TIMEOUT = 0x20, CVM_THREAD_SLEEPING = 0x40, CVM_THREAD_WAITING = 0x80, CVM_THREAD_OBJECT_WAIT = 0x100, CVM_THREAD_BLOCKED_MONITOR_ENTER = 0x400, CVM_THREAD_SUSPENDED = 0x100000, CVM_THREAD_INTERRUPTED = 0x200000, CVM_THREAD_IN_NATIVE = 0x400000, CVM_THREAD_STACK_MUTATOR_LOCK = 0x800000} CVMThreadState;/* * Per-thread C stack global pool operations and macros */#define CVM_CSTACK_BUF_SIZE 8192 /* Fixed size of the EE buffer used by * ZipFile and RandomAccess IO read * and write operation. */#define CVMCstackBuffer(ee) ((ee)->cstackBuffer)#define CVMCstackBufferFlag(ee) ((ee)->cstackBufferFlag)#define CVMCstackBufferIsNull(ee) ((ee)->cstackBuffer == NULL)#define CVMCstackBufferIsSet(ee) ((ee)->cstackBufferFlag)/* * The flag that tells the status of the EE-buffer is initially unset * when a thread is created */#define CVMCstackBufferInit(ee) { \ (ee)->cstackBufferFlag = CVM_FALSE; \ } /* * Return C stack global buffer in ee if exists. * Otherwise, allocate C stack global buffer in ee. * Assert that the flag is not set before using the EE-buffer. * The flag is set when the buffer allocated successfully. Otherwise, * it remains unset. */#define CVMCstackGetBuffer(ee, buf) { \ CVMassert(!CVMCstackBufferIsSet(ee)); \ if (CVMCstackBufferIsNull(ee)) { \ CVMCstackBuffer(ee) = (char *)malloc(CVM_CSTACK_BUF_SIZE); \ } \ buf = CVMCstackBuffer(ee); \ if (buf != NULL) { \ CVMCstackBufferFlag(ee) = CVM_TRUE; \ } \ }/* * Deallocate the EE-buffer when a thread is killed. * Assert that the flag is not set before freeing the EE-buffer. */#define CVMCstackFreeBuffer(ee) { \ CVMassert(!CVMCstackBufferIsSet(ee)); \ if (!CVMCstackBufferIsNull(ee)) \ free(CVMCstackBuffer(ee)); \ }/* * Release the EE-buffer at the end of the buffer operation. * Assert that the flag is set before it's released. */#define CVMCstackReleaseBuffer(ee) { \ CVMassert(CVMCstackBufferIsSet(ee)); \ CVMCstackBufferFlag(ee) = CVM_FALSE; \ }/* * States for isHandlingAnException. */typedef enum { CVM_EXCEPTION_NONE = 0, /* no exception handling in progress */ CVM_EXCEPTION_TOP, /* exception thrown in current frame */ CVM_EXCEPTION_UNWINDING /* stack unwinding in progress */}CVMExceptionState;/**************************************************************************** * CVMExecEnv * * CVMExecEnv is the per thread execution context. ****************************************************************************/struct CVMExecEnv { /* per-thread data for consistent states */ CVMTCState tcstate[CVM_NUM_CONSISTENT_STATES]; CVMUint8 isThrowingAnException; CVMUint8 isHandlingAnException; CVMUint16 remoteExceptionsDisabledCount; CVMThrowableICell* localExceptionICell; /* local exception object */ CVMThrowableICell* remoteExceptionICell; /* remote exception object */ CVMThrowableICell* currentExceptionICell;/* exception being processed */ union { struct { CVMUint8 remote; /* async, like from Thread.stop() */ CVMUint8 local; /* local to the interpreter */ } oneflag; CVMUint16 bothflags; /* for checking both flags at one time */ } exceptionFlags; CVMThreadICell* threadICell;/* back-pointer to thread object */ CVMObjectICell* miscICell; /* Per-thread root for miscellaneous use */ CVMObjectICell* syncICell; /* Per-thread root for the sync code use. */ /* * CVMgcAllocNewInstance() needs a root to hold the newly allocated object * in if it has to call Finalizer.register() on that object. */ CVMObjectICell* finalizerRegisterICell; CVMJNIEnv jniEnv; /* per-thread JNI data */ /* linked-list of EE's */ CVMExecEnv **prevEEPtr; CVMExecEnv *nextEE; CVMStack interpreterStack; /* stack for interpreter frames */ CVMStack localRootsStack; /* stack for local root frames */ CVMBool cstackBufferFlag; /* flag to tell the EE buffer is in use */ char *cstackBuffer; /* buffer for reading bytes of data from * input stream into a global pool for * Java_java_io_FileInputStream_readBytes * Java_java_io_RandomAccessFile_readBytes */ void * nativeRunInfo; /* for "system" threads */ /* NOTE: objLockCurrent could be replaced by an atomically-updated integer reference count */ CVMObjMonitor * volatile objLockCurrent; /* being referenced, set while unsafe */ CVMObjMonitor *objLocksFreeUnlocked; CVMOwnedMonitor *objLocksOwned; /* list of all CVMObjMonitor locks owned */ CVMOwnedMonitor *objLocksFreeOwned; /* pre-allocated memory for thread shutdown */ CVMBool threadExiting; CVMOwnedMonitor *objLocksReservedOwned; CVMObjMonitor *objLocksReservedUnlocked;#ifdef CVM_JIT CVMMethodBlock* invokeMb; /* method currently being invoked */ CVMInt32 noOSRSkip; CVMInt8 noOSRStackAdjust; CVMBool noCompilations; /* if true, thread can't do compilations */#endif CVMThreadID threadInfo; /* platform-specific thread info */ CVMThreadState threadState; CVMUint32 threadID;#ifdef CVM_DEBUG_ASSERTS int nativeRunInfoType;#endif#ifdef CVM_DEBUG CVMSysMutex *sysLocks; /* list of all CVMSysMutex locks held */ int microLock; /* micro lock depth */#endif CVMBool userThread; /* true if not a daemon thread */ /* For GC-safe returns of the results of allocation retries. */ CVMObjectICell* allocationRetryICell; /* for tracking nesting of CVMD_gcEnterCriticalRegion calls */ CVMUint32 criticalCount; CVMBool hasPostedExitEvents;#ifdef CVM_JVMTI volatile CVMJvmtiExecEnv jvmtiEE;#endif#ifdef CVM_JVMPI void *jvmpiProfilerData; /* JVMPI Profiler thread-local data. */#endif#if defined(CVM_JVMPI) || defined(CVM_JVMTI) CVMProfiledMonitor *blockingLockEntryMonitor; CVMProfiledMonitor *blockingWaitMonitor; CVMBool hasRun; /* Has this thread run since its last suspension? */#endif#ifdef CVM_TEST_GC CVMBarrierType barrier;#endif#ifdef CVM_LVM /* %begin lvm */ CVMLVMExecEnv lvmEE; /* Info on LVM to which this EE belongs */#endif /* %end lvm */#ifdef CVM_TRACE_ENABLED#ifdef CVM_PROFILE_METHOD CVMInt64 t0; CVMMethodBlock *cmb; int cindx; int traceEra;#endif#endif CVMBool interruptsMasked; /* See CVM.maskInterrupts() */ CVMBool maskedInterrupt; /* Was Thread.interrupt() called while interrupts were masked? */#if defined(CVMJIT_SIMPLE_SYNC_METHODS) \ && CVM_FASTLOCK_TYPE == CVM_FASTLOCK_ATOMICOPS CVMOwnedMonitor simpleSyncReservedOwnedMonitor;#if CVM_DEBUG /* The currently executing Simple Sync method and the method that inlined the currently executing Simple Sync method. Note that these are set every time a Simple Sync method is executed and are never cleared, thus they can be stale. */ CVMMethodBlock* currentSimpleSyncMB; CVMMethodBlock* currentMB;#endif#endif /* pinned object monitors during thread shutdown */ /* 16 is overkill. To find the minimum number, build */ /* with CVM_FASTLOCK_TYPE set to CVM_FASTLOCK_NONE */#define CVM_PINNED_OBJMON_COUNT 16 CVMObjMonitor *objLocksPinned[CVM_PINNED_OBJMON_COUNT]; CVMSize objLocksPinnedCount;#ifdef CVM_TRACE CVMUint32 traceDepth;#endif#ifdef CVM_INSPECTOR CVMInt32 priority; CVMUint32 tickCount;#endif#ifdef CVM_TRACE_ENABLED CVMUint32 debugFlags;#endif};/* * This structure is used to pass info from a parent thread to a child. * This is actually the (void *) argument passed to start_func through * CVMthreadCreate. This data structure is required to be allocated * using malloc() by the caller; start_func is responsible for * freeing it. */typedef struct { /* This is required to be non-NULL and to point to a valid global * root which contains a java.lang.Thread object. start_func is * responsible for holding on to the Thread object (by storing it * in the new thread's execution environment's currentThreadICell) * and deallocating the global root. */ CVMThreadICell* threadICell; /* This function pointer must be NULL for all Java threads (i.e., * those started by a call to JVM_StartThread). The JVMTI and * JVMPI, however, need to be able to create "system threads", * which are arbitrary function pointers which execute in the * context of an CVMExecEnv, so they can make JNI calls. */ void (*nativeFunc)(void *); /* This must be NULL for non-system threads. For system threads, * if this argument is non-NULL, it must be allocated on the heap * by the caller. start_func does not free this argument, only * passes it down to the native function. */ void* nativeFuncArg; CVMBool isDaemon;#ifdef CVM_LVM /* %begin lvm */ CVMLVMEEInitAux lvmEEInitAux; /* for passing Logical VM related info */#endif /* %end lvm */ /* died an early death? */ int started; /* Synchronize child startup */ CVMMutex parentLock; CVMCondVar parentCond; /* EE for child */ CVMExecEnv *ee; int priority;} CVMThreadStartInfo;#define CVM_TCSTATE(ee, x) (&(ee)->tcstate[(x)])#define CVMjniEnv2ExecEnv(je) \ ((CVMExecEnv *)((char *)(je) - \ CVMoffsetof(CVMExecEnv, jniEnv)))#define CVMexecEnv2JniEnv(ee) CVMjniPrivEnv2PubEnv(&(ee)->jniEnv)#define CVMthreadID2ExecEnv(tid) \ ((CVMExecEnv *)((char *)((tid)) - \ CVMoffsetof(CVMExecEnv, threadInfo)))#define CVMexecEnv2threadID(ee) (&(ee)->threadInfo)#define CVMeeGetCurrentFrame(ee) \ ((ee)->interpreterStack.currentFrame)/* Get the mb of the current frame. */#ifdef CVM_JIT#define CVMeeGetCurrentFrameMb(ee) CVMJITeeGetCurrentFrameMb((ee))#else#define CVMeeGetCurrentFrameMb(ee) (CVMeeGetCurrentFrame((ee))->mb)#endif/* * Get the mb of the given frame at the saved pc. * This also works for frames with inlined methods. */#ifdef CVM_JIT#define CVMframeGetMb(frame) CVMJITframeGetMb((frame))#else#define CVMframeGetMb(frame) ((frame)->mb)#endif/* Get the cb of the current frame. */#define CVMeeGetCurrentFrameCb(ee) \ CVMmbClassBlock(CVMeeGetCurrentFrameMb(ee))/* Get the constant pool of the current frame. */#define CVMeeGetCurrentFrameCp(ee) \ CVMcbConstantPool(CVMeeGetCurrentFrameCb(ee))/* * Initialize an ExecEnv before first use, and destroy after use. * If CVMinitExecEnv fails, it returns CVM_FALSE. An exception is * NOT thrown. */extern CVMBoolCVMinitExecEnv(CVMExecEnv* ee, CVMExecEnv *targetEE, CVMThreadStartInfo* threadInfo);extern voidCVMdestroyExecEnv(CVMExecEnv* ee);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?