blob: 97fbe015eaf635b5e7bb3fe05591e0c7756f4794 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
2 * This file was generated automatically by gen-mterp.py for 'x86'.
3 *
4 * --> DO NOT EDIT <--
5 */
6
7/* File: c/header.c */
8/*
9 * Copyright (C) 2008 The Android Open Source Project
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/* common includes */
25#include "Dalvik.h"
26#include "interp/InterpDefs.h"
27#include "mterp/Mterp.h"
28#include <math.h> // needed for fmod, fmodf
Ben Chengba4fc8b2009-06-01 13:00:29 -070029#include "mterp/common/FindInterface.h"
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080030
31/*
32 * Configuration defines. These affect the C implementations, i.e. the
33 * portable interpreter(s) and C stubs.
34 *
35 * Some defines are controlled by the Makefile, e.g.:
36 * WITH_PROFILER
37 * WITH_DEBUGGER
38 * WITH_INSTR_CHECKS
39 * WITH_TRACKREF_CHECKS
40 * EASY_GDB
41 * NDEBUG
42 *
43 * If THREADED_INTERP is not defined, we use a classic "while true / switch"
44 * interpreter. If it is defined, then the tail end of each instruction
45 * handler fetches the next instruction and jumps directly to the handler.
46 * This increases the size of the "Std" interpreter by about 10%, but
47 * provides a speedup of about the same magnitude.
48 *
49 * There's a "hybrid" approach that uses a goto table instead of a switch
50 * statement, avoiding the "is the opcode in range" tests required for switch.
51 * The performance is close to the threaded version, and without the 10%
52 * size increase, but the benchmark results are off enough that it's not
53 * worth adding as a third option.
54 */
55#define THREADED_INTERP /* threaded vs. while-loop interpreter */
56
The Android Open Source Project99409882009-03-18 22:20:24 -070057#ifdef WITH_INSTR_CHECKS /* instruction-level paranoia (slow!) */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080058# define CHECK_BRANCH_OFFSETS
59# define CHECK_REGISTER_INDICES
60#endif
61
62/*
63 * ARM EABI requires 64-bit alignment for access to 64-bit data types. We
64 * can't just use pointers to copy 64-bit values out of our interpreted
65 * register set, because gcc will generate ldrd/strd.
66 *
67 * The __UNION version copies data in and out of a union. The __MEMCPY
68 * version uses a memcpy() call to do the transfer; gcc is smart enough to
69 * not actually call memcpy(). The __UNION version is very bad on ARM;
70 * it only uses one more instruction than __MEMCPY, but for some reason
71 * gcc thinks it needs separate storage for every instance of the union.
72 * On top of that, it feels the need to zero them out at the start of the
73 * method. Net result is we zero out ~700 bytes of stack space at the top
74 * of the interpreter using ARM STM instructions.
75 */
76#if defined(__ARM_EABI__)
77//# define NO_UNALIGN_64__UNION
78# define NO_UNALIGN_64__MEMCPY
79#endif
80
81//#define LOG_INSTR /* verbose debugging */
82/* set and adjust ANDROID_LOG_TAGS='*:i jdwp:i dalvikvm:i dalvikvmi:i' */
83
84/*
85 * Keep a tally of accesses to fields. Currently only works if full DEX
86 * optimization is disabled.
87 */
88#ifdef PROFILE_FIELD_ACCESS
89# define UPDATE_FIELD_GET(_field) { (_field)->gets++; }
90# define UPDATE_FIELD_PUT(_field) { (_field)->puts++; }
91#else
92# define UPDATE_FIELD_GET(_field) ((void)0)
93# define UPDATE_FIELD_PUT(_field) ((void)0)
94#endif
95
96/*
The Android Open Source Project99409882009-03-18 22:20:24 -070097 * Export another copy of the PC on every instruction; this is largely
98 * redundant with EXPORT_PC and the debugger code. This value can be
99 * compared against what we have stored on the stack with EXPORT_PC to
100 * help ensure that we aren't missing any export calls.
101 */
102#if WITH_EXTRA_GC_CHECKS > 1
103# define EXPORT_EXTRA_PC() (self->currentPc2 = pc)
104#else
105# define EXPORT_EXTRA_PC()
106#endif
107
108/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800109 * Adjust the program counter. "_offset" is a signed int, in 16-bit units.
110 *
111 * Assumes the existence of "const u2* pc" and "const u2* curMethod->insns".
112 *
113 * We don't advance the program counter until we finish an instruction or
114 * branch, because we do want to have to unroll the PC if there's an
115 * exception.
116 */
117#ifdef CHECK_BRANCH_OFFSETS
118# define ADJUST_PC(_offset) do { \
119 int myoff = _offset; /* deref only once */ \
120 if (pc + myoff < curMethod->insns || \
121 pc + myoff >= curMethod->insns + dvmGetMethodInsnsSize(curMethod)) \
122 { \
123 char* desc; \
124 desc = dexProtoCopyMethodDescriptor(&curMethod->prototype); \
125 LOGE("Invalid branch %d at 0x%04x in %s.%s %s\n", \
126 myoff, (int) (pc - curMethod->insns), \
127 curMethod->clazz->descriptor, curMethod->name, desc); \
128 free(desc); \
129 dvmAbort(); \
130 } \
131 pc += myoff; \
The Android Open Source Project99409882009-03-18 22:20:24 -0700132 EXPORT_EXTRA_PC(); \
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800133 } while (false)
134#else
The Android Open Source Project99409882009-03-18 22:20:24 -0700135# define ADJUST_PC(_offset) do { \
136 pc += _offset; \
137 EXPORT_EXTRA_PC(); \
138 } while (false)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800139#endif
140
141/*
142 * If enabled, log instructions as we execute them.
143 */
144#ifdef LOG_INSTR
145# define ILOGD(...) ILOG(LOG_DEBUG, __VA_ARGS__)
146# define ILOGV(...) ILOG(LOG_VERBOSE, __VA_ARGS__)
147# define ILOG(_level, ...) do { \
148 char debugStrBuf[128]; \
149 snprintf(debugStrBuf, sizeof(debugStrBuf), __VA_ARGS__); \
150 if (curMethod != NULL) \
151 LOG(_level, LOG_TAG"i", "%-2d|%04x%s\n", \
152 self->threadId, (int)(pc - curMethod->insns), debugStrBuf); \
153 else \
154 LOG(_level, LOG_TAG"i", "%-2d|####%s\n", \
155 self->threadId, debugStrBuf); \
156 } while(false)
157void dvmDumpRegs(const Method* method, const u4* framePtr, bool inOnly);
158# define DUMP_REGS(_meth, _frame, _inOnly) dvmDumpRegs(_meth, _frame, _inOnly)
159static const char kSpacing[] = " ";
160#else
161# define ILOGD(...) ((void)0)
162# define ILOGV(...) ((void)0)
163# define DUMP_REGS(_meth, _frame, _inOnly) ((void)0)
164#endif
165
166/* get a long from an array of u4 */
167static inline s8 getLongFromArray(const u4* ptr, int idx)
168{
169#if defined(NO_UNALIGN_64__UNION)
170 union { s8 ll; u4 parts[2]; } conv;
171
172 ptr += idx;
173 conv.parts[0] = ptr[0];
174 conv.parts[1] = ptr[1];
175 return conv.ll;
176#elif defined(NO_UNALIGN_64__MEMCPY)
177 s8 val;
178 memcpy(&val, &ptr[idx], 8);
179 return val;
180#else
181 return *((s8*) &ptr[idx]);
182#endif
183}
184
185/* store a long into an array of u4 */
186static inline void putLongToArray(u4* ptr, int idx, s8 val)
187{
188#if defined(NO_UNALIGN_64__UNION)
189 union { s8 ll; u4 parts[2]; } conv;
190
191 ptr += idx;
192 conv.ll = val;
193 ptr[0] = conv.parts[0];
194 ptr[1] = conv.parts[1];
195#elif defined(NO_UNALIGN_64__MEMCPY)
196 memcpy(&ptr[idx], &val, 8);
197#else
198 *((s8*) &ptr[idx]) = val;
199#endif
200}
201
202/* get a double from an array of u4 */
203static inline double getDoubleFromArray(const u4* ptr, int idx)
204{
205#if defined(NO_UNALIGN_64__UNION)
206 union { double d; u4 parts[2]; } conv;
207
208 ptr += idx;
209 conv.parts[0] = ptr[0];
210 conv.parts[1] = ptr[1];
211 return conv.d;
212#elif defined(NO_UNALIGN_64__MEMCPY)
213 double dval;
214 memcpy(&dval, &ptr[idx], 8);
215 return dval;
216#else
217 return *((double*) &ptr[idx]);
218#endif
219}
220
221/* store a double into an array of u4 */
222static inline void putDoubleToArray(u4* ptr, int idx, double dval)
223{
224#if defined(NO_UNALIGN_64__UNION)
225 union { double d; u4 parts[2]; } conv;
226
227 ptr += idx;
228 conv.d = dval;
229 ptr[0] = conv.parts[0];
230 ptr[1] = conv.parts[1];
231#elif defined(NO_UNALIGN_64__MEMCPY)
232 memcpy(&ptr[idx], &dval, 8);
233#else
234 *((double*) &ptr[idx]) = dval;
235#endif
236}
237
238/*
239 * If enabled, validate the register number on every access. Otherwise,
240 * just do an array access.
241 *
242 * Assumes the existence of "u4* fp".
243 *
244 * "_idx" may be referenced more than once.
245 */
246#ifdef CHECK_REGISTER_INDICES
247# define GET_REGISTER(_idx) \
248 ( (_idx) < curMethod->registersSize ? \
249 (fp[(_idx)]) : (assert(!"bad reg"),1969) )
250# define SET_REGISTER(_idx, _val) \
251 ( (_idx) < curMethod->registersSize ? \
252 (fp[(_idx)] = (u4)(_val)) : (assert(!"bad reg"),1969) )
253# define GET_REGISTER_AS_OBJECT(_idx) ((Object *)GET_REGISTER(_idx))
254# define SET_REGISTER_AS_OBJECT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
255# define GET_REGISTER_INT(_idx) ((s4) GET_REGISTER(_idx))
256# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
257# define GET_REGISTER_WIDE(_idx) \
258 ( (_idx) < curMethod->registersSize-1 ? \
259 getLongFromArray(fp, (_idx)) : (assert(!"bad reg"),1969) )
260# define SET_REGISTER_WIDE(_idx, _val) \
261 ( (_idx) < curMethod->registersSize-1 ? \
262 putLongToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969) )
263# define GET_REGISTER_FLOAT(_idx) \
264 ( (_idx) < curMethod->registersSize ? \
265 (*((float*) &fp[(_idx)])) : (assert(!"bad reg"),1969.0f) )
266# define SET_REGISTER_FLOAT(_idx, _val) \
267 ( (_idx) < curMethod->registersSize ? \
268 (*((float*) &fp[(_idx)]) = (_val)) : (assert(!"bad reg"),1969.0f) )
269# define GET_REGISTER_DOUBLE(_idx) \
270 ( (_idx) < curMethod->registersSize-1 ? \
271 getDoubleFromArray(fp, (_idx)) : (assert(!"bad reg"),1969.0) )
272# define SET_REGISTER_DOUBLE(_idx, _val) \
273 ( (_idx) < curMethod->registersSize-1 ? \
274 putDoubleToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969.0) )
275#else
276# define GET_REGISTER(_idx) (fp[(_idx)])
277# define SET_REGISTER(_idx, _val) (fp[(_idx)] = (_val))
278# define GET_REGISTER_AS_OBJECT(_idx) ((Object*) fp[(_idx)])
279# define SET_REGISTER_AS_OBJECT(_idx, _val) (fp[(_idx)] = (u4)(_val))
280# define GET_REGISTER_INT(_idx) ((s4)GET_REGISTER(_idx))
281# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
282# define GET_REGISTER_WIDE(_idx) getLongFromArray(fp, (_idx))
283# define SET_REGISTER_WIDE(_idx, _val) putLongToArray(fp, (_idx), (_val))
284# define GET_REGISTER_FLOAT(_idx) (*((float*) &fp[(_idx)]))
285# define SET_REGISTER_FLOAT(_idx, _val) (*((float*) &fp[(_idx)]) = (_val))
286# define GET_REGISTER_DOUBLE(_idx) getDoubleFromArray(fp, (_idx))
287# define SET_REGISTER_DOUBLE(_idx, _val) putDoubleToArray(fp, (_idx), (_val))
288#endif
289
290/*
291 * Get 16 bits from the specified offset of the program counter. We always
292 * want to load 16 bits at a time from the instruction stream -- it's more
293 * efficient than 8 and won't have the alignment problems that 32 might.
294 *
295 * Assumes existence of "const u2* pc".
296 */
297#define FETCH(_offset) (pc[(_offset)])
298
299/*
300 * Extract instruction byte from 16-bit fetch (_inst is a u2).
301 */
302#define INST_INST(_inst) ((_inst) & 0xff)
303
304/*
Andy McFadden96516932009-10-28 17:39:02 -0700305 * Replace the opcode (used when handling breakpoints). _opcode is a u1.
306 */
307#define INST_REPLACE_OP(_inst, _opcode) (((_inst) & 0xff00) | _opcode)
308
309/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800310 * Extract the "vA, vB" 4-bit registers from the instruction word (_inst is u2).
311 */
312#define INST_A(_inst) (((_inst) >> 8) & 0x0f)
313#define INST_B(_inst) ((_inst) >> 12)
314
315/*
316 * Get the 8-bit "vAA" 8-bit register index from the instruction word.
317 * (_inst is u2)
318 */
319#define INST_AA(_inst) ((_inst) >> 8)
320
321/*
322 * The current PC must be available to Throwable constructors, e.g.
323 * those created by dvmThrowException(), so that the exception stack
324 * trace can be generated correctly. If we don't do this, the offset
325 * within the current method won't be shown correctly. See the notes
326 * in Exception.c.
327 *
The Android Open Source Project99409882009-03-18 22:20:24 -0700328 * This is also used to determine the address for precise GC.
329 *
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800330 * Assumes existence of "u4* fp" and "const u2* pc".
331 */
332#define EXPORT_PC() (SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc)
333
334/*
335 * Determine if we need to switch to a different interpreter. "_current"
336 * is either INTERP_STD or INTERP_DBG. It should be fixed for a given
337 * interpreter generation file, which should remove the outer conditional
338 * from the following.
339 *
340 * If we're building without debug and profiling support, we never switch.
341 */
342#if defined(WITH_PROFILER) || defined(WITH_DEBUGGER)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700343#if defined(WITH_JIT)
344# define NEED_INTERP_SWITCH(_current) ( \
345 (_current == INTERP_STD) ? \
Bill Buzbee5540f6e2010-02-08 10:41:32 -0800346 dvmJitDebuggerOrProfilerActive() : !dvmJitDebuggerOrProfilerActive() )
Ben Chengba4fc8b2009-06-01 13:00:29 -0700347#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800348# define NEED_INTERP_SWITCH(_current) ( \
349 (_current == INTERP_STD) ? \
350 dvmDebuggerOrProfilerActive() : !dvmDebuggerOrProfilerActive() )
Ben Chengba4fc8b2009-06-01 13:00:29 -0700351#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800352#else
353# define NEED_INTERP_SWITCH(_current) (false)
354#endif
355
356/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800357 * Check to see if "obj" is NULL. If so, throw an exception. Assumes the
358 * pc has already been exported to the stack.
359 *
360 * Perform additional checks on debug builds.
361 *
362 * Use this to check for NULL when the instruction handler calls into
363 * something that could throw an exception (so we have already called
364 * EXPORT_PC at the top).
365 */
366static inline bool checkForNull(Object* obj)
367{
368 if (obj == NULL) {
369 dvmThrowException("Ljava/lang/NullPointerException;", NULL);
370 return false;
371 }
372#ifdef WITH_EXTRA_OBJECT_VALIDATION
373 if (!dvmIsValidObject(obj)) {
374 LOGE("Invalid object %p\n", obj);
375 dvmAbort();
376 }
377#endif
378#ifndef NDEBUG
379 if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
380 /* probable heap corruption */
381 LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj);
382 dvmAbort();
383 }
384#endif
385 return true;
386}
387
388/*
389 * Check to see if "obj" is NULL. If so, export the PC into the stack
390 * frame and throw an exception.
391 *
392 * Perform additional checks on debug builds.
393 *
394 * Use this to check for NULL when the instruction handler doesn't do
395 * anything else that can throw an exception.
396 */
397static inline bool checkForNullExportPC(Object* obj, u4* fp, const u2* pc)
398{
399 if (obj == NULL) {
400 EXPORT_PC();
401 dvmThrowException("Ljava/lang/NullPointerException;", NULL);
402 return false;
403 }
404#ifdef WITH_EXTRA_OBJECT_VALIDATION
405 if (!dvmIsValidObject(obj)) {
406 LOGE("Invalid object %p\n", obj);
407 dvmAbort();
408 }
409#endif
410#ifndef NDEBUG
411 if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
412 /* probable heap corruption */
413 LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj);
414 dvmAbort();
415 }
416#endif
417 return true;
418}
419
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800420/* File: cstubs/stubdefs.c */
421/* this is a standard (no debug support) interpreter */
422#define INTERP_TYPE INTERP_STD
423#define CHECK_DEBUG_AND_PROF() ((void)0)
424# define CHECK_TRACKED_REFS() ((void)0)
Bill Buzbee5540f6e2010-02-08 10:41:32 -0800425#if defined(WITH_JIT)
426#define CHECK_JIT() (0)
427#define ABORT_JIT_TSELECT() ((void)0)
428#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800429
430/*
431 * In the C mterp stubs, "goto" is a function call followed immediately
432 * by a return.
433 */
434
435#define GOTO_TARGET_DECL(_target, ...) \
436 void dvmMterp_##_target(MterpGlue* glue, ## __VA_ARGS__);
437
438#define GOTO_TARGET(_target, ...) \
439 void dvmMterp_##_target(MterpGlue* glue, ## __VA_ARGS__) { \
440 u2 ref, vsrc1, vsrc2, vdst; \
441 u2 inst = FETCH(0); \
442 const Method* methodToCall; \
443 StackSaveArea* debugSaveArea;
444
445#define GOTO_TARGET_END }
446
447/*
448 * Redefine what used to be local variable accesses into MterpGlue struct
449 * references. (These are undefined down in "footer.c".)
450 */
451#define retval glue->retval
452#define pc glue->pc
453#define fp glue->fp
454#define curMethod glue->method
455#define methodClassDex glue->methodClassDex
456#define self glue->self
457#define debugTrackedRefStart glue->debugTrackedRefStart
458
459/* ugh */
460#define STUB_HACK(x) x
461
462
463/*
464 * Opcode handler framing macros. Here, each opcode is a separate function
465 * that takes a "glue" argument and returns void. We can't declare
466 * these "static" because they may be called from an assembly stub.
467 */
468#define HANDLE_OPCODE(_op) \
469 void dvmMterp_##_op(MterpGlue* glue) { \
470 u2 ref, vsrc1, vsrc2, vdst; \
471 u2 inst = FETCH(0);
472
473#define OP_END }
474
475/*
476 * Like the "portable" FINISH, but don't reload "inst", and return to caller
477 * when done.
478 */
479#define FINISH(_offset) { \
480 ADJUST_PC(_offset); \
481 CHECK_DEBUG_AND_PROF(); \
482 CHECK_TRACKED_REFS(); \
483 return; \
484 }
485
486
487/*
488 * The "goto label" statements turn into function calls followed by
489 * return statements. Some of the functions take arguments, which in the
490 * portable interpreter are handled by assigning values to globals.
491 */
492
493#define GOTO_exceptionThrown() \
494 do { \
495 dvmMterp_exceptionThrown(glue); \
496 return; \
497 } while(false)
498
499#define GOTO_returnFromMethod() \
500 do { \
501 dvmMterp_returnFromMethod(glue); \
502 return; \
503 } while(false)
504
505#define GOTO_invoke(_target, _methodCallRange) \
506 do { \
507 dvmMterp_##_target(glue, _methodCallRange); \
508 return; \
509 } while(false)
510
511#define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst) \
512 do { \
513 dvmMterp_invokeMethod(glue, _methodCallRange, _methodToCall, \
514 _vsrc1, _vdst); \
515 return; \
516 } while(false)
517
518/*
519 * As a special case, "goto bail" turns into a longjmp. Use "bail_switch"
520 * if we need to switch to the other interpreter upon our return.
521 */
522#define GOTO_bail() \
523 dvmMterpStdBail(glue, false);
524#define GOTO_bail_switch() \
525 dvmMterpStdBail(glue, true);
526
527/*
528 * Periodically check for thread suspension.
529 *
530 * While we're at it, see if a debugger has attached or the profiler has
531 * started. If so, switch to a different "goto" table.
532 */
533#define PERIODIC_CHECKS(_entryPoint, _pcadj) { \
The Android Open Source Project99409882009-03-18 22:20:24 -0700534 if (dvmCheckSuspendQuick(self)) { \
535 EXPORT_PC(); /* need for precise GC */ \
536 dvmCheckSuspendPending(self); \
537 } \
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800538 if (NEED_INTERP_SWITCH(INTERP_TYPE)) { \
539 ADJUST_PC(_pcadj); \
540 glue->entryPoint = _entryPoint; \
541 LOGVV("threadid=%d: switch to STD ep=%d adj=%d\n", \
Andy McFadden080ca4a2009-08-05 13:20:16 -0700542 self->threadId, (_entryPoint), (_pcadj)); \
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800543 GOTO_bail_switch(); \
544 } \
545 }
546
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800547/* File: c/opcommon.c */
548/* forward declarations of goto targets */
549GOTO_TARGET_DECL(filledNewArray, bool methodCallRange);
550GOTO_TARGET_DECL(invokeVirtual, bool methodCallRange);
551GOTO_TARGET_DECL(invokeSuper, bool methodCallRange);
552GOTO_TARGET_DECL(invokeInterface, bool methodCallRange);
553GOTO_TARGET_DECL(invokeDirect, bool methodCallRange);
554GOTO_TARGET_DECL(invokeStatic, bool methodCallRange);
555GOTO_TARGET_DECL(invokeVirtualQuick, bool methodCallRange);
556GOTO_TARGET_DECL(invokeSuperQuick, bool methodCallRange);
557GOTO_TARGET_DECL(invokeMethod, bool methodCallRange, const Method* methodToCall,
558 u2 count, u2 regs);
559GOTO_TARGET_DECL(returnFromMethod);
560GOTO_TARGET_DECL(exceptionThrown);
561
562/*
563 * ===========================================================================
564 *
565 * What follows are opcode definitions shared between multiple opcodes with
566 * minor substitutions handled by the C pre-processor. These should probably
567 * use the mterp substitution mechanism instead, with the code here moved
568 * into common fragment files (like the asm "binop.S"), although it's hard
569 * to give up the C preprocessor in favor of the much simpler text subst.
570 *
571 * ===========================================================================
572 */
573
574#define HANDLE_NUMCONV(_opcode, _opname, _fromtype, _totype) \
575 HANDLE_OPCODE(_opcode /*vA, vB*/) \
576 vdst = INST_A(inst); \
577 vsrc1 = INST_B(inst); \
578 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
579 SET_REGISTER##_totype(vdst, \
580 GET_REGISTER##_fromtype(vsrc1)); \
581 FINISH(1);
582
583#define HANDLE_FLOAT_TO_INT(_opcode, _opname, _fromvtype, _fromrtype, \
584 _tovtype, _tortype) \
585 HANDLE_OPCODE(_opcode /*vA, vB*/) \
586 { \
587 /* spec defines specific handling for +/- inf and NaN values */ \
588 _fromvtype val; \
589 _tovtype intMin, intMax, result; \
590 vdst = INST_A(inst); \
591 vsrc1 = INST_B(inst); \
592 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
593 val = GET_REGISTER##_fromrtype(vsrc1); \
594 intMin = (_tovtype) 1 << (sizeof(_tovtype) * 8 -1); \
595 intMax = ~intMin; \
596 result = (_tovtype) val; \
597 if (val >= intMax) /* +inf */ \
598 result = intMax; \
599 else if (val <= intMin) /* -inf */ \
600 result = intMin; \
601 else if (val != val) /* NaN */ \
602 result = 0; \
603 else \
604 result = (_tovtype) val; \
605 SET_REGISTER##_tortype(vdst, result); \
606 } \
607 FINISH(1);
608
609#define HANDLE_INT_TO_SMALL(_opcode, _opname, _type) \
610 HANDLE_OPCODE(_opcode /*vA, vB*/) \
611 vdst = INST_A(inst); \
612 vsrc1 = INST_B(inst); \
613 ILOGV("|int-to-%s v%d,v%d", (_opname), vdst, vsrc1); \
614 SET_REGISTER(vdst, (_type) GET_REGISTER(vsrc1)); \
615 FINISH(1);
616
617/* NOTE: the comparison result is always a signed 4-byte integer */
618#define HANDLE_OP_CMPX(_opcode, _opname, _varType, _type, _nanVal) \
619 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
620 { \
621 int result; \
622 u2 regs; \
623 _varType val1, val2; \
624 vdst = INST_AA(inst); \
625 regs = FETCH(1); \
626 vsrc1 = regs & 0xff; \
627 vsrc2 = regs >> 8; \
628 ILOGV("|cmp%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
629 val1 = GET_REGISTER##_type(vsrc1); \
630 val2 = GET_REGISTER##_type(vsrc2); \
631 if (val1 == val2) \
632 result = 0; \
633 else if (val1 < val2) \
634 result = -1; \
635 else if (val1 > val2) \
636 result = 1; \
637 else \
638 result = (_nanVal); \
639 ILOGV("+ result=%d\n", result); \
640 SET_REGISTER(vdst, result); \
641 } \
642 FINISH(2);
643
644#define HANDLE_OP_IF_XX(_opcode, _opname, _cmp) \
645 HANDLE_OPCODE(_opcode /*vA, vB, +CCCC*/) \
646 vsrc1 = INST_A(inst); \
647 vsrc2 = INST_B(inst); \
648 if ((s4) GET_REGISTER(vsrc1) _cmp (s4) GET_REGISTER(vsrc2)) { \
649 int branchOffset = (s2)FETCH(1); /* sign-extended */ \
650 ILOGV("|if-%s v%d,v%d,+0x%04x", (_opname), vsrc1, vsrc2, \
651 branchOffset); \
652 ILOGV("> branch taken"); \
653 if (branchOffset < 0) \
654 PERIODIC_CHECKS(kInterpEntryInstr, branchOffset); \
655 FINISH(branchOffset); \
656 } else { \
657 ILOGV("|if-%s v%d,v%d,-", (_opname), vsrc1, vsrc2); \
658 FINISH(2); \
659 }
660
661#define HANDLE_OP_IF_XXZ(_opcode, _opname, _cmp) \
662 HANDLE_OPCODE(_opcode /*vAA, +BBBB*/) \
663 vsrc1 = INST_AA(inst); \
664 if ((s4) GET_REGISTER(vsrc1) _cmp 0) { \
665 int branchOffset = (s2)FETCH(1); /* sign-extended */ \
666 ILOGV("|if-%s v%d,+0x%04x", (_opname), vsrc1, branchOffset); \
667 ILOGV("> branch taken"); \
668 if (branchOffset < 0) \
669 PERIODIC_CHECKS(kInterpEntryInstr, branchOffset); \
670 FINISH(branchOffset); \
671 } else { \
672 ILOGV("|if-%s v%d,-", (_opname), vsrc1); \
673 FINISH(2); \
674 }
675
676#define HANDLE_UNOP(_opcode, _opname, _pfx, _sfx, _type) \
677 HANDLE_OPCODE(_opcode /*vA, vB*/) \
678 vdst = INST_A(inst); \
679 vsrc1 = INST_B(inst); \
680 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
681 SET_REGISTER##_type(vdst, _pfx GET_REGISTER##_type(vsrc1) _sfx); \
682 FINISH(1);
683
684#define HANDLE_OP_X_INT(_opcode, _opname, _op, _chkdiv) \
685 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
686 { \
687 u2 srcRegs; \
688 vdst = INST_AA(inst); \
689 srcRegs = FETCH(1); \
690 vsrc1 = srcRegs & 0xff; \
691 vsrc2 = srcRegs >> 8; \
692 ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \
693 if (_chkdiv != 0) { \
694 s4 firstVal, secondVal, result; \
695 firstVal = GET_REGISTER(vsrc1); \
696 secondVal = GET_REGISTER(vsrc2); \
697 if (secondVal == 0) { \
698 EXPORT_PC(); \
699 dvmThrowException("Ljava/lang/ArithmeticException;", \
700 "divide by zero"); \
701 GOTO_exceptionThrown(); \
702 } \
703 if ((u4)firstVal == 0x80000000 && secondVal == -1) { \
704 if (_chkdiv == 1) \
705 result = firstVal; /* division */ \
706 else \
707 result = 0; /* remainder */ \
708 } else { \
709 result = firstVal _op secondVal; \
710 } \
711 SET_REGISTER(vdst, result); \
712 } else { \
713 /* non-div/rem case */ \
714 SET_REGISTER(vdst, \
715 (s4) GET_REGISTER(vsrc1) _op (s4) GET_REGISTER(vsrc2)); \
716 } \
717 } \
718 FINISH(2);
719
720#define HANDLE_OP_SHX_INT(_opcode, _opname, _cast, _op) \
721 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
722 { \
723 u2 srcRegs; \
724 vdst = INST_AA(inst); \
725 srcRegs = FETCH(1); \
726 vsrc1 = srcRegs & 0xff; \
727 vsrc2 = srcRegs >> 8; \
728 ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \
729 SET_REGISTER(vdst, \
730 _cast GET_REGISTER(vsrc1) _op (GET_REGISTER(vsrc2) & 0x1f)); \
731 } \
732 FINISH(2);
733
734#define HANDLE_OP_X_INT_LIT16(_opcode, _opname, _op, _chkdiv) \
735 HANDLE_OPCODE(_opcode /*vA, vB, #+CCCC*/) \
736 vdst = INST_A(inst); \
737 vsrc1 = INST_B(inst); \
738 vsrc2 = FETCH(1); \
739 ILOGV("|%s-int/lit16 v%d,v%d,#+0x%04x", \
740 (_opname), vdst, vsrc1, vsrc2); \
741 if (_chkdiv != 0) { \
742 s4 firstVal, result; \
743 firstVal = GET_REGISTER(vsrc1); \
744 if ((s2) vsrc2 == 0) { \
745 EXPORT_PC(); \
746 dvmThrowException("Ljava/lang/ArithmeticException;", \
747 "divide by zero"); \
748 GOTO_exceptionThrown(); \
749 } \
750 if ((u4)firstVal == 0x80000000 && ((s2) vsrc2) == -1) { \
751 /* won't generate /lit16 instr for this; check anyway */ \
752 if (_chkdiv == 1) \
753 result = firstVal; /* division */ \
754 else \
755 result = 0; /* remainder */ \
756 } else { \
757 result = firstVal _op (s2) vsrc2; \
758 } \
759 SET_REGISTER(vdst, result); \
760 } else { \
761 /* non-div/rem case */ \
762 SET_REGISTER(vdst, GET_REGISTER(vsrc1) _op (s2) vsrc2); \
763 } \
764 FINISH(2);
765
766#define HANDLE_OP_X_INT_LIT8(_opcode, _opname, _op, _chkdiv) \
767 HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \
768 { \
769 u2 litInfo; \
770 vdst = INST_AA(inst); \
771 litInfo = FETCH(1); \
772 vsrc1 = litInfo & 0xff; \
773 vsrc2 = litInfo >> 8; /* constant */ \
774 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \
775 (_opname), vdst, vsrc1, vsrc2); \
776 if (_chkdiv != 0) { \
777 s4 firstVal, result; \
778 firstVal = GET_REGISTER(vsrc1); \
779 if ((s1) vsrc2 == 0) { \
780 EXPORT_PC(); \
781 dvmThrowException("Ljava/lang/ArithmeticException;", \
782 "divide by zero"); \
783 GOTO_exceptionThrown(); \
784 } \
785 if ((u4)firstVal == 0x80000000 && ((s1) vsrc2) == -1) { \
786 if (_chkdiv == 1) \
787 result = firstVal; /* division */ \
788 else \
789 result = 0; /* remainder */ \
790 } else { \
791 result = firstVal _op ((s1) vsrc2); \
792 } \
793 SET_REGISTER(vdst, result); \
794 } else { \
795 SET_REGISTER(vdst, \
796 (s4) GET_REGISTER(vsrc1) _op (s1) vsrc2); \
797 } \
798 } \
799 FINISH(2);
800
801#define HANDLE_OP_SHX_INT_LIT8(_opcode, _opname, _cast, _op) \
802 HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \
803 { \
804 u2 litInfo; \
805 vdst = INST_AA(inst); \
806 litInfo = FETCH(1); \
807 vsrc1 = litInfo & 0xff; \
808 vsrc2 = litInfo >> 8; /* constant */ \
809 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \
810 (_opname), vdst, vsrc1, vsrc2); \
811 SET_REGISTER(vdst, \
812 _cast GET_REGISTER(vsrc1) _op (vsrc2 & 0x1f)); \
813 } \
814 FINISH(2);
815
816#define HANDLE_OP_X_INT_2ADDR(_opcode, _opname, _op, _chkdiv) \
817 HANDLE_OPCODE(_opcode /*vA, vB*/) \
818 vdst = INST_A(inst); \
819 vsrc1 = INST_B(inst); \
820 ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \
821 if (_chkdiv != 0) { \
822 s4 firstVal, secondVal, result; \
823 firstVal = GET_REGISTER(vdst); \
824 secondVal = GET_REGISTER(vsrc1); \
825 if (secondVal == 0) { \
826 EXPORT_PC(); \
827 dvmThrowException("Ljava/lang/ArithmeticException;", \
828 "divide by zero"); \
829 GOTO_exceptionThrown(); \
830 } \
831 if ((u4)firstVal == 0x80000000 && secondVal == -1) { \
832 if (_chkdiv == 1) \
833 result = firstVal; /* division */ \
834 else \
835 result = 0; /* remainder */ \
836 } else { \
837 result = firstVal _op secondVal; \
838 } \
839 SET_REGISTER(vdst, result); \
840 } else { \
841 SET_REGISTER(vdst, \
842 (s4) GET_REGISTER(vdst) _op (s4) GET_REGISTER(vsrc1)); \
843 } \
844 FINISH(1);
845
846#define HANDLE_OP_SHX_INT_2ADDR(_opcode, _opname, _cast, _op) \
847 HANDLE_OPCODE(_opcode /*vA, vB*/) \
848 vdst = INST_A(inst); \
849 vsrc1 = INST_B(inst); \
850 ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \
851 SET_REGISTER(vdst, \
852 _cast GET_REGISTER(vdst) _op (GET_REGISTER(vsrc1) & 0x1f)); \
853 FINISH(1);
854
855#define HANDLE_OP_X_LONG(_opcode, _opname, _op, _chkdiv) \
856 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
857 { \
858 u2 srcRegs; \
859 vdst = INST_AA(inst); \
860 srcRegs = FETCH(1); \
861 vsrc1 = srcRegs & 0xff; \
862 vsrc2 = srcRegs >> 8; \
863 ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
864 if (_chkdiv != 0) { \
865 s8 firstVal, secondVal, result; \
866 firstVal = GET_REGISTER_WIDE(vsrc1); \
867 secondVal = GET_REGISTER_WIDE(vsrc2); \
868 if (secondVal == 0LL) { \
869 EXPORT_PC(); \
870 dvmThrowException("Ljava/lang/ArithmeticException;", \
871 "divide by zero"); \
872 GOTO_exceptionThrown(); \
873 } \
874 if ((u8)firstVal == 0x8000000000000000ULL && \
875 secondVal == -1LL) \
876 { \
877 if (_chkdiv == 1) \
878 result = firstVal; /* division */ \
879 else \
880 result = 0; /* remainder */ \
881 } else { \
882 result = firstVal _op secondVal; \
883 } \
884 SET_REGISTER_WIDE(vdst, result); \
885 } else { \
886 SET_REGISTER_WIDE(vdst, \
887 (s8) GET_REGISTER_WIDE(vsrc1) _op (s8) GET_REGISTER_WIDE(vsrc2)); \
888 } \
889 } \
890 FINISH(2);
891
892#define HANDLE_OP_SHX_LONG(_opcode, _opname, _cast, _op) \
893 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
894 { \
895 u2 srcRegs; \
896 vdst = INST_AA(inst); \
897 srcRegs = FETCH(1); \
898 vsrc1 = srcRegs & 0xff; \
899 vsrc2 = srcRegs >> 8; \
900 ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
901 SET_REGISTER_WIDE(vdst, \
902 _cast GET_REGISTER_WIDE(vsrc1) _op (GET_REGISTER(vsrc2) & 0x3f)); \
903 } \
904 FINISH(2);
905
906#define HANDLE_OP_X_LONG_2ADDR(_opcode, _opname, _op, _chkdiv) \
907 HANDLE_OPCODE(_opcode /*vA, vB*/) \
908 vdst = INST_A(inst); \
909 vsrc1 = INST_B(inst); \
910 ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \
911 if (_chkdiv != 0) { \
912 s8 firstVal, secondVal, result; \
913 firstVal = GET_REGISTER_WIDE(vdst); \
914 secondVal = GET_REGISTER_WIDE(vsrc1); \
915 if (secondVal == 0LL) { \
916 EXPORT_PC(); \
917 dvmThrowException("Ljava/lang/ArithmeticException;", \
918 "divide by zero"); \
919 GOTO_exceptionThrown(); \
920 } \
921 if ((u8)firstVal == 0x8000000000000000ULL && \
922 secondVal == -1LL) \
923 { \
924 if (_chkdiv == 1) \
925 result = firstVal; /* division */ \
926 else \
927 result = 0; /* remainder */ \
928 } else { \
929 result = firstVal _op secondVal; \
930 } \
931 SET_REGISTER_WIDE(vdst, result); \
932 } else { \
933 SET_REGISTER_WIDE(vdst, \
934 (s8) GET_REGISTER_WIDE(vdst) _op (s8)GET_REGISTER_WIDE(vsrc1));\
935 } \
936 FINISH(1);
937
938#define HANDLE_OP_SHX_LONG_2ADDR(_opcode, _opname, _cast, _op) \
939 HANDLE_OPCODE(_opcode /*vA, vB*/) \
940 vdst = INST_A(inst); \
941 vsrc1 = INST_B(inst); \
942 ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \
943 SET_REGISTER_WIDE(vdst, \
944 _cast GET_REGISTER_WIDE(vdst) _op (GET_REGISTER(vsrc1) & 0x3f)); \
945 FINISH(1);
946
947#define HANDLE_OP_X_FLOAT(_opcode, _opname, _op) \
948 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
949 { \
950 u2 srcRegs; \
951 vdst = INST_AA(inst); \
952 srcRegs = FETCH(1); \
953 vsrc1 = srcRegs & 0xff; \
954 vsrc2 = srcRegs >> 8; \
955 ILOGV("|%s-float v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
956 SET_REGISTER_FLOAT(vdst, \
957 GET_REGISTER_FLOAT(vsrc1) _op GET_REGISTER_FLOAT(vsrc2)); \
958 } \
959 FINISH(2);
960
961#define HANDLE_OP_X_DOUBLE(_opcode, _opname, _op) \
962 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
963 { \
964 u2 srcRegs; \
965 vdst = INST_AA(inst); \
966 srcRegs = FETCH(1); \
967 vsrc1 = srcRegs & 0xff; \
968 vsrc2 = srcRegs >> 8; \
969 ILOGV("|%s-double v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
970 SET_REGISTER_DOUBLE(vdst, \
971 GET_REGISTER_DOUBLE(vsrc1) _op GET_REGISTER_DOUBLE(vsrc2)); \
972 } \
973 FINISH(2);
974
975#define HANDLE_OP_X_FLOAT_2ADDR(_opcode, _opname, _op) \
976 HANDLE_OPCODE(_opcode /*vA, vB*/) \
977 vdst = INST_A(inst); \
978 vsrc1 = INST_B(inst); \
979 ILOGV("|%s-float-2addr v%d,v%d", (_opname), vdst, vsrc1); \
980 SET_REGISTER_FLOAT(vdst, \
981 GET_REGISTER_FLOAT(vdst) _op GET_REGISTER_FLOAT(vsrc1)); \
982 FINISH(1);
983
984#define HANDLE_OP_X_DOUBLE_2ADDR(_opcode, _opname, _op) \
985 HANDLE_OPCODE(_opcode /*vA, vB*/) \
986 vdst = INST_A(inst); \
987 vsrc1 = INST_B(inst); \
988 ILOGV("|%s-double-2addr v%d,v%d", (_opname), vdst, vsrc1); \
989 SET_REGISTER_DOUBLE(vdst, \
990 GET_REGISTER_DOUBLE(vdst) _op GET_REGISTER_DOUBLE(vsrc1)); \
991 FINISH(1);
992
993#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \
994 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
995 { \
996 ArrayObject* arrayObj; \
997 u2 arrayInfo; \
998 EXPORT_PC(); \
999 vdst = INST_AA(inst); \
1000 arrayInfo = FETCH(1); \
1001 vsrc1 = arrayInfo & 0xff; /* array ptr */ \
1002 vsrc2 = arrayInfo >> 8; /* index */ \
1003 ILOGV("|aget%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
1004 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \
1005 if (!checkForNull((Object*) arrayObj)) \
1006 GOTO_exceptionThrown(); \
1007 if (GET_REGISTER(vsrc2) >= arrayObj->length) { \
1008 LOGV("Invalid array access: %p %d (len=%d)\n", \
1009 arrayObj, vsrc2, arrayObj->length); \
1010 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
1011 NULL); \
1012 GOTO_exceptionThrown(); \
1013 } \
1014 SET_REGISTER##_regsize(vdst, \
1015 ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]); \
1016 ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \
1017 } \
1018 FINISH(2);
1019
1020#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \
1021 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
1022 { \
1023 ArrayObject* arrayObj; \
1024 u2 arrayInfo; \
1025 EXPORT_PC(); \
1026 vdst = INST_AA(inst); /* AA: source value */ \
1027 arrayInfo = FETCH(1); \
1028 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */ \
1029 vsrc2 = arrayInfo >> 8; /* CC: index */ \
1030 ILOGV("|aput%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
1031 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \
1032 if (!checkForNull((Object*) arrayObj)) \
1033 GOTO_exceptionThrown(); \
1034 if (GET_REGISTER(vsrc2) >= arrayObj->length) { \
1035 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
1036 NULL); \
1037 GOTO_exceptionThrown(); \
1038 } \
1039 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
1040 ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] = \
1041 GET_REGISTER##_regsize(vdst); \
1042 } \
1043 FINISH(2);
1044
1045/*
1046 * It's possible to get a bad value out of a field with sub-32-bit stores
1047 * because the -quick versions always operate on 32 bits. Consider:
1048 * short foo = -1 (sets a 32-bit register to 0xffffffff)
1049 * iput-quick foo (writes all 32 bits to the field)
1050 * short bar = 1 (sets a 32-bit register to 0x00000001)
1051 * iput-short (writes the low 16 bits to the field)
1052 * iget-quick foo (reads all 32 bits from the field, yielding 0xffff0001)
1053 * This can only happen when optimized and non-optimized code has interleaved
1054 * access to the same field. This is unlikely but possible.
1055 *
1056 * The easiest way to fix this is to always read/write 32 bits at a time. On
1057 * a device with a 16-bit data bus this is sub-optimal. (The alternative
1058 * approach is to have sub-int versions of iget-quick, but now we're wasting
1059 * Dalvik instruction space and making it less likely that handler code will
1060 * already be in the CPU i-cache.)
1061 */
1062#define HANDLE_IGET_X(_opcode, _opname, _ftype, _regsize) \
1063 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1064 { \
1065 InstField* ifield; \
1066 Object* obj; \
1067 EXPORT_PC(); \
1068 vdst = INST_A(inst); \
1069 vsrc1 = INST_B(inst); /* object ptr */ \
1070 ref = FETCH(1); /* field ref */ \
1071 ILOGV("|iget%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1072 obj = (Object*) GET_REGISTER(vsrc1); \
1073 if (!checkForNull(obj)) \
1074 GOTO_exceptionThrown(); \
1075 ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \
1076 if (ifield == NULL) { \
1077 ifield = dvmResolveInstField(curMethod->clazz, ref); \
1078 if (ifield == NULL) \
1079 GOTO_exceptionThrown(); \
1080 } \
1081 SET_REGISTER##_regsize(vdst, \
1082 dvmGetField##_ftype(obj, ifield->byteOffset)); \
1083 ILOGV("+ IGET '%s'=0x%08llx", ifield->field.name, \
1084 (u8) GET_REGISTER##_regsize(vdst)); \
1085 UPDATE_FIELD_GET(&ifield->field); \
1086 } \
1087 FINISH(2);
1088
1089#define HANDLE_IGET_X_QUICK(_opcode, _opname, _ftype, _regsize) \
1090 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1091 { \
1092 Object* obj; \
1093 vdst = INST_A(inst); \
1094 vsrc1 = INST_B(inst); /* object ptr */ \
1095 ref = FETCH(1); /* field offset */ \
1096 ILOGV("|iget%s-quick v%d,v%d,field@+%u", \
1097 (_opname), vdst, vsrc1, ref); \
1098 obj = (Object*) GET_REGISTER(vsrc1); \
1099 if (!checkForNullExportPC(obj, fp, pc)) \
1100 GOTO_exceptionThrown(); \
1101 SET_REGISTER##_regsize(vdst, dvmGetField##_ftype(obj, ref)); \
1102 ILOGV("+ IGETQ %d=0x%08llx", ref, \
1103 (u8) GET_REGISTER##_regsize(vdst)); \
1104 } \
1105 FINISH(2);
1106
1107#define HANDLE_IPUT_X(_opcode, _opname, _ftype, _regsize) \
1108 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1109 { \
1110 InstField* ifield; \
1111 Object* obj; \
1112 EXPORT_PC(); \
1113 vdst = INST_A(inst); \
1114 vsrc1 = INST_B(inst); /* object ptr */ \
1115 ref = FETCH(1); /* field ref */ \
1116 ILOGV("|iput%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1117 obj = (Object*) GET_REGISTER(vsrc1); \
1118 if (!checkForNull(obj)) \
1119 GOTO_exceptionThrown(); \
1120 ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \
1121 if (ifield == NULL) { \
1122 ifield = dvmResolveInstField(curMethod->clazz, ref); \
1123 if (ifield == NULL) \
1124 GOTO_exceptionThrown(); \
1125 } \
1126 dvmSetField##_ftype(obj, ifield->byteOffset, \
1127 GET_REGISTER##_regsize(vdst)); \
1128 ILOGV("+ IPUT '%s'=0x%08llx", ifield->field.name, \
1129 (u8) GET_REGISTER##_regsize(vdst)); \
1130 UPDATE_FIELD_PUT(&ifield->field); \
1131 } \
1132 FINISH(2);
1133
1134#define HANDLE_IPUT_X_QUICK(_opcode, _opname, _ftype, _regsize) \
1135 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1136 { \
1137 Object* obj; \
1138 vdst = INST_A(inst); \
1139 vsrc1 = INST_B(inst); /* object ptr */ \
1140 ref = FETCH(1); /* field offset */ \
1141 ILOGV("|iput%s-quick v%d,v%d,field@0x%04x", \
1142 (_opname), vdst, vsrc1, ref); \
1143 obj = (Object*) GET_REGISTER(vsrc1); \
1144 if (!checkForNullExportPC(obj, fp, pc)) \
1145 GOTO_exceptionThrown(); \
1146 dvmSetField##_ftype(obj, ref, GET_REGISTER##_regsize(vdst)); \
1147 ILOGV("+ IPUTQ %d=0x%08llx", ref, \
1148 (u8) GET_REGISTER##_regsize(vdst)); \
1149 } \
1150 FINISH(2);
1151
1152#define HANDLE_SGET_X(_opcode, _opname, _ftype, _regsize) \
1153 HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \
1154 { \
1155 StaticField* sfield; \
1156 vdst = INST_AA(inst); \
1157 ref = FETCH(1); /* field ref */ \
1158 ILOGV("|sget%s v%d,sfield@0x%04x", (_opname), vdst, ref); \
1159 sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1160 if (sfield == NULL) { \
1161 EXPORT_PC(); \
1162 sfield = dvmResolveStaticField(curMethod->clazz, ref); \
1163 if (sfield == NULL) \
1164 GOTO_exceptionThrown(); \
1165 } \
1166 SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield)); \
1167 ILOGV("+ SGET '%s'=0x%08llx", \
1168 sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \
1169 UPDATE_FIELD_GET(&sfield->field); \
1170 } \
1171 FINISH(2);
1172
1173#define HANDLE_SPUT_X(_opcode, _opname, _ftype, _regsize) \
1174 HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \
1175 { \
1176 StaticField* sfield; \
1177 vdst = INST_AA(inst); \
1178 ref = FETCH(1); /* field ref */ \
1179 ILOGV("|sput%s v%d,sfield@0x%04x", (_opname), vdst, ref); \
1180 sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1181 if (sfield == NULL) { \
1182 EXPORT_PC(); \
1183 sfield = dvmResolveStaticField(curMethod->clazz, ref); \
1184 if (sfield == NULL) \
1185 GOTO_exceptionThrown(); \
1186 } \
1187 dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst)); \
1188 ILOGV("+ SPUT '%s'=0x%08llx", \
1189 sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \
1190 UPDATE_FIELD_PUT(&sfield->field); \
1191 } \
1192 FINISH(2);
1193
1194
Andy McFadden53878242010-03-05 07:24:27 -08001195/* File: c/OP_IGET_WIDE_VOLATILE.c */
1196HANDLE_IGET_X(OP_IGET_WIDE_VOLATILE, "-wide-volatile", Long, _WIDE)
1197OP_END
1198
1199/* File: c/OP_IPUT_WIDE_VOLATILE.c */
1200HANDLE_IPUT_X(OP_IPUT_WIDE_VOLATILE, "-wide-volatile", Long, _WIDE)
1201OP_END
1202
1203/* File: c/OP_SGET_WIDE_VOLATILE.c */
1204HANDLE_SGET_X(OP_SGET_WIDE_VOLATILE, "-wide-volatile", Long, _WIDE)
1205OP_END
1206
1207/* File: c/OP_SPUT_WIDE_VOLATILE.c */
1208HANDLE_SPUT_X(OP_SPUT_WIDE_VOLATILE, "-wide-volatile", Long, _WIDE)
1209OP_END
1210
Andy McFaddenb0a05412009-11-19 10:23:41 -08001211/* File: c/OP_EXECUTE_INLINE_RANGE.c */
1212HANDLE_OPCODE(OP_EXECUTE_INLINE_RANGE /*{vCCCC..v(CCCC+AA-1)}, inline@BBBB*/)
1213 {
1214 u4 arg0, arg1, arg2, arg3;
1215 arg0 = arg1 = arg2 = arg3 = 0; /* placate gcc */
1216
1217 EXPORT_PC();
1218
1219 vsrc1 = INST_AA(inst); /* #of args */
1220 ref = FETCH(1); /* inline call "ref" */
1221 vdst = FETCH(2); /* range base */
1222 ILOGV("|execute-inline-range args=%d @%d {regs=v%d-v%d}",
1223 vsrc1, ref, vdst, vdst+vsrc1-1);
1224
1225 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
1226 assert(vsrc1 <= 4);
1227
1228 switch (vsrc1) {
1229 case 4:
1230 arg3 = GET_REGISTER(vdst+3);
1231 /* fall through */
1232 case 3:
1233 arg2 = GET_REGISTER(vdst+2);
1234 /* fall through */
1235 case 2:
1236 arg1 = GET_REGISTER(vdst+1);
1237 /* fall through */
1238 case 1:
1239 arg0 = GET_REGISTER(vdst+0);
1240 /* fall through */
1241 default: // case 0
1242 ;
1243 }
1244
1245#if INTERP_TYPE == INTERP_DBG
1246 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
1247 GOTO_exceptionThrown();
1248#else
1249 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
1250 GOTO_exceptionThrown();
1251#endif
1252 }
1253 FINISH(3);
1254OP_END
1255
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001256/* File: c/gotoTargets.c */
1257/*
1258 * C footer. This has some common code shared by the various targets.
1259 */
1260
1261/*
1262 * Everything from here on is a "goto target". In the basic interpreter
1263 * we jump into these targets and then jump directly to the handler for
1264 * next instruction. Here, these are subroutines that return to the caller.
1265 */
1266
1267GOTO_TARGET(filledNewArray, bool methodCallRange)
1268 {
1269 ClassObject* arrayClass;
1270 ArrayObject* newArray;
1271 u4* contents;
1272 char typeCh;
1273 int i;
1274 u4 arg5;
1275
1276 EXPORT_PC();
1277
1278 ref = FETCH(1); /* class ref */
1279 vdst = FETCH(2); /* first 4 regs -or- range base */
1280
1281 if (methodCallRange) {
1282 vsrc1 = INST_AA(inst); /* #of elements */
1283 arg5 = -1; /* silence compiler warning */
1284 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
1285 vsrc1, ref, vdst, vdst+vsrc1-1);
1286 } else {
1287 arg5 = INST_A(inst);
1288 vsrc1 = INST_B(inst); /* #of elements */
1289 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
1290 vsrc1, ref, vdst, arg5);
1291 }
1292
1293 /*
1294 * Resolve the array class.
1295 */
1296 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
1297 if (arrayClass == NULL) {
1298 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
1299 if (arrayClass == NULL)
1300 GOTO_exceptionThrown();
1301 }
1302 /*
1303 if (!dvmIsArrayClass(arrayClass)) {
1304 dvmThrowException("Ljava/lang/RuntimeError;",
1305 "filled-new-array needs array class");
1306 GOTO_exceptionThrown();
1307 }
1308 */
1309 /* verifier guarantees this is an array class */
1310 assert(dvmIsArrayClass(arrayClass));
1311 assert(dvmIsClassInitialized(arrayClass));
1312
1313 /*
1314 * Create an array of the specified type.
1315 */
1316 LOGVV("+++ filled-new-array type is '%s'\n", arrayClass->descriptor);
1317 typeCh = arrayClass->descriptor[1];
1318 if (typeCh == 'D' || typeCh == 'J') {
1319 /* category 2 primitives not allowed */
1320 dvmThrowException("Ljava/lang/RuntimeError;",
1321 "bad filled array req");
1322 GOTO_exceptionThrown();
1323 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
1324 /* TODO: requires multiple "fill in" loops with different widths */
1325 LOGE("non-int primitives not implemented\n");
1326 dvmThrowException("Ljava/lang/InternalError;",
1327 "filled-new-array not implemented for anything but 'int'");
1328 GOTO_exceptionThrown();
1329 }
1330
1331 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
1332 if (newArray == NULL)
1333 GOTO_exceptionThrown();
1334
1335 /*
1336 * Fill in the elements. It's legal for vsrc1 to be zero.
1337 */
1338 contents = (u4*) newArray->contents;
1339 if (methodCallRange) {
1340 for (i = 0; i < vsrc1; i++)
1341 contents[i] = GET_REGISTER(vdst+i);
1342 } else {
1343 assert(vsrc1 <= 5);
1344 if (vsrc1 == 5) {
1345 contents[4] = GET_REGISTER(arg5);
1346 vsrc1--;
1347 }
1348 for (i = 0; i < vsrc1; i++) {
1349 contents[i] = GET_REGISTER(vdst & 0x0f);
1350 vdst >>= 4;
1351 }
1352 }
1353
1354 retval.l = newArray;
1355 }
1356 FINISH(3);
1357GOTO_TARGET_END
1358
1359
1360GOTO_TARGET(invokeVirtual, bool methodCallRange)
1361 {
1362 Method* baseMethod;
1363 Object* thisPtr;
1364
1365 EXPORT_PC();
1366
1367 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1368 ref = FETCH(1); /* method ref */
1369 vdst = FETCH(2); /* 4 regs -or- first reg */
1370
1371 /*
1372 * The object against which we are executing a method is always
1373 * in the first argument.
1374 */
1375 if (methodCallRange) {
1376 assert(vsrc1 > 0);
1377 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
1378 vsrc1, ref, vdst, vdst+vsrc1-1);
1379 thisPtr = (Object*) GET_REGISTER(vdst);
1380 } else {
1381 assert((vsrc1>>4) > 0);
1382 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
1383 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1384 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
1385 }
1386
1387 if (!checkForNull(thisPtr))
1388 GOTO_exceptionThrown();
1389
1390 /*
1391 * Resolve the method. This is the correct method for the static
1392 * type of the object. We also verify access permissions here.
1393 */
1394 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
1395 if (baseMethod == NULL) {
1396 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
1397 if (baseMethod == NULL) {
1398 ILOGV("+ unknown method or access denied\n");
1399 GOTO_exceptionThrown();
1400 }
1401 }
1402
1403 /*
1404 * Combine the object we found with the vtable offset in the
1405 * method.
1406 */
1407 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
1408 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
1409
1410#if 0
1411 if (dvmIsAbstractMethod(methodToCall)) {
1412 /*
1413 * This can happen if you create two classes, Base and Sub, where
1414 * Sub is a sub-class of Base. Declare a protected abstract
1415 * method foo() in Base, and invoke foo() from a method in Base.
1416 * Base is an "abstract base class" and is never instantiated
1417 * directly. Now, Override foo() in Sub, and use Sub. This
1418 * Works fine unless Sub stops providing an implementation of
1419 * the method.
1420 */
1421 dvmThrowException("Ljava/lang/AbstractMethodError;",
1422 "abstract method not implemented");
1423 GOTO_exceptionThrown();
1424 }
1425#else
1426 assert(!dvmIsAbstractMethod(methodToCall) ||
1427 methodToCall->nativeFunc != NULL);
1428#endif
1429
1430 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s\n",
1431 baseMethod->clazz->descriptor, baseMethod->name,
1432 (u4) baseMethod->methodIndex,
1433 methodToCall->clazz->descriptor, methodToCall->name);
1434 assert(methodToCall != NULL);
1435
1436#if 0
1437 if (vsrc1 != methodToCall->insSize) {
1438 LOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s\n",
1439 baseMethod->clazz->descriptor, baseMethod->name,
1440 (u4) baseMethod->methodIndex,
1441 methodToCall->clazz->descriptor, methodToCall->name);
1442 //dvmDumpClass(baseMethod->clazz);
1443 //dvmDumpClass(methodToCall->clazz);
1444 dvmDumpAllClasses(0);
1445 }
1446#endif
1447
1448 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1449 }
1450GOTO_TARGET_END
1451
1452GOTO_TARGET(invokeSuper, bool methodCallRange)
1453 {
1454 Method* baseMethod;
1455 u2 thisReg;
1456
1457 EXPORT_PC();
1458
1459 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1460 ref = FETCH(1); /* method ref */
1461 vdst = FETCH(2); /* 4 regs -or- first reg */
1462
1463 if (methodCallRange) {
1464 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
1465 vsrc1, ref, vdst, vdst+vsrc1-1);
1466 thisReg = vdst;
1467 } else {
1468 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
1469 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1470 thisReg = vdst & 0x0f;
1471 }
1472 /* impossible in well-formed code, but we must check nevertheless */
1473 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
1474 GOTO_exceptionThrown();
1475
1476 /*
1477 * Resolve the method. This is the correct method for the static
1478 * type of the object. We also verify access permissions here.
1479 * The first arg to dvmResolveMethod() is just the referring class
1480 * (used for class loaders and such), so we don't want to pass
1481 * the superclass into the resolution call.
1482 */
1483 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
1484 if (baseMethod == NULL) {
1485 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
1486 if (baseMethod == NULL) {
1487 ILOGV("+ unknown method or access denied\n");
1488 GOTO_exceptionThrown();
1489 }
1490 }
1491
1492 /*
1493 * Combine the object we found with the vtable offset in the
1494 * method's class.
1495 *
1496 * We're using the current method's class' superclass, not the
1497 * superclass of "this". This is because we might be executing
1498 * in a method inherited from a superclass, and we want to run
1499 * in that class' superclass.
1500 */
1501 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
1502 /*
1503 * Method does not exist in the superclass. Could happen if
1504 * superclass gets updated.
1505 */
1506 dvmThrowException("Ljava/lang/NoSuchMethodError;",
1507 baseMethod->name);
1508 GOTO_exceptionThrown();
1509 }
1510 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
1511#if 0
1512 if (dvmIsAbstractMethod(methodToCall)) {
1513 dvmThrowException("Ljava/lang/AbstractMethodError;",
1514 "abstract method not implemented");
1515 GOTO_exceptionThrown();
1516 }
1517#else
1518 assert(!dvmIsAbstractMethod(methodToCall) ||
1519 methodToCall->nativeFunc != NULL);
1520#endif
1521 LOGVV("+++ base=%s.%s super-virtual=%s.%s\n",
1522 baseMethod->clazz->descriptor, baseMethod->name,
1523 methodToCall->clazz->descriptor, methodToCall->name);
1524 assert(methodToCall != NULL);
1525
1526 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1527 }
1528GOTO_TARGET_END
1529
1530GOTO_TARGET(invokeInterface, bool methodCallRange)
1531 {
1532 Object* thisPtr;
1533 ClassObject* thisClass;
1534
1535 EXPORT_PC();
1536
1537 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1538 ref = FETCH(1); /* method ref */
1539 vdst = FETCH(2); /* 4 regs -or- first reg */
1540
1541 /*
1542 * The object against which we are executing a method is always
1543 * in the first argument.
1544 */
1545 if (methodCallRange) {
1546 assert(vsrc1 > 0);
1547 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
1548 vsrc1, ref, vdst, vdst+vsrc1-1);
1549 thisPtr = (Object*) GET_REGISTER(vdst);
1550 } else {
1551 assert((vsrc1>>4) > 0);
1552 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
1553 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1554 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
1555 }
1556 if (!checkForNull(thisPtr))
1557 GOTO_exceptionThrown();
1558
1559 thisClass = thisPtr->clazz;
1560
1561 /*
1562 * Given a class and a method index, find the Method* with the
1563 * actual code we want to execute.
1564 */
1565 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
1566 methodClassDex);
1567 if (methodToCall == NULL) {
1568 assert(dvmCheckException(self));
1569 GOTO_exceptionThrown();
1570 }
1571
1572 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1573 }
1574GOTO_TARGET_END
1575
1576GOTO_TARGET(invokeDirect, bool methodCallRange)
1577 {
1578 u2 thisReg;
1579
1580 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1581 ref = FETCH(1); /* method ref */
1582 vdst = FETCH(2); /* 4 regs -or- first reg */
1583
1584 EXPORT_PC();
1585
1586 if (methodCallRange) {
1587 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
1588 vsrc1, ref, vdst, vdst+vsrc1-1);
1589 thisReg = vdst;
1590 } else {
1591 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
1592 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1593 thisReg = vdst & 0x0f;
1594 }
1595 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
1596 GOTO_exceptionThrown();
1597
1598 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
1599 if (methodToCall == NULL) {
1600 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
1601 METHOD_DIRECT);
1602 if (methodToCall == NULL) {
1603 ILOGV("+ unknown direct method\n"); // should be impossible
1604 GOTO_exceptionThrown();
1605 }
1606 }
1607 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1608 }
1609GOTO_TARGET_END
1610
1611GOTO_TARGET(invokeStatic, bool methodCallRange)
1612 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1613 ref = FETCH(1); /* method ref */
1614 vdst = FETCH(2); /* 4 regs -or- first reg */
1615
1616 EXPORT_PC();
1617
1618 if (methodCallRange)
1619 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
1620 vsrc1, ref, vdst, vdst+vsrc1-1);
1621 else
1622 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
1623 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1624
1625 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
1626 if (methodToCall == NULL) {
1627 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
1628 if (methodToCall == NULL) {
1629 ILOGV("+ unknown method\n");
1630 GOTO_exceptionThrown();
1631 }
1632 }
1633 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1634GOTO_TARGET_END
1635
1636GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
1637 {
1638 Object* thisPtr;
1639
1640 EXPORT_PC();
1641
1642 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1643 ref = FETCH(1); /* vtable index */
1644 vdst = FETCH(2); /* 4 regs -or- first reg */
1645
1646 /*
1647 * The object against which we are executing a method is always
1648 * in the first argument.
1649 */
1650 if (methodCallRange) {
1651 assert(vsrc1 > 0);
1652 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
1653 vsrc1, ref, vdst, vdst+vsrc1-1);
1654 thisPtr = (Object*) GET_REGISTER(vdst);
1655 } else {
1656 assert((vsrc1>>4) > 0);
1657 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
1658 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1659 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
1660 }
1661
1662 if (!checkForNull(thisPtr))
1663 GOTO_exceptionThrown();
1664
1665 /*
1666 * Combine the object we found with the vtable offset in the
1667 * method.
1668 */
1669 assert(ref < thisPtr->clazz->vtableCount);
1670 methodToCall = thisPtr->clazz->vtable[ref];
1671
1672#if 0
1673 if (dvmIsAbstractMethod(methodToCall)) {
1674 dvmThrowException("Ljava/lang/AbstractMethodError;",
1675 "abstract method not implemented");
1676 GOTO_exceptionThrown();
1677 }
1678#else
1679 assert(!dvmIsAbstractMethod(methodToCall) ||
1680 methodToCall->nativeFunc != NULL);
1681#endif
1682
1683 LOGVV("+++ virtual[%d]=%s.%s\n",
1684 ref, methodToCall->clazz->descriptor, methodToCall->name);
1685 assert(methodToCall != NULL);
1686
1687 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1688 }
1689GOTO_TARGET_END
1690
1691GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
1692 {
1693 u2 thisReg;
1694
1695 EXPORT_PC();
1696
1697 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1698 ref = FETCH(1); /* vtable index */
1699 vdst = FETCH(2); /* 4 regs -or- first reg */
1700
1701 if (methodCallRange) {
1702 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
1703 vsrc1, ref, vdst, vdst+vsrc1-1);
1704 thisReg = vdst;
1705 } else {
1706 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
1707 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1708 thisReg = vdst & 0x0f;
1709 }
1710 /* impossible in well-formed code, but we must check nevertheless */
1711 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
1712 GOTO_exceptionThrown();
1713
1714#if 0 /* impossible in optimized + verified code */
1715 if (ref >= curMethod->clazz->super->vtableCount) {
1716 dvmThrowException("Ljava/lang/NoSuchMethodError;", NULL);
1717 GOTO_exceptionThrown();
1718 }
1719#else
1720 assert(ref < curMethod->clazz->super->vtableCount);
1721#endif
1722
1723 /*
1724 * Combine the object we found with the vtable offset in the
1725 * method's class.
1726 *
1727 * We're using the current method's class' superclass, not the
1728 * superclass of "this". This is because we might be executing
1729 * in a method inherited from a superclass, and we want to run
1730 * in the method's class' superclass.
1731 */
1732 methodToCall = curMethod->clazz->super->vtable[ref];
1733
1734#if 0
1735 if (dvmIsAbstractMethod(methodToCall)) {
1736 dvmThrowException("Ljava/lang/AbstractMethodError;",
1737 "abstract method not implemented");
1738 GOTO_exceptionThrown();
1739 }
1740#else
1741 assert(!dvmIsAbstractMethod(methodToCall) ||
1742 methodToCall->nativeFunc != NULL);
1743#endif
1744 LOGVV("+++ super-virtual[%d]=%s.%s\n",
1745 ref, methodToCall->clazz->descriptor, methodToCall->name);
1746 assert(methodToCall != NULL);
1747
1748 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1749 }
1750GOTO_TARGET_END
1751
1752
1753
1754 /*
1755 * General handling for return-void, return, and return-wide. Put the
1756 * return value in "retval" before jumping here.
1757 */
1758GOTO_TARGET(returnFromMethod)
1759 {
1760 StackSaveArea* saveArea;
1761
1762 /*
1763 * We must do this BEFORE we pop the previous stack frame off, so
1764 * that the GC can see the return value (if any) in the local vars.
1765 *
1766 * Since this is now an interpreter switch point, we must do it before
1767 * we do anything at all.
1768 */
1769 PERIODIC_CHECKS(kInterpEntryReturn, 0);
1770
1771 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
1772 retval.j, curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04001773 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001774 //DUMP_REGS(curMethod, fp);
1775
1776 saveArea = SAVEAREA_FROM_FP(fp);
1777
1778#ifdef EASY_GDB
1779 debugSaveArea = saveArea;
1780#endif
1781#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
1782 TRACE_METHOD_EXIT(self, curMethod);
1783#endif
1784
1785 /* back up to previous frame and see if we hit a break */
1786 fp = saveArea->prevFrame;
1787 assert(fp != NULL);
1788 if (dvmIsBreakFrame(fp)) {
1789 /* bail without popping the method frame from stack */
1790 LOGVV("+++ returned into break frame\n");
Bill Buzbeed7269912009-11-10 14:31:32 -08001791#if defined(WITH_JIT)
1792 /* Let the Jit know the return is terminating normally */
1793 CHECK_JIT();
1794#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001795 GOTO_bail();
1796 }
1797
1798 /* update thread FP, and reset local variables */
1799 self->curFrame = fp;
1800 curMethod = SAVEAREA_FROM_FP(fp)->method;
1801 //methodClass = curMethod->clazz;
1802 methodClassDex = curMethod->clazz->pDvmDex;
1803 pc = saveArea->savedPc;
1804 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04001805 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001806
1807 /* use FINISH on the caller's invoke instruction */
1808 //u2 invokeInstr = INST_INST(FETCH(0));
1809 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
1810 invokeInstr <= OP_INVOKE_INTERFACE*/)
1811 {
1812 FINISH(3);
1813 } else {
1814 //LOGE("Unknown invoke instr %02x at %d\n",
1815 // invokeInstr, (int) (pc - curMethod->insns));
1816 assert(false);
1817 }
1818 }
1819GOTO_TARGET_END
1820
1821
1822 /*
1823 * Jump here when the code throws an exception.
1824 *
1825 * By the time we get here, the Throwable has been created and the stack
1826 * trace has been saved off.
1827 */
1828GOTO_TARGET(exceptionThrown)
1829 {
1830 Object* exception;
1831 int catchRelPc;
1832
1833 /*
1834 * Since this is now an interpreter switch point, we must do it before
1835 * we do anything at all.
1836 */
1837 PERIODIC_CHECKS(kInterpEntryThrow, 0);
1838
Ben Cheng79d173c2009-09-29 16:12:51 -07001839#if defined(WITH_JIT)
1840 // Something threw during trace selection - abort the current trace
Bill Buzbee5540f6e2010-02-08 10:41:32 -08001841 ABORT_JIT_TSELECT();
Ben Cheng79d173c2009-09-29 16:12:51 -07001842#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001843 /*
1844 * We save off the exception and clear the exception status. While
1845 * processing the exception we might need to load some Throwable
1846 * classes, and we don't want class loader exceptions to get
1847 * confused with this one.
1848 */
1849 assert(dvmCheckException(self));
1850 exception = dvmGetException(self);
1851 dvmAddTrackedAlloc(exception, self);
1852 dvmClearException(self);
1853
1854 LOGV("Handling exception %s at %s:%d\n",
1855 exception->clazz->descriptor, curMethod->name,
1856 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
1857
1858#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
1859 /*
1860 * Tell the debugger about it.
1861 *
1862 * TODO: if the exception was thrown by interpreted code, control
1863 * fell through native, and then back to us, we will report the
1864 * exception at the point of the throw and again here. We can avoid
1865 * this by not reporting exceptions when we jump here directly from
1866 * the native call code above, but then we won't report exceptions
1867 * that were thrown *from* the JNI code (as opposed to *through* it).
1868 *
1869 * The correct solution is probably to ignore from-native exceptions
1870 * here, and have the JNI exception code do the reporting to the
1871 * debugger.
1872 */
1873 if (gDvm.debuggerActive) {
1874 void* catchFrame;
1875 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
1876 exception, true, &catchFrame);
1877 dvmDbgPostException(fp, pc - curMethod->insns, catchFrame,
1878 catchRelPc, exception);
1879 }
1880#endif
1881
1882 /*
1883 * We need to unroll to the catch block or the nearest "break"
1884 * frame.
1885 *
1886 * A break frame could indicate that we have reached an intermediate
1887 * native call, or have gone off the top of the stack and the thread
1888 * needs to exit. Either way, we return from here, leaving the
1889 * exception raised.
1890 *
1891 * If we do find a catch block, we want to transfer execution to
1892 * that point.
Andy McFadden4fbba1f2010-02-03 07:21:14 -08001893 *
1894 * Note this can cause an exception while resolving classes in
1895 * the "catch" blocks.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001896 */
1897 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
1898 exception, false, (void*)&fp);
1899
1900 /*
1901 * Restore the stack bounds after an overflow. This isn't going to
1902 * be correct in all circumstances, e.g. if JNI code devours the
1903 * exception this won't happen until some other exception gets
1904 * thrown. If the code keeps pushing the stack bounds we'll end
1905 * up aborting the VM.
1906 *
1907 * Note we want to do this *after* the call to dvmFindCatchBlock,
1908 * because that may need extra stack space to resolve exception
1909 * classes (e.g. through a class loader).
Andy McFadden4fbba1f2010-02-03 07:21:14 -08001910 *
1911 * It's possible for the stack overflow handling to cause an
1912 * exception (specifically, class resolution in a "catch" block
1913 * during the call above), so we could see the thread's overflow
1914 * flag raised but actually be running in a "nested" interpreter
1915 * frame. We don't allow doubled-up StackOverflowErrors, so
1916 * we can check for this by just looking at the exception type
1917 * in the cleanup function. Also, we won't unroll past the SOE
1918 * point because the more-recent exception will hit a break frame
1919 * as it unrolls to here.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001920 */
1921 if (self->stackOverflowed)
Andy McFadden4fbba1f2010-02-03 07:21:14 -08001922 dvmCleanupStackOverflow(self, exception);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001923
1924 if (catchRelPc < 0) {
1925 /* falling through to JNI code or off the bottom of the stack */
1926#if DVM_SHOW_EXCEPTION >= 2
1927 LOGD("Exception %s from %s:%d not caught locally\n",
1928 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
1929 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
1930#endif
1931 dvmSetException(self, exception);
1932 dvmReleaseTrackedAlloc(exception, self);
1933 GOTO_bail();
1934 }
1935
1936#if DVM_SHOW_EXCEPTION >= 3
1937 {
1938 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
1939 LOGD("Exception %s thrown from %s:%d to %s:%d\n",
1940 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
1941 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
1942 dvmGetMethodSourceFile(catchMethod),
1943 dvmLineNumFromPC(catchMethod, catchRelPc));
1944 }
1945#endif
1946
1947 /*
1948 * Adjust local variables to match self->curFrame and the
1949 * updated PC.
1950 */
1951 //fp = (u4*) self->curFrame;
1952 curMethod = SAVEAREA_FROM_FP(fp)->method;
1953 //methodClass = curMethod->clazz;
1954 methodClassDex = curMethod->clazz->pDvmDex;
1955 pc = curMethod->insns + catchRelPc;
1956 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04001957 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001958 DUMP_REGS(curMethod, fp, false); // show all regs
1959
1960 /*
1961 * Restore the exception if the handler wants it.
1962 *
1963 * The Dalvik spec mandates that, if an exception handler wants to
1964 * do something with the exception, the first instruction executed
1965 * must be "move-exception". We can pass the exception along
1966 * through the thread struct, and let the move-exception instruction
1967 * clear it for us.
1968 *
1969 * If the handler doesn't call move-exception, we don't want to
1970 * finish here with an exception still pending.
1971 */
1972 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
1973 dvmSetException(self, exception);
1974
1975 dvmReleaseTrackedAlloc(exception, self);
1976 FINISH(0);
1977 }
1978GOTO_TARGET_END
1979
1980
1981 /*
1982 * General handling for invoke-{virtual,super,direct,static,interface},
1983 * including "quick" variants.
1984 *
1985 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
1986 * depending on whether this is a "/range" instruction.
1987 *
1988 * For a range call:
1989 * "vsrc1" holds the argument count (8 bits)
1990 * "vdst" holds the first argument in the range
1991 * For a non-range call:
1992 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
1993 * "vdst" holds four 4-bit register indices
1994 *
1995 * The caller must EXPORT_PC before jumping here, because any method
1996 * call can throw a stack overflow exception.
1997 */
1998GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
1999 u2 count, u2 regs)
2000 {
2001 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
2002
2003 //printf("range=%d call=%p count=%d regs=0x%04x\n",
2004 // methodCallRange, methodToCall, count, regs);
2005 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04002006 // methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002007
2008 u4* outs;
2009 int i;
2010
2011 /*
2012 * Copy args. This may corrupt vsrc1/vdst.
2013 */
2014 if (methodCallRange) {
2015 // could use memcpy or a "Duff's device"; most functions have
2016 // so few args it won't matter much
2017 assert(vsrc1 <= curMethod->outsSize);
2018 assert(vsrc1 == methodToCall->insSize);
2019 outs = OUTS_FROM_FP(fp, vsrc1);
2020 for (i = 0; i < vsrc1; i++)
2021 outs[i] = GET_REGISTER(vdst+i);
2022 } else {
2023 u4 count = vsrc1 >> 4;
2024
2025 assert(count <= curMethod->outsSize);
2026 assert(count == methodToCall->insSize);
2027 assert(count <= 5);
2028
2029 outs = OUTS_FROM_FP(fp, count);
2030#if 0
2031 if (count == 5) {
2032 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
2033 count--;
2034 }
2035 for (i = 0; i < (int) count; i++) {
2036 outs[i] = GET_REGISTER(vdst & 0x0f);
2037 vdst >>= 4;
2038 }
2039#else
2040 // This version executes fewer instructions but is larger
2041 // overall. Seems to be a teensy bit faster.
2042 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
2043 switch (count) {
2044 case 5:
2045 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
2046 case 4:
2047 outs[3] = GET_REGISTER(vdst >> 12);
2048 case 3:
2049 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
2050 case 2:
2051 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
2052 case 1:
2053 outs[0] = GET_REGISTER(vdst & 0x0f);
2054 default:
2055 ;
2056 }
2057#endif
2058 }
2059 }
2060
2061 /*
2062 * (This was originally a "goto" target; I've kept it separate from the
2063 * stuff above in case we want to refactor things again.)
2064 *
2065 * At this point, we have the arguments stored in the "outs" area of
2066 * the current method's stack frame, and the method to call in
2067 * "methodToCall". Push a new stack frame.
2068 */
2069 {
2070 StackSaveArea* newSaveArea;
2071 u4* newFp;
2072
2073 ILOGV("> %s%s.%s %s",
2074 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
2075 methodToCall->clazz->descriptor, methodToCall->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04002076 methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002077
2078 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
2079 newSaveArea = SAVEAREA_FROM_FP(newFp);
2080
2081 /* verify that we have enough space */
2082 if (true) {
2083 u1* bottom;
2084 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
2085 if (bottom < self->interpStackEnd) {
2086 /* stack overflow */
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07002087 LOGV("Stack overflow on method call (start=%p end=%p newBot=%p(%d) size=%d '%s')\n",
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002088 self->interpStackStart, self->interpStackEnd, bottom,
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07002089 (u1*) fp - bottom, self->interpStackSize,
2090 methodToCall->name);
2091 dvmHandleStackOverflow(self, methodToCall);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002092 assert(dvmCheckException(self));
2093 GOTO_exceptionThrown();
2094 }
2095 //LOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p\n",
2096 // fp, newFp, newSaveArea, bottom);
2097 }
2098
2099#ifdef LOG_INSTR
2100 if (methodToCall->registersSize > methodToCall->insSize) {
2101 /*
2102 * This makes valgrind quiet when we print registers that
2103 * haven't been initialized. Turn it off when the debug
2104 * messages are disabled -- we want valgrind to report any
2105 * used-before-initialized issues.
2106 */
2107 memset(newFp, 0xcc,
2108 (methodToCall->registersSize - methodToCall->insSize) * 4);
2109 }
2110#endif
2111
2112#ifdef EASY_GDB
2113 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
2114#endif
2115 newSaveArea->prevFrame = fp;
2116 newSaveArea->savedPc = pc;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002117#if defined(WITH_JIT)
2118 newSaveArea->returnAddr = 0;
2119#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002120 newSaveArea->method = methodToCall;
2121
2122 if (!dvmIsNativeMethod(methodToCall)) {
2123 /*
2124 * "Call" interpreted code. Reposition the PC, update the
2125 * frame pointer and other local state, and continue.
2126 */
2127 curMethod = methodToCall;
2128 methodClassDex = curMethod->clazz->pDvmDex;
2129 pc = methodToCall->insns;
2130 fp = self->curFrame = newFp;
2131#ifdef EASY_GDB
2132 debugSaveArea = SAVEAREA_FROM_FP(newFp);
2133#endif
2134#if INTERP_TYPE == INTERP_DBG
2135 debugIsMethodEntry = true; // profiling, debugging
2136#endif
2137 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04002138 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002139 DUMP_REGS(curMethod, fp, true); // show input args
2140 FINISH(0); // jump to method start
2141 } else {
2142 /* set this up for JNI locals, even if not a JNI native */
Andy McFaddend5ab7262009-08-25 07:19:34 -07002143#ifdef USE_INDIRECT_REF
2144 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.segmentState.all;
2145#else
2146 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.nextEntry;
2147#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002148
2149 self->curFrame = newFp;
2150
2151 DUMP_REGS(methodToCall, newFp, true); // show input args
2152
2153#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
2154 if (gDvm.debuggerActive) {
2155 dvmDbgPostLocationEvent(methodToCall, -1,
2156 dvmGetThisPtr(curMethod, fp), DBG_METHOD_ENTRY);
2157 }
2158#endif
2159#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
2160 TRACE_METHOD_ENTER(self, methodToCall);
2161#endif
2162
2163 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04002164 methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002165
Bill Buzbeed7269912009-11-10 14:31:32 -08002166#if defined(WITH_JIT)
2167 /* Allow the Jit to end any pending trace building */
2168 CHECK_JIT();
2169#endif
2170
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002171 /*
2172 * Jump through native call bridge. Because we leave no
2173 * space for locals on native calls, "newFp" points directly
2174 * to the method arguments.
2175 */
2176 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
2177
2178#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
2179 if (gDvm.debuggerActive) {
2180 dvmDbgPostLocationEvent(methodToCall, -1,
2181 dvmGetThisPtr(curMethod, fp), DBG_METHOD_EXIT);
2182 }
2183#endif
2184#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
2185 TRACE_METHOD_EXIT(self, methodToCall);
2186#endif
2187
2188 /* pop frame off */
2189 dvmPopJniLocals(self, newSaveArea);
2190 self->curFrame = fp;
2191
2192 /*
2193 * If the native code threw an exception, or interpreted code
2194 * invoked by the native call threw one and nobody has cleared
2195 * it, jump to our local exception handling.
2196 */
2197 if (dvmCheckException(self)) {
2198 LOGV("Exception thrown by/below native code\n");
2199 GOTO_exceptionThrown();
2200 }
2201
2202 ILOGD("> retval=0x%llx (leaving native)", retval.j);
2203 ILOGD("> (return from native %s.%s to %s.%s %s)",
2204 methodToCall->clazz->descriptor, methodToCall->name,
2205 curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04002206 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002207
2208 //u2 invokeInstr = INST_INST(FETCH(0));
2209 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
2210 invokeInstr <= OP_INVOKE_INTERFACE*/)
2211 {
2212 FINISH(3);
2213 } else {
2214 //LOGE("Unknown invoke instr %02x at %d\n",
2215 // invokeInstr, (int) (pc - curMethod->insns));
2216 assert(false);
2217 }
2218 }
2219 }
2220 assert(false); // should not get here
2221GOTO_TARGET_END
2222
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002223/* File: cstubs/enddefs.c */
2224
2225/* undefine "magic" name remapping */
2226#undef retval
2227#undef pc
2228#undef fp
2229#undef curMethod
2230#undef methodClassDex
2231#undef self
2232#undef debugTrackedRefStart
2233