blob: 635a87318273df8f0c69970b4d21276cedd614fb [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 'allstubs'.
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
29
30/*
31 * Configuration defines. These affect the C implementations, i.e. the
32 * portable interpreter(s) and C stubs.
33 *
34 * Some defines are controlled by the Makefile, e.g.:
35 * WITH_PROFILER
36 * WITH_DEBUGGER
37 * WITH_INSTR_CHECKS
38 * WITH_TRACKREF_CHECKS
39 * EASY_GDB
40 * NDEBUG
41 *
42 * If THREADED_INTERP is not defined, we use a classic "while true / switch"
43 * interpreter. If it is defined, then the tail end of each instruction
44 * handler fetches the next instruction and jumps directly to the handler.
45 * This increases the size of the "Std" interpreter by about 10%, but
46 * provides a speedup of about the same magnitude.
47 *
48 * There's a "hybrid" approach that uses a goto table instead of a switch
49 * statement, avoiding the "is the opcode in range" tests required for switch.
50 * The performance is close to the threaded version, and without the 10%
51 * size increase, but the benchmark results are off enough that it's not
52 * worth adding as a third option.
53 */
54#define THREADED_INTERP /* threaded vs. while-loop interpreter */
55
56#ifdef WITH_INSTR_CHECKS /* instruction-level paranoia */
57# define CHECK_BRANCH_OFFSETS
58# define CHECK_REGISTER_INDICES
59#endif
60
61/*
62 * ARM EABI requires 64-bit alignment for access to 64-bit data types. We
63 * can't just use pointers to copy 64-bit values out of our interpreted
64 * register set, because gcc will generate ldrd/strd.
65 *
66 * The __UNION version copies data in and out of a union. The __MEMCPY
67 * version uses a memcpy() call to do the transfer; gcc is smart enough to
68 * not actually call memcpy(). The __UNION version is very bad on ARM;
69 * it only uses one more instruction than __MEMCPY, but for some reason
70 * gcc thinks it needs separate storage for every instance of the union.
71 * On top of that, it feels the need to zero them out at the start of the
72 * method. Net result is we zero out ~700 bytes of stack space at the top
73 * of the interpreter using ARM STM instructions.
74 */
75#if defined(__ARM_EABI__)
76//# define NO_UNALIGN_64__UNION
77# define NO_UNALIGN_64__MEMCPY
78#endif
79
80//#define LOG_INSTR /* verbose debugging */
81/* set and adjust ANDROID_LOG_TAGS='*:i jdwp:i dalvikvm:i dalvikvmi:i' */
82
83/*
84 * Keep a tally of accesses to fields. Currently only works if full DEX
85 * optimization is disabled.
86 */
87#ifdef PROFILE_FIELD_ACCESS
88# define UPDATE_FIELD_GET(_field) { (_field)->gets++; }
89# define UPDATE_FIELD_PUT(_field) { (_field)->puts++; }
90#else
91# define UPDATE_FIELD_GET(_field) ((void)0)
92# define UPDATE_FIELD_PUT(_field) ((void)0)
93#endif
94
95/*
96 * Adjust the program counter. "_offset" is a signed int, in 16-bit units.
97 *
98 * Assumes the existence of "const u2* pc" and "const u2* curMethod->insns".
99 *
100 * We don't advance the program counter until we finish an instruction or
101 * branch, because we do want to have to unroll the PC if there's an
102 * exception.
103 */
104#ifdef CHECK_BRANCH_OFFSETS
105# define ADJUST_PC(_offset) do { \
106 int myoff = _offset; /* deref only once */ \
107 if (pc + myoff < curMethod->insns || \
108 pc + myoff >= curMethod->insns + dvmGetMethodInsnsSize(curMethod)) \
109 { \
110 char* desc; \
111 desc = dexProtoCopyMethodDescriptor(&curMethod->prototype); \
112 LOGE("Invalid branch %d at 0x%04x in %s.%s %s\n", \
113 myoff, (int) (pc - curMethod->insns), \
114 curMethod->clazz->descriptor, curMethod->name, desc); \
115 free(desc); \
116 dvmAbort(); \
117 } \
118 pc += myoff; \
119 } while (false)
120#else
121# define ADJUST_PC(_offset) (pc += _offset)
122#endif
123
124/*
125 * If enabled, log instructions as we execute them.
126 */
127#ifdef LOG_INSTR
128# define ILOGD(...) ILOG(LOG_DEBUG, __VA_ARGS__)
129# define ILOGV(...) ILOG(LOG_VERBOSE, __VA_ARGS__)
130# define ILOG(_level, ...) do { \
131 char debugStrBuf[128]; \
132 snprintf(debugStrBuf, sizeof(debugStrBuf), __VA_ARGS__); \
133 if (curMethod != NULL) \
134 LOG(_level, LOG_TAG"i", "%-2d|%04x%s\n", \
135 self->threadId, (int)(pc - curMethod->insns), debugStrBuf); \
136 else \
137 LOG(_level, LOG_TAG"i", "%-2d|####%s\n", \
138 self->threadId, debugStrBuf); \
139 } while(false)
140void dvmDumpRegs(const Method* method, const u4* framePtr, bool inOnly);
141# define DUMP_REGS(_meth, _frame, _inOnly) dvmDumpRegs(_meth, _frame, _inOnly)
142static const char kSpacing[] = " ";
143#else
144# define ILOGD(...) ((void)0)
145# define ILOGV(...) ((void)0)
146# define DUMP_REGS(_meth, _frame, _inOnly) ((void)0)
147#endif
148
149/* get a long from an array of u4 */
150static inline s8 getLongFromArray(const u4* ptr, int idx)
151{
152#if defined(NO_UNALIGN_64__UNION)
153 union { s8 ll; u4 parts[2]; } conv;
154
155 ptr += idx;
156 conv.parts[0] = ptr[0];
157 conv.parts[1] = ptr[1];
158 return conv.ll;
159#elif defined(NO_UNALIGN_64__MEMCPY)
160 s8 val;
161 memcpy(&val, &ptr[idx], 8);
162 return val;
163#else
164 return *((s8*) &ptr[idx]);
165#endif
166}
167
168/* store a long into an array of u4 */
169static inline void putLongToArray(u4* ptr, int idx, s8 val)
170{
171#if defined(NO_UNALIGN_64__UNION)
172 union { s8 ll; u4 parts[2]; } conv;
173
174 ptr += idx;
175 conv.ll = val;
176 ptr[0] = conv.parts[0];
177 ptr[1] = conv.parts[1];
178#elif defined(NO_UNALIGN_64__MEMCPY)
179 memcpy(&ptr[idx], &val, 8);
180#else
181 *((s8*) &ptr[idx]) = val;
182#endif
183}
184
185/* get a double from an array of u4 */
186static inline double getDoubleFromArray(const u4* ptr, int idx)
187{
188#if defined(NO_UNALIGN_64__UNION)
189 union { double d; u4 parts[2]; } conv;
190
191 ptr += idx;
192 conv.parts[0] = ptr[0];
193 conv.parts[1] = ptr[1];
194 return conv.d;
195#elif defined(NO_UNALIGN_64__MEMCPY)
196 double dval;
197 memcpy(&dval, &ptr[idx], 8);
198 return dval;
199#else
200 return *((double*) &ptr[idx]);
201#endif
202}
203
204/* store a double into an array of u4 */
205static inline void putDoubleToArray(u4* ptr, int idx, double dval)
206{
207#if defined(NO_UNALIGN_64__UNION)
208 union { double d; u4 parts[2]; } conv;
209
210 ptr += idx;
211 conv.d = dval;
212 ptr[0] = conv.parts[0];
213 ptr[1] = conv.parts[1];
214#elif defined(NO_UNALIGN_64__MEMCPY)
215 memcpy(&ptr[idx], &dval, 8);
216#else
217 *((double*) &ptr[idx]) = dval;
218#endif
219}
220
221/*
222 * If enabled, validate the register number on every access. Otherwise,
223 * just do an array access.
224 *
225 * Assumes the existence of "u4* fp".
226 *
227 * "_idx" may be referenced more than once.
228 */
229#ifdef CHECK_REGISTER_INDICES
230# define GET_REGISTER(_idx) \
231 ( (_idx) < curMethod->registersSize ? \
232 (fp[(_idx)]) : (assert(!"bad reg"),1969) )
233# define SET_REGISTER(_idx, _val) \
234 ( (_idx) < curMethod->registersSize ? \
235 (fp[(_idx)] = (u4)(_val)) : (assert(!"bad reg"),1969) )
236# define GET_REGISTER_AS_OBJECT(_idx) ((Object *)GET_REGISTER(_idx))
237# define SET_REGISTER_AS_OBJECT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
238# define GET_REGISTER_INT(_idx) ((s4) GET_REGISTER(_idx))
239# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
240# define GET_REGISTER_WIDE(_idx) \
241 ( (_idx) < curMethod->registersSize-1 ? \
242 getLongFromArray(fp, (_idx)) : (assert(!"bad reg"),1969) )
243# define SET_REGISTER_WIDE(_idx, _val) \
244 ( (_idx) < curMethod->registersSize-1 ? \
245 putLongToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969) )
246# define GET_REGISTER_FLOAT(_idx) \
247 ( (_idx) < curMethod->registersSize ? \
248 (*((float*) &fp[(_idx)])) : (assert(!"bad reg"),1969.0f) )
249# define SET_REGISTER_FLOAT(_idx, _val) \
250 ( (_idx) < curMethod->registersSize ? \
251 (*((float*) &fp[(_idx)]) = (_val)) : (assert(!"bad reg"),1969.0f) )
252# define GET_REGISTER_DOUBLE(_idx) \
253 ( (_idx) < curMethod->registersSize-1 ? \
254 getDoubleFromArray(fp, (_idx)) : (assert(!"bad reg"),1969.0) )
255# define SET_REGISTER_DOUBLE(_idx, _val) \
256 ( (_idx) < curMethod->registersSize-1 ? \
257 putDoubleToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969.0) )
258#else
259# define GET_REGISTER(_idx) (fp[(_idx)])
260# define SET_REGISTER(_idx, _val) (fp[(_idx)] = (_val))
261# define GET_REGISTER_AS_OBJECT(_idx) ((Object*) fp[(_idx)])
262# define SET_REGISTER_AS_OBJECT(_idx, _val) (fp[(_idx)] = (u4)(_val))
263# define GET_REGISTER_INT(_idx) ((s4)GET_REGISTER(_idx))
264# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
265# define GET_REGISTER_WIDE(_idx) getLongFromArray(fp, (_idx))
266# define SET_REGISTER_WIDE(_idx, _val) putLongToArray(fp, (_idx), (_val))
267# define GET_REGISTER_FLOAT(_idx) (*((float*) &fp[(_idx)]))
268# define SET_REGISTER_FLOAT(_idx, _val) (*((float*) &fp[(_idx)]) = (_val))
269# define GET_REGISTER_DOUBLE(_idx) getDoubleFromArray(fp, (_idx))
270# define SET_REGISTER_DOUBLE(_idx, _val) putDoubleToArray(fp, (_idx), (_val))
271#endif
272
273/*
274 * Get 16 bits from the specified offset of the program counter. We always
275 * want to load 16 bits at a time from the instruction stream -- it's more
276 * efficient than 8 and won't have the alignment problems that 32 might.
277 *
278 * Assumes existence of "const u2* pc".
279 */
280#define FETCH(_offset) (pc[(_offset)])
281
282/*
283 * Extract instruction byte from 16-bit fetch (_inst is a u2).
284 */
285#define INST_INST(_inst) ((_inst) & 0xff)
286
287/*
288 * Extract the "vA, vB" 4-bit registers from the instruction word (_inst is u2).
289 */
290#define INST_A(_inst) (((_inst) >> 8) & 0x0f)
291#define INST_B(_inst) ((_inst) >> 12)
292
293/*
294 * Get the 8-bit "vAA" 8-bit register index from the instruction word.
295 * (_inst is u2)
296 */
297#define INST_AA(_inst) ((_inst) >> 8)
298
299/*
300 * The current PC must be available to Throwable constructors, e.g.
301 * those created by dvmThrowException(), so that the exception stack
302 * trace can be generated correctly. If we don't do this, the offset
303 * within the current method won't be shown correctly. See the notes
304 * in Exception.c.
305 *
306 * Assumes existence of "u4* fp" and "const u2* pc".
307 */
308#define EXPORT_PC() (SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc)
309
310/*
311 * Determine if we need to switch to a different interpreter. "_current"
312 * is either INTERP_STD or INTERP_DBG. It should be fixed for a given
313 * interpreter generation file, which should remove the outer conditional
314 * from the following.
315 *
316 * If we're building without debug and profiling support, we never switch.
317 */
318#if defined(WITH_PROFILER) || defined(WITH_DEBUGGER)
319# define NEED_INTERP_SWITCH(_current) ( \
320 (_current == INTERP_STD) ? \
321 dvmDebuggerOrProfilerActive() : !dvmDebuggerOrProfilerActive() )
322#else
323# define NEED_INTERP_SWITCH(_current) (false)
324#endif
325
326/*
327 * Look up an interface on a class using the cache.
328 */
329INLINE Method* dvmFindInterfaceMethodInCache(ClassObject* thisClass,
330 u4 methodIdx, const Method* method, DvmDex* methodClassDex)
331{
332#define ATOMIC_CACHE_CALC \
333 dvmInterpFindInterfaceMethod(thisClass, methodIdx, method, methodClassDex)
334
335 return (Method*) ATOMIC_CACHE_LOOKUP(methodClassDex->pInterfaceCache,
336 DEX_INTERFACE_CACHE_SIZE, thisClass, methodIdx);
337
338#undef ATOMIC_CACHE_CALC
339}
340
341/*
342 * Check to see if "obj" is NULL. If so, throw an exception. Assumes the
343 * pc has already been exported to the stack.
344 *
345 * Perform additional checks on debug builds.
346 *
347 * Use this to check for NULL when the instruction handler calls into
348 * something that could throw an exception (so we have already called
349 * EXPORT_PC at the top).
350 */
351static inline bool checkForNull(Object* obj)
352{
353 if (obj == NULL) {
354 dvmThrowException("Ljava/lang/NullPointerException;", NULL);
355 return false;
356 }
357#ifdef WITH_EXTRA_OBJECT_VALIDATION
358 if (!dvmIsValidObject(obj)) {
359 LOGE("Invalid object %p\n", obj);
360 dvmAbort();
361 }
362#endif
363#ifndef NDEBUG
364 if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
365 /* probable heap corruption */
366 LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj);
367 dvmAbort();
368 }
369#endif
370 return true;
371}
372
373/*
374 * Check to see if "obj" is NULL. If so, export the PC into the stack
375 * frame and throw an exception.
376 *
377 * Perform additional checks on debug builds.
378 *
379 * Use this to check for NULL when the instruction handler doesn't do
380 * anything else that can throw an exception.
381 */
382static inline bool checkForNullExportPC(Object* obj, u4* fp, const u2* pc)
383{
384 if (obj == NULL) {
385 EXPORT_PC();
386 dvmThrowException("Ljava/lang/NullPointerException;", NULL);
387 return false;
388 }
389#ifdef WITH_EXTRA_OBJECT_VALIDATION
390 if (!dvmIsValidObject(obj)) {
391 LOGE("Invalid object %p\n", obj);
392 dvmAbort();
393 }
394#endif
395#ifndef NDEBUG
396 if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
397 /* probable heap corruption */
398 LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj);
399 dvmAbort();
400 }
401#endif
402 return true;
403}
404
405
406/* File: cstubs/stubdefs.c */
407/* this is a standard (no debug support) interpreter */
408#define INTERP_TYPE INTERP_STD
409#define CHECK_DEBUG_AND_PROF() ((void)0)
410# define CHECK_TRACKED_REFS() ((void)0)
411
412/*
413 * In the C mterp stubs, "goto" is a function call followed immediately
414 * by a return.
415 */
416
417#define GOTO_TARGET_DECL(_target, ...) \
418 void dvmMterp_##_target(MterpGlue* glue, ## __VA_ARGS__);
419
420#define GOTO_TARGET(_target, ...) \
421 void dvmMterp_##_target(MterpGlue* glue, ## __VA_ARGS__) { \
422 u2 ref, vsrc1, vsrc2, vdst; \
423 u2 inst = FETCH(0); \
424 const Method* methodToCall; \
425 StackSaveArea* debugSaveArea;
426
427#define GOTO_TARGET_END }
428
429/*
430 * Redefine what used to be local variable accesses into MterpGlue struct
431 * references. (These are undefined down in "footer.c".)
432 */
433#define retval glue->retval
434#define pc glue->pc
435#define fp glue->fp
436#define curMethod glue->method
437#define methodClassDex glue->methodClassDex
438#define self glue->self
439#define debugTrackedRefStart glue->debugTrackedRefStart
440
441/* ugh */
442#define STUB_HACK(x) x
443
444
445/*
446 * Opcode handler framing macros. Here, each opcode is a separate function
447 * that takes a "glue" argument and returns void. We can't declare
448 * these "static" because they may be called from an assembly stub.
449 */
450#define HANDLE_OPCODE(_op) \
451 void dvmMterp_##_op(MterpGlue* glue) { \
452 u2 ref, vsrc1, vsrc2, vdst; \
453 u2 inst = FETCH(0);
454
455#define OP_END }
456
457/*
458 * Like the "portable" FINISH, but don't reload "inst", and return to caller
459 * when done.
460 */
461#define FINISH(_offset) { \
462 ADJUST_PC(_offset); \
463 CHECK_DEBUG_AND_PROF(); \
464 CHECK_TRACKED_REFS(); \
465 return; \
466 }
467
468
469/*
470 * The "goto label" statements turn into function calls followed by
471 * return statements. Some of the functions take arguments, which in the
472 * portable interpreter are handled by assigning values to globals.
473 */
474
475#define GOTO_exceptionThrown() \
476 do { \
477 dvmMterp_exceptionThrown(glue); \
478 return; \
479 } while(false)
480
481#define GOTO_returnFromMethod() \
482 do { \
483 dvmMterp_returnFromMethod(glue); \
484 return; \
485 } while(false)
486
487#define GOTO_invoke(_target, _methodCallRange) \
488 do { \
489 dvmMterp_##_target(glue, _methodCallRange); \
490 return; \
491 } while(false)
492
493#define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst) \
494 do { \
495 dvmMterp_invokeMethod(glue, _methodCallRange, _methodToCall, \
496 _vsrc1, _vdst); \
497 return; \
498 } while(false)
499
500/*
501 * As a special case, "goto bail" turns into a longjmp. Use "bail_switch"
502 * if we need to switch to the other interpreter upon our return.
503 */
504#define GOTO_bail() \
505 dvmMterpStdBail(glue, false);
506#define GOTO_bail_switch() \
507 dvmMterpStdBail(glue, true);
508
509/*
510 * Periodically check for thread suspension.
511 *
512 * While we're at it, see if a debugger has attached or the profiler has
513 * started. If so, switch to a different "goto" table.
514 */
515#define PERIODIC_CHECKS(_entryPoint, _pcadj) { \
516 dvmCheckSuspendQuick(self); \
517 if (NEED_INTERP_SWITCH(INTERP_TYPE)) { \
518 ADJUST_PC(_pcadj); \
519 glue->entryPoint = _entryPoint; \
520 LOGVV("threadid=%d: switch to STD ep=%d adj=%d\n", \
521 glue->self->threadId, (_entryPoint), (_pcadj)); \
522 GOTO_bail_switch(); \
523 } \
524 }
525
526
527/* File: c/opcommon.c */
528/* forward declarations of goto targets */
529GOTO_TARGET_DECL(filledNewArray, bool methodCallRange);
530GOTO_TARGET_DECL(invokeVirtual, bool methodCallRange);
531GOTO_TARGET_DECL(invokeSuper, bool methodCallRange);
532GOTO_TARGET_DECL(invokeInterface, bool methodCallRange);
533GOTO_TARGET_DECL(invokeDirect, bool methodCallRange);
534GOTO_TARGET_DECL(invokeStatic, bool methodCallRange);
535GOTO_TARGET_DECL(invokeVirtualQuick, bool methodCallRange);
536GOTO_TARGET_DECL(invokeSuperQuick, bool methodCallRange);
537GOTO_TARGET_DECL(invokeMethod, bool methodCallRange, const Method* methodToCall,
538 u2 count, u2 regs);
539GOTO_TARGET_DECL(returnFromMethod);
540GOTO_TARGET_DECL(exceptionThrown);
541
542/*
543 * ===========================================================================
544 *
545 * What follows are opcode definitions shared between multiple opcodes with
546 * minor substitutions handled by the C pre-processor. These should probably
547 * use the mterp substitution mechanism instead, with the code here moved
548 * into common fragment files (like the asm "binop.S"), although it's hard
549 * to give up the C preprocessor in favor of the much simpler text subst.
550 *
551 * ===========================================================================
552 */
553
554#define HANDLE_NUMCONV(_opcode, _opname, _fromtype, _totype) \
555 HANDLE_OPCODE(_opcode /*vA, vB*/) \
556 vdst = INST_A(inst); \
557 vsrc1 = INST_B(inst); \
558 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
559 SET_REGISTER##_totype(vdst, \
560 GET_REGISTER##_fromtype(vsrc1)); \
561 FINISH(1);
562
563#define HANDLE_FLOAT_TO_INT(_opcode, _opname, _fromvtype, _fromrtype, \
564 _tovtype, _tortype) \
565 HANDLE_OPCODE(_opcode /*vA, vB*/) \
566 { \
567 /* spec defines specific handling for +/- inf and NaN values */ \
568 _fromvtype val; \
569 _tovtype intMin, intMax, result; \
570 vdst = INST_A(inst); \
571 vsrc1 = INST_B(inst); \
572 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
573 val = GET_REGISTER##_fromrtype(vsrc1); \
574 intMin = (_tovtype) 1 << (sizeof(_tovtype) * 8 -1); \
575 intMax = ~intMin; \
576 result = (_tovtype) val; \
577 if (val >= intMax) /* +inf */ \
578 result = intMax; \
579 else if (val <= intMin) /* -inf */ \
580 result = intMin; \
581 else if (val != val) /* NaN */ \
582 result = 0; \
583 else \
584 result = (_tovtype) val; \
585 SET_REGISTER##_tortype(vdst, result); \
586 } \
587 FINISH(1);
588
589#define HANDLE_INT_TO_SMALL(_opcode, _opname, _type) \
590 HANDLE_OPCODE(_opcode /*vA, vB*/) \
591 vdst = INST_A(inst); \
592 vsrc1 = INST_B(inst); \
593 ILOGV("|int-to-%s v%d,v%d", (_opname), vdst, vsrc1); \
594 SET_REGISTER(vdst, (_type) GET_REGISTER(vsrc1)); \
595 FINISH(1);
596
597/* NOTE: the comparison result is always a signed 4-byte integer */
598#define HANDLE_OP_CMPX(_opcode, _opname, _varType, _type, _nanVal) \
599 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
600 { \
601 int result; \
602 u2 regs; \
603 _varType val1, val2; \
604 vdst = INST_AA(inst); \
605 regs = FETCH(1); \
606 vsrc1 = regs & 0xff; \
607 vsrc2 = regs >> 8; \
608 ILOGV("|cmp%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
609 val1 = GET_REGISTER##_type(vsrc1); \
610 val2 = GET_REGISTER##_type(vsrc2); \
611 if (val1 == val2) \
612 result = 0; \
613 else if (val1 < val2) \
614 result = -1; \
615 else if (val1 > val2) \
616 result = 1; \
617 else \
618 result = (_nanVal); \
619 ILOGV("+ result=%d\n", result); \
620 SET_REGISTER(vdst, result); \
621 } \
622 FINISH(2);
623
624#define HANDLE_OP_IF_XX(_opcode, _opname, _cmp) \
625 HANDLE_OPCODE(_opcode /*vA, vB, +CCCC*/) \
626 vsrc1 = INST_A(inst); \
627 vsrc2 = INST_B(inst); \
628 if ((s4) GET_REGISTER(vsrc1) _cmp (s4) GET_REGISTER(vsrc2)) { \
629 int branchOffset = (s2)FETCH(1); /* sign-extended */ \
630 ILOGV("|if-%s v%d,v%d,+0x%04x", (_opname), vsrc1, vsrc2, \
631 branchOffset); \
632 ILOGV("> branch taken"); \
633 if (branchOffset < 0) \
634 PERIODIC_CHECKS(kInterpEntryInstr, branchOffset); \
635 FINISH(branchOffset); \
636 } else { \
637 ILOGV("|if-%s v%d,v%d,-", (_opname), vsrc1, vsrc2); \
638 FINISH(2); \
639 }
640
641#define HANDLE_OP_IF_XXZ(_opcode, _opname, _cmp) \
642 HANDLE_OPCODE(_opcode /*vAA, +BBBB*/) \
643 vsrc1 = INST_AA(inst); \
644 if ((s4) GET_REGISTER(vsrc1) _cmp 0) { \
645 int branchOffset = (s2)FETCH(1); /* sign-extended */ \
646 ILOGV("|if-%s v%d,+0x%04x", (_opname), vsrc1, branchOffset); \
647 ILOGV("> branch taken"); \
648 if (branchOffset < 0) \
649 PERIODIC_CHECKS(kInterpEntryInstr, branchOffset); \
650 FINISH(branchOffset); \
651 } else { \
652 ILOGV("|if-%s v%d,-", (_opname), vsrc1); \
653 FINISH(2); \
654 }
655
656#define HANDLE_UNOP(_opcode, _opname, _pfx, _sfx, _type) \
657 HANDLE_OPCODE(_opcode /*vA, vB*/) \
658 vdst = INST_A(inst); \
659 vsrc1 = INST_B(inst); \
660 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
661 SET_REGISTER##_type(vdst, _pfx GET_REGISTER##_type(vsrc1) _sfx); \
662 FINISH(1);
663
664#define HANDLE_OP_X_INT(_opcode, _opname, _op, _chkdiv) \
665 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
666 { \
667 u2 srcRegs; \
668 vdst = INST_AA(inst); \
669 srcRegs = FETCH(1); \
670 vsrc1 = srcRegs & 0xff; \
671 vsrc2 = srcRegs >> 8; \
672 ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \
673 if (_chkdiv != 0) { \
674 s4 firstVal, secondVal, result; \
675 firstVal = GET_REGISTER(vsrc1); \
676 secondVal = GET_REGISTER(vsrc2); \
677 if (secondVal == 0) { \
678 EXPORT_PC(); \
679 dvmThrowException("Ljava/lang/ArithmeticException;", \
680 "divide by zero"); \
681 GOTO_exceptionThrown(); \
682 } \
683 if ((u4)firstVal == 0x80000000 && secondVal == -1) { \
684 if (_chkdiv == 1) \
685 result = firstVal; /* division */ \
686 else \
687 result = 0; /* remainder */ \
688 } else { \
689 result = firstVal _op secondVal; \
690 } \
691 SET_REGISTER(vdst, result); \
692 } else { \
693 /* non-div/rem case */ \
694 SET_REGISTER(vdst, \
695 (s4) GET_REGISTER(vsrc1) _op (s4) GET_REGISTER(vsrc2)); \
696 } \
697 } \
698 FINISH(2);
699
700#define HANDLE_OP_SHX_INT(_opcode, _opname, _cast, _op) \
701 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
702 { \
703 u2 srcRegs; \
704 vdst = INST_AA(inst); \
705 srcRegs = FETCH(1); \
706 vsrc1 = srcRegs & 0xff; \
707 vsrc2 = srcRegs >> 8; \
708 ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \
709 SET_REGISTER(vdst, \
710 _cast GET_REGISTER(vsrc1) _op (GET_REGISTER(vsrc2) & 0x1f)); \
711 } \
712 FINISH(2);
713
714#define HANDLE_OP_X_INT_LIT16(_opcode, _opname, _op, _chkdiv) \
715 HANDLE_OPCODE(_opcode /*vA, vB, #+CCCC*/) \
716 vdst = INST_A(inst); \
717 vsrc1 = INST_B(inst); \
718 vsrc2 = FETCH(1); \
719 ILOGV("|%s-int/lit16 v%d,v%d,#+0x%04x", \
720 (_opname), vdst, vsrc1, vsrc2); \
721 if (_chkdiv != 0) { \
722 s4 firstVal, result; \
723 firstVal = GET_REGISTER(vsrc1); \
724 if ((s2) vsrc2 == 0) { \
725 EXPORT_PC(); \
726 dvmThrowException("Ljava/lang/ArithmeticException;", \
727 "divide by zero"); \
728 GOTO_exceptionThrown(); \
729 } \
730 if ((u4)firstVal == 0x80000000 && ((s2) vsrc2) == -1) { \
731 /* won't generate /lit16 instr for this; check anyway */ \
732 if (_chkdiv == 1) \
733 result = firstVal; /* division */ \
734 else \
735 result = 0; /* remainder */ \
736 } else { \
737 result = firstVal _op (s2) vsrc2; \
738 } \
739 SET_REGISTER(vdst, result); \
740 } else { \
741 /* non-div/rem case */ \
742 SET_REGISTER(vdst, GET_REGISTER(vsrc1) _op (s2) vsrc2); \
743 } \
744 FINISH(2);
745
746#define HANDLE_OP_X_INT_LIT8(_opcode, _opname, _op, _chkdiv) \
747 HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \
748 { \
749 u2 litInfo; \
750 vdst = INST_AA(inst); \
751 litInfo = FETCH(1); \
752 vsrc1 = litInfo & 0xff; \
753 vsrc2 = litInfo >> 8; /* constant */ \
754 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \
755 (_opname), vdst, vsrc1, vsrc2); \
756 if (_chkdiv != 0) { \
757 s4 firstVal, result; \
758 firstVal = GET_REGISTER(vsrc1); \
759 if ((s1) vsrc2 == 0) { \
760 EXPORT_PC(); \
761 dvmThrowException("Ljava/lang/ArithmeticException;", \
762 "divide by zero"); \
763 GOTO_exceptionThrown(); \
764 } \
765 if ((u4)firstVal == 0x80000000 && ((s1) vsrc2) == -1) { \
766 if (_chkdiv == 1) \
767 result = firstVal; /* division */ \
768 else \
769 result = 0; /* remainder */ \
770 } else { \
771 result = firstVal _op ((s1) vsrc2); \
772 } \
773 SET_REGISTER(vdst, result); \
774 } else { \
775 SET_REGISTER(vdst, \
776 (s4) GET_REGISTER(vsrc1) _op (s1) vsrc2); \
777 } \
778 } \
779 FINISH(2);
780
781#define HANDLE_OP_SHX_INT_LIT8(_opcode, _opname, _cast, _op) \
782 HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \
783 { \
784 u2 litInfo; \
785 vdst = INST_AA(inst); \
786 litInfo = FETCH(1); \
787 vsrc1 = litInfo & 0xff; \
788 vsrc2 = litInfo >> 8; /* constant */ \
789 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \
790 (_opname), vdst, vsrc1, vsrc2); \
791 SET_REGISTER(vdst, \
792 _cast GET_REGISTER(vsrc1) _op (vsrc2 & 0x1f)); \
793 } \
794 FINISH(2);
795
796#define HANDLE_OP_X_INT_2ADDR(_opcode, _opname, _op, _chkdiv) \
797 HANDLE_OPCODE(_opcode /*vA, vB*/) \
798 vdst = INST_A(inst); \
799 vsrc1 = INST_B(inst); \
800 ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \
801 if (_chkdiv != 0) { \
802 s4 firstVal, secondVal, result; \
803 firstVal = GET_REGISTER(vdst); \
804 secondVal = GET_REGISTER(vsrc1); \
805 if (secondVal == 0) { \
806 EXPORT_PC(); \
807 dvmThrowException("Ljava/lang/ArithmeticException;", \
808 "divide by zero"); \
809 GOTO_exceptionThrown(); \
810 } \
811 if ((u4)firstVal == 0x80000000 && secondVal == -1) { \
812 if (_chkdiv == 1) \
813 result = firstVal; /* division */ \
814 else \
815 result = 0; /* remainder */ \
816 } else { \
817 result = firstVal _op secondVal; \
818 } \
819 SET_REGISTER(vdst, result); \
820 } else { \
821 SET_REGISTER(vdst, \
822 (s4) GET_REGISTER(vdst) _op (s4) GET_REGISTER(vsrc1)); \
823 } \
824 FINISH(1);
825
826#define HANDLE_OP_SHX_INT_2ADDR(_opcode, _opname, _cast, _op) \
827 HANDLE_OPCODE(_opcode /*vA, vB*/) \
828 vdst = INST_A(inst); \
829 vsrc1 = INST_B(inst); \
830 ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \
831 SET_REGISTER(vdst, \
832 _cast GET_REGISTER(vdst) _op (GET_REGISTER(vsrc1) & 0x1f)); \
833 FINISH(1);
834
835#define HANDLE_OP_X_LONG(_opcode, _opname, _op, _chkdiv) \
836 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
837 { \
838 u2 srcRegs; \
839 vdst = INST_AA(inst); \
840 srcRegs = FETCH(1); \
841 vsrc1 = srcRegs & 0xff; \
842 vsrc2 = srcRegs >> 8; \
843 ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
844 if (_chkdiv != 0) { \
845 s8 firstVal, secondVal, result; \
846 firstVal = GET_REGISTER_WIDE(vsrc1); \
847 secondVal = GET_REGISTER_WIDE(vsrc2); \
848 if (secondVal == 0LL) { \
849 EXPORT_PC(); \
850 dvmThrowException("Ljava/lang/ArithmeticException;", \
851 "divide by zero"); \
852 GOTO_exceptionThrown(); \
853 } \
854 if ((u8)firstVal == 0x8000000000000000ULL && \
855 secondVal == -1LL) \
856 { \
857 if (_chkdiv == 1) \
858 result = firstVal; /* division */ \
859 else \
860 result = 0; /* remainder */ \
861 } else { \
862 result = firstVal _op secondVal; \
863 } \
864 SET_REGISTER_WIDE(vdst, result); \
865 } else { \
866 SET_REGISTER_WIDE(vdst, \
867 (s8) GET_REGISTER_WIDE(vsrc1) _op (s8) GET_REGISTER_WIDE(vsrc2)); \
868 } \
869 } \
870 FINISH(2);
871
872#define HANDLE_OP_SHX_LONG(_opcode, _opname, _cast, _op) \
873 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
874 { \
875 u2 srcRegs; \
876 vdst = INST_AA(inst); \
877 srcRegs = FETCH(1); \
878 vsrc1 = srcRegs & 0xff; \
879 vsrc2 = srcRegs >> 8; \
880 ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
881 SET_REGISTER_WIDE(vdst, \
882 _cast GET_REGISTER_WIDE(vsrc1) _op (GET_REGISTER(vsrc2) & 0x3f)); \
883 } \
884 FINISH(2);
885
886#define HANDLE_OP_X_LONG_2ADDR(_opcode, _opname, _op, _chkdiv) \
887 HANDLE_OPCODE(_opcode /*vA, vB*/) \
888 vdst = INST_A(inst); \
889 vsrc1 = INST_B(inst); \
890 ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \
891 if (_chkdiv != 0) { \
892 s8 firstVal, secondVal, result; \
893 firstVal = GET_REGISTER_WIDE(vdst); \
894 secondVal = GET_REGISTER_WIDE(vsrc1); \
895 if (secondVal == 0LL) { \
896 EXPORT_PC(); \
897 dvmThrowException("Ljava/lang/ArithmeticException;", \
898 "divide by zero"); \
899 GOTO_exceptionThrown(); \
900 } \
901 if ((u8)firstVal == 0x8000000000000000ULL && \
902 secondVal == -1LL) \
903 { \
904 if (_chkdiv == 1) \
905 result = firstVal; /* division */ \
906 else \
907 result = 0; /* remainder */ \
908 } else { \
909 result = firstVal _op secondVal; \
910 } \
911 SET_REGISTER_WIDE(vdst, result); \
912 } else { \
913 SET_REGISTER_WIDE(vdst, \
914 (s8) GET_REGISTER_WIDE(vdst) _op (s8)GET_REGISTER_WIDE(vsrc1));\
915 } \
916 FINISH(1);
917
918#define HANDLE_OP_SHX_LONG_2ADDR(_opcode, _opname, _cast, _op) \
919 HANDLE_OPCODE(_opcode /*vA, vB*/) \
920 vdst = INST_A(inst); \
921 vsrc1 = INST_B(inst); \
922 ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \
923 SET_REGISTER_WIDE(vdst, \
924 _cast GET_REGISTER_WIDE(vdst) _op (GET_REGISTER(vsrc1) & 0x3f)); \
925 FINISH(1);
926
927#define HANDLE_OP_X_FLOAT(_opcode, _opname, _op) \
928 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
929 { \
930 u2 srcRegs; \
931 vdst = INST_AA(inst); \
932 srcRegs = FETCH(1); \
933 vsrc1 = srcRegs & 0xff; \
934 vsrc2 = srcRegs >> 8; \
935 ILOGV("|%s-float v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
936 SET_REGISTER_FLOAT(vdst, \
937 GET_REGISTER_FLOAT(vsrc1) _op GET_REGISTER_FLOAT(vsrc2)); \
938 } \
939 FINISH(2);
940
941#define HANDLE_OP_X_DOUBLE(_opcode, _opname, _op) \
942 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
943 { \
944 u2 srcRegs; \
945 vdst = INST_AA(inst); \
946 srcRegs = FETCH(1); \
947 vsrc1 = srcRegs & 0xff; \
948 vsrc2 = srcRegs >> 8; \
949 ILOGV("|%s-double v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
950 SET_REGISTER_DOUBLE(vdst, \
951 GET_REGISTER_DOUBLE(vsrc1) _op GET_REGISTER_DOUBLE(vsrc2)); \
952 } \
953 FINISH(2);
954
955#define HANDLE_OP_X_FLOAT_2ADDR(_opcode, _opname, _op) \
956 HANDLE_OPCODE(_opcode /*vA, vB*/) \
957 vdst = INST_A(inst); \
958 vsrc1 = INST_B(inst); \
959 ILOGV("|%s-float-2addr v%d,v%d", (_opname), vdst, vsrc1); \
960 SET_REGISTER_FLOAT(vdst, \
961 GET_REGISTER_FLOAT(vdst) _op GET_REGISTER_FLOAT(vsrc1)); \
962 FINISH(1);
963
964#define HANDLE_OP_X_DOUBLE_2ADDR(_opcode, _opname, _op) \
965 HANDLE_OPCODE(_opcode /*vA, vB*/) \
966 vdst = INST_A(inst); \
967 vsrc1 = INST_B(inst); \
968 ILOGV("|%s-double-2addr v%d,v%d", (_opname), vdst, vsrc1); \
969 SET_REGISTER_DOUBLE(vdst, \
970 GET_REGISTER_DOUBLE(vdst) _op GET_REGISTER_DOUBLE(vsrc1)); \
971 FINISH(1);
972
973#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \
974 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
975 { \
976 ArrayObject* arrayObj; \
977 u2 arrayInfo; \
978 EXPORT_PC(); \
979 vdst = INST_AA(inst); \
980 arrayInfo = FETCH(1); \
981 vsrc1 = arrayInfo & 0xff; /* array ptr */ \
982 vsrc2 = arrayInfo >> 8; /* index */ \
983 ILOGV("|aget%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
984 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \
985 if (!checkForNull((Object*) arrayObj)) \
986 GOTO_exceptionThrown(); \
987 if (GET_REGISTER(vsrc2) >= arrayObj->length) { \
988 LOGV("Invalid array access: %p %d (len=%d)\n", \
989 arrayObj, vsrc2, arrayObj->length); \
990 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
991 NULL); \
992 GOTO_exceptionThrown(); \
993 } \
994 SET_REGISTER##_regsize(vdst, \
995 ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]); \
996 ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \
997 } \
998 FINISH(2);
999
1000#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \
1001 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
1002 { \
1003 ArrayObject* arrayObj; \
1004 u2 arrayInfo; \
1005 EXPORT_PC(); \
1006 vdst = INST_AA(inst); /* AA: source value */ \
1007 arrayInfo = FETCH(1); \
1008 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */ \
1009 vsrc2 = arrayInfo >> 8; /* CC: index */ \
1010 ILOGV("|aput%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
1011 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \
1012 if (!checkForNull((Object*) arrayObj)) \
1013 GOTO_exceptionThrown(); \
1014 if (GET_REGISTER(vsrc2) >= arrayObj->length) { \
1015 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
1016 NULL); \
1017 GOTO_exceptionThrown(); \
1018 } \
1019 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
1020 ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] = \
1021 GET_REGISTER##_regsize(vdst); \
1022 } \
1023 FINISH(2);
1024
1025/*
1026 * It's possible to get a bad value out of a field with sub-32-bit stores
1027 * because the -quick versions always operate on 32 bits. Consider:
1028 * short foo = -1 (sets a 32-bit register to 0xffffffff)
1029 * iput-quick foo (writes all 32 bits to the field)
1030 * short bar = 1 (sets a 32-bit register to 0x00000001)
1031 * iput-short (writes the low 16 bits to the field)
1032 * iget-quick foo (reads all 32 bits from the field, yielding 0xffff0001)
1033 * This can only happen when optimized and non-optimized code has interleaved
1034 * access to the same field. This is unlikely but possible.
1035 *
1036 * The easiest way to fix this is to always read/write 32 bits at a time. On
1037 * a device with a 16-bit data bus this is sub-optimal. (The alternative
1038 * approach is to have sub-int versions of iget-quick, but now we're wasting
1039 * Dalvik instruction space and making it less likely that handler code will
1040 * already be in the CPU i-cache.)
1041 */
1042#define HANDLE_IGET_X(_opcode, _opname, _ftype, _regsize) \
1043 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1044 { \
1045 InstField* ifield; \
1046 Object* obj; \
1047 EXPORT_PC(); \
1048 vdst = INST_A(inst); \
1049 vsrc1 = INST_B(inst); /* object ptr */ \
1050 ref = FETCH(1); /* field ref */ \
1051 ILOGV("|iget%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1052 obj = (Object*) GET_REGISTER(vsrc1); \
1053 if (!checkForNull(obj)) \
1054 GOTO_exceptionThrown(); \
1055 ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \
1056 if (ifield == NULL) { \
1057 ifield = dvmResolveInstField(curMethod->clazz, ref); \
1058 if (ifield == NULL) \
1059 GOTO_exceptionThrown(); \
1060 } \
1061 SET_REGISTER##_regsize(vdst, \
1062 dvmGetField##_ftype(obj, ifield->byteOffset)); \
1063 ILOGV("+ IGET '%s'=0x%08llx", ifield->field.name, \
1064 (u8) GET_REGISTER##_regsize(vdst)); \
1065 UPDATE_FIELD_GET(&ifield->field); \
1066 } \
1067 FINISH(2);
1068
1069#define HANDLE_IGET_X_QUICK(_opcode, _opname, _ftype, _regsize) \
1070 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1071 { \
1072 Object* obj; \
1073 vdst = INST_A(inst); \
1074 vsrc1 = INST_B(inst); /* object ptr */ \
1075 ref = FETCH(1); /* field offset */ \
1076 ILOGV("|iget%s-quick v%d,v%d,field@+%u", \
1077 (_opname), vdst, vsrc1, ref); \
1078 obj = (Object*) GET_REGISTER(vsrc1); \
1079 if (!checkForNullExportPC(obj, fp, pc)) \
1080 GOTO_exceptionThrown(); \
1081 SET_REGISTER##_regsize(vdst, dvmGetField##_ftype(obj, ref)); \
1082 ILOGV("+ IGETQ %d=0x%08llx", ref, \
1083 (u8) GET_REGISTER##_regsize(vdst)); \
1084 } \
1085 FINISH(2);
1086
1087#define HANDLE_IPUT_X(_opcode, _opname, _ftype, _regsize) \
1088 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1089 { \
1090 InstField* ifield; \
1091 Object* obj; \
1092 EXPORT_PC(); \
1093 vdst = INST_A(inst); \
1094 vsrc1 = INST_B(inst); /* object ptr */ \
1095 ref = FETCH(1); /* field ref */ \
1096 ILOGV("|iput%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1097 obj = (Object*) GET_REGISTER(vsrc1); \
1098 if (!checkForNull(obj)) \
1099 GOTO_exceptionThrown(); \
1100 ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \
1101 if (ifield == NULL) { \
1102 ifield = dvmResolveInstField(curMethod->clazz, ref); \
1103 if (ifield == NULL) \
1104 GOTO_exceptionThrown(); \
1105 } \
1106 dvmSetField##_ftype(obj, ifield->byteOffset, \
1107 GET_REGISTER##_regsize(vdst)); \
1108 ILOGV("+ IPUT '%s'=0x%08llx", ifield->field.name, \
1109 (u8) GET_REGISTER##_regsize(vdst)); \
1110 UPDATE_FIELD_PUT(&ifield->field); \
1111 } \
1112 FINISH(2);
1113
1114#define HANDLE_IPUT_X_QUICK(_opcode, _opname, _ftype, _regsize) \
1115 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1116 { \
1117 Object* obj; \
1118 vdst = INST_A(inst); \
1119 vsrc1 = INST_B(inst); /* object ptr */ \
1120 ref = FETCH(1); /* field offset */ \
1121 ILOGV("|iput%s-quick v%d,v%d,field@0x%04x", \
1122 (_opname), vdst, vsrc1, ref); \
1123 obj = (Object*) GET_REGISTER(vsrc1); \
1124 if (!checkForNullExportPC(obj, fp, pc)) \
1125 GOTO_exceptionThrown(); \
1126 dvmSetField##_ftype(obj, ref, GET_REGISTER##_regsize(vdst)); \
1127 ILOGV("+ IPUTQ %d=0x%08llx", ref, \
1128 (u8) GET_REGISTER##_regsize(vdst)); \
1129 } \
1130 FINISH(2);
1131
1132#define HANDLE_SGET_X(_opcode, _opname, _ftype, _regsize) \
1133 HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \
1134 { \
1135 StaticField* sfield; \
1136 vdst = INST_AA(inst); \
1137 ref = FETCH(1); /* field ref */ \
1138 ILOGV("|sget%s v%d,sfield@0x%04x", (_opname), vdst, ref); \
1139 sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1140 if (sfield == NULL) { \
1141 EXPORT_PC(); \
1142 sfield = dvmResolveStaticField(curMethod->clazz, ref); \
1143 if (sfield == NULL) \
1144 GOTO_exceptionThrown(); \
1145 } \
1146 SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield)); \
1147 ILOGV("+ SGET '%s'=0x%08llx", \
1148 sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \
1149 UPDATE_FIELD_GET(&sfield->field); \
1150 } \
1151 FINISH(2);
1152
1153#define HANDLE_SPUT_X(_opcode, _opname, _ftype, _regsize) \
1154 HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \
1155 { \
1156 StaticField* sfield; \
1157 vdst = INST_AA(inst); \
1158 ref = FETCH(1); /* field ref */ \
1159 ILOGV("|sput%s v%d,sfield@0x%04x", (_opname), vdst, ref); \
1160 sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1161 if (sfield == NULL) { \
1162 EXPORT_PC(); \
1163 sfield = dvmResolveStaticField(curMethod->clazz, ref); \
1164 if (sfield == NULL) \
1165 GOTO_exceptionThrown(); \
1166 } \
1167 dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst)); \
1168 ILOGV("+ SPUT '%s'=0x%08llx", \
1169 sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \
1170 UPDATE_FIELD_PUT(&sfield->field); \
1171 } \
1172 FINISH(2);
1173
1174
1175/* File: c/OP_NOP.c */
1176HANDLE_OPCODE(OP_NOP)
1177 FINISH(1);
1178OP_END
1179
1180/* File: c/OP_MOVE.c */
1181HANDLE_OPCODE(OP_MOVE /*vA, vB*/)
1182 vdst = INST_A(inst);
1183 vsrc1 = INST_B(inst);
1184 ILOGV("|move%s v%d,v%d %s(v%d=0x%08x)",
1185 (INST_INST(inst) == OP_MOVE) ? "" : "-object", vdst, vsrc1,
1186 kSpacing, vdst, GET_REGISTER(vsrc1));
1187 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1188 FINISH(1);
1189OP_END
1190
1191/* File: c/OP_MOVE_FROM16.c */
1192HANDLE_OPCODE(OP_MOVE_FROM16 /*vAA, vBBBB*/)
1193 vdst = INST_AA(inst);
1194 vsrc1 = FETCH(1);
1195 ILOGV("|move%s/from16 v%d,v%d %s(v%d=0x%08x)",
1196 (INST_INST(inst) == OP_MOVE_FROM16) ? "" : "-object", vdst, vsrc1,
1197 kSpacing, vdst, GET_REGISTER(vsrc1));
1198 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1199 FINISH(2);
1200OP_END
1201
1202/* File: c/OP_MOVE_16.c */
1203HANDLE_OPCODE(OP_MOVE_16 /*vAAAA, vBBBB*/)
1204 vdst = FETCH(1);
1205 vsrc1 = FETCH(2);
1206 ILOGV("|move%s/16 v%d,v%d %s(v%d=0x%08x)",
1207 (INST_INST(inst) == OP_MOVE_16) ? "" : "-object", vdst, vsrc1,
1208 kSpacing, vdst, GET_REGISTER(vsrc1));
1209 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1210 FINISH(3);
1211OP_END
1212
1213/* File: c/OP_MOVE_WIDE.c */
1214HANDLE_OPCODE(OP_MOVE_WIDE /*vA, vB*/)
1215 /* IMPORTANT: must correctly handle overlapping registers, e.g. both
1216 * "move-wide v6, v7" and "move-wide v7, v6" */
1217 vdst = INST_A(inst);
1218 vsrc1 = INST_B(inst);
1219 ILOGV("|move-wide v%d,v%d %s(v%d=0x%08llx)", vdst, vsrc1,
1220 kSpacing+5, vdst, GET_REGISTER_WIDE(vsrc1));
1221 SET_REGISTER_WIDE(vdst, GET_REGISTER_WIDE(vsrc1));
1222 FINISH(1);
1223OP_END
1224
1225/* File: c/OP_MOVE_WIDE_FROM16.c */
1226HANDLE_OPCODE(OP_MOVE_WIDE_FROM16 /*vAA, vBBBB*/)
1227 vdst = INST_AA(inst);
1228 vsrc1 = FETCH(1);
1229 ILOGV("|move-wide/from16 v%d,v%d (v%d=0x%08llx)", vdst, vsrc1,
1230 vdst, GET_REGISTER_WIDE(vsrc1));
1231 SET_REGISTER_WIDE(vdst, GET_REGISTER_WIDE(vsrc1));
1232 FINISH(2);
1233OP_END
1234
1235/* File: c/OP_MOVE_WIDE_16.c */
1236HANDLE_OPCODE(OP_MOVE_WIDE_16 /*vAAAA, vBBBB*/)
1237 vdst = FETCH(1);
1238 vsrc1 = FETCH(2);
1239 ILOGV("|move-wide/16 v%d,v%d %s(v%d=0x%08llx)", vdst, vsrc1,
1240 kSpacing+8, vdst, GET_REGISTER_WIDE(vsrc1));
1241 SET_REGISTER_WIDE(vdst, GET_REGISTER_WIDE(vsrc1));
1242 FINISH(3);
1243OP_END
1244
1245/* File: c/OP_MOVE_OBJECT.c */
1246/* File: c/OP_MOVE.c */
1247HANDLE_OPCODE(OP_MOVE_OBJECT /*vA, vB*/)
1248 vdst = INST_A(inst);
1249 vsrc1 = INST_B(inst);
1250 ILOGV("|move%s v%d,v%d %s(v%d=0x%08x)",
1251 (INST_INST(inst) == OP_MOVE) ? "" : "-object", vdst, vsrc1,
1252 kSpacing, vdst, GET_REGISTER(vsrc1));
1253 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1254 FINISH(1);
1255OP_END
1256
1257
1258/* File: c/OP_MOVE_OBJECT_FROM16.c */
1259/* File: c/OP_MOVE_FROM16.c */
1260HANDLE_OPCODE(OP_MOVE_OBJECT_FROM16 /*vAA, vBBBB*/)
1261 vdst = INST_AA(inst);
1262 vsrc1 = FETCH(1);
1263 ILOGV("|move%s/from16 v%d,v%d %s(v%d=0x%08x)",
1264 (INST_INST(inst) == OP_MOVE_FROM16) ? "" : "-object", vdst, vsrc1,
1265 kSpacing, vdst, GET_REGISTER(vsrc1));
1266 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1267 FINISH(2);
1268OP_END
1269
1270
1271/* File: c/OP_MOVE_OBJECT_16.c */
1272/* File: c/OP_MOVE_16.c */
1273HANDLE_OPCODE(OP_MOVE_OBJECT_16 /*vAAAA, vBBBB*/)
1274 vdst = FETCH(1);
1275 vsrc1 = FETCH(2);
1276 ILOGV("|move%s/16 v%d,v%d %s(v%d=0x%08x)",
1277 (INST_INST(inst) == OP_MOVE_16) ? "" : "-object", vdst, vsrc1,
1278 kSpacing, vdst, GET_REGISTER(vsrc1));
1279 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1280 FINISH(3);
1281OP_END
1282
1283
1284/* File: c/OP_MOVE_RESULT.c */
1285HANDLE_OPCODE(OP_MOVE_RESULT /*vAA*/)
1286 vdst = INST_AA(inst);
1287 ILOGV("|move-result%s v%d %s(v%d=0x%08x)",
1288 (INST_INST(inst) == OP_MOVE_RESULT) ? "" : "-object",
1289 vdst, kSpacing+4, vdst,retval.i);
1290 SET_REGISTER(vdst, retval.i);
1291 FINISH(1);
1292OP_END
1293
1294/* File: c/OP_MOVE_RESULT_WIDE.c */
1295HANDLE_OPCODE(OP_MOVE_RESULT_WIDE /*vAA*/)
1296 vdst = INST_AA(inst);
1297 ILOGV("|move-result-wide v%d %s(0x%08llx)", vdst, kSpacing, retval.j);
1298 SET_REGISTER_WIDE(vdst, retval.j);
1299 FINISH(1);
1300OP_END
1301
1302/* File: c/OP_MOVE_RESULT_OBJECT.c */
1303/* File: c/OP_MOVE_RESULT.c */
1304HANDLE_OPCODE(OP_MOVE_RESULT_OBJECT /*vAA*/)
1305 vdst = INST_AA(inst);
1306 ILOGV("|move-result%s v%d %s(v%d=0x%08x)",
1307 (INST_INST(inst) == OP_MOVE_RESULT) ? "" : "-object",
1308 vdst, kSpacing+4, vdst,retval.i);
1309 SET_REGISTER(vdst, retval.i);
1310 FINISH(1);
1311OP_END
1312
1313
1314/* File: c/OP_MOVE_EXCEPTION.c */
1315HANDLE_OPCODE(OP_MOVE_EXCEPTION /*vAA*/)
1316 vdst = INST_AA(inst);
1317 ILOGV("|move-exception v%d", vdst);
1318 assert(self->exception != NULL);
1319 SET_REGISTER(vdst, (u4)self->exception);
1320 dvmClearException(self);
1321 FINISH(1);
1322OP_END
1323
1324/* File: c/OP_RETURN_VOID.c */
1325HANDLE_OPCODE(OP_RETURN_VOID /**/)
1326 ILOGV("|return-void");
1327#ifndef NDEBUG
1328 retval.j = 0xababababULL; // placate valgrind
1329#endif
1330 GOTO_returnFromMethod();
1331OP_END
1332
1333/* File: c/OP_RETURN.c */
1334HANDLE_OPCODE(OP_RETURN /*vAA*/)
1335 vsrc1 = INST_AA(inst);
1336 ILOGV("|return%s v%d",
1337 (INST_INST(inst) == OP_RETURN) ? "" : "-object", vsrc1);
1338 retval.i = GET_REGISTER(vsrc1);
1339 GOTO_returnFromMethod();
1340OP_END
1341
1342/* File: c/OP_RETURN_WIDE.c */
1343HANDLE_OPCODE(OP_RETURN_WIDE /*vAA*/)
1344 vsrc1 = INST_AA(inst);
1345 ILOGV("|return-wide v%d", vsrc1);
1346 retval.j = GET_REGISTER_WIDE(vsrc1);
1347 GOTO_returnFromMethod();
1348OP_END
1349
1350/* File: c/OP_RETURN_OBJECT.c */
1351/* File: c/OP_RETURN.c */
1352HANDLE_OPCODE(OP_RETURN_OBJECT /*vAA*/)
1353 vsrc1 = INST_AA(inst);
1354 ILOGV("|return%s v%d",
1355 (INST_INST(inst) == OP_RETURN) ? "" : "-object", vsrc1);
1356 retval.i = GET_REGISTER(vsrc1);
1357 GOTO_returnFromMethod();
1358OP_END
1359
1360
1361/* File: c/OP_CONST_4.c */
1362HANDLE_OPCODE(OP_CONST_4 /*vA, #+B*/)
1363 {
1364 s4 tmp;
1365
1366 vdst = INST_A(inst);
1367 tmp = (s4) (INST_B(inst) << 28) >> 28; // sign extend 4-bit value
1368 ILOGV("|const/4 v%d,#0x%02x", vdst, (s4)tmp);
1369 SET_REGISTER(vdst, tmp);
1370 }
1371 FINISH(1);
1372OP_END
1373
1374/* File: c/OP_CONST_16.c */
1375HANDLE_OPCODE(OP_CONST_16 /*vAA, #+BBBB*/)
1376 vdst = INST_AA(inst);
1377 vsrc1 = FETCH(1);
1378 ILOGV("|const/16 v%d,#0x%04x", vdst, (s2)vsrc1);
1379 SET_REGISTER(vdst, (s2) vsrc1);
1380 FINISH(2);
1381OP_END
1382
1383/* File: c/OP_CONST.c */
1384HANDLE_OPCODE(OP_CONST /*vAA, #+BBBBBBBB*/)
1385 {
1386 u4 tmp;
1387
1388 vdst = INST_AA(inst);
1389 tmp = FETCH(1);
1390 tmp |= (u4)FETCH(2) << 16;
1391 ILOGV("|const v%d,#0x%08x", vdst, tmp);
1392 SET_REGISTER(vdst, tmp);
1393 }
1394 FINISH(3);
1395OP_END
1396
1397/* File: c/OP_CONST_HIGH16.c */
1398HANDLE_OPCODE(OP_CONST_HIGH16 /*vAA, #+BBBB0000*/)
1399 vdst = INST_AA(inst);
1400 vsrc1 = FETCH(1);
1401 ILOGV("|const/high16 v%d,#0x%04x0000", vdst, vsrc1);
1402 SET_REGISTER(vdst, vsrc1 << 16);
1403 FINISH(2);
1404OP_END
1405
1406/* File: c/OP_CONST_WIDE_16.c */
1407HANDLE_OPCODE(OP_CONST_WIDE_16 /*vAA, #+BBBB*/)
1408 vdst = INST_AA(inst);
1409 vsrc1 = FETCH(1);
1410 ILOGV("|const-wide/16 v%d,#0x%04x", vdst, (s2)vsrc1);
1411 SET_REGISTER_WIDE(vdst, (s2)vsrc1);
1412 FINISH(2);
1413OP_END
1414
1415/* File: c/OP_CONST_WIDE_32.c */
1416HANDLE_OPCODE(OP_CONST_WIDE_32 /*vAA, #+BBBBBBBB*/)
1417 {
1418 u4 tmp;
1419
1420 vdst = INST_AA(inst);
1421 tmp = FETCH(1);
1422 tmp |= (u4)FETCH(2) << 16;
1423 ILOGV("|const-wide/32 v%d,#0x%08x", vdst, tmp);
1424 SET_REGISTER_WIDE(vdst, (s4) tmp);
1425 }
1426 FINISH(3);
1427OP_END
1428
1429/* File: c/OP_CONST_WIDE.c */
1430HANDLE_OPCODE(OP_CONST_WIDE /*vAA, #+BBBBBBBBBBBBBBBB*/)
1431 {
1432 u8 tmp;
1433
1434 vdst = INST_AA(inst);
1435 tmp = FETCH(1);
1436 tmp |= (u8)FETCH(2) << 16;
1437 tmp |= (u8)FETCH(3) << 32;
1438 tmp |= (u8)FETCH(4) << 48;
1439 ILOGV("|const-wide v%d,#0x%08llx", vdst, tmp);
1440 SET_REGISTER_WIDE(vdst, tmp);
1441 }
1442 FINISH(5);
1443OP_END
1444
1445/* File: c/OP_CONST_WIDE_HIGH16.c */
1446HANDLE_OPCODE(OP_CONST_WIDE_HIGH16 /*vAA, #+BBBB000000000000*/)
1447 vdst = INST_AA(inst);
1448 vsrc1 = FETCH(1);
1449 ILOGV("|const-wide/high16 v%d,#0x%04x000000000000", vdst, vsrc1);
1450 SET_REGISTER_WIDE(vdst, ((u8) vsrc1) << 48);
1451 FINISH(2);
1452OP_END
1453
1454/* File: c/OP_CONST_STRING.c */
1455HANDLE_OPCODE(OP_CONST_STRING /*vAA, string@BBBB*/)
1456 {
1457 StringObject* strObj;
1458
1459 vdst = INST_AA(inst);
1460 ref = FETCH(1);
1461 ILOGV("|const-string v%d string@0x%04x", vdst, ref);
1462 strObj = dvmDexGetResolvedString(methodClassDex, ref);
1463 if (strObj == NULL) {
1464 EXPORT_PC();
1465 strObj = dvmResolveString(curMethod->clazz, ref);
1466 if (strObj == NULL)
1467 GOTO_exceptionThrown();
1468 }
1469 SET_REGISTER(vdst, (u4) strObj);
1470 }
1471 FINISH(2);
1472OP_END
1473
1474/* File: c/OP_CONST_STRING_JUMBO.c */
1475HANDLE_OPCODE(OP_CONST_STRING_JUMBO /*vAA, string@BBBBBBBB*/)
1476 {
1477 StringObject* strObj;
1478 u4 tmp;
1479
1480 vdst = INST_AA(inst);
1481 tmp = FETCH(1);
1482 tmp |= (u4)FETCH(2) << 16;
1483 ILOGV("|const-string/jumbo v%d string@0x%08x", vdst, tmp);
1484 strObj = dvmDexGetResolvedString(methodClassDex, tmp);
1485 if (strObj == NULL) {
1486 EXPORT_PC();
1487 strObj = dvmResolveString(curMethod->clazz, tmp);
1488 if (strObj == NULL)
1489 GOTO_exceptionThrown();
1490 }
1491 SET_REGISTER(vdst, (u4) strObj);
1492 }
1493 FINISH(3);
1494OP_END
1495
1496/* File: c/OP_CONST_CLASS.c */
1497HANDLE_OPCODE(OP_CONST_CLASS /*vAA, class@BBBB*/)
1498 {
1499 ClassObject* clazz;
1500
1501 vdst = INST_AA(inst);
1502 ref = FETCH(1);
1503 ILOGV("|const-class v%d class@0x%04x", vdst, ref);
1504 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1505 if (clazz == NULL) {
1506 EXPORT_PC();
1507 clazz = dvmResolveClass(curMethod->clazz, ref, true);
1508 if (clazz == NULL)
1509 GOTO_exceptionThrown();
1510 }
1511 SET_REGISTER(vdst, (u4) clazz);
1512 }
1513 FINISH(2);
1514OP_END
1515
1516/* File: c/OP_MONITOR_ENTER.c */
1517HANDLE_OPCODE(OP_MONITOR_ENTER /*vAA*/)
1518 {
1519 Object* obj;
1520
1521 vsrc1 = INST_AA(inst);
1522 ILOGV("|monitor-enter v%d %s(0x%08x)",
1523 vsrc1, kSpacing+6, GET_REGISTER(vsrc1));
1524 obj = (Object*)GET_REGISTER(vsrc1);
1525 if (!checkForNullExportPC(obj, fp, pc))
1526 GOTO_exceptionThrown();
1527 ILOGV("+ locking %p %s\n", obj, obj->clazz->descriptor);
1528#ifdef WITH_MONITOR_TRACKING
1529 EXPORT_PC(); /* need for stack trace */
1530#endif
1531 dvmLockObject(self, obj);
1532#ifdef WITH_DEADLOCK_PREDICTION
1533 if (dvmCheckException(self))
1534 GOTO_exceptionThrown();
1535#endif
1536 }
1537 FINISH(1);
1538OP_END
1539
1540/* File: c/OP_MONITOR_EXIT.c */
1541HANDLE_OPCODE(OP_MONITOR_EXIT /*vAA*/)
1542 {
1543 Object* obj;
1544
1545 EXPORT_PC();
1546
1547 vsrc1 = INST_AA(inst);
1548 ILOGV("|monitor-exit v%d %s(0x%08x)",
1549 vsrc1, kSpacing+5, GET_REGISTER(vsrc1));
1550 obj = (Object*)GET_REGISTER(vsrc1);
1551 if (!checkForNull(obj)) {
1552 /*
1553 * The exception needs to be processed at the *following*
1554 * instruction, not the current instruction (see the Dalvik
1555 * spec). Because we're jumping to an exception handler,
1556 * we're not actually at risk of skipping an instruction
1557 * by doing so.
1558 */
1559 ADJUST_PC(1); /* monitor-exit width is 1 */
1560 GOTO_exceptionThrown();
1561 }
1562 ILOGV("+ unlocking %p %s\n", obj, obj->clazz->descriptor);
1563 if (!dvmUnlockObject(self, obj)) {
1564 assert(dvmCheckException(self));
1565 ADJUST_PC(1);
1566 GOTO_exceptionThrown();
1567 }
1568 }
1569 FINISH(1);
1570OP_END
1571
1572/* File: c/OP_CHECK_CAST.c */
1573HANDLE_OPCODE(OP_CHECK_CAST /*vAA, class@BBBB*/)
1574 {
1575 ClassObject* clazz;
1576 Object* obj;
1577
1578 EXPORT_PC();
1579
1580 vsrc1 = INST_AA(inst);
1581 ref = FETCH(1); /* class to check against */
1582 ILOGV("|check-cast v%d,class@0x%04x", vsrc1, ref);
1583
1584 obj = (Object*)GET_REGISTER(vsrc1);
1585 if (obj != NULL) {
1586#if defined(WITH_EXTRA_OBJECT_VALIDATION)
1587 if (!checkForNull(obj))
1588 GOTO_exceptionThrown();
1589#endif
1590 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1591 if (clazz == NULL) {
1592 clazz = dvmResolveClass(curMethod->clazz, ref, false);
1593 if (clazz == NULL)
1594 GOTO_exceptionThrown();
1595 }
1596 if (!dvmInstanceof(obj->clazz, clazz)) {
1597 dvmThrowExceptionWithClassMessage(
1598 "Ljava/lang/ClassCastException;", obj->clazz->descriptor);
1599 GOTO_exceptionThrown();
1600 }
1601 }
1602 }
1603 FINISH(2);
1604OP_END
1605
1606/* File: c/OP_INSTANCE_OF.c */
1607HANDLE_OPCODE(OP_INSTANCE_OF /*vA, vB, class@CCCC*/)
1608 {
1609 ClassObject* clazz;
1610 Object* obj;
1611
1612 vdst = INST_A(inst);
1613 vsrc1 = INST_B(inst); /* object to check */
1614 ref = FETCH(1); /* class to check against */
1615 ILOGV("|instance-of v%d,v%d,class@0x%04x", vdst, vsrc1, ref);
1616
1617 obj = (Object*)GET_REGISTER(vsrc1);
1618 if (obj == NULL) {
1619 SET_REGISTER(vdst, 0);
1620 } else {
1621#if defined(WITH_EXTRA_OBJECT_VALIDATION)
1622 if (!checkForNullExportPC(obj, fp, pc))
1623 GOTO_exceptionThrown();
1624#endif
1625 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1626 if (clazz == NULL) {
1627 EXPORT_PC();
1628 clazz = dvmResolveClass(curMethod->clazz, ref, true);
1629 if (clazz == NULL)
1630 GOTO_exceptionThrown();
1631 }
1632 SET_REGISTER(vdst, dvmInstanceof(obj->clazz, clazz));
1633 }
1634 }
1635 FINISH(2);
1636OP_END
1637
1638/* File: c/OP_ARRAY_LENGTH.c */
1639HANDLE_OPCODE(OP_ARRAY_LENGTH /*vA, vB*/)
1640 {
1641 ArrayObject* arrayObj;
1642
1643 vdst = INST_A(inst);
1644 vsrc1 = INST_B(inst);
1645 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
1646 ILOGV("|array-length v%d,v%d (%p)", vdst, vsrc1, arrayObj);
1647 if (!checkForNullExportPC((Object*) arrayObj, fp, pc))
1648 GOTO_exceptionThrown();
1649 /* verifier guarantees this is an array reference */
1650 SET_REGISTER(vdst, arrayObj->length);
1651 }
1652 FINISH(1);
1653OP_END
1654
1655/* File: c/OP_NEW_INSTANCE.c */
1656HANDLE_OPCODE(OP_NEW_INSTANCE /*vAA, class@BBBB*/)
1657 {
1658 ClassObject* clazz;
1659 Object* newObj;
1660
1661 EXPORT_PC();
1662
1663 vdst = INST_AA(inst);
1664 ref = FETCH(1);
1665 ILOGV("|new-instance v%d,class@0x%04x", vdst, ref);
1666 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1667 if (clazz == NULL) {
1668 clazz = dvmResolveClass(curMethod->clazz, ref, false);
1669 if (clazz == NULL)
1670 GOTO_exceptionThrown();
1671 }
1672
1673 if (!dvmIsClassInitialized(clazz) && !dvmInitClass(clazz))
1674 GOTO_exceptionThrown();
1675
1676 /*
1677 * Note: the verifier can ensure that this never happens, allowing us
1678 * to remove the check. However, the spec requires we throw the
1679 * exception at runtime, not verify time, so the verifier would
1680 * need to replace the new-instance call with a magic "throw
1681 * InstantiationError" instruction.
1682 *
1683 * Since this relies on the verifier, which is optional, we would
1684 * also need a "new-instance-quick" instruction to identify instances
1685 * that don't require the check.
1686 */
1687 if (dvmIsInterfaceClass(clazz) || dvmIsAbstractClass(clazz)) {
1688 dvmThrowExceptionWithClassMessage("Ljava/lang/InstantiationError;",
1689 clazz->descriptor);
1690 GOTO_exceptionThrown();
1691 }
1692 newObj = dvmAllocObject(clazz, ALLOC_DONT_TRACK);
1693 if (newObj == NULL)
1694 GOTO_exceptionThrown();
1695 SET_REGISTER(vdst, (u4) newObj);
1696 }
1697 FINISH(2);
1698OP_END
1699
1700/* File: c/OP_NEW_ARRAY.c */
1701HANDLE_OPCODE(OP_NEW_ARRAY /*vA, vB, class@CCCC*/)
1702 {
1703 ClassObject* arrayClass;
1704 ArrayObject* newArray;
1705 s4 length;
1706
1707 EXPORT_PC();
1708
1709 vdst = INST_A(inst);
1710 vsrc1 = INST_B(inst); /* length reg */
1711 ref = FETCH(1);
1712 ILOGV("|new-array v%d,v%d,class@0x%04x (%d elements)",
1713 vdst, vsrc1, ref, (s4) GET_REGISTER(vsrc1));
1714 length = (s4) GET_REGISTER(vsrc1);
1715 if (length < 0) {
1716 dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL);
1717 GOTO_exceptionThrown();
1718 }
1719 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
1720 if (arrayClass == NULL) {
1721 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
1722 if (arrayClass == NULL)
1723 GOTO_exceptionThrown();
1724 }
1725 /* verifier guarantees this is an array class */
1726 assert(dvmIsArrayClass(arrayClass));
1727 assert(dvmIsClassInitialized(arrayClass));
1728
1729 newArray = dvmAllocArrayByClass(arrayClass, length, ALLOC_DONT_TRACK);
1730 if (newArray == NULL)
1731 GOTO_exceptionThrown();
1732 SET_REGISTER(vdst, (u4) newArray);
1733 }
1734 FINISH(2);
1735OP_END
1736
1737
1738/* File: c/OP_FILLED_NEW_ARRAY.c */
1739HANDLE_OPCODE(OP_FILLED_NEW_ARRAY /*vB, {vD, vE, vF, vG, vA}, class@CCCC*/)
1740 GOTO_invoke(filledNewArray, false);
1741OP_END
1742
1743/* File: c/OP_FILLED_NEW_ARRAY_RANGE.c */
1744HANDLE_OPCODE(OP_FILLED_NEW_ARRAY_RANGE /*{vCCCC..v(CCCC+AA-1)}, class@BBBB*/)
1745 GOTO_invoke(filledNewArray, true);
1746OP_END
1747
1748/* File: c/OP_FILL_ARRAY_DATA.c */
1749HANDLE_OPCODE(OP_FILL_ARRAY_DATA) /*vAA, +BBBBBBBB*/
1750 {
1751 const u2* arrayData;
1752 s4 offset;
1753 ArrayObject* arrayObj;
1754
1755 EXPORT_PC();
1756 vsrc1 = INST_AA(inst);
1757 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1758 ILOGV("|fill-array-data v%d +0x%04x", vsrc1, offset);
1759 arrayData = pc + offset; // offset in 16-bit units
1760#ifndef NDEBUG
1761 if (arrayData < curMethod->insns ||
1762 arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1763 {
1764 /* should have been caught in verifier */
1765 dvmThrowException("Ljava/lang/InternalError;",
1766 "bad fill array data");
1767 GOTO_exceptionThrown();
1768 }
1769#endif
1770 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
1771 if (!dvmInterpHandleFillArrayData(arrayObj, arrayData)) {
1772 GOTO_exceptionThrown();
1773 }
1774 FINISH(3);
1775 }
1776OP_END
1777
1778/* File: c/OP_THROW.c */
1779HANDLE_OPCODE(OP_THROW /*vAA*/)
1780 {
1781 Object* obj;
1782
1783 vsrc1 = INST_AA(inst);
1784 ILOGV("|throw v%d (%p)", vsrc1, (void*)GET_REGISTER(vsrc1));
1785 obj = (Object*) GET_REGISTER(vsrc1);
1786 if (!checkForNullExportPC(obj, fp, pc)) {
1787 /* will throw a null pointer exception */
1788 LOGVV("Bad exception\n");
1789 } else {
1790 /* use the requested exception */
1791 dvmSetException(self, obj);
1792 }
1793 GOTO_exceptionThrown();
1794 }
1795OP_END
1796
1797/* File: c/OP_GOTO.c */
1798HANDLE_OPCODE(OP_GOTO /*+AA*/)
1799 vdst = INST_AA(inst);
1800 if ((s1)vdst < 0)
1801 ILOGV("|goto -0x%02x", -((s1)vdst));
1802 else
1803 ILOGV("|goto +0x%02x", ((s1)vdst));
1804 ILOGV("> branch taken");
1805 if ((s1)vdst < 0)
1806 PERIODIC_CHECKS(kInterpEntryInstr, (s1)vdst);
1807 FINISH((s1)vdst);
1808OP_END
1809
1810/* File: c/OP_GOTO_16.c */
1811HANDLE_OPCODE(OP_GOTO_16 /*+AAAA*/)
1812 {
1813 s4 offset = (s2) FETCH(1); /* sign-extend next code unit */
1814
1815 if (offset < 0)
1816 ILOGV("|goto/16 -0x%04x", -offset);
1817 else
1818 ILOGV("|goto/16 +0x%04x", offset);
1819 ILOGV("> branch taken");
1820 if (offset < 0)
1821 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1822 FINISH(offset);
1823 }
1824OP_END
1825
1826/* File: c/OP_GOTO_32.c */
1827HANDLE_OPCODE(OP_GOTO_32 /*+AAAAAAAA*/)
1828 {
1829 s4 offset = FETCH(1); /* low-order 16 bits */
1830 offset |= ((s4) FETCH(2)) << 16; /* high-order 16 bits */
1831
1832 if (offset < 0)
1833 ILOGV("|goto/32 -0x%08x", -offset);
1834 else
1835 ILOGV("|goto/32 +0x%08x", offset);
1836 ILOGV("> branch taken");
1837 if (offset <= 0) /* allowed to branch to self */
1838 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1839 FINISH(offset);
1840 }
1841OP_END
1842
1843/* File: c/OP_PACKED_SWITCH.c */
1844HANDLE_OPCODE(OP_PACKED_SWITCH /*vAA, +BBBB*/)
1845 {
1846 const u2* switchData;
1847 u4 testVal;
1848 s4 offset;
1849
1850 vsrc1 = INST_AA(inst);
1851 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1852 ILOGV("|packed-switch v%d +0x%04x", vsrc1, vsrc2);
1853 switchData = pc + offset; // offset in 16-bit units
1854#ifndef NDEBUG
1855 if (switchData < curMethod->insns ||
1856 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1857 {
1858 /* should have been caught in verifier */
1859 EXPORT_PC();
1860 dvmThrowException("Ljava/lang/InternalError;", "bad packed switch");
1861 GOTO_exceptionThrown();
1862 }
1863#endif
1864 testVal = GET_REGISTER(vsrc1);
1865
1866 offset = dvmInterpHandlePackedSwitch(switchData, testVal);
1867 ILOGV("> branch taken (0x%04x)\n", offset);
1868 if (offset <= 0) /* uncommon */
1869 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1870 FINISH(offset);
1871 }
1872OP_END
1873
1874/* File: c/OP_SPARSE_SWITCH.c */
1875HANDLE_OPCODE(OP_SPARSE_SWITCH /*vAA, +BBBB*/)
1876 {
1877 const u2* switchData;
1878 u4 testVal;
1879 s4 offset;
1880
1881 vsrc1 = INST_AA(inst);
1882 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1883 ILOGV("|sparse-switch v%d +0x%04x", vsrc1, vsrc2);
1884 switchData = pc + offset; // offset in 16-bit units
1885#ifndef NDEBUG
1886 if (switchData < curMethod->insns ||
1887 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1888 {
1889 /* should have been caught in verifier */
1890 EXPORT_PC();
1891 dvmThrowException("Ljava/lang/InternalError;", "bad sparse switch");
1892 GOTO_exceptionThrown();
1893 }
1894#endif
1895 testVal = GET_REGISTER(vsrc1);
1896
1897 offset = dvmInterpHandleSparseSwitch(switchData, testVal);
1898 ILOGV("> branch taken (0x%04x)\n", offset);
1899 if (offset <= 0) /* uncommon */
1900 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1901 FINISH(offset);
1902 }
1903OP_END
1904
1905/* File: c/OP_CMPL_FLOAT.c */
1906HANDLE_OP_CMPX(OP_CMPL_FLOAT, "l-float", float, _FLOAT, -1)
1907OP_END
1908
1909/* File: c/OP_CMPG_FLOAT.c */
1910HANDLE_OP_CMPX(OP_CMPG_FLOAT, "g-float", float, _FLOAT, 1)
1911OP_END
1912
1913/* File: c/OP_CMPL_DOUBLE.c */
1914HANDLE_OP_CMPX(OP_CMPL_DOUBLE, "l-double", double, _DOUBLE, -1)
1915OP_END
1916
1917/* File: c/OP_CMPG_DOUBLE.c */
1918HANDLE_OP_CMPX(OP_CMPG_DOUBLE, "g-double", double, _DOUBLE, 1)
1919OP_END
1920
1921/* File: c/OP_CMP_LONG.c */
1922HANDLE_OP_CMPX(OP_CMP_LONG, "-long", s8, _WIDE, 0)
1923OP_END
1924
1925/* File: c/OP_IF_EQ.c */
1926HANDLE_OP_IF_XX(OP_IF_EQ, "eq", ==)
1927OP_END
1928
1929/* File: c/OP_IF_NE.c */
1930HANDLE_OP_IF_XX(OP_IF_NE, "ne", !=)
1931OP_END
1932
1933/* File: c/OP_IF_LT.c */
1934HANDLE_OP_IF_XX(OP_IF_LT, "lt", <)
1935OP_END
1936
1937/* File: c/OP_IF_GE.c */
1938HANDLE_OP_IF_XX(OP_IF_GE, "ge", >=)
1939OP_END
1940
1941/* File: c/OP_IF_GT.c */
1942HANDLE_OP_IF_XX(OP_IF_GT, "gt", >)
1943OP_END
1944
1945/* File: c/OP_IF_LE.c */
1946HANDLE_OP_IF_XX(OP_IF_LE, "le", <=)
1947OP_END
1948
1949/* File: c/OP_IF_EQZ.c */
1950HANDLE_OP_IF_XXZ(OP_IF_EQZ, "eqz", ==)
1951OP_END
1952
1953/* File: c/OP_IF_NEZ.c */
1954HANDLE_OP_IF_XXZ(OP_IF_NEZ, "nez", !=)
1955OP_END
1956
1957/* File: c/OP_IF_LTZ.c */
1958HANDLE_OP_IF_XXZ(OP_IF_LTZ, "ltz", <)
1959OP_END
1960
1961/* File: c/OP_IF_GEZ.c */
1962HANDLE_OP_IF_XXZ(OP_IF_GEZ, "gez", >=)
1963OP_END
1964
1965/* File: c/OP_IF_GTZ.c */
1966HANDLE_OP_IF_XXZ(OP_IF_GTZ, "gtz", >)
1967OP_END
1968
1969/* File: c/OP_IF_LEZ.c */
1970HANDLE_OP_IF_XXZ(OP_IF_LEZ, "lez", <=)
1971OP_END
1972
1973/* File: c/OP_UNUSED_3E.c */
1974HANDLE_OPCODE(OP_UNUSED_3E)
1975OP_END
1976
1977/* File: c/OP_UNUSED_3F.c */
1978HANDLE_OPCODE(OP_UNUSED_3F)
1979OP_END
1980
1981/* File: c/OP_UNUSED_40.c */
1982HANDLE_OPCODE(OP_UNUSED_40)
1983OP_END
1984
1985/* File: c/OP_UNUSED_41.c */
1986HANDLE_OPCODE(OP_UNUSED_41)
1987OP_END
1988
1989/* File: c/OP_UNUSED_42.c */
1990HANDLE_OPCODE(OP_UNUSED_42)
1991OP_END
1992
1993/* File: c/OP_UNUSED_43.c */
1994HANDLE_OPCODE(OP_UNUSED_43)
1995OP_END
1996
1997/* File: c/OP_AGET.c */
1998HANDLE_OP_AGET(OP_AGET, "", u4, )
1999OP_END
2000
2001/* File: c/OP_AGET_WIDE.c */
2002HANDLE_OP_AGET(OP_AGET_WIDE, "-wide", s8, _WIDE)
2003OP_END
2004
2005/* File: c/OP_AGET_OBJECT.c */
2006HANDLE_OP_AGET(OP_AGET_OBJECT, "-object", u4, )
2007OP_END
2008
2009/* File: c/OP_AGET_BOOLEAN.c */
2010HANDLE_OP_AGET(OP_AGET_BOOLEAN, "-boolean", u1, )
2011OP_END
2012
2013/* File: c/OP_AGET_BYTE.c */
2014HANDLE_OP_AGET(OP_AGET_BYTE, "-byte", s1, )
2015OP_END
2016
2017/* File: c/OP_AGET_CHAR.c */
2018HANDLE_OP_AGET(OP_AGET_CHAR, "-char", u2, )
2019OP_END
2020
2021/* File: c/OP_AGET_SHORT.c */
2022HANDLE_OP_AGET(OP_AGET_SHORT, "-short", s2, )
2023OP_END
2024
2025/* File: c/OP_APUT.c */
2026HANDLE_OP_APUT(OP_APUT, "", u4, )
2027OP_END
2028
2029/* File: c/OP_APUT_WIDE.c */
2030HANDLE_OP_APUT(OP_APUT_WIDE, "-wide", s8, _WIDE)
2031OP_END
2032
2033/* File: c/OP_APUT_OBJECT.c */
2034HANDLE_OPCODE(OP_APUT_OBJECT /*vAA, vBB, vCC*/)
2035 {
2036 ArrayObject* arrayObj;
2037 Object* obj;
2038 u2 arrayInfo;
2039 EXPORT_PC();
2040 vdst = INST_AA(inst); /* AA: source value */
2041 arrayInfo = FETCH(1);
2042 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */
2043 vsrc2 = arrayInfo >> 8; /* CC: index */
2044 ILOGV("|aput%s v%d,v%d,v%d", "-object", vdst, vsrc1, vsrc2);
2045 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
2046 if (!checkForNull((Object*) arrayObj))
2047 GOTO_exceptionThrown();
2048 if (GET_REGISTER(vsrc2) >= arrayObj->length) {
2049 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
2050 NULL);
2051 GOTO_exceptionThrown();
2052 }
2053 obj = (Object*) GET_REGISTER(vdst);
2054 if (obj != NULL) {
2055 if (!checkForNull(obj))
2056 GOTO_exceptionThrown();
2057 if (!dvmCanPutArrayElement(obj->clazz, arrayObj->obj.clazz)) {
2058 LOGV("Can't put a '%s'(%p) into array type='%s'(%p)\n",
2059 obj->clazz->descriptor, obj,
2060 arrayObj->obj.clazz->descriptor, arrayObj);
2061 //dvmDumpClass(obj->clazz);
2062 //dvmDumpClass(arrayObj->obj.clazz);
2063 dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
2064 GOTO_exceptionThrown();
2065 }
2066 }
2067 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));
2068 ((u4*) arrayObj->contents)[GET_REGISTER(vsrc2)] =
2069 GET_REGISTER(vdst);
2070 }
2071 FINISH(2);
2072OP_END
2073
2074/* File: c/OP_APUT_BOOLEAN.c */
2075HANDLE_OP_APUT(OP_APUT_BOOLEAN, "-boolean", u1, )
2076OP_END
2077
2078/* File: c/OP_APUT_BYTE.c */
2079HANDLE_OP_APUT(OP_APUT_BYTE, "-byte", s1, )
2080OP_END
2081
2082/* File: c/OP_APUT_CHAR.c */
2083HANDLE_OP_APUT(OP_APUT_CHAR, "-char", u2, )
2084OP_END
2085
2086/* File: c/OP_APUT_SHORT.c */
2087HANDLE_OP_APUT(OP_APUT_SHORT, "-short", s2, )
2088OP_END
2089
2090/* File: c/OP_IGET.c */
2091HANDLE_IGET_X(OP_IGET, "", Int, )
2092OP_END
2093
2094/* File: c/OP_IGET_WIDE.c */
2095HANDLE_IGET_X(OP_IGET_WIDE, "-wide", Long, _WIDE)
2096OP_END
2097
2098/* File: c/OP_IGET_OBJECT.c */
2099HANDLE_IGET_X(OP_IGET_OBJECT, "-object", Object, _AS_OBJECT)
2100OP_END
2101
2102/* File: c/OP_IGET_BOOLEAN.c */
2103HANDLE_IGET_X(OP_IGET_BOOLEAN, "", Int, )
2104OP_END
2105
2106/* File: c/OP_IGET_BYTE.c */
2107HANDLE_IGET_X(OP_IGET_BYTE, "", Int, )
2108OP_END
2109
2110/* File: c/OP_IGET_CHAR.c */
2111HANDLE_IGET_X(OP_IGET_CHAR, "", Int, )
2112OP_END
2113
2114/* File: c/OP_IGET_SHORT.c */
2115HANDLE_IGET_X(OP_IGET_SHORT, "", Int, )
2116OP_END
2117
2118/* File: c/OP_IPUT.c */
2119HANDLE_IPUT_X(OP_IPUT, "", Int, )
2120OP_END
2121
2122/* File: c/OP_IPUT_WIDE.c */
2123HANDLE_IPUT_X(OP_IPUT_WIDE, "-wide", Long, _WIDE)
2124OP_END
2125
2126/* File: c/OP_IPUT_OBJECT.c */
2127/*
2128 * The VM spec says we should verify that the reference being stored into
2129 * the field is assignment compatible. In practice, many popular VMs don't
2130 * do this because it slows down a very common operation. It's not so bad
2131 * for us, since "dexopt" quickens it whenever possible, but it's still an
2132 * issue.
2133 *
2134 * To make this spec-complaint, we'd need to add a ClassObject pointer to
2135 * the Field struct, resolve the field's type descriptor at link or class
2136 * init time, and then verify the type here.
2137 */
2138HANDLE_IPUT_X(OP_IPUT_OBJECT, "-object", Object, _AS_OBJECT)
2139OP_END
2140
2141/* File: c/OP_IPUT_BOOLEAN.c */
2142HANDLE_IPUT_X(OP_IPUT_BOOLEAN, "", Int, )
2143OP_END
2144
2145/* File: c/OP_IPUT_BYTE.c */
2146HANDLE_IPUT_X(OP_IPUT_BYTE, "", Int, )
2147OP_END
2148
2149/* File: c/OP_IPUT_CHAR.c */
2150HANDLE_IPUT_X(OP_IPUT_CHAR, "", Int, )
2151OP_END
2152
2153/* File: c/OP_IPUT_SHORT.c */
2154HANDLE_IPUT_X(OP_IPUT_SHORT, "", Int, )
2155OP_END
2156
2157/* File: c/OP_SGET.c */
2158HANDLE_SGET_X(OP_SGET, "", Int, )
2159OP_END
2160
2161/* File: c/OP_SGET_WIDE.c */
2162HANDLE_SGET_X(OP_SGET_WIDE, "-wide", Long, _WIDE)
2163OP_END
2164
2165/* File: c/OP_SGET_OBJECT.c */
2166HANDLE_SGET_X(OP_SGET_OBJECT, "-object", Object, _AS_OBJECT)
2167OP_END
2168
2169/* File: c/OP_SGET_BOOLEAN.c */
2170HANDLE_SGET_X(OP_SGET_BOOLEAN, "", Int, )
2171OP_END
2172
2173/* File: c/OP_SGET_BYTE.c */
2174HANDLE_SGET_X(OP_SGET_BYTE, "", Int, )
2175OP_END
2176
2177/* File: c/OP_SGET_CHAR.c */
2178HANDLE_SGET_X(OP_SGET_CHAR, "", Int, )
2179OP_END
2180
2181/* File: c/OP_SGET_SHORT.c */
2182HANDLE_SGET_X(OP_SGET_SHORT, "", Int, )
2183OP_END
2184
2185/* File: c/OP_SPUT.c */
2186HANDLE_SPUT_X(OP_SPUT, "", Int, )
2187OP_END
2188
2189/* File: c/OP_SPUT_WIDE.c */
2190HANDLE_SPUT_X(OP_SPUT_WIDE, "-wide", Long, _WIDE)
2191OP_END
2192
2193/* File: c/OP_SPUT_OBJECT.c */
2194HANDLE_SPUT_X(OP_SPUT_OBJECT, "-object", Object, _AS_OBJECT)
2195OP_END
2196
2197/* File: c/OP_SPUT_BOOLEAN.c */
2198HANDLE_SPUT_X(OP_SPUT_BOOLEAN, "", Int, )
2199OP_END
2200
2201/* File: c/OP_SPUT_BYTE.c */
2202HANDLE_SPUT_X(OP_SPUT_BYTE, "", Int, )
2203OP_END
2204
2205/* File: c/OP_SPUT_CHAR.c */
2206HANDLE_SPUT_X(OP_SPUT_CHAR, "", Int, )
2207OP_END
2208
2209/* File: c/OP_SPUT_SHORT.c */
2210HANDLE_SPUT_X(OP_SPUT_SHORT, "", Int, )
2211OP_END
2212
2213/* File: c/OP_INVOKE_VIRTUAL.c */
2214HANDLE_OPCODE(OP_INVOKE_VIRTUAL /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2215 GOTO_invoke(invokeVirtual, false);
2216OP_END
2217
2218/* File: c/OP_INVOKE_SUPER.c */
2219HANDLE_OPCODE(OP_INVOKE_SUPER /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2220 GOTO_invoke(invokeSuper, false);
2221OP_END
2222
2223/* File: c/OP_INVOKE_DIRECT.c */
2224HANDLE_OPCODE(OP_INVOKE_DIRECT /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2225 GOTO_invoke(invokeDirect, false);
2226OP_END
2227
2228/* File: c/OP_INVOKE_STATIC.c */
2229HANDLE_OPCODE(OP_INVOKE_STATIC /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2230 GOTO_invoke(invokeStatic, false);
2231OP_END
2232
2233/* File: c/OP_INVOKE_INTERFACE.c */
2234HANDLE_OPCODE(OP_INVOKE_INTERFACE /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2235 GOTO_invoke(invokeInterface, false);
2236OP_END
2237
2238/* File: c/OP_UNUSED_73.c */
2239HANDLE_OPCODE(OP_UNUSED_73)
2240OP_END
2241
2242/* File: c/OP_INVOKE_VIRTUAL_RANGE.c */
2243HANDLE_OPCODE(OP_INVOKE_VIRTUAL_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2244 GOTO_invoke(invokeVirtual, true);
2245OP_END
2246
2247/* File: c/OP_INVOKE_SUPER_RANGE.c */
2248HANDLE_OPCODE(OP_INVOKE_SUPER_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2249 GOTO_invoke(invokeSuper, true);
2250OP_END
2251
2252/* File: c/OP_INVOKE_DIRECT_RANGE.c */
2253HANDLE_OPCODE(OP_INVOKE_DIRECT_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2254 GOTO_invoke(invokeDirect, true);
2255OP_END
2256
2257/* File: c/OP_INVOKE_STATIC_RANGE.c */
2258HANDLE_OPCODE(OP_INVOKE_STATIC_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2259 GOTO_invoke(invokeStatic, true);
2260OP_END
2261
2262/* File: c/OP_INVOKE_INTERFACE_RANGE.c */
2263HANDLE_OPCODE(OP_INVOKE_INTERFACE_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2264 GOTO_invoke(invokeInterface, true);
2265OP_END
2266
2267/* File: c/OP_UNUSED_79.c */
2268HANDLE_OPCODE(OP_UNUSED_79)
2269OP_END
2270
2271/* File: c/OP_UNUSED_7A.c */
2272HANDLE_OPCODE(OP_UNUSED_7A)
2273OP_END
2274
2275/* File: c/OP_NEG_INT.c */
2276HANDLE_UNOP(OP_NEG_INT, "neg-int", -, , )
2277OP_END
2278
2279/* File: c/OP_NOT_INT.c */
2280HANDLE_UNOP(OP_NOT_INT, "not-int", , ^ 0xffffffff, )
2281OP_END
2282
2283/* File: c/OP_NEG_LONG.c */
2284HANDLE_UNOP(OP_NEG_LONG, "neg-long", -, , _WIDE)
2285OP_END
2286
2287/* File: c/OP_NOT_LONG.c */
2288HANDLE_UNOP(OP_NOT_LONG, "not-long", , ^ 0xffffffffffffffffULL, _WIDE)
2289OP_END
2290
2291/* File: c/OP_NEG_FLOAT.c */
2292HANDLE_UNOP(OP_NEG_FLOAT, "neg-float", -, , _FLOAT)
2293OP_END
2294
2295/* File: c/OP_NEG_DOUBLE.c */
2296HANDLE_UNOP(OP_NEG_DOUBLE, "neg-double", -, , _DOUBLE)
2297OP_END
2298
2299/* File: c/OP_INT_TO_LONG.c */
2300HANDLE_NUMCONV(OP_INT_TO_LONG, "int-to-long", _INT, _WIDE)
2301OP_END
2302
2303/* File: c/OP_INT_TO_FLOAT.c */
2304HANDLE_NUMCONV(OP_INT_TO_FLOAT, "int-to-float", _INT, _FLOAT)
2305OP_END
2306
2307/* File: c/OP_INT_TO_DOUBLE.c */
2308HANDLE_NUMCONV(OP_INT_TO_DOUBLE, "int-to-double", _INT, _DOUBLE)
2309OP_END
2310
2311/* File: c/OP_LONG_TO_INT.c */
2312HANDLE_NUMCONV(OP_LONG_TO_INT, "long-to-int", _WIDE, _INT)
2313OP_END
2314
2315/* File: c/OP_LONG_TO_FLOAT.c */
2316HANDLE_NUMCONV(OP_LONG_TO_FLOAT, "long-to-float", _WIDE, _FLOAT)
2317OP_END
2318
2319/* File: c/OP_LONG_TO_DOUBLE.c */
2320HANDLE_NUMCONV(OP_LONG_TO_DOUBLE, "long-to-double", _WIDE, _DOUBLE)
2321OP_END
2322
2323/* File: c/OP_FLOAT_TO_INT.c */
2324HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_INT, "float-to-int",
2325 float, _FLOAT, s4, _INT)
2326OP_END
2327
2328/* File: c/OP_FLOAT_TO_LONG.c */
2329HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_LONG, "float-to-long",
2330 float, _FLOAT, s8, _WIDE)
2331OP_END
2332
2333/* File: c/OP_FLOAT_TO_DOUBLE.c */
2334HANDLE_NUMCONV(OP_FLOAT_TO_DOUBLE, "float-to-double", _FLOAT, _DOUBLE)
2335OP_END
2336
2337/* File: c/OP_DOUBLE_TO_INT.c */
2338HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_INT, "double-to-int",
2339 double, _DOUBLE, s4, _INT)
2340OP_END
2341
2342/* File: c/OP_DOUBLE_TO_LONG.c */
2343HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_LONG, "double-to-long",
2344 double, _DOUBLE, s8, _WIDE)
2345OP_END
2346
2347/* File: c/OP_DOUBLE_TO_FLOAT.c */
2348HANDLE_NUMCONV(OP_DOUBLE_TO_FLOAT, "double-to-float", _DOUBLE, _FLOAT)
2349OP_END
2350
2351/* File: c/OP_INT_TO_BYTE.c */
2352HANDLE_INT_TO_SMALL(OP_INT_TO_BYTE, "byte", s1)
2353OP_END
2354
2355/* File: c/OP_INT_TO_CHAR.c */
2356HANDLE_INT_TO_SMALL(OP_INT_TO_CHAR, "char", u2)
2357OP_END
2358
2359/* File: c/OP_INT_TO_SHORT.c */
2360HANDLE_INT_TO_SMALL(OP_INT_TO_SHORT, "short", s2) /* want sign bit */
2361OP_END
2362
2363/* File: c/OP_ADD_INT.c */
2364HANDLE_OP_X_INT(OP_ADD_INT, "add", +, 0)
2365OP_END
2366
2367/* File: c/OP_SUB_INT.c */
2368HANDLE_OP_X_INT(OP_SUB_INT, "sub", -, 0)
2369OP_END
2370
2371/* File: c/OP_MUL_INT.c */
2372HANDLE_OP_X_INT(OP_MUL_INT, "mul", *, 0)
2373OP_END
2374
2375/* File: c/OP_DIV_INT.c */
2376HANDLE_OP_X_INT(OP_DIV_INT, "div", /, 1)
2377OP_END
2378
2379/* File: c/OP_REM_INT.c */
2380HANDLE_OP_X_INT(OP_REM_INT, "rem", %, 2)
2381OP_END
2382
2383/* File: c/OP_AND_INT.c */
2384HANDLE_OP_X_INT(OP_AND_INT, "and", &, 0)
2385OP_END
2386
2387/* File: c/OP_OR_INT.c */
2388HANDLE_OP_X_INT(OP_OR_INT, "or", |, 0)
2389OP_END
2390
2391/* File: c/OP_XOR_INT.c */
2392HANDLE_OP_X_INT(OP_XOR_INT, "xor", ^, 0)
2393OP_END
2394
2395/* File: c/OP_SHL_INT.c */
2396HANDLE_OP_SHX_INT(OP_SHL_INT, "shl", (s4), <<)
2397OP_END
2398
2399/* File: c/OP_SHR_INT.c */
2400HANDLE_OP_SHX_INT(OP_SHR_INT, "shr", (s4), >>)
2401OP_END
2402
2403/* File: c/OP_USHR_INT.c */
2404HANDLE_OP_SHX_INT(OP_USHR_INT, "ushr", (u4), >>)
2405OP_END
2406
2407/* File: c/OP_ADD_LONG.c */
2408HANDLE_OP_X_LONG(OP_ADD_LONG, "add", +, 0)
2409OP_END
2410
2411/* File: c/OP_SUB_LONG.c */
2412HANDLE_OP_X_LONG(OP_SUB_LONG, "sub", -, 0)
2413OP_END
2414
2415/* File: c/OP_MUL_LONG.c */
2416HANDLE_OP_X_LONG(OP_MUL_LONG, "mul", *, 0)
2417OP_END
2418
2419/* File: c/OP_DIV_LONG.c */
2420HANDLE_OP_X_LONG(OP_DIV_LONG, "div", /, 1)
2421OP_END
2422
2423/* File: c/OP_REM_LONG.c */
2424HANDLE_OP_X_LONG(OP_REM_LONG, "rem", %, 2)
2425OP_END
2426
2427/* File: c/OP_AND_LONG.c */
2428HANDLE_OP_X_LONG(OP_AND_LONG, "and", &, 0)
2429OP_END
2430
2431/* File: c/OP_OR_LONG.c */
2432HANDLE_OP_X_LONG(OP_OR_LONG, "or", |, 0)
2433OP_END
2434
2435/* File: c/OP_XOR_LONG.c */
2436HANDLE_OP_X_LONG(OP_XOR_LONG, "xor", ^, 0)
2437OP_END
2438
2439/* File: c/OP_SHL_LONG.c */
2440HANDLE_OP_SHX_LONG(OP_SHL_LONG, "shl", (s8), <<)
2441OP_END
2442
2443/* File: c/OP_SHR_LONG.c */
2444HANDLE_OP_SHX_LONG(OP_SHR_LONG, "shr", (s8), >>)
2445OP_END
2446
2447/* File: c/OP_USHR_LONG.c */
2448HANDLE_OP_SHX_LONG(OP_USHR_LONG, "ushr", (u8), >>)
2449OP_END
2450
2451/* File: c/OP_ADD_FLOAT.c */
2452HANDLE_OP_X_FLOAT(OP_ADD_FLOAT, "add", +)
2453OP_END
2454
2455/* File: c/OP_SUB_FLOAT.c */
2456HANDLE_OP_X_FLOAT(OP_SUB_FLOAT, "sub", -)
2457OP_END
2458
2459/* File: c/OP_MUL_FLOAT.c */
2460HANDLE_OP_X_FLOAT(OP_MUL_FLOAT, "mul", *)
2461OP_END
2462
2463/* File: c/OP_DIV_FLOAT.c */
2464HANDLE_OP_X_FLOAT(OP_DIV_FLOAT, "div", /)
2465OP_END
2466
2467/* File: c/OP_REM_FLOAT.c */
2468HANDLE_OPCODE(OP_REM_FLOAT /*vAA, vBB, vCC*/)
2469 {
2470 u2 srcRegs;
2471 vdst = INST_AA(inst);
2472 srcRegs = FETCH(1);
2473 vsrc1 = srcRegs & 0xff;
2474 vsrc2 = srcRegs >> 8;
2475 ILOGV("|%s-float v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2476 SET_REGISTER_FLOAT(vdst,
2477 fmodf(GET_REGISTER_FLOAT(vsrc1), GET_REGISTER_FLOAT(vsrc2)));
2478 }
2479 FINISH(2);
2480OP_END
2481
2482/* File: c/OP_ADD_DOUBLE.c */
2483HANDLE_OP_X_DOUBLE(OP_ADD_DOUBLE, "add", +)
2484OP_END
2485
2486/* File: c/OP_SUB_DOUBLE.c */
2487HANDLE_OP_X_DOUBLE(OP_SUB_DOUBLE, "sub", -)
2488OP_END
2489
2490/* File: c/OP_MUL_DOUBLE.c */
2491HANDLE_OP_X_DOUBLE(OP_MUL_DOUBLE, "mul", *)
2492OP_END
2493
2494/* File: c/OP_DIV_DOUBLE.c */
2495HANDLE_OP_X_DOUBLE(OP_DIV_DOUBLE, "div", /)
2496OP_END
2497
2498/* File: c/OP_REM_DOUBLE.c */
2499HANDLE_OPCODE(OP_REM_DOUBLE /*vAA, vBB, vCC*/)
2500 {
2501 u2 srcRegs;
2502 vdst = INST_AA(inst);
2503 srcRegs = FETCH(1);
2504 vsrc1 = srcRegs & 0xff;
2505 vsrc2 = srcRegs >> 8;
2506 ILOGV("|%s-double v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2507 SET_REGISTER_DOUBLE(vdst,
2508 fmod(GET_REGISTER_DOUBLE(vsrc1), GET_REGISTER_DOUBLE(vsrc2)));
2509 }
2510 FINISH(2);
2511OP_END
2512
2513/* File: c/OP_ADD_INT_2ADDR.c */
2514HANDLE_OP_X_INT_2ADDR(OP_ADD_INT_2ADDR, "add", +, 0)
2515OP_END
2516
2517/* File: c/OP_SUB_INT_2ADDR.c */
2518HANDLE_OP_X_INT_2ADDR(OP_SUB_INT_2ADDR, "sub", -, 0)
2519OP_END
2520
2521/* File: c/OP_MUL_INT_2ADDR.c */
2522HANDLE_OP_X_INT_2ADDR(OP_MUL_INT_2ADDR, "mul", *, 0)
2523OP_END
2524
2525/* File: c/OP_DIV_INT_2ADDR.c */
2526HANDLE_OP_X_INT_2ADDR(OP_DIV_INT_2ADDR, "div", /, 1)
2527OP_END
2528
2529/* File: c/OP_REM_INT_2ADDR.c */
2530HANDLE_OP_X_INT_2ADDR(OP_REM_INT_2ADDR, "rem", %, 2)
2531OP_END
2532
2533/* File: c/OP_AND_INT_2ADDR.c */
2534HANDLE_OP_X_INT_2ADDR(OP_AND_INT_2ADDR, "and", &, 0)
2535OP_END
2536
2537/* File: c/OP_OR_INT_2ADDR.c */
2538HANDLE_OP_X_INT_2ADDR(OP_OR_INT_2ADDR, "or", |, 0)
2539OP_END
2540
2541/* File: c/OP_XOR_INT_2ADDR.c */
2542HANDLE_OP_X_INT_2ADDR(OP_XOR_INT_2ADDR, "xor", ^, 0)
2543OP_END
2544
2545/* File: c/OP_SHL_INT_2ADDR.c */
2546HANDLE_OP_SHX_INT_2ADDR(OP_SHL_INT_2ADDR, "shl", (s4), <<)
2547OP_END
2548
2549/* File: c/OP_SHR_INT_2ADDR.c */
2550HANDLE_OP_SHX_INT_2ADDR(OP_SHR_INT_2ADDR, "shr", (s4), >>)
2551OP_END
2552
2553/* File: c/OP_USHR_INT_2ADDR.c */
2554HANDLE_OP_SHX_INT_2ADDR(OP_USHR_INT_2ADDR, "ushr", (u4), >>)
2555OP_END
2556
2557/* File: c/OP_ADD_LONG_2ADDR.c */
2558HANDLE_OP_X_LONG_2ADDR(OP_ADD_LONG_2ADDR, "add", +, 0)
2559OP_END
2560
2561/* File: c/OP_SUB_LONG_2ADDR.c */
2562HANDLE_OP_X_LONG_2ADDR(OP_SUB_LONG_2ADDR, "sub", -, 0)
2563OP_END
2564
2565/* File: c/OP_MUL_LONG_2ADDR.c */
2566HANDLE_OP_X_LONG_2ADDR(OP_MUL_LONG_2ADDR, "mul", *, 0)
2567OP_END
2568
2569/* File: c/OP_DIV_LONG_2ADDR.c */
2570HANDLE_OP_X_LONG_2ADDR(OP_DIV_LONG_2ADDR, "div", /, 1)
2571OP_END
2572
2573/* File: c/OP_REM_LONG_2ADDR.c */
2574HANDLE_OP_X_LONG_2ADDR(OP_REM_LONG_2ADDR, "rem", %, 2)
2575OP_END
2576
2577/* File: c/OP_AND_LONG_2ADDR.c */
2578HANDLE_OP_X_LONG_2ADDR(OP_AND_LONG_2ADDR, "and", &, 0)
2579OP_END
2580
2581/* File: c/OP_OR_LONG_2ADDR.c */
2582HANDLE_OP_X_LONG_2ADDR(OP_OR_LONG_2ADDR, "or", |, 0)
2583OP_END
2584
2585/* File: c/OP_XOR_LONG_2ADDR.c */
2586HANDLE_OP_X_LONG_2ADDR(OP_XOR_LONG_2ADDR, "xor", ^, 0)
2587OP_END
2588
2589/* File: c/OP_SHL_LONG_2ADDR.c */
2590HANDLE_OP_SHX_LONG_2ADDR(OP_SHL_LONG_2ADDR, "shl", (s8), <<)
2591OP_END
2592
2593/* File: c/OP_SHR_LONG_2ADDR.c */
2594HANDLE_OP_SHX_LONG_2ADDR(OP_SHR_LONG_2ADDR, "shr", (s8), >>)
2595OP_END
2596
2597/* File: c/OP_USHR_LONG_2ADDR.c */
2598HANDLE_OP_SHX_LONG_2ADDR(OP_USHR_LONG_2ADDR, "ushr", (u8), >>)
2599OP_END
2600
2601/* File: c/OP_ADD_FLOAT_2ADDR.c */
2602HANDLE_OP_X_FLOAT_2ADDR(OP_ADD_FLOAT_2ADDR, "add", +)
2603OP_END
2604
2605/* File: c/OP_SUB_FLOAT_2ADDR.c */
2606HANDLE_OP_X_FLOAT_2ADDR(OP_SUB_FLOAT_2ADDR, "sub", -)
2607OP_END
2608
2609/* File: c/OP_MUL_FLOAT_2ADDR.c */
2610HANDLE_OP_X_FLOAT_2ADDR(OP_MUL_FLOAT_2ADDR, "mul", *)
2611OP_END
2612
2613/* File: c/OP_DIV_FLOAT_2ADDR.c */
2614HANDLE_OP_X_FLOAT_2ADDR(OP_DIV_FLOAT_2ADDR, "div", /)
2615OP_END
2616
2617/* File: c/OP_REM_FLOAT_2ADDR.c */
2618HANDLE_OPCODE(OP_REM_FLOAT_2ADDR /*vA, vB*/)
2619 vdst = INST_A(inst);
2620 vsrc1 = INST_B(inst);
2621 ILOGV("|%s-float-2addr v%d,v%d", "mod", vdst, vsrc1);
2622 SET_REGISTER_FLOAT(vdst,
2623 fmodf(GET_REGISTER_FLOAT(vdst), GET_REGISTER_FLOAT(vsrc1)));
2624 FINISH(1);
2625OP_END
2626
2627/* File: c/OP_ADD_DOUBLE_2ADDR.c */
2628HANDLE_OP_X_DOUBLE_2ADDR(OP_ADD_DOUBLE_2ADDR, "add", +)
2629OP_END
2630
2631/* File: c/OP_SUB_DOUBLE_2ADDR.c */
2632HANDLE_OP_X_DOUBLE_2ADDR(OP_SUB_DOUBLE_2ADDR, "sub", -)
2633OP_END
2634
2635/* File: c/OP_MUL_DOUBLE_2ADDR.c */
2636HANDLE_OP_X_DOUBLE_2ADDR(OP_MUL_DOUBLE_2ADDR, "mul", *)
2637OP_END
2638
2639/* File: c/OP_DIV_DOUBLE_2ADDR.c */
2640HANDLE_OP_X_DOUBLE_2ADDR(OP_DIV_DOUBLE_2ADDR, "div", /)
2641OP_END
2642
2643/* File: c/OP_REM_DOUBLE_2ADDR.c */
2644HANDLE_OPCODE(OP_REM_DOUBLE_2ADDR /*vA, vB*/)
2645 vdst = INST_A(inst);
2646 vsrc1 = INST_B(inst);
2647 ILOGV("|%s-double-2addr v%d,v%d", "mod", vdst, vsrc1);
2648 SET_REGISTER_DOUBLE(vdst,
2649 fmod(GET_REGISTER_DOUBLE(vdst), GET_REGISTER_DOUBLE(vsrc1)));
2650 FINISH(1);
2651OP_END
2652
2653/* File: c/OP_ADD_INT_LIT16.c */
2654HANDLE_OP_X_INT_LIT16(OP_ADD_INT_LIT16, "add", +, 0)
2655OP_END
2656
2657/* File: c/OP_RSUB_INT.c */
2658HANDLE_OPCODE(OP_RSUB_INT /*vA, vB, #+CCCC*/)
2659 {
2660 vdst = INST_A(inst);
2661 vsrc1 = INST_B(inst);
2662 vsrc2 = FETCH(1);
2663 ILOGV("|rsub-int v%d,v%d,#+0x%04x", vdst, vsrc1, vsrc2);
2664 SET_REGISTER(vdst, (s2) vsrc2 - (s4) GET_REGISTER(vsrc1));
2665 }
2666 FINISH(2);
2667OP_END
2668
2669/* File: c/OP_MUL_INT_LIT16.c */
2670HANDLE_OP_X_INT_LIT16(OP_MUL_INT_LIT16, "mul", *, 0)
2671OP_END
2672
2673/* File: c/OP_DIV_INT_LIT16.c */
2674HANDLE_OP_X_INT_LIT16(OP_DIV_INT_LIT16, "div", /, 1)
2675OP_END
2676
2677/* File: c/OP_REM_INT_LIT16.c */
2678HANDLE_OP_X_INT_LIT16(OP_REM_INT_LIT16, "rem", %, 2)
2679OP_END
2680
2681/* File: c/OP_AND_INT_LIT16.c */
2682HANDLE_OP_X_INT_LIT16(OP_AND_INT_LIT16, "and", &, 0)
2683OP_END
2684
2685/* File: c/OP_OR_INT_LIT16.c */
2686HANDLE_OP_X_INT_LIT16(OP_OR_INT_LIT16, "or", |, 0)
2687OP_END
2688
2689/* File: c/OP_XOR_INT_LIT16.c */
2690HANDLE_OP_X_INT_LIT16(OP_XOR_INT_LIT16, "xor", ^, 0)
2691OP_END
2692
2693/* File: c/OP_ADD_INT_LIT8.c */
2694HANDLE_OP_X_INT_LIT8(OP_ADD_INT_LIT8, "add", +, 0)
2695OP_END
2696
2697/* File: c/OP_RSUB_INT_LIT8.c */
2698HANDLE_OPCODE(OP_RSUB_INT_LIT8 /*vAA, vBB, #+CC*/)
2699 {
2700 u2 litInfo;
2701 vdst = INST_AA(inst);
2702 litInfo = FETCH(1);
2703 vsrc1 = litInfo & 0xff;
2704 vsrc2 = litInfo >> 8;
2705 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", "rsub", vdst, vsrc1, vsrc2);
2706 SET_REGISTER(vdst, (s1) vsrc2 - (s4) GET_REGISTER(vsrc1));
2707 }
2708 FINISH(2);
2709OP_END
2710
2711/* File: c/OP_MUL_INT_LIT8.c */
2712HANDLE_OP_X_INT_LIT8(OP_MUL_INT_LIT8, "mul", *, 0)
2713OP_END
2714
2715/* File: c/OP_DIV_INT_LIT8.c */
2716HANDLE_OP_X_INT_LIT8(OP_DIV_INT_LIT8, "div", /, 1)
2717OP_END
2718
2719/* File: c/OP_REM_INT_LIT8.c */
2720HANDLE_OP_X_INT_LIT8(OP_REM_INT_LIT8, "rem", %, 2)
2721OP_END
2722
2723/* File: c/OP_AND_INT_LIT8.c */
2724HANDLE_OP_X_INT_LIT8(OP_AND_INT_LIT8, "and", &, 0)
2725OP_END
2726
2727/* File: c/OP_OR_INT_LIT8.c */
2728HANDLE_OP_X_INT_LIT8(OP_OR_INT_LIT8, "or", |, 0)
2729OP_END
2730
2731/* File: c/OP_XOR_INT_LIT8.c */
2732HANDLE_OP_X_INT_LIT8(OP_XOR_INT_LIT8, "xor", ^, 0)
2733OP_END
2734
2735/* File: c/OP_SHL_INT_LIT8.c */
2736HANDLE_OP_SHX_INT_LIT8(OP_SHL_INT_LIT8, "shl", (s4), <<)
2737OP_END
2738
2739/* File: c/OP_SHR_INT_LIT8.c */
2740HANDLE_OP_SHX_INT_LIT8(OP_SHR_INT_LIT8, "shr", (s4), >>)
2741OP_END
2742
2743/* File: c/OP_USHR_INT_LIT8.c */
2744HANDLE_OP_SHX_INT_LIT8(OP_USHR_INT_LIT8, "ushr", (u4), >>)
2745OP_END
2746
2747/* File: c/OP_UNUSED_E3.c */
2748HANDLE_OPCODE(OP_UNUSED_E3)
2749OP_END
2750
2751/* File: c/OP_UNUSED_E4.c */
2752HANDLE_OPCODE(OP_UNUSED_E4)
2753OP_END
2754
2755/* File: c/OP_UNUSED_E5.c */
2756HANDLE_OPCODE(OP_UNUSED_E5)
2757OP_END
2758
2759/* File: c/OP_UNUSED_E6.c */
2760HANDLE_OPCODE(OP_UNUSED_E6)
2761OP_END
2762
2763/* File: c/OP_UNUSED_E7.c */
2764HANDLE_OPCODE(OP_UNUSED_E7)
2765OP_END
2766
2767/* File: c/OP_UNUSED_E8.c */
2768HANDLE_OPCODE(OP_UNUSED_E8)
2769OP_END
2770
2771/* File: c/OP_UNUSED_E9.c */
2772HANDLE_OPCODE(OP_UNUSED_E9)
2773OP_END
2774
2775/* File: c/OP_UNUSED_EA.c */
2776HANDLE_OPCODE(OP_UNUSED_EA)
2777OP_END
2778
2779/* File: c/OP_UNUSED_EB.c */
2780HANDLE_OPCODE(OP_UNUSED_EB)
2781OP_END
2782
2783/* File: c/OP_UNUSED_EC.c */
2784HANDLE_OPCODE(OP_UNUSED_EC)
2785OP_END
2786
2787/* File: c/OP_UNUSED_ED.c */
2788HANDLE_OPCODE(OP_UNUSED_ED)
2789OP_END
2790
2791/* File: c/OP_EXECUTE_INLINE.c */
2792HANDLE_OPCODE(OP_EXECUTE_INLINE /*vB, {vD, vE, vF, vG}, inline@CCCC*/)
2793 {
2794 /*
2795 * This has the same form as other method calls, but we ignore
2796 * the 5th argument (vA). This is chiefly because the first four
2797 * arguments to a function on ARM are in registers.
2798 *
2799 * We only set the arguments that are actually used, leaving
2800 * the rest uninitialized. We're assuming that, if the method
2801 * needs them, they'll be specified in the call.
2802 *
2803 * This annoys gcc when optimizations are enabled, causing a
2804 * "may be used uninitialized" warning. We can quiet the warnings
2805 * for a slight penalty (5%: 373ns vs. 393ns on empty method). Note
2806 * that valgrind is perfectly happy with this arrangement, because
2807 * the uninitialiezd values are never actually used.
2808 */
2809 u4 arg0, arg1, arg2, arg3;
2810 //arg0 = arg1 = arg2 = arg3 = 0;
2811
2812 EXPORT_PC();
2813
2814 vsrc1 = INST_B(inst); /* #of args */
2815 ref = FETCH(1); /* inline call "ref" */
2816 vdst = FETCH(2); /* 0-4 register indices */
2817 ILOGV("|execute-inline args=%d @%d {regs=0x%04x}",
2818 vsrc1, ref, vdst);
2819
2820 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
2821 assert(vsrc1 <= 4);
2822
2823 switch (vsrc1) {
2824 case 4:
2825 arg3 = GET_REGISTER(vdst >> 12);
2826 /* fall through */
2827 case 3:
2828 arg2 = GET_REGISTER((vdst & 0x0f00) >> 8);
2829 /* fall through */
2830 case 2:
2831 arg1 = GET_REGISTER((vdst & 0x00f0) >> 4);
2832 /* fall through */
2833 case 1:
2834 arg0 = GET_REGISTER(vdst & 0x0f);
2835 /* fall through */
2836 default: // case 0
2837 ;
2838 }
2839
2840#if INTERP_TYPE == INTERP_DBG
2841 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
2842 GOTO_exceptionThrown();
2843#else
2844 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
2845 GOTO_exceptionThrown();
2846#endif
2847 }
2848 FINISH(3);
2849OP_END
2850
2851/* File: c/OP_UNUSED_EF.c */
2852HANDLE_OPCODE(OP_UNUSED_EF)
2853OP_END
2854
2855/* File: c/OP_INVOKE_DIRECT_EMPTY.c */
2856HANDLE_OPCODE(OP_INVOKE_DIRECT_EMPTY /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2857#if INTERP_TYPE != INTERP_DBG
2858 //LOGI("Ignoring empty\n");
2859 FINISH(3);
2860#else
2861 if (!gDvm.debuggerActive) {
2862 //LOGI("Skipping empty\n");
2863 FINISH(3); // don't want it to show up in profiler output
2864 } else {
2865 //LOGI("Running empty\n");
2866 /* fall through to OP_INVOKE_DIRECT */
2867 GOTO_invoke(invokeDirect, false);
2868 }
2869#endif
2870OP_END
2871
2872/* File: c/OP_UNUSED_F1.c */
2873HANDLE_OPCODE(OP_UNUSED_F1)
2874OP_END
2875
2876/* File: c/OP_IGET_QUICK.c */
2877HANDLE_IGET_X_QUICK(OP_IGET_QUICK, "", Int, )
2878OP_END
2879
2880/* File: c/OP_IGET_WIDE_QUICK.c */
2881HANDLE_IGET_X_QUICK(OP_IGET_WIDE_QUICK, "-wide", Long, _WIDE)
2882OP_END
2883
2884/* File: c/OP_IGET_OBJECT_QUICK.c */
2885HANDLE_IGET_X_QUICK(OP_IGET_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
2886OP_END
2887
2888/* File: c/OP_IPUT_QUICK.c */
2889HANDLE_IPUT_X_QUICK(OP_IPUT_QUICK, "", Int, )
2890OP_END
2891
2892/* File: c/OP_IPUT_WIDE_QUICK.c */
2893HANDLE_IPUT_X_QUICK(OP_IPUT_WIDE_QUICK, "-wide", Long, _WIDE)
2894OP_END
2895
2896/* File: c/OP_IPUT_OBJECT_QUICK.c */
2897HANDLE_IPUT_X_QUICK(OP_IPUT_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
2898OP_END
2899
2900/* File: c/OP_INVOKE_VIRTUAL_QUICK.c */
2901HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2902 GOTO_invoke(invokeVirtualQuick, false);
2903OP_END
2904
2905/* File: c/OP_INVOKE_VIRTUAL_QUICK_RANGE.c */
2906HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK_RANGE/*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2907 GOTO_invoke(invokeVirtualQuick, true);
2908OP_END
2909
2910/* File: c/OP_INVOKE_SUPER_QUICK.c */
2911HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2912 GOTO_invoke(invokeSuperQuick, false);
2913OP_END
2914
2915/* File: c/OP_INVOKE_SUPER_QUICK_RANGE.c */
2916HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2917 GOTO_invoke(invokeSuperQuick, true);
2918OP_END
2919
2920/* File: c/OP_UNUSED_FC.c */
2921HANDLE_OPCODE(OP_UNUSED_FC)
2922OP_END
2923
2924/* File: c/OP_UNUSED_FD.c */
2925HANDLE_OPCODE(OP_UNUSED_FD)
2926OP_END
2927
2928/* File: c/OP_UNUSED_FE.c */
2929HANDLE_OPCODE(OP_UNUSED_FE)
2930OP_END
2931
2932/* File: c/OP_UNUSED_FF.c */
2933HANDLE_OPCODE(OP_UNUSED_FF)
2934 /*
2935 * In portable interp, most unused opcodes will fall through to here.
2936 */
2937 LOGE("unknown opcode 0x%02x\n", INST_INST(inst));
2938 dvmAbort();
2939 FINISH(1);
2940OP_END
2941
2942/* File: cstubs/entry.c */
2943/*
2944 * Handler function table, one entry per opcode.
2945 */
2946#undef H
2947#define H(_op) dvmMterp_##_op
2948DEFINE_GOTO_TABLE(gDvmMterpHandlers)
2949
2950#undef H
2951#define H(_op) #_op
2952DEFINE_GOTO_TABLE(gDvmMterpHandlerNames)
2953
2954#include <setjmp.h>
2955
2956/*
2957 * C mterp entry point. This just calls the various C fallbacks, making
2958 * this a slow but portable interpeter.
2959 *
2960 * This is only used for the "allstubs" variant.
2961 */
2962bool dvmMterpStdRun(MterpGlue* glue)
2963{
2964 jmp_buf jmpBuf;
2965 int changeInterp;
2966
2967 glue->bailPtr = &jmpBuf;
2968
2969 /*
2970 * We want to return "changeInterp" as a boolean, but we can't return
2971 * zero through longjmp, so we return (boolean+1).
2972 */
2973 changeInterp = setjmp(jmpBuf) -1;
2974 if (changeInterp >= 0) {
2975 Thread* threadSelf = dvmThreadSelf();
2976 LOGVV("mterp threadid=%d returning %d\n",
2977 threadSelf->threadId, changeInterp);
2978 return changeInterp;
2979 }
2980
2981 /*
2982 * We may not be starting at a point where we're executing instructions.
2983 * We need to pick up where the other interpreter left off.
2984 *
2985 * In some cases we need to call into a throw/return handler which
2986 * will do some processing and then either return to us (updating "glue")
2987 * or longjmp back out.
2988 */
2989 switch (glue->entryPoint) {
2990 case kInterpEntryInstr:
2991 /* just start at the start */
2992 break;
2993 case kInterpEntryReturn:
2994 dvmMterp_returnFromMethod(glue);
2995 break;
2996 case kInterpEntryThrow:
2997 dvmMterp_exceptionThrown(glue);
2998 break;
2999 default:
3000 dvmAbort();
3001 }
3002
3003 /* run until somebody longjmp()s out */
3004 while (true) {
3005 typedef void (*Handler)(MterpGlue* glue);
3006
3007 u2 inst = /*glue->*/pc[0];
3008 Handler handler = (Handler) gDvmMterpHandlers[inst & 0xff];
3009 LOGVV("handler %p %s\n",
3010 handler, (const char*) gDvmMterpHandlerNames[inst & 0xff]);
3011 (*handler)(glue);
3012 }
3013}
3014
3015/*
3016 * C mterp exit point. Call here to bail out of the interpreter.
3017 */
3018void dvmMterpStdBail(MterpGlue* glue, bool changeInterp)
3019{
3020 jmp_buf* pJmpBuf = glue->bailPtr;
3021 longjmp(*pJmpBuf, ((int)changeInterp)+1);
3022}
3023
3024
3025/* File: c/gotoTargets.c */
3026/*
3027 * C footer. This has some common code shared by the various targets.
3028 */
3029
3030/*
3031 * Everything from here on is a "goto target". In the basic interpreter
3032 * we jump into these targets and then jump directly to the handler for
3033 * next instruction. Here, these are subroutines that return to the caller.
3034 */
3035
3036GOTO_TARGET(filledNewArray, bool methodCallRange)
3037 {
3038 ClassObject* arrayClass;
3039 ArrayObject* newArray;
3040 u4* contents;
3041 char typeCh;
3042 int i;
3043 u4 arg5;
3044
3045 EXPORT_PC();
3046
3047 ref = FETCH(1); /* class ref */
3048 vdst = FETCH(2); /* first 4 regs -or- range base */
3049
3050 if (methodCallRange) {
3051 vsrc1 = INST_AA(inst); /* #of elements */
3052 arg5 = -1; /* silence compiler warning */
3053 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
3054 vsrc1, ref, vdst, vdst+vsrc1-1);
3055 } else {
3056 arg5 = INST_A(inst);
3057 vsrc1 = INST_B(inst); /* #of elements */
3058 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
3059 vsrc1, ref, vdst, arg5);
3060 }
3061
3062 /*
3063 * Resolve the array class.
3064 */
3065 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
3066 if (arrayClass == NULL) {
3067 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
3068 if (arrayClass == NULL)
3069 GOTO_exceptionThrown();
3070 }
3071 /*
3072 if (!dvmIsArrayClass(arrayClass)) {
3073 dvmThrowException("Ljava/lang/RuntimeError;",
3074 "filled-new-array needs array class");
3075 GOTO_exceptionThrown();
3076 }
3077 */
3078 /* verifier guarantees this is an array class */
3079 assert(dvmIsArrayClass(arrayClass));
3080 assert(dvmIsClassInitialized(arrayClass));
3081
3082 /*
3083 * Create an array of the specified type.
3084 */
3085 LOGVV("+++ filled-new-array type is '%s'\n", arrayClass->descriptor);
3086 typeCh = arrayClass->descriptor[1];
3087 if (typeCh == 'D' || typeCh == 'J') {
3088 /* category 2 primitives not allowed */
3089 dvmThrowException("Ljava/lang/RuntimeError;",
3090 "bad filled array req");
3091 GOTO_exceptionThrown();
3092 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
3093 /* TODO: requires multiple "fill in" loops with different widths */
3094 LOGE("non-int primitives not implemented\n");
3095 dvmThrowException("Ljava/lang/InternalError;",
3096 "filled-new-array not implemented for anything but 'int'");
3097 GOTO_exceptionThrown();
3098 }
3099
3100 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
3101 if (newArray == NULL)
3102 GOTO_exceptionThrown();
3103
3104 /*
3105 * Fill in the elements. It's legal for vsrc1 to be zero.
3106 */
3107 contents = (u4*) newArray->contents;
3108 if (methodCallRange) {
3109 for (i = 0; i < vsrc1; i++)
3110 contents[i] = GET_REGISTER(vdst+i);
3111 } else {
3112 assert(vsrc1 <= 5);
3113 if (vsrc1 == 5) {
3114 contents[4] = GET_REGISTER(arg5);
3115 vsrc1--;
3116 }
3117 for (i = 0; i < vsrc1; i++) {
3118 contents[i] = GET_REGISTER(vdst & 0x0f);
3119 vdst >>= 4;
3120 }
3121 }
3122
3123 retval.l = newArray;
3124 }
3125 FINISH(3);
3126GOTO_TARGET_END
3127
3128
3129GOTO_TARGET(invokeVirtual, bool methodCallRange)
3130 {
3131 Method* baseMethod;
3132 Object* thisPtr;
3133
3134 EXPORT_PC();
3135
3136 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3137 ref = FETCH(1); /* method ref */
3138 vdst = FETCH(2); /* 4 regs -or- first reg */
3139
3140 /*
3141 * The object against which we are executing a method is always
3142 * in the first argument.
3143 */
3144 if (methodCallRange) {
3145 assert(vsrc1 > 0);
3146 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
3147 vsrc1, ref, vdst, vdst+vsrc1-1);
3148 thisPtr = (Object*) GET_REGISTER(vdst);
3149 } else {
3150 assert((vsrc1>>4) > 0);
3151 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
3152 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3153 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3154 }
3155
3156 if (!checkForNull(thisPtr))
3157 GOTO_exceptionThrown();
3158
3159 /*
3160 * Resolve the method. This is the correct method for the static
3161 * type of the object. We also verify access permissions here.
3162 */
3163 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3164 if (baseMethod == NULL) {
3165 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3166 if (baseMethod == NULL) {
3167 ILOGV("+ unknown method or access denied\n");
3168 GOTO_exceptionThrown();
3169 }
3170 }
3171
3172 /*
3173 * Combine the object we found with the vtable offset in the
3174 * method.
3175 */
3176 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
3177 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
3178
3179#if 0
3180 if (dvmIsAbstractMethod(methodToCall)) {
3181 /*
3182 * This can happen if you create two classes, Base and Sub, where
3183 * Sub is a sub-class of Base. Declare a protected abstract
3184 * method foo() in Base, and invoke foo() from a method in Base.
3185 * Base is an "abstract base class" and is never instantiated
3186 * directly. Now, Override foo() in Sub, and use Sub. This
3187 * Works fine unless Sub stops providing an implementation of
3188 * the method.
3189 */
3190 dvmThrowException("Ljava/lang/AbstractMethodError;",
3191 "abstract method not implemented");
3192 GOTO_exceptionThrown();
3193 }
3194#else
3195 assert(!dvmIsAbstractMethod(methodToCall) ||
3196 methodToCall->nativeFunc != NULL);
3197#endif
3198
3199 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s\n",
3200 baseMethod->clazz->descriptor, baseMethod->name,
3201 (u4) baseMethod->methodIndex,
3202 methodToCall->clazz->descriptor, methodToCall->name);
3203 assert(methodToCall != NULL);
3204
3205#if 0
3206 if (vsrc1 != methodToCall->insSize) {
3207 LOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s\n",
3208 baseMethod->clazz->descriptor, baseMethod->name,
3209 (u4) baseMethod->methodIndex,
3210 methodToCall->clazz->descriptor, methodToCall->name);
3211 //dvmDumpClass(baseMethod->clazz);
3212 //dvmDumpClass(methodToCall->clazz);
3213 dvmDumpAllClasses(0);
3214 }
3215#endif
3216
3217 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3218 }
3219GOTO_TARGET_END
3220
3221GOTO_TARGET(invokeSuper, bool methodCallRange)
3222 {
3223 Method* baseMethod;
3224 u2 thisReg;
3225
3226 EXPORT_PC();
3227
3228 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3229 ref = FETCH(1); /* method ref */
3230 vdst = FETCH(2); /* 4 regs -or- first reg */
3231
3232 if (methodCallRange) {
3233 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
3234 vsrc1, ref, vdst, vdst+vsrc1-1);
3235 thisReg = vdst;
3236 } else {
3237 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
3238 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3239 thisReg = vdst & 0x0f;
3240 }
3241 /* impossible in well-formed code, but we must check nevertheless */
3242 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3243 GOTO_exceptionThrown();
3244
3245 /*
3246 * Resolve the method. This is the correct method for the static
3247 * type of the object. We also verify access permissions here.
3248 * The first arg to dvmResolveMethod() is just the referring class
3249 * (used for class loaders and such), so we don't want to pass
3250 * the superclass into the resolution call.
3251 */
3252 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3253 if (baseMethod == NULL) {
3254 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3255 if (baseMethod == NULL) {
3256 ILOGV("+ unknown method or access denied\n");
3257 GOTO_exceptionThrown();
3258 }
3259 }
3260
3261 /*
3262 * Combine the object we found with the vtable offset in the
3263 * method's class.
3264 *
3265 * We're using the current method's class' superclass, not the
3266 * superclass of "this". This is because we might be executing
3267 * in a method inherited from a superclass, and we want to run
3268 * in that class' superclass.
3269 */
3270 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
3271 /*
3272 * Method does not exist in the superclass. Could happen if
3273 * superclass gets updated.
3274 */
3275 dvmThrowException("Ljava/lang/NoSuchMethodError;",
3276 baseMethod->name);
3277 GOTO_exceptionThrown();
3278 }
3279 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
3280#if 0
3281 if (dvmIsAbstractMethod(methodToCall)) {
3282 dvmThrowException("Ljava/lang/AbstractMethodError;",
3283 "abstract method not implemented");
3284 GOTO_exceptionThrown();
3285 }
3286#else
3287 assert(!dvmIsAbstractMethod(methodToCall) ||
3288 methodToCall->nativeFunc != NULL);
3289#endif
3290 LOGVV("+++ base=%s.%s super-virtual=%s.%s\n",
3291 baseMethod->clazz->descriptor, baseMethod->name,
3292 methodToCall->clazz->descriptor, methodToCall->name);
3293 assert(methodToCall != NULL);
3294
3295 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3296 }
3297GOTO_TARGET_END
3298
3299GOTO_TARGET(invokeInterface, bool methodCallRange)
3300 {
3301 Object* thisPtr;
3302 ClassObject* thisClass;
3303
3304 EXPORT_PC();
3305
3306 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3307 ref = FETCH(1); /* method ref */
3308 vdst = FETCH(2); /* 4 regs -or- first reg */
3309
3310 /*
3311 * The object against which we are executing a method is always
3312 * in the first argument.
3313 */
3314 if (methodCallRange) {
3315 assert(vsrc1 > 0);
3316 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
3317 vsrc1, ref, vdst, vdst+vsrc1-1);
3318 thisPtr = (Object*) GET_REGISTER(vdst);
3319 } else {
3320 assert((vsrc1>>4) > 0);
3321 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
3322 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3323 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3324 }
3325 if (!checkForNull(thisPtr))
3326 GOTO_exceptionThrown();
3327
3328 thisClass = thisPtr->clazz;
3329
3330 /*
3331 * Given a class and a method index, find the Method* with the
3332 * actual code we want to execute.
3333 */
3334 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
3335 methodClassDex);
3336 if (methodToCall == NULL) {
3337 assert(dvmCheckException(self));
3338 GOTO_exceptionThrown();
3339 }
3340
3341 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3342 }
3343GOTO_TARGET_END
3344
3345GOTO_TARGET(invokeDirect, bool methodCallRange)
3346 {
3347 u2 thisReg;
3348
3349 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3350 ref = FETCH(1); /* method ref */
3351 vdst = FETCH(2); /* 4 regs -or- first reg */
3352
3353 EXPORT_PC();
3354
3355 if (methodCallRange) {
3356 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
3357 vsrc1, ref, vdst, vdst+vsrc1-1);
3358 thisReg = vdst;
3359 } else {
3360 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
3361 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3362 thisReg = vdst & 0x0f;
3363 }
3364 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3365 GOTO_exceptionThrown();
3366
3367 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3368 if (methodToCall == NULL) {
3369 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
3370 METHOD_DIRECT);
3371 if (methodToCall == NULL) {
3372 ILOGV("+ unknown direct method\n"); // should be impossible
3373 GOTO_exceptionThrown();
3374 }
3375 }
3376 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3377 }
3378GOTO_TARGET_END
3379
3380GOTO_TARGET(invokeStatic, bool methodCallRange)
3381 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3382 ref = FETCH(1); /* method ref */
3383 vdst = FETCH(2); /* 4 regs -or- first reg */
3384
3385 EXPORT_PC();
3386
3387 if (methodCallRange)
3388 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
3389 vsrc1, ref, vdst, vdst+vsrc1-1);
3390 else
3391 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
3392 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3393
3394 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3395 if (methodToCall == NULL) {
3396 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
3397 if (methodToCall == NULL) {
3398 ILOGV("+ unknown method\n");
3399 GOTO_exceptionThrown();
3400 }
3401 }
3402 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3403GOTO_TARGET_END
3404
3405GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
3406 {
3407 Object* thisPtr;
3408
3409 EXPORT_PC();
3410
3411 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3412 ref = FETCH(1); /* vtable index */
3413 vdst = FETCH(2); /* 4 regs -or- first reg */
3414
3415 /*
3416 * The object against which we are executing a method is always
3417 * in the first argument.
3418 */
3419 if (methodCallRange) {
3420 assert(vsrc1 > 0);
3421 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3422 vsrc1, ref, vdst, vdst+vsrc1-1);
3423 thisPtr = (Object*) GET_REGISTER(vdst);
3424 } else {
3425 assert((vsrc1>>4) > 0);
3426 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
3427 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3428 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3429 }
3430
3431 if (!checkForNull(thisPtr))
3432 GOTO_exceptionThrown();
3433
3434 /*
3435 * Combine the object we found with the vtable offset in the
3436 * method.
3437 */
3438 assert(ref < thisPtr->clazz->vtableCount);
3439 methodToCall = thisPtr->clazz->vtable[ref];
3440
3441#if 0
3442 if (dvmIsAbstractMethod(methodToCall)) {
3443 dvmThrowException("Ljava/lang/AbstractMethodError;",
3444 "abstract method not implemented");
3445 GOTO_exceptionThrown();
3446 }
3447#else
3448 assert(!dvmIsAbstractMethod(methodToCall) ||
3449 methodToCall->nativeFunc != NULL);
3450#endif
3451
3452 LOGVV("+++ virtual[%d]=%s.%s\n",
3453 ref, methodToCall->clazz->descriptor, methodToCall->name);
3454 assert(methodToCall != NULL);
3455
3456 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3457 }
3458GOTO_TARGET_END
3459
3460GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
3461 {
3462 u2 thisReg;
3463
3464 EXPORT_PC();
3465
3466 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3467 ref = FETCH(1); /* vtable index */
3468 vdst = FETCH(2); /* 4 regs -or- first reg */
3469
3470 if (methodCallRange) {
3471 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3472 vsrc1, ref, vdst, vdst+vsrc1-1);
3473 thisReg = vdst;
3474 } else {
3475 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
3476 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3477 thisReg = vdst & 0x0f;
3478 }
3479 /* impossible in well-formed code, but we must check nevertheless */
3480 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3481 GOTO_exceptionThrown();
3482
3483#if 0 /* impossible in optimized + verified code */
3484 if (ref >= curMethod->clazz->super->vtableCount) {
3485 dvmThrowException("Ljava/lang/NoSuchMethodError;", NULL);
3486 GOTO_exceptionThrown();
3487 }
3488#else
3489 assert(ref < curMethod->clazz->super->vtableCount);
3490#endif
3491
3492 /*
3493 * Combine the object we found with the vtable offset in the
3494 * method's class.
3495 *
3496 * We're using the current method's class' superclass, not the
3497 * superclass of "this". This is because we might be executing
3498 * in a method inherited from a superclass, and we want to run
3499 * in the method's class' superclass.
3500 */
3501 methodToCall = curMethod->clazz->super->vtable[ref];
3502
3503#if 0
3504 if (dvmIsAbstractMethod(methodToCall)) {
3505 dvmThrowException("Ljava/lang/AbstractMethodError;",
3506 "abstract method not implemented");
3507 GOTO_exceptionThrown();
3508 }
3509#else
3510 assert(!dvmIsAbstractMethod(methodToCall) ||
3511 methodToCall->nativeFunc != NULL);
3512#endif
3513 LOGVV("+++ super-virtual[%d]=%s.%s\n",
3514 ref, methodToCall->clazz->descriptor, methodToCall->name);
3515 assert(methodToCall != NULL);
3516
3517 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3518 }
3519GOTO_TARGET_END
3520
3521
3522
3523 /*
3524 * General handling for return-void, return, and return-wide. Put the
3525 * return value in "retval" before jumping here.
3526 */
3527GOTO_TARGET(returnFromMethod)
3528 {
3529 StackSaveArea* saveArea;
3530
3531 /*
3532 * We must do this BEFORE we pop the previous stack frame off, so
3533 * that the GC can see the return value (if any) in the local vars.
3534 *
3535 * Since this is now an interpreter switch point, we must do it before
3536 * we do anything at all.
3537 */
3538 PERIODIC_CHECKS(kInterpEntryReturn, 0);
3539
3540 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
3541 retval.j, curMethod->clazz->descriptor, curMethod->name,
3542 curMethod->signature);
3543 //DUMP_REGS(curMethod, fp);
3544
3545 saveArea = SAVEAREA_FROM_FP(fp);
3546
3547#ifdef EASY_GDB
3548 debugSaveArea = saveArea;
3549#endif
3550#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3551 TRACE_METHOD_EXIT(self, curMethod);
3552#endif
3553
3554 /* back up to previous frame and see if we hit a break */
3555 fp = saveArea->prevFrame;
3556 assert(fp != NULL);
3557 if (dvmIsBreakFrame(fp)) {
3558 /* bail without popping the method frame from stack */
3559 LOGVV("+++ returned into break frame\n");
3560 GOTO_bail();
3561 }
3562
3563 /* update thread FP, and reset local variables */
3564 self->curFrame = fp;
3565 curMethod = SAVEAREA_FROM_FP(fp)->method;
3566 //methodClass = curMethod->clazz;
3567 methodClassDex = curMethod->clazz->pDvmDex;
3568 pc = saveArea->savedPc;
3569 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
3570 curMethod->name, curMethod->signature);
3571
3572 /* use FINISH on the caller's invoke instruction */
3573 //u2 invokeInstr = INST_INST(FETCH(0));
3574 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3575 invokeInstr <= OP_INVOKE_INTERFACE*/)
3576 {
3577 FINISH(3);
3578 } else {
3579 //LOGE("Unknown invoke instr %02x at %d\n",
3580 // invokeInstr, (int) (pc - curMethod->insns));
3581 assert(false);
3582 }
3583 }
3584GOTO_TARGET_END
3585
3586
3587 /*
3588 * Jump here when the code throws an exception.
3589 *
3590 * By the time we get here, the Throwable has been created and the stack
3591 * trace has been saved off.
3592 */
3593GOTO_TARGET(exceptionThrown)
3594 {
3595 Object* exception;
3596 int catchRelPc;
3597
3598 /*
3599 * Since this is now an interpreter switch point, we must do it before
3600 * we do anything at all.
3601 */
3602 PERIODIC_CHECKS(kInterpEntryThrow, 0);
3603
3604 /*
3605 * We save off the exception and clear the exception status. While
3606 * processing the exception we might need to load some Throwable
3607 * classes, and we don't want class loader exceptions to get
3608 * confused with this one.
3609 */
3610 assert(dvmCheckException(self));
3611 exception = dvmGetException(self);
3612 dvmAddTrackedAlloc(exception, self);
3613 dvmClearException(self);
3614
3615 LOGV("Handling exception %s at %s:%d\n",
3616 exception->clazz->descriptor, curMethod->name,
3617 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3618
3619#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3620 /*
3621 * Tell the debugger about it.
3622 *
3623 * TODO: if the exception was thrown by interpreted code, control
3624 * fell through native, and then back to us, we will report the
3625 * exception at the point of the throw and again here. We can avoid
3626 * this by not reporting exceptions when we jump here directly from
3627 * the native call code above, but then we won't report exceptions
3628 * that were thrown *from* the JNI code (as opposed to *through* it).
3629 *
3630 * The correct solution is probably to ignore from-native exceptions
3631 * here, and have the JNI exception code do the reporting to the
3632 * debugger.
3633 */
3634 if (gDvm.debuggerActive) {
3635 void* catchFrame;
3636 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3637 exception, true, &catchFrame);
3638 dvmDbgPostException(fp, pc - curMethod->insns, catchFrame,
3639 catchRelPc, exception);
3640 }
3641#endif
3642
3643 /*
3644 * We need to unroll to the catch block or the nearest "break"
3645 * frame.
3646 *
3647 * A break frame could indicate that we have reached an intermediate
3648 * native call, or have gone off the top of the stack and the thread
3649 * needs to exit. Either way, we return from here, leaving the
3650 * exception raised.
3651 *
3652 * If we do find a catch block, we want to transfer execution to
3653 * that point.
3654 */
3655 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3656 exception, false, (void*)&fp);
3657
3658 /*
3659 * Restore the stack bounds after an overflow. This isn't going to
3660 * be correct in all circumstances, e.g. if JNI code devours the
3661 * exception this won't happen until some other exception gets
3662 * thrown. If the code keeps pushing the stack bounds we'll end
3663 * up aborting the VM.
3664 *
3665 * Note we want to do this *after* the call to dvmFindCatchBlock,
3666 * because that may need extra stack space to resolve exception
3667 * classes (e.g. through a class loader).
3668 */
3669 if (self->stackOverflowed)
3670 dvmCleanupStackOverflow(self);
3671
3672 if (catchRelPc < 0) {
3673 /* falling through to JNI code or off the bottom of the stack */
3674#if DVM_SHOW_EXCEPTION >= 2
3675 LOGD("Exception %s from %s:%d not caught locally\n",
3676 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3677 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3678#endif
3679 dvmSetException(self, exception);
3680 dvmReleaseTrackedAlloc(exception, self);
3681 GOTO_bail();
3682 }
3683
3684#if DVM_SHOW_EXCEPTION >= 3
3685 {
3686 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
3687 LOGD("Exception %s thrown from %s:%d to %s:%d\n",
3688 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3689 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
3690 dvmGetMethodSourceFile(catchMethod),
3691 dvmLineNumFromPC(catchMethod, catchRelPc));
3692 }
3693#endif
3694
3695 /*
3696 * Adjust local variables to match self->curFrame and the
3697 * updated PC.
3698 */
3699 //fp = (u4*) self->curFrame;
3700 curMethod = SAVEAREA_FROM_FP(fp)->method;
3701 //methodClass = curMethod->clazz;
3702 methodClassDex = curMethod->clazz->pDvmDex;
3703 pc = curMethod->insns + catchRelPc;
3704 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
3705 curMethod->name, curMethod->signature);
3706 DUMP_REGS(curMethod, fp, false); // show all regs
3707
3708 /*
3709 * Restore the exception if the handler wants it.
3710 *
3711 * The Dalvik spec mandates that, if an exception handler wants to
3712 * do something with the exception, the first instruction executed
3713 * must be "move-exception". We can pass the exception along
3714 * through the thread struct, and let the move-exception instruction
3715 * clear it for us.
3716 *
3717 * If the handler doesn't call move-exception, we don't want to
3718 * finish here with an exception still pending.
3719 */
3720 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
3721 dvmSetException(self, exception);
3722
3723 dvmReleaseTrackedAlloc(exception, self);
3724 FINISH(0);
3725 }
3726GOTO_TARGET_END
3727
3728
3729 /*
3730 * General handling for invoke-{virtual,super,direct,static,interface},
3731 * including "quick" variants.
3732 *
3733 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
3734 * depending on whether this is a "/range" instruction.
3735 *
3736 * For a range call:
3737 * "vsrc1" holds the argument count (8 bits)
3738 * "vdst" holds the first argument in the range
3739 * For a non-range call:
3740 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
3741 * "vdst" holds four 4-bit register indices
3742 *
3743 * The caller must EXPORT_PC before jumping here, because any method
3744 * call can throw a stack overflow exception.
3745 */
3746GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
3747 u2 count, u2 regs)
3748 {
3749 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
3750
3751 //printf("range=%d call=%p count=%d regs=0x%04x\n",
3752 // methodCallRange, methodToCall, count, regs);
3753 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
3754 // methodToCall->name, methodToCall->signature);
3755
3756 u4* outs;
3757 int i;
3758
3759 /*
3760 * Copy args. This may corrupt vsrc1/vdst.
3761 */
3762 if (methodCallRange) {
3763 // could use memcpy or a "Duff's device"; most functions have
3764 // so few args it won't matter much
3765 assert(vsrc1 <= curMethod->outsSize);
3766 assert(vsrc1 == methodToCall->insSize);
3767 outs = OUTS_FROM_FP(fp, vsrc1);
3768 for (i = 0; i < vsrc1; i++)
3769 outs[i] = GET_REGISTER(vdst+i);
3770 } else {
3771 u4 count = vsrc1 >> 4;
3772
3773 assert(count <= curMethod->outsSize);
3774 assert(count == methodToCall->insSize);
3775 assert(count <= 5);
3776
3777 outs = OUTS_FROM_FP(fp, count);
3778#if 0
3779 if (count == 5) {
3780 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3781 count--;
3782 }
3783 for (i = 0; i < (int) count; i++) {
3784 outs[i] = GET_REGISTER(vdst & 0x0f);
3785 vdst >>= 4;
3786 }
3787#else
3788 // This version executes fewer instructions but is larger
3789 // overall. Seems to be a teensy bit faster.
3790 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
3791 switch (count) {
3792 case 5:
3793 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3794 case 4:
3795 outs[3] = GET_REGISTER(vdst >> 12);
3796 case 3:
3797 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
3798 case 2:
3799 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
3800 case 1:
3801 outs[0] = GET_REGISTER(vdst & 0x0f);
3802 default:
3803 ;
3804 }
3805#endif
3806 }
3807 }
3808
3809 /*
3810 * (This was originally a "goto" target; I've kept it separate from the
3811 * stuff above in case we want to refactor things again.)
3812 *
3813 * At this point, we have the arguments stored in the "outs" area of
3814 * the current method's stack frame, and the method to call in
3815 * "methodToCall". Push a new stack frame.
3816 */
3817 {
3818 StackSaveArea* newSaveArea;
3819 u4* newFp;
3820
3821 ILOGV("> %s%s.%s %s",
3822 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
3823 methodToCall->clazz->descriptor, methodToCall->name,
3824 methodToCall->signature);
3825
3826 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
3827 newSaveArea = SAVEAREA_FROM_FP(newFp);
3828
3829 /* verify that we have enough space */
3830 if (true) {
3831 u1* bottom;
3832 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
3833 if (bottom < self->interpStackEnd) {
3834 /* stack overflow */
3835 LOGV("Stack overflow on method call (start=%p end=%p newBot=%p size=%d '%s')\n",
3836 self->interpStackStart, self->interpStackEnd, bottom,
3837 self->interpStackSize, methodToCall->name);
3838 dvmHandleStackOverflow(self);
3839 assert(dvmCheckException(self));
3840 GOTO_exceptionThrown();
3841 }
3842 //LOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p\n",
3843 // fp, newFp, newSaveArea, bottom);
3844 }
3845
3846#ifdef LOG_INSTR
3847 if (methodToCall->registersSize > methodToCall->insSize) {
3848 /*
3849 * This makes valgrind quiet when we print registers that
3850 * haven't been initialized. Turn it off when the debug
3851 * messages are disabled -- we want valgrind to report any
3852 * used-before-initialized issues.
3853 */
3854 memset(newFp, 0xcc,
3855 (methodToCall->registersSize - methodToCall->insSize) * 4);
3856 }
3857#endif
3858
3859#ifdef EASY_GDB
3860 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
3861#endif
3862 newSaveArea->prevFrame = fp;
3863 newSaveArea->savedPc = pc;
3864 newSaveArea->method = methodToCall;
3865
3866 if (!dvmIsNativeMethod(methodToCall)) {
3867 /*
3868 * "Call" interpreted code. Reposition the PC, update the
3869 * frame pointer and other local state, and continue.
3870 */
3871 curMethod = methodToCall;
3872 methodClassDex = curMethod->clazz->pDvmDex;
3873 pc = methodToCall->insns;
3874 fp = self->curFrame = newFp;
3875#ifdef EASY_GDB
3876 debugSaveArea = SAVEAREA_FROM_FP(newFp);
3877#endif
3878#if INTERP_TYPE == INTERP_DBG
3879 debugIsMethodEntry = true; // profiling, debugging
3880#endif
3881 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
3882 curMethod->name, curMethod->signature);
3883 DUMP_REGS(curMethod, fp, true); // show input args
3884 FINISH(0); // jump to method start
3885 } else {
3886 /* set this up for JNI locals, even if not a JNI native */
3887 newSaveArea->xtra.localRefTop = self->jniLocalRefTable.nextEntry;
3888
3889 self->curFrame = newFp;
3890
3891 DUMP_REGS(methodToCall, newFp, true); // show input args
3892
3893#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3894 if (gDvm.debuggerActive) {
3895 dvmDbgPostLocationEvent(methodToCall, -1,
3896 dvmGetThisPtr(curMethod, fp), DBG_METHOD_ENTRY);
3897 }
3898#endif
3899#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3900 TRACE_METHOD_ENTER(self, methodToCall);
3901#endif
3902
3903 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
3904 methodToCall->name, methodToCall->signature);
3905
3906 /*
3907 * Jump through native call bridge. Because we leave no
3908 * space for locals on native calls, "newFp" points directly
3909 * to the method arguments.
3910 */
3911 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
3912
3913#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3914 if (gDvm.debuggerActive) {
3915 dvmDbgPostLocationEvent(methodToCall, -1,
3916 dvmGetThisPtr(curMethod, fp), DBG_METHOD_EXIT);
3917 }
3918#endif
3919#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3920 TRACE_METHOD_EXIT(self, methodToCall);
3921#endif
3922
3923 /* pop frame off */
3924 dvmPopJniLocals(self, newSaveArea);
3925 self->curFrame = fp;
3926
3927 /*
3928 * If the native code threw an exception, or interpreted code
3929 * invoked by the native call threw one and nobody has cleared
3930 * it, jump to our local exception handling.
3931 */
3932 if (dvmCheckException(self)) {
3933 LOGV("Exception thrown by/below native code\n");
3934 GOTO_exceptionThrown();
3935 }
3936
3937 ILOGD("> retval=0x%llx (leaving native)", retval.j);
3938 ILOGD("> (return from native %s.%s to %s.%s %s)",
3939 methodToCall->clazz->descriptor, methodToCall->name,
3940 curMethod->clazz->descriptor, curMethod->name,
3941 curMethod->signature);
3942
3943 //u2 invokeInstr = INST_INST(FETCH(0));
3944 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3945 invokeInstr <= OP_INVOKE_INTERFACE*/)
3946 {
3947 FINISH(3);
3948 } else {
3949 //LOGE("Unknown invoke instr %02x at %d\n",
3950 // invokeInstr, (int) (pc - curMethod->insns));
3951 assert(false);
3952 }
3953 }
3954 }
3955 assert(false); // should not get here
3956GOTO_TARGET_END
3957
3958
3959/* File: cstubs/enddefs.c */
3960
3961/* undefine "magic" name remapping */
3962#undef retval
3963#undef pc
3964#undef fp
3965#undef curMethod
3966#undef methodClassDex
3967#undef self
3968#undef debugTrackedRefStart
3969