blob: a37893aef91df89b2faf90a29f31e13c7da4defd [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 /*
1696 * Note: the verifier can ensure that this never happens, allowing us
1697 * to remove the check. However, the spec requires we throw the
1698 * exception at runtime, not verify time, so the verifier would
1699 * need to replace the new-instance call with a magic "throw
1700 * InstantiationError" instruction.
1701 *
1702 * Since this relies on the verifier, which is optional, we would
1703 * also need a "new-instance-quick" instruction to identify instances
1704 * that don't require the check.
1705 */
1706 if (dvmIsInterfaceClass(clazz) || dvmIsAbstractClass(clazz)) {
1707 dvmThrowExceptionWithClassMessage("Ljava/lang/InstantiationError;",
1708 clazz->descriptor);
1709 GOTO_exceptionThrown();
1710 }
1711 newObj = dvmAllocObject(clazz, ALLOC_DONT_TRACK);
1712 if (newObj == NULL)
1713 GOTO_exceptionThrown();
1714 SET_REGISTER(vdst, (u4) newObj);
1715 }
1716 FINISH(2);
1717OP_END
1718
1719/* File: c/OP_NEW_ARRAY.c */
1720HANDLE_OPCODE(OP_NEW_ARRAY /*vA, vB, class@CCCC*/)
1721 {
1722 ClassObject* arrayClass;
1723 ArrayObject* newArray;
1724 s4 length;
1725
1726 EXPORT_PC();
1727
1728 vdst = INST_A(inst);
1729 vsrc1 = INST_B(inst); /* length reg */
1730 ref = FETCH(1);
1731 ILOGV("|new-array v%d,v%d,class@0x%04x (%d elements)",
1732 vdst, vsrc1, ref, (s4) GET_REGISTER(vsrc1));
1733 length = (s4) GET_REGISTER(vsrc1);
1734 if (length < 0) {
1735 dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL);
1736 GOTO_exceptionThrown();
1737 }
1738 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
1739 if (arrayClass == NULL) {
1740 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
1741 if (arrayClass == NULL)
1742 GOTO_exceptionThrown();
1743 }
1744 /* verifier guarantees this is an array class */
1745 assert(dvmIsArrayClass(arrayClass));
1746 assert(dvmIsClassInitialized(arrayClass));
1747
1748 newArray = dvmAllocArrayByClass(arrayClass, length, ALLOC_DONT_TRACK);
1749 if (newArray == NULL)
1750 GOTO_exceptionThrown();
1751 SET_REGISTER(vdst, (u4) newArray);
1752 }
1753 FINISH(2);
1754OP_END
1755
1756
1757/* File: c/OP_FILLED_NEW_ARRAY.c */
1758HANDLE_OPCODE(OP_FILLED_NEW_ARRAY /*vB, {vD, vE, vF, vG, vA}, class@CCCC*/)
1759 GOTO_invoke(filledNewArray, false);
1760OP_END
1761
1762/* File: c/OP_FILLED_NEW_ARRAY_RANGE.c */
1763HANDLE_OPCODE(OP_FILLED_NEW_ARRAY_RANGE /*{vCCCC..v(CCCC+AA-1)}, class@BBBB*/)
1764 GOTO_invoke(filledNewArray, true);
1765OP_END
1766
1767/* File: c/OP_FILL_ARRAY_DATA.c */
1768HANDLE_OPCODE(OP_FILL_ARRAY_DATA) /*vAA, +BBBBBBBB*/
1769 {
1770 const u2* arrayData;
1771 s4 offset;
1772 ArrayObject* arrayObj;
1773
1774 EXPORT_PC();
1775 vsrc1 = INST_AA(inst);
1776 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1777 ILOGV("|fill-array-data v%d +0x%04x", vsrc1, offset);
1778 arrayData = pc + offset; // offset in 16-bit units
1779#ifndef NDEBUG
1780 if (arrayData < curMethod->insns ||
1781 arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1782 {
1783 /* should have been caught in verifier */
1784 dvmThrowException("Ljava/lang/InternalError;",
1785 "bad fill array data");
1786 GOTO_exceptionThrown();
1787 }
1788#endif
1789 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
1790 if (!dvmInterpHandleFillArrayData(arrayObj, arrayData)) {
1791 GOTO_exceptionThrown();
1792 }
1793 FINISH(3);
1794 }
1795OP_END
1796
1797/* File: c/OP_THROW.c */
1798HANDLE_OPCODE(OP_THROW /*vAA*/)
1799 {
1800 Object* obj;
1801
1802 vsrc1 = INST_AA(inst);
1803 ILOGV("|throw v%d (%p)", vsrc1, (void*)GET_REGISTER(vsrc1));
1804 obj = (Object*) GET_REGISTER(vsrc1);
1805 if (!checkForNullExportPC(obj, fp, pc)) {
1806 /* will throw a null pointer exception */
1807 LOGVV("Bad exception\n");
1808 } else {
1809 /* use the requested exception */
1810 dvmSetException(self, obj);
1811 }
1812 GOTO_exceptionThrown();
1813 }
1814OP_END
1815
1816/* File: c/OP_GOTO.c */
1817HANDLE_OPCODE(OP_GOTO /*+AA*/)
1818 vdst = INST_AA(inst);
1819 if ((s1)vdst < 0)
1820 ILOGV("|goto -0x%02x", -((s1)vdst));
1821 else
1822 ILOGV("|goto +0x%02x", ((s1)vdst));
1823 ILOGV("> branch taken");
1824 if ((s1)vdst < 0)
1825 PERIODIC_CHECKS(kInterpEntryInstr, (s1)vdst);
1826 FINISH((s1)vdst);
1827OP_END
1828
1829/* File: c/OP_GOTO_16.c */
1830HANDLE_OPCODE(OP_GOTO_16 /*+AAAA*/)
1831 {
1832 s4 offset = (s2) FETCH(1); /* sign-extend next code unit */
1833
1834 if (offset < 0)
1835 ILOGV("|goto/16 -0x%04x", -offset);
1836 else
1837 ILOGV("|goto/16 +0x%04x", offset);
1838 ILOGV("> branch taken");
1839 if (offset < 0)
1840 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1841 FINISH(offset);
1842 }
1843OP_END
1844
1845/* File: c/OP_GOTO_32.c */
1846HANDLE_OPCODE(OP_GOTO_32 /*+AAAAAAAA*/)
1847 {
1848 s4 offset = FETCH(1); /* low-order 16 bits */
1849 offset |= ((s4) FETCH(2)) << 16; /* high-order 16 bits */
1850
1851 if (offset < 0)
1852 ILOGV("|goto/32 -0x%08x", -offset);
1853 else
1854 ILOGV("|goto/32 +0x%08x", offset);
1855 ILOGV("> branch taken");
1856 if (offset <= 0) /* allowed to branch to self */
1857 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1858 FINISH(offset);
1859 }
1860OP_END
1861
1862/* File: c/OP_PACKED_SWITCH.c */
1863HANDLE_OPCODE(OP_PACKED_SWITCH /*vAA, +BBBB*/)
1864 {
1865 const u2* switchData;
1866 u4 testVal;
1867 s4 offset;
1868
1869 vsrc1 = INST_AA(inst);
1870 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1871 ILOGV("|packed-switch v%d +0x%04x", vsrc1, vsrc2);
1872 switchData = pc + offset; // offset in 16-bit units
1873#ifndef NDEBUG
1874 if (switchData < curMethod->insns ||
1875 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1876 {
1877 /* should have been caught in verifier */
1878 EXPORT_PC();
1879 dvmThrowException("Ljava/lang/InternalError;", "bad packed switch");
1880 GOTO_exceptionThrown();
1881 }
1882#endif
1883 testVal = GET_REGISTER(vsrc1);
1884
1885 offset = dvmInterpHandlePackedSwitch(switchData, testVal);
1886 ILOGV("> branch taken (0x%04x)\n", offset);
1887 if (offset <= 0) /* uncommon */
1888 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1889 FINISH(offset);
1890 }
1891OP_END
1892
1893/* File: c/OP_SPARSE_SWITCH.c */
1894HANDLE_OPCODE(OP_SPARSE_SWITCH /*vAA, +BBBB*/)
1895 {
1896 const u2* switchData;
1897 u4 testVal;
1898 s4 offset;
1899
1900 vsrc1 = INST_AA(inst);
1901 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1902 ILOGV("|sparse-switch v%d +0x%04x", vsrc1, vsrc2);
1903 switchData = pc + offset; // offset in 16-bit units
1904#ifndef NDEBUG
1905 if (switchData < curMethod->insns ||
1906 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1907 {
1908 /* should have been caught in verifier */
1909 EXPORT_PC();
1910 dvmThrowException("Ljava/lang/InternalError;", "bad sparse switch");
1911 GOTO_exceptionThrown();
1912 }
1913#endif
1914 testVal = GET_REGISTER(vsrc1);
1915
1916 offset = dvmInterpHandleSparseSwitch(switchData, testVal);
1917 ILOGV("> branch taken (0x%04x)\n", offset);
1918 if (offset <= 0) /* uncommon */
1919 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1920 FINISH(offset);
1921 }
1922OP_END
1923
1924/* File: c/OP_CMPL_FLOAT.c */
1925HANDLE_OP_CMPX(OP_CMPL_FLOAT, "l-float", float, _FLOAT, -1)
1926OP_END
1927
1928/* File: c/OP_CMPG_FLOAT.c */
1929HANDLE_OP_CMPX(OP_CMPG_FLOAT, "g-float", float, _FLOAT, 1)
1930OP_END
1931
1932/* File: c/OP_CMPL_DOUBLE.c */
1933HANDLE_OP_CMPX(OP_CMPL_DOUBLE, "l-double", double, _DOUBLE, -1)
1934OP_END
1935
1936/* File: c/OP_CMPG_DOUBLE.c */
1937HANDLE_OP_CMPX(OP_CMPG_DOUBLE, "g-double", double, _DOUBLE, 1)
1938OP_END
1939
1940/* File: c/OP_CMP_LONG.c */
1941HANDLE_OP_CMPX(OP_CMP_LONG, "-long", s8, _WIDE, 0)
1942OP_END
1943
1944/* File: c/OP_IF_EQ.c */
1945HANDLE_OP_IF_XX(OP_IF_EQ, "eq", ==)
1946OP_END
1947
1948/* File: c/OP_IF_NE.c */
1949HANDLE_OP_IF_XX(OP_IF_NE, "ne", !=)
1950OP_END
1951
1952/* File: c/OP_IF_LT.c */
1953HANDLE_OP_IF_XX(OP_IF_LT, "lt", <)
1954OP_END
1955
1956/* File: c/OP_IF_GE.c */
1957HANDLE_OP_IF_XX(OP_IF_GE, "ge", >=)
1958OP_END
1959
1960/* File: c/OP_IF_GT.c */
1961HANDLE_OP_IF_XX(OP_IF_GT, "gt", >)
1962OP_END
1963
1964/* File: c/OP_IF_LE.c */
1965HANDLE_OP_IF_XX(OP_IF_LE, "le", <=)
1966OP_END
1967
1968/* File: c/OP_IF_EQZ.c */
1969HANDLE_OP_IF_XXZ(OP_IF_EQZ, "eqz", ==)
1970OP_END
1971
1972/* File: c/OP_IF_NEZ.c */
1973HANDLE_OP_IF_XXZ(OP_IF_NEZ, "nez", !=)
1974OP_END
1975
1976/* File: c/OP_IF_LTZ.c */
1977HANDLE_OP_IF_XXZ(OP_IF_LTZ, "ltz", <)
1978OP_END
1979
1980/* File: c/OP_IF_GEZ.c */
1981HANDLE_OP_IF_XXZ(OP_IF_GEZ, "gez", >=)
1982OP_END
1983
1984/* File: c/OP_IF_GTZ.c */
1985HANDLE_OP_IF_XXZ(OP_IF_GTZ, "gtz", >)
1986OP_END
1987
1988/* File: c/OP_IF_LEZ.c */
1989HANDLE_OP_IF_XXZ(OP_IF_LEZ, "lez", <=)
1990OP_END
1991
1992/* File: c/OP_UNUSED_3E.c */
1993HANDLE_OPCODE(OP_UNUSED_3E)
1994OP_END
1995
1996/* File: c/OP_UNUSED_3F.c */
1997HANDLE_OPCODE(OP_UNUSED_3F)
1998OP_END
1999
2000/* File: c/OP_UNUSED_40.c */
2001HANDLE_OPCODE(OP_UNUSED_40)
2002OP_END
2003
2004/* File: c/OP_UNUSED_41.c */
2005HANDLE_OPCODE(OP_UNUSED_41)
2006OP_END
2007
2008/* File: c/OP_UNUSED_42.c */
2009HANDLE_OPCODE(OP_UNUSED_42)
2010OP_END
2011
2012/* File: c/OP_UNUSED_43.c */
2013HANDLE_OPCODE(OP_UNUSED_43)
2014OP_END
2015
2016/* File: c/OP_AGET.c */
2017HANDLE_OP_AGET(OP_AGET, "", u4, )
2018OP_END
2019
2020/* File: c/OP_AGET_WIDE.c */
2021HANDLE_OP_AGET(OP_AGET_WIDE, "-wide", s8, _WIDE)
2022OP_END
2023
2024/* File: c/OP_AGET_OBJECT.c */
2025HANDLE_OP_AGET(OP_AGET_OBJECT, "-object", u4, )
2026OP_END
2027
2028/* File: c/OP_AGET_BOOLEAN.c */
2029HANDLE_OP_AGET(OP_AGET_BOOLEAN, "-boolean", u1, )
2030OP_END
2031
2032/* File: c/OP_AGET_BYTE.c */
2033HANDLE_OP_AGET(OP_AGET_BYTE, "-byte", s1, )
2034OP_END
2035
2036/* File: c/OP_AGET_CHAR.c */
2037HANDLE_OP_AGET(OP_AGET_CHAR, "-char", u2, )
2038OP_END
2039
2040/* File: c/OP_AGET_SHORT.c */
2041HANDLE_OP_AGET(OP_AGET_SHORT, "-short", s2, )
2042OP_END
2043
2044/* File: c/OP_APUT.c */
2045HANDLE_OP_APUT(OP_APUT, "", u4, )
2046OP_END
2047
2048/* File: c/OP_APUT_WIDE.c */
2049HANDLE_OP_APUT(OP_APUT_WIDE, "-wide", s8, _WIDE)
2050OP_END
2051
2052/* File: c/OP_APUT_OBJECT.c */
2053HANDLE_OPCODE(OP_APUT_OBJECT /*vAA, vBB, vCC*/)
2054 {
2055 ArrayObject* arrayObj;
2056 Object* obj;
2057 u2 arrayInfo;
2058 EXPORT_PC();
2059 vdst = INST_AA(inst); /* AA: source value */
2060 arrayInfo = FETCH(1);
2061 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */
2062 vsrc2 = arrayInfo >> 8; /* CC: index */
2063 ILOGV("|aput%s v%d,v%d,v%d", "-object", vdst, vsrc1, vsrc2);
2064 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
2065 if (!checkForNull((Object*) arrayObj))
2066 GOTO_exceptionThrown();
2067 if (GET_REGISTER(vsrc2) >= arrayObj->length) {
2068 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
2069 NULL);
2070 GOTO_exceptionThrown();
2071 }
2072 obj = (Object*) GET_REGISTER(vdst);
2073 if (obj != NULL) {
2074 if (!checkForNull(obj))
2075 GOTO_exceptionThrown();
2076 if (!dvmCanPutArrayElement(obj->clazz, arrayObj->obj.clazz)) {
2077 LOGV("Can't put a '%s'(%p) into array type='%s'(%p)\n",
2078 obj->clazz->descriptor, obj,
2079 arrayObj->obj.clazz->descriptor, arrayObj);
2080 //dvmDumpClass(obj->clazz);
2081 //dvmDumpClass(arrayObj->obj.clazz);
2082 dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
2083 GOTO_exceptionThrown();
2084 }
2085 }
2086 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));
2087 ((u4*) arrayObj->contents)[GET_REGISTER(vsrc2)] =
2088 GET_REGISTER(vdst);
2089 }
2090 FINISH(2);
2091OP_END
2092
2093/* File: c/OP_APUT_BOOLEAN.c */
2094HANDLE_OP_APUT(OP_APUT_BOOLEAN, "-boolean", u1, )
2095OP_END
2096
2097/* File: c/OP_APUT_BYTE.c */
2098HANDLE_OP_APUT(OP_APUT_BYTE, "-byte", s1, )
2099OP_END
2100
2101/* File: c/OP_APUT_CHAR.c */
2102HANDLE_OP_APUT(OP_APUT_CHAR, "-char", u2, )
2103OP_END
2104
2105/* File: c/OP_APUT_SHORT.c */
2106HANDLE_OP_APUT(OP_APUT_SHORT, "-short", s2, )
2107OP_END
2108
2109/* File: c/OP_IGET.c */
2110HANDLE_IGET_X(OP_IGET, "", Int, )
2111OP_END
2112
2113/* File: c/OP_IGET_WIDE.c */
2114HANDLE_IGET_X(OP_IGET_WIDE, "-wide", Long, _WIDE)
2115OP_END
2116
2117/* File: c/OP_IGET_OBJECT.c */
2118HANDLE_IGET_X(OP_IGET_OBJECT, "-object", Object, _AS_OBJECT)
2119OP_END
2120
2121/* File: c/OP_IGET_BOOLEAN.c */
2122HANDLE_IGET_X(OP_IGET_BOOLEAN, "", Int, )
2123OP_END
2124
2125/* File: c/OP_IGET_BYTE.c */
2126HANDLE_IGET_X(OP_IGET_BYTE, "", Int, )
2127OP_END
2128
2129/* File: c/OP_IGET_CHAR.c */
2130HANDLE_IGET_X(OP_IGET_CHAR, "", Int, )
2131OP_END
2132
2133/* File: c/OP_IGET_SHORT.c */
2134HANDLE_IGET_X(OP_IGET_SHORT, "", Int, )
2135OP_END
2136
2137/* File: c/OP_IPUT.c */
2138HANDLE_IPUT_X(OP_IPUT, "", Int, )
2139OP_END
2140
2141/* File: c/OP_IPUT_WIDE.c */
2142HANDLE_IPUT_X(OP_IPUT_WIDE, "-wide", Long, _WIDE)
2143OP_END
2144
2145/* File: c/OP_IPUT_OBJECT.c */
2146/*
2147 * The VM spec says we should verify that the reference being stored into
2148 * the field is assignment compatible. In practice, many popular VMs don't
2149 * do this because it slows down a very common operation. It's not so bad
2150 * for us, since "dexopt" quickens it whenever possible, but it's still an
2151 * issue.
2152 *
2153 * To make this spec-complaint, we'd need to add a ClassObject pointer to
2154 * the Field struct, resolve the field's type descriptor at link or class
2155 * init time, and then verify the type here.
2156 */
2157HANDLE_IPUT_X(OP_IPUT_OBJECT, "-object", Object, _AS_OBJECT)
2158OP_END
2159
2160/* File: c/OP_IPUT_BOOLEAN.c */
2161HANDLE_IPUT_X(OP_IPUT_BOOLEAN, "", Int, )
2162OP_END
2163
2164/* File: c/OP_IPUT_BYTE.c */
2165HANDLE_IPUT_X(OP_IPUT_BYTE, "", Int, )
2166OP_END
2167
2168/* File: c/OP_IPUT_CHAR.c */
2169HANDLE_IPUT_X(OP_IPUT_CHAR, "", Int, )
2170OP_END
2171
2172/* File: c/OP_IPUT_SHORT.c */
2173HANDLE_IPUT_X(OP_IPUT_SHORT, "", Int, )
2174OP_END
2175
2176/* File: c/OP_SGET.c */
2177HANDLE_SGET_X(OP_SGET, "", Int, )
2178OP_END
2179
2180/* File: c/OP_SGET_WIDE.c */
2181HANDLE_SGET_X(OP_SGET_WIDE, "-wide", Long, _WIDE)
2182OP_END
2183
2184/* File: c/OP_SGET_OBJECT.c */
2185HANDLE_SGET_X(OP_SGET_OBJECT, "-object", Object, _AS_OBJECT)
2186OP_END
2187
2188/* File: c/OP_SGET_BOOLEAN.c */
2189HANDLE_SGET_X(OP_SGET_BOOLEAN, "", Int, )
2190OP_END
2191
2192/* File: c/OP_SGET_BYTE.c */
2193HANDLE_SGET_X(OP_SGET_BYTE, "", Int, )
2194OP_END
2195
2196/* File: c/OP_SGET_CHAR.c */
2197HANDLE_SGET_X(OP_SGET_CHAR, "", Int, )
2198OP_END
2199
2200/* File: c/OP_SGET_SHORT.c */
2201HANDLE_SGET_X(OP_SGET_SHORT, "", Int, )
2202OP_END
2203
2204/* File: c/OP_SPUT.c */
2205HANDLE_SPUT_X(OP_SPUT, "", Int, )
2206OP_END
2207
2208/* File: c/OP_SPUT_WIDE.c */
2209HANDLE_SPUT_X(OP_SPUT_WIDE, "-wide", Long, _WIDE)
2210OP_END
2211
2212/* File: c/OP_SPUT_OBJECT.c */
2213HANDLE_SPUT_X(OP_SPUT_OBJECT, "-object", Object, _AS_OBJECT)
2214OP_END
2215
2216/* File: c/OP_SPUT_BOOLEAN.c */
2217HANDLE_SPUT_X(OP_SPUT_BOOLEAN, "", Int, )
2218OP_END
2219
2220/* File: c/OP_SPUT_BYTE.c */
2221HANDLE_SPUT_X(OP_SPUT_BYTE, "", Int, )
2222OP_END
2223
2224/* File: c/OP_SPUT_CHAR.c */
2225HANDLE_SPUT_X(OP_SPUT_CHAR, "", Int, )
2226OP_END
2227
2228/* File: c/OP_SPUT_SHORT.c */
2229HANDLE_SPUT_X(OP_SPUT_SHORT, "", Int, )
2230OP_END
2231
2232/* File: c/OP_INVOKE_VIRTUAL.c */
2233HANDLE_OPCODE(OP_INVOKE_VIRTUAL /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2234 GOTO_invoke(invokeVirtual, false);
2235OP_END
2236
2237/* File: c/OP_INVOKE_SUPER.c */
2238HANDLE_OPCODE(OP_INVOKE_SUPER /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2239 GOTO_invoke(invokeSuper, false);
2240OP_END
2241
2242/* File: c/OP_INVOKE_DIRECT.c */
2243HANDLE_OPCODE(OP_INVOKE_DIRECT /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2244 GOTO_invoke(invokeDirect, false);
2245OP_END
2246
2247/* File: c/OP_INVOKE_STATIC.c */
2248HANDLE_OPCODE(OP_INVOKE_STATIC /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2249 GOTO_invoke(invokeStatic, false);
2250OP_END
2251
2252/* File: c/OP_INVOKE_INTERFACE.c */
2253HANDLE_OPCODE(OP_INVOKE_INTERFACE /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2254 GOTO_invoke(invokeInterface, false);
2255OP_END
2256
2257/* File: c/OP_UNUSED_73.c */
2258HANDLE_OPCODE(OP_UNUSED_73)
2259OP_END
2260
2261/* File: c/OP_INVOKE_VIRTUAL_RANGE.c */
2262HANDLE_OPCODE(OP_INVOKE_VIRTUAL_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2263 GOTO_invoke(invokeVirtual, true);
2264OP_END
2265
2266/* File: c/OP_INVOKE_SUPER_RANGE.c */
2267HANDLE_OPCODE(OP_INVOKE_SUPER_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2268 GOTO_invoke(invokeSuper, true);
2269OP_END
2270
2271/* File: c/OP_INVOKE_DIRECT_RANGE.c */
2272HANDLE_OPCODE(OP_INVOKE_DIRECT_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2273 GOTO_invoke(invokeDirect, true);
2274OP_END
2275
2276/* File: c/OP_INVOKE_STATIC_RANGE.c */
2277HANDLE_OPCODE(OP_INVOKE_STATIC_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2278 GOTO_invoke(invokeStatic, true);
2279OP_END
2280
2281/* File: c/OP_INVOKE_INTERFACE_RANGE.c */
2282HANDLE_OPCODE(OP_INVOKE_INTERFACE_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2283 GOTO_invoke(invokeInterface, true);
2284OP_END
2285
2286/* File: c/OP_UNUSED_79.c */
2287HANDLE_OPCODE(OP_UNUSED_79)
2288OP_END
2289
2290/* File: c/OP_UNUSED_7A.c */
2291HANDLE_OPCODE(OP_UNUSED_7A)
2292OP_END
2293
2294/* File: c/OP_NEG_INT.c */
2295HANDLE_UNOP(OP_NEG_INT, "neg-int", -, , )
2296OP_END
2297
2298/* File: c/OP_NOT_INT.c */
2299HANDLE_UNOP(OP_NOT_INT, "not-int", , ^ 0xffffffff, )
2300OP_END
2301
2302/* File: c/OP_NEG_LONG.c */
2303HANDLE_UNOP(OP_NEG_LONG, "neg-long", -, , _WIDE)
2304OP_END
2305
2306/* File: c/OP_NOT_LONG.c */
2307HANDLE_UNOP(OP_NOT_LONG, "not-long", , ^ 0xffffffffffffffffULL, _WIDE)
2308OP_END
2309
2310/* File: c/OP_NEG_FLOAT.c */
2311HANDLE_UNOP(OP_NEG_FLOAT, "neg-float", -, , _FLOAT)
2312OP_END
2313
2314/* File: c/OP_NEG_DOUBLE.c */
2315HANDLE_UNOP(OP_NEG_DOUBLE, "neg-double", -, , _DOUBLE)
2316OP_END
2317
2318/* File: c/OP_INT_TO_LONG.c */
2319HANDLE_NUMCONV(OP_INT_TO_LONG, "int-to-long", _INT, _WIDE)
2320OP_END
2321
2322/* File: c/OP_INT_TO_FLOAT.c */
2323HANDLE_NUMCONV(OP_INT_TO_FLOAT, "int-to-float", _INT, _FLOAT)
2324OP_END
2325
2326/* File: c/OP_INT_TO_DOUBLE.c */
2327HANDLE_NUMCONV(OP_INT_TO_DOUBLE, "int-to-double", _INT, _DOUBLE)
2328OP_END
2329
2330/* File: c/OP_LONG_TO_INT.c */
2331HANDLE_NUMCONV(OP_LONG_TO_INT, "long-to-int", _WIDE, _INT)
2332OP_END
2333
2334/* File: c/OP_LONG_TO_FLOAT.c */
2335HANDLE_NUMCONV(OP_LONG_TO_FLOAT, "long-to-float", _WIDE, _FLOAT)
2336OP_END
2337
2338/* File: c/OP_LONG_TO_DOUBLE.c */
2339HANDLE_NUMCONV(OP_LONG_TO_DOUBLE, "long-to-double", _WIDE, _DOUBLE)
2340OP_END
2341
2342/* File: c/OP_FLOAT_TO_INT.c */
2343HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_INT, "float-to-int",
2344 float, _FLOAT, s4, _INT)
2345OP_END
2346
2347/* File: c/OP_FLOAT_TO_LONG.c */
2348HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_LONG, "float-to-long",
2349 float, _FLOAT, s8, _WIDE)
2350OP_END
2351
2352/* File: c/OP_FLOAT_TO_DOUBLE.c */
2353HANDLE_NUMCONV(OP_FLOAT_TO_DOUBLE, "float-to-double", _FLOAT, _DOUBLE)
2354OP_END
2355
2356/* File: c/OP_DOUBLE_TO_INT.c */
2357HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_INT, "double-to-int",
2358 double, _DOUBLE, s4, _INT)
2359OP_END
2360
2361/* File: c/OP_DOUBLE_TO_LONG.c */
2362HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_LONG, "double-to-long",
2363 double, _DOUBLE, s8, _WIDE)
2364OP_END
2365
2366/* File: c/OP_DOUBLE_TO_FLOAT.c */
2367HANDLE_NUMCONV(OP_DOUBLE_TO_FLOAT, "double-to-float", _DOUBLE, _FLOAT)
2368OP_END
2369
2370/* File: c/OP_INT_TO_BYTE.c */
2371HANDLE_INT_TO_SMALL(OP_INT_TO_BYTE, "byte", s1)
2372OP_END
2373
2374/* File: c/OP_INT_TO_CHAR.c */
2375HANDLE_INT_TO_SMALL(OP_INT_TO_CHAR, "char", u2)
2376OP_END
2377
2378/* File: c/OP_INT_TO_SHORT.c */
2379HANDLE_INT_TO_SMALL(OP_INT_TO_SHORT, "short", s2) /* want sign bit */
2380OP_END
2381
2382/* File: c/OP_ADD_INT.c */
2383HANDLE_OP_X_INT(OP_ADD_INT, "add", +, 0)
2384OP_END
2385
2386/* File: c/OP_SUB_INT.c */
2387HANDLE_OP_X_INT(OP_SUB_INT, "sub", -, 0)
2388OP_END
2389
2390/* File: c/OP_MUL_INT.c */
2391HANDLE_OP_X_INT(OP_MUL_INT, "mul", *, 0)
2392OP_END
2393
2394/* File: c/OP_DIV_INT.c */
2395HANDLE_OP_X_INT(OP_DIV_INT, "div", /, 1)
2396OP_END
2397
2398/* File: c/OP_REM_INT.c */
2399HANDLE_OP_X_INT(OP_REM_INT, "rem", %, 2)
2400OP_END
2401
2402/* File: c/OP_AND_INT.c */
2403HANDLE_OP_X_INT(OP_AND_INT, "and", &, 0)
2404OP_END
2405
2406/* File: c/OP_OR_INT.c */
2407HANDLE_OP_X_INT(OP_OR_INT, "or", |, 0)
2408OP_END
2409
2410/* File: c/OP_XOR_INT.c */
2411HANDLE_OP_X_INT(OP_XOR_INT, "xor", ^, 0)
2412OP_END
2413
2414/* File: c/OP_SHL_INT.c */
2415HANDLE_OP_SHX_INT(OP_SHL_INT, "shl", (s4), <<)
2416OP_END
2417
2418/* File: c/OP_SHR_INT.c */
2419HANDLE_OP_SHX_INT(OP_SHR_INT, "shr", (s4), >>)
2420OP_END
2421
2422/* File: c/OP_USHR_INT.c */
2423HANDLE_OP_SHX_INT(OP_USHR_INT, "ushr", (u4), >>)
2424OP_END
2425
2426/* File: c/OP_ADD_LONG.c */
2427HANDLE_OP_X_LONG(OP_ADD_LONG, "add", +, 0)
2428OP_END
2429
2430/* File: c/OP_SUB_LONG.c */
2431HANDLE_OP_X_LONG(OP_SUB_LONG, "sub", -, 0)
2432OP_END
2433
2434/* File: c/OP_MUL_LONG.c */
2435HANDLE_OP_X_LONG(OP_MUL_LONG, "mul", *, 0)
2436OP_END
2437
2438/* File: c/OP_DIV_LONG.c */
2439HANDLE_OP_X_LONG(OP_DIV_LONG, "div", /, 1)
2440OP_END
2441
2442/* File: c/OP_REM_LONG.c */
2443HANDLE_OP_X_LONG(OP_REM_LONG, "rem", %, 2)
2444OP_END
2445
2446/* File: c/OP_AND_LONG.c */
2447HANDLE_OP_X_LONG(OP_AND_LONG, "and", &, 0)
2448OP_END
2449
2450/* File: c/OP_OR_LONG.c */
2451HANDLE_OP_X_LONG(OP_OR_LONG, "or", |, 0)
2452OP_END
2453
2454/* File: c/OP_XOR_LONG.c */
2455HANDLE_OP_X_LONG(OP_XOR_LONG, "xor", ^, 0)
2456OP_END
2457
2458/* File: c/OP_SHL_LONG.c */
2459HANDLE_OP_SHX_LONG(OP_SHL_LONG, "shl", (s8), <<)
2460OP_END
2461
2462/* File: c/OP_SHR_LONG.c */
2463HANDLE_OP_SHX_LONG(OP_SHR_LONG, "shr", (s8), >>)
2464OP_END
2465
2466/* File: c/OP_USHR_LONG.c */
2467HANDLE_OP_SHX_LONG(OP_USHR_LONG, "ushr", (u8), >>)
2468OP_END
2469
2470/* File: c/OP_ADD_FLOAT.c */
2471HANDLE_OP_X_FLOAT(OP_ADD_FLOAT, "add", +)
2472OP_END
2473
2474/* File: c/OP_SUB_FLOAT.c */
2475HANDLE_OP_X_FLOAT(OP_SUB_FLOAT, "sub", -)
2476OP_END
2477
2478/* File: c/OP_MUL_FLOAT.c */
2479HANDLE_OP_X_FLOAT(OP_MUL_FLOAT, "mul", *)
2480OP_END
2481
2482/* File: c/OP_DIV_FLOAT.c */
2483HANDLE_OP_X_FLOAT(OP_DIV_FLOAT, "div", /)
2484OP_END
2485
2486/* File: c/OP_REM_FLOAT.c */
2487HANDLE_OPCODE(OP_REM_FLOAT /*vAA, vBB, vCC*/)
2488 {
2489 u2 srcRegs;
2490 vdst = INST_AA(inst);
2491 srcRegs = FETCH(1);
2492 vsrc1 = srcRegs & 0xff;
2493 vsrc2 = srcRegs >> 8;
2494 ILOGV("|%s-float v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2495 SET_REGISTER_FLOAT(vdst,
2496 fmodf(GET_REGISTER_FLOAT(vsrc1), GET_REGISTER_FLOAT(vsrc2)));
2497 }
2498 FINISH(2);
2499OP_END
2500
2501/* File: c/OP_ADD_DOUBLE.c */
2502HANDLE_OP_X_DOUBLE(OP_ADD_DOUBLE, "add", +)
2503OP_END
2504
2505/* File: c/OP_SUB_DOUBLE.c */
2506HANDLE_OP_X_DOUBLE(OP_SUB_DOUBLE, "sub", -)
2507OP_END
2508
2509/* File: c/OP_MUL_DOUBLE.c */
2510HANDLE_OP_X_DOUBLE(OP_MUL_DOUBLE, "mul", *)
2511OP_END
2512
2513/* File: c/OP_DIV_DOUBLE.c */
2514HANDLE_OP_X_DOUBLE(OP_DIV_DOUBLE, "div", /)
2515OP_END
2516
2517/* File: c/OP_REM_DOUBLE.c */
2518HANDLE_OPCODE(OP_REM_DOUBLE /*vAA, vBB, vCC*/)
2519 {
2520 u2 srcRegs;
2521 vdst = INST_AA(inst);
2522 srcRegs = FETCH(1);
2523 vsrc1 = srcRegs & 0xff;
2524 vsrc2 = srcRegs >> 8;
2525 ILOGV("|%s-double v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2526 SET_REGISTER_DOUBLE(vdst,
2527 fmod(GET_REGISTER_DOUBLE(vsrc1), GET_REGISTER_DOUBLE(vsrc2)));
2528 }
2529 FINISH(2);
2530OP_END
2531
2532/* File: c/OP_ADD_INT_2ADDR.c */
2533HANDLE_OP_X_INT_2ADDR(OP_ADD_INT_2ADDR, "add", +, 0)
2534OP_END
2535
2536/* File: c/OP_SUB_INT_2ADDR.c */
2537HANDLE_OP_X_INT_2ADDR(OP_SUB_INT_2ADDR, "sub", -, 0)
2538OP_END
2539
2540/* File: c/OP_MUL_INT_2ADDR.c */
2541HANDLE_OP_X_INT_2ADDR(OP_MUL_INT_2ADDR, "mul", *, 0)
2542OP_END
2543
2544/* File: c/OP_DIV_INT_2ADDR.c */
2545HANDLE_OP_X_INT_2ADDR(OP_DIV_INT_2ADDR, "div", /, 1)
2546OP_END
2547
2548/* File: c/OP_REM_INT_2ADDR.c */
2549HANDLE_OP_X_INT_2ADDR(OP_REM_INT_2ADDR, "rem", %, 2)
2550OP_END
2551
2552/* File: c/OP_AND_INT_2ADDR.c */
2553HANDLE_OP_X_INT_2ADDR(OP_AND_INT_2ADDR, "and", &, 0)
2554OP_END
2555
2556/* File: c/OP_OR_INT_2ADDR.c */
2557HANDLE_OP_X_INT_2ADDR(OP_OR_INT_2ADDR, "or", |, 0)
2558OP_END
2559
2560/* File: c/OP_XOR_INT_2ADDR.c */
2561HANDLE_OP_X_INT_2ADDR(OP_XOR_INT_2ADDR, "xor", ^, 0)
2562OP_END
2563
2564/* File: c/OP_SHL_INT_2ADDR.c */
2565HANDLE_OP_SHX_INT_2ADDR(OP_SHL_INT_2ADDR, "shl", (s4), <<)
2566OP_END
2567
2568/* File: c/OP_SHR_INT_2ADDR.c */
2569HANDLE_OP_SHX_INT_2ADDR(OP_SHR_INT_2ADDR, "shr", (s4), >>)
2570OP_END
2571
2572/* File: c/OP_USHR_INT_2ADDR.c */
2573HANDLE_OP_SHX_INT_2ADDR(OP_USHR_INT_2ADDR, "ushr", (u4), >>)
2574OP_END
2575
2576/* File: c/OP_ADD_LONG_2ADDR.c */
2577HANDLE_OP_X_LONG_2ADDR(OP_ADD_LONG_2ADDR, "add", +, 0)
2578OP_END
2579
2580/* File: c/OP_SUB_LONG_2ADDR.c */
2581HANDLE_OP_X_LONG_2ADDR(OP_SUB_LONG_2ADDR, "sub", -, 0)
2582OP_END
2583
2584/* File: c/OP_MUL_LONG_2ADDR.c */
2585HANDLE_OP_X_LONG_2ADDR(OP_MUL_LONG_2ADDR, "mul", *, 0)
2586OP_END
2587
2588/* File: c/OP_DIV_LONG_2ADDR.c */
2589HANDLE_OP_X_LONG_2ADDR(OP_DIV_LONG_2ADDR, "div", /, 1)
2590OP_END
2591
2592/* File: c/OP_REM_LONG_2ADDR.c */
2593HANDLE_OP_X_LONG_2ADDR(OP_REM_LONG_2ADDR, "rem", %, 2)
2594OP_END
2595
2596/* File: c/OP_AND_LONG_2ADDR.c */
2597HANDLE_OP_X_LONG_2ADDR(OP_AND_LONG_2ADDR, "and", &, 0)
2598OP_END
2599
2600/* File: c/OP_OR_LONG_2ADDR.c */
2601HANDLE_OP_X_LONG_2ADDR(OP_OR_LONG_2ADDR, "or", |, 0)
2602OP_END
2603
2604/* File: c/OP_XOR_LONG_2ADDR.c */
2605HANDLE_OP_X_LONG_2ADDR(OP_XOR_LONG_2ADDR, "xor", ^, 0)
2606OP_END
2607
2608/* File: c/OP_SHL_LONG_2ADDR.c */
2609HANDLE_OP_SHX_LONG_2ADDR(OP_SHL_LONG_2ADDR, "shl", (s8), <<)
2610OP_END
2611
2612/* File: c/OP_SHR_LONG_2ADDR.c */
2613HANDLE_OP_SHX_LONG_2ADDR(OP_SHR_LONG_2ADDR, "shr", (s8), >>)
2614OP_END
2615
2616/* File: c/OP_USHR_LONG_2ADDR.c */
2617HANDLE_OP_SHX_LONG_2ADDR(OP_USHR_LONG_2ADDR, "ushr", (u8), >>)
2618OP_END
2619
2620/* File: c/OP_ADD_FLOAT_2ADDR.c */
2621HANDLE_OP_X_FLOAT_2ADDR(OP_ADD_FLOAT_2ADDR, "add", +)
2622OP_END
2623
2624/* File: c/OP_SUB_FLOAT_2ADDR.c */
2625HANDLE_OP_X_FLOAT_2ADDR(OP_SUB_FLOAT_2ADDR, "sub", -)
2626OP_END
2627
2628/* File: c/OP_MUL_FLOAT_2ADDR.c */
2629HANDLE_OP_X_FLOAT_2ADDR(OP_MUL_FLOAT_2ADDR, "mul", *)
2630OP_END
2631
2632/* File: c/OP_DIV_FLOAT_2ADDR.c */
2633HANDLE_OP_X_FLOAT_2ADDR(OP_DIV_FLOAT_2ADDR, "div", /)
2634OP_END
2635
2636/* File: c/OP_REM_FLOAT_2ADDR.c */
2637HANDLE_OPCODE(OP_REM_FLOAT_2ADDR /*vA, vB*/)
2638 vdst = INST_A(inst);
2639 vsrc1 = INST_B(inst);
2640 ILOGV("|%s-float-2addr v%d,v%d", "mod", vdst, vsrc1);
2641 SET_REGISTER_FLOAT(vdst,
2642 fmodf(GET_REGISTER_FLOAT(vdst), GET_REGISTER_FLOAT(vsrc1)));
2643 FINISH(1);
2644OP_END
2645
2646/* File: c/OP_ADD_DOUBLE_2ADDR.c */
2647HANDLE_OP_X_DOUBLE_2ADDR(OP_ADD_DOUBLE_2ADDR, "add", +)
2648OP_END
2649
2650/* File: c/OP_SUB_DOUBLE_2ADDR.c */
2651HANDLE_OP_X_DOUBLE_2ADDR(OP_SUB_DOUBLE_2ADDR, "sub", -)
2652OP_END
2653
2654/* File: c/OP_MUL_DOUBLE_2ADDR.c */
2655HANDLE_OP_X_DOUBLE_2ADDR(OP_MUL_DOUBLE_2ADDR, "mul", *)
2656OP_END
2657
2658/* File: c/OP_DIV_DOUBLE_2ADDR.c */
2659HANDLE_OP_X_DOUBLE_2ADDR(OP_DIV_DOUBLE_2ADDR, "div", /)
2660OP_END
2661
2662/* File: c/OP_REM_DOUBLE_2ADDR.c */
2663HANDLE_OPCODE(OP_REM_DOUBLE_2ADDR /*vA, vB*/)
2664 vdst = INST_A(inst);
2665 vsrc1 = INST_B(inst);
2666 ILOGV("|%s-double-2addr v%d,v%d", "mod", vdst, vsrc1);
2667 SET_REGISTER_DOUBLE(vdst,
2668 fmod(GET_REGISTER_DOUBLE(vdst), GET_REGISTER_DOUBLE(vsrc1)));
2669 FINISH(1);
2670OP_END
2671
2672/* File: c/OP_ADD_INT_LIT16.c */
2673HANDLE_OP_X_INT_LIT16(OP_ADD_INT_LIT16, "add", +, 0)
2674OP_END
2675
2676/* File: c/OP_RSUB_INT.c */
2677HANDLE_OPCODE(OP_RSUB_INT /*vA, vB, #+CCCC*/)
2678 {
2679 vdst = INST_A(inst);
2680 vsrc1 = INST_B(inst);
2681 vsrc2 = FETCH(1);
2682 ILOGV("|rsub-int v%d,v%d,#+0x%04x", vdst, vsrc1, vsrc2);
2683 SET_REGISTER(vdst, (s2) vsrc2 - (s4) GET_REGISTER(vsrc1));
2684 }
2685 FINISH(2);
2686OP_END
2687
2688/* File: c/OP_MUL_INT_LIT16.c */
2689HANDLE_OP_X_INT_LIT16(OP_MUL_INT_LIT16, "mul", *, 0)
2690OP_END
2691
2692/* File: c/OP_DIV_INT_LIT16.c */
2693HANDLE_OP_X_INT_LIT16(OP_DIV_INT_LIT16, "div", /, 1)
2694OP_END
2695
2696/* File: c/OP_REM_INT_LIT16.c */
2697HANDLE_OP_X_INT_LIT16(OP_REM_INT_LIT16, "rem", %, 2)
2698OP_END
2699
2700/* File: c/OP_AND_INT_LIT16.c */
2701HANDLE_OP_X_INT_LIT16(OP_AND_INT_LIT16, "and", &, 0)
2702OP_END
2703
2704/* File: c/OP_OR_INT_LIT16.c */
2705HANDLE_OP_X_INT_LIT16(OP_OR_INT_LIT16, "or", |, 0)
2706OP_END
2707
2708/* File: c/OP_XOR_INT_LIT16.c */
2709HANDLE_OP_X_INT_LIT16(OP_XOR_INT_LIT16, "xor", ^, 0)
2710OP_END
2711
2712/* File: c/OP_ADD_INT_LIT8.c */
2713HANDLE_OP_X_INT_LIT8(OP_ADD_INT_LIT8, "add", +, 0)
2714OP_END
2715
2716/* File: c/OP_RSUB_INT_LIT8.c */
2717HANDLE_OPCODE(OP_RSUB_INT_LIT8 /*vAA, vBB, #+CC*/)
2718 {
2719 u2 litInfo;
2720 vdst = INST_AA(inst);
2721 litInfo = FETCH(1);
2722 vsrc1 = litInfo & 0xff;
2723 vsrc2 = litInfo >> 8;
2724 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", "rsub", vdst, vsrc1, vsrc2);
2725 SET_REGISTER(vdst, (s1) vsrc2 - (s4) GET_REGISTER(vsrc1));
2726 }
2727 FINISH(2);
2728OP_END
2729
2730/* File: c/OP_MUL_INT_LIT8.c */
2731HANDLE_OP_X_INT_LIT8(OP_MUL_INT_LIT8, "mul", *, 0)
2732OP_END
2733
2734/* File: c/OP_DIV_INT_LIT8.c */
2735HANDLE_OP_X_INT_LIT8(OP_DIV_INT_LIT8, "div", /, 1)
2736OP_END
2737
2738/* File: c/OP_REM_INT_LIT8.c */
2739HANDLE_OP_X_INT_LIT8(OP_REM_INT_LIT8, "rem", %, 2)
2740OP_END
2741
2742/* File: c/OP_AND_INT_LIT8.c */
2743HANDLE_OP_X_INT_LIT8(OP_AND_INT_LIT8, "and", &, 0)
2744OP_END
2745
2746/* File: c/OP_OR_INT_LIT8.c */
2747HANDLE_OP_X_INT_LIT8(OP_OR_INT_LIT8, "or", |, 0)
2748OP_END
2749
2750/* File: c/OP_XOR_INT_LIT8.c */
2751HANDLE_OP_X_INT_LIT8(OP_XOR_INT_LIT8, "xor", ^, 0)
2752OP_END
2753
2754/* File: c/OP_SHL_INT_LIT8.c */
2755HANDLE_OP_SHX_INT_LIT8(OP_SHL_INT_LIT8, "shl", (s4), <<)
2756OP_END
2757
2758/* File: c/OP_SHR_INT_LIT8.c */
2759HANDLE_OP_SHX_INT_LIT8(OP_SHR_INT_LIT8, "shr", (s4), >>)
2760OP_END
2761
2762/* File: c/OP_USHR_INT_LIT8.c */
2763HANDLE_OP_SHX_INT_LIT8(OP_USHR_INT_LIT8, "ushr", (u4), >>)
2764OP_END
2765
2766/* File: c/OP_UNUSED_E3.c */
2767HANDLE_OPCODE(OP_UNUSED_E3)
2768OP_END
2769
2770/* File: c/OP_UNUSED_E4.c */
2771HANDLE_OPCODE(OP_UNUSED_E4)
2772OP_END
2773
2774/* File: c/OP_UNUSED_E5.c */
2775HANDLE_OPCODE(OP_UNUSED_E5)
2776OP_END
2777
2778/* File: c/OP_UNUSED_E6.c */
2779HANDLE_OPCODE(OP_UNUSED_E6)
2780OP_END
2781
2782/* File: c/OP_UNUSED_E7.c */
2783HANDLE_OPCODE(OP_UNUSED_E7)
2784OP_END
2785
2786/* File: c/OP_UNUSED_E8.c */
2787HANDLE_OPCODE(OP_UNUSED_E8)
2788OP_END
2789
2790/* File: c/OP_UNUSED_E9.c */
2791HANDLE_OPCODE(OP_UNUSED_E9)
2792OP_END
2793
2794/* File: c/OP_UNUSED_EA.c */
2795HANDLE_OPCODE(OP_UNUSED_EA)
2796OP_END
2797
2798/* File: c/OP_UNUSED_EB.c */
2799HANDLE_OPCODE(OP_UNUSED_EB)
2800OP_END
2801
2802/* File: c/OP_UNUSED_EC.c */
2803HANDLE_OPCODE(OP_UNUSED_EC)
2804OP_END
2805
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002806/* File: c/OP_THROW_VERIFICATION_ERROR.c */
2807HANDLE_OPCODE(OP_THROW_VERIFICATION_ERROR)
2808 vsrc1 = INST_AA(inst);
2809 ref = FETCH(1); /* class/field/method ref */
2810 dvmThrowVerificationError(methodClassDex, vsrc1, ref);
2811 GOTO_exceptionThrown();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002812OP_END
2813
2814/* File: c/OP_EXECUTE_INLINE.c */
2815HANDLE_OPCODE(OP_EXECUTE_INLINE /*vB, {vD, vE, vF, vG}, inline@CCCC*/)
2816 {
2817 /*
2818 * This has the same form as other method calls, but we ignore
2819 * the 5th argument (vA). This is chiefly because the first four
2820 * arguments to a function on ARM are in registers.
2821 *
2822 * We only set the arguments that are actually used, leaving
2823 * the rest uninitialized. We're assuming that, if the method
2824 * needs them, they'll be specified in the call.
2825 *
2826 * This annoys gcc when optimizations are enabled, causing a
2827 * "may be used uninitialized" warning. We can quiet the warnings
2828 * for a slight penalty (5%: 373ns vs. 393ns on empty method). Note
2829 * that valgrind is perfectly happy with this arrangement, because
2830 * the uninitialiezd values are never actually used.
2831 */
2832 u4 arg0, arg1, arg2, arg3;
2833 //arg0 = arg1 = arg2 = arg3 = 0;
2834
2835 EXPORT_PC();
2836
2837 vsrc1 = INST_B(inst); /* #of args */
2838 ref = FETCH(1); /* inline call "ref" */
2839 vdst = FETCH(2); /* 0-4 register indices */
2840 ILOGV("|execute-inline args=%d @%d {regs=0x%04x}",
2841 vsrc1, ref, vdst);
2842
2843 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
2844 assert(vsrc1 <= 4);
2845
2846 switch (vsrc1) {
2847 case 4:
2848 arg3 = GET_REGISTER(vdst >> 12);
2849 /* fall through */
2850 case 3:
2851 arg2 = GET_REGISTER((vdst & 0x0f00) >> 8);
2852 /* fall through */
2853 case 2:
2854 arg1 = GET_REGISTER((vdst & 0x00f0) >> 4);
2855 /* fall through */
2856 case 1:
2857 arg0 = GET_REGISTER(vdst & 0x0f);
2858 /* fall through */
2859 default: // case 0
2860 ;
2861 }
2862
2863#if INTERP_TYPE == INTERP_DBG
2864 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
2865 GOTO_exceptionThrown();
2866#else
2867 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
2868 GOTO_exceptionThrown();
2869#endif
2870 }
2871 FINISH(3);
2872OP_END
2873
2874/* File: c/OP_UNUSED_EF.c */
2875HANDLE_OPCODE(OP_UNUSED_EF)
2876OP_END
2877
2878/* File: c/OP_INVOKE_DIRECT_EMPTY.c */
2879HANDLE_OPCODE(OP_INVOKE_DIRECT_EMPTY /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2880#if INTERP_TYPE != INTERP_DBG
2881 //LOGI("Ignoring empty\n");
2882 FINISH(3);
2883#else
2884 if (!gDvm.debuggerActive) {
2885 //LOGI("Skipping empty\n");
2886 FINISH(3); // don't want it to show up in profiler output
2887 } else {
2888 //LOGI("Running empty\n");
2889 /* fall through to OP_INVOKE_DIRECT */
2890 GOTO_invoke(invokeDirect, false);
2891 }
2892#endif
2893OP_END
2894
2895/* File: c/OP_UNUSED_F1.c */
2896HANDLE_OPCODE(OP_UNUSED_F1)
2897OP_END
2898
2899/* File: c/OP_IGET_QUICK.c */
2900HANDLE_IGET_X_QUICK(OP_IGET_QUICK, "", Int, )
2901OP_END
2902
2903/* File: c/OP_IGET_WIDE_QUICK.c */
2904HANDLE_IGET_X_QUICK(OP_IGET_WIDE_QUICK, "-wide", Long, _WIDE)
2905OP_END
2906
2907/* File: c/OP_IGET_OBJECT_QUICK.c */
2908HANDLE_IGET_X_QUICK(OP_IGET_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
2909OP_END
2910
2911/* File: c/OP_IPUT_QUICK.c */
2912HANDLE_IPUT_X_QUICK(OP_IPUT_QUICK, "", Int, )
2913OP_END
2914
2915/* File: c/OP_IPUT_WIDE_QUICK.c */
2916HANDLE_IPUT_X_QUICK(OP_IPUT_WIDE_QUICK, "-wide", Long, _WIDE)
2917OP_END
2918
2919/* File: c/OP_IPUT_OBJECT_QUICK.c */
2920HANDLE_IPUT_X_QUICK(OP_IPUT_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
2921OP_END
2922
2923/* File: c/OP_INVOKE_VIRTUAL_QUICK.c */
2924HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2925 GOTO_invoke(invokeVirtualQuick, false);
2926OP_END
2927
2928/* File: c/OP_INVOKE_VIRTUAL_QUICK_RANGE.c */
2929HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK_RANGE/*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2930 GOTO_invoke(invokeVirtualQuick, true);
2931OP_END
2932
2933/* File: c/OP_INVOKE_SUPER_QUICK.c */
2934HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2935 GOTO_invoke(invokeSuperQuick, false);
2936OP_END
2937
2938/* File: c/OP_INVOKE_SUPER_QUICK_RANGE.c */
2939HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2940 GOTO_invoke(invokeSuperQuick, true);
2941OP_END
2942
2943/* File: c/OP_UNUSED_FC.c */
2944HANDLE_OPCODE(OP_UNUSED_FC)
2945OP_END
2946
2947/* File: c/OP_UNUSED_FD.c */
2948HANDLE_OPCODE(OP_UNUSED_FD)
2949OP_END
2950
2951/* File: c/OP_UNUSED_FE.c */
2952HANDLE_OPCODE(OP_UNUSED_FE)
2953OP_END
2954
2955/* File: c/OP_UNUSED_FF.c */
2956HANDLE_OPCODE(OP_UNUSED_FF)
2957 /*
2958 * In portable interp, most unused opcodes will fall through to here.
2959 */
2960 LOGE("unknown opcode 0x%02x\n", INST_INST(inst));
2961 dvmAbort();
2962 FINISH(1);
2963OP_END
2964
2965/* File: cstubs/entry.c */
2966/*
2967 * Handler function table, one entry per opcode.
2968 */
2969#undef H
2970#define H(_op) dvmMterp_##_op
2971DEFINE_GOTO_TABLE(gDvmMterpHandlers)
2972
2973#undef H
2974#define H(_op) #_op
2975DEFINE_GOTO_TABLE(gDvmMterpHandlerNames)
2976
2977#include <setjmp.h>
2978
2979/*
2980 * C mterp entry point. This just calls the various C fallbacks, making
2981 * this a slow but portable interpeter.
2982 *
2983 * This is only used for the "allstubs" variant.
2984 */
2985bool dvmMterpStdRun(MterpGlue* glue)
2986{
2987 jmp_buf jmpBuf;
2988 int changeInterp;
2989
2990 glue->bailPtr = &jmpBuf;
2991
2992 /*
2993 * We want to return "changeInterp" as a boolean, but we can't return
2994 * zero through longjmp, so we return (boolean+1).
2995 */
2996 changeInterp = setjmp(jmpBuf) -1;
2997 if (changeInterp >= 0) {
2998 Thread* threadSelf = dvmThreadSelf();
2999 LOGVV("mterp threadid=%d returning %d\n",
3000 threadSelf->threadId, changeInterp);
3001 return changeInterp;
3002 }
3003
3004 /*
3005 * We may not be starting at a point where we're executing instructions.
3006 * We need to pick up where the other interpreter left off.
3007 *
3008 * In some cases we need to call into a throw/return handler which
3009 * will do some processing and then either return to us (updating "glue")
3010 * or longjmp back out.
3011 */
3012 switch (glue->entryPoint) {
3013 case kInterpEntryInstr:
3014 /* just start at the start */
3015 break;
3016 case kInterpEntryReturn:
3017 dvmMterp_returnFromMethod(glue);
3018 break;
3019 case kInterpEntryThrow:
3020 dvmMterp_exceptionThrown(glue);
3021 break;
3022 default:
3023 dvmAbort();
3024 }
3025
3026 /* run until somebody longjmp()s out */
3027 while (true) {
3028 typedef void (*Handler)(MterpGlue* glue);
3029
3030 u2 inst = /*glue->*/pc[0];
3031 Handler handler = (Handler) gDvmMterpHandlers[inst & 0xff];
3032 LOGVV("handler %p %s\n",
3033 handler, (const char*) gDvmMterpHandlerNames[inst & 0xff]);
3034 (*handler)(glue);
3035 }
3036}
3037
3038/*
3039 * C mterp exit point. Call here to bail out of the interpreter.
3040 */
3041void dvmMterpStdBail(MterpGlue* glue, bool changeInterp)
3042{
3043 jmp_buf* pJmpBuf = glue->bailPtr;
3044 longjmp(*pJmpBuf, ((int)changeInterp)+1);
3045}
3046
3047
3048/* File: c/gotoTargets.c */
3049/*
3050 * C footer. This has some common code shared by the various targets.
3051 */
3052
3053/*
3054 * Everything from here on is a "goto target". In the basic interpreter
3055 * we jump into these targets and then jump directly to the handler for
3056 * next instruction. Here, these are subroutines that return to the caller.
3057 */
3058
3059GOTO_TARGET(filledNewArray, bool methodCallRange)
3060 {
3061 ClassObject* arrayClass;
3062 ArrayObject* newArray;
3063 u4* contents;
3064 char typeCh;
3065 int i;
3066 u4 arg5;
3067
3068 EXPORT_PC();
3069
3070 ref = FETCH(1); /* class ref */
3071 vdst = FETCH(2); /* first 4 regs -or- range base */
3072
3073 if (methodCallRange) {
3074 vsrc1 = INST_AA(inst); /* #of elements */
3075 arg5 = -1; /* silence compiler warning */
3076 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
3077 vsrc1, ref, vdst, vdst+vsrc1-1);
3078 } else {
3079 arg5 = INST_A(inst);
3080 vsrc1 = INST_B(inst); /* #of elements */
3081 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
3082 vsrc1, ref, vdst, arg5);
3083 }
3084
3085 /*
3086 * Resolve the array class.
3087 */
3088 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
3089 if (arrayClass == NULL) {
3090 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
3091 if (arrayClass == NULL)
3092 GOTO_exceptionThrown();
3093 }
3094 /*
3095 if (!dvmIsArrayClass(arrayClass)) {
3096 dvmThrowException("Ljava/lang/RuntimeError;",
3097 "filled-new-array needs array class");
3098 GOTO_exceptionThrown();
3099 }
3100 */
3101 /* verifier guarantees this is an array class */
3102 assert(dvmIsArrayClass(arrayClass));
3103 assert(dvmIsClassInitialized(arrayClass));
3104
3105 /*
3106 * Create an array of the specified type.
3107 */
3108 LOGVV("+++ filled-new-array type is '%s'\n", arrayClass->descriptor);
3109 typeCh = arrayClass->descriptor[1];
3110 if (typeCh == 'D' || typeCh == 'J') {
3111 /* category 2 primitives not allowed */
3112 dvmThrowException("Ljava/lang/RuntimeError;",
3113 "bad filled array req");
3114 GOTO_exceptionThrown();
3115 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
3116 /* TODO: requires multiple "fill in" loops with different widths */
3117 LOGE("non-int primitives not implemented\n");
3118 dvmThrowException("Ljava/lang/InternalError;",
3119 "filled-new-array not implemented for anything but 'int'");
3120 GOTO_exceptionThrown();
3121 }
3122
3123 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
3124 if (newArray == NULL)
3125 GOTO_exceptionThrown();
3126
3127 /*
3128 * Fill in the elements. It's legal for vsrc1 to be zero.
3129 */
3130 contents = (u4*) newArray->contents;
3131 if (methodCallRange) {
3132 for (i = 0; i < vsrc1; i++)
3133 contents[i] = GET_REGISTER(vdst+i);
3134 } else {
3135 assert(vsrc1 <= 5);
3136 if (vsrc1 == 5) {
3137 contents[4] = GET_REGISTER(arg5);
3138 vsrc1--;
3139 }
3140 for (i = 0; i < vsrc1; i++) {
3141 contents[i] = GET_REGISTER(vdst & 0x0f);
3142 vdst >>= 4;
3143 }
3144 }
3145
3146 retval.l = newArray;
3147 }
3148 FINISH(3);
3149GOTO_TARGET_END
3150
3151
3152GOTO_TARGET(invokeVirtual, bool methodCallRange)
3153 {
3154 Method* baseMethod;
3155 Object* thisPtr;
3156
3157 EXPORT_PC();
3158
3159 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3160 ref = FETCH(1); /* method ref */
3161 vdst = FETCH(2); /* 4 regs -or- first reg */
3162
3163 /*
3164 * The object against which we are executing a method is always
3165 * in the first argument.
3166 */
3167 if (methodCallRange) {
3168 assert(vsrc1 > 0);
3169 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
3170 vsrc1, ref, vdst, vdst+vsrc1-1);
3171 thisPtr = (Object*) GET_REGISTER(vdst);
3172 } else {
3173 assert((vsrc1>>4) > 0);
3174 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
3175 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3176 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3177 }
3178
3179 if (!checkForNull(thisPtr))
3180 GOTO_exceptionThrown();
3181
3182 /*
3183 * Resolve the method. This is the correct method for the static
3184 * type of the object. We also verify access permissions here.
3185 */
3186 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3187 if (baseMethod == NULL) {
3188 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3189 if (baseMethod == NULL) {
3190 ILOGV("+ unknown method or access denied\n");
3191 GOTO_exceptionThrown();
3192 }
3193 }
3194
3195 /*
3196 * Combine the object we found with the vtable offset in the
3197 * method.
3198 */
3199 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
3200 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
3201
3202#if 0
3203 if (dvmIsAbstractMethod(methodToCall)) {
3204 /*
3205 * This can happen if you create two classes, Base and Sub, where
3206 * Sub is a sub-class of Base. Declare a protected abstract
3207 * method foo() in Base, and invoke foo() from a method in Base.
3208 * Base is an "abstract base class" and is never instantiated
3209 * directly. Now, Override foo() in Sub, and use Sub. This
3210 * Works fine unless Sub stops providing an implementation of
3211 * the method.
3212 */
3213 dvmThrowException("Ljava/lang/AbstractMethodError;",
3214 "abstract method not implemented");
3215 GOTO_exceptionThrown();
3216 }
3217#else
3218 assert(!dvmIsAbstractMethod(methodToCall) ||
3219 methodToCall->nativeFunc != NULL);
3220#endif
3221
3222 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s\n",
3223 baseMethod->clazz->descriptor, baseMethod->name,
3224 (u4) baseMethod->methodIndex,
3225 methodToCall->clazz->descriptor, methodToCall->name);
3226 assert(methodToCall != NULL);
3227
3228#if 0
3229 if (vsrc1 != methodToCall->insSize) {
3230 LOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s\n",
3231 baseMethod->clazz->descriptor, baseMethod->name,
3232 (u4) baseMethod->methodIndex,
3233 methodToCall->clazz->descriptor, methodToCall->name);
3234 //dvmDumpClass(baseMethod->clazz);
3235 //dvmDumpClass(methodToCall->clazz);
3236 dvmDumpAllClasses(0);
3237 }
3238#endif
3239
3240 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3241 }
3242GOTO_TARGET_END
3243
3244GOTO_TARGET(invokeSuper, bool methodCallRange)
3245 {
3246 Method* baseMethod;
3247 u2 thisReg;
3248
3249 EXPORT_PC();
3250
3251 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3252 ref = FETCH(1); /* method ref */
3253 vdst = FETCH(2); /* 4 regs -or- first reg */
3254
3255 if (methodCallRange) {
3256 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
3257 vsrc1, ref, vdst, vdst+vsrc1-1);
3258 thisReg = vdst;
3259 } else {
3260 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
3261 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3262 thisReg = vdst & 0x0f;
3263 }
3264 /* impossible in well-formed code, but we must check nevertheless */
3265 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3266 GOTO_exceptionThrown();
3267
3268 /*
3269 * Resolve the method. This is the correct method for the static
3270 * type of the object. We also verify access permissions here.
3271 * The first arg to dvmResolveMethod() is just the referring class
3272 * (used for class loaders and such), so we don't want to pass
3273 * the superclass into the resolution call.
3274 */
3275 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3276 if (baseMethod == NULL) {
3277 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3278 if (baseMethod == NULL) {
3279 ILOGV("+ unknown method or access denied\n");
3280 GOTO_exceptionThrown();
3281 }
3282 }
3283
3284 /*
3285 * Combine the object we found with the vtable offset in the
3286 * method's class.
3287 *
3288 * We're using the current method's class' superclass, not the
3289 * superclass of "this". This is because we might be executing
3290 * in a method inherited from a superclass, and we want to run
3291 * in that class' superclass.
3292 */
3293 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
3294 /*
3295 * Method does not exist in the superclass. Could happen if
3296 * superclass gets updated.
3297 */
3298 dvmThrowException("Ljava/lang/NoSuchMethodError;",
3299 baseMethod->name);
3300 GOTO_exceptionThrown();
3301 }
3302 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
3303#if 0
3304 if (dvmIsAbstractMethod(methodToCall)) {
3305 dvmThrowException("Ljava/lang/AbstractMethodError;",
3306 "abstract method not implemented");
3307 GOTO_exceptionThrown();
3308 }
3309#else
3310 assert(!dvmIsAbstractMethod(methodToCall) ||
3311 methodToCall->nativeFunc != NULL);
3312#endif
3313 LOGVV("+++ base=%s.%s super-virtual=%s.%s\n",
3314 baseMethod->clazz->descriptor, baseMethod->name,
3315 methodToCall->clazz->descriptor, methodToCall->name);
3316 assert(methodToCall != NULL);
3317
3318 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3319 }
3320GOTO_TARGET_END
3321
3322GOTO_TARGET(invokeInterface, bool methodCallRange)
3323 {
3324 Object* thisPtr;
3325 ClassObject* thisClass;
3326
3327 EXPORT_PC();
3328
3329 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3330 ref = FETCH(1); /* method ref */
3331 vdst = FETCH(2); /* 4 regs -or- first reg */
3332
3333 /*
3334 * The object against which we are executing a method is always
3335 * in the first argument.
3336 */
3337 if (methodCallRange) {
3338 assert(vsrc1 > 0);
3339 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
3340 vsrc1, ref, vdst, vdst+vsrc1-1);
3341 thisPtr = (Object*) GET_REGISTER(vdst);
3342 } else {
3343 assert((vsrc1>>4) > 0);
3344 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
3345 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3346 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3347 }
3348 if (!checkForNull(thisPtr))
3349 GOTO_exceptionThrown();
3350
3351 thisClass = thisPtr->clazz;
3352
3353 /*
3354 * Given a class and a method index, find the Method* with the
3355 * actual code we want to execute.
3356 */
3357 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
3358 methodClassDex);
3359 if (methodToCall == NULL) {
3360 assert(dvmCheckException(self));
3361 GOTO_exceptionThrown();
3362 }
3363
3364 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3365 }
3366GOTO_TARGET_END
3367
3368GOTO_TARGET(invokeDirect, bool methodCallRange)
3369 {
3370 u2 thisReg;
3371
3372 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3373 ref = FETCH(1); /* method ref */
3374 vdst = FETCH(2); /* 4 regs -or- first reg */
3375
3376 EXPORT_PC();
3377
3378 if (methodCallRange) {
3379 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
3380 vsrc1, ref, vdst, vdst+vsrc1-1);
3381 thisReg = vdst;
3382 } else {
3383 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
3384 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3385 thisReg = vdst & 0x0f;
3386 }
3387 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3388 GOTO_exceptionThrown();
3389
3390 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3391 if (methodToCall == NULL) {
3392 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
3393 METHOD_DIRECT);
3394 if (methodToCall == NULL) {
3395 ILOGV("+ unknown direct method\n"); // should be impossible
3396 GOTO_exceptionThrown();
3397 }
3398 }
3399 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3400 }
3401GOTO_TARGET_END
3402
3403GOTO_TARGET(invokeStatic, bool methodCallRange)
3404 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3405 ref = FETCH(1); /* method ref */
3406 vdst = FETCH(2); /* 4 regs -or- first reg */
3407
3408 EXPORT_PC();
3409
3410 if (methodCallRange)
3411 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
3412 vsrc1, ref, vdst, vdst+vsrc1-1);
3413 else
3414 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
3415 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3416
3417 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3418 if (methodToCall == NULL) {
3419 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
3420 if (methodToCall == NULL) {
3421 ILOGV("+ unknown method\n");
3422 GOTO_exceptionThrown();
3423 }
3424 }
3425 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3426GOTO_TARGET_END
3427
3428GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
3429 {
3430 Object* thisPtr;
3431
3432 EXPORT_PC();
3433
3434 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3435 ref = FETCH(1); /* vtable index */
3436 vdst = FETCH(2); /* 4 regs -or- first reg */
3437
3438 /*
3439 * The object against which we are executing a method is always
3440 * in the first argument.
3441 */
3442 if (methodCallRange) {
3443 assert(vsrc1 > 0);
3444 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3445 vsrc1, ref, vdst, vdst+vsrc1-1);
3446 thisPtr = (Object*) GET_REGISTER(vdst);
3447 } else {
3448 assert((vsrc1>>4) > 0);
3449 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
3450 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3451 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3452 }
3453
3454 if (!checkForNull(thisPtr))
3455 GOTO_exceptionThrown();
3456
3457 /*
3458 * Combine the object we found with the vtable offset in the
3459 * method.
3460 */
3461 assert(ref < thisPtr->clazz->vtableCount);
3462 methodToCall = thisPtr->clazz->vtable[ref];
3463
3464#if 0
3465 if (dvmIsAbstractMethod(methodToCall)) {
3466 dvmThrowException("Ljava/lang/AbstractMethodError;",
3467 "abstract method not implemented");
3468 GOTO_exceptionThrown();
3469 }
3470#else
3471 assert(!dvmIsAbstractMethod(methodToCall) ||
3472 methodToCall->nativeFunc != NULL);
3473#endif
3474
3475 LOGVV("+++ virtual[%d]=%s.%s\n",
3476 ref, methodToCall->clazz->descriptor, methodToCall->name);
3477 assert(methodToCall != NULL);
3478
3479 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3480 }
3481GOTO_TARGET_END
3482
3483GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
3484 {
3485 u2 thisReg;
3486
3487 EXPORT_PC();
3488
3489 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3490 ref = FETCH(1); /* vtable index */
3491 vdst = FETCH(2); /* 4 regs -or- first reg */
3492
3493 if (methodCallRange) {
3494 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3495 vsrc1, ref, vdst, vdst+vsrc1-1);
3496 thisReg = vdst;
3497 } else {
3498 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
3499 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3500 thisReg = vdst & 0x0f;
3501 }
3502 /* impossible in well-formed code, but we must check nevertheless */
3503 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3504 GOTO_exceptionThrown();
3505
3506#if 0 /* impossible in optimized + verified code */
3507 if (ref >= curMethod->clazz->super->vtableCount) {
3508 dvmThrowException("Ljava/lang/NoSuchMethodError;", NULL);
3509 GOTO_exceptionThrown();
3510 }
3511#else
3512 assert(ref < curMethod->clazz->super->vtableCount);
3513#endif
3514
3515 /*
3516 * Combine the object we found with the vtable offset in the
3517 * method's class.
3518 *
3519 * We're using the current method's class' superclass, not the
3520 * superclass of "this". This is because we might be executing
3521 * in a method inherited from a superclass, and we want to run
3522 * in the method's class' superclass.
3523 */
3524 methodToCall = curMethod->clazz->super->vtable[ref];
3525
3526#if 0
3527 if (dvmIsAbstractMethod(methodToCall)) {
3528 dvmThrowException("Ljava/lang/AbstractMethodError;",
3529 "abstract method not implemented");
3530 GOTO_exceptionThrown();
3531 }
3532#else
3533 assert(!dvmIsAbstractMethod(methodToCall) ||
3534 methodToCall->nativeFunc != NULL);
3535#endif
3536 LOGVV("+++ super-virtual[%d]=%s.%s\n",
3537 ref, methodToCall->clazz->descriptor, methodToCall->name);
3538 assert(methodToCall != NULL);
3539
3540 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3541 }
3542GOTO_TARGET_END
3543
3544
3545
3546 /*
3547 * General handling for return-void, return, and return-wide. Put the
3548 * return value in "retval" before jumping here.
3549 */
3550GOTO_TARGET(returnFromMethod)
3551 {
3552 StackSaveArea* saveArea;
3553
3554 /*
3555 * We must do this BEFORE we pop the previous stack frame off, so
3556 * that the GC can see the return value (if any) in the local vars.
3557 *
3558 * Since this is now an interpreter switch point, we must do it before
3559 * we do anything at all.
3560 */
3561 PERIODIC_CHECKS(kInterpEntryReturn, 0);
3562
3563 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
3564 retval.j, curMethod->clazz->descriptor, curMethod->name,
3565 curMethod->signature);
3566 //DUMP_REGS(curMethod, fp);
3567
3568 saveArea = SAVEAREA_FROM_FP(fp);
3569
3570#ifdef EASY_GDB
3571 debugSaveArea = saveArea;
3572#endif
3573#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3574 TRACE_METHOD_EXIT(self, curMethod);
3575#endif
3576
3577 /* back up to previous frame and see if we hit a break */
3578 fp = saveArea->prevFrame;
3579 assert(fp != NULL);
3580 if (dvmIsBreakFrame(fp)) {
3581 /* bail without popping the method frame from stack */
3582 LOGVV("+++ returned into break frame\n");
3583 GOTO_bail();
3584 }
3585
3586 /* update thread FP, and reset local variables */
3587 self->curFrame = fp;
3588 curMethod = SAVEAREA_FROM_FP(fp)->method;
3589 //methodClass = curMethod->clazz;
3590 methodClassDex = curMethod->clazz->pDvmDex;
3591 pc = saveArea->savedPc;
3592 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
3593 curMethod->name, curMethod->signature);
3594
3595 /* use FINISH on the caller's invoke instruction */
3596 //u2 invokeInstr = INST_INST(FETCH(0));
3597 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3598 invokeInstr <= OP_INVOKE_INTERFACE*/)
3599 {
3600 FINISH(3);
3601 } else {
3602 //LOGE("Unknown invoke instr %02x at %d\n",
3603 // invokeInstr, (int) (pc - curMethod->insns));
3604 assert(false);
3605 }
3606 }
3607GOTO_TARGET_END
3608
3609
3610 /*
3611 * Jump here when the code throws an exception.
3612 *
3613 * By the time we get here, the Throwable has been created and the stack
3614 * trace has been saved off.
3615 */
3616GOTO_TARGET(exceptionThrown)
3617 {
3618 Object* exception;
3619 int catchRelPc;
3620
3621 /*
3622 * Since this is now an interpreter switch point, we must do it before
3623 * we do anything at all.
3624 */
3625 PERIODIC_CHECKS(kInterpEntryThrow, 0);
3626
3627 /*
3628 * We save off the exception and clear the exception status. While
3629 * processing the exception we might need to load some Throwable
3630 * classes, and we don't want class loader exceptions to get
3631 * confused with this one.
3632 */
3633 assert(dvmCheckException(self));
3634 exception = dvmGetException(self);
3635 dvmAddTrackedAlloc(exception, self);
3636 dvmClearException(self);
3637
3638 LOGV("Handling exception %s at %s:%d\n",
3639 exception->clazz->descriptor, curMethod->name,
3640 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3641
3642#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3643 /*
3644 * Tell the debugger about it.
3645 *
3646 * TODO: if the exception was thrown by interpreted code, control
3647 * fell through native, and then back to us, we will report the
3648 * exception at the point of the throw and again here. We can avoid
3649 * this by not reporting exceptions when we jump here directly from
3650 * the native call code above, but then we won't report exceptions
3651 * that were thrown *from* the JNI code (as opposed to *through* it).
3652 *
3653 * The correct solution is probably to ignore from-native exceptions
3654 * here, and have the JNI exception code do the reporting to the
3655 * debugger.
3656 */
3657 if (gDvm.debuggerActive) {
3658 void* catchFrame;
3659 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3660 exception, true, &catchFrame);
3661 dvmDbgPostException(fp, pc - curMethod->insns, catchFrame,
3662 catchRelPc, exception);
3663 }
3664#endif
3665
3666 /*
3667 * We need to unroll to the catch block or the nearest "break"
3668 * frame.
3669 *
3670 * A break frame could indicate that we have reached an intermediate
3671 * native call, or have gone off the top of the stack and the thread
3672 * needs to exit. Either way, we return from here, leaving the
3673 * exception raised.
3674 *
3675 * If we do find a catch block, we want to transfer execution to
3676 * that point.
3677 */
3678 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3679 exception, false, (void*)&fp);
3680
3681 /*
3682 * Restore the stack bounds after an overflow. This isn't going to
3683 * be correct in all circumstances, e.g. if JNI code devours the
3684 * exception this won't happen until some other exception gets
3685 * thrown. If the code keeps pushing the stack bounds we'll end
3686 * up aborting the VM.
3687 *
3688 * Note we want to do this *after* the call to dvmFindCatchBlock,
3689 * because that may need extra stack space to resolve exception
3690 * classes (e.g. through a class loader).
3691 */
3692 if (self->stackOverflowed)
3693 dvmCleanupStackOverflow(self);
3694
3695 if (catchRelPc < 0) {
3696 /* falling through to JNI code or off the bottom of the stack */
3697#if DVM_SHOW_EXCEPTION >= 2
3698 LOGD("Exception %s from %s:%d not caught locally\n",
3699 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3700 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3701#endif
3702 dvmSetException(self, exception);
3703 dvmReleaseTrackedAlloc(exception, self);
3704 GOTO_bail();
3705 }
3706
3707#if DVM_SHOW_EXCEPTION >= 3
3708 {
3709 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
3710 LOGD("Exception %s thrown from %s:%d to %s:%d\n",
3711 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3712 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
3713 dvmGetMethodSourceFile(catchMethod),
3714 dvmLineNumFromPC(catchMethod, catchRelPc));
3715 }
3716#endif
3717
3718 /*
3719 * Adjust local variables to match self->curFrame and the
3720 * updated PC.
3721 */
3722 //fp = (u4*) self->curFrame;
3723 curMethod = SAVEAREA_FROM_FP(fp)->method;
3724 //methodClass = curMethod->clazz;
3725 methodClassDex = curMethod->clazz->pDvmDex;
3726 pc = curMethod->insns + catchRelPc;
3727 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
3728 curMethod->name, curMethod->signature);
3729 DUMP_REGS(curMethod, fp, false); // show all regs
3730
3731 /*
3732 * Restore the exception if the handler wants it.
3733 *
3734 * The Dalvik spec mandates that, if an exception handler wants to
3735 * do something with the exception, the first instruction executed
3736 * must be "move-exception". We can pass the exception along
3737 * through the thread struct, and let the move-exception instruction
3738 * clear it for us.
3739 *
3740 * If the handler doesn't call move-exception, we don't want to
3741 * finish here with an exception still pending.
3742 */
3743 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
3744 dvmSetException(self, exception);
3745
3746 dvmReleaseTrackedAlloc(exception, self);
3747 FINISH(0);
3748 }
3749GOTO_TARGET_END
3750
3751
3752 /*
3753 * General handling for invoke-{virtual,super,direct,static,interface},
3754 * including "quick" variants.
3755 *
3756 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
3757 * depending on whether this is a "/range" instruction.
3758 *
3759 * For a range call:
3760 * "vsrc1" holds the argument count (8 bits)
3761 * "vdst" holds the first argument in the range
3762 * For a non-range call:
3763 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
3764 * "vdst" holds four 4-bit register indices
3765 *
3766 * The caller must EXPORT_PC before jumping here, because any method
3767 * call can throw a stack overflow exception.
3768 */
3769GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
3770 u2 count, u2 regs)
3771 {
3772 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
3773
3774 //printf("range=%d call=%p count=%d regs=0x%04x\n",
3775 // methodCallRange, methodToCall, count, regs);
3776 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
3777 // methodToCall->name, methodToCall->signature);
3778
3779 u4* outs;
3780 int i;
3781
3782 /*
3783 * Copy args. This may corrupt vsrc1/vdst.
3784 */
3785 if (methodCallRange) {
3786 // could use memcpy or a "Duff's device"; most functions have
3787 // so few args it won't matter much
3788 assert(vsrc1 <= curMethod->outsSize);
3789 assert(vsrc1 == methodToCall->insSize);
3790 outs = OUTS_FROM_FP(fp, vsrc1);
3791 for (i = 0; i < vsrc1; i++)
3792 outs[i] = GET_REGISTER(vdst+i);
3793 } else {
3794 u4 count = vsrc1 >> 4;
3795
3796 assert(count <= curMethod->outsSize);
3797 assert(count == methodToCall->insSize);
3798 assert(count <= 5);
3799
3800 outs = OUTS_FROM_FP(fp, count);
3801#if 0
3802 if (count == 5) {
3803 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3804 count--;
3805 }
3806 for (i = 0; i < (int) count; i++) {
3807 outs[i] = GET_REGISTER(vdst & 0x0f);
3808 vdst >>= 4;
3809 }
3810#else
3811 // This version executes fewer instructions but is larger
3812 // overall. Seems to be a teensy bit faster.
3813 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
3814 switch (count) {
3815 case 5:
3816 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3817 case 4:
3818 outs[3] = GET_REGISTER(vdst >> 12);
3819 case 3:
3820 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
3821 case 2:
3822 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
3823 case 1:
3824 outs[0] = GET_REGISTER(vdst & 0x0f);
3825 default:
3826 ;
3827 }
3828#endif
3829 }
3830 }
3831
3832 /*
3833 * (This was originally a "goto" target; I've kept it separate from the
3834 * stuff above in case we want to refactor things again.)
3835 *
3836 * At this point, we have the arguments stored in the "outs" area of
3837 * the current method's stack frame, and the method to call in
3838 * "methodToCall". Push a new stack frame.
3839 */
3840 {
3841 StackSaveArea* newSaveArea;
3842 u4* newFp;
3843
3844 ILOGV("> %s%s.%s %s",
3845 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
3846 methodToCall->clazz->descriptor, methodToCall->name,
3847 methodToCall->signature);
3848
3849 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
3850 newSaveArea = SAVEAREA_FROM_FP(newFp);
3851
3852 /* verify that we have enough space */
3853 if (true) {
3854 u1* bottom;
3855 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
3856 if (bottom < self->interpStackEnd) {
3857 /* stack overflow */
3858 LOGV("Stack overflow on method call (start=%p end=%p newBot=%p size=%d '%s')\n",
3859 self->interpStackStart, self->interpStackEnd, bottom,
3860 self->interpStackSize, methodToCall->name);
3861 dvmHandleStackOverflow(self);
3862 assert(dvmCheckException(self));
3863 GOTO_exceptionThrown();
3864 }
3865 //LOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p\n",
3866 // fp, newFp, newSaveArea, bottom);
3867 }
3868
3869#ifdef LOG_INSTR
3870 if (methodToCall->registersSize > methodToCall->insSize) {
3871 /*
3872 * This makes valgrind quiet when we print registers that
3873 * haven't been initialized. Turn it off when the debug
3874 * messages are disabled -- we want valgrind to report any
3875 * used-before-initialized issues.
3876 */
3877 memset(newFp, 0xcc,
3878 (methodToCall->registersSize - methodToCall->insSize) * 4);
3879 }
3880#endif
3881
3882#ifdef EASY_GDB
3883 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
3884#endif
3885 newSaveArea->prevFrame = fp;
3886 newSaveArea->savedPc = pc;
3887 newSaveArea->method = methodToCall;
3888
3889 if (!dvmIsNativeMethod(methodToCall)) {
3890 /*
3891 * "Call" interpreted code. Reposition the PC, update the
3892 * frame pointer and other local state, and continue.
3893 */
3894 curMethod = methodToCall;
3895 methodClassDex = curMethod->clazz->pDvmDex;
3896 pc = methodToCall->insns;
3897 fp = self->curFrame = newFp;
3898#ifdef EASY_GDB
3899 debugSaveArea = SAVEAREA_FROM_FP(newFp);
3900#endif
3901#if INTERP_TYPE == INTERP_DBG
3902 debugIsMethodEntry = true; // profiling, debugging
3903#endif
3904 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
3905 curMethod->name, curMethod->signature);
3906 DUMP_REGS(curMethod, fp, true); // show input args
3907 FINISH(0); // jump to method start
3908 } else {
3909 /* set this up for JNI locals, even if not a JNI native */
3910 newSaveArea->xtra.localRefTop = self->jniLocalRefTable.nextEntry;
3911
3912 self->curFrame = newFp;
3913
3914 DUMP_REGS(methodToCall, newFp, true); // show input args
3915
3916#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3917 if (gDvm.debuggerActive) {
3918 dvmDbgPostLocationEvent(methodToCall, -1,
3919 dvmGetThisPtr(curMethod, fp), DBG_METHOD_ENTRY);
3920 }
3921#endif
3922#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3923 TRACE_METHOD_ENTER(self, methodToCall);
3924#endif
3925
3926 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
3927 methodToCall->name, methodToCall->signature);
3928
3929 /*
3930 * Jump through native call bridge. Because we leave no
3931 * space for locals on native calls, "newFp" points directly
3932 * to the method arguments.
3933 */
3934 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
3935
3936#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3937 if (gDvm.debuggerActive) {
3938 dvmDbgPostLocationEvent(methodToCall, -1,
3939 dvmGetThisPtr(curMethod, fp), DBG_METHOD_EXIT);
3940 }
3941#endif
3942#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3943 TRACE_METHOD_EXIT(self, methodToCall);
3944#endif
3945
3946 /* pop frame off */
3947 dvmPopJniLocals(self, newSaveArea);
3948 self->curFrame = fp;
3949
3950 /*
3951 * If the native code threw an exception, or interpreted code
3952 * invoked by the native call threw one and nobody has cleared
3953 * it, jump to our local exception handling.
3954 */
3955 if (dvmCheckException(self)) {
3956 LOGV("Exception thrown by/below native code\n");
3957 GOTO_exceptionThrown();
3958 }
3959
3960 ILOGD("> retval=0x%llx (leaving native)", retval.j);
3961 ILOGD("> (return from native %s.%s to %s.%s %s)",
3962 methodToCall->clazz->descriptor, methodToCall->name,
3963 curMethod->clazz->descriptor, curMethod->name,
3964 curMethod->signature);
3965
3966 //u2 invokeInstr = INST_INST(FETCH(0));
3967 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3968 invokeInstr <= OP_INVOKE_INTERFACE*/)
3969 {
3970 FINISH(3);
3971 } else {
3972 //LOGE("Unknown invoke instr %02x at %d\n",
3973 // invokeInstr, (int) (pc - curMethod->insns));
3974 assert(false);
3975 }
3976 }
3977 }
3978 assert(false); // should not get here
3979GOTO_TARGET_END
3980
3981
3982/* File: cstubs/enddefs.c */
3983
3984/* undefine "magic" name remapping */
3985#undef retval
3986#undef pc
3987#undef fp
3988#undef curMethod
3989#undef methodClassDex
3990#undef self
3991#undef debugTrackedRefStart
3992