Interp.h revision 375fb116bcb817b37509ab579dbd55cdbb765cbf
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_H_
21#define DALVIK_INTERP_INTERP_H_
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 */
49extern "C" void dvmThrowVerificationError(const Method* method,
50                                          int kind, int ref);
51
52/*
53 * One-time initialization and shutdown.
54 */
55bool dvmBreakpointStartup(void);
56void dvmBreakpointShutdown(void);
57void dvmInitInterpreterState(Thread* self);
58
59/*
60 * Breakpoint implementation.
61 */
62void dvmInitBreakpoints();
63void dvmAddBreakAddr(Method* method, unsigned int instrOffset);
64void dvmClearBreakAddr(Method* method, unsigned int instrOffset);
65bool dvmAddSingleStep(Thread* thread, int size, int depth);
66void dvmClearSingleStep(Thread* thread);
67
68/*
69 * Recover the opcode that was replaced by a breakpoint.
70 */
71extern "C" u1 dvmGetOriginalOpcode(const u2* addr);
72
73/*
74 * Flush any breakpoints associated with methods in "clazz".
75 */
76void dvmFlushBreakpoints(ClassObject* clazz);
77
78/*
79 * Debugger support
80 */
81extern "C" void dvmCheckBefore(const u2 *dPC, u4 *fp, Thread* self);
82extern "C" void dvmReportExceptionThrow(Thread* self, Object* exception);
83extern "C" void dvmReportPreNativeInvoke(const Method* methodToCall, Thread* self, u4* fp);
84extern "C" void dvmReportPostNativeInvoke(const Method* methodToCall, Thread* self, u4* fp);
85extern "C" void dvmReportInvoke(Thread* self, const Method* methodToCall);
86extern "C" void dvmReportReturn(Thread* self);
87
88/*
89 * InterpBreak & subMode control
90 */
91void dvmDisableSubMode(Thread* thread, ExecutionSubModes subMode);
92extern "C" void dvmEnableSubMode(Thread* thread, ExecutionSubModes subMode);
93void dvmDisableAllSubMode(ExecutionSubModes subMode);
94void dvmEnableAllSubMode(ExecutionSubModes subMode);
95void dvmAddToSuspendCounts(Thread* thread, int delta, int dbgDelta);
96void dvmCheckInterpStateConsistency();
97void dvmInitializeInterpBreak(Thread* thread);
98
99/*
100 * Register a callback to occur at the next safe point for a single thread.
101 * If funct is NULL, the previous registration is cancelled.
102 *
103 * The callback prototype is:
104 *        bool funct(Thread* thread, void* arg)
105 *
106 *  If funct returns false, the callback will be disarmed.  If true,
107 *  it will stay in effect.
108 */
109void dvmArmSafePointCallback(Thread* thread, SafePointCallback funct,
110                             void* arg);
111
112
113#ifndef DVM_NO_ASM_INTERP
114extern void* dvmAsmInstructionStart[];
115extern void* dvmAsmAltInstructionStart[];
116#endif
117
118#endif  // DALVIK_INTERP_INTERP_H_
119