• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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. */
38 typedef struct JitTranslationInfo {
39     void     *codeAddress;
40     JitInstructionSetType instructionSet;
41 } JitTranslationInfo;
42 
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;
53     JitTranslationInfo result;
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
65 } JitState;
66 
67 typedef enum JitHint {
68    kJitHintNone = 0,
69    kJitHintTaken = 1,         // Last inst in run was taken branch
70    kJitHintNotTaken = 2,      // Last inst in run was not taken branch
71    kJitHintNoBias = 3,        // Last inst in run was unbiased branch
72 } jitHint;
73 
74 /*
75  * Element of a Jit trace description.  Describes a contiguous
76  * sequence of Dalvik byte codes, the last of which can be
77  * associated with a hint.
78  * Dalvik byte code
79  */
80 typedef struct {
81     u2    startOffset;       // Starting offset for trace run
82     unsigned numInsts:8;     // Number of Byte codes in run
83     unsigned runEnd:1;       // Run ends with last byte code
84     jitHint  hint:7;         // Hint to apply to final code of run
85 } JitCodeDesc;
86 
87 typedef union {
88     JitCodeDesc frag;
89     void*       hint;
90 } JitTraceRun;
91 
92 /*
93  * Trace description as will appear in the translation cache.  Note
94  * flexible array at end, as these will be of variable size.  To
95  * conserve space in the translation cache, total length of JitTraceRun
96  * array must be recomputed via seqential scan if needed.
97  */
98 typedef struct {
99     const Method* method;
100     JitTraceRun trace[];
101 } JitTraceDescription;
102 
103 typedef struct CompilerMethodStats {
104     const Method *method;       // Used as hash entry signature
105     int dalvikSize;             // # of bytes for dalvik bytecodes
106     int compiledDalvikSize;     // # of compiled dalvik bytecodes
107     int nativeSize;             // # of bytes for produced native code
108 } CompilerMethodStats;
109 
110 bool dvmCompilerSetupCodeCache(void);
111 bool dvmCompilerArchInit(void);
112 void dvmCompilerArchDump(void);
113 bool dvmCompilerStartup(void);
114 void dvmCompilerShutdown(void);
115 bool dvmCompilerWorkEnqueue(const u2* pc, WorkOrderKind kind, void* info);
116 void *dvmCheckCodeCache(void *method);
117 bool dvmCompileMethod(const Method *method, JitTranslationInfo *info);
118 bool dvmCompileTrace(JitTraceDescription *trace, int numMaxInsts,
119                      JitTranslationInfo *info);
120 void dvmCompilerDumpStats(void);
121 void dvmCompilerDrainQueue(void);
122 void dvmJitUnchainAll(void);
123 void dvmCompilerSortAndPrintTraceProfiles(void);
124 
125 #endif /* _DALVIK_VM_COMPILER */
126