blob: b0adbc84a85e8dbe4f2aec839a02a4ae43af04d1 [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);
2195 //dvmDumpClass(obj->clazz);
2196 //dvmDumpClass(arrayObj->obj.clazz);
2197 dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
2198 GOTO_exceptionThrown();
2199 }
2200 }
2201 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));
Barry Hayes364f9d92010-06-11 16:12:47 -07002202 dvmSetObjectArrayElement(arrayObj,
2203 GET_REGISTER(vsrc2),
2204 (Object *)GET_REGISTER(vdst));
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002205 }
2206 FINISH(2);
2207OP_END
2208
2209/* File: c/OP_APUT_BOOLEAN.c */
2210HANDLE_OP_APUT(OP_APUT_BOOLEAN, "-boolean", u1, )
2211OP_END
2212
2213/* File: c/OP_APUT_BYTE.c */
2214HANDLE_OP_APUT(OP_APUT_BYTE, "-byte", s1, )
2215OP_END
2216
2217/* File: c/OP_APUT_CHAR.c */
2218HANDLE_OP_APUT(OP_APUT_CHAR, "-char", u2, )
2219OP_END
2220
2221/* File: c/OP_APUT_SHORT.c */
2222HANDLE_OP_APUT(OP_APUT_SHORT, "-short", s2, )
2223OP_END
2224
2225/* File: c/OP_IGET.c */
2226HANDLE_IGET_X(OP_IGET, "", Int, )
2227OP_END
2228
2229/* File: c/OP_IGET_WIDE.c */
2230HANDLE_IGET_X(OP_IGET_WIDE, "-wide", Long, _WIDE)
2231OP_END
2232
2233/* File: c/OP_IGET_OBJECT.c */
2234HANDLE_IGET_X(OP_IGET_OBJECT, "-object", Object, _AS_OBJECT)
2235OP_END
2236
2237/* File: c/OP_IGET_BOOLEAN.c */
2238HANDLE_IGET_X(OP_IGET_BOOLEAN, "", Int, )
2239OP_END
2240
2241/* File: c/OP_IGET_BYTE.c */
2242HANDLE_IGET_X(OP_IGET_BYTE, "", Int, )
2243OP_END
2244
2245/* File: c/OP_IGET_CHAR.c */
2246HANDLE_IGET_X(OP_IGET_CHAR, "", Int, )
2247OP_END
2248
2249/* File: c/OP_IGET_SHORT.c */
2250HANDLE_IGET_X(OP_IGET_SHORT, "", Int, )
2251OP_END
2252
2253/* File: c/OP_IPUT.c */
2254HANDLE_IPUT_X(OP_IPUT, "", Int, )
2255OP_END
2256
2257/* File: c/OP_IPUT_WIDE.c */
2258HANDLE_IPUT_X(OP_IPUT_WIDE, "-wide", Long, _WIDE)
2259OP_END
2260
2261/* File: c/OP_IPUT_OBJECT.c */
2262/*
2263 * The VM spec says we should verify that the reference being stored into
2264 * the field is assignment compatible. In practice, many popular VMs don't
2265 * do this because it slows down a very common operation. It's not so bad
2266 * for us, since "dexopt" quickens it whenever possible, but it's still an
2267 * issue.
2268 *
2269 * To make this spec-complaint, we'd need to add a ClassObject pointer to
2270 * the Field struct, resolve the field's type descriptor at link or class
2271 * init time, and then verify the type here.
2272 */
2273HANDLE_IPUT_X(OP_IPUT_OBJECT, "-object", Object, _AS_OBJECT)
2274OP_END
2275
2276/* File: c/OP_IPUT_BOOLEAN.c */
2277HANDLE_IPUT_X(OP_IPUT_BOOLEAN, "", Int, )
2278OP_END
2279
2280/* File: c/OP_IPUT_BYTE.c */
2281HANDLE_IPUT_X(OP_IPUT_BYTE, "", Int, )
2282OP_END
2283
2284/* File: c/OP_IPUT_CHAR.c */
2285HANDLE_IPUT_X(OP_IPUT_CHAR, "", Int, )
2286OP_END
2287
2288/* File: c/OP_IPUT_SHORT.c */
2289HANDLE_IPUT_X(OP_IPUT_SHORT, "", Int, )
2290OP_END
2291
2292/* File: c/OP_SGET.c */
2293HANDLE_SGET_X(OP_SGET, "", Int, )
2294OP_END
2295
2296/* File: c/OP_SGET_WIDE.c */
2297HANDLE_SGET_X(OP_SGET_WIDE, "-wide", Long, _WIDE)
2298OP_END
2299
2300/* File: c/OP_SGET_OBJECT.c */
2301HANDLE_SGET_X(OP_SGET_OBJECT, "-object", Object, _AS_OBJECT)
2302OP_END
2303
2304/* File: c/OP_SGET_BOOLEAN.c */
2305HANDLE_SGET_X(OP_SGET_BOOLEAN, "", Int, )
2306OP_END
2307
2308/* File: c/OP_SGET_BYTE.c */
2309HANDLE_SGET_X(OP_SGET_BYTE, "", Int, )
2310OP_END
2311
2312/* File: c/OP_SGET_CHAR.c */
2313HANDLE_SGET_X(OP_SGET_CHAR, "", Int, )
2314OP_END
2315
2316/* File: c/OP_SGET_SHORT.c */
2317HANDLE_SGET_X(OP_SGET_SHORT, "", Int, )
2318OP_END
2319
2320/* File: c/OP_SPUT.c */
2321HANDLE_SPUT_X(OP_SPUT, "", Int, )
2322OP_END
2323
2324/* File: c/OP_SPUT_WIDE.c */
2325HANDLE_SPUT_X(OP_SPUT_WIDE, "-wide", Long, _WIDE)
2326OP_END
2327
2328/* File: c/OP_SPUT_OBJECT.c */
2329HANDLE_SPUT_X(OP_SPUT_OBJECT, "-object", Object, _AS_OBJECT)
2330OP_END
2331
2332/* File: c/OP_SPUT_BOOLEAN.c */
2333HANDLE_SPUT_X(OP_SPUT_BOOLEAN, "", Int, )
2334OP_END
2335
2336/* File: c/OP_SPUT_BYTE.c */
2337HANDLE_SPUT_X(OP_SPUT_BYTE, "", Int, )
2338OP_END
2339
2340/* File: c/OP_SPUT_CHAR.c */
2341HANDLE_SPUT_X(OP_SPUT_CHAR, "", Int, )
2342OP_END
2343
2344/* File: c/OP_SPUT_SHORT.c */
2345HANDLE_SPUT_X(OP_SPUT_SHORT, "", Int, )
2346OP_END
2347
2348/* File: c/OP_INVOKE_VIRTUAL.c */
2349HANDLE_OPCODE(OP_INVOKE_VIRTUAL /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2350 GOTO_invoke(invokeVirtual, false);
2351OP_END
2352
2353/* File: c/OP_INVOKE_SUPER.c */
2354HANDLE_OPCODE(OP_INVOKE_SUPER /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2355 GOTO_invoke(invokeSuper, false);
2356OP_END
2357
2358/* File: c/OP_INVOKE_DIRECT.c */
2359HANDLE_OPCODE(OP_INVOKE_DIRECT /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2360 GOTO_invoke(invokeDirect, false);
2361OP_END
2362
2363/* File: c/OP_INVOKE_STATIC.c */
2364HANDLE_OPCODE(OP_INVOKE_STATIC /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2365 GOTO_invoke(invokeStatic, false);
2366OP_END
2367
2368/* File: c/OP_INVOKE_INTERFACE.c */
2369HANDLE_OPCODE(OP_INVOKE_INTERFACE /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
2370 GOTO_invoke(invokeInterface, false);
2371OP_END
2372
2373/* File: c/OP_UNUSED_73.c */
2374HANDLE_OPCODE(OP_UNUSED_73)
2375OP_END
2376
2377/* File: c/OP_INVOKE_VIRTUAL_RANGE.c */
2378HANDLE_OPCODE(OP_INVOKE_VIRTUAL_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2379 GOTO_invoke(invokeVirtual, true);
2380OP_END
2381
2382/* File: c/OP_INVOKE_SUPER_RANGE.c */
2383HANDLE_OPCODE(OP_INVOKE_SUPER_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2384 GOTO_invoke(invokeSuper, true);
2385OP_END
2386
2387/* File: c/OP_INVOKE_DIRECT_RANGE.c */
2388HANDLE_OPCODE(OP_INVOKE_DIRECT_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2389 GOTO_invoke(invokeDirect, true);
2390OP_END
2391
2392/* File: c/OP_INVOKE_STATIC_RANGE.c */
2393HANDLE_OPCODE(OP_INVOKE_STATIC_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2394 GOTO_invoke(invokeStatic, true);
2395OP_END
2396
2397/* File: c/OP_INVOKE_INTERFACE_RANGE.c */
2398HANDLE_OPCODE(OP_INVOKE_INTERFACE_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
2399 GOTO_invoke(invokeInterface, true);
2400OP_END
2401
2402/* File: c/OP_UNUSED_79.c */
2403HANDLE_OPCODE(OP_UNUSED_79)
2404OP_END
2405
2406/* File: c/OP_UNUSED_7A.c */
2407HANDLE_OPCODE(OP_UNUSED_7A)
2408OP_END
2409
2410/* File: c/OP_NEG_INT.c */
2411HANDLE_UNOP(OP_NEG_INT, "neg-int", -, , )
2412OP_END
2413
2414/* File: c/OP_NOT_INT.c */
2415HANDLE_UNOP(OP_NOT_INT, "not-int", , ^ 0xffffffff, )
2416OP_END
2417
2418/* File: c/OP_NEG_LONG.c */
2419HANDLE_UNOP(OP_NEG_LONG, "neg-long", -, , _WIDE)
2420OP_END
2421
2422/* File: c/OP_NOT_LONG.c */
2423HANDLE_UNOP(OP_NOT_LONG, "not-long", , ^ 0xffffffffffffffffULL, _WIDE)
2424OP_END
2425
2426/* File: c/OP_NEG_FLOAT.c */
2427HANDLE_UNOP(OP_NEG_FLOAT, "neg-float", -, , _FLOAT)
2428OP_END
2429
2430/* File: c/OP_NEG_DOUBLE.c */
2431HANDLE_UNOP(OP_NEG_DOUBLE, "neg-double", -, , _DOUBLE)
2432OP_END
2433
2434/* File: c/OP_INT_TO_LONG.c */
2435HANDLE_NUMCONV(OP_INT_TO_LONG, "int-to-long", _INT, _WIDE)
2436OP_END
2437
2438/* File: c/OP_INT_TO_FLOAT.c */
2439HANDLE_NUMCONV(OP_INT_TO_FLOAT, "int-to-float", _INT, _FLOAT)
2440OP_END
2441
2442/* File: c/OP_INT_TO_DOUBLE.c */
2443HANDLE_NUMCONV(OP_INT_TO_DOUBLE, "int-to-double", _INT, _DOUBLE)
2444OP_END
2445
2446/* File: c/OP_LONG_TO_INT.c */
2447HANDLE_NUMCONV(OP_LONG_TO_INT, "long-to-int", _WIDE, _INT)
2448OP_END
2449
2450/* File: c/OP_LONG_TO_FLOAT.c */
2451HANDLE_NUMCONV(OP_LONG_TO_FLOAT, "long-to-float", _WIDE, _FLOAT)
2452OP_END
2453
2454/* File: c/OP_LONG_TO_DOUBLE.c */
2455HANDLE_NUMCONV(OP_LONG_TO_DOUBLE, "long-to-double", _WIDE, _DOUBLE)
2456OP_END
2457
2458/* File: c/OP_FLOAT_TO_INT.c */
2459HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_INT, "float-to-int",
2460 float, _FLOAT, s4, _INT)
2461OP_END
2462
2463/* File: c/OP_FLOAT_TO_LONG.c */
2464HANDLE_FLOAT_TO_INT(OP_FLOAT_TO_LONG, "float-to-long",
2465 float, _FLOAT, s8, _WIDE)
2466OP_END
2467
2468/* File: c/OP_FLOAT_TO_DOUBLE.c */
2469HANDLE_NUMCONV(OP_FLOAT_TO_DOUBLE, "float-to-double", _FLOAT, _DOUBLE)
2470OP_END
2471
2472/* File: c/OP_DOUBLE_TO_INT.c */
2473HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_INT, "double-to-int",
2474 double, _DOUBLE, s4, _INT)
2475OP_END
2476
2477/* File: c/OP_DOUBLE_TO_LONG.c */
2478HANDLE_FLOAT_TO_INT(OP_DOUBLE_TO_LONG, "double-to-long",
2479 double, _DOUBLE, s8, _WIDE)
2480OP_END
2481
2482/* File: c/OP_DOUBLE_TO_FLOAT.c */
2483HANDLE_NUMCONV(OP_DOUBLE_TO_FLOAT, "double-to-float", _DOUBLE, _FLOAT)
2484OP_END
2485
2486/* File: c/OP_INT_TO_BYTE.c */
2487HANDLE_INT_TO_SMALL(OP_INT_TO_BYTE, "byte", s1)
2488OP_END
2489
2490/* File: c/OP_INT_TO_CHAR.c */
2491HANDLE_INT_TO_SMALL(OP_INT_TO_CHAR, "char", u2)
2492OP_END
2493
2494/* File: c/OP_INT_TO_SHORT.c */
2495HANDLE_INT_TO_SMALL(OP_INT_TO_SHORT, "short", s2) /* want sign bit */
2496OP_END
2497
2498/* File: c/OP_ADD_INT.c */
2499HANDLE_OP_X_INT(OP_ADD_INT, "add", +, 0)
2500OP_END
2501
2502/* File: c/OP_SUB_INT.c */
2503HANDLE_OP_X_INT(OP_SUB_INT, "sub", -, 0)
2504OP_END
2505
2506/* File: c/OP_MUL_INT.c */
2507HANDLE_OP_X_INT(OP_MUL_INT, "mul", *, 0)
2508OP_END
2509
2510/* File: c/OP_DIV_INT.c */
2511HANDLE_OP_X_INT(OP_DIV_INT, "div", /, 1)
2512OP_END
2513
2514/* File: c/OP_REM_INT.c */
2515HANDLE_OP_X_INT(OP_REM_INT, "rem", %, 2)
2516OP_END
2517
2518/* File: c/OP_AND_INT.c */
2519HANDLE_OP_X_INT(OP_AND_INT, "and", &, 0)
2520OP_END
2521
2522/* File: c/OP_OR_INT.c */
2523HANDLE_OP_X_INT(OP_OR_INT, "or", |, 0)
2524OP_END
2525
2526/* File: c/OP_XOR_INT.c */
2527HANDLE_OP_X_INT(OP_XOR_INT, "xor", ^, 0)
2528OP_END
2529
2530/* File: c/OP_SHL_INT.c */
2531HANDLE_OP_SHX_INT(OP_SHL_INT, "shl", (s4), <<)
2532OP_END
2533
2534/* File: c/OP_SHR_INT.c */
2535HANDLE_OP_SHX_INT(OP_SHR_INT, "shr", (s4), >>)
2536OP_END
2537
2538/* File: c/OP_USHR_INT.c */
2539HANDLE_OP_SHX_INT(OP_USHR_INT, "ushr", (u4), >>)
2540OP_END
2541
2542/* File: c/OP_ADD_LONG.c */
2543HANDLE_OP_X_LONG(OP_ADD_LONG, "add", +, 0)
2544OP_END
2545
2546/* File: c/OP_SUB_LONG.c */
2547HANDLE_OP_X_LONG(OP_SUB_LONG, "sub", -, 0)
2548OP_END
2549
2550/* File: c/OP_MUL_LONG.c */
2551HANDLE_OP_X_LONG(OP_MUL_LONG, "mul", *, 0)
2552OP_END
2553
2554/* File: c/OP_DIV_LONG.c */
2555HANDLE_OP_X_LONG(OP_DIV_LONG, "div", /, 1)
2556OP_END
2557
2558/* File: c/OP_REM_LONG.c */
2559HANDLE_OP_X_LONG(OP_REM_LONG, "rem", %, 2)
2560OP_END
2561
2562/* File: c/OP_AND_LONG.c */
2563HANDLE_OP_X_LONG(OP_AND_LONG, "and", &, 0)
2564OP_END
2565
2566/* File: c/OP_OR_LONG.c */
2567HANDLE_OP_X_LONG(OP_OR_LONG, "or", |, 0)
2568OP_END
2569
2570/* File: c/OP_XOR_LONG.c */
2571HANDLE_OP_X_LONG(OP_XOR_LONG, "xor", ^, 0)
2572OP_END
2573
2574/* File: c/OP_SHL_LONG.c */
2575HANDLE_OP_SHX_LONG(OP_SHL_LONG, "shl", (s8), <<)
2576OP_END
2577
2578/* File: c/OP_SHR_LONG.c */
2579HANDLE_OP_SHX_LONG(OP_SHR_LONG, "shr", (s8), >>)
2580OP_END
2581
2582/* File: c/OP_USHR_LONG.c */
2583HANDLE_OP_SHX_LONG(OP_USHR_LONG, "ushr", (u8), >>)
2584OP_END
2585
2586/* File: c/OP_ADD_FLOAT.c */
2587HANDLE_OP_X_FLOAT(OP_ADD_FLOAT, "add", +)
2588OP_END
2589
2590/* File: c/OP_SUB_FLOAT.c */
2591HANDLE_OP_X_FLOAT(OP_SUB_FLOAT, "sub", -)
2592OP_END
2593
2594/* File: c/OP_MUL_FLOAT.c */
2595HANDLE_OP_X_FLOAT(OP_MUL_FLOAT, "mul", *)
2596OP_END
2597
2598/* File: c/OP_DIV_FLOAT.c */
2599HANDLE_OP_X_FLOAT(OP_DIV_FLOAT, "div", /)
2600OP_END
2601
2602/* File: c/OP_REM_FLOAT.c */
2603HANDLE_OPCODE(OP_REM_FLOAT /*vAA, vBB, vCC*/)
2604 {
2605 u2 srcRegs;
2606 vdst = INST_AA(inst);
2607 srcRegs = FETCH(1);
2608 vsrc1 = srcRegs & 0xff;
2609 vsrc2 = srcRegs >> 8;
2610 ILOGV("|%s-float v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2611 SET_REGISTER_FLOAT(vdst,
2612 fmodf(GET_REGISTER_FLOAT(vsrc1), GET_REGISTER_FLOAT(vsrc2)));
2613 }
2614 FINISH(2);
2615OP_END
2616
2617/* File: c/OP_ADD_DOUBLE.c */
2618HANDLE_OP_X_DOUBLE(OP_ADD_DOUBLE, "add", +)
2619OP_END
2620
2621/* File: c/OP_SUB_DOUBLE.c */
2622HANDLE_OP_X_DOUBLE(OP_SUB_DOUBLE, "sub", -)
2623OP_END
2624
2625/* File: c/OP_MUL_DOUBLE.c */
2626HANDLE_OP_X_DOUBLE(OP_MUL_DOUBLE, "mul", *)
2627OP_END
2628
2629/* File: c/OP_DIV_DOUBLE.c */
2630HANDLE_OP_X_DOUBLE(OP_DIV_DOUBLE, "div", /)
2631OP_END
2632
2633/* File: c/OP_REM_DOUBLE.c */
2634HANDLE_OPCODE(OP_REM_DOUBLE /*vAA, vBB, vCC*/)
2635 {
2636 u2 srcRegs;
2637 vdst = INST_AA(inst);
2638 srcRegs = FETCH(1);
2639 vsrc1 = srcRegs & 0xff;
2640 vsrc2 = srcRegs >> 8;
2641 ILOGV("|%s-double v%d,v%d,v%d", "mod", vdst, vsrc1, vsrc2);
2642 SET_REGISTER_DOUBLE(vdst,
2643 fmod(GET_REGISTER_DOUBLE(vsrc1), GET_REGISTER_DOUBLE(vsrc2)));
2644 }
2645 FINISH(2);
2646OP_END
2647
2648/* File: c/OP_ADD_INT_2ADDR.c */
2649HANDLE_OP_X_INT_2ADDR(OP_ADD_INT_2ADDR, "add", +, 0)
2650OP_END
2651
2652/* File: c/OP_SUB_INT_2ADDR.c */
2653HANDLE_OP_X_INT_2ADDR(OP_SUB_INT_2ADDR, "sub", -, 0)
2654OP_END
2655
2656/* File: c/OP_MUL_INT_2ADDR.c */
2657HANDLE_OP_X_INT_2ADDR(OP_MUL_INT_2ADDR, "mul", *, 0)
2658OP_END
2659
2660/* File: c/OP_DIV_INT_2ADDR.c */
2661HANDLE_OP_X_INT_2ADDR(OP_DIV_INT_2ADDR, "div", /, 1)
2662OP_END
2663
2664/* File: c/OP_REM_INT_2ADDR.c */
2665HANDLE_OP_X_INT_2ADDR(OP_REM_INT_2ADDR, "rem", %, 2)
2666OP_END
2667
2668/* File: c/OP_AND_INT_2ADDR.c */
2669HANDLE_OP_X_INT_2ADDR(OP_AND_INT_2ADDR, "and", &, 0)
2670OP_END
2671
2672/* File: c/OP_OR_INT_2ADDR.c */
2673HANDLE_OP_X_INT_2ADDR(OP_OR_INT_2ADDR, "or", |, 0)
2674OP_END
2675
2676/* File: c/OP_XOR_INT_2ADDR.c */
2677HANDLE_OP_X_INT_2ADDR(OP_XOR_INT_2ADDR, "xor", ^, 0)
2678OP_END
2679
2680/* File: c/OP_SHL_INT_2ADDR.c */
2681HANDLE_OP_SHX_INT_2ADDR(OP_SHL_INT_2ADDR, "shl", (s4), <<)
2682OP_END
2683
2684/* File: c/OP_SHR_INT_2ADDR.c */
2685HANDLE_OP_SHX_INT_2ADDR(OP_SHR_INT_2ADDR, "shr", (s4), >>)
2686OP_END
2687
2688/* File: c/OP_USHR_INT_2ADDR.c */
2689HANDLE_OP_SHX_INT_2ADDR(OP_USHR_INT_2ADDR, "ushr", (u4), >>)
2690OP_END
2691
2692/* File: c/OP_ADD_LONG_2ADDR.c */
2693HANDLE_OP_X_LONG_2ADDR(OP_ADD_LONG_2ADDR, "add", +, 0)
2694OP_END
2695
2696/* File: c/OP_SUB_LONG_2ADDR.c */
2697HANDLE_OP_X_LONG_2ADDR(OP_SUB_LONG_2ADDR, "sub", -, 0)
2698OP_END
2699
2700/* File: c/OP_MUL_LONG_2ADDR.c */
2701HANDLE_OP_X_LONG_2ADDR(OP_MUL_LONG_2ADDR, "mul", *, 0)
2702OP_END
2703
2704/* File: c/OP_DIV_LONG_2ADDR.c */
2705HANDLE_OP_X_LONG_2ADDR(OP_DIV_LONG_2ADDR, "div", /, 1)
2706OP_END
2707
2708/* File: c/OP_REM_LONG_2ADDR.c */
2709HANDLE_OP_X_LONG_2ADDR(OP_REM_LONG_2ADDR, "rem", %, 2)
2710OP_END
2711
2712/* File: c/OP_AND_LONG_2ADDR.c */
2713HANDLE_OP_X_LONG_2ADDR(OP_AND_LONG_2ADDR, "and", &, 0)
2714OP_END
2715
2716/* File: c/OP_OR_LONG_2ADDR.c */
2717HANDLE_OP_X_LONG_2ADDR(OP_OR_LONG_2ADDR, "or", |, 0)
2718OP_END
2719
2720/* File: c/OP_XOR_LONG_2ADDR.c */
2721HANDLE_OP_X_LONG_2ADDR(OP_XOR_LONG_2ADDR, "xor", ^, 0)
2722OP_END
2723
2724/* File: c/OP_SHL_LONG_2ADDR.c */
2725HANDLE_OP_SHX_LONG_2ADDR(OP_SHL_LONG_2ADDR, "shl", (s8), <<)
2726OP_END
2727
2728/* File: c/OP_SHR_LONG_2ADDR.c */
2729HANDLE_OP_SHX_LONG_2ADDR(OP_SHR_LONG_2ADDR, "shr", (s8), >>)
2730OP_END
2731
2732/* File: c/OP_USHR_LONG_2ADDR.c */
2733HANDLE_OP_SHX_LONG_2ADDR(OP_USHR_LONG_2ADDR, "ushr", (u8), >>)
2734OP_END
2735
2736/* File: c/OP_ADD_FLOAT_2ADDR.c */
2737HANDLE_OP_X_FLOAT_2ADDR(OP_ADD_FLOAT_2ADDR, "add", +)
2738OP_END
2739
2740/* File: c/OP_SUB_FLOAT_2ADDR.c */
2741HANDLE_OP_X_FLOAT_2ADDR(OP_SUB_FLOAT_2ADDR, "sub", -)
2742OP_END
2743
2744/* File: c/OP_MUL_FLOAT_2ADDR.c */
2745HANDLE_OP_X_FLOAT_2ADDR(OP_MUL_FLOAT_2ADDR, "mul", *)
2746OP_END
2747
2748/* File: c/OP_DIV_FLOAT_2ADDR.c */
2749HANDLE_OP_X_FLOAT_2ADDR(OP_DIV_FLOAT_2ADDR, "div", /)
2750OP_END
2751
2752/* File: c/OP_REM_FLOAT_2ADDR.c */
2753HANDLE_OPCODE(OP_REM_FLOAT_2ADDR /*vA, vB*/)
2754 vdst = INST_A(inst);
2755 vsrc1 = INST_B(inst);
2756 ILOGV("|%s-float-2addr v%d,v%d", "mod", vdst, vsrc1);
2757 SET_REGISTER_FLOAT(vdst,
2758 fmodf(GET_REGISTER_FLOAT(vdst), GET_REGISTER_FLOAT(vsrc1)));
2759 FINISH(1);
2760OP_END
2761
2762/* File: c/OP_ADD_DOUBLE_2ADDR.c */
2763HANDLE_OP_X_DOUBLE_2ADDR(OP_ADD_DOUBLE_2ADDR, "add", +)
2764OP_END
2765
2766/* File: c/OP_SUB_DOUBLE_2ADDR.c */
2767HANDLE_OP_X_DOUBLE_2ADDR(OP_SUB_DOUBLE_2ADDR, "sub", -)
2768OP_END
2769
2770/* File: c/OP_MUL_DOUBLE_2ADDR.c */
2771HANDLE_OP_X_DOUBLE_2ADDR(OP_MUL_DOUBLE_2ADDR, "mul", *)
2772OP_END
2773
2774/* File: c/OP_DIV_DOUBLE_2ADDR.c */
2775HANDLE_OP_X_DOUBLE_2ADDR(OP_DIV_DOUBLE_2ADDR, "div", /)
2776OP_END
2777
2778/* File: c/OP_REM_DOUBLE_2ADDR.c */
2779HANDLE_OPCODE(OP_REM_DOUBLE_2ADDR /*vA, vB*/)
2780 vdst = INST_A(inst);
2781 vsrc1 = INST_B(inst);
2782 ILOGV("|%s-double-2addr v%d,v%d", "mod", vdst, vsrc1);
2783 SET_REGISTER_DOUBLE(vdst,
2784 fmod(GET_REGISTER_DOUBLE(vdst), GET_REGISTER_DOUBLE(vsrc1)));
2785 FINISH(1);
2786OP_END
2787
2788/* File: c/OP_ADD_INT_LIT16.c */
2789HANDLE_OP_X_INT_LIT16(OP_ADD_INT_LIT16, "add", +, 0)
2790OP_END
2791
2792/* File: c/OP_RSUB_INT.c */
2793HANDLE_OPCODE(OP_RSUB_INT /*vA, vB, #+CCCC*/)
2794 {
2795 vdst = INST_A(inst);
2796 vsrc1 = INST_B(inst);
2797 vsrc2 = FETCH(1);
2798 ILOGV("|rsub-int v%d,v%d,#+0x%04x", vdst, vsrc1, vsrc2);
2799 SET_REGISTER(vdst, (s2) vsrc2 - (s4) GET_REGISTER(vsrc1));
2800 }
2801 FINISH(2);
2802OP_END
2803
2804/* File: c/OP_MUL_INT_LIT16.c */
2805HANDLE_OP_X_INT_LIT16(OP_MUL_INT_LIT16, "mul", *, 0)
2806OP_END
2807
2808/* File: c/OP_DIV_INT_LIT16.c */
2809HANDLE_OP_X_INT_LIT16(OP_DIV_INT_LIT16, "div", /, 1)
2810OP_END
2811
2812/* File: c/OP_REM_INT_LIT16.c */
2813HANDLE_OP_X_INT_LIT16(OP_REM_INT_LIT16, "rem", %, 2)
2814OP_END
2815
2816/* File: c/OP_AND_INT_LIT16.c */
2817HANDLE_OP_X_INT_LIT16(OP_AND_INT_LIT16, "and", &, 0)
2818OP_END
2819
2820/* File: c/OP_OR_INT_LIT16.c */
2821HANDLE_OP_X_INT_LIT16(OP_OR_INT_LIT16, "or", |, 0)
2822OP_END
2823
2824/* File: c/OP_XOR_INT_LIT16.c */
2825HANDLE_OP_X_INT_LIT16(OP_XOR_INT_LIT16, "xor", ^, 0)
2826OP_END
2827
2828/* File: c/OP_ADD_INT_LIT8.c */
2829HANDLE_OP_X_INT_LIT8(OP_ADD_INT_LIT8, "add", +, 0)
2830OP_END
2831
2832/* File: c/OP_RSUB_INT_LIT8.c */
2833HANDLE_OPCODE(OP_RSUB_INT_LIT8 /*vAA, vBB, #+CC*/)
2834 {
2835 u2 litInfo;
2836 vdst = INST_AA(inst);
2837 litInfo = FETCH(1);
2838 vsrc1 = litInfo & 0xff;
2839 vsrc2 = litInfo >> 8;
2840 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", "rsub", vdst, vsrc1, vsrc2);
2841 SET_REGISTER(vdst, (s1) vsrc2 - (s4) GET_REGISTER(vsrc1));
2842 }
2843 FINISH(2);
2844OP_END
2845
2846/* File: c/OP_MUL_INT_LIT8.c */
2847HANDLE_OP_X_INT_LIT8(OP_MUL_INT_LIT8, "mul", *, 0)
2848OP_END
2849
2850/* File: c/OP_DIV_INT_LIT8.c */
2851HANDLE_OP_X_INT_LIT8(OP_DIV_INT_LIT8, "div", /, 1)
2852OP_END
2853
2854/* File: c/OP_REM_INT_LIT8.c */
2855HANDLE_OP_X_INT_LIT8(OP_REM_INT_LIT8, "rem", %, 2)
2856OP_END
2857
2858/* File: c/OP_AND_INT_LIT8.c */
2859HANDLE_OP_X_INT_LIT8(OP_AND_INT_LIT8, "and", &, 0)
2860OP_END
2861
2862/* File: c/OP_OR_INT_LIT8.c */
2863HANDLE_OP_X_INT_LIT8(OP_OR_INT_LIT8, "or", |, 0)
2864OP_END
2865
2866/* File: c/OP_XOR_INT_LIT8.c */
2867HANDLE_OP_X_INT_LIT8(OP_XOR_INT_LIT8, "xor", ^, 0)
2868OP_END
2869
2870/* File: c/OP_SHL_INT_LIT8.c */
2871HANDLE_OP_SHX_INT_LIT8(OP_SHL_INT_LIT8, "shl", (s4), <<)
2872OP_END
2873
2874/* File: c/OP_SHR_INT_LIT8.c */
2875HANDLE_OP_SHX_INT_LIT8(OP_SHR_INT_LIT8, "shr", (s4), >>)
2876OP_END
2877
2878/* File: c/OP_USHR_INT_LIT8.c */
2879HANDLE_OP_SHX_INT_LIT8(OP_USHR_INT_LIT8, "ushr", (u4), >>)
2880OP_END
2881
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07002882/* File: c/OP_IGET_VOLATILE.c */
2883HANDLE_IGET_X(OP_IGET_VOLATILE, "-volatile", IntVolatile, )
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002884OP_END
2885
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07002886/* File: c/OP_IPUT_VOLATILE.c */
2887HANDLE_IPUT_X(OP_IPUT_VOLATILE, "-volatile", IntVolatile, )
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002888OP_END
2889
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07002890/* File: c/OP_SGET_VOLATILE.c */
2891HANDLE_SGET_X(OP_SGET_VOLATILE, "-volatile", IntVolatile, )
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002892OP_END
2893
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07002894/* File: c/OP_SPUT_VOLATILE.c */
2895HANDLE_SPUT_X(OP_SPUT_VOLATILE, "-volatile", IntVolatile, )
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002896OP_END
2897
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07002898/* File: c/OP_IGET_OBJECT_VOLATILE.c */
2899HANDLE_IGET_X(OP_IGET_OBJECT_VOLATILE, "-object-volatile", ObjectVolatile, _AS_OBJECT)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002900OP_END
2901
Andy McFadden53878242010-03-05 07:24:27 -08002902/* File: c/OP_IGET_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002903HANDLE_IGET_X(OP_IGET_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002904OP_END
2905
Andy McFadden53878242010-03-05 07:24:27 -08002906/* File: c/OP_IPUT_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002907HANDLE_IPUT_X(OP_IPUT_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002908OP_END
2909
Andy McFadden53878242010-03-05 07:24:27 -08002910/* File: c/OP_SGET_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002911HANDLE_SGET_X(OP_SGET_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002912OP_END
2913
Andy McFadden53878242010-03-05 07:24:27 -08002914/* File: c/OP_SPUT_WIDE_VOLATILE.c */
Andy McFadden861b3382010-03-05 15:58:31 -08002915HANDLE_SPUT_X(OP_SPUT_WIDE_VOLATILE, "-wide-volatile", LongVolatile, _WIDE)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002916OP_END
2917
Andy McFadden96516932009-10-28 17:39:02 -07002918/* File: c/OP_BREAKPOINT.c */
2919HANDLE_OPCODE(OP_BREAKPOINT)
Andy McFadden0d615c32010-08-18 12:19:51 -07002920#if (INTERP_TYPE == INTERP_DBG)
Andy McFadden96516932009-10-28 17:39:02 -07002921 {
2922 /*
2923 * Restart this instruction with the original opcode. We do
2924 * this by simply jumping to the handler.
2925 *
2926 * It's probably not necessary to update "inst", but we do it
2927 * for the sake of anything that needs to do disambiguation in a
2928 * common handler with INST_INST.
2929 *
2930 * The breakpoint itself is handled over in updateDebugger(),
2931 * because we need to detect other events (method entry, single
2932 * step) and report them in the same event packet, and we're not
2933 * yet handling those through breakpoint instructions. By the
2934 * time we get here, the breakpoint has already been handled and
2935 * the thread resumed.
2936 */
2937 u1 originalOpCode = dvmGetOriginalOpCode(pc);
2938 LOGV("+++ break 0x%02x (0x%04x -> 0x%04x)\n", originalOpCode, inst,
2939 INST_REPLACE_OP(inst, originalOpCode));
2940 inst = INST_REPLACE_OP(inst, originalOpCode);
2941 FINISH_BKPT(originalOpCode);
2942 }
2943#else
2944 LOGE("Breakpoint hit in non-debug interpreter\n");
2945 dvmAbort();
2946#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002947OP_END
2948
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002949/* File: c/OP_THROW_VERIFICATION_ERROR.c */
2950HANDLE_OPCODE(OP_THROW_VERIFICATION_ERROR)
Andy McFaddenb51ea112009-05-08 16:50:17 -07002951 EXPORT_PC();
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002952 vsrc1 = INST_AA(inst);
2953 ref = FETCH(1); /* class/field/method ref */
Andy McFaddenb51ea112009-05-08 16:50:17 -07002954 dvmThrowVerificationError(curMethod, vsrc1, ref);
Andy McFadden3a1aedb2009-05-07 13:30:23 -07002955 GOTO_exceptionThrown();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002956OP_END
2957
2958/* File: c/OP_EXECUTE_INLINE.c */
2959HANDLE_OPCODE(OP_EXECUTE_INLINE /*vB, {vD, vE, vF, vG}, inline@CCCC*/)
2960 {
2961 /*
2962 * This has the same form as other method calls, but we ignore
2963 * the 5th argument (vA). This is chiefly because the first four
2964 * arguments to a function on ARM are in registers.
2965 *
2966 * We only set the arguments that are actually used, leaving
2967 * the rest uninitialized. We're assuming that, if the method
2968 * needs them, they'll be specified in the call.
2969 *
Carl Shapiro7bbb9ce2009-12-21 18:34:11 -08002970 * However, this annoys gcc when optimizations are enabled,
2971 * causing a "may be used uninitialized" warning. Quieting
2972 * the warnings incurs a slight penalty (5%: 373ns vs. 393ns
2973 * on empty method). Note that valgrind is perfectly happy
2974 * either way as the uninitialiezd values are never actually
2975 * used.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002976 */
2977 u4 arg0, arg1, arg2, arg3;
Carl Shapiro7bbb9ce2009-12-21 18:34:11 -08002978 arg0 = arg1 = arg2 = arg3 = 0;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08002979
2980 EXPORT_PC();
2981
2982 vsrc1 = INST_B(inst); /* #of args */
2983 ref = FETCH(1); /* inline call "ref" */
2984 vdst = FETCH(2); /* 0-4 register indices */
2985 ILOGV("|execute-inline args=%d @%d {regs=0x%04x}",
2986 vsrc1, ref, vdst);
2987
2988 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
2989 assert(vsrc1 <= 4);
2990
2991 switch (vsrc1) {
2992 case 4:
2993 arg3 = GET_REGISTER(vdst >> 12);
2994 /* fall through */
2995 case 3:
2996 arg2 = GET_REGISTER((vdst & 0x0f00) >> 8);
2997 /* fall through */
2998 case 2:
2999 arg1 = GET_REGISTER((vdst & 0x00f0) >> 4);
3000 /* fall through */
3001 case 1:
3002 arg0 = GET_REGISTER(vdst & 0x0f);
3003 /* fall through */
3004 default: // case 0
3005 ;
3006 }
3007
3008#if INTERP_TYPE == INTERP_DBG
3009 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
3010 GOTO_exceptionThrown();
3011#else
3012 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
3013 GOTO_exceptionThrown();
3014#endif
3015 }
3016 FINISH(3);
3017OP_END
3018
Andy McFaddenb0a05412009-11-19 10:23:41 -08003019/* File: c/OP_EXECUTE_INLINE_RANGE.c */
3020HANDLE_OPCODE(OP_EXECUTE_INLINE_RANGE /*{vCCCC..v(CCCC+AA-1)}, inline@BBBB*/)
3021 {
3022 u4 arg0, arg1, arg2, arg3;
3023 arg0 = arg1 = arg2 = arg3 = 0; /* placate gcc */
3024
3025 EXPORT_PC();
3026
3027 vsrc1 = INST_AA(inst); /* #of args */
3028 ref = FETCH(1); /* inline call "ref" */
3029 vdst = FETCH(2); /* range base */
3030 ILOGV("|execute-inline-range args=%d @%d {regs=v%d-v%d}",
3031 vsrc1, ref, vdst, vdst+vsrc1-1);
3032
3033 assert((vdst >> 16) == 0); // 16-bit type -or- high 16 bits clear
3034 assert(vsrc1 <= 4);
3035
3036 switch (vsrc1) {
3037 case 4:
3038 arg3 = GET_REGISTER(vdst+3);
3039 /* fall through */
3040 case 3:
3041 arg2 = GET_REGISTER(vdst+2);
3042 /* fall through */
3043 case 2:
3044 arg1 = GET_REGISTER(vdst+1);
3045 /* fall through */
3046 case 1:
3047 arg0 = GET_REGISTER(vdst+0);
3048 /* fall through */
3049 default: // case 0
3050 ;
3051 }
3052
3053#if INTERP_TYPE == INTERP_DBG
3054 if (!dvmPerformInlineOp4Dbg(arg0, arg1, arg2, arg3, &retval, ref))
3055 GOTO_exceptionThrown();
3056#else
3057 if (!dvmPerformInlineOp4Std(arg0, arg1, arg2, arg3, &retval, ref))
3058 GOTO_exceptionThrown();
3059#endif
3060 }
3061 FINISH(3);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003062OP_END
3063
3064/* File: c/OP_INVOKE_DIRECT_EMPTY.c */
3065HANDLE_OPCODE(OP_INVOKE_DIRECT_EMPTY /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3066#if INTERP_TYPE != INTERP_DBG
3067 //LOGI("Ignoring empty\n");
3068 FINISH(3);
3069#else
3070 if (!gDvm.debuggerActive) {
3071 //LOGI("Skipping empty\n");
3072 FINISH(3); // don't want it to show up in profiler output
3073 } else {
3074 //LOGI("Running empty\n");
3075 /* fall through to OP_INVOKE_DIRECT */
3076 GOTO_invoke(invokeDirect, false);
3077 }
3078#endif
3079OP_END
3080
Andy McFadden291758c2010-09-10 08:04:52 -07003081/* File: c/OP_RETURN_VOID_BARRIER.c */
3082HANDLE_OPCODE(OP_RETURN_VOID_BARRIER /**/)
3083 ILOGV("|return-void");
3084#ifndef NDEBUG
3085 retval.j = 0xababababULL; /* placate valgrind */
3086#endif
Andy McFadden1df319e2010-09-15 13:40:01 -07003087 ANDROID_MEMBAR_STORE();
Andy McFadden291758c2010-09-10 08:04:52 -07003088 GOTO_returnFromMethod();
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003089OP_END
3090
3091/* File: c/OP_IGET_QUICK.c */
3092HANDLE_IGET_X_QUICK(OP_IGET_QUICK, "", Int, )
3093OP_END
3094
3095/* File: c/OP_IGET_WIDE_QUICK.c */
3096HANDLE_IGET_X_QUICK(OP_IGET_WIDE_QUICK, "-wide", Long, _WIDE)
3097OP_END
3098
3099/* File: c/OP_IGET_OBJECT_QUICK.c */
3100HANDLE_IGET_X_QUICK(OP_IGET_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
3101OP_END
3102
3103/* File: c/OP_IPUT_QUICK.c */
3104HANDLE_IPUT_X_QUICK(OP_IPUT_QUICK, "", Int, )
3105OP_END
3106
3107/* File: c/OP_IPUT_WIDE_QUICK.c */
3108HANDLE_IPUT_X_QUICK(OP_IPUT_WIDE_QUICK, "-wide", Long, _WIDE)
3109OP_END
3110
3111/* File: c/OP_IPUT_OBJECT_QUICK.c */
3112HANDLE_IPUT_X_QUICK(OP_IPUT_OBJECT_QUICK, "-object", Object, _AS_OBJECT)
3113OP_END
3114
3115/* File: c/OP_INVOKE_VIRTUAL_QUICK.c */
3116HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3117 GOTO_invoke(invokeVirtualQuick, false);
3118OP_END
3119
3120/* File: c/OP_INVOKE_VIRTUAL_QUICK_RANGE.c */
3121HANDLE_OPCODE(OP_INVOKE_VIRTUAL_QUICK_RANGE/*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
3122 GOTO_invoke(invokeVirtualQuick, true);
3123OP_END
3124
3125/* File: c/OP_INVOKE_SUPER_QUICK.c */
3126HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK /*vB, {vD, vE, vF, vG, vA}, meth@CCCC*/)
3127 GOTO_invoke(invokeSuperQuick, false);
3128OP_END
3129
3130/* File: c/OP_INVOKE_SUPER_QUICK_RANGE.c */
3131HANDLE_OPCODE(OP_INVOKE_SUPER_QUICK_RANGE /*{vCCCC..v(CCCC+AA-1)}, meth@BBBB*/)
3132 GOTO_invoke(invokeSuperQuick, true);
3133OP_END
3134
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07003135/* File: c/OP_IPUT_OBJECT_VOLATILE.c */
3136HANDLE_IPUT_X(OP_IPUT_OBJECT_VOLATILE, "-object-volatile", ObjectVolatile, _AS_OBJECT)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003137OP_END
3138
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07003139/* File: c/OP_SGET_OBJECT_VOLATILE.c */
3140HANDLE_SGET_X(OP_SGET_OBJECT_VOLATILE, "-object-volatile", ObjectVolatile, _AS_OBJECT)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003141OP_END
3142
Andy McFaddenc35a2ef2010-06-17 12:36:00 -07003143/* File: c/OP_SPUT_OBJECT_VOLATILE.c */
3144HANDLE_SPUT_X(OP_SPUT_OBJECT_VOLATILE, "-object-volatile", ObjectVolatile, _AS_OBJECT)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003145OP_END
3146
3147/* File: c/OP_UNUSED_FF.c */
3148HANDLE_OPCODE(OP_UNUSED_FF)
3149 /*
3150 * In portable interp, most unused opcodes will fall through to here.
3151 */
3152 LOGE("unknown opcode 0x%02x\n", INST_INST(inst));
3153 dvmAbort();
3154 FINISH(1);
3155OP_END
3156
3157/* File: c/gotoTargets.c */
3158/*
3159 * C footer. This has some common code shared by the various targets.
3160 */
3161
3162/*
3163 * Everything from here on is a "goto target". In the basic interpreter
3164 * we jump into these targets and then jump directly to the handler for
3165 * next instruction. Here, these are subroutines that return to the caller.
3166 */
3167
3168GOTO_TARGET(filledNewArray, bool methodCallRange)
3169 {
3170 ClassObject* arrayClass;
3171 ArrayObject* newArray;
3172 u4* contents;
3173 char typeCh;
3174 int i;
3175 u4 arg5;
3176
3177 EXPORT_PC();
3178
3179 ref = FETCH(1); /* class ref */
3180 vdst = FETCH(2); /* first 4 regs -or- range base */
3181
3182 if (methodCallRange) {
3183 vsrc1 = INST_AA(inst); /* #of elements */
3184 arg5 = -1; /* silence compiler warning */
3185 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
3186 vsrc1, ref, vdst, vdst+vsrc1-1);
3187 } else {
3188 arg5 = INST_A(inst);
3189 vsrc1 = INST_B(inst); /* #of elements */
3190 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
3191 vsrc1, ref, vdst, arg5);
3192 }
3193
3194 /*
3195 * Resolve the array class.
3196 */
3197 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
3198 if (arrayClass == NULL) {
3199 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
3200 if (arrayClass == NULL)
3201 GOTO_exceptionThrown();
3202 }
3203 /*
3204 if (!dvmIsArrayClass(arrayClass)) {
3205 dvmThrowException("Ljava/lang/RuntimeError;",
3206 "filled-new-array needs array class");
3207 GOTO_exceptionThrown();
3208 }
3209 */
3210 /* verifier guarantees this is an array class */
3211 assert(dvmIsArrayClass(arrayClass));
3212 assert(dvmIsClassInitialized(arrayClass));
3213
3214 /*
3215 * Create an array of the specified type.
3216 */
3217 LOGVV("+++ filled-new-array type is '%s'\n", arrayClass->descriptor);
3218 typeCh = arrayClass->descriptor[1];
3219 if (typeCh == 'D' || typeCh == 'J') {
3220 /* category 2 primitives not allowed */
3221 dvmThrowException("Ljava/lang/RuntimeError;",
3222 "bad filled array req");
3223 GOTO_exceptionThrown();
3224 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
3225 /* TODO: requires multiple "fill in" loops with different widths */
3226 LOGE("non-int primitives not implemented\n");
3227 dvmThrowException("Ljava/lang/InternalError;",
3228 "filled-new-array not implemented for anything but 'int'");
3229 GOTO_exceptionThrown();
3230 }
3231
3232 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
3233 if (newArray == NULL)
3234 GOTO_exceptionThrown();
3235
3236 /*
3237 * Fill in the elements. It's legal for vsrc1 to be zero.
3238 */
3239 contents = (u4*) newArray->contents;
3240 if (methodCallRange) {
3241 for (i = 0; i < vsrc1; i++)
3242 contents[i] = GET_REGISTER(vdst+i);
3243 } else {
3244 assert(vsrc1 <= 5);
3245 if (vsrc1 == 5) {
3246 contents[4] = GET_REGISTER(arg5);
3247 vsrc1--;
3248 }
3249 for (i = 0; i < vsrc1; i++) {
3250 contents[i] = GET_REGISTER(vdst & 0x0f);
3251 vdst >>= 4;
3252 }
3253 }
Barry Hayes364f9d92010-06-11 16:12:47 -07003254 if (typeCh == 'L' || typeCh == '[') {
3255 dvmWriteBarrierArray(newArray, 0, newArray->length);
3256 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003257
3258 retval.l = newArray;
3259 }
3260 FINISH(3);
3261GOTO_TARGET_END
3262
3263
3264GOTO_TARGET(invokeVirtual, bool methodCallRange)
3265 {
3266 Method* baseMethod;
3267 Object* thisPtr;
3268
3269 EXPORT_PC();
3270
3271 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3272 ref = FETCH(1); /* method ref */
3273 vdst = FETCH(2); /* 4 regs -or- first reg */
3274
3275 /*
3276 * The object against which we are executing a method is always
3277 * in the first argument.
3278 */
3279 if (methodCallRange) {
3280 assert(vsrc1 > 0);
3281 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
3282 vsrc1, ref, vdst, vdst+vsrc1-1);
3283 thisPtr = (Object*) GET_REGISTER(vdst);
3284 } else {
3285 assert((vsrc1>>4) > 0);
3286 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
3287 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3288 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3289 }
3290
3291 if (!checkForNull(thisPtr))
3292 GOTO_exceptionThrown();
3293
3294 /*
3295 * Resolve the method. This is the correct method for the static
3296 * type of the object. We also verify access permissions here.
3297 */
3298 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3299 if (baseMethod == NULL) {
3300 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3301 if (baseMethod == NULL) {
3302 ILOGV("+ unknown method or access denied\n");
3303 GOTO_exceptionThrown();
3304 }
3305 }
3306
3307 /*
3308 * Combine the object we found with the vtable offset in the
3309 * method.
3310 */
3311 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
3312 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
3313
Ben Cheng7a2697d2010-06-07 13:44:23 -07003314#if defined(WITH_JIT) && (INTERP_TYPE == INTERP_DBG)
3315 callsiteClass = thisPtr->clazz;
3316#endif
3317
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003318#if 0
3319 if (dvmIsAbstractMethod(methodToCall)) {
3320 /*
3321 * This can happen if you create two classes, Base and Sub, where
3322 * Sub is a sub-class of Base. Declare a protected abstract
3323 * method foo() in Base, and invoke foo() from a method in Base.
3324 * Base is an "abstract base class" and is never instantiated
3325 * directly. Now, Override foo() in Sub, and use Sub. This
3326 * Works fine unless Sub stops providing an implementation of
3327 * the method.
3328 */
3329 dvmThrowException("Ljava/lang/AbstractMethodError;",
3330 "abstract method not implemented");
3331 GOTO_exceptionThrown();
3332 }
3333#else
3334 assert(!dvmIsAbstractMethod(methodToCall) ||
3335 methodToCall->nativeFunc != NULL);
3336#endif
3337
3338 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s\n",
3339 baseMethod->clazz->descriptor, baseMethod->name,
3340 (u4) baseMethod->methodIndex,
3341 methodToCall->clazz->descriptor, methodToCall->name);
3342 assert(methodToCall != NULL);
3343
3344#if 0
3345 if (vsrc1 != methodToCall->insSize) {
3346 LOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s\n",
3347 baseMethod->clazz->descriptor, baseMethod->name,
3348 (u4) baseMethod->methodIndex,
3349 methodToCall->clazz->descriptor, methodToCall->name);
3350 //dvmDumpClass(baseMethod->clazz);
3351 //dvmDumpClass(methodToCall->clazz);
3352 dvmDumpAllClasses(0);
3353 }
3354#endif
3355
3356 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3357 }
3358GOTO_TARGET_END
3359
3360GOTO_TARGET(invokeSuper, bool methodCallRange)
3361 {
3362 Method* baseMethod;
3363 u2 thisReg;
3364
3365 EXPORT_PC();
3366
3367 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3368 ref = FETCH(1); /* method ref */
3369 vdst = FETCH(2); /* 4 regs -or- first reg */
3370
3371 if (methodCallRange) {
3372 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
3373 vsrc1, ref, vdst, vdst+vsrc1-1);
3374 thisReg = vdst;
3375 } else {
3376 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
3377 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3378 thisReg = vdst & 0x0f;
3379 }
3380 /* impossible in well-formed code, but we must check nevertheless */
3381 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3382 GOTO_exceptionThrown();
3383
3384 /*
3385 * Resolve the method. This is the correct method for the static
3386 * type of the object. We also verify access permissions here.
3387 * The first arg to dvmResolveMethod() is just the referring class
3388 * (used for class loaders and such), so we don't want to pass
3389 * the superclass into the resolution call.
3390 */
3391 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
3392 if (baseMethod == NULL) {
3393 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
3394 if (baseMethod == NULL) {
3395 ILOGV("+ unknown method or access denied\n");
3396 GOTO_exceptionThrown();
3397 }
3398 }
3399
3400 /*
3401 * Combine the object we found with the vtable offset in the
3402 * method's class.
3403 *
3404 * We're using the current method's class' superclass, not the
3405 * superclass of "this". This is because we might be executing
3406 * in a method inherited from a superclass, and we want to run
3407 * in that class' superclass.
3408 */
3409 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
3410 /*
3411 * Method does not exist in the superclass. Could happen if
3412 * superclass gets updated.
3413 */
3414 dvmThrowException("Ljava/lang/NoSuchMethodError;",
3415 baseMethod->name);
3416 GOTO_exceptionThrown();
3417 }
3418 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
3419#if 0
3420 if (dvmIsAbstractMethod(methodToCall)) {
3421 dvmThrowException("Ljava/lang/AbstractMethodError;",
3422 "abstract method not implemented");
3423 GOTO_exceptionThrown();
3424 }
3425#else
3426 assert(!dvmIsAbstractMethod(methodToCall) ||
3427 methodToCall->nativeFunc != NULL);
3428#endif
3429 LOGVV("+++ base=%s.%s super-virtual=%s.%s\n",
3430 baseMethod->clazz->descriptor, baseMethod->name,
3431 methodToCall->clazz->descriptor, methodToCall->name);
3432 assert(methodToCall != NULL);
3433
3434 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3435 }
3436GOTO_TARGET_END
3437
3438GOTO_TARGET(invokeInterface, bool methodCallRange)
3439 {
3440 Object* thisPtr;
3441 ClassObject* thisClass;
3442
3443 EXPORT_PC();
3444
3445 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3446 ref = FETCH(1); /* method ref */
3447 vdst = FETCH(2); /* 4 regs -or- first reg */
3448
3449 /*
3450 * The object against which we are executing a method is always
3451 * in the first argument.
3452 */
3453 if (methodCallRange) {
3454 assert(vsrc1 > 0);
3455 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
3456 vsrc1, ref, vdst, vdst+vsrc1-1);
3457 thisPtr = (Object*) GET_REGISTER(vdst);
3458 } else {
3459 assert((vsrc1>>4) > 0);
3460 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
3461 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3462 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3463 }
3464 if (!checkForNull(thisPtr))
3465 GOTO_exceptionThrown();
3466
3467 thisClass = thisPtr->clazz;
3468
Ben Cheng7a2697d2010-06-07 13:44:23 -07003469#if defined(WITH_JIT) && (INTERP_TYPE == INTERP_DBG)
3470 callsiteClass = thisClass;
3471#endif
3472
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003473 /*
3474 * Given a class and a method index, find the Method* with the
3475 * actual code we want to execute.
3476 */
3477 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
3478 methodClassDex);
3479 if (methodToCall == NULL) {
3480 assert(dvmCheckException(self));
3481 GOTO_exceptionThrown();
3482 }
3483
3484 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3485 }
3486GOTO_TARGET_END
3487
3488GOTO_TARGET(invokeDirect, bool methodCallRange)
3489 {
3490 u2 thisReg;
3491
3492 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3493 ref = FETCH(1); /* method ref */
3494 vdst = FETCH(2); /* 4 regs -or- first reg */
3495
3496 EXPORT_PC();
3497
3498 if (methodCallRange) {
3499 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
3500 vsrc1, ref, vdst, vdst+vsrc1-1);
3501 thisReg = vdst;
3502 } else {
3503 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
3504 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3505 thisReg = vdst & 0x0f;
3506 }
3507 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3508 GOTO_exceptionThrown();
3509
3510 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3511 if (methodToCall == NULL) {
3512 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
3513 METHOD_DIRECT);
3514 if (methodToCall == NULL) {
3515 ILOGV("+ unknown direct method\n"); // should be impossible
3516 GOTO_exceptionThrown();
3517 }
3518 }
3519 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3520 }
3521GOTO_TARGET_END
3522
3523GOTO_TARGET(invokeStatic, bool methodCallRange)
3524 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3525 ref = FETCH(1); /* method ref */
3526 vdst = FETCH(2); /* 4 regs -or- first reg */
3527
3528 EXPORT_PC();
3529
3530 if (methodCallRange)
3531 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
3532 vsrc1, ref, vdst, vdst+vsrc1-1);
3533 else
3534 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
3535 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3536
3537 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
3538 if (methodToCall == NULL) {
3539 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
3540 if (methodToCall == NULL) {
3541 ILOGV("+ unknown method\n");
3542 GOTO_exceptionThrown();
3543 }
Ben Chengdd6e8702010-05-07 13:05:47 -07003544
3545 /*
3546 * The JIT needs dvmDexGetResolvedMethod() to return non-null.
3547 * Since we use the portable interpreter to build the trace, this extra
3548 * check is not needed for mterp.
3549 */
3550 if (dvmDexGetResolvedMethod(methodClassDex, ref) == NULL) {
3551 /* Class initialization is still ongoing */
3552 ABORT_JIT_TSELECT();
3553 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003554 }
3555 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3556GOTO_TARGET_END
3557
3558GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
3559 {
3560 Object* thisPtr;
3561
3562 EXPORT_PC();
3563
3564 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3565 ref = FETCH(1); /* vtable index */
3566 vdst = FETCH(2); /* 4 regs -or- first reg */
3567
3568 /*
3569 * The object against which we are executing a method is always
3570 * in the first argument.
3571 */
3572 if (methodCallRange) {
3573 assert(vsrc1 > 0);
3574 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3575 vsrc1, ref, vdst, vdst+vsrc1-1);
3576 thisPtr = (Object*) GET_REGISTER(vdst);
3577 } else {
3578 assert((vsrc1>>4) > 0);
3579 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
3580 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3581 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
3582 }
3583
3584 if (!checkForNull(thisPtr))
3585 GOTO_exceptionThrown();
3586
Ben Cheng7a2697d2010-06-07 13:44:23 -07003587#if defined(WITH_JIT) && (INTERP_TYPE == INTERP_DBG)
3588 callsiteClass = thisPtr->clazz;
3589#endif
3590
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003591 /*
3592 * Combine the object we found with the vtable offset in the
3593 * method.
3594 */
3595 assert(ref < thisPtr->clazz->vtableCount);
3596 methodToCall = thisPtr->clazz->vtable[ref];
3597
3598#if 0
3599 if (dvmIsAbstractMethod(methodToCall)) {
3600 dvmThrowException("Ljava/lang/AbstractMethodError;",
3601 "abstract method not implemented");
3602 GOTO_exceptionThrown();
3603 }
3604#else
3605 assert(!dvmIsAbstractMethod(methodToCall) ||
3606 methodToCall->nativeFunc != NULL);
3607#endif
3608
3609 LOGVV("+++ virtual[%d]=%s.%s\n",
3610 ref, methodToCall->clazz->descriptor, methodToCall->name);
3611 assert(methodToCall != NULL);
3612
3613 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3614 }
3615GOTO_TARGET_END
3616
3617GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
3618 {
3619 u2 thisReg;
3620
3621 EXPORT_PC();
3622
3623 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
3624 ref = FETCH(1); /* vtable index */
3625 vdst = FETCH(2); /* 4 regs -or- first reg */
3626
3627 if (methodCallRange) {
3628 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
3629 vsrc1, ref, vdst, vdst+vsrc1-1);
3630 thisReg = vdst;
3631 } else {
3632 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
3633 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
3634 thisReg = vdst & 0x0f;
3635 }
3636 /* impossible in well-formed code, but we must check nevertheless */
3637 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
3638 GOTO_exceptionThrown();
3639
3640#if 0 /* impossible in optimized + verified code */
3641 if (ref >= curMethod->clazz->super->vtableCount) {
3642 dvmThrowException("Ljava/lang/NoSuchMethodError;", NULL);
3643 GOTO_exceptionThrown();
3644 }
3645#else
3646 assert(ref < curMethod->clazz->super->vtableCount);
3647#endif
3648
3649 /*
3650 * Combine the object we found with the vtable offset in the
3651 * method's class.
3652 *
3653 * We're using the current method's class' superclass, not the
3654 * superclass of "this". This is because we might be executing
3655 * in a method inherited from a superclass, and we want to run
3656 * in the method's class' superclass.
3657 */
3658 methodToCall = curMethod->clazz->super->vtable[ref];
3659
3660#if 0
3661 if (dvmIsAbstractMethod(methodToCall)) {
3662 dvmThrowException("Ljava/lang/AbstractMethodError;",
3663 "abstract method not implemented");
3664 GOTO_exceptionThrown();
3665 }
3666#else
3667 assert(!dvmIsAbstractMethod(methodToCall) ||
3668 methodToCall->nativeFunc != NULL);
3669#endif
3670 LOGVV("+++ super-virtual[%d]=%s.%s\n",
3671 ref, methodToCall->clazz->descriptor, methodToCall->name);
3672 assert(methodToCall != NULL);
3673
3674 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
3675 }
3676GOTO_TARGET_END
3677
3678
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003679 /*
3680 * General handling for return-void, return, and return-wide. Put the
3681 * return value in "retval" before jumping here.
3682 */
3683GOTO_TARGET(returnFromMethod)
3684 {
3685 StackSaveArea* saveArea;
3686
3687 /*
3688 * We must do this BEFORE we pop the previous stack frame off, so
3689 * that the GC can see the return value (if any) in the local vars.
3690 *
3691 * Since this is now an interpreter switch point, we must do it before
3692 * we do anything at all.
3693 */
3694 PERIODIC_CHECKS(kInterpEntryReturn, 0);
3695
3696 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
3697 retval.j, curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04003698 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003699 //DUMP_REGS(curMethod, fp);
3700
3701 saveArea = SAVEAREA_FROM_FP(fp);
3702
3703#ifdef EASY_GDB
3704 debugSaveArea = saveArea;
3705#endif
Andy McFadden0d615c32010-08-18 12:19:51 -07003706#if (INTERP_TYPE == INTERP_DBG)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003707 TRACE_METHOD_EXIT(self, curMethod);
3708#endif
3709
3710 /* back up to previous frame and see if we hit a break */
3711 fp = saveArea->prevFrame;
3712 assert(fp != NULL);
3713 if (dvmIsBreakFrame(fp)) {
3714 /* bail without popping the method frame from stack */
3715 LOGVV("+++ returned into break frame\n");
Bill Buzbeed7269912009-11-10 14:31:32 -08003716#if defined(WITH_JIT)
3717 /* Let the Jit know the return is terminating normally */
Ben Chengfc075c22010-05-28 15:20:08 -07003718 CHECK_JIT_VOID();
Bill Buzbeed7269912009-11-10 14:31:32 -08003719#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003720 GOTO_bail();
3721 }
3722
3723 /* update thread FP, and reset local variables */
3724 self->curFrame = fp;
3725 curMethod = SAVEAREA_FROM_FP(fp)->method;
3726 //methodClass = curMethod->clazz;
3727 methodClassDex = curMethod->clazz->pDvmDex;
3728 pc = saveArea->savedPc;
3729 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003730 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003731
3732 /* use FINISH on the caller's invoke instruction */
3733 //u2 invokeInstr = INST_INST(FETCH(0));
3734 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
3735 invokeInstr <= OP_INVOKE_INTERFACE*/)
3736 {
3737 FINISH(3);
3738 } else {
3739 //LOGE("Unknown invoke instr %02x at %d\n",
3740 // invokeInstr, (int) (pc - curMethod->insns));
3741 assert(false);
3742 }
3743 }
3744GOTO_TARGET_END
3745
3746
3747 /*
3748 * Jump here when the code throws an exception.
3749 *
3750 * By the time we get here, the Throwable has been created and the stack
3751 * trace has been saved off.
3752 */
3753GOTO_TARGET(exceptionThrown)
3754 {
3755 Object* exception;
3756 int catchRelPc;
3757
3758 /*
3759 * Since this is now an interpreter switch point, we must do it before
3760 * we do anything at all.
3761 */
3762 PERIODIC_CHECKS(kInterpEntryThrow, 0);
3763
Ben Cheng79d173c2009-09-29 16:12:51 -07003764#if defined(WITH_JIT)
3765 // Something threw during trace selection - abort the current trace
Bill Buzbee5540f6e2010-02-08 10:41:32 -08003766 ABORT_JIT_TSELECT();
Ben Cheng79d173c2009-09-29 16:12:51 -07003767#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003768 /*
3769 * We save off the exception and clear the exception status. While
3770 * processing the exception we might need to load some Throwable
3771 * classes, and we don't want class loader exceptions to get
3772 * confused with this one.
3773 */
3774 assert(dvmCheckException(self));
3775 exception = dvmGetException(self);
3776 dvmAddTrackedAlloc(exception, self);
3777 dvmClearException(self);
3778
3779 LOGV("Handling exception %s at %s:%d\n",
3780 exception->clazz->descriptor, curMethod->name,
3781 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3782
Andy McFadden0d615c32010-08-18 12:19:51 -07003783#if (INTERP_TYPE == INTERP_DBG)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003784 /*
3785 * Tell the debugger about it.
3786 *
3787 * TODO: if the exception was thrown by interpreted code, control
3788 * fell through native, and then back to us, we will report the
3789 * exception at the point of the throw and again here. We can avoid
3790 * this by not reporting exceptions when we jump here directly from
3791 * the native call code above, but then we won't report exceptions
3792 * that were thrown *from* the JNI code (as opposed to *through* it).
3793 *
3794 * The correct solution is probably to ignore from-native exceptions
3795 * here, and have the JNI exception code do the reporting to the
3796 * debugger.
3797 */
3798 if (gDvm.debuggerActive) {
3799 void* catchFrame;
3800 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3801 exception, true, &catchFrame);
3802 dvmDbgPostException(fp, pc - curMethod->insns, catchFrame,
3803 catchRelPc, exception);
3804 }
3805#endif
3806
3807 /*
3808 * We need to unroll to the catch block or the nearest "break"
3809 * frame.
3810 *
3811 * A break frame could indicate that we have reached an intermediate
3812 * native call, or have gone off the top of the stack and the thread
3813 * needs to exit. Either way, we return from here, leaving the
3814 * exception raised.
3815 *
3816 * If we do find a catch block, we want to transfer execution to
3817 * that point.
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003818 *
3819 * Note this can cause an exception while resolving classes in
3820 * the "catch" blocks.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003821 */
3822 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
3823 exception, false, (void*)&fp);
3824
3825 /*
3826 * Restore the stack bounds after an overflow. This isn't going to
3827 * be correct in all circumstances, e.g. if JNI code devours the
3828 * exception this won't happen until some other exception gets
3829 * thrown. If the code keeps pushing the stack bounds we'll end
3830 * up aborting the VM.
3831 *
3832 * Note we want to do this *after* the call to dvmFindCatchBlock,
3833 * because that may need extra stack space to resolve exception
3834 * classes (e.g. through a class loader).
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003835 *
3836 * It's possible for the stack overflow handling to cause an
3837 * exception (specifically, class resolution in a "catch" block
3838 * during the call above), so we could see the thread's overflow
3839 * flag raised but actually be running in a "nested" interpreter
3840 * frame. We don't allow doubled-up StackOverflowErrors, so
3841 * we can check for this by just looking at the exception type
3842 * in the cleanup function. Also, we won't unroll past the SOE
3843 * point because the more-recent exception will hit a break frame
3844 * as it unrolls to here.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003845 */
3846 if (self->stackOverflowed)
Andy McFadden4fbba1f2010-02-03 07:21:14 -08003847 dvmCleanupStackOverflow(self, exception);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003848
3849 if (catchRelPc < 0) {
3850 /* falling through to JNI code or off the bottom of the stack */
3851#if DVM_SHOW_EXCEPTION >= 2
3852 LOGD("Exception %s from %s:%d not caught locally\n",
3853 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3854 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
3855#endif
3856 dvmSetException(self, exception);
3857 dvmReleaseTrackedAlloc(exception, self);
3858 GOTO_bail();
3859 }
3860
3861#if DVM_SHOW_EXCEPTION >= 3
3862 {
3863 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
3864 LOGD("Exception %s thrown from %s:%d to %s:%d\n",
3865 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
3866 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
3867 dvmGetMethodSourceFile(catchMethod),
3868 dvmLineNumFromPC(catchMethod, catchRelPc));
3869 }
3870#endif
3871
3872 /*
3873 * Adjust local variables to match self->curFrame and the
3874 * updated PC.
3875 */
3876 //fp = (u4*) self->curFrame;
3877 curMethod = SAVEAREA_FROM_FP(fp)->method;
3878 //methodClass = curMethod->clazz;
3879 methodClassDex = curMethod->clazz->pDvmDex;
3880 pc = curMethod->insns + catchRelPc;
3881 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003882 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003883 DUMP_REGS(curMethod, fp, false); // show all regs
3884
3885 /*
3886 * Restore the exception if the handler wants it.
3887 *
3888 * The Dalvik spec mandates that, if an exception handler wants to
3889 * do something with the exception, the first instruction executed
3890 * must be "move-exception". We can pass the exception along
3891 * through the thread struct, and let the move-exception instruction
3892 * clear it for us.
3893 *
3894 * If the handler doesn't call move-exception, we don't want to
3895 * finish here with an exception still pending.
3896 */
3897 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
3898 dvmSetException(self, exception);
3899
3900 dvmReleaseTrackedAlloc(exception, self);
3901 FINISH(0);
3902 }
3903GOTO_TARGET_END
3904
3905
Elliott Hughes8afa9df2010-07-07 14:47:25 -07003906
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003907 /*
3908 * General handling for invoke-{virtual,super,direct,static,interface},
3909 * including "quick" variants.
3910 *
3911 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
3912 * depending on whether this is a "/range" instruction.
3913 *
3914 * For a range call:
3915 * "vsrc1" holds the argument count (8 bits)
3916 * "vdst" holds the first argument in the range
3917 * For a non-range call:
3918 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
3919 * "vdst" holds four 4-bit register indices
3920 *
3921 * The caller must EXPORT_PC before jumping here, because any method
3922 * call can throw a stack overflow exception.
3923 */
3924GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
3925 u2 count, u2 regs)
3926 {
3927 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
3928
3929 //printf("range=%d call=%p count=%d regs=0x%04x\n",
3930 // methodCallRange, methodToCall, count, regs);
3931 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04003932 // methodToCall->name, methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08003933
3934 u4* outs;
3935 int i;
3936
3937 /*
3938 * Copy args. This may corrupt vsrc1/vdst.
3939 */
3940 if (methodCallRange) {
3941 // could use memcpy or a "Duff's device"; most functions have
3942 // so few args it won't matter much
3943 assert(vsrc1 <= curMethod->outsSize);
3944 assert(vsrc1 == methodToCall->insSize);
3945 outs = OUTS_FROM_FP(fp, vsrc1);
3946 for (i = 0; i < vsrc1; i++)
3947 outs[i] = GET_REGISTER(vdst+i);
3948 } else {
3949 u4 count = vsrc1 >> 4;
3950
3951 assert(count <= curMethod->outsSize);
3952 assert(count == methodToCall->insSize);
3953 assert(count <= 5);
3954
3955 outs = OUTS_FROM_FP(fp, count);
3956#if 0
3957 if (count == 5) {
3958 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3959 count--;
3960 }
3961 for (i = 0; i < (int) count; i++) {
3962 outs[i] = GET_REGISTER(vdst & 0x0f);
3963 vdst >>= 4;
3964 }
3965#else
3966 // This version executes fewer instructions but is larger
3967 // overall. Seems to be a teensy bit faster.
3968 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
3969 switch (count) {
3970 case 5:
3971 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
3972 case 4:
3973 outs[3] = GET_REGISTER(vdst >> 12);
3974 case 3:
3975 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
3976 case 2:
3977 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
3978 case 1:
3979 outs[0] = GET_REGISTER(vdst & 0x0f);
3980 default:
3981 ;
3982 }
3983#endif
3984 }
3985 }
3986
3987 /*
3988 * (This was originally a "goto" target; I've kept it separate from the
3989 * stuff above in case we want to refactor things again.)
3990 *
3991 * At this point, we have the arguments stored in the "outs" area of
3992 * the current method's stack frame, and the method to call in
3993 * "methodToCall". Push a new stack frame.
3994 */
3995 {
3996 StackSaveArea* newSaveArea;
3997 u4* newFp;
3998
3999 ILOGV("> %s%s.%s %s",
4000 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
4001 methodToCall->clazz->descriptor, methodToCall->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04004002 methodToCall->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004003
4004 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
4005 newSaveArea = SAVEAREA_FROM_FP(newFp);
4006
4007 /* verify that we have enough space */
4008 if (true) {
4009 u1* bottom;
4010 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
4011 if (bottom < self->interpStackEnd) {
4012 /* stack overflow */
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07004013 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 -08004014 self->interpStackStart, self->interpStackEnd, bottom,
Andy McFadden6ed1a0f2009-09-10 15:34:19 -07004015 (u1*) fp - bottom, self->interpStackSize,
4016 methodToCall->name);
4017 dvmHandleStackOverflow(self, methodToCall);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004018 assert(dvmCheckException(self));
4019 GOTO_exceptionThrown();
4020 }
4021 //LOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p\n",
4022 // fp, newFp, newSaveArea, bottom);
4023 }
4024
4025#ifdef LOG_INSTR
4026 if (methodToCall->registersSize > methodToCall->insSize) {
4027 /*
4028 * This makes valgrind quiet when we print registers that
4029 * haven't been initialized. Turn it off when the debug
4030 * messages are disabled -- we want valgrind to report any
4031 * used-before-initialized issues.
4032 */
4033 memset(newFp, 0xcc,
4034 (methodToCall->registersSize - methodToCall->insSize) * 4);
4035 }
4036#endif
4037
4038#ifdef EASY_GDB
4039 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
4040#endif
4041 newSaveArea->prevFrame = fp;
4042 newSaveArea->savedPc = pc;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004043#if defined(WITH_JIT)
4044 newSaveArea->returnAddr = 0;
4045#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004046 newSaveArea->method = methodToCall;
4047
4048 if (!dvmIsNativeMethod(methodToCall)) {
4049 /*
4050 * "Call" interpreted code. Reposition the PC, update the
4051 * frame pointer and other local state, and continue.
4052 */
4053 curMethod = methodToCall;
4054 methodClassDex = curMethod->clazz->pDvmDex;
4055 pc = methodToCall->insns;
4056 fp = self->curFrame = newFp;
4057#ifdef EASY_GDB
4058 debugSaveArea = SAVEAREA_FROM_FP(newFp);
4059#endif
4060#if INTERP_TYPE == INTERP_DBG
4061 debugIsMethodEntry = true; // profiling, debugging
4062#endif
4063 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
Mike Lockwood85745e12009-07-08 12:39:37 -04004064 curMethod->name, curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004065 DUMP_REGS(curMethod, fp, true); // show input args
4066 FINISH(0); // jump to method start
4067 } else {
4068 /* set this up for JNI locals, even if not a JNI native */
Andy McFaddend5ab7262009-08-25 07:19:34 -07004069#ifdef USE_INDIRECT_REF
4070 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.segmentState.all;
4071#else
4072 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.nextEntry;
4073#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004074
4075 self->curFrame = newFp;
4076
4077 DUMP_REGS(methodToCall, newFp, true); // show input args
4078
Andy McFadden0d615c32010-08-18 12:19:51 -07004079#if (INTERP_TYPE == INTERP_DBG)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004080 if (gDvm.debuggerActive) {
4081 dvmDbgPostLocationEvent(methodToCall, -1,
4082 dvmGetThisPtr(curMethod, fp), DBG_METHOD_ENTRY);
4083 }
4084#endif
Andy McFadden0d615c32010-08-18 12:19:51 -07004085#if (INTERP_TYPE == INTERP_DBG)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004086 TRACE_METHOD_ENTER(self, methodToCall);
4087#endif
4088
Elliott Hughes8afa9df2010-07-07 14:47:25 -07004089 {
4090 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
4091 methodToCall->name, methodToCall->shorty);
4092 }
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004093
Bill Buzbeed7269912009-11-10 14:31:32 -08004094#if defined(WITH_JIT)
4095 /* Allow the Jit to end any pending trace building */
Ben Chengfc075c22010-05-28 15:20:08 -07004096 CHECK_JIT_VOID();
Bill Buzbeed7269912009-11-10 14:31:32 -08004097#endif
4098
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004099 /*
4100 * Jump through native call bridge. Because we leave no
4101 * space for locals on native calls, "newFp" points directly
4102 * to the method arguments.
4103 */
4104 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
4105
Andy McFadden0d615c32010-08-18 12:19:51 -07004106#if (INTERP_TYPE == INTERP_DBG)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004107 if (gDvm.debuggerActive) {
4108 dvmDbgPostLocationEvent(methodToCall, -1,
4109 dvmGetThisPtr(curMethod, fp), DBG_METHOD_EXIT);
4110 }
4111#endif
Andy McFadden0d615c32010-08-18 12:19:51 -07004112#if (INTERP_TYPE == INTERP_DBG)
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004113 TRACE_METHOD_EXIT(self, methodToCall);
4114#endif
4115
4116 /* pop frame off */
4117 dvmPopJniLocals(self, newSaveArea);
4118 self->curFrame = fp;
4119
4120 /*
4121 * If the native code threw an exception, or interpreted code
4122 * invoked by the native call threw one and nobody has cleared
4123 * it, jump to our local exception handling.
4124 */
4125 if (dvmCheckException(self)) {
4126 LOGV("Exception thrown by/below native code\n");
4127 GOTO_exceptionThrown();
4128 }
4129
4130 ILOGD("> retval=0x%llx (leaving native)", retval.j);
4131 ILOGD("> (return from native %s.%s to %s.%s %s)",
4132 methodToCall->clazz->descriptor, methodToCall->name,
4133 curMethod->clazz->descriptor, curMethod->name,
Mike Lockwood85745e12009-07-08 12:39:37 -04004134 curMethod->shorty);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004135
4136 //u2 invokeInstr = INST_INST(FETCH(0));
4137 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
4138 invokeInstr <= OP_INVOKE_INTERFACE*/)
4139 {
4140 FINISH(3);
4141 } else {
4142 //LOGE("Unknown invoke instr %02x at %d\n",
4143 // invokeInstr, (int) (pc - curMethod->insns));
4144 assert(false);
4145 }
4146 }
4147 }
4148 assert(false); // should not get here
4149GOTO_TARGET_END
4150
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004151/* File: portable/enddefs.c */
4152/*--- end of opcodes ---*/
4153
4154#ifndef THREADED_INTERP
4155 } // end of "switch"
4156 } // end of "while"
4157#endif
4158
4159bail:
4160 ILOGD("|-- Leaving interpreter loop"); // note "curMethod" may be NULL
4161
4162 interpState->retval = retval;
4163 return false;
4164
4165bail_switch:
4166 /*
4167 * The standard interpreter currently doesn't set or care about the
4168 * "debugIsMethodEntry" value, so setting this is only of use if we're
4169 * switching between two "debug" interpreters, which we never do.
4170 *
4171 * TODO: figure out if preserving this makes any sense.
4172 */
Andy McFadden0d615c32010-08-18 12:19:51 -07004173#if INTERP_TYPE == INTERP_DBG
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004174 interpState->debugIsMethodEntry = debugIsMethodEntry;
Andy McFadden0d615c32010-08-18 12:19:51 -07004175#else
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004176 interpState->debugIsMethodEntry = false;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08004177#endif
4178
4179 /* export state changes */
4180 interpState->method = curMethod;
4181 interpState->pc = pc;
4182 interpState->fp = fp;
4183 /* debugTrackedRefStart doesn't change */
4184 interpState->retval = retval; /* need for _entryPoint=ret */
4185 interpState->nextMode =
4186 (INTERP_TYPE == INTERP_STD) ? INTERP_DBG : INTERP_STD;
4187 LOGVV(" meth='%s.%s' pc=0x%x fp=%p\n",
4188 curMethod->clazz->descriptor, curMethod->name,
4189 pc - curMethod->insns, fp);
4190 return true;
4191}
4192