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