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