blob: c3139ee73b9e3f5de77b9c824e3451cc3fec73e6 [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 */
buzbee9f601a92011-02-11 17:48:20 -08006bool INTERP_FUNC_NAME(Thread* self)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08007{
8#if defined(EASY_GDB)
9 StackSaveArea* debugSaveArea = SAVEAREA_FROM_FP(self->curFrame);
10#endif
11#if INTERP_TYPE == INTERP_DBG
Andy McFaddenc95e0fb2010-04-29 14:13:01 -070012 bool debugIsMethodEntry = false;
buzbee9f601a92011-02-11 17:48:20 -080013 debugIsMethodEntry = self->debugIsMethodEntry;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080014#endif
15#if defined(WITH_TRACKREF_CHECKS)
buzbeeef5db622011-02-22 14:01:46 -080016 int debugTrackedRefStart = self->interpSave.debugTrackedRefStart;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080017#endif
18 DvmDex* methodClassDex; // curMethod->clazz->pDvmDex
19 JValue retval;
20
21 /* core state */
22 const Method* curMethod; // method we're interpreting
23 const u2* pc; // program counter
24 u4* fp; // frame pointer
25 u2 inst; // current instruction
26 /* instruction decoding */
jeffhao71eee1f2011-01-04 14:18:54 -080027 u4 ref; // 16 or 32-bit quantity fetched directly
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080028 u2 vsrc1, vsrc2, vdst; // usually used for register indexes
29 /* method call setup */
30 const Method* methodToCall;
31 bool methodCallRange;
jeffhao71eee1f2011-01-04 14:18:54 -080032 bool jumboFormat;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080033
Ben Chengba4fc8b2009-06-01 13:00:29 -070034
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080035#if defined(THREADED_INTERP)
36 /* static computed goto table */
37 DEFINE_GOTO_TABLE(handlerTable);
38#endif
39
Ben Chengba4fc8b2009-06-01 13:00:29 -070040#if defined(WITH_JIT)
41#if 0
42 LOGD("*DebugInterp - entrypoint is %d, tgt is 0x%x, %s\n",
buzbee9f601a92011-02-11 17:48:20 -080043 self->entryPoint,
44 self->interpSave.pc,
45 self->interpSave.method->name);
Ben Chengba4fc8b2009-06-01 13:00:29 -070046#endif
Ben Chengba4fc8b2009-06-01 13:00:29 -070047#if INTERP_TYPE == INTERP_DBG
Ben Cheng7a2697d2010-06-07 13:44:23 -070048 const ClassObject* callsiteClass = NULL;
49
50#if defined(WITH_SELF_VERIFICATION)
buzbee9f601a92011-02-11 17:48:20 -080051 if (self->jitState != kJitSelfVerification) {
52 self->shadowSpace->jitExitState = kSVSIdle;
Ben Cheng7a2697d2010-06-07 13:44:23 -070053 }
54#endif
55
Bill Buzbee06bb8392010-01-31 18:53:15 -080056 /* Check to see if we've got a trace selection request. */
57 if (
Ben Cheng95cd9ac2010-03-12 16:58:24 -080058 /*
Ben Chenga4973592010-03-31 11:59:18 -070059 * Only perform dvmJitCheckTraceRequest if the entry point is
60 * EntryInstr and the jit state is either kJitTSelectRequest or
61 * kJitTSelectRequestHot. If debugger/profiler happens to be attached,
62 * dvmJitCheckTraceRequest will change the jitState to kJitDone but
63 * but stay in the dbg interpreter.
Ben Cheng95cd9ac2010-03-12 16:58:24 -080064 */
buzbee9f601a92011-02-11 17:48:20 -080065 (self->entryPoint == kInterpEntryInstr) &&
66 (self->jitState == kJitTSelectRequest ||
67 self->jitState == kJitTSelectRequestHot) &&
68 dvmJitCheckTraceRequest(self)) {
69 self->nextMode = INTERP_STD;
Bill Buzbee06bb8392010-01-31 18:53:15 -080070 //LOGD("Invalid trace request, exiting\n");
Ben Chengba4fc8b2009-06-01 13:00:29 -070071 return true;
72 }
Jeff Hao97319a82009-08-12 16:57:15 -070073#endif /* INTERP_TYPE == INTERP_DBG */
74#endif /* WITH_JIT */
Ben Chengba4fc8b2009-06-01 13:00:29 -070075
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080076 /* copy state in */
buzbee9f601a92011-02-11 17:48:20 -080077 curMethod = self->interpSave.method;
78 pc = self->interpSave.pc;
79 fp = self->interpSave.fp;
80 retval = self->retval; /* only need for kInterpEntryReturn? */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080081
82 methodClassDex = curMethod->clazz->pDvmDex;
83
84 LOGVV("threadid=%d: entry(%s) %s.%s pc=0x%x fp=%p ep=%d\n",
buzbee9f601a92011-02-11 17:48:20 -080085 self->threadId, (self->nextMode == INTERP_STD) ? "STD" : "DBG",
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080086 curMethod->clazz->descriptor, curMethod->name, pc - curMethod->insns,
buzbee9f601a92011-02-11 17:48:20 -080087 fp, self->entryPoint);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080088
89 /*
90 * DEBUG: scramble this to ensure we're not relying on it.
91 */
92 methodToCall = (const Method*) -1;
93
94#if INTERP_TYPE == INTERP_DBG
95 if (debugIsMethodEntry) {
96 ILOGD("|-- Now interpreting %s.%s", curMethod->clazz->descriptor,
97 curMethod->name);
buzbee9f601a92011-02-11 17:48:20 -080098 DUMP_REGS(curMethod, self->interpSave.fp, false);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080099 }
100#endif
101
buzbee9f601a92011-02-11 17:48:20 -0800102 switch (self->entryPoint) {
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800103 case kInterpEntryInstr:
104 /* just fall through to instruction loop or threaded kickstart */
105 break;
106 case kInterpEntryReturn:
Ben Chengfc075c22010-05-28 15:20:08 -0700107 CHECK_JIT_VOID();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800108 goto returnFromMethod;
109 case kInterpEntryThrow:
110 goto exceptionThrown;
111 default:
112 dvmAbort();
113 }
114
115#ifdef THREADED_INTERP
116 FINISH(0); /* fetch and execute first instruction */
117#else
118 while (1) {
119 CHECK_DEBUG_AND_PROF(); /* service debugger and profiling */
120 CHECK_TRACKED_REFS(); /* check local reference tracking */
121
122 /* fetch the next 16 bits from the instruction stream */
123 inst = FETCH(0);
124
125 switch (INST_INST(inst)) {
126#endif
127
128/*--- start of opcodes ---*/