jit_common.h

来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 693 行 · 第 1/2 页

H
693
字号
/* * 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 JITs. It is the interface * between a particular JIT implementation and the rest of the VM. */#ifndef _INCLUDED_JIT_COMMON_H#define _INCLUDED_JIT_COMMON_H#ifdef CVM_JIT#include "javavm/include/defs.h"#include "javavm/include/utils.h"#include "javavm/include/stacks.h"	/* CVMFrameFlags */#include "javavm/include/jit/jit.h"#include "javavm/include/porting/jit/jit.h"#ifdef CVM_USE_MEM_MGR#include "javavm/include/mem_mgr.h"#endifCVMFrameGCScannerFunc CVMcompiledFrameScanner;typedef struct {    CVMFrame *frame;    CVMMethodBlock *mb;    CVMCompiledInliningInfoEntry *inliningEntries;    CVMInt32 pcOffset;    CVMInt32 index;    CVMInt32 numEntries;    CVMInt32 invokePC;} CVMJITFrameIterator;/* * Given a compiled frame, this function re-constructs the back-trace * for the PC in the frame. Due to inlining, a PC can correspond to  * multiple mb's. */extern voidCVMJITframeIterate(CVMFrame* frame, CVMJITFrameIterator* iter);extern CVMBoolCVMJITframeIterateSkip(CVMJITFrameIterator* iter,    CVMBool skipArtificial, CVMBool popFrame);#define CVMJITframeIterateNext(iter)	\    CVMJITframeIterateSkip((iter), 0, CVM_TRUE, CVM_FALSE)#define CVMJITframeIteratePop(iter)	\    CVMJITframeIterateSkip((iter), 0, CVM_TRUE, CVM_TRUE)extern CVMUint32CVMJITframeIterateCount(CVMJITFrameIterator* iter, CVMBool skipArtificial);extern CVMFrame *CVMJITframeIterateGetFrame(CVMJITFrameIterator *iter);extern CVMMethodBlock *CVMJITframeIterateGetMb(CVMJITFrameIterator *iter);extern CVMUint8 *CVMJITframeIterateGetJavaPc(CVMJITFrameIterator *iter);extern voidCVMJITframeIterateSetJavaPc(CVMJITFrameIterator *iter, CVMUint8 *pc);extern CVMStackVal32 *CVMJITframeIterateGetLocals(CVMJITFrameIterator *iter);extern CVMObjectICell *CVMJITframeIterateSyncObject(CVMJITFrameIterator *iter);extern CVMFrameFlagsCVMJITframeIterateGetFlags(CVMJITFrameIterator *iter);extern CVMBoolCVMJITframeIterateIsInlined(CVMJITFrameIterator *iter);extern CVMBoolCVMJITframeIterateHandlesExceptions(CVMJITFrameIterator *iter);extern voidCVMJITframeIterateSetFlags(CVMJITFrameIterator *iter, CVMFrameFlags flags);extern CVMMethodBlock *CVMJITframeGetMb(CVMFrame *frame);extern CVMMethodBlock *CVMJITeeGetCurrentFrameMb(CVMExecEnv *ee);#define CVMinvokeCompiled(ee, jfp)			\    CVMJITgoNative(NULL, ee, jfp, (jfp)->pcX)#define CVMreturnToCompiled(ee, jfp, exceptionObject)	\    CVMJITgoNative(exceptionObject, ee, jfp, (jfp)->pcX)/* Result codes for compiled native methods. */typedef enum {    CVM_COMPILED_RETURN,    CVM_COMPILED_NEW_MB,    CVM_COMPILED_NEW_TRANSITION,    CVM_COMPILED_EXCEPTION} CVMCompiledResultCode;extern CVMCompiledResultCodeCVMinvokeCompiledHelper(CVMExecEnv *ee, CVMFrame *frame, CVMMethodBlock **mb);extern CVMCompiledResultCodeCVMreturnToCompiledHelper(CVMExecEnv *ee, CVMFrame *frame,			  CVMMethodBlock **mb, CVMObject* exceptionObject);/* Purpose: Do on-stack replacement of an interpreted stack frame with a            compiled stack frame and continue executing the method using its            compiled form at the location indicated by the specified bytecode            PC. */extern CVMCompiledResultCodeCVMinvokeOSRCompiledHelper(CVMExecEnv *ee, CVMFrame *frame,                           CVMMethodBlock **mb, CVMUint8 *pc);#define CVM_JIT_OPTIONS "[-Xjit:[<option>[,<option>]...]] "/* Order must match jitWhenToCompileOptions table */typedef enum {    CVMJIT_COMPILE_NONE,    CVMJIT_COMPILE_ALL,    CVMJIT_COMPILE_POLICY,    /* NOTE: CVMJIT_COMPILE_NUM_OPTIONS must be the last entry in this list: */    CVMJIT_COMPILE_NUM_OPTIONS} CVMJITWhenToCompileOption;/* Order must match jitWhatToInlineOptions table */typedef enum {    CVMJIT_INLINE_VIRTUAL,    CVMJIT_INLINE_NONVIRTUAL,    CVMJIT_INLINE_VIRTUAL_SYNC,    CVMJIT_INLINE_NONVIRTUAL_SYNC,    CVMJIT_INLINE_DOPRIVILEGED,    CVMJIT_INLINE_USE_VIRTUAL_HINTS,    CVMJIT_INLINE_USE_INTERFACE_HINTS,    /* NOTE: CVMJIT_INLINE_NUM_OPTIONS must be the last entry in this list: */    CVMJIT_INLINE_NUM_OPTIONS} CVMJITWhatToInlineOption;#define CVMJITinlines(inlineType_) \    ((CVMglobals.jit.whatToInline & (1<<CVMJIT_INLINE_##inlineType_)) != 0)/* * The default values of our command-line options */#define CVMJIT_DEFAULT_ICOST        20#define CVMJIT_DEFAULT_MCOST        50#define CVMJIT_DEFAULT_BCOST        4#define CVMJIT_DEFAULT_CLIMIT       20000#define CVMJIT_DEFAULT_POLICY       CVMJIT_COMPILE_POLICY#define CVMJIT_DEFAULT_INLINING     \        ((1 << CVMJIT_INLINE_VIRTUAL) | \         (1 << CVMJIT_INLINE_NONVIRTUAL) | \         (1 << CVMJIT_INLINE_USE_VIRTUAL_HINTS) | \         (1 << CVMJIT_INLINE_USE_INTERFACE_HINTS))#define CVMJIT_DEFAULT_MAX_INLINE_DEPTH     12#define CVMJIT_DEFAULT_MAX_INLINE_CODELEN   68#define CVMJIT_DEFAULT_MIN_INLINE_CODELEN   16#define CVMJIT_DEFAULT_MAX_WORKING_MEM      (1024*1024)#define CVMJIT_DEFAULT_MAX_COMP_METH_SIZE   (64*1024 - 1)#ifndef JAVASE#define CVMJIT_DEFAULT_CODE_CACHE_SIZE      512*1024#else#define CVMJIT_DEFAULT_CODE_CACHE_SIZE      2*1024*1024#endif#define CVMJIT_DEFAULT_UPPER_CCACHE_THR     95/* NOTE: the default of -1 for lower code cache threshold is   significant. See CVMJITcodeCacheInitOptions */#define CVMJIT_DEFAULT_LOWER_CCACHE_THR     -1#ifdef CVM_AOT#define CVMJIT_DEFAULT_AOT_CODE_CACHE_SIZE 672*1024#endif/* * Normally the CVMJIT_MAX_CODE_CACHE_SIZE is set to 32MB. The size shouldn't * be larger than the maximum offset possible with a PC relative call  * instruction. Otherwise poor code will be generated when calling CCM glue  * code that is copied to the start of the code cache. 32MB is within the  * PC relative call limit for ARM, Sparc, MIPS, PowerPC, and x86. * * If CVM_JIT_PATCHED_METHOD_INVOCATIONS is enabled, then the code cache is * limited by the the number of encoding bits for the  codecache offset value * stored in a patch entry in the Caller Table. Currently there are 23 bits * for the offset (see  CVMJITPMICallerRecord), allowing the size to be * 2^23 * CVMCPU_INSTRUCTION_SIZE.  This works out to 32MB on 32-bit RISC * platforms, but x86 is stuck with just 8MB because we have to assume * a 1 byte instruction size. */#ifdef CVM_JIT_PATCHED_METHOD_INVOCATIONS#define CVMJIT_MAX_CODE_CACHE_SIZE (8*1024*1024*CVMCPU_INSTRUCTION_SIZE)#else#define CVMJIT_MAX_CODE_CACHE_SIZE (32*1024*1024)#endif#ifdef CVM_JIT_COLLECT_STATS/* Order must match jitStatsToCollect table */typedef enum {    CVMJIT_STATS_HELP,    CVMJIT_STATS_COLLECT_NONE,    CVMJIT_STATS_COLLECT_MINIMAL,    CVMJIT_STATS_COLLECT_MORE,    CVMJIT_STATS_COLLECT_VERBOSE,    CVMJIT_STATS_COLLECT_CONSTANTS,    CVMJIT_STATS_COLLECT_MAXIMAL,    /* NOTE: CVMJIT_STATS_NUM_OPTIONS must be the last entry in this list.       The only exception is CVMJIT_STATS_ABORTED which is used for error       tracking. */    CVMJIT_STATS_NUM_OPTIONS,    CVMJIT_STATS_ABORTED} CVMJITStatsToCollectOption;#endif /* CVM_JIT_COLLECT_STATS *//* * Used to keep track of patch points in ccm code required for gc. */typedef struct CVMCCMGCPatchPoint {    CVMUint8* patchPoint; /* instruction to patch */    CVMCPUInstruction  patchInstruction; /* instr that does gc rendezvous */} CVMCCMGCPatchPoint;#ifdef CVM_JIT_PATCHED_METHOD_INVOCATIONStypedef struct CVMJITPMICalleeRecord CVMJITPMICalleeRecord;typedef struct CVMJITPMICallerRecord CVMJITPMICallerRecord;/* * Add a patch record. callerMb is making a direct call to calleeMb at * address instrAddr. If isVirtual is true, then this is a virtual * invoke of a method that has not been overridden. Returns CVM_FALSE * if this fails for any reason, in which case a direct method call * should not be used. */extern CVMBoolCVMJITPMIaddPatchRecord(CVMMethodBlock* callerMb,			CVMMethodBlock* calleeMb,			CVMUint8* instrAddr,			CVMBool isVirtual);/* * Remove patch records. callerMb is being decompiled, so remove all * calleeMb records that refer to addresses in callerMb. */extern voidCVMJITPMIremovePatchRecords(CVMMethodBlock* callerMb, CVMMethodBlock* calleeMb,			    CVMUint8* callerStartPC, CVMUint8* callerEndPC);/* * Patch method calls to calleeMb based on the new state of the callee method. */typedef enum {    CVMJITPMI_PATCHSTATE_COMPILED = 0,    /* calleeMb was just compiled */    CVMJITPMI_PATCHSTATE_DECOMPILED = 1,  /* calleeMb was just decompiled */    CVMJITPMI_PATCHSTATE_OVERRIDDEN = 2   /* calleeMb was just overridden */} CVMJITPMI_PATCHSTATE;extern voidCVMJITPMIpatchCallsToMethod(CVMMethodBlock* calleeMb,			    CVMJITPMI_PATCHSTATE newPatchState);#if defined(CVM_DEBUG) || defined(CVM_TRACE_JIT)extern voidCVMJITPMIdumpMethodCalleeInfo(CVMMethodBlock* callerMb,			      CVMBool printCallerInfo);#endif#endif /* CVM_JIT_PATCHED_METHOD_INVOCATIONS *//********************************************************************* * Support for copying ccm assembler code into the start of the code cache  * for faster access and less code generation on some platforms. *********************************************************************//* * We want the table of ccm function mappings (from code cache address to * function name) if we are copying ccm code to the code cache, and either * debug or profiling is enabled. */#if (defined(CVM_DEBUG) || defined(CVM_JIT_PROFILE) || defined(CVM_JVMPI)) && \    defined(CVM_JIT_COPY_CCMCODE_TO_CODECACHE)#define CVM_JIT_HAVE_CCM_CODECACHE_COPY_ENTRIES/* * used to keep track of ccm entry points that we want to profile separately. */typedef struct CVMCCMCodeCacheCopyEntry {    CVMUint8* helper;    const char* helperName;} CVMCCMCodeCacheCopyEntry;#endif/* * Return the offset from start of code buffer of the ccm function, * which is located in the beginning of the code cache. */#if defined(CVM_JIT_COPY_CCMCODE_TO_CODECACHE)#define CVMCCMcodeCacheCopyHelperOffset(con, helper)   	\    (CVMglobals.jit.ccmCodeCacheCopyAddress - con->codeEntry +	\     (CVMUint8*)helper - (CVMUint8*)&CVMCCMcodeCacheCopyStart)#endif /* CVM_JIT_COPY_CCMCODE_TO_CODECACHE *//* * CVMJIT_CCMCODE_ADDR - returns the address of a ccm entry point. * This address will be in the code cache if we copied the ccm assembler * code to the code cache. Otherwise, it is just the linker symbol. */#ifdef CVM_JIT_COPY_CCMCODE_TO_CODECACHE#define CVMJIT_CCMCODE_ADDR(ccmAddr)			       	\    (CVMUint8*)(CVMglobals.jit.ccmCodeCacheCopyAddress + 		\		 ((CVMUint8*)(ccmAddr) - (CVMUint8*)&CVMCCMcodeCacheCopyStart))#else#define CVMJIT_CCMCODE_ADDR(ccmAddr)  ((CVMUint8*)(ccmAddr))

⌨️ 快捷键说明

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