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