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 | |
| 28 | typedef enum WorkOrderKind { |
| 29 | kWorkOrderInvalid = 0, // Should never see by the backend |
| 30 | kWorkOrderMethod = 1, // Work is to compile a whole method |
| 31 | kWorkOrderTrace = 2, // Work is to compile code fragment(s) |
| 32 | } WorkOrderKind; |
| 33 | |
| 34 | typedef struct CompilerWorkOrder { |
| 35 | const u2* pc; |
| 36 | WorkOrderKind kind; |
| 37 | void* info; |
| 38 | } CompilerWorkOrder; |
| 39 | |
| 40 | typedef enum JitState { |
| 41 | kJitOff = 0, |
| 42 | kJitNormal = 1, // Profiling in mterp or running native |
| 43 | kJitTSelectRequest = 2, // Transition state - start trace selection |
| 44 | kJitTSelect = 3, // Actively selecting trace in dbg interp |
| 45 | kJitTSelectAbort = 4, // Something threw during selection - abort |
| 46 | kJitTSelectEnd = 5, // Done with the trace - wrap it up |
| 47 | kJitSingleStep = 6, // Single step interpretation |
| 48 | kJitSingleStepEnd = 7, // Done with single step, return to mterp |
| 49 | } JitState; |
| 50 | |
| 51 | typedef enum JitHint { |
| 52 | kJitHintNone = 0, |
| 53 | kJitHintTaken = 1, // Last inst in run was taken branch |
| 54 | kJitHintNotTaken = 2, // Last inst in run was not taken branch |
| 55 | kJitHintNoBias = 3, // Last inst in run was unbiased branch |
| 56 | } jitHint; |
| 57 | |
| 58 | /* |
| 59 | * Element of a Jit trace description. Describes a contiguous |
| 60 | * sequence of Dalvik byte codes, the last of which can be |
| 61 | * associated with a hint. |
| 62 | * Dalvik byte code |
| 63 | */ |
| 64 | typedef struct { |
| 65 | u2 startOffset; // Starting offset for trace run |
| 66 | unsigned numInsts:8; // Number of Byte codes in run |
| 67 | unsigned runEnd:1; // Run ends with last byte code |
| 68 | jitHint hint:7; // Hint to apply to final code of run |
| 69 | } JitCodeDesc; |
| 70 | |
| 71 | typedef union { |
| 72 | JitCodeDesc frag; |
| 73 | void* hint; |
| 74 | } JitTraceRun; |
| 75 | |
| 76 | /* |
| 77 | * Trace description as will appear in the translation cache. Note |
| 78 | * flexible array at end, as these will be of variable size. To |
| 79 | * conserve space in the translation cache, total length of JitTraceRun |
| 80 | * array must be recomputed via seqential scan if needed. |
| 81 | */ |
| 82 | typedef struct { |
| 83 | const Method* method; |
| 84 | JitTraceRun trace[]; |
| 85 | } JitTraceDescription; |
| 86 | |
| 87 | bool dvmCompilerSetupCodeCache(void); |
| 88 | bool dvmCompilerArchInit(void); |
| 89 | void dvmCompilerArchDump(void); |
| 90 | bool dvmCompilerStartup(void); |
| 91 | void dvmCompilerShutdown(void); |
| 92 | bool dvmCompilerWorkEnqueue(const u2* pc, WorkOrderKind kind, void* info); |
| 93 | void *dvmCheckCodeCache(void *method); |
| 94 | void *dvmCompileMethod(Method *method); |
| 95 | void *dvmCompileTrace(JitTraceDescription *trace); |
| 96 | void dvmCompilerDumpStats(void); |
| 97 | void dvmCompilerDrainQueue(void); |
| 98 | |
| 99 | #endif /* _DALVIK_VM_COMPILER */ |