Interp.h revision 99e3e6e72e3471eb85fc2e405866392b01c080fe
1/*
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/*
18 * Dalvik interpreter public definitions.
19 */
20#ifndef _DALVIK_INTERP_INTERP
21#define _DALVIK_INTERP_INTERP
22
23/*
24 * Stash the dalvik PC in the frame.  Called  during interpretation.
25 */
26INLINE void dvmExportPC(const u2* pc, const u4* fp)
27{
28    SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc;
29}
30
31/*
32 * Extract the Dalvik opcode
33 */
34#define GET_OPCODE(_inst) (((_inst & 0xff) == OP_DISPATCH_FF) ? \
35                           (0x100 + ((_inst >> 8) & 0xff)) : (_inst & 0xff))
36
37/*
38 * Interpreter entry point.  Call here after setting up the interpreted
39 * stack (most code will want to get here via dvmCallMethod().)
40 */
41void dvmInterpret(Thread* thread, const Method* method, JValue* pResult);
42
43/*
44 * Throw an exception for a problem detected by the verifier.
45 *
46 * This is called from the handler for the throw-verification-error
47 * instruction.  "method" is the method currently being executed.
48 */
49void dvmThrowVerificationError(const Method* method, int kind, int ref);
50
51/*
52 * One-time initialization and shutdown.
53 */
54bool dvmBreakpointStartup(void);
55void dvmBreakpointShutdown(void);
56void dvmInitInterpreterState(Thread* self);
57
58/*
59 * Breakpoint implementation.
60 */
61void dvmInitBreakpoints();
62void dvmAddBreakAddr(Method* method, unsigned int instrOffset);
63void dvmClearBreakAddr(Method* method, unsigned int instrOffset);
64bool dvmAddSingleStep(Thread* thread, int size, int depth);
65void dvmClearSingleStep(Thread* thread);
66
67/*
68 * Recover the opcode that was replaced by a breakpoint.
69 */
70u1 dvmGetOriginalOpcode(const u2* addr);
71
72/*
73 * Flush any breakpoints associated with methods in "clazz".
74 */
75void dvmFlushBreakpoints(ClassObject* clazz);
76
77/*
78 * Debugger support
79 */
80void dvmCheckBefore(const u2 *dPC, u4 *fp, Thread* self);
81void dvmReportExceptionThrow(Thread* self, Object* exception);
82void dvmReportPreNativeInvoke(const Method* methodToCall, Thread* self);
83void dvmReportPostNativeInvoke(const Method* methodToCall, Thread* self);
84void dvmReportInvoke(Thread* self, const Method* methodToCall);
85void dvmReportReturn(Thread* self);
86
87/*
88 * Update interpBreak
89 */
90void dvmUpdateInterpBreak(Thread* thread, int newBreak, int newMode,
91                          bool enable);
92void dvmAddToSuspendCounts(Thread* thread, int delta, int dbgDelta);
93void dvmCheckInterpStateConsistency();
94void dvmInitializeInterpBreak(Thread* thread);
95
96/*
97 * Update interpBreak for all threads
98 */
99void dvmUpdateAllInterpBreak(int newBreak, int newMode, bool enable);
100
101/*
102 * Register a callback to occur at the next safe point for a single thread.
103 * If funct is NULL, the previous registration is cancelled.
104 *
105 * The callback prototype is:
106 *        bool funct(Thread* thread, void* arg)
107 *
108 *  If funct returns false, the callback will be disarmed.  If true,
109 *  it will stay in effect.
110 */
111void dvmArmSafePointCallback(Thread* thread, SafePointCallback funct,
112                             void* arg);
113
114
115#ifndef DVM_NO_ASM_INTERP
116extern void* dvmAsmInstructionStart[];
117extern void* dvmAsmAltInstructionStart[];
118#endif
119
120#endif /*_DALVIK_INTERP_INTERP*/
121