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