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