OSDN Git Service

am 46413c1b: Add notice file for dx.jar and dexdump
[android-x86/dalvik.git] / vm / interp / Jit.h
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  * Jit control
18  */
19 #ifndef _DALVIK_INTERP_JIT
20 #define _DALVIK_INTERP_JIT
21
22 #include "InterpDefs.h"
23 #include "mterp/common/jit-config.h"
24
25 #define JIT_MAX_TRACE_LEN 100
26
27 #if defined (WITH_SELF_VERIFICATION)
28
29 #define REG_SPACE 256                /* default size of shadow space */
30 #define HEAP_SPACE JIT_MAX_TRACE_LEN /* default size of heap space */
31
32 typedef struct ShadowHeap {
33     int addr;
34     int data;
35 } ShadowHeap;
36
37 typedef struct InstructionTrace {
38     int addr;
39     DecodedInstruction decInsn;
40 } InstructionTrace;
41
42 typedef struct ShadowSpace {
43     const u2* startPC;          /* starting pc of jitted region */
44     u4* fp;                     /* starting fp of jitted region */
45     const Method *method;
46     DvmDex* methodClassDex;
47     JValue retval;
48     const u1* interpStackEnd;
49     SelfVerificationState jitExitState;  /* exit point for JIT'ed code */
50     SelfVerificationState selfVerificationState;  /* current SV running state */
51     const u2* endPC;            /* ending pc of jitted region */
52     void* shadowFP;       /* pointer to fp in shadow space */
53     int* registerSpace;         /* copy of register state */
54     int registerSpaceSize;      /* current size of register space */
55     ShadowHeap heapSpace[HEAP_SPACE]; /* copy of heap space */
56     ShadowHeap* heapSpaceTail;        /* tail pointer to heapSpace */
57     const void* endShadowFP;    /* ending fp in shadow space */
58     InstructionTrace trace[JIT_MAX_TRACE_LEN]; /* opcode trace for debugging */
59     int traceLength;            /* counter for current trace length */
60 } ShadowSpace;
61
62 /*
63  * Self verification functions.
64  */
65 void* dvmSelfVerificationShadowSpaceAlloc(Thread* self);
66 void dvmSelfVerificationShadowSpaceFree(Thread* self);
67 void* dvmSelfVerificationSaveState(const u2* pc, u4* fp,
68                                    Thread* self,
69                                    int targetTrace);
70 void* dvmSelfVerificationRestoreState(const u2* pc, u4* fp,
71                                       SelfVerificationState exitPoint,
72                                       Thread *self);
73 #endif
74
75 /*
76  * JitTable hash function.
77  */
78
79 static inline u4 dvmJitHashMask( const u2* p, u4 mask ) {
80     return ((((u4)p>>12)^(u4)p)>>1) & (mask);
81 }
82
83 static inline u4 dvmJitHash( const u2* p ) {
84     return dvmJitHashMask( p, gDvmJit.jitTableMask );
85 }
86
87 /*
88  * The width of the chain field in JitEntryInfo sets the upper
89  * bound on the number of translations.  Be careful if changing
90  * the size of JitEntry struct - the Dalvik PC to JitEntry
91  * hash functions have built-in knowledge of the size.
92  */
93 #define JIT_ENTRY_CHAIN_WIDTH 2
94 #define JIT_MAX_ENTRIES (1 << (JIT_ENTRY_CHAIN_WIDTH * 8))
95
96 /*
97  * The trace profiling counters are allocated in blocks and individual
98  * counters must not move so long as any referencing trace exists.
99  */
100 #define JIT_PROF_BLOCK_ENTRIES 1024
101 #define JIT_PROF_BLOCK_BUCKETS (JIT_MAX_ENTRIES / JIT_PROF_BLOCK_ENTRIES)
102
103 typedef s4 JitTraceCounter_t;
104
105 typedef struct JitTraceProfCounters {
106     unsigned int           next;
107     JitTraceCounter_t      *buckets[JIT_PROF_BLOCK_BUCKETS];
108 } JitTraceProfCounters;
109
110 /*
111  * Entries in the JIT's address lookup hash table.
112  * Fields which may be updated by multiple threads packed into a
113  * single 32-bit word to allow use of atomic update.
114  */
115
116 typedef struct JitEntryInfo {
117     unsigned int           isMethodEntry:1;
118     unsigned int           inlineCandidate:1;
119     unsigned int           profileEnabled:1;
120     JitInstructionSetType  instructionSet:3;
121     unsigned int           profileOffset:5;
122     unsigned int           unused:5;
123     u2                     chain;                 /* Index of next in chain */
124 } JitEntryInfo;
125
126 typedef union JitEntryInfoUnion {
127     JitEntryInfo info;
128     volatile int infoWord;
129 } JitEntryInfoUnion;
130
131 typedef struct JitEntry {
132     JitEntryInfoUnion   u;
133     const u2*           dPC;            /* Dalvik code address */
134     void*               codeAddress;    /* Code address of native translation */
135 } JitEntry;
136
137 int dvmCheckJit(const u2* pc, Thread* self, const ClassObject *callsiteClass,
138                 const Method* curMethod);
139 void* dvmJitGetTraceAddr(const u2* dPC);
140 void* dvmJitGetMethodAddr(const u2* dPC);
141 bool dvmJitCheckTraceRequest(Thread* self);
142 void dvmJitStopTranslationRequests(void);
143 void dvmJitStats(void);
144 bool dvmJitResizeJitTable(unsigned int size);
145 void dvmJitResetTable(void);
146 struct JitEntry *dvmJitFindEntry(const u2* pc, bool isMethodEntry);
147 s8 dvmJitd2l(double d);
148 s8 dvmJitf2l(float f);
149 void dvmJitSetCodeAddr(const u2* dPC, void *nPC, JitInstructionSetType set,
150                        bool isMethodEntry, int profilePrefixSize);
151 void dvmJitEndTraceSelect(Thread* self);
152 JitTraceCounter_t *dvmJitNextTraceCounter(void);
153 void dvmJitTraceProfilingOff(void);
154 void dvmJitTraceProfilingOn(void);
155 void dvmJitChangeProfileMode(TraceProfilingModes newState);
156
157 #endif /*_DALVIK_INTERP_JIT*/