Compiler.h revision 97319a8a234e9fe1cf90ca39aa6eca37d729afd5
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _DALVIK_VM_COMPILER 18#define _DALVIK_VM_COMPILER 19 20#define CODE_CACHE_SIZE 1024*1024 21#define MAX_JIT_RUN_LEN 64 22#define COMPILER_WORK_QUEUE_SIZE 100 23 24#define COMPILER_TRACED(X) 25#define COMPILER_TRACEE(X) 26#define COMPILER_TRACE_CHAINING(X) 27 28typedef enum JitInstructionSetType { 29 DALVIK_JIT_NONE = 0, 30 DALVIK_JIT_ARM, 31 DALVIK_JIT_THUMB, 32 DALVIK_JIT_THUMB2, 33 DALVIK_JIT_THUMB2EE, 34 DALVIK_JIT_X86 35} JitInstructionSetType; 36 37/* Description of a compiled trace. */ 38typedef struct JitTranslationInfo { 39 void *codeAddress; 40 JitInstructionSetType instructionSet; 41} JitTranslationInfo; 42 43typedef enum WorkOrderKind { 44 kWorkOrderInvalid = 0, // Should never see by the backend 45 kWorkOrderMethod = 1, // Work is to compile a whole method 46 kWorkOrderTrace = 2, // Work is to compile code fragment(s) 47} WorkOrderKind; 48 49typedef struct CompilerWorkOrder { 50 const u2* pc; 51 WorkOrderKind kind; 52 void* info; 53 JitTranslationInfo result; 54} CompilerWorkOrder; 55 56typedef enum JitState { 57 kJitOff = 0, 58 kJitNormal = 1, // Profiling in mterp or running native 59 kJitTSelectRequest = 2, // Transition state - start trace selection 60 kJitTSelect = 3, // Actively selecting trace in dbg interp 61 kJitTSelectAbort = 4, // Something threw during selection - abort 62 kJitTSelectEnd = 5, // Done with the trace - wrap it up 63 kJitSingleStep = 6, // Single step interpretation 64 kJitSingleStepEnd = 7, // Done with single step, return to mterp 65 kJitSelfVerification = 8, // Self Verification Mode 66} JitState; 67 68#if defined(WITH_SELF_VERIFICATION) 69typedef enum SelfVerificationState { 70 kSVSIdle = 0, // Idle 71 kSVSStart = 1, // Shadow space set up, running compiled code 72 kSVSPunt = 2, // Exiting compiled code by punting 73 kSVSSingleStep = 3, // Exiting compiled code by single stepping 74 kSVSTraceSelect = 4, // Exiting compiled code by trace select 75 kSVSNormal = 5, // Exiting compiled code normally 76 kSVSNoChain = 6, // Exiting compiled code by no chain 77 kSVSBackwardBranch = 7, // Exiting compiled code with backward branch trace 78 kSVSDebugInterp = 8, // Normal state restored, running debug interpreter 79} SelfVerificationState; 80#endif 81 82typedef enum JitHint { 83 kJitHintNone = 0, 84 kJitHintTaken = 1, // Last inst in run was taken branch 85 kJitHintNotTaken = 2, // Last inst in run was not taken branch 86 kJitHintNoBias = 3, // Last inst in run was unbiased branch 87} jitHint; 88 89/* 90 * Element of a Jit trace description. Describes a contiguous 91 * sequence of Dalvik byte codes, the last of which can be 92 * associated with a hint. 93 * Dalvik byte code 94 */ 95typedef struct { 96 u2 startOffset; // Starting offset for trace run 97 unsigned numInsts:8; // Number of Byte codes in run 98 unsigned runEnd:1; // Run ends with last byte code 99 jitHint hint:7; // Hint to apply to final code of run 100} JitCodeDesc; 101 102typedef union { 103 JitCodeDesc frag; 104 void* hint; 105} JitTraceRun; 106 107/* 108 * Trace description as will appear in the translation cache. Note 109 * flexible array at end, as these will be of variable size. To 110 * conserve space in the translation cache, total length of JitTraceRun 111 * array must be recomputed via seqential scan if needed. 112 */ 113typedef struct { 114 const Method* method; 115 JitTraceRun trace[]; 116} JitTraceDescription; 117 118typedef struct CompilerMethodStats { 119 const Method *method; // Used as hash entry signature 120 int dalvikSize; // # of bytes for dalvik bytecodes 121 int compiledDalvikSize; // # of compiled dalvik bytecodes 122 int nativeSize; // # of bytes for produced native code 123} CompilerMethodStats; 124 125bool dvmCompilerSetupCodeCache(void); 126bool dvmCompilerArchInit(void); 127void dvmCompilerArchDump(void); 128bool dvmCompilerStartup(void); 129void dvmCompilerShutdown(void); 130bool dvmCompilerWorkEnqueue(const u2* pc, WorkOrderKind kind, void* info); 131void *dvmCheckCodeCache(void *method); 132bool dvmCompileMethod(const Method *method, JitTranslationInfo *info); 133bool dvmCompileTrace(JitTraceDescription *trace, int numMaxInsts, 134 JitTranslationInfo *info); 135void dvmCompilerDumpStats(void); 136void dvmCompilerDrainQueue(void); 137void dvmJitUnchainAll(void); 138void dvmCompilerSortAndPrintTraceProfiles(void); 139 140#endif /* _DALVIK_VM_COMPILER */ 141