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