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