blob: 9d17a52687efaab5100eae082b5a885aa0391462 [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 * Jit control
18 */
19#ifndef _DALVIK_INTERP_JIT
20#define _DALVIK_INTERP_JIT
21
22#include "InterpDefs.h"
Ben Cheng7b133ef2010-02-04 16:15:59 -080023#include "mterp/common/jit-config.h"
Ben Cheng1efc9c52009-06-08 18:25:27 -070024
25#define JIT_MAX_TRACE_LEN 100
26
Jeff Hao97319a82009-08-12 16:57:15 -070027#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
32typedef struct ShadowHeap {
33 int addr;
34 int data;
35} ShadowHeap;
36
37typedef struct InstructionTrace {
38 int addr;
Ben Chengbcdc1de2009-08-21 16:18:46 -070039 DecodedInstruction decInsn;
Jeff Hao97319a82009-08-12 16:57:15 -070040} InstructionTrace;
41
42typedef struct ShadowSpace {
43 const u2* startPC; /* starting pc of jitted region */
44 const void* fp; /* starting fp of jitted region */
Ben Chengd5adae12010-03-26 17:45:28 -070045 void* glue; /* starting glue of jitted region */
Jeff Hao97319a82009-08-12 16:57:15 -070046 SelfVerificationState selfVerificationState; /* self verification state */
47 const u2* endPC; /* ending pc of jitted region */
48 void* shadowFP; /* pointer to fp in shadow space */
49 InterpState interpState; /* copy of interpState */
50 int* registerSpace; /* copy of register state */
51 int registerSpaceSize; /* current size of register space */
52 ShadowHeap heapSpace[HEAP_SPACE]; /* copy of heap space */
53 ShadowHeap* heapSpaceTail; /* tail pointer to heapSpace */
54 const void* endShadowFP; /* ending fp in shadow space */
55 InstructionTrace trace[JIT_MAX_TRACE_LEN]; /* opcode trace for debugging */
56 int traceLength; /* counter for current trace length */
Ben Chengccd6c012009-10-15 14:52:45 -070057 const Method* method; /* starting method of jitted region */
Jeff Hao97319a82009-08-12 16:57:15 -070058} ShadowSpace;
59
60/*
61 * Self verification functions.
62 */
63void* dvmSelfVerificationShadowSpaceAlloc(Thread* self);
64void dvmSelfVerificationShadowSpaceFree(Thread* self);
65void* dvmSelfVerificationSaveState(const u2* pc, const void* fp,
Bill Buzbee9a8c75a2009-11-08 14:31:20 -080066 InterpState* interpState,
67 int targetTrace);
Jeff Hao97319a82009-08-12 16:57:15 -070068void* dvmSelfVerificationRestoreState(const u2* pc, const void* fp,
69 SelfVerificationState exitPoint);
70#endif
71
Ben Chengba4fc8b2009-06-01 13:00:29 -070072/*
73 * JitTable hash function.
74 */
Bill Buzbee27176222009-06-09 09:20:16 -070075
76static inline u4 dvmJitHashMask( const u2* p, u4 mask ) {
77 return ((((u4)p>>12)^(u4)p)>>1) & (mask);
Ben Chengba4fc8b2009-06-01 13:00:29 -070078}
79
Bill Buzbee27176222009-06-09 09:20:16 -070080static inline u4 dvmJitHash( const u2* p ) {
81 return dvmJitHashMask( p, gDvmJit.jitTableMask );
82}
83
Ben Chengba4fc8b2009-06-01 13:00:29 -070084/*
85 * Entries in the JIT's address lookup hash table.
Bill Buzbee716f1202009-07-23 13:22:09 -070086 * Fields which may be updated by multiple threads packed into a
87 * single 32-bit word to allow use of atomic update.
Ben Chengba4fc8b2009-06-01 13:00:29 -070088 */
Bill Buzbee716f1202009-07-23 13:22:09 -070089
90typedef struct JitEntryInfo {
Bill Buzbeed7269912009-11-10 14:31:32 -080091 unsigned int traceConstruction:1; /* build underway? */
Bill Buzbee716f1202009-07-23 13:22:09 -070092 unsigned int isMethodEntry:1;
93 unsigned int inlineCandidate:1;
94 unsigned int profileEnabled:1;
95 JitInstructionSetType instructionSet:4;
96 unsigned int unused:8;
Bill Buzbeed7269912009-11-10 14:31:32 -080097 u2 chain; /* Index of next in chain */
Bill Buzbee716f1202009-07-23 13:22:09 -070098} JitEntryInfo;
99
100typedef union JitEntryInfoUnion {
101 JitEntryInfo info;
102 volatile int infoWord;
103} JitEntryInfoUnion;
104
Ben Chengba4fc8b2009-06-01 13:00:29 -0700105typedef struct JitEntry {
Ben Cheng60c24f42010-01-04 12:29:56 -0800106 JitEntryInfoUnion u;
107 const u2* dPC; /* Dalvik code address */
108 void* codeAddress; /* Code address of native translation */
Ben Chengba4fc8b2009-06-01 13:00:29 -0700109} JitEntry;
110
Ben Chengba4fc8b2009-06-01 13:00:29 -0700111int dvmCheckJit(const u2* pc, Thread* self, InterpState* interpState);
112void* dvmJitGetCodeAddr(const u2* dPC);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700113bool dvmJitCheckTraceRequest(Thread* self, InterpState* interpState);
Bill Buzbee27176222009-06-09 09:20:16 -0700114void dvmJitStopTranslationRequests(void);
115void dvmJitStats(void);
116bool dvmJitResizeJitTable(unsigned int size);
Ben Cheng60c24f42010-01-04 12:29:56 -0800117void dvmJitResetTable(void);
Bill Buzbee27176222009-06-09 09:20:16 -0700118struct JitEntry *dvmFindJitEntry(const u2* pc);
Bill Buzbee50a6bf22009-07-08 13:08:04 -0700119s8 dvmJitd2l(double d);
120s8 dvmJitf2l(float f);
Bill Buzbee716f1202009-07-23 13:22:09 -0700121void dvmJitSetCodeAddr(const u2* dPC, void *nPC, JitInstructionSetType set);
Bill Buzbeed7269912009-11-10 14:31:32 -0800122void dvmJitAbortTraceSelect(InterpState* interpState);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700123
124#endif /*_DALVIK_INTERP_JIT*/