blob: 856c2f5869aa5bf7d3ae25d8628b8ee5b24a028d [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
2 * Copyright (C) 2008 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 * Dalvik interpreter definitions. These are internal to the interpreter.
18 *
19 * This includes defines, types, function declarations, and inline functions
20 * that are common to all interpreter implementations.
21 *
22 * Functions and globals declared here are defined in Interp.c.
23 */
24#ifndef _DALVIK_INTERP_DEFS
25#define _DALVIK_INTERP_DEFS
26
27
28/*
29 * Specify the starting point when switching between interpreters.
30 */
31typedef enum InterpEntry {
32 kInterpEntryInstr = 0, // continue to next instruction
33 kInterpEntryReturn = 1, // jump to method return
34 kInterpEntryThrow = 2, // jump to exception throw
35} InterpEntry;
36
37/*
38 * Interpreter context, used when switching from one interpreter to
39 * another. We also tuck "mterp" state in here.
40 */
41typedef struct InterpState {
42 /*
43 * To make some mterp state updates easier, "pc" and "fp" MUST come
44 * first and MUST appear in this order.
45 */
46 const u2* pc; // program counter
47 u4* fp; // frame pointer
48
49 JValue retval; // return value -- "out" only
50 const Method* method; // method being executed
51
52
53 /* ----------------------------------------------------------------------
54 * Mterp-only state
55 */
56 DvmDex* methodClassDex;
57 Thread* self;
58
59 /* housekeeping */
60 void* bailPtr;
61
62 /*
63 * These are available globally, from gDvm, or from another glue field
64 * (self/method). They're copied in here for speed.
65 */
66 const u1* interpStackEnd;
67 volatile int* pSelfSuspendCount;
68#if defined(WITH_DEBUGGER)
69 volatile bool* pDebuggerActive;
70#endif
71#if defined(WITH_PROFILER)
72 volatile int* pActiveProfilers;
73#endif
74 /* ----------------------------------------------------------------------
75 */
76
77 /*
78 * Interpreter switching.
79 */
80 InterpEntry entryPoint; // what to do when we start
81 int nextMode; // INTERP_STD or INTERP_DBG
82
83
84#if defined(WITH_PROFILER) || defined(WITH_DEBUGGER)
85 bool debugIsMethodEntry; // used for method entry event triggers
86#endif
87#if defined(WITH_TRACKREF_CHECKS)
88 int debugTrackedRefStart; // tracked refs from prior invocations
89#endif
90
91} InterpState;
92
93/*
94 * These are generated from InterpCore.h.
95 */
96extern bool dvmInterpretDbg(Thread* self, InterpState* interpState);
97extern bool dvmInterpretStd(Thread* self, InterpState* interpState);
98#define INTERP_STD 0
99#define INTERP_DBG 1
100
101/*
102 * "mterp" interpreter.
103 */
104extern bool dvmMterpStd(Thread* self, InterpState* interpState);
105
106/*
107 * Get the "this" pointer from the current frame.
108 */
109Object* dvmGetThisPtr(const Method* method, const u4* fp);
110
111/*
112 * Verify that our tracked local references are valid.
113 */
114void dvmInterpCheckTrackedRefs(Thread* self, const Method* method,
115 int debugTrackedRefStart);
116
117/*
118 * Process switch statement.
119 */
120s4 dvmInterpHandlePackedSwitch(const u2* switchData, s4 testVal);
121s4 dvmInterpHandleSparseSwitch(const u2* switchData, s4 testVal);
122
123/*
124 * Process fill-array-data.
125 */
126bool dvmInterpHandleFillArrayData(ArrayObject* arrayObject,
127 const u2* arrayData);
128
129/*
130 * Find an interface method.
131 */
132Method* dvmInterpFindInterfaceMethod(ClassObject* thisClass, u4 methodIdx,
133 const Method* method, DvmDex* methodClassDex);
134
135/*
136 * Determine if the debugger or profiler is currently active. Used when
137 * selecting which interpreter to start or switch to.
138 */
139static inline bool dvmDebuggerOrProfilerActive(void)
140{
141 return gDvm.debuggerActive
142#if defined(WITH_PROFILER)
143 || gDvm.activeProfilers != 0
144#endif
145 ;
146}
147
148#endif /*_DALVIK_INTERP_DEFS*/