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
24 #define JIT_PROF_SIZE 512
25
26 #define JIT_MAX_TRACE_LEN 100
27
28 /*
29 * JitTable hash function.
30 */
31
dvmJitHashMask(const u2 * p,u4 mask)32 static inline u4 dvmJitHashMask( const u2* p, u4 mask ) {
33 return ((((u4)p>>12)^(u4)p)>>1) & (mask);
34 }
35
dvmJitHash(const u2 * p)36 static inline u4 dvmJitHash( const u2* p ) {
37 return dvmJitHashMask( p, gDvmJit.jitTableMask );
38 }
39
40 /*
41 * Entries in the JIT's address lookup hash table.
42 * Fields which may be updated by multiple threads packed into a
43 * single 32-bit word to allow use of atomic update.
44 */
45
46 typedef struct JitEntryInfo {
47 unsigned int traceRequested:1; /* already requested a translation */
48 unsigned int isMethodEntry:1;
49 unsigned int inlineCandidate:1;
50 unsigned int profileEnabled:1;
51 JitInstructionSetType instructionSet:4;
52 unsigned int unused:8;
53 u2 chain; /* Index of next in chain */
54 } JitEntryInfo;
55
56 typedef union JitEntryInfoUnion {
57 JitEntryInfo info;
58 volatile int infoWord;
59 } JitEntryInfoUnion;
60
61 typedef struct JitEntry {
62 JitEntryInfoUnion u;
63 u2 chain; /* Index of next in chain */
64 const u2* dPC; /* Dalvik code address */
65 void* codeAddress; /* Code address of native translation */
66 } JitEntry;
67
68 int dvmJitStartup(void);
69 void dvmJitShutdown(void);
70 int dvmCheckJit(const u2* pc, Thread* self, InterpState* interpState);
71 void* dvmJitGetCodeAddr(const u2* dPC);
72 bool dvmJitCheckTraceRequest(Thread* self, InterpState* interpState);
73 void dvmJitStopTranslationRequests(void);
74 void dvmJitStats(void);
75 bool dvmJitResizeJitTable(unsigned int size);
76 struct JitEntry *dvmFindJitEntry(const u2* pc);
77 s8 dvmJitd2l(double d);
78 s8 dvmJitf2l(float f);
79 void dvmJitSetCodeAddr(const u2* dPC, void *nPC, JitInstructionSetType set);
80
81
82 #endif /*_DALVIK_INTERP_JIT*/
83