blob: 3b7ae542cf2b115b53ab95a2993beeec8c96617a [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
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 Buzbee716f1202009-07-23 13:22:09 -070028typedef enum JitInstructionSetType {
29 DALVIK_JIT_NONE = 0,
30 DALVIK_JIT_ARM,
31 DALVIK_JIT_THUMB,
32 DALVIK_JIT_THUMB2,
Bill Buzbee9bc3df32009-07-30 10:52:29 -070033 DALVIK_JIT_THUMB2EE,
Bill Buzbee716f1202009-07-23 13:22:09 -070034 DALVIK_JIT_X86
35} JitInstructionSetType;
36
37/* Description of a compiled trace. */
38typedef struct JitTranslationInfo {
39 void *codeAddress;
40 JitInstructionSetType instructionSet;
41} JitTranslationInfo;
42
Ben Chengba4fc8b2009-06-01 13:00:29 -070043typedef 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;
Bill Buzbee716f1202009-07-23 13:22:09 -070053 JitTranslationInfo result;
Ben Chengba4fc8b2009-06-01 13:00:29 -070054} 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} JitState;
66
67typedef 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 */
80typedef 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
87typedef 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 */
98typedef struct {
99 const Method* method;
100 JitTraceRun trace[];
101} JitTraceDescription;
102
Ben Cheng8b258bf2009-06-24 17:27:07 -0700103typedef 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
Ben Chengba4fc8b2009-06-01 13:00:29 -0700110bool dvmCompilerSetupCodeCache(void);
111bool dvmCompilerArchInit(void);
112void dvmCompilerArchDump(void);
113bool dvmCompilerStartup(void);
114void dvmCompilerShutdown(void);
115bool dvmCompilerWorkEnqueue(const u2* pc, WorkOrderKind kind, void* info);
116void *dvmCheckCodeCache(void *method);
Bill Buzbee716f1202009-07-23 13:22:09 -0700117bool dvmCompileMethod(const Method *method, JitTranslationInfo *info);
118bool dvmCompileTrace(JitTraceDescription *trace, int numMaxInsts,
119 JitTranslationInfo *info);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700120void dvmCompilerDumpStats(void);
121void dvmCompilerDrainQueue(void);
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700122void dvmJitUnchainAll(void);
Bill Buzbee716f1202009-07-23 13:22:09 -0700123void dvmCompilerSortAndPrintTraceProfiles(void);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700124
125#endif /* _DALVIK_VM_COMPILER */