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