blob: a0bc17e49242d6867dd219d9eff135de4c234ad3 [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
1187 bool debugIsMethodEntry = interpState->debugIsMethodEntry;
1188#endif
1189#if defined(WITH_TRACKREF_CHECKS)
1190 int debugTrackedRefStart = interpState->debugTrackedRefStart;
1191#endif
1192 DvmDex* methodClassDex; // curMethod->clazz->pDvmDex
1193 JValue retval;
1194
1195 /* core state */
1196 const Method* curMethod; // method we're interpreting
1197 const u2* pc; // program counter
1198 u4* fp; // frame pointer
1199 u2 inst; // current instruction
1200 /* instruction decoding */
1201 u2 ref; // 16-bit quantity fetched directly
1202 u2 vsrc1, vsrc2, vdst; // usually used for register indexes
1203 /* method call setup */
1204 const Method* methodToCall;
1205 bool methodCallRange;
1206
Ben Chengba4fc8b2009-06-01 13:00:29 -07001207
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001208#if defined(THREADED_INTERP)
1209 /* static computed goto table */
1210 DEFINE_GOTO_TABLE(handlerTable);
1211#endif
1212
Ben Chengba4fc8b2009-06-01 13:00:29 -07001213#if defined(WITH_JIT)
1214#if 0
1215 LOGD("*DebugInterp - entrypoint is %d, tgt is 0x%x, %s\n",
1216 interpState->entryPoint,
1217 interpState->pc,
1218 interpState->method->name);
1219#endif
Ben Chengba4fc8b2009-06-01 13:00:29 -07001220#if INTERP_TYPE == INTERP_DBG
Bill Buzbee06bb8392010-01-31 18:53:15 -08001221 /* Check to see if we've got a trace selection request. */
1222 if (
1223#if defined(WITH_SELF_VERIFICATION)
1224 (interpState->jitState != kJitSelfVerification) &&
1225#endif
Ben Cheng95cd9ac2010-03-12 16:58:24 -08001226 /*
1227 * Don't bail out of the dbg interpreter if the entry reason is to
1228 * deal with a thrown exception.
1229 */
1230 (interpState->entryPoint != kInterpEntryThrow) &&
Bill Buzbee06bb8392010-01-31 18:53:15 -08001231 !gDvm.debuggerActive &&
1232#if defined(WITH_PROFILER)
1233 (gDvm.activeProfilers == 0) &&
1234#endif
1235 dvmJitCheckTraceRequest(self, interpState)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001236 interpState->nextMode = INTERP_STD;
Bill Buzbee06bb8392010-01-31 18:53:15 -08001237 //LOGD("Invalid trace request, exiting\n");
Ben Chengba4fc8b2009-06-01 13:00:29 -07001238 return true;
1239 }
Jeff Hao97319a82009-08-12 16:57:15 -07001240#endif /* INTERP_TYPE == INTERP_DBG */
1241#endif /* WITH_JIT */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001242
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001243 /* copy state in */
1244 curMethod = interpState->method;
1245 pc = interpState->pc;
1246 fp = interpState->fp;
1247 retval = interpState->retval; /* only need for kInterpEntryReturn? */
1248
1249 methodClassDex = curMethod->clazz->pDvmDex;
1250
1251 LOGVV("threadid=%d: entry(%s) %s.%s pc=0x%x fp=%p ep=%d\n",
1252 self->threadId, (interpState->nextMode == INTERP_STD) ? "STD" : "DBG",
1253 curMethod->clazz->descriptor, curMethod->name, pc - curMethod->insns,
1254 fp, interpState->entryPoint);
1255
1256 /*
1257 * DEBUG: scramble this to ensure we're not relying on it.
1258 */
1259 methodToCall = (const Method*) -1;
1260
1261#if INTERP_TYPE == INTERP_DBG
1262 if (debugIsMethodEntry) {
1263 ILOGD("|-- Now interpreting %s.%s", curMethod->clazz->descriptor,
1264 curMethod->name);
1265 DUMP_REGS(curMethod, interpState->fp, false);
1266 }
1267#endif
1268
1269 switch (interpState->entryPoint) {
1270 case kInterpEntryInstr:
1271 /* just fall through to instruction loop or threaded kickstart */
1272 break;
1273 case kInterpEntryReturn:
Ben Cheng9c147b82009-10-07 16:41:46 -07001274 CHECK_JIT();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001275 goto returnFromMethod;
1276 case kInterpEntryThrow:
1277 goto exceptionThrown;
1278 default:
1279 dvmAbort();
1280 }
1281
1282#ifdef THREADED_INTERP
1283 FINISH(0); /* fetch and execute first instruction */
1284#else
1285 while (1) {
1286 CHECK_DEBUG_AND_PROF(); /* service debugger and profiling */
1287 CHECK_TRACKED_REFS(); /* check local reference tracking */
1288
1289 /* fetch the next 16 bits from the instruction stream */
1290 inst = FETCH(0);
1291
1292 switch (INST_INST(inst)) {
1293#endif
1294
1295/*--- start of opcodes ---*/
1296
1297/* File: c/OP_NOP.c */
1298HANDLE_OPCODE(OP_NOP)
1299 FINISH(1);
1300OP_END
1301
1302/* File: c/OP_MOVE.c */
1303HANDLE_OPCODE(OP_MOVE /*vA, vB*/)
1304 vdst = INST_A(inst);
1305 vsrc1 = INST_B(inst);
1306 ILOGV("|move%s v%d,v%d %s(v%d=0x%08x)",
1307 (INST_INST(inst) == OP_MOVE) ? "" : "-object", vdst, vsrc1,
1308 kSpacing, vdst, GET_REGISTER(vsrc1));
1309 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1310 FINISH(1);
1311OP_END
1312
1313/* File: c/OP_MOVE_FROM16.c */
1314HANDLE_OPCODE(OP_MOVE_FROM16 /*vAA, vBBBB*/)
1315 vdst = INST_AA(inst);
1316 vsrc1 = FETCH(1);
1317 ILOGV("|move%s/from16 v%d,v%d %s(v%d=0x%08x)",
1318 (INST_INST(inst) == OP_MOVE_FROM16) ? "" : "-object", vdst, vsrc1,
1319 kSpacing, vdst, GET_REGISTER(vsrc1));
1320 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1321 FINISH(2);
1322OP_END
1323
1324/* File: c/OP_MOVE_16.c */
1325HANDLE_OPCODE(OP_MOVE_16 /*vAAAA, vBBBB*/)
1326 vdst = FETCH(1);
1327 vsrc1 = FETCH(2);
1328 ILOGV("|move%s/16 v%d,v%d %s(v%d=0x%08x)",
1329 (INST_INST(inst) == OP_MOVE_16) ? "" : "-object", vdst, vsrc1,
1330 kSpacing, vdst, GET_REGISTER(vsrc1));
1331 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1332 FINISH(3);
1333OP_END
1334
1335/* File: c/OP_MOVE_WIDE.c */
1336HANDLE_OPCODE(OP_MOVE_WIDE /*vA, vB*/)
1337 /* IMPORTANT: must correctly handle overlapping registers, e.g. both
1338 * "move-wide v6, v7" and "move-wide v7, v6" */
1339 vdst = INST_A(inst);
1340 vsrc1 = INST_B(inst);
1341 ILOGV("|move-wide v%d,v%d %s(v%d=0x%08llx)", vdst, vsrc1,
1342 kSpacing+5, vdst, GET_REGISTER_WIDE(vsrc1));
1343 SET_REGISTER_WIDE(vdst, GET_REGISTER_WIDE(vsrc1));
1344 FINISH(1);
1345OP_END
1346
1347/* File: c/OP_MOVE_WIDE_FROM16.c */
1348HANDLE_OPCODE(OP_MOVE_WIDE_FROM16 /*vAA, vBBBB*/)
1349 vdst = INST_AA(inst);
1350 vsrc1 = FETCH(1);
1351 ILOGV("|move-wide/from16 v%d,v%d (v%d=0x%08llx)", vdst, vsrc1,
1352 vdst, GET_REGISTER_WIDE(vsrc1));
1353 SET_REGISTER_WIDE(vdst, GET_REGISTER_WIDE(vsrc1));
1354 FINISH(2);
1355OP_END
1356
1357/* File: c/OP_MOVE_WIDE_16.c */
1358HANDLE_OPCODE(OP_MOVE_WIDE_16 /*vAAAA, vBBBB*/)
1359 vdst = FETCH(1);
1360 vsrc1 = FETCH(2);
1361 ILOGV("|move-wide/16 v%d,v%d %s(v%d=0x%08llx)", vdst, vsrc1,
1362 kSpacing+8, vdst, GET_REGISTER_WIDE(vsrc1));
1363 SET_REGISTER_WIDE(vdst, GET_REGISTER_WIDE(vsrc1));
1364 FINISH(3);
1365OP_END
1366
1367/* File: c/OP_MOVE_OBJECT.c */
1368/* File: c/OP_MOVE.c */
1369HANDLE_OPCODE(OP_MOVE_OBJECT /*vA, vB*/)
1370 vdst = INST_A(inst);
1371 vsrc1 = INST_B(inst);
1372 ILOGV("|move%s v%d,v%d %s(v%d=0x%08x)",
1373 (INST_INST(inst) == OP_MOVE) ? "" : "-object", vdst, vsrc1,
1374 kSpacing, vdst, GET_REGISTER(vsrc1));
1375 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1376 FINISH(1);
1377OP_END
1378
1379
1380/* File: c/OP_MOVE_OBJECT_FROM16.c */
1381/* File: c/OP_MOVE_FROM16.c */
1382HANDLE_OPCODE(OP_MOVE_OBJECT_FROM16 /*vAA, vBBBB*/)
1383 vdst = INST_AA(inst);
1384 vsrc1 = FETCH(1);
1385 ILOGV("|move%s/from16 v%d,v%d %s(v%d=0x%08x)",
1386 (INST_INST(inst) == OP_MOVE_FROM16) ? "" : "-object", vdst, vsrc1,
1387 kSpacing, vdst, GET_REGISTER(vsrc1));
1388 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1389 FINISH(2);
1390OP_END
1391
1392
1393/* File: c/OP_MOVE_OBJECT_16.c */
1394/* File: c/OP_MOVE_16.c */
1395HANDLE_OPCODE(OP_MOVE_OBJECT_16 /*vAAAA, vBBBB*/)
1396 vdst = FETCH(1);
1397 vsrc1 = FETCH(2);
1398 ILOGV("|move%s/16 v%d,v%d %s(v%d=0x%08x)",
1399 (INST_INST(inst) == OP_MOVE_16) ? "" : "-object", vdst, vsrc1,
1400 kSpacing, vdst, GET_REGISTER(vsrc1));
1401 SET_REGISTER(vdst, GET_REGISTER(vsrc1));
1402 FINISH(3);
1403OP_END
1404
1405
1406/* File: c/OP_MOVE_RESULT.c */
1407HANDLE_OPCODE(OP_MOVE_RESULT /*vAA*/)
1408 vdst = INST_AA(inst);
1409 ILOGV("|move-result%s v%d %s(v%d=0x%08x)",
1410 (INST_INST(inst) == OP_MOVE_RESULT) ? "" : "-object",
1411 vdst, kSpacing+4, vdst,retval.i);
1412 SET_REGISTER(vdst, retval.i);
1413 FINISH(1);
1414OP_END
1415
1416/* File: c/OP_MOVE_RESULT_WIDE.c */
1417HANDLE_OPCODE(OP_MOVE_RESULT_WIDE /*vAA*/)
1418 vdst = INST_AA(inst);
1419 ILOGV("|move-result-wide v%d %s(0x%08llx)", vdst, kSpacing, retval.j);
1420 SET_REGISTER_WIDE(vdst, retval.j);
1421 FINISH(1);
1422OP_END
1423
1424/* File: c/OP_MOVE_RESULT_OBJECT.c */
1425/* File: c/OP_MOVE_RESULT.c */
1426HANDLE_OPCODE(OP_MOVE_RESULT_OBJECT /*vAA*/)
1427 vdst = INST_AA(inst);
1428 ILOGV("|move-result%s v%d %s(v%d=0x%08x)",
1429 (INST_INST(inst) == OP_MOVE_RESULT) ? "" : "-object",
1430 vdst, kSpacing+4, vdst,retval.i);
1431 SET_REGISTER(vdst, retval.i);
1432 FINISH(1);
1433OP_END
1434
1435
1436/* File: c/OP_MOVE_EXCEPTION.c */
1437HANDLE_OPCODE(OP_MOVE_EXCEPTION /*vAA*/)
1438 vdst = INST_AA(inst);
1439 ILOGV("|move-exception v%d", vdst);
1440 assert(self->exception != NULL);
1441 SET_REGISTER(vdst, (u4)self->exception);
1442 dvmClearException(self);
1443 FINISH(1);
1444OP_END
1445
1446/* File: c/OP_RETURN_VOID.c */
1447HANDLE_OPCODE(OP_RETURN_VOID /**/)
1448 ILOGV("|return-void");
1449#ifndef NDEBUG
1450 retval.j = 0xababababULL; // placate valgrind
1451#endif
1452 GOTO_returnFromMethod();
1453OP_END
1454
1455/* File: c/OP_RETURN.c */
1456HANDLE_OPCODE(OP_RETURN /*vAA*/)
1457 vsrc1 = INST_AA(inst);
1458 ILOGV("|return%s v%d",
1459 (INST_INST(inst) == OP_RETURN) ? "" : "-object", vsrc1);
1460 retval.i = GET_REGISTER(vsrc1);
1461 GOTO_returnFromMethod();
1462OP_END
1463
1464/* File: c/OP_RETURN_WIDE.c */
1465HANDLE_OPCODE(OP_RETURN_WIDE /*vAA*/)
1466 vsrc1 = INST_AA(inst);
1467 ILOGV("|return-wide v%d", vsrc1);
1468 retval.j = GET_REGISTER_WIDE(vsrc1);
1469 GOTO_returnFromMethod();
1470OP_END
1471
1472/* File: c/OP_RETURN_OBJECT.c */
1473/* File: c/OP_RETURN.c */
1474HANDLE_OPCODE(OP_RETURN_OBJECT /*vAA*/)
1475 vsrc1 = INST_AA(inst);
1476 ILOGV("|return%s v%d",
1477 (INST_INST(inst) == OP_RETURN) ? "" : "-object", vsrc1);
1478 retval.i = GET_REGISTER(vsrc1);
1479 GOTO_returnFromMethod();
1480OP_END
1481
1482
1483/* File: c/OP_CONST_4.c */
1484HANDLE_OPCODE(OP_CONST_4 /*vA, #+B*/)
1485 {
1486 s4 tmp;
1487
1488 vdst = INST_A(inst);
1489 tmp = (s4) (INST_B(inst) << 28) >> 28; // sign extend 4-bit value
1490 ILOGV("|const/4 v%d,#0x%02x", vdst, (s4)tmp);
1491 SET_REGISTER(vdst, tmp);
1492 }
1493 FINISH(1);
1494OP_END
1495
1496/* File: c/OP_CONST_16.c */
1497HANDLE_OPCODE(OP_CONST_16 /*vAA, #+BBBB*/)
1498 vdst = INST_AA(inst);
1499 vsrc1 = FETCH(1);
1500 ILOGV("|const/16 v%d,#0x%04x", vdst, (s2)vsrc1);
1501 SET_REGISTER(vdst, (s2) vsrc1);
1502 FINISH(2);
1503OP_END
1504
1505/* File: c/OP_CONST.c */
1506HANDLE_OPCODE(OP_CONST /*vAA, #+BBBBBBBB*/)
1507 {
1508 u4 tmp;
1509
1510 vdst = INST_AA(inst);
1511 tmp = FETCH(1);
1512 tmp |= (u4)FETCH(2) << 16;
1513 ILOGV("|const v%d,#0x%08x", vdst, tmp);
1514 SET_REGISTER(vdst, tmp);
1515 }
1516 FINISH(3);
1517OP_END
1518
1519/* File: c/OP_CONST_HIGH16.c */
1520HANDLE_OPCODE(OP_CONST_HIGH16 /*vAA, #+BBBB0000*/)
1521 vdst = INST_AA(inst);
1522 vsrc1 = FETCH(1);
1523 ILOGV("|const/high16 v%d,#0x%04x0000", vdst, vsrc1);
1524 SET_REGISTER(vdst, vsrc1 << 16);
1525 FINISH(2);
1526OP_END
1527
1528/* File: c/OP_CONST_WIDE_16.c */
1529HANDLE_OPCODE(OP_CONST_WIDE_16 /*vAA, #+BBBB*/)
1530 vdst = INST_AA(inst);
1531 vsrc1 = FETCH(1);
1532 ILOGV("|const-wide/16 v%d,#0x%04x", vdst, (s2)vsrc1);
1533 SET_REGISTER_WIDE(vdst, (s2)vsrc1);
1534 FINISH(2);
1535OP_END
1536
1537/* File: c/OP_CONST_WIDE_32.c */
1538HANDLE_OPCODE(OP_CONST_WIDE_32 /*vAA, #+BBBBBBBB*/)
1539 {
1540 u4 tmp;
1541
1542 vdst = INST_AA(inst);
1543 tmp = FETCH(1);
1544 tmp |= (u4)FETCH(2) << 16;
1545 ILOGV("|const-wide/32 v%d,#0x%08x", vdst, tmp);
1546 SET_REGISTER_WIDE(vdst, (s4) tmp);
1547 }
1548 FINISH(3);
1549OP_END
1550
1551/* File: c/OP_CONST_WIDE.c */
1552HANDLE_OPCODE(OP_CONST_WIDE /*vAA, #+BBBBBBBBBBBBBBBB*/)
1553 {
1554 u8 tmp;
1555
1556 vdst = INST_AA(inst);
1557 tmp = FETCH(1);
1558 tmp |= (u8)FETCH(2) << 16;
1559 tmp |= (u8)FETCH(3) << 32;
1560 tmp |= (u8)FETCH(4) << 48;
1561 ILOGV("|const-wide v%d,#0x%08llx", vdst, tmp);
1562 SET_REGISTER_WIDE(vdst, tmp);
1563 }
1564 FINISH(5);
1565OP_END
1566
1567/* File: c/OP_CONST_WIDE_HIGH16.c */
1568HANDLE_OPCODE(OP_CONST_WIDE_HIGH16 /*vAA, #+BBBB000000000000*/)
1569 vdst = INST_AA(inst);
1570 vsrc1 = FETCH(1);
1571 ILOGV("|const-wide/high16 v%d,#0x%04x000000000000", vdst, vsrc1);
1572 SET_REGISTER_WIDE(vdst, ((u8) vsrc1) << 48);
1573 FINISH(2);
1574OP_END
1575
1576/* File: c/OP_CONST_STRING.c */
1577HANDLE_OPCODE(OP_CONST_STRING /*vAA, string@BBBB*/)
1578 {
1579 StringObject* strObj;
1580
1581 vdst = INST_AA(inst);
1582 ref = FETCH(1);
1583 ILOGV("|const-string v%d string@0x%04x", vdst, ref);
1584 strObj = dvmDexGetResolvedString(methodClassDex, ref);
1585 if (strObj == NULL) {
1586 EXPORT_PC();
1587 strObj = dvmResolveString(curMethod->clazz, ref);
1588 if (strObj == NULL)
1589 GOTO_exceptionThrown();
1590 }
1591 SET_REGISTER(vdst, (u4) strObj);
1592 }
1593 FINISH(2);
1594OP_END
1595
1596/* File: c/OP_CONST_STRING_JUMBO.c */
1597HANDLE_OPCODE(OP_CONST_STRING_JUMBO /*vAA, string@BBBBBBBB*/)
1598 {
1599 StringObject* strObj;
1600 u4 tmp;
1601
1602 vdst = INST_AA(inst);
1603 tmp = FETCH(1);
1604 tmp |= (u4)FETCH(2) << 16;
1605 ILOGV("|const-string/jumbo v%d string@0x%08x", vdst, tmp);
1606 strObj = dvmDexGetResolvedString(methodClassDex, tmp);
1607 if (strObj == NULL) {
1608 EXPORT_PC();
1609 strObj = dvmResolveString(curMethod->clazz, tmp);
1610 if (strObj == NULL)
1611 GOTO_exceptionThrown();
1612 }
1613 SET_REGISTER(vdst, (u4) strObj);
1614 }
1615 FINISH(3);
1616OP_END
1617
1618/* File: c/OP_CONST_CLASS.c */
1619HANDLE_OPCODE(OP_CONST_CLASS /*vAA, class@BBBB*/)
1620 {
1621 ClassObject* clazz;
1622
1623 vdst = INST_AA(inst);
1624 ref = FETCH(1);
1625 ILOGV("|const-class v%d class@0x%04x", vdst, ref);
1626 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1627 if (clazz == NULL) {
1628 EXPORT_PC();
1629 clazz = dvmResolveClass(curMethod->clazz, ref, true);
1630 if (clazz == NULL)
1631 GOTO_exceptionThrown();
1632 }
1633 SET_REGISTER(vdst, (u4) clazz);
1634 }
1635 FINISH(2);
1636OP_END
1637
1638/* File: c/OP_MONITOR_ENTER.c */
1639HANDLE_OPCODE(OP_MONITOR_ENTER /*vAA*/)
1640 {
1641 Object* obj;
1642
1643 vsrc1 = INST_AA(inst);
1644 ILOGV("|monitor-enter v%d %s(0x%08x)",
1645 vsrc1, kSpacing+6, GET_REGISTER(vsrc1));
1646 obj = (Object*)GET_REGISTER(vsrc1);
1647 if (!checkForNullExportPC(obj, fp, pc))
1648 GOTO_exceptionThrown();
1649 ILOGV("+ locking %p %s\n", obj, obj->clazz->descriptor);
The Android Open Source Project99409882009-03-18 22:20:24 -07001650 EXPORT_PC(); /* need for precise GC, also WITH_MONITOR_TRACKING */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001651 dvmLockObject(self, obj);
1652#ifdef WITH_DEADLOCK_PREDICTION
1653 if (dvmCheckException(self))
1654 GOTO_exceptionThrown();
1655#endif
1656 }
1657 FINISH(1);
1658OP_END
1659
1660/* File: c/OP_MONITOR_EXIT.c */
1661HANDLE_OPCODE(OP_MONITOR_EXIT /*vAA*/)
1662 {
1663 Object* obj;
1664
1665 EXPORT_PC();
1666
1667 vsrc1 = INST_AA(inst);
1668 ILOGV("|monitor-exit v%d %s(0x%08x)",
1669 vsrc1, kSpacing+5, GET_REGISTER(vsrc1));
1670 obj = (Object*)GET_REGISTER(vsrc1);
1671 if (!checkForNull(obj)) {
1672 /*
1673 * The exception needs to be processed at the *following*
1674 * instruction, not the current instruction (see the Dalvik
1675 * spec). Because we're jumping to an exception handler,
1676 * we're not actually at risk of skipping an instruction
1677 * by doing so.
1678 */
1679 ADJUST_PC(1); /* monitor-exit width is 1 */
1680 GOTO_exceptionThrown();
1681 }
1682 ILOGV("+ unlocking %p %s\n", obj, obj->clazz->descriptor);
1683 if (!dvmUnlockObject(self, obj)) {
1684 assert(dvmCheckException(self));
1685 ADJUST_PC(1);
1686 GOTO_exceptionThrown();
1687 }
1688 }
1689 FINISH(1);
1690OP_END
1691
1692/* File: c/OP_CHECK_CAST.c */
1693HANDLE_OPCODE(OP_CHECK_CAST /*vAA, class@BBBB*/)
1694 {
1695 ClassObject* clazz;
1696 Object* obj;
1697
1698 EXPORT_PC();
1699
1700 vsrc1 = INST_AA(inst);
1701 ref = FETCH(1); /* class to check against */
1702 ILOGV("|check-cast v%d,class@0x%04x", vsrc1, ref);
1703
1704 obj = (Object*)GET_REGISTER(vsrc1);
1705 if (obj != NULL) {
1706#if defined(WITH_EXTRA_OBJECT_VALIDATION)
1707 if (!checkForNull(obj))
1708 GOTO_exceptionThrown();
1709#endif
1710 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1711 if (clazz == NULL) {
1712 clazz = dvmResolveClass(curMethod->clazz, ref, false);
1713 if (clazz == NULL)
1714 GOTO_exceptionThrown();
1715 }
1716 if (!dvmInstanceof(obj->clazz, clazz)) {
1717 dvmThrowExceptionWithClassMessage(
1718 "Ljava/lang/ClassCastException;", obj->clazz->descriptor);
1719 GOTO_exceptionThrown();
1720 }
1721 }
1722 }
1723 FINISH(2);
1724OP_END
1725
1726/* File: c/OP_INSTANCE_OF.c */
1727HANDLE_OPCODE(OP_INSTANCE_OF /*vA, vB, class@CCCC*/)
1728 {
1729 ClassObject* clazz;
1730 Object* obj;
1731
1732 vdst = INST_A(inst);
1733 vsrc1 = INST_B(inst); /* object to check */
1734 ref = FETCH(1); /* class to check against */
1735 ILOGV("|instance-of v%d,v%d,class@0x%04x", vdst, vsrc1, ref);
1736
1737 obj = (Object*)GET_REGISTER(vsrc1);
1738 if (obj == NULL) {
1739 SET_REGISTER(vdst, 0);
1740 } else {
1741#if defined(WITH_EXTRA_OBJECT_VALIDATION)
1742 if (!checkForNullExportPC(obj, fp, pc))
1743 GOTO_exceptionThrown();
1744#endif
1745 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1746 if (clazz == NULL) {
1747 EXPORT_PC();
1748 clazz = dvmResolveClass(curMethod->clazz, ref, true);
1749 if (clazz == NULL)
1750 GOTO_exceptionThrown();
1751 }
1752 SET_REGISTER(vdst, dvmInstanceof(obj->clazz, clazz));
1753 }
1754 }
1755 FINISH(2);
1756OP_END
1757
1758/* File: c/OP_ARRAY_LENGTH.c */
1759HANDLE_OPCODE(OP_ARRAY_LENGTH /*vA, vB*/)
1760 {
1761 ArrayObject* arrayObj;
1762
1763 vdst = INST_A(inst);
1764 vsrc1 = INST_B(inst);
1765 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
1766 ILOGV("|array-length v%d,v%d (%p)", vdst, vsrc1, arrayObj);
1767 if (!checkForNullExportPC((Object*) arrayObj, fp, pc))
1768 GOTO_exceptionThrown();
1769 /* verifier guarantees this is an array reference */
1770 SET_REGISTER(vdst, arrayObj->length);
1771 }
1772 FINISH(1);
1773OP_END
1774
1775/* File: c/OP_NEW_INSTANCE.c */
1776HANDLE_OPCODE(OP_NEW_INSTANCE /*vAA, class@BBBB*/)
1777 {
1778 ClassObject* clazz;
1779 Object* newObj;
1780
1781 EXPORT_PC();
1782
1783 vdst = INST_AA(inst);
1784 ref = FETCH(1);
1785 ILOGV("|new-instance v%d,class@0x%04x", vdst, ref);
1786 clazz = dvmDexGetResolvedClass(methodClassDex, ref);
1787 if (clazz == NULL) {
1788 clazz = dvmResolveClass(curMethod->clazz, ref, false);
1789 if (clazz == NULL)
1790 GOTO_exceptionThrown();
1791 }
1792
1793 if (!dvmIsClassInitialized(clazz) && !dvmInitClass(clazz))
1794 GOTO_exceptionThrown();
1795
1796 /*
Andy McFaddenb51ea112009-05-08 16:50:17 -07001797 * Verifier now tests for interface/abstract class.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001798 */
Andy McFaddenb51ea112009-05-08 16:50:17 -07001799 //if (dvmIsInterfaceClass(clazz) || dvmIsAbstractClass(clazz)) {
1800 // dvmThrowExceptionWithClassMessage("Ljava/lang/InstantiationError;",
1801 // clazz->descriptor);
1802 // GOTO_exceptionThrown();
1803 //}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001804 newObj = dvmAllocObject(clazz, ALLOC_DONT_TRACK);
1805 if (newObj == NULL)
1806 GOTO_exceptionThrown();
1807 SET_REGISTER(vdst, (u4) newObj);
1808 }
1809 FINISH(2);
1810OP_END
1811
1812/* File: c/OP_NEW_ARRAY.c */
1813HANDLE_OPCODE(OP_NEW_ARRAY /*vA, vB, class@CCCC*/)
1814 {
1815 ClassObject* arrayClass;
1816 ArrayObject* newArray;
1817 s4 length;
1818
1819 EXPORT_PC();
1820
1821 vdst = INST_A(inst);
1822 vsrc1 = INST_B(inst); /* length reg */
1823 ref = FETCH(1);
1824 ILOGV("|new-array v%d,v%d,class@0x%04x (%d elements)",
1825 vdst, vsrc1, ref, (s4) GET_REGISTER(vsrc1));
1826 length = (s4) GET_REGISTER(vsrc1);
1827 if (length < 0) {
1828 dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL);
1829 GOTO_exceptionThrown();
1830 }
1831 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
1832 if (arrayClass == NULL) {
1833 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
1834 if (arrayClass == NULL)
1835 GOTO_exceptionThrown();
1836 }
1837 /* verifier guarantees this is an array class */
1838 assert(dvmIsArrayClass(arrayClass));
1839 assert(dvmIsClassInitialized(arrayClass));
1840
1841 newArray = dvmAllocArrayByClass(arrayClass, length, ALLOC_DONT_TRACK);
1842 if (newArray == NULL)
1843 GOTO_exceptionThrown();
1844 SET_REGISTER(vdst, (u4) newArray);
1845 }
1846 FINISH(2);
1847OP_END
1848
1849
1850/* File: c/OP_FILLED_NEW_ARRAY.c */
1851HANDLE_OPCODE(OP_FILLED_NEW_ARRAY /*vB, {vD, vE, vF, vG, vA}, class@CCCC*/)
1852 GOTO_invoke(filledNewArray, false);
1853OP_END
1854
1855/* File: c/OP_FILLED_NEW_ARRAY_RANGE.c */
1856HANDLE_OPCODE(OP_FILLED_NEW_ARRAY_RANGE /*{vCCCC..v(CCCC+AA-1)}, class@BBBB*/)
1857 GOTO_invoke(filledNewArray, true);
1858OP_END
1859
1860/* File: c/OP_FILL_ARRAY_DATA.c */
1861HANDLE_OPCODE(OP_FILL_ARRAY_DATA) /*vAA, +BBBBBBBB*/
1862 {
1863 const u2* arrayData;
1864 s4 offset;
1865 ArrayObject* arrayObj;
1866
1867 EXPORT_PC();
1868 vsrc1 = INST_AA(inst);
1869 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1870 ILOGV("|fill-array-data v%d +0x%04x", vsrc1, offset);
1871 arrayData = pc + offset; // offset in 16-bit units
1872#ifndef NDEBUG
1873 if (arrayData < curMethod->insns ||
1874 arrayData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1875 {
1876 /* should have been caught in verifier */
1877 dvmThrowException("Ljava/lang/InternalError;",
1878 "bad fill array data");
1879 GOTO_exceptionThrown();
1880 }
1881#endif
1882 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
1883 if (!dvmInterpHandleFillArrayData(arrayObj, arrayData)) {
1884 GOTO_exceptionThrown();
1885 }
1886 FINISH(3);
1887 }
1888OP_END
1889
1890/* File: c/OP_THROW.c */
1891HANDLE_OPCODE(OP_THROW /*vAA*/)
1892 {
1893 Object* obj;
1894
1895 vsrc1 = INST_AA(inst);
1896 ILOGV("|throw v%d (%p)", vsrc1, (void*)GET_REGISTER(vsrc1));
1897 obj = (Object*) GET_REGISTER(vsrc1);
1898 if (!checkForNullExportPC(obj, fp, pc)) {
1899 /* will throw a null pointer exception */
1900 LOGVV("Bad exception\n");
1901 } else {
1902 /* use the requested exception */
1903 dvmSetException(self, obj);
1904 }
1905 GOTO_exceptionThrown();
1906 }
1907OP_END
1908
1909/* File: c/OP_GOTO.c */
1910HANDLE_OPCODE(OP_GOTO /*+AA*/)
1911 vdst = INST_AA(inst);
1912 if ((s1)vdst < 0)
1913 ILOGV("|goto -0x%02x", -((s1)vdst));
1914 else
1915 ILOGV("|goto +0x%02x", ((s1)vdst));
1916 ILOGV("> branch taken");
1917 if ((s1)vdst < 0)
1918 PERIODIC_CHECKS(kInterpEntryInstr, (s1)vdst);
1919 FINISH((s1)vdst);
1920OP_END
1921
1922/* File: c/OP_GOTO_16.c */
1923HANDLE_OPCODE(OP_GOTO_16 /*+AAAA*/)
1924 {
1925 s4 offset = (s2) FETCH(1); /* sign-extend next code unit */
1926
1927 if (offset < 0)
1928 ILOGV("|goto/16 -0x%04x", -offset);
1929 else
1930 ILOGV("|goto/16 +0x%04x", offset);
1931 ILOGV("> branch taken");
1932 if (offset < 0)
1933 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1934 FINISH(offset);
1935 }
1936OP_END
1937
1938/* File: c/OP_GOTO_32.c */
1939HANDLE_OPCODE(OP_GOTO_32 /*+AAAAAAAA*/)
1940 {
1941 s4 offset = FETCH(1); /* low-order 16 bits */
1942 offset |= ((s4) FETCH(2)) << 16; /* high-order 16 bits */
1943
1944 if (offset < 0)
1945 ILOGV("|goto/32 -0x%08x", -offset);
1946 else
1947 ILOGV("|goto/32 +0x%08x", offset);
1948 ILOGV("> branch taken");
1949 if (offset <= 0) /* allowed to branch to self */
1950 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1951 FINISH(offset);
1952 }
1953OP_END
1954
1955/* File: c/OP_PACKED_SWITCH.c */
1956HANDLE_OPCODE(OP_PACKED_SWITCH /*vAA, +BBBB*/)
1957 {
1958 const u2* switchData;
1959 u4 testVal;
1960 s4 offset;
1961
1962 vsrc1 = INST_AA(inst);
1963 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1964 ILOGV("|packed-switch v%d +0x%04x", vsrc1, vsrc2);
1965 switchData = pc + offset; // offset in 16-bit units
1966#ifndef NDEBUG
1967 if (switchData < curMethod->insns ||
1968 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1969 {
1970 /* should have been caught in verifier */
1971 EXPORT_PC();
1972 dvmThrowException("Ljava/lang/InternalError;", "bad packed switch");
1973 GOTO_exceptionThrown();
1974 }
1975#endif
1976 testVal = GET_REGISTER(vsrc1);
1977
1978 offset = dvmInterpHandlePackedSwitch(switchData, testVal);
1979 ILOGV("> branch taken (0x%04x)\n", offset);
1980 if (offset <= 0) /* uncommon */
1981 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1982 FINISH(offset);
1983 }
1984OP_END
1985
1986/* File: c/OP_SPARSE_SWITCH.c */
1987HANDLE_OPCODE(OP_SPARSE_SWITCH /*vAA, +BBBB*/)
1988 {
1989 const u2* switchData;
1990 u4 testVal;
1991 s4 offset;
1992
1993 vsrc1 = INST_AA(inst);
1994 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1995 ILOGV("|sparse-switch v%d +0x%04x", vsrc1, vsrc2);
1996 switchData = pc + offset; // offset in 16-bit units
1997#ifndef NDEBUG
1998 if (switchData < curMethod->insns ||
1999 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
2000 {
2001 /* should have been caught in verifier */
2002 EXPORT_PC();
2003 dvmThrowException("Ljava/lang/InternalError;", "bad sparse switch");
2004 GOTO_exceptionThrown();
2005 }
2006#endif
2007 testVal = GET_REGISTER(vsrc1);
2008
2009 offset = dvmInterpHandleSparseSwitch(switchData, testVal);
2010 ILOGV("> branch taken (0x%04x)\n", offset);
2011 if (offset <= 0) /* uncommon */
2012 PERIODIC_CHECKS(kInterpEntryInstr, offset);
2013 FINISH(offset);
2014 }
2015OP_END
2016
2017/* File: c/OP_CMPL_FLOAT.c */
2018HANDLE_OP_CMPX(OP_CMPL_FLOAT, "l-float", float, _FLOAT, -1)
2019OP_END
2020
2021/* File: c/OP_CMPG_FLOAT.c */
2022HANDLE_OP_CMPX(OP_CMPG_FLOAT, "g-float", float, _FLOAT, 1)
2023OP_END
2024
2025/* File: c/OP_CMPL_DOUBLE.c */
2026HANDLE_OP_CMPX(OP_CMPL_DOUBLE, "l-double", double, _DOUBLE, -1)
2027OP_END
2028
2029/* File: c/OP_CMPG_DOUBLE.c */
2030HANDLE_OP_CMPX(OP_CMPG_DOUBLE, "g-double", double, _DOUBLE, 1)
2031OP_END
2032
2033/* File: c/OP_CMP_LONG.c */
2034HANDLE_OP_CMPX(OP_CMP_LONG, "-long", s8, _WIDE, 0)
2035OP_END
2036
2037/* File: c/OP_IF_EQ.c */
2038HANDLE_OP_IF_XX(OP_IF_EQ, "eq", ==)
2039OP_END
2040
2041/* File: c/OP_IF_NE.c */
2042HANDLE_OP_IF_XX(OP_IF_NE, "ne", !=)
2043OP_END
2044
2045/* File: c/OP_IF_LT.c */
2046HANDLE_OP_IF_XX(OP_IF_LT, "lt", <)
2047OP_END
2048
2049/* File: c/OP_IF_GE.c */
2050HANDLE_OP_IF_XX(OP_IF_GE, "ge", >=)
2051OP_END
2052
2053/* File: c/OP_IF_GT.c */
2054HANDLE_OP_IF_XX(OP_IF_GT, "gt", >)
2055OP_END
2056
2057/* File: c/OP_IF_LE.c */
2058HANDLE_OP_IF_XX(OP_IF_LE, "le", <=)
2059OP_END
2060
2061/* File: c/OP_IF_EQZ.c */
2062HANDLE_OP_IF_XXZ(OP_IF_EQZ, "eqz", ==)
2063OP_END
2064
2065/* File: c/OP_IF_NEZ.c */
2066HANDLE_OP_IF_XXZ(OP_IF_NEZ, "nez", !=)
2067OP_END
2068
2069/* File: c/OP_IF_LTZ.c */
2070HANDLE_OP_IF_XXZ(OP_IF_LTZ, "ltz", <)
2071OP_END
2072
2073/* File: c/OP_IF_GEZ.c */
2074HANDLE_OP_IF_XXZ(OP_IF_GEZ, "gez", >=)
2075OP_END
2076
2077/* File: c/OP_IF_GTZ.c */
2078HANDLE_OP_IF_XXZ(OP_IF_GTZ, "gtz", >)
2079OP_END
2080
2081/* File: c/OP_IF_LEZ.c */
2082HANDLE_OP_IF_XXZ(OP_IF_LEZ, "lez", <=)
2083OP_END
2084
2085/* File: c/OP_UNUSED_3E.c */
2086HANDLE_OPCODE(OP_UNUSED_3E)
2087OP_END
2088
2089/* File: c/OP_UNUSED_3F.c */
2090HANDLE_OPCODE(OP_UNUSED_3F)
2091OP_END
2092
2093/* File: c/OP_UNUSED_40.c */
2094HANDLE_OPCODE(OP_UNUSED_40)
2095OP_END
2096
2097/* File: c/OP_UNUSED_41.c */
2098HANDLE_OPCODE(OP_UNUSED_41)
2099OP_END
2100
2101/* File: c/OP_UNUSED_42.c */
2102HANDLE_OPCODE(OP_UNUSED_42)
2103OP_END
2104
2105/* File: c/OP_UNUSED_43.c */
2106HANDLE_OPCODE(OP_UNUSED_43)
2107OP_END
2108
2109/* File: c/OP_AGET.c */
2110HANDLE_OP_AGET(OP_AGET, "", u4, )
2111OP_END
2112
2113/* File: c/OP_AGET_WIDE.c */
2114HANDLE_OP_AGET(OP_AGET_WIDE, "-wide", s8, _WIDE)
2115OP_END
2116
2117/* File: c/OP_AGET_OBJECT.c */
2118HANDLE_OP_AGET(OP_AGET_OBJECT, "-object", u4, )
2119OP_END
2120
2121/* File: c/OP_AGET_BOOLEAN.c */
2122HANDLE_OP_AGET(OP_AGET_BOOLEAN, "-boolean", u1, )
2123OP_END
2124
2125/* File: c/OP_AGET_BYTE.c */
2126HANDLE_OP_AGET(OP_AGET_BYTE, "-byte", s1, )
2127OP_END
2128
2129/* File: c/OP_AGET_CHAR.c */
2130HANDLE_OP_AGET(OP_AGET_CHAR, "-char", u2, )
2131OP_END
2132
2133/* File: c/OP_AGET_SHORT.c */
2134HANDLE_OP_AGET(OP_AGET_SHORT, "-short", s2, )
2135OP_END
2136
2137/* File: c/OP_APUT.c */
2138HANDLE_OP_APUT(OP_APUT, "", u4, )
2139OP_END
2140
2141/* File: c/OP_APUT_WIDE.c */
2142HANDLE_OP_APUT(OP_APUT_WIDE, "-wide", s8, _WIDE)
2143OP_END
2144
2145/* File: c/OP_APUT_OBJECT.c */
2146HANDLE_OPCODE(OP_APUT_OBJECT /*vAA, vBB, vCC*/)
2147 {
2148 ArrayObject* arrayObj;
2149 Object* obj;
2150 u2 arrayInfo;
2151 EXPORT_PC();
2152 vdst = INST_AA(inst); /* AA: source value */
2153 arrayInfo = FETCH(1);
2154 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */
2155 vsrc2 = arrayInfo >> 8; /* CC: index */
2156 ILOGV("|aput%s v%d,v%d,v%d", "-object", vdst, vsrc1, vsrc2);
2157 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
2158 if (!checkForNull((Object*) arrayObj))
2159 GOTO_exceptionThrown();
2160 if (GET_REGISTER(vsrc2) >= arrayObj->length) {
2161 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
2162 NULL);
2163 GOTO_exceptionThrown();
2164 }
2165 obj = (Object*) GET_REGISTER(vdst);
2166 if (obj != NULL) {
2167 if (!checkForNull(obj))
2168 GOTO_exceptionThrown();
2169 if (!dvmCanPutArrayElement(obj->clazz, arrayObj->obj.clazz)) {
2170 LOGV("Can't put a '%s'(%p) into array type='%s'(%p)\n",
2171 obj->clazz->descriptor, obj,
2172 arrayObj->obj.clazz->descriptor, arrayObj);
2173 //dvmDumpClass(obj->clazz);
2174 //dvmDumpClass(arrayObj->obj.clazz);
2175 dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
2176 GOTO_exceptionThrown();
2177 }
2178 }
2179 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));
2180 ((u4*) arrayObj->contents)[GET_REGISTER(vsrc2)] =
2181 GET_REGISTER(vdst);
2182 }
2183 FINISH(2);
2184OP_END
2185
2186/* File: c/OP_APUT_BOOLEAN.c */
2187HANDLE_OP_APUT(OP_APUT_BOOLEAN, "-boolean", u1, )
2188OP_END
2189
2190/* File: c/OP_APUT_BYTE.c */
2191HANDLE_OP_APUT(OP_APUT_BYTE, "-byte", s1, )
2192OP_END
2193
2194/* File: c/OP_APUT_CHAR.c */
2195HANDLE_OP_APUT(OP_APUT_CHAR, "-char", u2, )
2196OP_END
2197
2198/* File: c/OP_APUT_SHORT.c */
2199HANDLE_OP_APUT(OP_APUT_SHORT, "-short", s2, )
2200OP_END
2201
2202/* File: c/OP_IGET.c */
2203HANDLE_IGET_X(OP_IGET, "", Int, )
2204OP_END
2205
2206/* File: c/OP_IGET_WIDE.c */
2207HANDLE_IGET_X(OP_IGET_WIDE, "-wide", Long, _WIDE)
2208OP_END
2209
2210/* File: c/OP_IGET_OBJECT.c */
2211HANDLE_IGET_X(OP_IGET_OBJECT, "-object", Object, _AS_OBJECT)
2212OP_END
2213
2214/* File: c/OP_IGET_BOOLEAN.c */
2215HANDLE_IGET_X(OP_IGET_BOOLEAN, "", Int, )
2216OP_END
2217
2218/* File: c/OP_IGET_BYTE.c */
2219HANDLE_IGET_X(OP_IGET_BYTE, "", Int, )
2220OP_END
2221
2222/* File: c/OP_IGET_CHAR.c */
2223HANDLE_IGET_X(OP_IGET_CHAR, "", Int, )
2224OP_END
2225
2226/* File: c/OP_IGET_SHORT.c */
2227HANDLE_IGET_X(OP_IGET_SHORT, "", Int, )
2228OP_END
2229
2230/* File: c/OP_IPUT.c */
2231HANDLE_IPUT_X(OP_IPUT, "", Int, )
2232OP_END
2233
2234/* File: c/OP_IPUT_WIDE.c */
2235HANDLE_IPUT_X(OP_IPUT_WIDE, "-wide", Long, _WIDE)
2236OP_END
2237
2238/* File: c/OP_IPUT_OBJECT.c */
2239/*
2240 * The VM spec says we should verify that the reference being stored into
2241 * the field is assignment compatible. In practice, many popular VMs don't
2242 * do this because it slows down a very common operation. It's not so bad
2243 * for us, since "dexopt" quickens it whenever possible, but it's still an
2244 * issue.
2245 *
2246 * To make this spec-complaint, we'd need to add a ClassObject pointer to
2247 * the Field struct, resolve the field's type descriptor at link or class
2248 * init time, and then verify the type here.
2249 */
2250HANDLE_IPUT_X(OP_IPUT_OBJECT, "-object", Object, _AS_OBJECT)
2251OP_END
2252
2253/* File: c/OP_IPUT_BOOLEAN.c */
2254HANDLE_IPUT_X(OP_IPUT_BOOLEAN, "", Int, )
2255OP_END
2256
2257/* File: c/OP_IPUT_BYTE.c */
2258HANDLE_IPUT_X(OP_IPUT_BYTE, "", Int, )
2259OP_END
2260
2261/* File: c/OP_IPUT_CHAR.c */
2262HANDLE_IPUT_X(OP_IPUT_CHAR, "", Int, )
2263OP_END
2264
2265/* File: c/OP_IPUT_SHORT.c */
2266HANDLE_IPUT_X(OP_IPUT_SHORT, "", Int, )
2267OP_END
2268
2269/* File: c/OP_SGET.c */
2270HANDLE_SGET_X(OP_SGET, "", Int, )
2271OP_END
2272
2273/* File: c/OP_SGET_WIDE.c */
2274HANDLE_SGET_X(OP_SGET_WIDE, "-wide", Long, _WIDE)
2275OP_END
2276
2277/* File: c/OP_SGET_OBJECT.c */
2278HANDLE_SGET_X(OP_SGET_OBJECT, "-object", Object, _AS_OBJECT)
2279OP_END
2280
2281/* File: c/OP_SGET_BOOLEAN.c */
2282HANDLE_SGET_X(OP_SGET_BOOLEAN, "", Int, )
2283OP_END
2284
2285/* File: c/OP_SGET_BYTE.c */
2286HANDLE_SGET_X(OP_SGET_BYTE, "", Int, )
2287OP_END
2288
2289/* File: c/OP_SGET_CHAR.c */
2290HANDLE_SGET_X(OP_SGET_CHAR, "", Int, )
2291OP_END
2292
2293/* File: c/OP_SGET_SHORT.c */
2294HANDLE_SGET_X(OP_SGET_SHORT, "", Int, )
2295OP_END
2296
2297/* File: c/OP_SPUT.c */
2298HANDLE_SPUT_X(OP_SPUT, "", Int, )
2299OP_END
2300
2301/* File: c/OP_SPUT_WIDE.c */
2302HANDLE_SPUT_X(OP_SPUT_WIDE, "-wide", Long, _WIDE)
2303OP_END
2304
2305/* File: c/OP_SPUT_OBJECT.c */
2306HANDLE_SPUT_X(OP_SPUT_OBJECT, "-object", Object, _AS_OBJECT)
2307OP_END
2308
2309/* File: c/OP_SPUT_BOOLEAN.c */
2310HANDLE_SPUT_X(OP_SPUT_BOOLEAN, "", Int, )
2311OP_END
2312
2313/* File: c/OP_SPUT_BYTE.c */
2314HANDLE_SPUT_X(OP_SPUT_BYTE, "", Int, )
2315OP_END
2316
2317/* File: c/OP_SPUT_CHAR.c */
2318HANDLE_SPUT_X(OP_SPUT_CHAR, "", Int, )
2319OP_END
2320
2321/* File: c/OP_SPUT_SHORT.c */
2322HANDLE_SPUT_X(OP_SPUT_SHORT, "", Int, )
2323OP_END
2324
2325/* File: c/OP_INVOKE_VIRTUAL.c */
2326HANDLE_OPCODE(OP_INVOKE_VIRTUAL /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2327 GOTO_invoke(invokeVirtual, false);
2328OP_END
2329
2330/* File: c/OP_INVOKE_SUPER.c */
2331HANDLE_OPCODE(OP_INVOKE_SUPER /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2332 GOTO_invoke(invokeSuper, false);
2333OP_END
2334
2335/* File: c/OP_INVOKE_DIRECT.c */
2336HANDLE_OPCODE(OP_INVOKE_DIRECT /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2337 GOTO_invoke(invokeDirect, false);
2338OP_END
2339
2340/* File: c/OP_INVOKE_STATIC.c */
2341HANDLE_OPCODE(OP_INVOKE_STATIC /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2342 GOTO_invoke(invokeStatic, false);
2343OP_END
2344
2345/* File: c/OP_INVOKE_INTERFACE.c */
2346HANDLE_OPCODE(OP_INVOKE_INTERFACE /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2347 GOTO_invoke(invokeInterface, false);
2348OP_END
2349
2350/* File: c/OP_UNUSED_73.c */
2351HANDLE_OPCODE(OP_UNUSED_73)
2352OP_END
2353
2354/* File: c/OP_INVOKE_VIRTUAL_RANGE.c */
2355HANDLE_OPCODE(OP_INVOKE_VIRTUAL_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2356 GOTO_invoke(invokeVirtual, true);
2357OP_END
2358
2359/* File: c/OP_INVOKE_SUPER_RANGE.c */
2360HANDLE_OPCODE(OP_INVOKE_SUPER_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2361 GOTO_invoke(invokeSuper, true);
2362OP_END
2363
2364/* File: c/OP_INVOKE_DIRECT_RANGE.c */
2365HANDLE_OPCODE(OP_INVOKE_DIRECT_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2366 GOTO_invoke(invokeDirect, true);
2367OP_END
2368
2369/* File: c/OP_INVOKE_STATIC_RANGE.c */
2370HANDLE_OPCODE(OP_INVOKE_STATIC_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2371 GOTO_invoke(invokeStatic, true);
2372OP_END
2373
2374/* File: c/OP_INVOKE_INTERFACE_RANGE.c */
2375HANDLE_OPCODE(OP_INVOKE_INTERFACE_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2376 GOTO_invoke(invokeInterface, true);
2377OP_END
2378
2379/* File: c/OP_UNUSED_79.c */
2380HANDLE_OPCODE(OP_UNUSED_79)
2381OP_END
2382
2383/* File: c/OP_UNUSED_7A.c */
2384HANDLE_OPCODE(OP_UNUSED_7A)
2385OP_END
2386
2387/* File: c/OP_NEG_INT.c */
2388HANDLE_UNOP(OP_NEG_INT, "neg-int", -, , )
2389OP_END
2390
2391/* File: c/OP_NOT_INT.c */
2392HANDLE_UNOP(OP_NOT_INT, "not-int", , ^ 0xffffffff, )
2393OP_END
2394
2395/* File: c/OP_NEG_LONG.c */
2396HANDLE_UNOP(OP_NEG_LONG, "neg-long", -, , _WIDE)
2397OP_END
2398
2399/* File: c/OP_NOT_LONG.c */
2400HANDLE_UNOP(OP_NOT_LONG, "not-long", , ^ 0xffffffffffffffffULL, _WIDE)
2401OP_END
2402
2403/* File: c/OP_NEG_FLOAT.c */
2404HANDLE_UNOP(OP_NEG_FLOAT, "neg-float", -, , _FLOAT)
2405OP_END
2406
2407/* File: c/OP_NEG_DOUBLE.c */
2408HANDLE_UNOP(OP_NEG_DOUBLE, "neg-double", -, , _DOUBLE)
2409OP_END
2410
2411/* File: c/OP_INT_TO_LONG.c */
2412HANDLE_NUMCONV(OP_INT_TO_LONG, "int-to-long", _INT, _WIDE)
2413OP_END
2414
2415/* File: c/OP_INT_TO_FLOAT.c */
2416HANDLE_NUMCONV(OP_INT_TO_FLOAT, "int-to-float", _INT, _FLOAT)
2417OP_END
2418
2419/* File: c/OP_INT_TO_DOUBLE.c */
2420HANDLE_NUMCONV(OP_INT_TO_DOUBLE, "int-to-double", _INT, _DOUBLE)
2421OP_END
2422
2423/* File: c/OP_LONG_TO_INT.c */
2424HANDLE_NUMCONV(OP_LONG_TO_INT, "long-to-int", _WIDE, _INT)
2425OP_END
2426
2427/* File: c/OP_LONG_TO_FLOAT.c */
2428HANDLE_NUMCONV(OP_LONG_TO_FLOAT, "long-to-float", _WIDE, _FLOAT)
2429OP_END
2430
2431/* File: c/OP_LONG_TO_DOUBLE.c */
2432HANDLE_NUMCONV(OP_LONG_TO_DOUBLE, "long-to-double", _WIDE, _DOUBLE)
2433OP_END
2434
2435/* File: c/OP_FLOAT_TO_INT.c */
2436HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_INT, "float-to-int",
2437 float, _FLOAT, s4, _INT)
2438OP_END
2439
2440/* File: c/OP_FLOAT_TO_LONG.c */
2441HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_LONG, "float-to-long",
2442 float, _FLOAT, s8, _WIDE)
2443OP_END
2444
2445/* File: c/OP_FLOAT_TO_DOUBLE.c */
2446HANDLE_NUMCONV(OP_FLOAT_TO_DOUBLE, "float-to-double", _FLOAT, _DOUBLE)
2447OP_END
2448
2449/* File: c/OP_DOUBLE_TO_INT.c */
2450HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_INT, "double-to-int",
2451 double, _DOUBLE, s4, _INT)
2452OP_END
2453
2454/* File: c/OP_DOUBLE_TO_LONG.c */
2455HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_LONG, "double-to-long",
2456 double, _DOUBLE, s8, _WIDE)
2457OP_END
2458
2459/* File: c/OP_DOUBLE_TO_FLOAT.c */
2460HANDLE_NUMCONV(OP_DOUBLE_TO_FLOAT, "double-to-float", _DOUBLE, _FLOAT)
2461OP_END
2462
2463/* File: c/OP_INT_TO_BYTE.c */
2464HANDLE_INT_TO_SMALL(OP_INT_TO_BYTE, "byte", s1)
2465OP_END
2466
2467/* File: c/OP_INT_TO_CHAR.c */
2468HANDLE_INT_TO_SMALL(OP_INT_TO_CHAR, "char", u2)
2469OP_END
2470
2471/* File: c/OP_INT_TO_SHORT.c */
2472HANDLE_INT_TO_SMALL(OP_INT_TO_SHORT, "short", s2) /* want sign bit */
2473OP_END
2474
2475/* File: c/OP_ADD_INT.c */
2476HANDLE_OP_X_INT(OP_ADD_INT, "add", +, 0)
2477OP_END
2478
2479/* File: c/OP_SUB_INT.c */
2480HANDLE_OP_X_INT(OP_SUB_INT, "sub", -, 0)
2481OP_END
2482
2483/* File: c/OP_MUL_INT.c */
2484HANDLE_OP_X_INT(OP_MUL_INT, "mul", *, 0)
2485OP_END
2486
2487/* File: c/OP_DIV_INT.c */
2488HANDLE_OP_X_INT(OP_DIV_INT, "div", /, 1)
2489OP_END
2490
2491/* File: c/OP_REM_INT.c */
2492HANDLE_OP_X_INT(OP_REM_INT, "rem", %, 2)
2493OP_END
2494
2495/* File: c/OP_AND_INT.c */
2496HANDLE_OP_X_INT(OP_AND_INT, "and", &, 0)
2497OP_END
2498
2499/* File: c/OP_OR_INT.c */
2500HANDLE_OP_X_INT(OP_OR_INT, "or", |, 0)
2501OP_END
2502
2503/* File: c/OP_XOR_INT.c */
2504HANDLE_OP_X_INT(OP_XOR_INT, "xor", ^, 0)
2505OP_END
2506
2507/* File: c/OP_SHL_INT.c */
2508HANDLE_OP_SHX_INT(OP_SHL_INT, "shl", (s4), <<)
2509OP_END
2510
2511/* File: c/OP_SHR_INT.c */
2512HANDLE_OP_SHX_INT(OP_SHR_INT, "shr", (s4), >>)
2513OP_END
2514
2515/* File: c/OP_USHR_INT.c */
2516HANDLE_OP_SHX_INT(OP_USHR_INT, "ushr", (u4), >>)
2517OP_END
2518
2519/* File: c/OP_ADD_LONG.c */
2520HANDLE_OP_X_LONG(OP_ADD_LONG, "add", +, 0)
2521OP_END
2522
2523/* File: c/OP_SUB_LONG.c */
2524HANDLE_OP_X_LONG(OP_SUB_LONG, "sub", -, 0)
2525OP_END
2526
2527/* File: c/OP_MUL_LONG.c */
2528HANDLE_OP_X_LONG(OP_MUL_LONG, "mul", *, 0)
2529OP_END
2530
2531/* File: c/OP_DIV_LONG.c */
2532HANDLE_OP_X_LONG(OP_DIV_LONG, "div", /, 1)
2533OP_END
2534
2535/* File: c/OP_REM_LONG.c */
2536HANDLE_OP_X_LONG(OP_REM_LONG, "rem", %, 2)
2537OP_END
2538
2539/* File: c/OP_AND_LONG.c */
2540HANDLE_OP_X_LONG(OP_AND_LONG, "and", &, 0)
2541OP_END
2542
2543/* File: c/OP_OR_LONG.c */
2544HANDLE_OP_X_LONG(OP_OR_LONG, "or", |, 0)
2545OP_END
2546
2547/* File: c/OP_XOR_LONG.c */
2548HANDLE_OP_X_LONG(OP_XOR_LONG, "xor", ^, 0)
2549OP_END
2550
2551/* File: c/OP_SHL_LONG.c */
2552HANDLE_OP_SHX_LONG(OP_SHL_LONG, "shl", (s8), <<)
2553OP_END
2554
2555/* File: c/OP_SHR_LONG.c */
2556HANDLE_OP_SHX_LONG(OP_SHR_LONG, "shr", (s8), >>)
2557OP_END
2558
2559/* File: c/OP_USHR_LONG.c */
2560HANDLE_OP_SHX_LONG(OP_USHR_LONG, "ushr", (u8), >>)
2561OP_END
2562
2563/* File: c/OP_ADD_FLOAT.c */
2564HANDLE_OP_X_FLOAT(OP_ADD_FLOAT, "add", +)
2565OP_END
2566
2567/* File: c/OP_SUB_FLOAT.c */
2568HANDLE_OP_X_FLOAT(OP_SUB_FLOAT, "sub", -)
2569OP_END
2570
2571/* File: c/OP_MUL_FLOAT.c */
2572HANDLE_OP_X_FLOAT(OP_MUL_FLOAT, "mul", *)
2573OP_END
2574
2575/* File: c/OP_DIV_FLOAT.c */
2576HANDLE_OP_X_FLOAT(OP_DIV_FLOAT, "div", /)
2577OP_END
2578
2579/* File: c/OP_REM_FLOAT.c */
2580HANDLE_OPCODE(OP_REM_FLOAT /*vAA, vBB, vCC*/)
2581 {
2582 u2 srcRegs;
2583 vdst = INST_AA(inst);
2584 srcRegs = FETCH(1);
2585 vsrc1 = srcRegs & 0xff;
2586 vsrc2 = srcRegs >> 8;
2587 ILOGV("|%s-float v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2588 SET_REGISTER_FLOAT(vdst,
2589 fmodf(GET_REGISTER_FLOAT(vsrc1), GET_REGISTER_FLOAT(vsrc2)));
2590 }
2591 FINISH(2);
2592OP_END
2593
2594/* File: c/OP_ADD_DOUBLE.c */
2595HANDLE_OP_X_DOUBLE(OP_ADD_DOUBLE, "add", +)
2596OP_END
2597
2598/* File: c/OP_SUB_DOUBLE.c */
2599HANDLE_OP_X_DOUBLE(OP_SUB_DOUBLE, "sub", -)
2600OP_END
2601
2602/* File: c/OP_MUL_DOUBLE.c */
2603HANDLE_OP_X_DOUBLE(OP_MUL_DOUBLE, "mul", *)
2604OP_END
2605
2606/* File: c/OP_DIV_DOUBLE.c */
2607HANDLE_OP_X_DOUBLE(OP_DIV_DOUBLE, "div", /)
2608OP_END
2609
2610/* File: c/OP_REM_DOUBLE.c */
2611HANDLE_OPCODE(OP_REM_DOUBLE /*vAA, vBB, vCC*/)
2612 {
2613 u2 srcRegs;
2614 vdst = INST_AA(inst);
2615 srcRegs = FETCH(1);
2616 vsrc1 = srcRegs & 0xff;
2617 vsrc2 = srcRegs >> 8;
2618 ILOGV("|%s-double v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2619 SET_REGISTER_DOUBLE(vdst,
2620 fmod(GET_REGISTER_DOUBLE(vsrc1), GET_REGISTER_DOUBLE(vsrc2)));
2621 }
2622 FINISH(2);
2623OP_END
2624
2625/* File: c/OP_ADD_INT_2ADDR.c */
2626HANDLE_OP_X_INT_2ADDR(OP_ADD_INT_2ADDR, "add", +, 0)
2627OP_END
2628
2629/* File: c/OP_SUB_INT_2ADDR.c */
2630HANDLE_OP_X_INT_2ADDR(OP_SUB_INT_2ADDR, "sub", -, 0)
2631OP_END
2632
2633/* File: c/OP_MUL_INT_2ADDR.c */
2634HANDLE_OP_X_INT_2ADDR(OP_MUL_INT_2ADDR, "mul", *, 0)
2635OP_END
2636
2637/* File: c/OP_DIV_INT_2ADDR.c */
2638HANDLE_OP_X_INT_2ADDR(OP_DIV_INT_2ADDR, "div", /, 1)
2639OP_END
2640
2641/* File: c/OP_REM_INT_2ADDR.c */
2642HANDLE_OP_X_INT_2ADDR(OP_REM_INT_2ADDR, "rem", %, 2)
2643OP_END
2644
2645/* File: c/OP_AND_INT_2ADDR.c */
2646HANDLE_OP_X_INT_2ADDR(OP_AND_INT_2ADDR, "and", &, 0)
2647OP_END
2648
2649/* File: c/OP_OR_INT_2ADDR.c */
2650HANDLE_OP_X_INT_2ADDR(OP_OR_INT_2ADDR, "or", |, 0)
2651OP_END
2652
2653/* File: c/OP_XOR_INT_2ADDR.c */
2654HANDLE_OP_X_INT_2ADDR(OP_XOR_INT_2ADDR, "xor", ^, 0)
2655OP_END
2656
2657/* File: c/OP_SHL_INT_2ADDR.c */
2658HANDLE_OP_SHX_INT_2ADDR(OP_SHL_INT_2ADDR, "shl", (s4), <<)
2659OP_END
2660
2661/* File: c/OP_SHR_INT_2ADDR.c */
2662HANDLE_OP_SHX_INT_2ADDR(OP_SHR_INT_2ADDR, "shr", (s4), >>)
2663OP_END
2664
2665/* File: c/OP_USHR_INT_2ADDR.c */
2666HANDLE_OP_SHX_INT_2ADDR(OP_USHR_INT_2ADDR, "ushr", (u4), >>)
2667OP_END
2668
2669/* File: c/OP_ADD_LONG_2ADDR.c */
2670HANDLE_OP_X_LONG_2ADDR(OP_ADD_LONG_2ADDR, "add", +, 0)
2671OP_END
2672
2673/* File: c/OP_SUB_LONG_2ADDR.c */
2674HANDLE_OP_X_LONG_2ADDR(OP_SUB_LONG_2ADDR, "sub", -, 0)
2675OP_END
2676
2677/* File: c/OP_MUL_LONG_2ADDR.c */
2678HANDLE_OP_X_LONG_2ADDR(OP_MUL_LONG_2ADDR, "mul", *, 0)
2679OP_END
2680
2681/* File: c/OP_DIV_LONG_2ADDR.c */
2682HANDLE_OP_X_LONG_2ADDR(OP_DIV_LONG_2ADDR, "div", /, 1)
2683OP_END
2684
2685/* File: c/OP_REM_LONG_2ADDR.c */
2686HANDLE_OP_X_LONG_2ADDR(OP_REM_LONG_2ADDR, "rem", %, 2)
2687OP_END
2688
2689/* File: c/OP_AND_LONG_2ADDR.c */
2690HANDLE_OP_X_LONG_2ADDR(OP_AND_LONG_2ADDR, "and", &, 0)
2691OP_END
2692
2693/* File: c/OP_OR_LONG_2ADDR.c */
2694HANDLE_OP_X_LONG_2ADDR(OP_OR_LONG_2ADDR, "or", |, 0)
2695OP_END
2696
2697/* File: c/OP_XOR_LONG_2ADDR.c */
2698HANDLE_OP_X_LONG_2ADDR(OP_XOR_LONG_2ADDR, "xor", ^, 0)
2699OP_END
2700
2701/* File: c/OP_SHL_LONG_2ADDR.c */
2702HANDLE_OP_SHX_LONG_2ADDR(OP_SHL_LONG_2ADDR, "shl", (s8), <<)
2703OP_END
2704
2705/* File: c/OP_SHR_LONG_2ADDR.c */
2706HANDLE_OP_SHX_LONG_2ADDR(OP_SHR_LONG_2ADDR, "shr", (s8), >>)
2707OP_END
2708
2709/* File: c/OP_USHR_LONG_2ADDR.c */
2710HANDLE_OP_SHX_LONG_2ADDR(OP_USHR_LONG_2ADDR, "ushr", (u8), >>)
2711OP_END
2712
2713/* File: c/OP_ADD_FLOAT_2ADDR.c */
2714HANDLE_OP_X_FLOAT_2ADDR(OP_ADD_FLOAT_2ADDR, "add", +)
2715OP_END
2716
2717/* File: c/OP_SUB_FLOAT_2ADDR.c */
2718HANDLE_OP_X_FLOAT_2ADDR(OP_SUB_FLOAT_2ADDR, "sub", -)
2719OP_END
2720
2721/* File: c/OP_MUL_FLOAT_2ADDR.c */
2722HANDLE_OP_X_FLOAT_2ADDR(OP_MUL_FLOAT_2ADDR, "mul", *)
2723OP_END
2724
2725/* File: c/OP_DIV_FLOAT_2ADDR.c */
2726HANDLE_OP_X_FLOAT_2ADDR(OP_DIV_FLOAT_2ADDR, "div", /)
2727OP_END
2728
2729/* File: c/OP_REM_FLOAT_2ADDR.c */
2730HANDLE_OPCODE(OP_REM_FLOAT_2ADDR /*vA, vB*/)
2731 vdst = INST_A(inst);
2732 vsrc1 = INST_B(inst);
2733 ILOGV("|%s-float-2addr v%d,v%d", "mod", vdst, vsrc1);
2734 SET_REGISTER_FLOAT(vdst,
2735 fmodf(GET_REGISTER_FLOAT(vdst), GET_REGISTER_FLOAT(vsrc1)));
2736 FINISH(1);
2737OP_END
2738
2739/* File: c/OP_ADD_DOUBLE_2ADDR.c */
2740HANDLE_OP_X_DOUBLE_2ADDR(OP_ADD_DOUBLE_2ADDR, "add", +)
2741OP_END
2742
2743/* File: c/OP_SUB_DOUBLE_2ADDR.c */
2744HANDLE_OP_X_DOUBLE_2ADDR(OP_SUB_DOUBLE_2ADDR, "sub", -)
2745OP_END
2746
2747/* File: c/OP_MUL_DOUBLE_2ADDR.c */
2748HANDLE_OP_X_DOUBLE_2ADDR(OP_MUL_DOUBLE_2ADDR, "mul", *)
2749OP_END
2750
2751/* File: c/OP_DIV_DOUBLE_2ADDR.c */
2752HANDLE_OP_X_DOUBLE_2ADDR(OP_DIV_DOUBLE_2ADDR, "div", /)
2753OP_END
2754
2755/* File: c/OP_REM_DOUBLE_2ADDR.c */
2756HANDLE_OPCODE(OP_REM_DOUBLE_2ADDR /*vA, vB*/)
2757 vdst = INST_A(inst);
2758 vsrc1 = INST_B(inst);
2759 ILOGV("|%s-double-2addr v%d,v%d", "mod", vdst, vsrc1);
2760 SET_REGISTER_DOUBLE(vdst,
2761 fmod(GET_REGISTER_DOUBLE(vdst), GET_REGISTER_DOUBLE(vsrc1)));
2762 FINISH(1);
2763OP_END
2764
2765/* File: c/OP_ADD_INT_LIT16.c */
2766HANDLE_OP_X_INT_LIT16(OP_ADD_INT_LIT16, "add", +, 0)
2767OP_END
2768
2769/* File: c/OP_RSUB_INT.c */
2770HANDLE_OPCODE(OP_RSUB_INT /*vA, vB, #+CCCC*/)
2771 {
2772 vdst = INST_A(inst);
2773 vsrc1 = INST_B(inst);
2774 vsrc2 = FETCH(1);
2775 ILOGV("|rsub-int v%d,v%d,#+0x%04x", vdst, vsrc1, vsrc2);
2776 SET_REGISTER(vdst, (s2) vsrc2 - (s4) GET_REGISTER(vsrc1));
2777 }
2778 FINISH(2);
2779OP_END
2780
2781/* File: c/OP_MUL_INT_LIT16.c */
2782HANDLE_OP_X_INT_LIT16(OP_MUL_INT_LIT16, "mul", *, 0)
2783OP_END
2784
2785/* File: c/OP_DIV_INT_LIT16.c */
2786HANDLE_OP_X_INT_LIT16(OP_DIV_INT_LIT16, "div", /, 1)
2787OP_END
2788
2789/* File: c/OP_REM_INT_LIT16.c */
2790HANDLE_OP_X_INT_LIT16(OP_REM_INT_LIT16, "rem", %, 2)
2791OP_END
2792
2793/* File: c/OP_AND_INT_LIT16.c */
2794HANDLE_OP_X_INT_LIT16(OP_AND_INT_LIT16, "and", &, 0)
2795OP_END
2796
2797/* File: c/OP_OR_INT_LIT16.c */
2798HANDLE_OP_X_INT_LIT16(OP_OR_INT_LIT16, "or", |, 0)
2799OP_END
2800
2801/* File: c/OP_XOR_INT_LIT16.c */
2802HANDLE_OP_X_INT_LIT16(OP_XOR_INT_LIT16, "xor", ^, 0)
2803OP_END
2804
2805/* File: c/OP_ADD_INT_LIT8.c */
2806HANDLE_OP_X_INT_LIT8(OP_ADD_INT_LIT8, "add", +, 0)
2807OP_END
2808
2809/* File: c/OP_RSUB_INT_LIT8.c */
2810HANDLE_OPCODE(OP_RSUB_INT_LIT8 /*vAA, vBB, #+CC*/)
2811 {
2812 u2 litInfo;
2813 vdst = INST_AA(inst);
2814 litInfo = FETCH(1);
2815 vsrc1 = litInfo & 0xff;
2816 vsrc2 = litInfo >> 8;
2817 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", "rsub", vdst, vsrc1, vsrc2);
2818 SET_REGISTER(vdst, (s1) vsrc2 - (s4) GET_REGISTER(vsrc1));
2819 }
2820 FINISH(2);
2821OP_END
2822
2823/* File: c/OP_MUL_INT_LIT8.c */
2824HANDLE_OP_X_INT_LIT8(OP_MUL_INT_LIT8, "mul", *, 0)
2825OP_END
2826
2827/* File: c/OP_DIV_INT_LIT8.c */
2828HANDLE_OP_X_INT_LIT8(OP_DIV_INT_LIT8, "div", /, 1)
2829OP_END
2830
2831/* File: c/OP_REM_INT_LIT8.c */
2832HANDLE_OP_X_INT_LIT8(OP_REM_INT_LIT8, "rem", %, 2)
2833OP_END
2834
2835/* File: c/OP_AND_INT_LIT8.c */
2836HANDLE_OP_X_INT_LIT8(OP_AND_INT_LIT8, "and", &, 0)
2837OP_END
2838
2839/* File: c/OP_OR_INT_LIT8.c */
2840HANDLE_OP_X_INT_LIT8(OP_OR_INT_LIT8, "or", |, 0)
2841OP_END
2842
2843/* File: c/OP_XOR_INT_LIT8.c */
2844HANDLE_OP_X_INT_LIT8(OP_XOR_INT_LIT8, "xor", ^, 0)
2845OP_END
2846
2847/* File: c/OP_SHL_INT_LIT8.c */
2848HANDLE_OP_SHX_INT_LIT8(OP_SHL_INT_LIT8, "shl", (s4), <<)
2849OP_END
2850
2851/* File: c/OP_SHR_INT_LIT8.c */
2852HANDLE_OP_SHX_INT_LIT8(OP_SHR_INT_LIT8, "shr", (s4), >>)
2853OP_END
2854
2855/* File: c/OP_USHR_INT_LIT8.c */
2856HANDLE_OP_SHX_INT_LIT8(OP_USHR_INT_LIT8, "ushr", (u4), >>)
2857OP_END
2858
2859/* File: c/OP_UNUSED_E3.c */
2860HANDLE_OPCODE(OP_UNUSED_E3)
2861OP_END
2862
2863/* File: c/OP_UNUSED_E4.c */
2864HANDLE_OPCODE(OP_UNUSED_E4)
2865OP_END
2866
2867/* File: c/OP_UNUSED_E5.c */
2868HANDLE_OPCODE(OP_UNUSED_E5)
2869OP_END
2870
2871/* File: c/OP_UNUSED_E6.c */
2872HANDLE_OPCODE(OP_UNUSED_E6)
2873OP_END
2874
2875/* File: c/OP_UNUSED_E7.c */
2876HANDLE_OPCODE(OP_UNUSED_E7)
2877OP_END
2878
2879/* File: c/OP_UNUSED_E8.c */
2880HANDLE_OPCODE(OP_UNUSED_E8)
2881OP_END
2882
2883/* File: c/OP_UNUSED_E9.c */
2884HANDLE_OPCODE(OP_UNUSED_E9)
2885OP_END
2886
2887/* File: c/OP_UNUSED_EA.c */
2888HANDLE_OPCODE(OP_UNUSED_EA)
2889OP_END
2890
2891/* File: c/OP_UNUSED_EB.c */
2892HANDLE_OPCODE(OP_UNUSED_EB)
2893OP_END
2894
Andy McFadden96516932009-10-28 17:39:02 -07002895/* File: c/OP_BREAKPOINT.c */
2896HANDLE_OPCODE(OP_BREAKPOINT)
2897#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
2898 {
2899 /*
2900 * Restart this instruction with the original opcode. We do
2901 * this by simply jumping to the handler.
2902 *
2903 * It's probably not necessary to update "inst", but we do it
2904 * for the sake of anything that needs to do disambiguation in a
2905 * common handler with INST_INST.
2906 *
2907 * The breakpoint itself is handled over in updateDebugger(),
2908 * because we need to detect other events (method entry, single
2909 * step) and report them in the same event packet, and we're not
2910 * yet handling those through breakpoint instructions. By the
2911 * time we get here, the breakpoint has already been handled and
2912 * the thread resumed.
2913 */
2914 u1 originalOpCode = dvmGetOriginalOpCode(pc);
2915 LOGV("+++ break 0x%02x (0x%04x -> 0x%04x)\n", originalOpCode, inst,
2916 INST_REPLACE_OP(inst, originalOpCode));
2917 inst = INST_REPLACE_OP(inst, originalOpCode);
2918 FINISH_BKPT(originalOpCode);
2919 }
2920#else
2921 LOGE("Breakpoint hit in non-debug interpreter\n");
2922 dvmAbort();
2923#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002924OP_END
2925
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002926/* File: c/OP_THROW_VERIFICATION_ERROR.c */
2927HANDLE_OPCODE(OP_THROW_VERIFICATION_ERROR)
Andy McFaddenb51ea112009-05-08 16:50:17 -07002928 EXPORT_PC();
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002929 vsrc1 = INST_AA(inst);
2930 ref = FETCH(1); /* class/field/method ref */
Andy McFaddenb51ea112009-05-08 16:50:17 -07002931 dvmThrowVerificationError(curMethod, vsrc1, ref);
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002932 GOTO_exceptionThrown();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002933OP_END
2934
2935/* File: c/OP_EXECUTE_INLINE.c */
2936HANDLE_OPCODE(OP_EXECUTE_INLINE /*vB, {vD, vE, vF, vG}, inline@CCCC*/)
2937 {
2938 /*
2939 * This has the same form as other method calls, but we ignore
2940 * the 5th argument (vA). This is chiefly because the first four
2941 * arguments to a function on ARM are in registers.
2942 *
2943 * We only set the arguments that are actually used, leaving
2944 * the rest uninitialized. We're assuming that, if the method
2945 * needs them, they'll be specified in the call.
2946 *
Carl Shapiro7bbb9ce2009-12-21 18:34:11 -08002947 * However, this annoys gcc when optimizations are enabled,
2948 * causing a "may be used uninitialized" warning. Quieting
2949 * the warnings incurs a slight penalty (5%: 373ns vs. 393ns
2950 * on empty method). Note that valgrind is perfectly happy
2951 * either way as the uninitialiezd values are never actually
2952 * used.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002953 */
2954 u4 arg0, arg1, arg2, arg3;
Carl Shapiro7bbb9ce2009-12-21 18:34:11 -08002955 arg0 = arg1 = arg2 = arg3 = 0;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002956
2957 EXPORT_PC();
2958
2959 vsrc1 = INST_B(inst); /* #of args */
2960 ref = FETCH(1); /* inline call "ref" */
2961 vdst = FETCH(2); /* 0-4 register indices */
2962 ILOGV("|execute-inline args=%d @%d {regs=0x%04x}",
2963 vsrc1, ref, vdst);
2964
2965 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
2966 assert(vsrc1 <= 4);
2967
2968 switch (vsrc1) {
2969 case 4:
2970 arg3 = GET_REGISTER(vdst >> 12);
2971 /* fall through */
2972 case 3:
2973 arg2 = GET_REGISTER((vdst & 0x0f00) >> 8);
2974 /* fall through */
2975 case 2:
2976 arg1 = GET_REGISTER((vdst & 0x00f0) >> 4);
2977 /* fall through */
2978 case 1:
2979 arg0 = GET_REGISTER(vdst & 0x0f);
2980 /* fall through */
2981 default: // case 0
2982 ;
2983 }
2984
2985#if INTERP_TYPE == INTERP_DBG
2986 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
2987 GOTO_exceptionThrown();
2988#else
2989 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
2990 GOTO_exceptionThrown();
2991#endif
2992 }
2993 FINISH(3);
2994OP_END
2995
Andy McFaddenb0a05412009-11-19 10:23:41 -08002996/* File: c/OP_EXECUTE_INLINE_RANGE.c */
2997HANDLE_OPCODE(OP_EXECUTE_INLINE_RANGE /*{vCCCC..v(CCCC+AA-1)}, inline@BBBB*/)
2998 {
2999 u4 arg0, arg1, arg2, arg3;
3000 arg0 = arg1 = arg2 = arg3 = 0; /* placate gcc */
3001
3002 EXPORT_PC();
3003
3004 vsrc1 = INST_AA(inst); /* #of args */
3005 ref = FETCH(1); /* inline call "ref" */
3006 vdst = FETCH(2); /* range base */
3007 ILOGV("|execute-inline-range args=%d @%d {regs=v%d-v%d}",
3008 vsrc1, ref, vdst, vdst+vsrc1-1);
3009
3010 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
3011 assert(vsrc1 <= 4);
3012
3013 switch (vsrc1) {
3014 case 4:
3015 arg3 = GET_REGISTER(vdst+3);
3016 /* fall through */
3017 case 3:
3018 arg2 = GET_REGISTER(vdst+2);
3019 /* fall through */
3020 case 2:
3021 arg1 = GET_REGISTER(vdst+1);
3022 /* fall through */
3023 case 1:
3024 arg0 = GET_REGISTER(vdst+0);
3025 /* fall through */
3026 default: // case 0
3027 ;
3028 }
3029
3030#if INTERP_TYPE == INTERP_DBG
3031 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
3032 GOTO_exceptionThrown();
3033#else
3034 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
3035 GOTO_exceptionThrown();
3036#endif
3037 }
3038 FINISH(3);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003039OP_END
3040
3041/* File: c/OP_INVOKE_DIRECT_EMPTY.c */
3042HANDLE_OPCODE(OP_INVOKE_DIRECT_EMPTY /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3043#if INTERP_TYPE != INTERP_DBG
3044 //LOGI("Ignoring empty\n");
3045 FINISH(3);
3046#else
3047 if (!gDvm.debuggerActive) {
3048 //LOGI("Skipping empty\n");
3049 FINISH(3); // don't want it to show up in profiler output
3050 } else {
3051 //LOGI("Running empty\n");
3052 /* fall through to OP_INVOKE_DIRECT */
3053 GOTO_invoke(invokeDirect, false);
3054 }
3055#endif
3056OP_END
3057
3058/* File: c/OP_UNUSED_F1.c */
3059HANDLE_OPCODE(OP_UNUSED_F1)
3060OP_END
3061
3062/* File: c/OP_IGET_QUICK.c */
3063HANDLE_IGET_X_QUICK(OP_IGET_QUICK, "", Int, )
3064OP_END
3065
3066/* File: c/OP_IGET_WIDE_QUICK.c */
3067HANDLE_IGET_X_QUICK(OP_IGET_WIDE_QUICK, "-wide", Long, _WIDE)
3068OP_END
3069
3070/* File: c/OP_IGET_OBJECT_QUICK.c */
3071HANDLE_IGET_X_QUICK(OP_IGET_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
3072OP_END
3073
3074/* File: c/OP_IPUT_QUICK.c */
3075HANDLE_IPUT_X_QUICK(OP_IPUT_QUICK, "", Int, )
3076OP_END
3077
3078/* File: c/OP_IPUT_WIDE_QUICK.c */
3079HANDLE_IPUT_X_QUICK(OP_IPUT_WIDE_QUICK, "-wide", Long, _WIDE)
3080OP_END
3081
3082/* File: c/OP_IPUT_OBJECT_QUICK.c */
3083HANDLE_IPUT_X_QUICK(OP_IPUT_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
3084OP_END
3085
3086/* File: c/OP_INVOKE_VIRTUAL_QUICK.c */
3087HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3088 GOTO_invoke(invokeVirtualQuick, false);
3089OP_END
3090
3091/* File: c/OP_INVOKE_VIRTUAL_QUICK_RANGE.c */
3092HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK_RANGE/*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
3093 GOTO_invoke(invokeVirtualQuick, true);
3094OP_END
3095
3096/* File: c/OP_INVOKE_SUPER_QUICK.c */
3097HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3098 GOTO_invoke(invokeSuperQuick, false);
3099OP_END
3100
3101/* File: c/OP_INVOKE_SUPER_QUICK_RANGE.c */
3102HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
3103 GOTO_invoke(invokeSuperQuick, true);
3104OP_END
3105
3106/* File: c/OP_UNUSED_FC.c */
3107HANDLE_OPCODE(OP_UNUSED_FC)
3108OP_END
3109
3110/* File: c/OP_UNUSED_FD.c */
3111HANDLE_OPCODE(OP_UNUSED_FD)
3112OP_END
3113
3114/* File: c/OP_UNUSED_FE.c */
3115HANDLE_OPCODE(OP_UNUSED_FE)
3116OP_END
3117
3118/* File: c/OP_UNUSED_FF.c */
3119HANDLE_OPCODE(OP_UNUSED_FF)
3120 /*
3121 * In portable interp, most unused opcodes will fall through to here.
3122 */
3123 LOGE("unknown opcode 0x%02x\n", INST_INST(inst));
3124 dvmAbort();
3125 FINISH(1);
3126OP_END
3127
3128/* File: c/gotoTargets.c */
3129/*
3130 * C footer. This has some common code shared by the various targets.
3131 */
3132
3133/*
3134 * Everything from here on is a "goto target". In the basic interpreter
3135 * we jump into these targets and then jump directly to the handler for
3136 * next instruction. Here, these are subroutines that return to the caller.
3137 */
3138
3139GOTO_TARGET(filledNewArray, bool methodCallRange)
3140 {
3141 ClassObject* arrayClass;
3142 ArrayObject* newArray;
3143 u4* contents;
3144 char typeCh;
3145 int i;
3146 u4 arg5;
3147
3148 EXPORT_PC();
3149
3150 ref = FETCH(1); /* class ref */
3151 vdst = FETCH(2); /* first 4 regs -or- range base */
3152
3153 if (methodCallRange) {
3154 vsrc1 = INST_AA(inst); /* #of elements */
3155 arg5 = -1; /* silence compiler warning */
3156 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
3157 vsrc1, ref, vdst, vdst+vsrc1-1);
3158 } else {
3159 arg5 = INST_A(inst);
3160 vsrc1 = INST_B(inst); /* #of elements */
3161 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
3162 vsrc1, ref, vdst, arg5);
3163 }
3164
3165 /*
3166 * Resolve the array class.
3167 */
3168 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
3169 if (arrayClass == NULL) {
3170 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
3171 if (arrayClass == NULL)
3172 GOTO_exceptionThrown();
3173 }
3174 /*
3175 if (!dvmIsArrayClass(arrayClass)) {
3176 dvmThrowException("Ljava/lang/RuntimeError;",
3177 "filled-new-array needs array class");
3178 GOTO_exceptionThrown();
3179 }
3180 */
3181 /* verifier guarantees this is an array class */
3182 assert(dvmIsArrayClass(arrayClass));
3183 assert(dvmIsClassInitialized(arrayClass));
3184
3185 /*
3186 * Create an array of the specified type.
3187 */
3188 LOGVV("+++ filled-new-array type is '%s'\n", arrayClass->descriptor);
3189 typeCh = arrayClass->descriptor[1];
3190 if (typeCh == 'D' || typeCh == 'J') {
3191 /* category 2 primitives not allowed */
3192 dvmThrowException("Ljava/lang/RuntimeError;",
3193 "bad filled array req");
3194 GOTO_exceptionThrown();
3195 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
3196 /* TODO: requires multiple "fill in" loops with different widths */
3197 LOGE("non-int primitives not implemented\n");
3198 dvmThrowException("Ljava/lang/InternalError;",
3199 "filled-new-array not implemented for anything but 'int'");
3200 GOTO_exceptionThrown();
3201 }
3202
3203 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
3204 if (newArray == NULL)
3205 GOTO_exceptionThrown();
3206
3207 /*
3208 * Fill in the elements. It's legal for vsrc1 to be zero.
3209 */
3210 contents = (u4*) newArray->contents;
3211 if (methodCallRange) {
3212 for (i = 0; i < vsrc1; i++)
3213 contents[i] = GET_REGISTER(vdst+i);
3214 } else {
3215 assert(vsrc1 <= 5);
3216 if (vsrc1 == 5) {
3217 contents[4] = GET_REGISTER(arg5);
3218 vsrc1--;
3219 }
3220 for (i = 0; i < vsrc1; i++) {
3221 contents[i] = GET_REGISTER(vdst & 0x0f);
3222 vdst >>= 4;
3223 }
3224 }
3225
3226 retval.l = newArray;
3227 }
3228 FINISH(3);
3229GOTO_TARGET_END
3230
3231
3232GOTO_TARGET(invokeVirtual, bool methodCallRange)
3233 {
3234 Method* baseMethod;
3235 Object* thisPtr;
3236
3237 EXPORT_PC();
3238
3239 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3240 ref = FETCH(1); /* method ref */
3241 vdst = FETCH(2); /* 4 regs -or- first reg */
3242
3243 /*
3244 * The object against which we are executing a method is always
3245 * in the first argument.
3246 */
3247 if (methodCallRange) {
3248 assert(vsrc1 > 0);
3249 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
3250 vsrc1, ref, vdst, vdst+vsrc1-1);
3251 thisPtr = (Object*) GET_REGISTER(vdst);
3252 } else {
3253 assert((vsrc1>>4) > 0);
3254 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
3255 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3256 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3257 }
3258
3259 if (!checkForNull(thisPtr))
3260 GOTO_exceptionThrown();
3261
3262 /*
3263 * Resolve the method. This is the correct method for the static
3264 * type of the object. We also verify access permissions here.
3265 */
3266 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3267 if (baseMethod == NULL) {
3268 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3269 if (baseMethod == NULL) {
3270 ILOGV("+ unknown method or access denied\n");
3271 GOTO_exceptionThrown();
3272 }
3273 }
3274
3275 /*
3276 * Combine the object we found with the vtable offset in the
3277 * method.
3278 */
3279 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
3280 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
3281
3282#if 0
3283 if (dvmIsAbstractMethod(methodToCall)) {
3284 /*
3285 * This can happen if you create two classes, Base and Sub, where
3286 * Sub is a sub-class of Base. Declare a protected abstract
3287 * method foo() in Base, and invoke foo() from a method in Base.
3288 * Base is an "abstract base class" and is never instantiated
3289 * directly. Now, Override foo() in Sub, and use Sub. This
3290 * Works fine unless Sub stops providing an implementation of
3291 * the method.
3292 */
3293 dvmThrowException("Ljava/lang/AbstractMethodError;",
3294 "abstract method not implemented");
3295 GOTO_exceptionThrown();
3296 }
3297#else
3298 assert(!dvmIsAbstractMethod(methodToCall) ||
3299 methodToCall->nativeFunc != NULL);
3300#endif
3301
3302 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s\n",
3303 baseMethod->clazz->descriptor, baseMethod->name,
3304 (u4) baseMethod->methodIndex,
3305 methodToCall->clazz->descriptor, methodToCall->name);
3306 assert(methodToCall != NULL);
3307
3308#if 0
3309 if (vsrc1 != methodToCall->insSize) {
3310 LOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s\n",
3311 baseMethod->clazz->descriptor, baseMethod->name,
3312 (u4) baseMethod->methodIndex,
3313 methodToCall->clazz->descriptor, methodToCall->name);
3314 //dvmDumpClass(baseMethod->clazz);
3315 //dvmDumpClass(methodToCall->clazz);
3316 dvmDumpAllClasses(0);
3317 }
3318#endif
3319
3320 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3321 }
3322GOTO_TARGET_END
3323
3324GOTO_TARGET(invokeSuper, bool methodCallRange)
3325 {
3326 Method* baseMethod;
3327 u2 thisReg;
3328
3329 EXPORT_PC();
3330
3331 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3332 ref = FETCH(1); /* method ref */
3333 vdst = FETCH(2); /* 4 regs -or- first reg */
3334
3335 if (methodCallRange) {
3336 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
3337 vsrc1, ref, vdst, vdst+vsrc1-1);
3338 thisReg = vdst;
3339 } else {
3340 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
3341 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3342 thisReg = vdst & 0x0f;
3343 }
3344 /* impossible in well-formed code, but we must check nevertheless */
3345 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3346 GOTO_exceptionThrown();
3347
3348 /*
3349 * Resolve the method. This is the correct method for the static
3350 * type of the object. We also verify access permissions here.
3351 * The first arg to dvmResolveMethod() is just the referring class
3352 * (used for class loaders and such), so we don't want to pass
3353 * the superclass into the resolution call.
3354 */
3355 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3356 if (baseMethod == NULL) {
3357 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3358 if (baseMethod == NULL) {
3359 ILOGV("+ unknown method or access denied\n");
3360 GOTO_exceptionThrown();
3361 }
3362 }
3363
3364 /*
3365 * Combine the object we found with the vtable offset in the
3366 * method's class.
3367 *
3368 * We're using the current method's class' superclass, not the
3369 * superclass of "this". This is because we might be executing
3370 * in a method inherited from a superclass, and we want to run
3371 * in that class' superclass.
3372 */
3373 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
3374 /*
3375 * Method does not exist in the superclass. Could happen if
3376 * superclass gets updated.
3377 */
3378 dvmThrowException("Ljava/lang/NoSuchMethodError;",
3379 baseMethod->name);
3380 GOTO_exceptionThrown();
3381 }
3382 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
3383#if 0
3384 if (dvmIsAbstractMethod(methodToCall)) {
3385 dvmThrowException("Ljava/lang/AbstractMethodError;",
3386 "abstract method not implemented");
3387 GOTO_exceptionThrown();
3388 }
3389#else
3390 assert(!dvmIsAbstractMethod(methodToCall) ||
3391 methodToCall->nativeFunc != NULL);
3392#endif
3393 LOGVV("+++ base=%s.%s super-virtual=%s.%s\n",
3394 baseMethod->clazz->descriptor, baseMethod->name,
3395 methodToCall->clazz->descriptor, methodToCall->name);
3396 assert(methodToCall != NULL);
3397
3398 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3399 }
3400GOTO_TARGET_END
3401
3402GOTO_TARGET(invokeInterface, bool methodCallRange)
3403 {
3404 Object* thisPtr;
3405 ClassObject* thisClass;
3406
3407 EXPORT_PC();
3408
3409 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3410 ref = FETCH(1); /* method ref */
3411 vdst = FETCH(2); /* 4 regs -or- first reg */
3412
3413 /*
3414 * The object against which we are executing a method is always
3415 * in the first argument.
3416 */
3417 if (methodCallRange) {
3418 assert(vsrc1 > 0);
3419 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
3420 vsrc1, ref, vdst, vdst+vsrc1-1);
3421 thisPtr = (Object*) GET_REGISTER(vdst);
3422 } else {
3423 assert((vsrc1>>4) > 0);
3424 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
3425 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3426 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3427 }
3428 if (!checkForNull(thisPtr))
3429 GOTO_exceptionThrown();
3430
3431 thisClass = thisPtr->clazz;
3432
3433 /*
3434 * Given a class and a method index, find the Method* with the
3435 * actual code we want to execute.
3436 */
3437 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
3438 methodClassDex);
3439 if (methodToCall == NULL) {
3440 assert(dvmCheckException(self));
3441 GOTO_exceptionThrown();
3442 }
3443
3444 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3445 }
3446GOTO_TARGET_END
3447
3448GOTO_TARGET(invokeDirect, bool methodCallRange)
3449 {
3450 u2 thisReg;
3451
3452 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3453 ref = FETCH(1); /* method ref */
3454 vdst = FETCH(2); /* 4 regs -or- first reg */
3455
3456 EXPORT_PC();
3457
3458 if (methodCallRange) {
3459 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
3460 vsrc1, ref, vdst, vdst+vsrc1-1);
3461 thisReg = vdst;
3462 } else {
3463 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
3464 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3465 thisReg = vdst & 0x0f;
3466 }
3467 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3468 GOTO_exceptionThrown();
3469
3470 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3471 if (methodToCall == NULL) {
3472 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
3473 METHOD_DIRECT);
3474 if (methodToCall == NULL) {
3475 ILOGV("+ unknown direct method\n"); // should be impossible
3476 GOTO_exceptionThrown();
3477 }
3478 }
3479 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3480 }
3481GOTO_TARGET_END
3482
3483GOTO_TARGET(invokeStatic, bool methodCallRange)
3484 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3485 ref = FETCH(1); /* method ref */
3486 vdst = FETCH(2); /* 4 regs -or- first reg */
3487
3488 EXPORT_PC();
3489
3490 if (methodCallRange)
3491 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
3492 vsrc1, ref, vdst, vdst+vsrc1-1);
3493 else
3494 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
3495 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3496
3497 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3498 if (methodToCall == NULL) {
3499 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
3500 if (methodToCall == NULL) {
3501 ILOGV("+ unknown method\n");
3502 GOTO_exceptionThrown();
3503 }
3504 }
3505 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3506GOTO_TARGET_END
3507
3508GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
3509 {
3510 Object* thisPtr;
3511
3512 EXPORT_PC();
3513
3514 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3515 ref = FETCH(1); /* vtable index */
3516 vdst = FETCH(2); /* 4 regs -or- first reg */
3517
3518 /*
3519 * The object against which we are executing a method is always
3520 * in the first argument.
3521 */
3522 if (methodCallRange) {
3523 assert(vsrc1 > 0);
3524 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3525 vsrc1, ref, vdst, vdst+vsrc1-1);
3526 thisPtr = (Object*) GET_REGISTER(vdst);
3527 } else {
3528 assert((vsrc1>>4) > 0);
3529 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
3530 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3531 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3532 }
3533
3534 if (!checkForNull(thisPtr))
3535 GOTO_exceptionThrown();
3536
3537 /*
3538 * Combine the object we found with the vtable offset in the
3539 * method.
3540 */
3541 assert(ref < thisPtr->clazz->vtableCount);
3542 methodToCall = thisPtr->clazz->vtable[ref];
3543
3544#if 0
3545 if (dvmIsAbstractMethod(methodToCall)) {
3546 dvmThrowException("Ljava/lang/AbstractMethodError;",
3547 "abstract method not implemented");
3548 GOTO_exceptionThrown();
3549 }
3550#else
3551 assert(!dvmIsAbstractMethod(methodToCall) ||
3552 methodToCall->nativeFunc != NULL);
3553#endif
3554
3555 LOGVV("+++ virtual[%d]=%s.%s\n",
3556 ref, methodToCall->clazz->descriptor, methodToCall->name);
3557 assert(methodToCall != NULL);
3558
3559 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3560 }
3561GOTO_TARGET_END
3562
3563GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
3564 {
3565 u2 thisReg;
3566
3567 EXPORT_PC();
3568
3569 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3570 ref = FETCH(1); /* vtable index */
3571 vdst = FETCH(2); /* 4 regs -or- first reg */
3572
3573 if (methodCallRange) {
3574 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3575 vsrc1, ref, vdst, vdst+vsrc1-1);
3576 thisReg = vdst;
3577 } else {
3578 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
3579 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3580 thisReg = vdst & 0x0f;
3581 }
3582 /* impossible in well-formed code, but we must check nevertheless */
3583 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3584 GOTO_exceptionThrown();
3585
3586#if 0 /* impossible in optimized + verified code */
3587 if (ref >= curMethod->clazz->super->vtableCount) {
3588 dvmThrowException("Ljava/lang/NoSuchMethodError;", NULL);
3589 GOTO_exceptionThrown();
3590 }
3591#else
3592 assert(ref < curMethod->clazz->super->vtableCount);
3593#endif
3594
3595 /*
3596 * Combine the object we found with the vtable offset in the
3597 * method's class.
3598 *
3599 * We're using the current method's class' superclass, not the
3600 * superclass of "this". This is because we might be executing
3601 * in a method inherited from a superclass, and we want to run
3602 * in the method's class' superclass.
3603 */
3604 methodToCall = curMethod->clazz->super->vtable[ref];
3605
3606#if 0
3607 if (dvmIsAbstractMethod(methodToCall)) {
3608 dvmThrowException("Ljava/lang/AbstractMethodError;",
3609 "abstract method not implemented");
3610 GOTO_exceptionThrown();
3611 }
3612#else
3613 assert(!dvmIsAbstractMethod(methodToCall) ||
3614 methodToCall->nativeFunc != NULL);
3615#endif
3616 LOGVV("+++ super-virtual[%d]=%s.%s\n",
3617 ref, methodToCall->clazz->descriptor, methodToCall->name);
3618 assert(methodToCall != NULL);
3619
3620 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3621 }
3622GOTO_TARGET_END
3623
3624
3625
3626 /*
3627 * General handling for return-void, return, and return-wide. Put the
3628 * return value in "retval" before jumping here.
3629 */
3630GOTO_TARGET(returnFromMethod)
3631 {
3632 StackSaveArea* saveArea;
3633
3634 /*
3635 * We must do this BEFORE we pop the previous stack frame off, so
3636 * that the GC can see the return value (if any) in the local vars.
3637 *
3638 * Since this is now an interpreter switch point, we must do it before
3639 * we do anything at all.
3640 */
3641 PERIODIC_CHECKS(kInterpEntryReturn, 0);
3642
3643 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
3644 retval.j, curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04003645 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003646 //DUMP_REGS(curMethod, fp);
3647
3648 saveArea = SAVEAREA_FROM_FP(fp);
3649
3650#ifdef EASY_GDB
3651 debugSaveArea = saveArea;
3652#endif
3653#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3654 TRACE_METHOD_EXIT(self, curMethod);
3655#endif
3656
3657 /* back up to previous frame and see if we hit a break */
3658 fp = saveArea->prevFrame;
3659 assert(fp != NULL);
3660 if (dvmIsBreakFrame(fp)) {
3661 /* bail without popping the method frame from stack */
3662 LOGVV("+++ returned into break frame\n");
Bill Buzbeed7269912009-11-10 14:31:32 -08003663#if defined(WITH_JIT)
3664 /* Let the Jit know the return is terminating normally */
3665 CHECK_JIT();
3666#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003667 GOTO_bail();
3668 }
3669
3670 /* update thread FP, and reset local variables */
3671 self->curFrame = fp;
3672 curMethod = SAVEAREA_FROM_FP(fp)->method;
3673 //methodClass = curMethod->clazz;
3674 methodClassDex = curMethod->clazz->pDvmDex;
3675 pc = saveArea->savedPc;
3676 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003677 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003678
3679 /* use FINISH on the caller's invoke instruction */
3680 //u2 invokeInstr = INST_INST(FETCH(0));
3681 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3682 invokeInstr <= OP_INVOKE_INTERFACE*/)
3683 {
3684 FINISH(3);
3685 } else {
3686 //LOGE("Unknown invoke instr %02x at %d\n",
3687 // invokeInstr, (int) (pc - curMethod->insns));
3688 assert(false);
3689 }
3690 }
3691GOTO_TARGET_END
3692
3693
3694 /*
3695 * Jump here when the code throws an exception.
3696 *
3697 * By the time we get here, the Throwable has been created and the stack
3698 * trace has been saved off.
3699 */
3700GOTO_TARGET(exceptionThrown)
3701 {
3702 Object* exception;
3703 int catchRelPc;
3704
3705 /*
3706 * Since this is now an interpreter switch point, we must do it before
3707 * we do anything at all.
3708 */
3709 PERIODIC_CHECKS(kInterpEntryThrow, 0);
3710
Ben Cheng79d173c2009-09-29 16:12:51 -07003711#if defined(WITH_JIT)
3712 // Something threw during trace selection - abort the current trace
Bill Buzbee5540f6e2010-02-08 10:41:32 -08003713 ABORT_JIT_TSELECT();
Ben Cheng79d173c2009-09-29 16:12:51 -07003714#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003715 /*
3716 * We save off the exception and clear the exception status. While
3717 * processing the exception we might need to load some Throwable
3718 * classes, and we don't want class loader exceptions to get
3719 * confused with this one.
3720 */
3721 assert(dvmCheckException(self));
3722 exception = dvmGetException(self);
3723 dvmAddTrackedAlloc(exception, self);
3724 dvmClearException(self);
3725
3726 LOGV("Handling exception %s at %s:%d\n",
3727 exception->clazz->descriptor, curMethod->name,
3728 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3729
3730#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3731 /*
3732 * Tell the debugger about it.
3733 *
3734 * TODO: if the exception was thrown by interpreted code, control
3735 * fell through native, and then back to us, we will report the
3736 * exception at the point of the throw and again here. We can avoid
3737 * this by not reporting exceptions when we jump here directly from
3738 * the native call code above, but then we won't report exceptions
3739 * that were thrown *from* the JNI code (as opposed to *through* it).
3740 *
3741 * The correct solution is probably to ignore from-native exceptions
3742 * here, and have the JNI exception code do the reporting to the
3743 * debugger.
3744 */
3745 if (gDvm.debuggerActive) {
3746 void* catchFrame;
3747 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3748 exception, true, &catchFrame);
3749 dvmDbgPostException(fp, pc - curMethod->insns, catchFrame,
3750 catchRelPc, exception);
3751 }
3752#endif
3753
3754 /*
3755 * We need to unroll to the catch block or the nearest "break"
3756 * frame.
3757 *
3758 * A break frame could indicate that we have reached an intermediate
3759 * native call, or have gone off the top of the stack and the thread
3760 * needs to exit. Either way, we return from here, leaving the
3761 * exception raised.
3762 *
3763 * If we do find a catch block, we want to transfer execution to
3764 * that point.
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003765 *
3766 * Note this can cause an exception while resolving classes in
3767 * the "catch" blocks.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003768 */
3769 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3770 exception, false, (void*)&fp);
3771
3772 /*
3773 * Restore the stack bounds after an overflow. This isn't going to
3774 * be correct in all circumstances, e.g. if JNI code devours the
3775 * exception this won't happen until some other exception gets
3776 * thrown. If the code keeps pushing the stack bounds we'll end
3777 * up aborting the VM.
3778 *
3779 * Note we want to do this *after* the call to dvmFindCatchBlock,
3780 * because that may need extra stack space to resolve exception
3781 * classes (e.g. through a class loader).
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003782 *
3783 * It's possible for the stack overflow handling to cause an
3784 * exception (specifically, class resolution in a "catch" block
3785 * during the call above), so we could see the thread's overflow
3786 * flag raised but actually be running in a "nested" interpreter
3787 * frame. We don't allow doubled-up StackOverflowErrors, so
3788 * we can check for this by just looking at the exception type
3789 * in the cleanup function. Also, we won't unroll past the SOE
3790 * point because the more-recent exception will hit a break frame
3791 * as it unrolls to here.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003792 */
3793 if (self->stackOverflowed)
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003794 dvmCleanupStackOverflow(self, exception);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003795
3796 if (catchRelPc < 0) {
3797 /* falling through to JNI code or off the bottom of the stack */
3798#if DVM_SHOW_EXCEPTION >= 2
3799 LOGD("Exception %s from %s:%d not caught locally\n",
3800 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3801 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3802#endif
3803 dvmSetException(self, exception);
3804 dvmReleaseTrackedAlloc(exception, self);
3805 GOTO_bail();
3806 }
3807
3808#if DVM_SHOW_EXCEPTION >= 3
3809 {
3810 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
3811 LOGD("Exception %s thrown from %s:%d to %s:%d\n",
3812 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3813 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
3814 dvmGetMethodSourceFile(catchMethod),
3815 dvmLineNumFromPC(catchMethod, catchRelPc));
3816 }
3817#endif
3818
3819 /*
3820 * Adjust local variables to match self->curFrame and the
3821 * updated PC.
3822 */
3823 //fp = (u4*) self->curFrame;
3824 curMethod = SAVEAREA_FROM_FP(fp)->method;
3825 //methodClass = curMethod->clazz;
3826 methodClassDex = curMethod->clazz->pDvmDex;
3827 pc = curMethod->insns + catchRelPc;
3828 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003829 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003830 DUMP_REGS(curMethod, fp, false); // show all regs
3831
3832 /*
3833 * Restore the exception if the handler wants it.
3834 *
3835 * The Dalvik spec mandates that, if an exception handler wants to
3836 * do something with the exception, the first instruction executed
3837 * must be "move-exception". We can pass the exception along
3838 * through the thread struct, and let the move-exception instruction
3839 * clear it for us.
3840 *
3841 * If the handler doesn't call move-exception, we don't want to
3842 * finish here with an exception still pending.
3843 */
3844 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
3845 dvmSetException(self, exception);
3846
3847 dvmReleaseTrackedAlloc(exception, self);
3848 FINISH(0);
3849 }
3850GOTO_TARGET_END
3851
3852
3853 /*
3854 * General handling for invoke-{virtual,super,direct,static,interface},
3855 * including "quick" variants.
3856 *
3857 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
3858 * depending on whether this is a "/range" instruction.
3859 *
3860 * For a range call:
3861 * "vsrc1" holds the argument count (8 bits)
3862 * "vdst" holds the first argument in the range
3863 * For a non-range call:
3864 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
3865 * "vdst" holds four 4-bit register indices
3866 *
3867 * The caller must EXPORT_PC before jumping here, because any method
3868 * call can throw a stack overflow exception.
3869 */
3870GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
3871 u2 count, u2 regs)
3872 {
3873 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
3874
3875 //printf("range=%d call=%p count=%d regs=0x%04x\n",
3876 // methodCallRange, methodToCall, count, regs);
3877 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003878 // methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003879
3880 u4* outs;
3881 int i;
3882
3883 /*
3884 * Copy args. This may corrupt vsrc1/vdst.
3885 */
3886 if (methodCallRange) {
3887 // could use memcpy or a "Duff's device"; most functions have
3888 // so few args it won't matter much
3889 assert(vsrc1 <= curMethod->outsSize);
3890 assert(vsrc1 == methodToCall->insSize);
3891 outs = OUTS_FROM_FP(fp, vsrc1);
3892 for (i = 0; i < vsrc1; i++)
3893 outs[i] = GET_REGISTER(vdst+i);
3894 } else {
3895 u4 count = vsrc1 >> 4;
3896
3897 assert(count <= curMethod->outsSize);
3898 assert(count == methodToCall->insSize);
3899 assert(count <= 5);
3900
3901 outs = OUTS_FROM_FP(fp, count);
3902#if 0
3903 if (count == 5) {
3904 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3905 count--;
3906 }
3907 for (i = 0; i < (int) count; i++) {
3908 outs[i] = GET_REGISTER(vdst & 0x0f);
3909 vdst >>= 4;
3910 }
3911#else
3912 // This version executes fewer instructions but is larger
3913 // overall. Seems to be a teensy bit faster.
3914 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
3915 switch (count) {
3916 case 5:
3917 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3918 case 4:
3919 outs[3] = GET_REGISTER(vdst >> 12);
3920 case 3:
3921 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
3922 case 2:
3923 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
3924 case 1:
3925 outs[0] = GET_REGISTER(vdst & 0x0f);
3926 default:
3927 ;
3928 }
3929#endif
3930 }
3931 }
3932
3933 /*
3934 * (This was originally a "goto" target; I've kept it separate from the
3935 * stuff above in case we want to refactor things again.)
3936 *
3937 * At this point, we have the arguments stored in the "outs" area of
3938 * the current method's stack frame, and the method to call in
3939 * "methodToCall". Push a new stack frame.
3940 */
3941 {
3942 StackSaveArea* newSaveArea;
3943 u4* newFp;
3944
3945 ILOGV("> %s%s.%s %s",
3946 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
3947 methodToCall->clazz->descriptor, methodToCall->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04003948 methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003949
3950 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
3951 newSaveArea = SAVEAREA_FROM_FP(newFp);
3952
3953 /* verify that we have enough space */
3954 if (true) {
3955 u1* bottom;
3956 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
3957 if (bottom < self->interpStackEnd) {
3958 /* stack overflow */
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07003959 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 -08003960 self->interpStackStart, self->interpStackEnd, bottom,
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07003961 (u1*) fp - bottom, self->interpStackSize,
3962 methodToCall->name);
3963 dvmHandleStackOverflow(self, methodToCall);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003964 assert(dvmCheckException(self));
3965 GOTO_exceptionThrown();
3966 }
3967 //LOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p\n",
3968 // fp, newFp, newSaveArea, bottom);
3969 }
3970
3971#ifdef LOG_INSTR
3972 if (methodToCall->registersSize > methodToCall->insSize) {
3973 /*
3974 * This makes valgrind quiet when we print registers that
3975 * haven't been initialized. Turn it off when the debug
3976 * messages are disabled -- we want valgrind to report any
3977 * used-before-initialized issues.
3978 */
3979 memset(newFp, 0xcc,
3980 (methodToCall->registersSize - methodToCall->insSize) * 4);
3981 }
3982#endif
3983
3984#ifdef EASY_GDB
3985 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
3986#endif
3987 newSaveArea->prevFrame = fp;
3988 newSaveArea->savedPc = pc;
Ben Chengba4fc8b2009-06-01 13:00:29 -07003989#if defined(WITH_JIT)
3990 newSaveArea->returnAddr = 0;
3991#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003992 newSaveArea->method = methodToCall;
3993
3994 if (!dvmIsNativeMethod(methodToCall)) {
3995 /*
3996 * "Call" interpreted code. Reposition the PC, update the
3997 * frame pointer and other local state, and continue.
3998 */
3999 curMethod = methodToCall;
4000 methodClassDex = curMethod->clazz->pDvmDex;
4001 pc = methodToCall->insns;
4002 fp = self->curFrame = newFp;
4003#ifdef EASY_GDB
4004 debugSaveArea = SAVEAREA_FROM_FP(newFp);
4005#endif
4006#if INTERP_TYPE == INTERP_DBG
4007 debugIsMethodEntry = true; // profiling, debugging
4008#endif
4009 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04004010 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004011 DUMP_REGS(curMethod, fp, true); // show input args
4012 FINISH(0); // jump to method start
4013 } else {
4014 /* set this up for JNI locals, even if not a JNI native */
Andy McFaddend5ab7262009-08-25 07:19:34 -07004015#ifdef USE_INDIRECT_REF
4016 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.segmentState.all;
4017#else
4018 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.nextEntry;
4019#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004020
4021 self->curFrame = newFp;
4022
4023 DUMP_REGS(methodToCall, newFp, true); // show input args
4024
4025#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
4026 if (gDvm.debuggerActive) {
4027 dvmDbgPostLocationEvent(methodToCall, -1,
4028 dvmGetThisPtr(curMethod, fp), DBG_METHOD_ENTRY);
4029 }
4030#endif
4031#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
4032 TRACE_METHOD_ENTER(self, methodToCall);
4033#endif
4034
4035 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04004036 methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004037
Bill Buzbeed7269912009-11-10 14:31:32 -08004038#if defined(WITH_JIT)
4039 /* Allow the Jit to end any pending trace building */
4040 CHECK_JIT();
4041#endif
4042
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004043 /*
4044 * Jump through native call bridge. Because we leave no
4045 * space for locals on native calls, "newFp" points directly
4046 * to the method arguments.
4047 */
4048 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
4049
4050#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
4051 if (gDvm.debuggerActive) {
4052 dvmDbgPostLocationEvent(methodToCall, -1,
4053 dvmGetThisPtr(curMethod, fp), DBG_METHOD_EXIT);
4054 }
4055#endif
4056#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
4057 TRACE_METHOD_EXIT(self, methodToCall);
4058#endif
4059
4060 /* pop frame off */
4061 dvmPopJniLocals(self, newSaveArea);
4062 self->curFrame = fp;
4063
4064 /*
4065 * If the native code threw an exception, or interpreted code
4066 * invoked by the native call threw one and nobody has cleared
4067 * it, jump to our local exception handling.
4068 */
4069 if (dvmCheckException(self)) {
4070 LOGV("Exception thrown by/below native code\n");
4071 GOTO_exceptionThrown();
4072 }
4073
4074 ILOGD("> retval=0x%llx (leaving native)", retval.j);
4075 ILOGD("> (return from native %s.%s to %s.%s %s)",
4076 methodToCall->clazz->descriptor, methodToCall->name,
4077 curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04004078 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004079
4080 //u2 invokeInstr = INST_INST(FETCH(0));
4081 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
4082 invokeInstr <= OP_INVOKE_INTERFACE*/)
4083 {
4084 FINISH(3);
4085 } else {
4086 //LOGE("Unknown invoke instr %02x at %d\n",
4087 // invokeInstr, (int) (pc - curMethod->insns));
4088 assert(false);
4089 }
4090 }
4091 }
4092 assert(false); // should not get here
4093GOTO_TARGET_END
4094
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004095/* File: portable/enddefs.c */
4096/*--- end of opcodes ---*/
4097
4098#ifndef THREADED_INTERP
4099 } // end of "switch"
4100 } // end of "while"
4101#endif
4102
4103bail:
4104 ILOGD("|-- Leaving interpreter loop"); // note "curMethod" may be NULL
4105
4106 interpState->retval = retval;
4107 return false;
4108
4109bail_switch:
4110 /*
4111 * The standard interpreter currently doesn't set or care about the
4112 * "debugIsMethodEntry" value, so setting this is only of use if we're
4113 * switching between two "debug" interpreters, which we never do.
4114 *
4115 * TODO: figure out if preserving this makes any sense.
4116 */
4117#if defined(WITH_PROFILER) || defined(WITH_DEBUGGER)
4118# if INTERP_TYPE == INTERP_DBG
4119 interpState->debugIsMethodEntry = debugIsMethodEntry;
4120# else
4121 interpState->debugIsMethodEntry = false;
4122# endif
4123#endif
4124
4125 /* export state changes */
4126 interpState->method = curMethod;
4127 interpState->pc = pc;
4128 interpState->fp = fp;
4129 /* debugTrackedRefStart doesn't change */
4130 interpState->retval = retval; /* need for _entryPoint=ret */
4131 interpState->nextMode =
4132 (INTERP_TYPE == INTERP_STD) ? INTERP_DBG : INTERP_STD;
4133 LOGVV(" meth='%s.%s' pc=0x%x fp=%p\n",
4134 curMethod->clazz->descriptor, curMethod->name,
4135 pc - curMethod->insns, fp);
4136 return true;
4137}
4138
4139