Interp.h revision ab35b50311951feea3782151dd5422ee944685c2
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)
35
36/*
37 * Interpreter entry point.  Call here after setting up the interpreted
38 * stack (most code will want to get here via dvmCallMethod().)
39 */
40void dvmInterpret(Thread* thread, const Method* method, JValue* pResult);
41
42/*
43 * Throw an exception for a problem detected by the verifier.
44 *
45 * This is called from the handler for the throw-verification-error
46 * instruction.  "method" is the method currently being executed.
47 */
48extern "C" void dvmThrowVerificationError(const Method* method,
49                                          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 */
70extern "C" u1 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 */
80extern "C" void dvmCheckBefore(const u2 *dPC, u4 *fp, Thread* self);
81extern "C" void dvmReportExceptionThrow(Thread* self, Object* exception);
82extern "C" void dvmReportPreNativeInvoke(const Method* methodToCall, Thread* self, u4* fp);
83extern "C" void dvmReportPostNativeInvoke(const Method* methodToCall, Thread* self, u4* fp);
84extern "C" void dvmReportInvoke(Thread* self, const Method* methodToCall);
85extern "C" void dvmReportReturn(Thread* self);
86
87/*
88 * InterpBreak & subMode control
89 */
90void dvmDisableSubMode(Thread* thread, ExecutionSubModes subMode);
91extern "C" void dvmEnableSubMode(Thread* thread, ExecutionSubModes subMode);
92void dvmDisableAllSubMode(ExecutionSubModes subMode);
93void dvmEnableAllSubMode(ExecutionSubModes subMode);
94void dvmAddToSuspendCounts(Thread* thread, int delta, int dbgDelta);
95void dvmCheckInterpStateConsistency();
96void dvmInitializeInterpBreak(Thread* thread);
97
98/*
99 * Register a callback to occur at the next safe point for a single thread.
100 * If funct is NULL, the previous registration is cancelled.
101 *
102 * The callback prototype is:
103 *        bool funct(Thread* thread, void* arg)
104 *
105 *  If funct returns false, the callback will be disarmed.  If true,
106 *  it will stay in effect.
107 */
108void dvmArmSafePointCallback(Thread* thread, SafePointCallback funct,
109                             void* arg);
110
111
112#ifndef DVM_NO_ASM_INTERP
113extern void* dvmAsmInstructionStart[];
114extern void* dvmAsmAltInstructionStart[];
115#endif
116
117#endif  // DALVIK_INTERP_INTERP_H_
118