After pushing the to-be-executed method frame on the top of stack thread, Dalvik will call the main interpreter to start the interpreting.
-dvmInterpret(Thread* self, const Method* method, JValue* pResult)
1. dvmInterpret()
-arguments:
1: Thread* self --> current thread
2: const Method* method --> current to-be-executed method
3: the returned value
-function work flow
1. Initialize working state
-source
interpState.method = method;
interpState.fp = (u4*) self->curFrame;
interpState.pc = method->insns;
interpState.entryPoint = kInterpEntryInstr;
if (dvmDebuggerOrProfilerActive())
interpState.nextMode = INTERP_DBG;
else
interpState.nextMode = INTERP_STD;
2. Determine execution mode. Typically, Dalvik has two modes of
interpreter to choose (C or Assembly for target platform).
-source
typedef bool (*Interpreter)(Thread*, InterpState*);
Interpreter stdInterp;
if (gDvm.executionMode == kExecutionModeInterpFast)
stdInterp = dvmMterpStd;
#if defined(WITH_JIT)
else if (gDvm.executionMode == kExecutionModeJit)
stdInterp = dvmMterpStd;
#endif
else
stdInterp = dvmInterpretStd;
3. Call the real interpreter with the thread and interpState parameters
change = true;
while (change) {
switch (interpState.nextMode) {
case INTERP_STD:
change = (*stdInterp)(self, &interpState);
break;
#if defined(WITH_PROFILER) || defined(WITH_DEBUGGER) || defined(WITH_JIT)
case INTERP_DBG:
change = dvmInterpretDbg(self, &interpState);
break;
#endif
default:
dvmAbort();
}
}
沒有留言:
張貼留言