blob: dbd556112b8afbd991878e3d0c5157d26b81a1c1 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
2 * Main interpreter loop.
3 *
4 * This was written with an ARM implementation in mind.
5 */
6bool INTERP_FUNC_NAME(Thread* self, InterpState* interpState)
7{
8#if defined(EASY_GDB)
9 StackSaveArea* debugSaveArea = SAVEAREA_FROM_FP(self->curFrame);
10#endif
11#if INTERP_TYPE == INTERP_DBG
12 bool debugIsMethodEntry = interpState->debugIsMethodEntry;
13#endif
14#if defined(WITH_TRACKREF_CHECKS)
15 int debugTrackedRefStart = interpState->debugTrackedRefStart;
16#endif
17 DvmDex* methodClassDex; // curMethod->clazz->pDvmDex
18 JValue retval;
19
20 /* core state */
21 const Method* curMethod; // method we're interpreting
22 const u2* pc; // program counter
23 u4* fp; // frame pointer
24 u2 inst; // current instruction
25 /* instruction decoding */
26 u2 ref; // 16-bit quantity fetched directly
27 u2 vsrc1, vsrc2, vdst; // usually used for register indexes
28 /* method call setup */
29 const Method* methodToCall;
30 bool methodCallRange;
31
Ben Chengba4fc8b2009-06-01 13:00:29 -070032
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080033#if defined(THREADED_INTERP)
34 /* static computed goto table */
35 DEFINE_GOTO_TABLE(handlerTable);
36#endif
37
Ben Chengba4fc8b2009-06-01 13:00:29 -070038#if defined(WITH_JIT)
39#if 0
40 LOGD("*DebugInterp - entrypoint is %d, tgt is 0x%x, %s\n",
41 interpState->entryPoint,
42 interpState->pc,
43 interpState->method->name);
44#endif
Ben Chengba4fc8b2009-06-01 13:00:29 -070045#if INTERP_TYPE == INTERP_DBG
Bill Buzbee06bb8392010-01-31 18:53:15 -080046 /* Check to see if we've got a trace selection request. */
47 if (
Ben Cheng95cd9ac2010-03-12 16:58:24 -080048 /*
Ben Chenga4973592010-03-31 11:59:18 -070049 * Only perform dvmJitCheckTraceRequest if the entry point is
50 * EntryInstr and the jit state is either kJitTSelectRequest or
51 * kJitTSelectRequestHot. If debugger/profiler happens to be attached,
52 * dvmJitCheckTraceRequest will change the jitState to kJitDone but
53 * but stay in the dbg interpreter.
Ben Cheng95cd9ac2010-03-12 16:58:24 -080054 */
Ben Chenga4973592010-03-31 11:59:18 -070055 (interpState->entryPoint == kInterpEntryInstr) &&
56 (interpState->jitState == kJitTSelectRequest ||
57 interpState->jitState == kJitTSelectRequestHot) &&
Bill Buzbee06bb8392010-01-31 18:53:15 -080058 dvmJitCheckTraceRequest(self, interpState)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -070059 interpState->nextMode = INTERP_STD;
Bill Buzbee06bb8392010-01-31 18:53:15 -080060 //LOGD("Invalid trace request, exiting\n");
Ben Chengba4fc8b2009-06-01 13:00:29 -070061 return true;
62 }
Jeff Hao97319a82009-08-12 16:57:15 -070063#endif /* INTERP_TYPE == INTERP_DBG */
64#endif /* WITH_JIT */
Ben Chengba4fc8b2009-06-01 13:00:29 -070065
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080066 /* copy state in */
67 curMethod = interpState->method;
68 pc = interpState->pc;
69 fp = interpState->fp;
70 retval = interpState->retval; /* only need for kInterpEntryReturn? */
71
72 methodClassDex = curMethod->clazz->pDvmDex;
73
74 LOGVV("threadid=%d: entry(%s) %s.%s pc=0x%x fp=%p ep=%d\n",
75 self->threadId, (interpState->nextMode == INTERP_STD) ? "STD" : "DBG",
76 curMethod->clazz->descriptor, curMethod->name, pc - curMethod->insns,
77 fp, interpState->entryPoint);
78
79 /*
80 * DEBUG: scramble this to ensure we're not relying on it.
81 */
82 methodToCall = (const Method*) -1;
83
84#if INTERP_TYPE == INTERP_DBG
85 if (debugIsMethodEntry) {
86 ILOGD("|-- Now interpreting %s.%s", curMethod->clazz->descriptor,
87 curMethod->name);
88 DUMP_REGS(curMethod, interpState->fp, false);
89 }
90#endif
91
92 switch (interpState->entryPoint) {
93 case kInterpEntryInstr:
94 /* just fall through to instruction loop or threaded kickstart */
95 break;
96 case kInterpEntryReturn:
Ben Cheng9c147b82009-10-07 16:41:46 -070097 CHECK_JIT();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080098 goto returnFromMethod;
99 case kInterpEntryThrow:
100 goto exceptionThrown;
101 default:
102 dvmAbort();
103 }
104
105#ifdef THREADED_INTERP
106 FINISH(0); /* fetch and execute first instruction */
107#else
108 while (1) {
109 CHECK_DEBUG_AND_PROF(); /* service debugger and profiling */
110 CHECK_TRACKED_REFS(); /* check local reference tracking */
111
112 /* fetch the next 16 bits from the instruction stream */
113 inst = FETCH(0);
114
115 switch (INST_INST(inst)) {
116#endif
117
118/*--- start of opcodes ---*/