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