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