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