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