Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 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 | |
Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 28 | typedef enum JitInstructionSetType { |
| 29 | DALVIK_JIT_NONE = 0, |
| 30 | DALVIK_JIT_ARM, |
| 31 | DALVIK_JIT_THUMB, |
| 32 | DALVIK_JIT_THUMB2, |
Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame] | 33 | DALVIK_JIT_THUMB2EE, |
Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 34 | DALVIK_JIT_X86 |
| 35 | } JitInstructionSetType; |
| 36 | |
| 37 | /* Description of a compiled trace. */ |
| 38 | typedef struct JitTranslationInfo { |
| 39 | void *codeAddress; |
| 40 | JitInstructionSetType instructionSet; |
| 41 | } JitTranslationInfo; |
| 42 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 43 | typedef 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 | |
| 49 | typedef struct CompilerWorkOrder { |
| 50 | const u2* pc; |
| 51 | WorkOrderKind kind; |
| 52 | void* info; |
Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 53 | JitTranslationInfo result; |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 54 | } CompilerWorkOrder; |
| 55 | |
| 56 | typedef 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 |
Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame^] | 65 | kJitSelfVerification = 8, // Self Verification Mode |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 66 | } JitState; |
| 67 | |
Jeff Hao | 97319a8 | 2009-08-12 16:57:15 -0700 | [diff] [blame^] | 68 | #if defined(WITH_SELF_VERIFICATION) |
| 69 | typedef 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 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 82 | typedef 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 | */ |
| 95 | typedef 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 | |
| 102 | typedef 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 | */ |
| 113 | typedef struct { |
| 114 | const Method* method; |
| 115 | JitTraceRun trace[]; |
| 116 | } JitTraceDescription; |
| 117 | |
Ben Cheng | 8b258bf | 2009-06-24 17:27:07 -0700 | [diff] [blame] | 118 | typedef 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 | |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 125 | bool dvmCompilerSetupCodeCache(void); |
| 126 | bool dvmCompilerArchInit(void); |
| 127 | void dvmCompilerArchDump(void); |
| 128 | bool dvmCompilerStartup(void); |
| 129 | void dvmCompilerShutdown(void); |
| 130 | bool dvmCompilerWorkEnqueue(const u2* pc, WorkOrderKind kind, void* info); |
| 131 | void *dvmCheckCodeCache(void *method); |
Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 132 | bool dvmCompileMethod(const Method *method, JitTranslationInfo *info); |
| 133 | bool dvmCompileTrace(JitTraceDescription *trace, int numMaxInsts, |
| 134 | JitTranslationInfo *info); |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 135 | void dvmCompilerDumpStats(void); |
| 136 | void dvmCompilerDrainQueue(void); |
Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 137 | void dvmJitUnchainAll(void); |
Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 138 | void dvmCompilerSortAndPrintTraceProfiles(void); |
Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 139 | |
| 140 | #endif /* _DALVIK_VM_COMPILER */ |