| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * In the C mterp stubs, "goto" is a function call followed immediately |
| 3 | * by a return. |
| 4 | */ |
| 5 | |
| 6 | #define GOTO_TARGET_DECL(_target, ...) |
| 7 | |
| 8 | #define GOTO_TARGET(_target, ...) _target: |
| 9 | |
| 10 | #define GOTO_TARGET_END |
| 11 | |
| 12 | /* ugh */ |
| 13 | #define STUB_HACK(x) |
| 14 | |
| 15 | /* |
| 16 | * Instruction framing. For a switch-oriented implementation this is |
| 17 | * case/break, for a threaded implementation it's a goto label and an |
| 18 | * instruction fetch/computed goto. |
| 19 | * |
| 20 | * Assumes the existence of "const u2* pc" and (for threaded operation) |
| 21 | * "u2 inst". |
| 22 | */ |
| 23 | #ifdef THREADED_INTERP |
| 24 | # define H(_op) &&op_##_op |
| 25 | # define HANDLE_OPCODE(_op) op_##_op: |
| 26 | # define FINISH(_offset) { \ |
| 27 | ADJUST_PC(_offset); \ |
| 28 | inst = FETCH(0); \ |
| 29 | CHECK_DEBUG_AND_PROF(); \ |
| 30 | CHECK_TRACKED_REFS(); \ |
| 31 | goto *handlerTable[INST_INST(inst)]; \ |
| 32 | } |
| 33 | #else |
| 34 | # define HANDLE_OPCODE(_op) case _op: |
| 35 | # define FINISH(_offset) { ADJUST_PC(_offset); break; } |
| 36 | #endif |
| 37 | |
| 38 | #define OP_END |
| 39 | |
| 40 | #if defined(WITH_TRACKREF_CHECKS) |
| 41 | # define CHECK_TRACKED_REFS() \ |
| 42 | dvmInterpCheckTrackedRefs(self, curMethod, debugTrackedRefStart) |
| 43 | #else |
| 44 | # define CHECK_TRACKED_REFS() ((void)0) |
| 45 | #endif |
| 46 | |
| 47 | |
| 48 | /* |
| 49 | * The "goto" targets just turn into goto statements. The "arguments" are |
| 50 | * passed through local variables. |
| 51 | */ |
| 52 | |
| 53 | #define GOTO_exceptionThrown() goto exceptionThrown; |
| 54 | |
| 55 | #define GOTO_returnFromMethod() goto returnFromMethod; |
| 56 | |
| 57 | #define GOTO_invoke(_target, _methodCallRange) \ |
| 58 | do { \ |
| 59 | methodCallRange = _methodCallRange; \ |
| 60 | goto _target; \ |
| 61 | } while(false) |
| 62 | |
| 63 | /* for this, the "args" are already in the locals */ |
| 64 | #define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst) goto invokeMethod; |
| 65 | |
| 66 | #define GOTO_bail() goto bail; |
| 67 | #define GOTO_bail_switch() goto bail_switch; |
| 68 | |
| 69 | /* |
| 70 | * Periodically check for thread suspension. |
| 71 | * |
| 72 | * While we're at it, see if a debugger has attached or the profiler has |
| 73 | * started. If so, switch to a different "goto" table. |
| 74 | */ |
| 75 | #define PERIODIC_CHECKS(_entryPoint, _pcadj) { \ |
| The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame^] | 76 | if (dvmCheckSuspendQuick(self)) { \ |
| 77 | EXPORT_PC(); /* need for precise GC */ \ |
| 78 | dvmCheckSuspendPending(self); \ |
| 79 | } \ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 80 | if (NEED_INTERP_SWITCH(INTERP_TYPE)) { \ |
| 81 | ADJUST_PC(_pcadj); \ |
| 82 | interpState->entryPoint = _entryPoint; \ |
| 83 | LOGVV("threadid=%d: switch to %s ep=%d adj=%d\n", \ |
| 84 | self->threadId, \ |
| 85 | (interpState->nextMode == INTERP_STD) ? "STD" : "DBG", \ |
| 86 | (_entryPoint), (_pcadj)); \ |
| 87 | GOTO_bail_switch(); \ |
| 88 | } \ |
| 89 | } |
| 90 | |