blob: 7e20714aa14bf4528456601dea6b8441c672c432 [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
Andy McFadden8ba27082010-05-21 12:20:23 -07001917 /*
1918 * We don't create an exception here, but the process of searching
1919 * for a catch block can do class lookups and throw exceptions.
1920 * We need to update the saved PC.
1921 */
1922 EXPORT_PC();
1923
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001924 vsrc1 = INST_AA(inst);
1925 ILOGV("|throw v%d (%p)", vsrc1, (void*)GET_REGISTER(vsrc1));
1926 obj = (Object*) GET_REGISTER(vsrc1);
Andy McFadden8ba27082010-05-21 12:20:23 -07001927 if (!checkForNull(obj)) {
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001928 /* will throw a null pointer exception */
1929 LOGVV("Bad exception\n");
1930 } else {
1931 /* use the requested exception */
1932 dvmSetException(self, obj);
1933 }
1934 GOTO_exceptionThrown();
1935 }
1936OP_END
1937
1938/* File: c/OP_GOTO.c */
1939HANDLE_OPCODE(OP_GOTO /*+AA*/)
1940 vdst = INST_AA(inst);
1941 if ((s1)vdst < 0)
1942 ILOGV("|goto -0x%02x", -((s1)vdst));
1943 else
1944 ILOGV("|goto +0x%02x", ((s1)vdst));
1945 ILOGV("> branch taken");
1946 if ((s1)vdst < 0)
1947 PERIODIC_CHECKS(kInterpEntryInstr, (s1)vdst);
1948 FINISH((s1)vdst);
1949OP_END
1950
1951/* File: c/OP_GOTO_16.c */
1952HANDLE_OPCODE(OP_GOTO_16 /*+AAAA*/)
1953 {
1954 s4 offset = (s2) FETCH(1); /* sign-extend next code unit */
1955
1956 if (offset < 0)
1957 ILOGV("|goto/16 -0x%04x", -offset);
1958 else
1959 ILOGV("|goto/16 +0x%04x", offset);
1960 ILOGV("> branch taken");
1961 if (offset < 0)
1962 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1963 FINISH(offset);
1964 }
1965OP_END
1966
1967/* File: c/OP_GOTO_32.c */
1968HANDLE_OPCODE(OP_GOTO_32 /*+AAAAAAAA*/)
1969 {
1970 s4 offset = FETCH(1); /* low-order 16 bits */
1971 offset |= ((s4) FETCH(2)) << 16; /* high-order 16 bits */
1972
1973 if (offset < 0)
1974 ILOGV("|goto/32 -0x%08x", -offset);
1975 else
1976 ILOGV("|goto/32 +0x%08x", offset);
1977 ILOGV("> branch taken");
1978 if (offset <= 0) /* allowed to branch to self */
1979 PERIODIC_CHECKS(kInterpEntryInstr, offset);
1980 FINISH(offset);
1981 }
1982OP_END
1983
1984/* File: c/OP_PACKED_SWITCH.c */
1985HANDLE_OPCODE(OP_PACKED_SWITCH /*vAA, +BBBB*/)
1986 {
1987 const u2* switchData;
1988 u4 testVal;
1989 s4 offset;
1990
1991 vsrc1 = INST_AA(inst);
1992 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
1993 ILOGV("|packed-switch v%d +0x%04x", vsrc1, vsrc2);
1994 switchData = pc + offset; // offset in 16-bit units
1995#ifndef NDEBUG
1996 if (switchData < curMethod->insns ||
1997 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
1998 {
1999 /* should have been caught in verifier */
2000 EXPORT_PC();
2001 dvmThrowException("Ljava/lang/InternalError;", "bad packed switch");
2002 GOTO_exceptionThrown();
2003 }
2004#endif
2005 testVal = GET_REGISTER(vsrc1);
2006
2007 offset = dvmInterpHandlePackedSwitch(switchData, testVal);
2008 ILOGV("> branch taken (0x%04x)\n", offset);
2009 if (offset <= 0) /* uncommon */
2010 PERIODIC_CHECKS(kInterpEntryInstr, offset);
2011 FINISH(offset);
2012 }
2013OP_END
2014
2015/* File: c/OP_SPARSE_SWITCH.c */
2016HANDLE_OPCODE(OP_SPARSE_SWITCH /*vAA, +BBBB*/)
2017 {
2018 const u2* switchData;
2019 u4 testVal;
2020 s4 offset;
2021
2022 vsrc1 = INST_AA(inst);
2023 offset = FETCH(1) | (((s4) FETCH(2)) << 16);
2024 ILOGV("|sparse-switch v%d +0x%04x", vsrc1, vsrc2);
2025 switchData = pc + offset; // offset in 16-bit units
2026#ifndef NDEBUG
2027 if (switchData < curMethod->insns ||
2028 switchData >= curMethod->insns + dvmGetMethodInsnsSize(curMethod))
2029 {
2030 /* should have been caught in verifier */
2031 EXPORT_PC();
2032 dvmThrowException("Ljava/lang/InternalError;", "bad sparse switch");
2033 GOTO_exceptionThrown();
2034 }
2035#endif
2036 testVal = GET_REGISTER(vsrc1);
2037
2038 offset = dvmInterpHandleSparseSwitch(switchData, testVal);
2039 ILOGV("> branch taken (0x%04x)\n", offset);
2040 if (offset <= 0) /* uncommon */
2041 PERIODIC_CHECKS(kInterpEntryInstr, offset);
2042 FINISH(offset);
2043 }
2044OP_END
2045
2046/* File: c/OP_CMPL_FLOAT.c */
2047HANDLE_OP_CMPX(OP_CMPL_FLOAT, "l-float", float, _FLOAT, -1)
2048OP_END
2049
2050/* File: c/OP_CMPG_FLOAT.c */
2051HANDLE_OP_CMPX(OP_CMPG_FLOAT, "g-float", float, _FLOAT, 1)
2052OP_END
2053
2054/* File: c/OP_CMPL_DOUBLE.c */
2055HANDLE_OP_CMPX(OP_CMPL_DOUBLE, "l-double", double, _DOUBLE, -1)
2056OP_END
2057
2058/* File: c/OP_CMPG_DOUBLE.c */
2059HANDLE_OP_CMPX(OP_CMPG_DOUBLE, "g-double", double, _DOUBLE, 1)
2060OP_END
2061
2062/* File: c/OP_CMP_LONG.c */
2063HANDLE_OP_CMPX(OP_CMP_LONG, "-long", s8, _WIDE, 0)
2064OP_END
2065
2066/* File: c/OP_IF_EQ.c */
2067HANDLE_OP_IF_XX(OP_IF_EQ, "eq", ==)
2068OP_END
2069
2070/* File: c/OP_IF_NE.c */
2071HANDLE_OP_IF_XX(OP_IF_NE, "ne", !=)
2072OP_END
2073
2074/* File: c/OP_IF_LT.c */
2075HANDLE_OP_IF_XX(OP_IF_LT, "lt", <)
2076OP_END
2077
2078/* File: c/OP_IF_GE.c */
2079HANDLE_OP_IF_XX(OP_IF_GE, "ge", >=)
2080OP_END
2081
2082/* File: c/OP_IF_GT.c */
2083HANDLE_OP_IF_XX(OP_IF_GT, "gt", >)
2084OP_END
2085
2086/* File: c/OP_IF_LE.c */
2087HANDLE_OP_IF_XX(OP_IF_LE, "le", <=)
2088OP_END
2089
2090/* File: c/OP_IF_EQZ.c */
2091HANDLE_OP_IF_XXZ(OP_IF_EQZ, "eqz", ==)
2092OP_END
2093
2094/* File: c/OP_IF_NEZ.c */
2095HANDLE_OP_IF_XXZ(OP_IF_NEZ, "nez", !=)
2096OP_END
2097
2098/* File: c/OP_IF_LTZ.c */
2099HANDLE_OP_IF_XXZ(OP_IF_LTZ, "ltz", <)
2100OP_END
2101
2102/* File: c/OP_IF_GEZ.c */
2103HANDLE_OP_IF_XXZ(OP_IF_GEZ, "gez", >=)
2104OP_END
2105
2106/* File: c/OP_IF_GTZ.c */
2107HANDLE_OP_IF_XXZ(OP_IF_GTZ, "gtz", >)
2108OP_END
2109
2110/* File: c/OP_IF_LEZ.c */
2111HANDLE_OP_IF_XXZ(OP_IF_LEZ, "lez", <=)
2112OP_END
2113
2114/* File: c/OP_UNUSED_3E.c */
2115HANDLE_OPCODE(OP_UNUSED_3E)
2116OP_END
2117
2118/* File: c/OP_UNUSED_3F.c */
2119HANDLE_OPCODE(OP_UNUSED_3F)
2120OP_END
2121
2122/* File: c/OP_UNUSED_40.c */
2123HANDLE_OPCODE(OP_UNUSED_40)
2124OP_END
2125
2126/* File: c/OP_UNUSED_41.c */
2127HANDLE_OPCODE(OP_UNUSED_41)
2128OP_END
2129
2130/* File: c/OP_UNUSED_42.c */
2131HANDLE_OPCODE(OP_UNUSED_42)
2132OP_END
2133
2134/* File: c/OP_UNUSED_43.c */
2135HANDLE_OPCODE(OP_UNUSED_43)
2136OP_END
2137
2138/* File: c/OP_AGET.c */
2139HANDLE_OP_AGET(OP_AGET, "", u4, )
2140OP_END
2141
2142/* File: c/OP_AGET_WIDE.c */
2143HANDLE_OP_AGET(OP_AGET_WIDE, "-wide", s8, _WIDE)
2144OP_END
2145
2146/* File: c/OP_AGET_OBJECT.c */
2147HANDLE_OP_AGET(OP_AGET_OBJECT, "-object", u4, )
2148OP_END
2149
2150/* File: c/OP_AGET_BOOLEAN.c */
2151HANDLE_OP_AGET(OP_AGET_BOOLEAN, "-boolean", u1, )
2152OP_END
2153
2154/* File: c/OP_AGET_BYTE.c */
2155HANDLE_OP_AGET(OP_AGET_BYTE, "-byte", s1, )
2156OP_END
2157
2158/* File: c/OP_AGET_CHAR.c */
2159HANDLE_OP_AGET(OP_AGET_CHAR, "-char", u2, )
2160OP_END
2161
2162/* File: c/OP_AGET_SHORT.c */
2163HANDLE_OP_AGET(OP_AGET_SHORT, "-short", s2, )
2164OP_END
2165
2166/* File: c/OP_APUT.c */
2167HANDLE_OP_APUT(OP_APUT, "", u4, )
2168OP_END
2169
2170/* File: c/OP_APUT_WIDE.c */
2171HANDLE_OP_APUT(OP_APUT_WIDE, "-wide", s8, _WIDE)
2172OP_END
2173
2174/* File: c/OP_APUT_OBJECT.c */
2175HANDLE_OPCODE(OP_APUT_OBJECT /*vAA, vBB, vCC*/)
2176 {
2177 ArrayObject* arrayObj;
2178 Object* obj;
2179 u2 arrayInfo;
2180 EXPORT_PC();
2181 vdst = INST_AA(inst); /* AA: source value */
2182 arrayInfo = FETCH(1);
2183 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */
2184 vsrc2 = arrayInfo >> 8; /* CC: index */
2185 ILOGV("|aput%s v%d,v%d,v%d", "-object", vdst, vsrc1, vsrc2);
2186 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);
2187 if (!checkForNull((Object*) arrayObj))
2188 GOTO_exceptionThrown();
2189 if (GET_REGISTER(vsrc2) >= arrayObj->length) {
2190 dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
2191 NULL);
2192 GOTO_exceptionThrown();
2193 }
2194 obj = (Object*) GET_REGISTER(vdst);
2195 if (obj != NULL) {
2196 if (!checkForNull(obj))
2197 GOTO_exceptionThrown();
2198 if (!dvmCanPutArrayElement(obj->clazz, arrayObj->obj.clazz)) {
2199 LOGV("Can't put a '%s'(%p) into array type='%s'(%p)\n",
2200 obj->clazz->descriptor, obj,
2201 arrayObj->obj.clazz->descriptor, arrayObj);
2202 //dvmDumpClass(obj->clazz);
2203 //dvmDumpClass(arrayObj->obj.clazz);
2204 dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
2205 GOTO_exceptionThrown();
2206 }
2207 }
2208 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));
2209 ((u4*) arrayObj->contents)[GET_REGISTER(vsrc2)] =
2210 GET_REGISTER(vdst);
2211 }
2212 FINISH(2);
2213OP_END
2214
2215/* File: c/OP_APUT_BOOLEAN.c */
2216HANDLE_OP_APUT(OP_APUT_BOOLEAN, "-boolean", u1, )
2217OP_END
2218
2219/* File: c/OP_APUT_BYTE.c */
2220HANDLE_OP_APUT(OP_APUT_BYTE, "-byte", s1, )
2221OP_END
2222
2223/* File: c/OP_APUT_CHAR.c */
2224HANDLE_OP_APUT(OP_APUT_CHAR, "-char", u2, )
2225OP_END
2226
2227/* File: c/OP_APUT_SHORT.c */
2228HANDLE_OP_APUT(OP_APUT_SHORT, "-short", s2, )
2229OP_END
2230
2231/* File: c/OP_IGET.c */
2232HANDLE_IGET_X(OP_IGET, "", Int, )
2233OP_END
2234
2235/* File: c/OP_IGET_WIDE.c */
2236HANDLE_IGET_X(OP_IGET_WIDE, "-wide", Long, _WIDE)
2237OP_END
2238
2239/* File: c/OP_IGET_OBJECT.c */
2240HANDLE_IGET_X(OP_IGET_OBJECT, "-object", Object, _AS_OBJECT)
2241OP_END
2242
2243/* File: c/OP_IGET_BOOLEAN.c */
2244HANDLE_IGET_X(OP_IGET_BOOLEAN, "", Int, )
2245OP_END
2246
2247/* File: c/OP_IGET_BYTE.c */
2248HANDLE_IGET_X(OP_IGET_BYTE, "", Int, )
2249OP_END
2250
2251/* File: c/OP_IGET_CHAR.c */
2252HANDLE_IGET_X(OP_IGET_CHAR, "", Int, )
2253OP_END
2254
2255/* File: c/OP_IGET_SHORT.c */
2256HANDLE_IGET_X(OP_IGET_SHORT, "", Int, )
2257OP_END
2258
2259/* File: c/OP_IPUT.c */
2260HANDLE_IPUT_X(OP_IPUT, "", Int, )
2261OP_END
2262
2263/* File: c/OP_IPUT_WIDE.c */
2264HANDLE_IPUT_X(OP_IPUT_WIDE, "-wide", Long, _WIDE)
2265OP_END
2266
2267/* File: c/OP_IPUT_OBJECT.c */
2268/*
2269 * The VM spec says we should verify that the reference being stored into
2270 * the field is assignment compatible. In practice, many popular VMs don't
2271 * do this because it slows down a very common operation. It's not so bad
2272 * for us, since "dexopt" quickens it whenever possible, but it's still an
2273 * issue.
2274 *
2275 * To make this spec-complaint, we'd need to add a ClassObject pointer to
2276 * the Field struct, resolve the field's type descriptor at link or class
2277 * init time, and then verify the type here.
2278 */
2279HANDLE_IPUT_X(OP_IPUT_OBJECT, "-object", Object, _AS_OBJECT)
2280OP_END
2281
2282/* File: c/OP_IPUT_BOOLEAN.c */
2283HANDLE_IPUT_X(OP_IPUT_BOOLEAN, "", Int, )
2284OP_END
2285
2286/* File: c/OP_IPUT_BYTE.c */
2287HANDLE_IPUT_X(OP_IPUT_BYTE, "", Int, )
2288OP_END
2289
2290/* File: c/OP_IPUT_CHAR.c */
2291HANDLE_IPUT_X(OP_IPUT_CHAR, "", Int, )
2292OP_END
2293
2294/* File: c/OP_IPUT_SHORT.c */
2295HANDLE_IPUT_X(OP_IPUT_SHORT, "", Int, )
2296OP_END
2297
2298/* File: c/OP_SGET.c */
2299HANDLE_SGET_X(OP_SGET, "", Int, )
2300OP_END
2301
2302/* File: c/OP_SGET_WIDE.c */
2303HANDLE_SGET_X(OP_SGET_WIDE, "-wide", Long, _WIDE)
2304OP_END
2305
2306/* File: c/OP_SGET_OBJECT.c */
2307HANDLE_SGET_X(OP_SGET_OBJECT, "-object", Object, _AS_OBJECT)
2308OP_END
2309
2310/* File: c/OP_SGET_BOOLEAN.c */
2311HANDLE_SGET_X(OP_SGET_BOOLEAN, "", Int, )
2312OP_END
2313
2314/* File: c/OP_SGET_BYTE.c */
2315HANDLE_SGET_X(OP_SGET_BYTE, "", Int, )
2316OP_END
2317
2318/* File: c/OP_SGET_CHAR.c */
2319HANDLE_SGET_X(OP_SGET_CHAR, "", Int, )
2320OP_END
2321
2322/* File: c/OP_SGET_SHORT.c */
2323HANDLE_SGET_X(OP_SGET_SHORT, "", Int, )
2324OP_END
2325
2326/* File: c/OP_SPUT.c */
2327HANDLE_SPUT_X(OP_SPUT, "", Int, )
2328OP_END
2329
2330/* File: c/OP_SPUT_WIDE.c */
2331HANDLE_SPUT_X(OP_SPUT_WIDE, "-wide", Long, _WIDE)
2332OP_END
2333
2334/* File: c/OP_SPUT_OBJECT.c */
2335HANDLE_SPUT_X(OP_SPUT_OBJECT, "-object", Object, _AS_OBJECT)
2336OP_END
2337
2338/* File: c/OP_SPUT_BOOLEAN.c */
2339HANDLE_SPUT_X(OP_SPUT_BOOLEAN, "", Int, )
2340OP_END
2341
2342/* File: c/OP_SPUT_BYTE.c */
2343HANDLE_SPUT_X(OP_SPUT_BYTE, "", Int, )
2344OP_END
2345
2346/* File: c/OP_SPUT_CHAR.c */
2347HANDLE_SPUT_X(OP_SPUT_CHAR, "", Int, )
2348OP_END
2349
2350/* File: c/OP_SPUT_SHORT.c */
2351HANDLE_SPUT_X(OP_SPUT_SHORT, "", Int, )
2352OP_END
2353
2354/* File: c/OP_INVOKE_VIRTUAL.c */
2355HANDLE_OPCODE(OP_INVOKE_VIRTUAL /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2356 GOTO_invoke(invokeVirtual, false);
2357OP_END
2358
2359/* File: c/OP_INVOKE_SUPER.c */
2360HANDLE_OPCODE(OP_INVOKE_SUPER /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2361 GOTO_invoke(invokeSuper, false);
2362OP_END
2363
2364/* File: c/OP_INVOKE_DIRECT.c */
2365HANDLE_OPCODE(OP_INVOKE_DIRECT /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2366 GOTO_invoke(invokeDirect, false);
2367OP_END
2368
2369/* File: c/OP_INVOKE_STATIC.c */
2370HANDLE_OPCODE(OP_INVOKE_STATIC /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2371 GOTO_invoke(invokeStatic, false);
2372OP_END
2373
2374/* File: c/OP_INVOKE_INTERFACE.c */
2375HANDLE_OPCODE(OP_INVOKE_INTERFACE /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2376 GOTO_invoke(invokeInterface, false);
2377OP_END
2378
2379/* File: c/OP_UNUSED_73.c */
2380HANDLE_OPCODE(OP_UNUSED_73)
2381OP_END
2382
2383/* File: c/OP_INVOKE_VIRTUAL_RANGE.c */
2384HANDLE_OPCODE(OP_INVOKE_VIRTUAL_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2385 GOTO_invoke(invokeVirtual, true);
2386OP_END
2387
2388/* File: c/OP_INVOKE_SUPER_RANGE.c */
2389HANDLE_OPCODE(OP_INVOKE_SUPER_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2390 GOTO_invoke(invokeSuper, true);
2391OP_END
2392
2393/* File: c/OP_INVOKE_DIRECT_RANGE.c */
2394HANDLE_OPCODE(OP_INVOKE_DIRECT_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2395 GOTO_invoke(invokeDirect, true);
2396OP_END
2397
2398/* File: c/OP_INVOKE_STATIC_RANGE.c */
2399HANDLE_OPCODE(OP_INVOKE_STATIC_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2400 GOTO_invoke(invokeStatic, true);
2401OP_END
2402
2403/* File: c/OP_INVOKE_INTERFACE_RANGE.c */
2404HANDLE_OPCODE(OP_INVOKE_INTERFACE_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2405 GOTO_invoke(invokeInterface, true);
2406OP_END
2407
2408/* File: c/OP_UNUSED_79.c */
2409HANDLE_OPCODE(OP_UNUSED_79)
2410OP_END
2411
2412/* File: c/OP_UNUSED_7A.c */
2413HANDLE_OPCODE(OP_UNUSED_7A)
2414OP_END
2415
2416/* File: c/OP_NEG_INT.c */
2417HANDLE_UNOP(OP_NEG_INT, "neg-int", -, , )
2418OP_END
2419
2420/* File: c/OP_NOT_INT.c */
2421HANDLE_UNOP(OP_NOT_INT, "not-int", , ^ 0xffffffff, )
2422OP_END
2423
2424/* File: c/OP_NEG_LONG.c */
2425HANDLE_UNOP(OP_NEG_LONG, "neg-long", -, , _WIDE)
2426OP_END
2427
2428/* File: c/OP_NOT_LONG.c */
2429HANDLE_UNOP(OP_NOT_LONG, "not-long", , ^ 0xffffffffffffffffULL, _WIDE)
2430OP_END
2431
2432/* File: c/OP_NEG_FLOAT.c */
2433HANDLE_UNOP(OP_NEG_FLOAT, "neg-float", -, , _FLOAT)
2434OP_END
2435
2436/* File: c/OP_NEG_DOUBLE.c */
2437HANDLE_UNOP(OP_NEG_DOUBLE, "neg-double", -, , _DOUBLE)
2438OP_END
2439
2440/* File: c/OP_INT_TO_LONG.c */
2441HANDLE_NUMCONV(OP_INT_TO_LONG, "int-to-long", _INT, _WIDE)
2442OP_END
2443
2444/* File: c/OP_INT_TO_FLOAT.c */
2445HANDLE_NUMCONV(OP_INT_TO_FLOAT, "int-to-float", _INT, _FLOAT)
2446OP_END
2447
2448/* File: c/OP_INT_TO_DOUBLE.c */
2449HANDLE_NUMCONV(OP_INT_TO_DOUBLE, "int-to-double", _INT, _DOUBLE)
2450OP_END
2451
2452/* File: c/OP_LONG_TO_INT.c */
2453HANDLE_NUMCONV(OP_LONG_TO_INT, "long-to-int", _WIDE, _INT)
2454OP_END
2455
2456/* File: c/OP_LONG_TO_FLOAT.c */
2457HANDLE_NUMCONV(OP_LONG_TO_FLOAT, "long-to-float", _WIDE, _FLOAT)
2458OP_END
2459
2460/* File: c/OP_LONG_TO_DOUBLE.c */
2461HANDLE_NUMCONV(OP_LONG_TO_DOUBLE, "long-to-double", _WIDE, _DOUBLE)
2462OP_END
2463
2464/* File: c/OP_FLOAT_TO_INT.c */
2465HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_INT, "float-to-int",
2466 float, _FLOAT, s4, _INT)
2467OP_END
2468
2469/* File: c/OP_FLOAT_TO_LONG.c */
2470HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_LONG, "float-to-long",
2471 float, _FLOAT, s8, _WIDE)
2472OP_END
2473
2474/* File: c/OP_FLOAT_TO_DOUBLE.c */
2475HANDLE_NUMCONV(OP_FLOAT_TO_DOUBLE, "float-to-double", _FLOAT, _DOUBLE)
2476OP_END
2477
2478/* File: c/OP_DOUBLE_TO_INT.c */
2479HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_INT, "double-to-int",
2480 double, _DOUBLE, s4, _INT)
2481OP_END
2482
2483/* File: c/OP_DOUBLE_TO_LONG.c */
2484HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_LONG, "double-to-long",
2485 double, _DOUBLE, s8, _WIDE)
2486OP_END
2487
2488/* File: c/OP_DOUBLE_TO_FLOAT.c */
2489HANDLE_NUMCONV(OP_DOUBLE_TO_FLOAT, "double-to-float", _DOUBLE, _FLOAT)
2490OP_END
2491
2492/* File: c/OP_INT_TO_BYTE.c */
2493HANDLE_INT_TO_SMALL(OP_INT_TO_BYTE, "byte", s1)
2494OP_END
2495
2496/* File: c/OP_INT_TO_CHAR.c */
2497HANDLE_INT_TO_SMALL(OP_INT_TO_CHAR, "char", u2)
2498OP_END
2499
2500/* File: c/OP_INT_TO_SHORT.c */
2501HANDLE_INT_TO_SMALL(OP_INT_TO_SHORT, "short", s2) /* want sign bit */
2502OP_END
2503
2504/* File: c/OP_ADD_INT.c */
2505HANDLE_OP_X_INT(OP_ADD_INT, "add", +, 0)
2506OP_END
2507
2508/* File: c/OP_SUB_INT.c */
2509HANDLE_OP_X_INT(OP_SUB_INT, "sub", -, 0)
2510OP_END
2511
2512/* File: c/OP_MUL_INT.c */
2513HANDLE_OP_X_INT(OP_MUL_INT, "mul", *, 0)
2514OP_END
2515
2516/* File: c/OP_DIV_INT.c */
2517HANDLE_OP_X_INT(OP_DIV_INT, "div", /, 1)
2518OP_END
2519
2520/* File: c/OP_REM_INT.c */
2521HANDLE_OP_X_INT(OP_REM_INT, "rem", %, 2)
2522OP_END
2523
2524/* File: c/OP_AND_INT.c */
2525HANDLE_OP_X_INT(OP_AND_INT, "and", &, 0)
2526OP_END
2527
2528/* File: c/OP_OR_INT.c */
2529HANDLE_OP_X_INT(OP_OR_INT, "or", |, 0)
2530OP_END
2531
2532/* File: c/OP_XOR_INT.c */
2533HANDLE_OP_X_INT(OP_XOR_INT, "xor", ^, 0)
2534OP_END
2535
2536/* File: c/OP_SHL_INT.c */
2537HANDLE_OP_SHX_INT(OP_SHL_INT, "shl", (s4), <<)
2538OP_END
2539
2540/* File: c/OP_SHR_INT.c */
2541HANDLE_OP_SHX_INT(OP_SHR_INT, "shr", (s4), >>)
2542OP_END
2543
2544/* File: c/OP_USHR_INT.c */
2545HANDLE_OP_SHX_INT(OP_USHR_INT, "ushr", (u4), >>)
2546OP_END
2547
2548/* File: c/OP_ADD_LONG.c */
2549HANDLE_OP_X_LONG(OP_ADD_LONG, "add", +, 0)
2550OP_END
2551
2552/* File: c/OP_SUB_LONG.c */
2553HANDLE_OP_X_LONG(OP_SUB_LONG, "sub", -, 0)
2554OP_END
2555
2556/* File: c/OP_MUL_LONG.c */
2557HANDLE_OP_X_LONG(OP_MUL_LONG, "mul", *, 0)
2558OP_END
2559
2560/* File: c/OP_DIV_LONG.c */
2561HANDLE_OP_X_LONG(OP_DIV_LONG, "div", /, 1)
2562OP_END
2563
2564/* File: c/OP_REM_LONG.c */
2565HANDLE_OP_X_LONG(OP_REM_LONG, "rem", %, 2)
2566OP_END
2567
2568/* File: c/OP_AND_LONG.c */
2569HANDLE_OP_X_LONG(OP_AND_LONG, "and", &, 0)
2570OP_END
2571
2572/* File: c/OP_OR_LONG.c */
2573HANDLE_OP_X_LONG(OP_OR_LONG, "or", |, 0)
2574OP_END
2575
2576/* File: c/OP_XOR_LONG.c */
2577HANDLE_OP_X_LONG(OP_XOR_LONG, "xor", ^, 0)
2578OP_END
2579
2580/* File: c/OP_SHL_LONG.c */
2581HANDLE_OP_SHX_LONG(OP_SHL_LONG, "shl", (s8), <<)
2582OP_END
2583
2584/* File: c/OP_SHR_LONG.c */
2585HANDLE_OP_SHX_LONG(OP_SHR_LONG, "shr", (s8), >>)
2586OP_END
2587
2588/* File: c/OP_USHR_LONG.c */
2589HANDLE_OP_SHX_LONG(OP_USHR_LONG, "ushr", (u8), >>)
2590OP_END
2591
2592/* File: c/OP_ADD_FLOAT.c */
2593HANDLE_OP_X_FLOAT(OP_ADD_FLOAT, "add", +)
2594OP_END
2595
2596/* File: c/OP_SUB_FLOAT.c */
2597HANDLE_OP_X_FLOAT(OP_SUB_FLOAT, "sub", -)
2598OP_END
2599
2600/* File: c/OP_MUL_FLOAT.c */
2601HANDLE_OP_X_FLOAT(OP_MUL_FLOAT, "mul", *)
2602OP_END
2603
2604/* File: c/OP_DIV_FLOAT.c */
2605HANDLE_OP_X_FLOAT(OP_DIV_FLOAT, "div", /)
2606OP_END
2607
2608/* File: c/OP_REM_FLOAT.c */
2609HANDLE_OPCODE(OP_REM_FLOAT /*vAA, vBB, vCC*/)
2610 {
2611 u2 srcRegs;
2612 vdst = INST_AA(inst);
2613 srcRegs = FETCH(1);
2614 vsrc1 = srcRegs & 0xff;
2615 vsrc2 = srcRegs >> 8;
2616 ILOGV("|%s-float v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2617 SET_REGISTER_FLOAT(vdst,
2618 fmodf(GET_REGISTER_FLOAT(vsrc1), GET_REGISTER_FLOAT(vsrc2)));
2619 }
2620 FINISH(2);
2621OP_END
2622
2623/* File: c/OP_ADD_DOUBLE.c */
2624HANDLE_OP_X_DOUBLE(OP_ADD_DOUBLE, "add", +)
2625OP_END
2626
2627/* File: c/OP_SUB_DOUBLE.c */
2628HANDLE_OP_X_DOUBLE(OP_SUB_DOUBLE, "sub", -)
2629OP_END
2630
2631/* File: c/OP_MUL_DOUBLE.c */
2632HANDLE_OP_X_DOUBLE(OP_MUL_DOUBLE, "mul", *)
2633OP_END
2634
2635/* File: c/OP_DIV_DOUBLE.c */
2636HANDLE_OP_X_DOUBLE(OP_DIV_DOUBLE, "div", /)
2637OP_END
2638
2639/* File: c/OP_REM_DOUBLE.c */
2640HANDLE_OPCODE(OP_REM_DOUBLE /*vAA, vBB, vCC*/)
2641 {
2642 u2 srcRegs;
2643 vdst = INST_AA(inst);
2644 srcRegs = FETCH(1);
2645 vsrc1 = srcRegs & 0xff;
2646 vsrc2 = srcRegs >> 8;
2647 ILOGV("|%s-double v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2648 SET_REGISTER_DOUBLE(vdst,
2649 fmod(GET_REGISTER_DOUBLE(vsrc1), GET_REGISTER_DOUBLE(vsrc2)));
2650 }
2651 FINISH(2);
2652OP_END
2653
2654/* File: c/OP_ADD_INT_2ADDR.c */
2655HANDLE_OP_X_INT_2ADDR(OP_ADD_INT_2ADDR, "add", +, 0)
2656OP_END
2657
2658/* File: c/OP_SUB_INT_2ADDR.c */
2659HANDLE_OP_X_INT_2ADDR(OP_SUB_INT_2ADDR, "sub", -, 0)
2660OP_END
2661
2662/* File: c/OP_MUL_INT_2ADDR.c */
2663HANDLE_OP_X_INT_2ADDR(OP_MUL_INT_2ADDR, "mul", *, 0)
2664OP_END
2665
2666/* File: c/OP_DIV_INT_2ADDR.c */
2667HANDLE_OP_X_INT_2ADDR(OP_DIV_INT_2ADDR, "div", /, 1)
2668OP_END
2669
2670/* File: c/OP_REM_INT_2ADDR.c */
2671HANDLE_OP_X_INT_2ADDR(OP_REM_INT_2ADDR, "rem", %, 2)
2672OP_END
2673
2674/* File: c/OP_AND_INT_2ADDR.c */
2675HANDLE_OP_X_INT_2ADDR(OP_AND_INT_2ADDR, "and", &, 0)
2676OP_END
2677
2678/* File: c/OP_OR_INT_2ADDR.c */
2679HANDLE_OP_X_INT_2ADDR(OP_OR_INT_2ADDR, "or", |, 0)
2680OP_END
2681
2682/* File: c/OP_XOR_INT_2ADDR.c */
2683HANDLE_OP_X_INT_2ADDR(OP_XOR_INT_2ADDR, "xor", ^, 0)
2684OP_END
2685
2686/* File: c/OP_SHL_INT_2ADDR.c */
2687HANDLE_OP_SHX_INT_2ADDR(OP_SHL_INT_2ADDR, "shl", (s4), <<)
2688OP_END
2689
2690/* File: c/OP_SHR_INT_2ADDR.c */
2691HANDLE_OP_SHX_INT_2ADDR(OP_SHR_INT_2ADDR, "shr", (s4), >>)
2692OP_END
2693
2694/* File: c/OP_USHR_INT_2ADDR.c */
2695HANDLE_OP_SHX_INT_2ADDR(OP_USHR_INT_2ADDR, "ushr", (u4), >>)
2696OP_END
2697
2698/* File: c/OP_ADD_LONG_2ADDR.c */
2699HANDLE_OP_X_LONG_2ADDR(OP_ADD_LONG_2ADDR, "add", +, 0)
2700OP_END
2701
2702/* File: c/OP_SUB_LONG_2ADDR.c */
2703HANDLE_OP_X_LONG_2ADDR(OP_SUB_LONG_2ADDR, "sub", -, 0)
2704OP_END
2705
2706/* File: c/OP_MUL_LONG_2ADDR.c */
2707HANDLE_OP_X_LONG_2ADDR(OP_MUL_LONG_2ADDR, "mul", *, 0)
2708OP_END
2709
2710/* File: c/OP_DIV_LONG_2ADDR.c */
2711HANDLE_OP_X_LONG_2ADDR(OP_DIV_LONG_2ADDR, "div", /, 1)
2712OP_END
2713
2714/* File: c/OP_REM_LONG_2ADDR.c */
2715HANDLE_OP_X_LONG_2ADDR(OP_REM_LONG_2ADDR, "rem", %, 2)
2716OP_END
2717
2718/* File: c/OP_AND_LONG_2ADDR.c */
2719HANDLE_OP_X_LONG_2ADDR(OP_AND_LONG_2ADDR, "and", &, 0)
2720OP_END
2721
2722/* File: c/OP_OR_LONG_2ADDR.c */
2723HANDLE_OP_X_LONG_2ADDR(OP_OR_LONG_2ADDR, "or", |, 0)
2724OP_END
2725
2726/* File: c/OP_XOR_LONG_2ADDR.c */
2727HANDLE_OP_X_LONG_2ADDR(OP_XOR_LONG_2ADDR, "xor", ^, 0)
2728OP_END
2729
2730/* File: c/OP_SHL_LONG_2ADDR.c */
2731HANDLE_OP_SHX_LONG_2ADDR(OP_SHL_LONG_2ADDR, "shl", (s8), <<)
2732OP_END
2733
2734/* File: c/OP_SHR_LONG_2ADDR.c */
2735HANDLE_OP_SHX_LONG_2ADDR(OP_SHR_LONG_2ADDR, "shr", (s8), >>)
2736OP_END
2737
2738/* File: c/OP_USHR_LONG_2ADDR.c */
2739HANDLE_OP_SHX_LONG_2ADDR(OP_USHR_LONG_2ADDR, "ushr", (u8), >>)
2740OP_END
2741
2742/* File: c/OP_ADD_FLOAT_2ADDR.c */
2743HANDLE_OP_X_FLOAT_2ADDR(OP_ADD_FLOAT_2ADDR, "add", +)
2744OP_END
2745
2746/* File: c/OP_SUB_FLOAT_2ADDR.c */
2747HANDLE_OP_X_FLOAT_2ADDR(OP_SUB_FLOAT_2ADDR, "sub", -)
2748OP_END
2749
2750/* File: c/OP_MUL_FLOAT_2ADDR.c */
2751HANDLE_OP_X_FLOAT_2ADDR(OP_MUL_FLOAT_2ADDR, "mul", *)
2752OP_END
2753
2754/* File: c/OP_DIV_FLOAT_2ADDR.c */
2755HANDLE_OP_X_FLOAT_2ADDR(OP_DIV_FLOAT_2ADDR, "div", /)
2756OP_END
2757
2758/* File: c/OP_REM_FLOAT_2ADDR.c */
2759HANDLE_OPCODE(OP_REM_FLOAT_2ADDR /*vA, vB*/)
2760 vdst = INST_A(inst);
2761 vsrc1 = INST_B(inst);
2762 ILOGV("|%s-float-2addr v%d,v%d", "mod", vdst, vsrc1);
2763 SET_REGISTER_FLOAT(vdst,
2764 fmodf(GET_REGISTER_FLOAT(vdst), GET_REGISTER_FLOAT(vsrc1)));
2765 FINISH(1);
2766OP_END
2767
2768/* File: c/OP_ADD_DOUBLE_2ADDR.c */
2769HANDLE_OP_X_DOUBLE_2ADDR(OP_ADD_DOUBLE_2ADDR, "add", +)
2770OP_END
2771
2772/* File: c/OP_SUB_DOUBLE_2ADDR.c */
2773HANDLE_OP_X_DOUBLE_2ADDR(OP_SUB_DOUBLE_2ADDR, "sub", -)
2774OP_END
2775
2776/* File: c/OP_MUL_DOUBLE_2ADDR.c */
2777HANDLE_OP_X_DOUBLE_2ADDR(OP_MUL_DOUBLE_2ADDR, "mul", *)
2778OP_END
2779
2780/* File: c/OP_DIV_DOUBLE_2ADDR.c */
2781HANDLE_OP_X_DOUBLE_2ADDR(OP_DIV_DOUBLE_2ADDR, "div", /)
2782OP_END
2783
2784/* File: c/OP_REM_DOUBLE_2ADDR.c */
2785HANDLE_OPCODE(OP_REM_DOUBLE_2ADDR /*vA, vB*/)
2786 vdst = INST_A(inst);
2787 vsrc1 = INST_B(inst);
2788 ILOGV("|%s-double-2addr v%d,v%d", "mod", vdst, vsrc1);
2789 SET_REGISTER_DOUBLE(vdst,
2790 fmod(GET_REGISTER_DOUBLE(vdst), GET_REGISTER_DOUBLE(vsrc1)));
2791 FINISH(1);
2792OP_END
2793
2794/* File: c/OP_ADD_INT_LIT16.c */
2795HANDLE_OP_X_INT_LIT16(OP_ADD_INT_LIT16, "add", +, 0)
2796OP_END
2797
2798/* File: c/OP_RSUB_INT.c */
2799HANDLE_OPCODE(OP_RSUB_INT /*vA, vB, #+CCCC*/)
2800 {
2801 vdst = INST_A(inst);
2802 vsrc1 = INST_B(inst);
2803 vsrc2 = FETCH(1);
2804 ILOGV("|rsub-int v%d,v%d,#+0x%04x", vdst, vsrc1, vsrc2);
2805 SET_REGISTER(vdst, (s2) vsrc2 - (s4) GET_REGISTER(vsrc1));
2806 }
2807 FINISH(2);
2808OP_END
2809
2810/* File: c/OP_MUL_INT_LIT16.c */
2811HANDLE_OP_X_INT_LIT16(OP_MUL_INT_LIT16, "mul", *, 0)
2812OP_END
2813
2814/* File: c/OP_DIV_INT_LIT16.c */
2815HANDLE_OP_X_INT_LIT16(OP_DIV_INT_LIT16, "div", /, 1)
2816OP_END
2817
2818/* File: c/OP_REM_INT_LIT16.c */
2819HANDLE_OP_X_INT_LIT16(OP_REM_INT_LIT16, "rem", %, 2)
2820OP_END
2821
2822/* File: c/OP_AND_INT_LIT16.c */
2823HANDLE_OP_X_INT_LIT16(OP_AND_INT_LIT16, "and", &, 0)
2824OP_END
2825
2826/* File: c/OP_OR_INT_LIT16.c */
2827HANDLE_OP_X_INT_LIT16(OP_OR_INT_LIT16, "or", |, 0)
2828OP_END
2829
2830/* File: c/OP_XOR_INT_LIT16.c */
2831HANDLE_OP_X_INT_LIT16(OP_XOR_INT_LIT16, "xor", ^, 0)
2832OP_END
2833
2834/* File: c/OP_ADD_INT_LIT8.c */
2835HANDLE_OP_X_INT_LIT8(OP_ADD_INT_LIT8, "add", +, 0)
2836OP_END
2837
2838/* File: c/OP_RSUB_INT_LIT8.c */
2839HANDLE_OPCODE(OP_RSUB_INT_LIT8 /*vAA, vBB, #+CC*/)
2840 {
2841 u2 litInfo;
2842 vdst = INST_AA(inst);
2843 litInfo = FETCH(1);
2844 vsrc1 = litInfo & 0xff;
2845 vsrc2 = litInfo >> 8;
2846 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", "rsub", vdst, vsrc1, vsrc2);
2847 SET_REGISTER(vdst, (s1) vsrc2 - (s4) GET_REGISTER(vsrc1));
2848 }
2849 FINISH(2);
2850OP_END
2851
2852/* File: c/OP_MUL_INT_LIT8.c */
2853HANDLE_OP_X_INT_LIT8(OP_MUL_INT_LIT8, "mul", *, 0)
2854OP_END
2855
2856/* File: c/OP_DIV_INT_LIT8.c */
2857HANDLE_OP_X_INT_LIT8(OP_DIV_INT_LIT8, "div", /, 1)
2858OP_END
2859
2860/* File: c/OP_REM_INT_LIT8.c */
2861HANDLE_OP_X_INT_LIT8(OP_REM_INT_LIT8, "rem", %, 2)
2862OP_END
2863
2864/* File: c/OP_AND_INT_LIT8.c */
2865HANDLE_OP_X_INT_LIT8(OP_AND_INT_LIT8, "and", &, 0)
2866OP_END
2867
2868/* File: c/OP_OR_INT_LIT8.c */
2869HANDLE_OP_X_INT_LIT8(OP_OR_INT_LIT8, "or", |, 0)
2870OP_END
2871
2872/* File: c/OP_XOR_INT_LIT8.c */
2873HANDLE_OP_X_INT_LIT8(OP_XOR_INT_LIT8, "xor", ^, 0)
2874OP_END
2875
2876/* File: c/OP_SHL_INT_LIT8.c */
2877HANDLE_OP_SHX_INT_LIT8(OP_SHL_INT_LIT8, "shl", (s4), <<)
2878OP_END
2879
2880/* File: c/OP_SHR_INT_LIT8.c */
2881HANDLE_OP_SHX_INT_LIT8(OP_SHR_INT_LIT8, "shr", (s4), >>)
2882OP_END
2883
2884/* File: c/OP_USHR_INT_LIT8.c */
2885HANDLE_OP_SHX_INT_LIT8(OP_USHR_INT_LIT8, "ushr", (u4), >>)
2886OP_END
2887
2888/* File: c/OP_UNUSED_E3.c */
2889HANDLE_OPCODE(OP_UNUSED_E3)
2890OP_END
2891
2892/* File: c/OP_UNUSED_E4.c */
2893HANDLE_OPCODE(OP_UNUSED_E4)
2894OP_END
2895
2896/* File: c/OP_UNUSED_E5.c */
2897HANDLE_OPCODE(OP_UNUSED_E5)
2898OP_END
2899
2900/* File: c/OP_UNUSED_E6.c */
2901HANDLE_OPCODE(OP_UNUSED_E6)
2902OP_END
2903
2904/* File: c/OP_UNUSED_E7.c */
2905HANDLE_OPCODE(OP_UNUSED_E7)
2906OP_END
2907
Andy McFadden53878242010-03-05 07:24:27 -08002908/* File: c/OP_IGET_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002909HANDLE_IGET_X(OP_IGET_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002910OP_END
2911
Andy McFadden53878242010-03-05 07:24:27 -08002912/* File: c/OP_IPUT_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002913HANDLE_IPUT_X(OP_IPUT_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002914OP_END
2915
Andy McFadden53878242010-03-05 07:24:27 -08002916/* File: c/OP_SGET_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002917HANDLE_SGET_X(OP_SGET_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002918OP_END
2919
Andy McFadden53878242010-03-05 07:24:27 -08002920/* File: c/OP_SPUT_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002921HANDLE_SPUT_X(OP_SPUT_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002922OP_END
2923
Andy McFadden96516932009-10-28 17:39:02 -07002924/* File: c/OP_BREAKPOINT.c */
2925HANDLE_OPCODE(OP_BREAKPOINT)
2926#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
2927 {
2928 /*
2929 * Restart this instruction with the original opcode. We do
2930 * this by simply jumping to the handler.
2931 *
2932 * It's probably not necessary to update "inst", but we do it
2933 * for the sake of anything that needs to do disambiguation in a
2934 * common handler with INST_INST.
2935 *
2936 * The breakpoint itself is handled over in updateDebugger(),
2937 * because we need to detect other events (method entry, single
2938 * step) and report them in the same event packet, and we're not
2939 * yet handling those through breakpoint instructions. By the
2940 * time we get here, the breakpoint has already been handled and
2941 * the thread resumed.
2942 */
2943 u1 originalOpCode = dvmGetOriginalOpCode(pc);
2944 LOGV("+++ break 0x%02x (0x%04x -> 0x%04x)\n", originalOpCode, inst,
2945 INST_REPLACE_OP(inst, originalOpCode));
2946 inst = INST_REPLACE_OP(inst, originalOpCode);
2947 FINISH_BKPT(originalOpCode);
2948 }
2949#else
2950 LOGE("Breakpoint hit in non-debug interpreter\n");
2951 dvmAbort();
2952#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002953OP_END
2954
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002955/* File: c/OP_THROW_VERIFICATION_ERROR.c */
2956HANDLE_OPCODE(OP_THROW_VERIFICATION_ERROR)
Andy McFaddenb51ea112009-05-08 16:50:17 -07002957 EXPORT_PC();
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002958 vsrc1 = INST_AA(inst);
2959 ref = FETCH(1); /* class/field/method ref */
Andy McFaddenb51ea112009-05-08 16:50:17 -07002960 dvmThrowVerificationError(curMethod, vsrc1, ref);
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002961 GOTO_exceptionThrown();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002962OP_END
2963
2964/* File: c/OP_EXECUTE_INLINE.c */
2965HANDLE_OPCODE(OP_EXECUTE_INLINE /*vB, {vD, vE, vF, vG}, inline@CCCC*/)
2966 {
2967 /*
2968 * This has the same form as other method calls, but we ignore
2969 * the 5th argument (vA). This is chiefly because the first four
2970 * arguments to a function on ARM are in registers.
2971 *
2972 * We only set the arguments that are actually used, leaving
2973 * the rest uninitialized. We're assuming that, if the method
2974 * needs them, they'll be specified in the call.
2975 *
Carl Shapiro7bbb9ce2009-12-21 18:34:11 -08002976 * However, this annoys gcc when optimizations are enabled,
2977 * causing a "may be used uninitialized" warning. Quieting
2978 * the warnings incurs a slight penalty (5%: 373ns vs. 393ns
2979 * on empty method). Note that valgrind is perfectly happy
2980 * either way as the uninitialiezd values are never actually
2981 * used.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002982 */
2983 u4 arg0, arg1, arg2, arg3;
Carl Shapiro7bbb9ce2009-12-21 18:34:11 -08002984 arg0 = arg1 = arg2 = arg3 = 0;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002985
2986 EXPORT_PC();
2987
2988 vsrc1 = INST_B(inst); /* #of args */
2989 ref = FETCH(1); /* inline call "ref" */
2990 vdst = FETCH(2); /* 0-4 register indices */
2991 ILOGV("|execute-inline args=%d @%d {regs=0x%04x}",
2992 vsrc1, ref, vdst);
2993
2994 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
2995 assert(vsrc1 <= 4);
2996
2997 switch (vsrc1) {
2998 case 4:
2999 arg3 = GET_REGISTER(vdst >> 12);
3000 /* fall through */
3001 case 3:
3002 arg2 = GET_REGISTER((vdst & 0x0f00) >> 8);
3003 /* fall through */
3004 case 2:
3005 arg1 = GET_REGISTER((vdst & 0x00f0) >> 4);
3006 /* fall through */
3007 case 1:
3008 arg0 = GET_REGISTER(vdst & 0x0f);
3009 /* fall through */
3010 default: // case 0
3011 ;
3012 }
3013
3014#if INTERP_TYPE == INTERP_DBG
3015 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
3016 GOTO_exceptionThrown();
3017#else
3018 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
3019 GOTO_exceptionThrown();
3020#endif
3021 }
3022 FINISH(3);
3023OP_END
3024
Andy McFaddenb0a05412009-11-19 10:23:41 -08003025/* File: c/OP_EXECUTE_INLINE_RANGE.c */
3026HANDLE_OPCODE(OP_EXECUTE_INLINE_RANGE /*{vCCCC..v(CCCC+AA-1)}, inline@BBBB*/)
3027 {
3028 u4 arg0, arg1, arg2, arg3;
3029 arg0 = arg1 = arg2 = arg3 = 0; /* placate gcc */
3030
3031 EXPORT_PC();
3032
3033 vsrc1 = INST_AA(inst); /* #of args */
3034 ref = FETCH(1); /* inline call "ref" */
3035 vdst = FETCH(2); /* range base */
3036 ILOGV("|execute-inline-range args=%d @%d {regs=v%d-v%d}",
3037 vsrc1, ref, vdst, vdst+vsrc1-1);
3038
3039 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
3040 assert(vsrc1 <= 4);
3041
3042 switch (vsrc1) {
3043 case 4:
3044 arg3 = GET_REGISTER(vdst+3);
3045 /* fall through */
3046 case 3:
3047 arg2 = GET_REGISTER(vdst+2);
3048 /* fall through */
3049 case 2:
3050 arg1 = GET_REGISTER(vdst+1);
3051 /* fall through */
3052 case 1:
3053 arg0 = GET_REGISTER(vdst+0);
3054 /* fall through */
3055 default: // case 0
3056 ;
3057 }
3058
3059#if INTERP_TYPE == INTERP_DBG
3060 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
3061 GOTO_exceptionThrown();
3062#else
3063 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
3064 GOTO_exceptionThrown();
3065#endif
3066 }
3067 FINISH(3);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003068OP_END
3069
3070/* File: c/OP_INVOKE_DIRECT_EMPTY.c */
3071HANDLE_OPCODE(OP_INVOKE_DIRECT_EMPTY /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3072#if INTERP_TYPE != INTERP_DBG
3073 //LOGI("Ignoring empty\n");
3074 FINISH(3);
3075#else
3076 if (!gDvm.debuggerActive) {
3077 //LOGI("Skipping empty\n");
3078 FINISH(3); // don't want it to show up in profiler output
3079 } else {
3080 //LOGI("Running empty\n");
3081 /* fall through to OP_INVOKE_DIRECT */
3082 GOTO_invoke(invokeDirect, false);
3083 }
3084#endif
3085OP_END
3086
3087/* File: c/OP_UNUSED_F1.c */
3088HANDLE_OPCODE(OP_UNUSED_F1)
3089OP_END
3090
3091/* File: c/OP_IGET_QUICK.c */
3092HANDLE_IGET_X_QUICK(OP_IGET_QUICK, "", Int, )
3093OP_END
3094
3095/* File: c/OP_IGET_WIDE_QUICK.c */
3096HANDLE_IGET_X_QUICK(OP_IGET_WIDE_QUICK, "-wide", Long, _WIDE)
3097OP_END
3098
3099/* File: c/OP_IGET_OBJECT_QUICK.c */
3100HANDLE_IGET_X_QUICK(OP_IGET_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
3101OP_END
3102
3103/* File: c/OP_IPUT_QUICK.c */
3104HANDLE_IPUT_X_QUICK(OP_IPUT_QUICK, "", Int, )
3105OP_END
3106
3107/* File: c/OP_IPUT_WIDE_QUICK.c */
3108HANDLE_IPUT_X_QUICK(OP_IPUT_WIDE_QUICK, "-wide", Long, _WIDE)
3109OP_END
3110
3111/* File: c/OP_IPUT_OBJECT_QUICK.c */
3112HANDLE_IPUT_X_QUICK(OP_IPUT_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
3113OP_END
3114
3115/* File: c/OP_INVOKE_VIRTUAL_QUICK.c */
3116HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3117 GOTO_invoke(invokeVirtualQuick, false);
3118OP_END
3119
3120/* File: c/OP_INVOKE_VIRTUAL_QUICK_RANGE.c */
3121HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK_RANGE/*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
3122 GOTO_invoke(invokeVirtualQuick, true);
3123OP_END
3124
3125/* File: c/OP_INVOKE_SUPER_QUICK.c */
3126HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3127 GOTO_invoke(invokeSuperQuick, false);
3128OP_END
3129
3130/* File: c/OP_INVOKE_SUPER_QUICK_RANGE.c */
3131HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
3132 GOTO_invoke(invokeSuperQuick, true);
3133OP_END
3134
3135/* File: c/OP_UNUSED_FC.c */
3136HANDLE_OPCODE(OP_UNUSED_FC)
3137OP_END
3138
3139/* File: c/OP_UNUSED_FD.c */
3140HANDLE_OPCODE(OP_UNUSED_FD)
3141OP_END
3142
3143/* File: c/OP_UNUSED_FE.c */
3144HANDLE_OPCODE(OP_UNUSED_FE)
3145OP_END
3146
3147/* File: c/OP_UNUSED_FF.c */
3148HANDLE_OPCODE(OP_UNUSED_FF)
3149 /*
3150 * In portable interp, most unused opcodes will fall through to here.
3151 */
3152 LOGE("unknown opcode 0x%02x\n", INST_INST(inst));
3153 dvmAbort();
3154 FINISH(1);
3155OP_END
3156
3157/* File: c/gotoTargets.c */
3158/*
3159 * C footer. This has some common code shared by the various targets.
3160 */
3161
3162/*
3163 * Everything from here on is a "goto target". In the basic interpreter
3164 * we jump into these targets and then jump directly to the handler for
3165 * next instruction. Here, these are subroutines that return to the caller.
3166 */
3167
3168GOTO_TARGET(filledNewArray, bool methodCallRange)
3169 {
3170 ClassObject* arrayClass;
3171 ArrayObject* newArray;
3172 u4* contents;
3173 char typeCh;
3174 int i;
3175 u4 arg5;
3176
3177 EXPORT_PC();
3178
3179 ref = FETCH(1); /* class ref */
3180 vdst = FETCH(2); /* first 4 regs -or- range base */
3181
3182 if (methodCallRange) {
3183 vsrc1 = INST_AA(inst); /* #of elements */
3184 arg5 = -1; /* silence compiler warning */
3185 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
3186 vsrc1, ref, vdst, vdst+vsrc1-1);
3187 } else {
3188 arg5 = INST_A(inst);
3189 vsrc1 = INST_B(inst); /* #of elements */
3190 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
3191 vsrc1, ref, vdst, arg5);
3192 }
3193
3194 /*
3195 * Resolve the array class.
3196 */
3197 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
3198 if (arrayClass == NULL) {
3199 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
3200 if (arrayClass == NULL)
3201 GOTO_exceptionThrown();
3202 }
3203 /*
3204 if (!dvmIsArrayClass(arrayClass)) {
3205 dvmThrowException("Ljava/lang/RuntimeError;",
3206 "filled-new-array needs array class");
3207 GOTO_exceptionThrown();
3208 }
3209 */
3210 /* verifier guarantees this is an array class */
3211 assert(dvmIsArrayClass(arrayClass));
3212 assert(dvmIsClassInitialized(arrayClass));
3213
3214 /*
3215 * Create an array of the specified type.
3216 */
3217 LOGVV("+++ filled-new-array type is '%s'\n", arrayClass->descriptor);
3218 typeCh = arrayClass->descriptor[1];
3219 if (typeCh == 'D' || typeCh == 'J') {
3220 /* category 2 primitives not allowed */
3221 dvmThrowException("Ljava/lang/RuntimeError;",
3222 "bad filled array req");
3223 GOTO_exceptionThrown();
3224 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
3225 /* TODO: requires multiple "fill in" loops with different widths */
3226 LOGE("non-int primitives not implemented\n");
3227 dvmThrowException("Ljava/lang/InternalError;",
3228 "filled-new-array not implemented for anything but 'int'");
3229 GOTO_exceptionThrown();
3230 }
3231
3232 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
3233 if (newArray == NULL)
3234 GOTO_exceptionThrown();
3235
3236 /*
3237 * Fill in the elements. It's legal for vsrc1 to be zero.
3238 */
3239 contents = (u4*) newArray->contents;
3240 if (methodCallRange) {
3241 for (i = 0; i < vsrc1; i++)
3242 contents[i] = GET_REGISTER(vdst+i);
3243 } else {
3244 assert(vsrc1 <= 5);
3245 if (vsrc1 == 5) {
3246 contents[4] = GET_REGISTER(arg5);
3247 vsrc1--;
3248 }
3249 for (i = 0; i < vsrc1; i++) {
3250 contents[i] = GET_REGISTER(vdst & 0x0f);
3251 vdst >>= 4;
3252 }
3253 }
3254
3255 retval.l = newArray;
3256 }
3257 FINISH(3);
3258GOTO_TARGET_END
3259
3260
3261GOTO_TARGET(invokeVirtual, bool methodCallRange)
3262 {
3263 Method* baseMethod;
3264 Object* thisPtr;
3265
3266 EXPORT_PC();
3267
3268 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3269 ref = FETCH(1); /* method ref */
3270 vdst = FETCH(2); /* 4 regs -or- first reg */
3271
3272 /*
3273 * The object against which we are executing a method is always
3274 * in the first argument.
3275 */
3276 if (methodCallRange) {
3277 assert(vsrc1 > 0);
3278 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
3279 vsrc1, ref, vdst, vdst+vsrc1-1);
3280 thisPtr = (Object*) GET_REGISTER(vdst);
3281 } else {
3282 assert((vsrc1>>4) > 0);
3283 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
3284 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3285 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3286 }
3287
3288 if (!checkForNull(thisPtr))
3289 GOTO_exceptionThrown();
3290
3291 /*
3292 * Resolve the method. This is the correct method for the static
3293 * type of the object. We also verify access permissions here.
3294 */
3295 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3296 if (baseMethod == NULL) {
3297 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3298 if (baseMethod == NULL) {
3299 ILOGV("+ unknown method or access denied\n");
3300 GOTO_exceptionThrown();
3301 }
3302 }
3303
3304 /*
3305 * Combine the object we found with the vtable offset in the
3306 * method.
3307 */
3308 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
3309 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
3310
3311#if 0
3312 if (dvmIsAbstractMethod(methodToCall)) {
3313 /*
3314 * This can happen if you create two classes, Base and Sub, where
3315 * Sub is a sub-class of Base. Declare a protected abstract
3316 * method foo() in Base, and invoke foo() from a method in Base.
3317 * Base is an "abstract base class" and is never instantiated
3318 * directly. Now, Override foo() in Sub, and use Sub. This
3319 * Works fine unless Sub stops providing an implementation of
3320 * the method.
3321 */
3322 dvmThrowException("Ljava/lang/AbstractMethodError;",
3323 "abstract method not implemented");
3324 GOTO_exceptionThrown();
3325 }
3326#else
3327 assert(!dvmIsAbstractMethod(methodToCall) ||
3328 methodToCall->nativeFunc != NULL);
3329#endif
3330
3331 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s\n",
3332 baseMethod->clazz->descriptor, baseMethod->name,
3333 (u4) baseMethod->methodIndex,
3334 methodToCall->clazz->descriptor, methodToCall->name);
3335 assert(methodToCall != NULL);
3336
3337#if 0
3338 if (vsrc1 != methodToCall->insSize) {
3339 LOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s\n",
3340 baseMethod->clazz->descriptor, baseMethod->name,
3341 (u4) baseMethod->methodIndex,
3342 methodToCall->clazz->descriptor, methodToCall->name);
3343 //dvmDumpClass(baseMethod->clazz);
3344 //dvmDumpClass(methodToCall->clazz);
3345 dvmDumpAllClasses(0);
3346 }
3347#endif
3348
3349 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3350 }
3351GOTO_TARGET_END
3352
3353GOTO_TARGET(invokeSuper, bool methodCallRange)
3354 {
3355 Method* baseMethod;
3356 u2 thisReg;
3357
3358 EXPORT_PC();
3359
3360 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3361 ref = FETCH(1); /* method ref */
3362 vdst = FETCH(2); /* 4 regs -or- first reg */
3363
3364 if (methodCallRange) {
3365 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
3366 vsrc1, ref, vdst, vdst+vsrc1-1);
3367 thisReg = vdst;
3368 } else {
3369 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
3370 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3371 thisReg = vdst & 0x0f;
3372 }
3373 /* impossible in well-formed code, but we must check nevertheless */
3374 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3375 GOTO_exceptionThrown();
3376
3377 /*
3378 * Resolve the method. This is the correct method for the static
3379 * type of the object. We also verify access permissions here.
3380 * The first arg to dvmResolveMethod() is just the referring class
3381 * (used for class loaders and such), so we don't want to pass
3382 * the superclass into the resolution call.
3383 */
3384 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3385 if (baseMethod == NULL) {
3386 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3387 if (baseMethod == NULL) {
3388 ILOGV("+ unknown method or access denied\n");
3389 GOTO_exceptionThrown();
3390 }
3391 }
3392
3393 /*
3394 * Combine the object we found with the vtable offset in the
3395 * method's class.
3396 *
3397 * We're using the current method's class' superclass, not the
3398 * superclass of "this". This is because we might be executing
3399 * in a method inherited from a superclass, and we want to run
3400 * in that class' superclass.
3401 */
3402 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
3403 /*
3404 * Method does not exist in the superclass. Could happen if
3405 * superclass gets updated.
3406 */
3407 dvmThrowException("Ljava/lang/NoSuchMethodError;",
3408 baseMethod->name);
3409 GOTO_exceptionThrown();
3410 }
3411 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
3412#if 0
3413 if (dvmIsAbstractMethod(methodToCall)) {
3414 dvmThrowException("Ljava/lang/AbstractMethodError;",
3415 "abstract method not implemented");
3416 GOTO_exceptionThrown();
3417 }
3418#else
3419 assert(!dvmIsAbstractMethod(methodToCall) ||
3420 methodToCall->nativeFunc != NULL);
3421#endif
3422 LOGVV("+++ base=%s.%s super-virtual=%s.%s\n",
3423 baseMethod->clazz->descriptor, baseMethod->name,
3424 methodToCall->clazz->descriptor, methodToCall->name);
3425 assert(methodToCall != NULL);
3426
3427 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3428 }
3429GOTO_TARGET_END
3430
3431GOTO_TARGET(invokeInterface, bool methodCallRange)
3432 {
3433 Object* thisPtr;
3434 ClassObject* thisClass;
3435
3436 EXPORT_PC();
3437
3438 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3439 ref = FETCH(1); /* method ref */
3440 vdst = FETCH(2); /* 4 regs -or- first reg */
3441
3442 /*
3443 * The object against which we are executing a method is always
3444 * in the first argument.
3445 */
3446 if (methodCallRange) {
3447 assert(vsrc1 > 0);
3448 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
3449 vsrc1, ref, vdst, vdst+vsrc1-1);
3450 thisPtr = (Object*) GET_REGISTER(vdst);
3451 } else {
3452 assert((vsrc1>>4) > 0);
3453 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
3454 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3455 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3456 }
3457 if (!checkForNull(thisPtr))
3458 GOTO_exceptionThrown();
3459
3460 thisClass = thisPtr->clazz;
3461
3462 /*
3463 * Given a class and a method index, find the Method* with the
3464 * actual code we want to execute.
3465 */
3466 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
3467 methodClassDex);
3468 if (methodToCall == NULL) {
3469 assert(dvmCheckException(self));
3470 GOTO_exceptionThrown();
3471 }
3472
3473 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3474 }
3475GOTO_TARGET_END
3476
3477GOTO_TARGET(invokeDirect, bool methodCallRange)
3478 {
3479 u2 thisReg;
3480
3481 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3482 ref = FETCH(1); /* method ref */
3483 vdst = FETCH(2); /* 4 regs -or- first reg */
3484
3485 EXPORT_PC();
3486
3487 if (methodCallRange) {
3488 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
3489 vsrc1, ref, vdst, vdst+vsrc1-1);
3490 thisReg = vdst;
3491 } else {
3492 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
3493 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3494 thisReg = vdst & 0x0f;
3495 }
3496 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3497 GOTO_exceptionThrown();
3498
3499 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3500 if (methodToCall == NULL) {
3501 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
3502 METHOD_DIRECT);
3503 if (methodToCall == NULL) {
3504 ILOGV("+ unknown direct method\n"); // should be impossible
3505 GOTO_exceptionThrown();
3506 }
3507 }
3508 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3509 }
3510GOTO_TARGET_END
3511
3512GOTO_TARGET(invokeStatic, bool methodCallRange)
3513 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3514 ref = FETCH(1); /* method ref */
3515 vdst = FETCH(2); /* 4 regs -or- first reg */
3516
3517 EXPORT_PC();
3518
3519 if (methodCallRange)
3520 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
3521 vsrc1, ref, vdst, vdst+vsrc1-1);
3522 else
3523 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
3524 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3525
3526 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3527 if (methodToCall == NULL) {
3528 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
3529 if (methodToCall == NULL) {
3530 ILOGV("+ unknown method\n");
3531 GOTO_exceptionThrown();
3532 }
Ben Chengdd6e8702010-05-07 13:05:47 -07003533
3534 /*
3535 * The JIT needs dvmDexGetResolvedMethod() to return non-null.
3536 * Since we use the portable interpreter to build the trace, this extra
3537 * check is not needed for mterp.
3538 */
3539 if (dvmDexGetResolvedMethod(methodClassDex, ref) == NULL) {
3540 /* Class initialization is still ongoing */
3541 ABORT_JIT_TSELECT();
3542 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003543 }
3544 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3545GOTO_TARGET_END
3546
3547GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
3548 {
3549 Object* thisPtr;
3550
3551 EXPORT_PC();
3552
3553 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3554 ref = FETCH(1); /* vtable index */
3555 vdst = FETCH(2); /* 4 regs -or- first reg */
3556
3557 /*
3558 * The object against which we are executing a method is always
3559 * in the first argument.
3560 */
3561 if (methodCallRange) {
3562 assert(vsrc1 > 0);
3563 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3564 vsrc1, ref, vdst, vdst+vsrc1-1);
3565 thisPtr = (Object*) GET_REGISTER(vdst);
3566 } else {
3567 assert((vsrc1>>4) > 0);
3568 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
3569 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3570 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3571 }
3572
3573 if (!checkForNull(thisPtr))
3574 GOTO_exceptionThrown();
3575
3576 /*
3577 * Combine the object we found with the vtable offset in the
3578 * method.
3579 */
3580 assert(ref < thisPtr->clazz->vtableCount);
3581 methodToCall = thisPtr->clazz->vtable[ref];
3582
3583#if 0
3584 if (dvmIsAbstractMethod(methodToCall)) {
3585 dvmThrowException("Ljava/lang/AbstractMethodError;",
3586 "abstract method not implemented");
3587 GOTO_exceptionThrown();
3588 }
3589#else
3590 assert(!dvmIsAbstractMethod(methodToCall) ||
3591 methodToCall->nativeFunc != NULL);
3592#endif
3593
3594 LOGVV("+++ virtual[%d]=%s.%s\n",
3595 ref, methodToCall->clazz->descriptor, methodToCall->name);
3596 assert(methodToCall != NULL);
3597
3598 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3599 }
3600GOTO_TARGET_END
3601
3602GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
3603 {
3604 u2 thisReg;
3605
3606 EXPORT_PC();
3607
3608 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3609 ref = FETCH(1); /* vtable index */
3610 vdst = FETCH(2); /* 4 regs -or- first reg */
3611
3612 if (methodCallRange) {
3613 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3614 vsrc1, ref, vdst, vdst+vsrc1-1);
3615 thisReg = vdst;
3616 } else {
3617 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
3618 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3619 thisReg = vdst & 0x0f;
3620 }
3621 /* impossible in well-formed code, but we must check nevertheless */
3622 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3623 GOTO_exceptionThrown();
3624
3625#if 0 /* impossible in optimized + verified code */
3626 if (ref >= curMethod->clazz->super->vtableCount) {
3627 dvmThrowException("Ljava/lang/NoSuchMethodError;", NULL);
3628 GOTO_exceptionThrown();
3629 }
3630#else
3631 assert(ref < curMethod->clazz->super->vtableCount);
3632#endif
3633
3634 /*
3635 * Combine the object we found with the vtable offset in the
3636 * method's class.
3637 *
3638 * We're using the current method's class' superclass, not the
3639 * superclass of "this". This is because we might be executing
3640 * in a method inherited from a superclass, and we want to run
3641 * in the method's class' superclass.
3642 */
3643 methodToCall = curMethod->clazz->super->vtable[ref];
3644
3645#if 0
3646 if (dvmIsAbstractMethod(methodToCall)) {
3647 dvmThrowException("Ljava/lang/AbstractMethodError;",
3648 "abstract method not implemented");
3649 GOTO_exceptionThrown();
3650 }
3651#else
3652 assert(!dvmIsAbstractMethod(methodToCall) ||
3653 methodToCall->nativeFunc != NULL);
3654#endif
3655 LOGVV("+++ super-virtual[%d]=%s.%s\n",
3656 ref, methodToCall->clazz->descriptor, methodToCall->name);
3657 assert(methodToCall != NULL);
3658
3659 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3660 }
3661GOTO_TARGET_END
3662
3663
3664
3665 /*
3666 * General handling for return-void, return, and return-wide. Put the
3667 * return value in "retval" before jumping here.
3668 */
3669GOTO_TARGET(returnFromMethod)
3670 {
3671 StackSaveArea* saveArea;
3672
3673 /*
3674 * We must do this BEFORE we pop the previous stack frame off, so
3675 * that the GC can see the return value (if any) in the local vars.
3676 *
3677 * Since this is now an interpreter switch point, we must do it before
3678 * we do anything at all.
3679 */
3680 PERIODIC_CHECKS(kInterpEntryReturn, 0);
3681
3682 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
3683 retval.j, curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04003684 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003685 //DUMP_REGS(curMethod, fp);
3686
3687 saveArea = SAVEAREA_FROM_FP(fp);
3688
3689#ifdef EASY_GDB
3690 debugSaveArea = saveArea;
3691#endif
3692#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
3693 TRACE_METHOD_EXIT(self, curMethod);
3694#endif
3695
3696 /* back up to previous frame and see if we hit a break */
3697 fp = saveArea->prevFrame;
3698 assert(fp != NULL);
3699 if (dvmIsBreakFrame(fp)) {
3700 /* bail without popping the method frame from stack */
3701 LOGVV("+++ returned into break frame\n");
Bill Buzbeed7269912009-11-10 14:31:32 -08003702#if defined(WITH_JIT)
3703 /* Let the Jit know the return is terminating normally */
Ben Chengfc075c22010-05-28 15:20:08 -07003704 CHECK_JIT_VOID();
Bill Buzbeed7269912009-11-10 14:31:32 -08003705#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003706 GOTO_bail();
3707 }
3708
3709 /* update thread FP, and reset local variables */
3710 self->curFrame = fp;
3711 curMethod = SAVEAREA_FROM_FP(fp)->method;
3712 //methodClass = curMethod->clazz;
3713 methodClassDex = curMethod->clazz->pDvmDex;
3714 pc = saveArea->savedPc;
3715 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003716 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003717
3718 /* use FINISH on the caller's invoke instruction */
3719 //u2 invokeInstr = INST_INST(FETCH(0));
3720 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3721 invokeInstr <= OP_INVOKE_INTERFACE*/)
3722 {
3723 FINISH(3);
3724 } else {
3725 //LOGE("Unknown invoke instr %02x at %d\n",
3726 // invokeInstr, (int) (pc - curMethod->insns));
3727 assert(false);
3728 }
3729 }
3730GOTO_TARGET_END
3731
3732
3733 /*
3734 * Jump here when the code throws an exception.
3735 *
3736 * By the time we get here, the Throwable has been created and the stack
3737 * trace has been saved off.
3738 */
3739GOTO_TARGET(exceptionThrown)
3740 {
3741 Object* exception;
3742 int catchRelPc;
3743
3744 /*
3745 * Since this is now an interpreter switch point, we must do it before
3746 * we do anything at all.
3747 */
3748 PERIODIC_CHECKS(kInterpEntryThrow, 0);
3749
Ben Cheng79d173c2009-09-29 16:12:51 -07003750#if defined(WITH_JIT)
3751 // Something threw during trace selection - abort the current trace
Bill Buzbee5540f6e2010-02-08 10:41:32 -08003752 ABORT_JIT_TSELECT();
Ben Cheng79d173c2009-09-29 16:12:51 -07003753#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003754 /*
3755 * We save off the exception and clear the exception status. While
3756 * processing the exception we might need to load some Throwable
3757 * classes, and we don't want class loader exceptions to get
3758 * confused with this one.
3759 */
3760 assert(dvmCheckException(self));
3761 exception = dvmGetException(self);
3762 dvmAddTrackedAlloc(exception, self);
3763 dvmClearException(self);
3764
3765 LOGV("Handling exception %s at %s:%d\n",
3766 exception->clazz->descriptor, curMethod->name,
3767 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3768
3769#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
3770 /*
3771 * Tell the debugger about it.
3772 *
3773 * TODO: if the exception was thrown by interpreted code, control
3774 * fell through native, and then back to us, we will report the
3775 * exception at the point of the throw and again here. We can avoid
3776 * this by not reporting exceptions when we jump here directly from
3777 * the native call code above, but then we won't report exceptions
3778 * that were thrown *from* the JNI code (as opposed to *through* it).
3779 *
3780 * The correct solution is probably to ignore from-native exceptions
3781 * here, and have the JNI exception code do the reporting to the
3782 * debugger.
3783 */
3784 if (gDvm.debuggerActive) {
3785 void* catchFrame;
3786 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3787 exception, true, &catchFrame);
3788 dvmDbgPostException(fp, pc - curMethod->insns, catchFrame,
3789 catchRelPc, exception);
3790 }
3791#endif
3792
3793 /*
3794 * We need to unroll to the catch block or the nearest "break"
3795 * frame.
3796 *
3797 * A break frame could indicate that we have reached an intermediate
3798 * native call, or have gone off the top of the stack and the thread
3799 * needs to exit. Either way, we return from here, leaving the
3800 * exception raised.
3801 *
3802 * If we do find a catch block, we want to transfer execution to
3803 * that point.
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003804 *
3805 * Note this can cause an exception while resolving classes in
3806 * the "catch" blocks.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003807 */
3808 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3809 exception, false, (void*)&fp);
3810
3811 /*
3812 * Restore the stack bounds after an overflow. This isn't going to
3813 * be correct in all circumstances, e.g. if JNI code devours the
3814 * exception this won't happen until some other exception gets
3815 * thrown. If the code keeps pushing the stack bounds we'll end
3816 * up aborting the VM.
3817 *
3818 * Note we want to do this *after* the call to dvmFindCatchBlock,
3819 * because that may need extra stack space to resolve exception
3820 * classes (e.g. through a class loader).
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003821 *
3822 * It's possible for the stack overflow handling to cause an
3823 * exception (specifically, class resolution in a "catch" block
3824 * during the call above), so we could see the thread's overflow
3825 * flag raised but actually be running in a "nested" interpreter
3826 * frame. We don't allow doubled-up StackOverflowErrors, so
3827 * we can check for this by just looking at the exception type
3828 * in the cleanup function. Also, we won't unroll past the SOE
3829 * point because the more-recent exception will hit a break frame
3830 * as it unrolls to here.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003831 */
3832 if (self->stackOverflowed)
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003833 dvmCleanupStackOverflow(self, exception);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003834
3835 if (catchRelPc < 0) {
3836 /* falling through to JNI code or off the bottom of the stack */
3837#if DVM_SHOW_EXCEPTION >= 2
3838 LOGD("Exception %s from %s:%d not caught locally\n",
3839 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3840 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3841#endif
3842 dvmSetException(self, exception);
3843 dvmReleaseTrackedAlloc(exception, self);
3844 GOTO_bail();
3845 }
3846
3847#if DVM_SHOW_EXCEPTION >= 3
3848 {
3849 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
3850 LOGD("Exception %s thrown from %s:%d to %s:%d\n",
3851 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3852 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
3853 dvmGetMethodSourceFile(catchMethod),
3854 dvmLineNumFromPC(catchMethod, catchRelPc));
3855 }
3856#endif
3857
3858 /*
3859 * Adjust local variables to match self->curFrame and the
3860 * updated PC.
3861 */
3862 //fp = (u4*) self->curFrame;
3863 curMethod = SAVEAREA_FROM_FP(fp)->method;
3864 //methodClass = curMethod->clazz;
3865 methodClassDex = curMethod->clazz->pDvmDex;
3866 pc = curMethod->insns + catchRelPc;
3867 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003868 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003869 DUMP_REGS(curMethod, fp, false); // show all regs
3870
3871 /*
3872 * Restore the exception if the handler wants it.
3873 *
3874 * The Dalvik spec mandates that, if an exception handler wants to
3875 * do something with the exception, the first instruction executed
3876 * must be "move-exception". We can pass the exception along
3877 * through the thread struct, and let the move-exception instruction
3878 * clear it for us.
3879 *
3880 * If the handler doesn't call move-exception, we don't want to
3881 * finish here with an exception still pending.
3882 */
3883 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
3884 dvmSetException(self, exception);
3885
3886 dvmReleaseTrackedAlloc(exception, self);
3887 FINISH(0);
3888 }
3889GOTO_TARGET_END
3890
3891
3892 /*
3893 * General handling for invoke-{virtual,super,direct,static,interface},
3894 * including "quick" variants.
3895 *
3896 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
3897 * depending on whether this is a "/range" instruction.
3898 *
3899 * For a range call:
3900 * "vsrc1" holds the argument count (8 bits)
3901 * "vdst" holds the first argument in the range
3902 * For a non-range call:
3903 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
3904 * "vdst" holds four 4-bit register indices
3905 *
3906 * The caller must EXPORT_PC before jumping here, because any method
3907 * call can throw a stack overflow exception.
3908 */
3909GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
3910 u2 count, u2 regs)
3911 {
3912 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
3913
3914 //printf("range=%d call=%p count=%d regs=0x%04x\n",
3915 // methodCallRange, methodToCall, count, regs);
3916 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003917 // methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003918
3919 u4* outs;
3920 int i;
3921
3922 /*
3923 * Copy args. This may corrupt vsrc1/vdst.
3924 */
3925 if (methodCallRange) {
3926 // could use memcpy or a "Duff's device"; most functions have
3927 // so few args it won't matter much
3928 assert(vsrc1 <= curMethod->outsSize);
3929 assert(vsrc1 == methodToCall->insSize);
3930 outs = OUTS_FROM_FP(fp, vsrc1);
3931 for (i = 0; i < vsrc1; i++)
3932 outs[i] = GET_REGISTER(vdst+i);
3933 } else {
3934 u4 count = vsrc1 >> 4;
3935
3936 assert(count <= curMethod->outsSize);
3937 assert(count == methodToCall->insSize);
3938 assert(count <= 5);
3939
3940 outs = OUTS_FROM_FP(fp, count);
3941#if 0
3942 if (count == 5) {
3943 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3944 count--;
3945 }
3946 for (i = 0; i < (int) count; i++) {
3947 outs[i] = GET_REGISTER(vdst & 0x0f);
3948 vdst >>= 4;
3949 }
3950#else
3951 // This version executes fewer instructions but is larger
3952 // overall. Seems to be a teensy bit faster.
3953 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
3954 switch (count) {
3955 case 5:
3956 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3957 case 4:
3958 outs[3] = GET_REGISTER(vdst >> 12);
3959 case 3:
3960 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
3961 case 2:
3962 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
3963 case 1:
3964 outs[0] = GET_REGISTER(vdst & 0x0f);
3965 default:
3966 ;
3967 }
3968#endif
3969 }
3970 }
3971
3972 /*
3973 * (This was originally a "goto" target; I've kept it separate from the
3974 * stuff above in case we want to refactor things again.)
3975 *
3976 * At this point, we have the arguments stored in the "outs" area of
3977 * the current method's stack frame, and the method to call in
3978 * "methodToCall". Push a new stack frame.
3979 */
3980 {
3981 StackSaveArea* newSaveArea;
3982 u4* newFp;
3983
3984 ILOGV("> %s%s.%s %s",
3985 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
3986 methodToCall->clazz->descriptor, methodToCall->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04003987 methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003988
3989 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
3990 newSaveArea = SAVEAREA_FROM_FP(newFp);
3991
3992 /* verify that we have enough space */
3993 if (true) {
3994 u1* bottom;
3995 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
3996 if (bottom < self->interpStackEnd) {
3997 /* stack overflow */
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07003998 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 -08003999 self->interpStackStart, self->interpStackEnd, bottom,
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07004000 (u1*) fp - bottom, self->interpStackSize,
4001 methodToCall->name);
4002 dvmHandleStackOverflow(self, methodToCall);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004003 assert(dvmCheckException(self));
4004 GOTO_exceptionThrown();
4005 }
4006 //LOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p\n",
4007 // fp, newFp, newSaveArea, bottom);
4008 }
4009
4010#ifdef LOG_INSTR
4011 if (methodToCall->registersSize > methodToCall->insSize) {
4012 /*
4013 * This makes valgrind quiet when we print registers that
4014 * haven't been initialized. Turn it off when the debug
4015 * messages are disabled -- we want valgrind to report any
4016 * used-before-initialized issues.
4017 */
4018 memset(newFp, 0xcc,
4019 (methodToCall->registersSize - methodToCall->insSize) * 4);
4020 }
4021#endif
4022
4023#ifdef EASY_GDB
4024 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
4025#endif
4026 newSaveArea->prevFrame = fp;
4027 newSaveArea->savedPc = pc;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004028#if defined(WITH_JIT)
4029 newSaveArea->returnAddr = 0;
4030#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004031 newSaveArea->method = methodToCall;
4032
4033 if (!dvmIsNativeMethod(methodToCall)) {
4034 /*
4035 * "Call" interpreted code. Reposition the PC, update the
4036 * frame pointer and other local state, and continue.
4037 */
4038 curMethod = methodToCall;
4039 methodClassDex = curMethod->clazz->pDvmDex;
4040 pc = methodToCall->insns;
4041 fp = self->curFrame = newFp;
4042#ifdef EASY_GDB
4043 debugSaveArea = SAVEAREA_FROM_FP(newFp);
4044#endif
4045#if INTERP_TYPE == INTERP_DBG
4046 debugIsMethodEntry = true; // profiling, debugging
4047#endif
4048 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04004049 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004050 DUMP_REGS(curMethod, fp, true); // show input args
4051 FINISH(0); // jump to method start
4052 } else {
4053 /* set this up for JNI locals, even if not a JNI native */
Andy McFaddend5ab7262009-08-25 07:19:34 -07004054#ifdef USE_INDIRECT_REF
4055 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.segmentState.all;
4056#else
4057 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.nextEntry;
4058#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004059
4060 self->curFrame = newFp;
4061
4062 DUMP_REGS(methodToCall, newFp, true); // show input args
4063
4064#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
4065 if (gDvm.debuggerActive) {
4066 dvmDbgPostLocationEvent(methodToCall, -1,
4067 dvmGetThisPtr(curMethod, fp), DBG_METHOD_ENTRY);
4068 }
4069#endif
4070#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
4071 TRACE_METHOD_ENTER(self, methodToCall);
4072#endif
4073
4074 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04004075 methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004076
Bill Buzbeed7269912009-11-10 14:31:32 -08004077#if defined(WITH_JIT)
4078 /* Allow the Jit to end any pending trace building */
Ben Chengfc075c22010-05-28 15:20:08 -07004079 CHECK_JIT_VOID();
Bill Buzbeed7269912009-11-10 14:31:32 -08004080#endif
4081
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004082 /*
4083 * Jump through native call bridge. Because we leave no
4084 * space for locals on native calls, "newFp" points directly
4085 * to the method arguments.
4086 */
4087 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
4088
4089#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_DEBUGGER)
4090 if (gDvm.debuggerActive) {
4091 dvmDbgPostLocationEvent(methodToCall, -1,
4092 dvmGetThisPtr(curMethod, fp), DBG_METHOD_EXIT);
4093 }
4094#endif
4095#if (INTERP_TYPE == INTERP_DBG) && defined(WITH_PROFILER)
4096 TRACE_METHOD_EXIT(self, methodToCall);
4097#endif
4098
4099 /* pop frame off */
4100 dvmPopJniLocals(self, newSaveArea);
4101 self->curFrame = fp;
4102
4103 /*
4104 * If the native code threw an exception, or interpreted code
4105 * invoked by the native call threw one and nobody has cleared
4106 * it, jump to our local exception handling.
4107 */
4108 if (dvmCheckException(self)) {
4109 LOGV("Exception thrown by/below native code\n");
4110 GOTO_exceptionThrown();
4111 }
4112
4113 ILOGD("> retval=0x%llx (leaving native)", retval.j);
4114 ILOGD("> (return from native %s.%s to %s.%s %s)",
4115 methodToCall->clazz->descriptor, methodToCall->name,
4116 curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04004117 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004118
4119 //u2 invokeInstr = INST_INST(FETCH(0));
4120 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
4121 invokeInstr <= OP_INVOKE_INTERFACE*/)
4122 {
4123 FINISH(3);
4124 } else {
4125 //LOGE("Unknown invoke instr %02x at %d\n",
4126 // invokeInstr, (int) (pc - curMethod->insns));
4127 assert(false);
4128 }
4129 }
4130 }
4131 assert(false); // should not get here
4132GOTO_TARGET_END
4133
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004134/* File: portable/enddefs.c */
4135/*--- end of opcodes ---*/
4136
4137#ifndef THREADED_INTERP
4138 } // end of "switch"
4139 } // end of "while"
4140#endif
4141
4142bail:
4143 ILOGD("|-- Leaving interpreter loop"); // note "curMethod" may be NULL
4144
4145 interpState->retval = retval;
4146 return false;
4147
4148bail_switch:
4149 /*
4150 * The standard interpreter currently doesn't set or care about the
4151 * "debugIsMethodEntry" value, so setting this is only of use if we're
4152 * switching between two "debug" interpreters, which we never do.
4153 *
4154 * TODO: figure out if preserving this makes any sense.
4155 */
4156#if defined(WITH_PROFILER) || defined(WITH_DEBUGGER)
4157# if INTERP_TYPE == INTERP_DBG
4158 interpState->debugIsMethodEntry = debugIsMethodEntry;
4159# else
4160 interpState->debugIsMethodEntry = false;
4161# endif
4162#endif
4163
4164 /* export state changes */
4165 interpState->method = curMethod;
4166 interpState->pc = pc;
4167 interpState->fp = fp;
4168 /* debugTrackedRefStart doesn't change */
4169 interpState->retval = retval; /* need for _entryPoint=ret */
4170 interpState->nextMode =
4171 (INTERP_TYPE == INTERP_STD) ? INTERP_DBG : INTERP_STD;
4172 LOGVV(" meth='%s.%s' pc=0x%x fp=%p\n",
4173 curMethod->clazz->descriptor, curMethod->name,
4174 pc - curMethod->insns, fp);
4175 return true;
4176}
4177
4178