jit_common.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 2,132 行 · 第 1/5 页
C
2,132 行
if (CVMaddressIsAtStartOfChunk(oldFrameStart, prevChunk)) { /* If we get here, then there is nothing else in the prevChunk except for the oldFrame. Hence, we should delete that chunk: */ CVMstackDeleteChunk(stack, prevChunk); }#ifdef CVM_TRACE_JIT CVMtraceJITOSR(("OSR: Intr2Comp across stack chunk: %C.%M\n", CVMmbClassBlock(mb), mb)); } else { CVMtraceJITOSR(("OSR: Intr2Comp: %C.%M\n", CVMmbClassBlock(mb), mb));#endif } /* Re-set the receiverObj: */ CVMID_icellAssignDirect(ee, &CVMframeReceiverObj(frame, Compiled), receiverObjICell); CVMID_icellSetNull(receiverObjICell); /* Get the interpreter -> compiled entry point: */ CVMcompiledFramePC(frame) = CVMpcmapJavaPcToCompiledPcStrict(frame->mb, pc);#ifdef CVMCPU_HAS_CP_REG /* Set the constantpool base reg: */ CVMcompiledFrameCpBaseReg(frame) = CVMcmdCPBaseReg(cmd);#endif CVMassert(frame->mb == mb); DECACHE_FRAME(); /* NOTE: The frame has been replaced completedly. Now, we can become GC safe again. */#if 0 /* Force GC for testing purposes. */ CVMD_gcSafeExec(ee, { CVMgcRunGC(ee); });#endif /* When are not supposed to have any arguments on the stack when we do OSR. Normally, the method prologue will adjust the stack by the spill adjust size. We'll have to do it ourselves in this case since we're not going through the method prologue. */ CVM_RESET_COMPILED_TOS(frame->topOfStack, frame); frame->topOfStack += CVMcmdSpillSize(CVMmbCmd(frame->mb)); ee->invokeMb = NULL; /* Continue executing in the compiled method: */#ifdef CVM_AOT /* Don't adjust entry count for AOT methods. */ if (!((CVMUint8*)cmd >= CVMglobals.jit.codeCacheAOTStart && (CVMUint8*)cmd < CVMglobals.jit.codeCacheAOTEnd))#endif { CVMcmdEntryCount(cmd)++; } resCode = CVMreturnToCompiledHelper(ee, frame, mb_p, NULL); return resCode;}/* Order must match CVMJITWhenToCompileOption enum */static const char* const jitWhenToCompileOptions[] = { "none", "all", "policy"};const CVMSubOptionEnumData jitInlineOptions[] = { { "none", 0 }, { "default", CVMJIT_DEFAULT_INLINING }, { "all", ((1 << CVMJIT_INLINE_VIRTUAL) | (1 << CVMJIT_INLINE_NONVIRTUAL) | (1 << CVMJIT_INLINE_USE_VIRTUAL_HINTS) | (1 << CVMJIT_INLINE_USE_INTERFACE_HINTS)) }, { "virtual", (1 << CVMJIT_INLINE_VIRTUAL) }, { "nonvirtual", (1 << CVMJIT_INLINE_NONVIRTUAL) }, { "vhints", (1 << CVMJIT_INLINE_USE_VIRTUAL_HINTS) }, { "ihints", (1 << CVMJIT_INLINE_USE_INTERFACE_HINTS) }, { "Xvsync", (1 << CVMJIT_INLINE_VIRTUAL_SYNC) }, { "Xnvsync", (1 << CVMJIT_INLINE_NONVIRTUAL_SYNC) }, { "Xdopriv", (1 << CVMJIT_INLINE_DOPRIVILEGED) },};#ifdef CVM_JIT_COLLECT_STATS/* Order must match CVMJITStatsToCollectOption enum */static const char* const jitStatsToCollectOptions[] = { "help", "none", "minimal", "more", "verbose", "constant", "maximal"};#endif#ifdef CVM_TRACE_JIT#define CVMJIT_DEFAULT_TRACE_OPTIONS 0const CVMSubOptionEnumData jitTraceOptions[] = { { "none", 0 }, { "default", CVMJIT_DEFAULT_TRACE_OPTIONS }, { "all", 0xffffffff }, { "status", CVM_DEBUGFLAG(TRACE_JITSTATUS) }, { "error", CVM_DEBUGFLAG(TRACE_JITERROR) }, { "bctoir", CVM_DEBUGFLAG(TRACE_JITBCTOIR) }, { "codegen", CVM_DEBUGFLAG(TRACE_JITCODEGEN) }, { "stats", CVM_DEBUGFLAG(TRACE_JITSTATS) }, { "iropt", CVM_DEBUGFLAG(TRACE_JITIROPT) }, { "inlining", CVM_DEBUGFLAG(TRACE_JITINLINING) }, { "osr", CVM_DEBUGFLAG(TRACE_JITOSR) }, { "reglocals", CVM_DEBUGFLAG(TRACE_JITREGLOCALS) },#ifdef CVM_JIT_PATCHED_METHOD_INVOCATIONS { "pmi", CVM_DEBUGFLAG(TRACE_JITPATCHEDINVOKES) },#endif};#endifstatic const CVMSubOptionData knownJitSubOptions[] = { {"icost", "Interpreter transition cost", CVM_INTEGER_OPTION, {{0, CVMJIT_MAX_INVOKE_COST / 2, CVMJIT_DEFAULT_ICOST}}, &CVMglobals.jit.interpreterTransitionCost}, {"mcost", "Mixed transition cost", CVM_INTEGER_OPTION, {{0, CVMJIT_MAX_INVOKE_COST / 2, CVMJIT_DEFAULT_MCOST}}, &CVMglobals.jit.mixedTransitionCost}, {"bcost", "Backwards branch cost", CVM_INTEGER_OPTION, {{0, CVMJIT_MAX_INVOKE_COST / 2, CVMJIT_DEFAULT_BCOST}}, &CVMglobals.jit.backwardsBranchCost}, {"climit", "Compilation threshold", CVM_INTEGER_OPTION, {{0, CVMJIT_MAX_INVOKE_COST, CVMJIT_DEFAULT_CLIMIT}}, &CVMglobals.jit.compileThreshold}, {"compile", "When to compile", CVM_MULTI_STRING_OPTION, {{CVMJIT_COMPILE_NUM_OPTIONS, (CVMAddr)jitWhenToCompileOptions, CVMJIT_DEFAULT_POLICY}}, &CVMglobals.jit.whenToCompile}, {"inline", "What to inline", CVM_ENUM_OPTION, {{sizeof(jitInlineOptions)/sizeof(jitInlineOptions[0]), (CVMAddr)jitInlineOptions, CVMJIT_DEFAULT_INLINING}}, &CVMglobals.jit.whatToInline}, {"maxInliningDepth", "Max Inlining Depth", CVM_INTEGER_OPTION, {{0, 1000, CVMJIT_DEFAULT_MAX_INLINE_DEPTH}}, &CVMglobals.jit.maxAllowedInliningDepth}, {"maxInliningCodeLength", "Max Inlining Code Length", CVM_INTEGER_OPTION, {{0, 1000, CVMJIT_DEFAULT_MAX_INLINE_CODELEN}}, &CVMglobals.jit.maxInliningCodeLength}, {"minInliningCodeLength", "Min Inlining Code Length", CVM_INTEGER_OPTION, {{0, 1000, CVMJIT_DEFAULT_MIN_INLINE_CODELEN}}, &CVMglobals.jit.minInliningCodeLength}, {"policyTriggeredDecompilations", "Policy Triggered Decompilations", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.policyTriggeredDecompilations}, {"maxWorkingMemorySize", "Max Working Memory Size", CVM_INTEGER_OPTION, {{0, 64*1024*1024, CVMJIT_DEFAULT_MAX_WORKING_MEM}}, &CVMglobals.jit.maxWorkingMemorySize}, {"maxCompiledMethodSize", "Max Compiled Method Size", CVM_INTEGER_OPTION, {{0, 64*1024 - 1, CVMJIT_DEFAULT_MAX_COMP_METH_SIZE}}, &CVMglobals.jit.maxCompiledMethodSize}, {"codeCacheSize", "Code Cache Size", CVM_INTEGER_OPTION, {{0, CVMJIT_MAX_CODE_CACHE_SIZE, CVMJIT_DEFAULT_CODE_CACHE_SIZE}}, &CVMglobals.jit.codeCacheSize}, {"upperCodeCacheThreshold", "Upper Code Cache Threshold", CVM_PERCENT_OPTION, {{0, 100, CVMJIT_DEFAULT_UPPER_CCACHE_THR}}, &CVMglobals.jit.upperCodeCacheThresholdPercent}, {"lowerCodeCacheThreshold", "Lower Code Cache Threshold", CVM_PERCENT_OPTION, {{0, 100, (CVMAddr)CVMJIT_DEFAULT_LOWER_CCACHE_THR}}, &CVMglobals.jit.lowerCodeCacheThresholdPercent},#ifdef CVM_AOT {"aot", "Enable AOT", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.aotEnabled}, {"aotFile", "AOT File Path", CVM_STRING_OPTION, {{0, (CVMAddr)"<AOT file>", 0}}, &CVMglobals.jit.aotFile}, {"recompileAOT", "Recompile AOT code", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_FALSE}}, &CVMglobals.jit.recompileAOT}, {"aotCodeCacheSize", "AOT Code Cache Size", CVM_INTEGER_OPTION, {{0, CVMJIT_MAX_CODE_CACHE_SIZE, CVMJIT_DEFAULT_AOT_CODE_CACHE_SIZE}}, &CVMglobals.jit.aotCodeCacheSize}, {"aotMethodList", "List of Method to be compiled ahead of time", CVM_STRING_OPTION, {{0, (CVMAddr)"<filename>", 0}}, &CVMglobals.jit.aotMethodList},#endif#define CVM_JIT_EXPERIMENTAL_OPTIONS#ifdef CVM_JIT_EXPERIMENTAL_OPTIONS {"XregisterPhis", "Pass Phi values in registers", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.registerPhis},#ifdef CVM_JIT_REGISTER_LOCALS {"XregisterLocals", "Pass locals in registers between blocks", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.registerLocals},#endif#ifdef IAI_CODE_SCHEDULER_SCORE_BOARD#ifdef CVM_DEBUG {"XremoveNOP", "Remove NOPs from generated code", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.codeSchedRemoveNOP},#endif {"XcodeScheduling", "Enable code scheduling", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.codeScheduling},#endif /*IAI_CODE_SCHEDULER_SCORE_BOARD*/ {"XcompilingCausesClassLoading", "Compiling Causes Class Loading", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_FALSE}}, &CVMglobals.jit.compilingCausesClassLoading},#ifdef CVM_JIT_PATCHED_METHOD_INVOCATIONS {"Xpmi", "Patched Method Invocations", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_TRUE}}, &CVMglobals.jit.pmiEnabled},#endif#endif#ifdef CVM_JIT_COLLECT_STATS {"stats", "Collect statistics about JIT activity", CVM_MULTI_STRING_OPTION, {{CVMJIT_STATS_NUM_OPTIONS, (CVMAddr)jitStatsToCollectOptions, CVMJIT_STATS_COLLECT_NONE}}, &CVMglobals.jit.statsToCollect},#endif#ifdef CVM_JIT_PROFILE {"profile", "Enable profiling of jit compiled code", CVM_STRING_OPTION, {{0, (CVMAddr)"<filename>", 0}}, &CVMglobals.jit.profile_filename}, {"profileInstructions", "profile at the instruction level", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_FALSE}}, &CVMglobals.jit.profileInstructions},#endif#ifdef CVM_JIT_ESTIMATE_COMPILATION_SPEED {"measureCSpeed", "Enable measurement of compilation speed", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_FALSE}}, &CVMglobals.jit.doCSpeedMeasurement}, {"testCSpeed", "Run compilation speed test", CVM_BOOLEAN_OPTION, {{CVM_FALSE, CVM_TRUE, CVM_FALSE}}, &CVMglobals.jit.doCSpeedTest},#endif#ifdef CVM_TRACE_JIT {"trace", "Trace", CVM_ENUM_OPTION, {{sizeof(jitTraceOptions)/sizeof(jitTraceOptions[0]), (CVMAddr)jitTraceOptions, CVMJIT_DEFAULT_TRACE_OPTIONS}}, &CVMglobals.debugJITFlags},#endif {NULL, NULL, 0, {{0, 0, 0}}, NULL}};/* Purpose: Initializes the compilation policy data. */CVMBoolCVMjitPolicyInit(CVMExecEnv* ee, CVMJITGlobalState* jgs){ /* Some extra logic to reconcile the -Xjit:compile option with the rest */ if (jgs->whenToCompile == CVMJIT_COMPILE_NONE) { /* Prevent stuff from getting compiled */ jgs->interpreterTransitionCost = 0; jgs->mixedTransitionCost = 0; jgs->backwardsBranchCost = 0; jgs->compileThreshold = 1000; } else if (jgs->whenToCompile == CVMJIT_COMPILE_ALL) { jgs->compileThreshold = 0;#if defined(CVM_AOT) || defined(CVM_MTASK) /* The [imb]cost were set to 0 earlier in CVMjitInit() to prevent unwanted methods being compiled as AOT methods. Need to reset [im]cost here. */ jgs->interpreterTransitionCost = CVMJIT_DEFAULT_ICOST; jgs->mixedTransitionCost = CVMJIT_DEFAULT_MCOST; jgs->backwardsBranchCost = CVMJIT_DEFAULT_BCOST;#endif } /* Otherwise do nothing. The default [im]cost and climit will do the work normally */ return CVM_TRUE;}#if defined(CVM_AOT) || defined(CVM_MTASK)/* During AOT compilation and MTASK warmup, dynamic compilation policy * is disabled. Patched method invocation (PMI) is also disabled during * that. This is used to re-initialize JIT options and policy after * pre-compilation. For AOT, if there is existing AOT code, this is * called after initializing the AOT code. */CVMBoolCVMjitProcessOptionsAndPolicyInit( CVMExecEnv* ee, CVMJITGlobalState* jgs){ if (!CVMprocessSubOptions(knownJitSubOptions, "-Xjit", &jgs->parsedSubOptions)) { return CVM_FALSE; } return CVMjitPolicyInit(ee, jgs);}#endif/* Purpose: Set up the inlining threshold table. */CVMBoolCVMjitSetInliningThresholds(CVMExecEnv* ee, CVMJITGlobalState* jgs){ /* Set up the inlining threshold table: */ CVMInt32 depth = jgs->maxAllowedInliningDepth; CVMInt32 thresholdLimit; CVMInt32 *costTable; CVMInt32 i; CVMInt32 effectiveMaxDepth; /* The inlining threshold table is used to determine if it is OK to inline a certain target method at a certain inlining depth. Basically, we use the current inlining depth to index into the inlining threshold table and come up with a threshold value. If the target method's invocation cost has decreased to or below the threshold value, then we'll allow that target method to be inlined. For inlining depths less or equal to 6, the threshold value are determine based on the quadratic curve: 100 * x^2. For inlining depths greater than 6, the target method must have a cost of 0 in order to be inlined. The choice of a quadratic mapping function, the QUAD_COEFFICIENT of 100, and EFFECTIVE_MAX_DEPTH_THRESHOLD of 6 were determined by testing. These heuristics were found to produce an effective inilining policy. */#define QUAD_COEFFICIENT 100#define EFFECTIVE_MAX_DEPTH_THRESHOLD 6#undef MIN#define MIN(x, y) (((x) < (y)) ? (x) : (y)) if (depth == 0) { depth = 1; } costTable = malloc(depth * sizeof(CVMInt32)); if (costTable == NULL) { return CVM_FALSE; } thresholdLimit = QUAD_COEFFICIENT * EFFECTIVE_MAX_DEPTH_THRESHOLD * EFFECTIVE_MAX_DEPTH_THRESHOLD; effectiveMaxDepth = MIN(depth, EFFECTIVE_MAX_DEPTH_THRESHOLD); for (i = 0; i < effectiveMaxDepth; i++) { CVMInt32 cost = (jgs->compileThreshold * (QUAD_COEFFICIENT *i*i)) / thresholdLimit; costTable[i] = jgs->compileThreshold - cost; if (costTable[i] < 0) { costTable[i] = 0; } } for (; i < depth; i++) { costTable[i] = costTable[effectiveMaxDepth-1]; } jgs->inliningThresholds = costTable;#undef QUAD_COEFFICIENT#undef EFFECTIVE_MAX_DEPTH_THRESHOLD#undef MIN return CVM_TRUE;}static voidhandleDoPrivileged(){ if (!CVMJITinlines(DOPRIVILEGED)) { CVMMethodBlock *mb0 = CVMglobals.java_security_AccessController_doPrivilegedAction2; CVMMethodBlock *mb1 = CVMglobals.java_security_AccessController_doPrivilegedExceptionAction2; CVMmbCompileFlags(mb0) |= CVMJIT_NOT_INLINABLE; CVMmbCompileFlags(mb1) |= CVMJIT_NOT_INLINABLE; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?