1 /*
2 * This file was generated automatically by gen-mterp.py for 'mips'.
3 *
4 * --> DO NOT EDIT <--
5 */
6
7 /* File: c/header.cpp */
8 /*
9 * Copyright (C) 2008 The Android Open Source Project
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24 /* common includes */
25 #include "Dalvik.h"
26 #include "interp/InterpDefs.h"
27 #include "mterp/Mterp.h"
28 #include <math.h> // needed for fmod, fmodf
29 #include "mterp/common/FindInterface.h"
30
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_INSTR_CHECKS
37 * WITH_TRACKREF_CHECKS
38 * EASY_GDB
39 * NDEBUG
40 */
41
42 #ifdef WITH_INSTR_CHECKS /* instruction-level paranoia (slow!) */
43 # define CHECK_BRANCH_OFFSETS
44 # define CHECK_REGISTER_INDICES
45 #endif
46
47 /*
48 * Some architectures require 64-bit alignment for access to 64-bit data
49 * types. We can't just use pointers to copy 64-bit values out of our
50 * interpreted register set, because gcc may assume the pointer target is
51 * aligned and generate invalid code.
52 *
53 * There are two common approaches:
54 * (1) Use a union that defines a 32-bit pair and a 64-bit value.
55 * (2) Call memcpy().
56 *
57 * Depending upon what compiler you're using and what options are specified,
58 * one may be faster than the other. For example, the compiler might
59 * convert a memcpy() of 8 bytes into a series of instructions and omit
60 * the call. The union version could cause some strange side-effects,
61 * e.g. for a while ARM gcc thought it needed separate storage for each
62 * inlined instance, and generated instructions to zero out ~700 bytes of
63 * stack space at the top of the interpreter.
64 *
65 * The default is to use memcpy(). The current gcc for ARM seems to do
66 * better with the union.
67 */
68 #if defined(__ARM_EABI__)
69 # define NO_UNALIGN_64__UNION
70 #endif
71 /*
72 * MIPS ABI requires 64-bit alignment for access to 64-bit data types.
73 *
74 * Use memcpy() to do the transfer
75 */
76 #if defined(__mips__)
77 /* # define NO_UNALIGN_64__UNION */
78 #endif
79
80
81 //#define LOG_INSTR /* verbose debugging */
82 /* set and adjust ANDROID_LOG_TAGS='*:i jdwp:i dalvikvm:i dalvikvmi:i' */
83
84 /*
85 * Export another copy of the PC on every instruction; this is largely
86 * redundant with EXPORT_PC and the debugger code. This value can be
87 * compared against what we have stored on the stack with EXPORT_PC to
88 * help ensure that we aren't missing any export calls.
89 */
90 #if WITH_EXTRA_GC_CHECKS > 1
91 # define EXPORT_EXTRA_PC() (self->currentPc2 = pc)
92 #else
93 # define EXPORT_EXTRA_PC()
94 #endif
95
96 /*
97 * Adjust the program counter. "_offset" is a signed int, in 16-bit units.
98 *
99 * Assumes the existence of "const u2* pc" and "const u2* curMethod->insns".
100 *
101 * We don't advance the program counter until we finish an instruction or
102 * branch, because we do want to have to unroll the PC if there's an
103 * exception.
104 */
105 #ifdef CHECK_BRANCH_OFFSETS
106 # define ADJUST_PC(_offset) do { \
107 int myoff = _offset; /* deref only once */ \
108 if (pc + myoff < curMethod->insns || \
109 pc + myoff >= curMethod->insns + dvmGetMethodInsnsSize(curMethod)) \
110 { \
111 char* desc; \
112 desc = dexProtoCopyMethodDescriptor(&curMethod->prototype); \
113 ALOGE("Invalid branch %d at 0x%04x in %s.%s %s", \
114 myoff, (int) (pc - curMethod->insns), \
115 curMethod->clazz->descriptor, curMethod->name, desc); \
116 free(desc); \
117 dvmAbort(); \
118 } \
119 pc += myoff; \
120 EXPORT_EXTRA_PC(); \
121 } while (false)
122 #else
123 # define ADJUST_PC(_offset) do { \
124 pc += _offset; \
125 EXPORT_EXTRA_PC(); \
126 } while (false)
127 #endif
128
129 /*
130 * If enabled, log instructions as we execute them.
131 */
132 #ifdef LOG_INSTR
133 # define ILOGD(...) ILOG(LOG_DEBUG, __VA_ARGS__)
134 # define ILOGV(...) ILOG(LOG_VERBOSE, __VA_ARGS__)
135 # define ILOG(_level, ...) do { \
136 char debugStrBuf[128]; \
137 snprintf(debugStrBuf, sizeof(debugStrBuf), __VA_ARGS__); \
138 if (curMethod != NULL) \
139 ALOG(_level, LOG_TAG"i", "%-2d|%04x%s", \
140 self->threadId, (int)(pc - curMethod->insns), debugStrBuf); \
141 else \
142 ALOG(_level, LOG_TAG"i", "%-2d|####%s", \
143 self->threadId, debugStrBuf); \
144 } while(false)
145 void dvmDumpRegs(const Method* method, const u4* framePtr, bool inOnly);
146 # define DUMP_REGS(_meth, _frame, _inOnly) dvmDumpRegs(_meth, _frame, _inOnly)
147 static const char kSpacing[] = " ";
148 #else
149 # define ILOGD(...) ((void)0)
150 # define ILOGV(...) ((void)0)
151 # define DUMP_REGS(_meth, _frame, _inOnly) ((void)0)
152 #endif
153
154 /* get a long from an array of u4 */
getLongFromArray(const u4 * ptr,int idx)155 static inline s8 getLongFromArray(const u4* ptr, int idx)
156 {
157 #if defined(NO_UNALIGN_64__UNION)
158 union { s8 ll; u4 parts[2]; } conv;
159
160 ptr += idx;
161 conv.parts[0] = ptr[0];
162 conv.parts[1] = ptr[1];
163 return conv.ll;
164 #else
165 s8 val;
166 memcpy(&val, &ptr[idx], 8);
167 return val;
168 #endif
169 }
170
171 /* store a long into an array of u4 */
putLongToArray(u4 * ptr,int idx,s8 val)172 static inline void putLongToArray(u4* ptr, int idx, s8 val)
173 {
174 #if defined(NO_UNALIGN_64__UNION)
175 union { s8 ll; u4 parts[2]; } conv;
176
177 ptr += idx;
178 conv.ll = val;
179 ptr[0] = conv.parts[0];
180 ptr[1] = conv.parts[1];
181 #else
182 memcpy(&ptr[idx], &val, 8);
183 #endif
184 }
185
186 /* get a double from an array of u4 */
getDoubleFromArray(const u4 * ptr,int idx)187 static inline double getDoubleFromArray(const u4* ptr, int idx)
188 {
189 #if defined(NO_UNALIGN_64__UNION)
190 union { double d; u4 parts[2]; } conv;
191
192 ptr += idx;
193 conv.parts[0] = ptr[0];
194 conv.parts[1] = ptr[1];
195 return conv.d;
196 #else
197 double dval;
198 memcpy(&dval, &ptr[idx], 8);
199 return dval;
200 #endif
201 }
202
203 /* store a double into an array of u4 */
putDoubleToArray(u4 * ptr,int idx,double dval)204 static inline void putDoubleToArray(u4* ptr, int idx, double dval)
205 {
206 #if defined(NO_UNALIGN_64__UNION)
207 union { double d; u4 parts[2]; } conv;
208
209 ptr += idx;
210 conv.d = dval;
211 ptr[0] = conv.parts[0];
212 ptr[1] = conv.parts[1];
213 #else
214 memcpy(&ptr[idx], &dval, 8);
215 #endif
216 }
217
218 /*
219 * If enabled, validate the register number on every access. Otherwise,
220 * just do an array access.
221 *
222 * Assumes the existence of "u4* fp".
223 *
224 * "_idx" may be referenced more than once.
225 */
226 #ifdef CHECK_REGISTER_INDICES
227 # define GET_REGISTER(_idx) \
228 ( (_idx) < curMethod->registersSize ? \
229 (fp[(_idx)]) : (assert(!"bad reg"),1969) )
230 # define SET_REGISTER(_idx, _val) \
231 ( (_idx) < curMethod->registersSize ? \
232 (fp[(_idx)] = (u4)(_val)) : (assert(!"bad reg"),1969) )
233 # define GET_REGISTER_AS_OBJECT(_idx) ((Object *)GET_REGISTER(_idx))
234 # define SET_REGISTER_AS_OBJECT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
235 # define GET_REGISTER_INT(_idx) ((s4) GET_REGISTER(_idx))
236 # define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
237 # define GET_REGISTER_WIDE(_idx) \
238 ( (_idx) < curMethod->registersSize-1 ? \
239 getLongFromArray(fp, (_idx)) : (assert(!"bad reg"),1969) )
240 # define SET_REGISTER_WIDE(_idx, _val) \
241 ( (_idx) < curMethod->registersSize-1 ? \
242 (void)putLongToArray(fp, (_idx), (_val)) : assert(!"bad reg") )
243 # define GET_REGISTER_FLOAT(_idx) \
244 ( (_idx) < curMethod->registersSize ? \
245 (*((float*) &fp[(_idx)])) : (assert(!"bad reg"),1969.0f) )
246 # define SET_REGISTER_FLOAT(_idx, _val) \
247 ( (_idx) < curMethod->registersSize ? \
248 (*((float*) &fp[(_idx)]) = (_val)) : (assert(!"bad reg"),1969.0f) )
249 # define GET_REGISTER_DOUBLE(_idx) \
250 ( (_idx) < curMethod->registersSize-1 ? \
251 getDoubleFromArray(fp, (_idx)) : (assert(!"bad reg"),1969.0) )
252 # define SET_REGISTER_DOUBLE(_idx, _val) \
253 ( (_idx) < curMethod->registersSize-1 ? \
254 (void)putDoubleToArray(fp, (_idx), (_val)) : assert(!"bad reg") )
255 #else
256 # define GET_REGISTER(_idx) (fp[(_idx)])
257 # define SET_REGISTER(_idx, _val) (fp[(_idx)] = (_val))
258 # define GET_REGISTER_AS_OBJECT(_idx) ((Object*) fp[(_idx)])
259 # define SET_REGISTER_AS_OBJECT(_idx, _val) (fp[(_idx)] = (u4)(_val))
260 # define GET_REGISTER_INT(_idx) ((s4)GET_REGISTER(_idx))
261 # define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
262 # define GET_REGISTER_WIDE(_idx) getLongFromArray(fp, (_idx))
263 # define SET_REGISTER_WIDE(_idx, _val) putLongToArray(fp, (_idx), (_val))
264 # define GET_REGISTER_FLOAT(_idx) (*((float*) &fp[(_idx)]))
265 # define SET_REGISTER_FLOAT(_idx, _val) (*((float*) &fp[(_idx)]) = (_val))
266 # define GET_REGISTER_DOUBLE(_idx) getDoubleFromArray(fp, (_idx))
267 # define SET_REGISTER_DOUBLE(_idx, _val) putDoubleToArray(fp, (_idx), (_val))
268 #endif
269
270 /*
271 * Get 16 bits from the specified offset of the program counter. We always
272 * want to load 16 bits at a time from the instruction stream -- it's more
273 * efficient than 8 and won't have the alignment problems that 32 might.
274 *
275 * Assumes existence of "const u2* pc".
276 */
277 #define FETCH(_offset) (pc[(_offset)])
278
279 /*
280 * Extract instruction byte from 16-bit fetch (_inst is a u2).
281 */
282 #define INST_INST(_inst) ((_inst) & 0xff)
283
284 /*
285 * Replace the opcode (used when handling breakpoints). _opcode is a u1.
286 */
287 #define INST_REPLACE_OP(_inst, _opcode) (((_inst) & 0xff00) | _opcode)
288
289 /*
290 * Extract the "vA, vB" 4-bit registers from the instruction word (_inst is u2).
291 */
292 #define INST_A(_inst) (((_inst) >> 8) & 0x0f)
293 #define INST_B(_inst) ((_inst) >> 12)
294
295 /*
296 * Get the 8-bit "vAA" 8-bit register index from the instruction word.
297 * (_inst is u2)
298 */
299 #define INST_AA(_inst) ((_inst) >> 8)
300
301 /*
302 * The current PC must be available to Throwable constructors, e.g.
303 * those created by the various exception throw routines, so that the
304 * exception stack trace can be generated correctly. If we don't do this,
305 * the offset within the current method won't be shown correctly. See the
306 * notes in Exception.c.
307 *
308 * This is also used to determine the address for precise GC.
309 *
310 * Assumes existence of "u4* fp" and "const u2* pc".
311 */
312 #define EXPORT_PC() (SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc)
313
314 /*
315 * Check to see if "obj" is NULL. If so, throw an exception. Assumes the
316 * pc has already been exported to the stack.
317 *
318 * Perform additional checks on debug builds.
319 *
320 * Use this to check for NULL when the instruction handler calls into
321 * something that could throw an exception (so we have already called
322 * EXPORT_PC at the top).
323 */
checkForNull(Object * obj)324 static inline bool checkForNull(Object* obj)
325 {
326 if (obj == NULL) {
327 dvmThrowNullPointerException(NULL);
328 return false;
329 }
330 #ifdef WITH_EXTRA_OBJECT_VALIDATION
331 if (!dvmIsHeapAddress(obj)) {
332 ALOGE("Invalid object %p", obj);
333 dvmAbort();
334 }
335 #endif
336 #ifndef NDEBUG
337 if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
338 /* probable heap corruption */
339 ALOGE("Invalid object class %p (in %p)", obj->clazz, obj);
340 dvmAbort();
341 }
342 #endif
343 return true;
344 }
345
346 /*
347 * Check to see if "obj" is NULL. If so, export the PC into the stack
348 * frame and throw an exception.
349 *
350 * Perform additional checks on debug builds.
351 *
352 * Use this to check for NULL when the instruction handler doesn't do
353 * anything else that can throw an exception.
354 */
checkForNullExportPC(Object * obj,u4 * fp,const u2 * pc)355 static inline bool checkForNullExportPC(Object* obj, u4* fp, const u2* pc)
356 {
357 if (obj == NULL) {
358 EXPORT_PC();
359 dvmThrowNullPointerException(NULL);
360 return false;
361 }
362 #ifdef WITH_EXTRA_OBJECT_VALIDATION
363 if (!dvmIsHeapAddress(obj)) {
364 ALOGE("Invalid object %p", obj);
365 dvmAbort();
366 }
367 #endif
368 #ifndef NDEBUG
369 if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
370 /* probable heap corruption */
371 ALOGE("Invalid object class %p (in %p)", obj->clazz, obj);
372 dvmAbort();
373 }
374 #endif
375 return true;
376 }
377
378 /* File: cstubs/stubdefs.cpp */
379 /*
380 * In the C mterp stubs, "goto" is a function call followed immediately
381 * by a return.
382 */
383
384 #define GOTO_TARGET_DECL(_target, ...) \
385 extern "C" void dvmMterp_##_target(Thread* self, ## __VA_ARGS__);
386
387 /* (void)xxx to quiet unused variable compiler warnings. */
388 #define GOTO_TARGET(_target, ...) \
389 void dvmMterp_##_target(Thread* self, ## __VA_ARGS__) { \
390 u2 ref, vsrc1, vsrc2, vdst; \
391 u2 inst = FETCH(0); \
392 const Method* methodToCall; \
393 StackSaveArea* debugSaveArea; \
394 (void)ref; (void)vsrc1; (void)vsrc2; (void)vdst; (void)inst; \
395 (void)methodToCall; (void)debugSaveArea;
396
397 #define GOTO_TARGET_END }
398
399 /*
400 * Redefine what used to be local variable accesses into Thread struct
401 * references. (These are undefined down in "footer.cpp".)
402 */
403 #define retval self->interpSave.retval
404 #define pc self->interpSave.pc
405 #define fp self->interpSave.curFrame
406 #define curMethod self->interpSave.method
407 #define methodClassDex self->interpSave.methodClassDex
408 #define debugTrackedRefStart self->interpSave.debugTrackedRefStart
409
410 /* ugh */
411 #define STUB_HACK(x) x
412 #if defined(WITH_JIT)
413 #define JIT_STUB_HACK(x) x
414 #else
415 #define JIT_STUB_HACK(x)
416 #endif
417
418 /*
419 * InterpSave's pc and fp must be valid when breaking out to a
420 * "Reportxxx" routine. Because the portable interpreter uses local
421 * variables for these, we must flush prior. Stubs, however, use
422 * the interpSave vars directly, so this is a nop for stubs.
423 */
424 #define PC_FP_TO_SELF()
425 #define PC_TO_SELF()
426
427 /*
428 * Opcode handler framing macros. Here, each opcode is a separate function
429 * that takes a "self" argument and returns void. We can't declare
430 * these "static" because they may be called from an assembly stub.
431 * (void)xxx to quiet unused variable compiler warnings.
432 */
433 #define HANDLE_OPCODE(_op) \
434 extern "C" void dvmMterp_##_op(Thread* self); \
435 void dvmMterp_##_op(Thread* self) { \
436 u4 ref; \
437 u2 vsrc1, vsrc2, vdst; \
438 u2 inst = FETCH(0); \
439 (void)ref; (void)vsrc1; (void)vsrc2; (void)vdst; (void)inst;
440
441 #define OP_END }
442
443 /*
444 * Like the "portable" FINISH, but don't reload "inst", and return to caller
445 * when done. Further, debugger/profiler checks are handled
446 * before handler execution in mterp, so we don't do them here either.
447 */
448 #if defined(WITH_JIT)
449 #define FINISH(_offset) { \
450 ADJUST_PC(_offset); \
451 if (self->interpBreak.ctl.subMode & kSubModeJitTraceBuild) { \
452 dvmCheckJit(pc, self); \
453 } \
454 return; \
455 }
456 #else
457 #define FINISH(_offset) { \
458 ADJUST_PC(_offset); \
459 return; \
460 }
461 #endif
462
463 #define FINISH_BKPT(_opcode) /* FIXME? */
464 #define DISPATCH_EXTENDED(_opcode) /* FIXME? */
465
466 /*
467 * The "goto label" statements turn into function calls followed by
468 * return statements. Some of the functions take arguments, which in the
469 * portable interpreter are handled by assigning values to globals.
470 */
471
472 #define GOTO_exceptionThrown() \
473 do { \
474 dvmMterp_exceptionThrown(self); \
475 return; \
476 } while(false)
477
478 #define GOTO_returnFromMethod() \
479 do { \
480 dvmMterp_returnFromMethod(self); \
481 return; \
482 } while(false)
483
484 #define GOTO_invoke(_target, _methodCallRange) \
485 do { \
486 dvmMterp_##_target(self, _methodCallRange); \
487 return; \
488 } while(false)
489
490 #define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst) \
491 do { \
492 dvmMterp_invokeMethod(self, _methodCallRange, _methodToCall, \
493 _vsrc1, _vdst); \
494 return; \
495 } while(false)
496
497 /*
498 * As a special case, "goto bail" turns into a longjmp.
499 */
500 #define GOTO_bail() \
501 dvmMterpStdBail(self)
502
503 /*
504 * Periodically check for thread suspension.
505 *
506 * While we're at it, see if a debugger has attached or the profiler has
507 * started.
508 */
509 #define PERIODIC_CHECKS(_pcadj) { \
510 if (dvmCheckSuspendQuick(self)) { \
511 EXPORT_PC(); /* need for precise GC */ \
512 dvmCheckSuspendPending(self); \
513 } \
514 }
515
516 /* File: c/opcommon.cpp */
517 /* forward declarations of goto targets */
518 GOTO_TARGET_DECL(filledNewArray, bool methodCallRange);
519 GOTO_TARGET_DECL(invokeVirtual, bool methodCallRange);
520 GOTO_TARGET_DECL(invokeSuper, bool methodCallRange);
521 GOTO_TARGET_DECL(invokeInterface, bool methodCallRange);
522 GOTO_TARGET_DECL(invokeDirect, bool methodCallRange);
523 GOTO_TARGET_DECL(invokeStatic, bool methodCallRange);
524 GOTO_TARGET_DECL(invokeVirtualQuick, bool methodCallRange);
525 GOTO_TARGET_DECL(invokeSuperQuick, bool methodCallRange);
526 GOTO_TARGET_DECL(invokeMethod, bool methodCallRange, const Method* methodToCall,
527 u2 count, u2 regs);
528 GOTO_TARGET_DECL(returnFromMethod);
529 GOTO_TARGET_DECL(exceptionThrown);
530
531 /*
532 * ===========================================================================
533 *
534 * What follows are opcode definitions shared between multiple opcodes with
535 * minor substitutions handled by the C pre-processor. These should probably
536 * use the mterp substitution mechanism instead, with the code here moved
537 * into common fragment files (like the asm "binop.S"), although it's hard
538 * to give up the C preprocessor in favor of the much simpler text subst.
539 *
540 * ===========================================================================
541 */
542
543 #define HANDLE_NUMCONV(_opcode, _opname, _fromtype, _totype) \
544 HANDLE_OPCODE(_opcode /*vA, vB*/) \
545 vdst = INST_A(inst); \
546 vsrc1 = INST_B(inst); \
547 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
548 SET_REGISTER##_totype(vdst, \
549 GET_REGISTER##_fromtype(vsrc1)); \
550 FINISH(1);
551
552 #define HANDLE_FLOAT_TO_INT(_opcode, _opname, _fromvtype, _fromrtype, \
553 _tovtype, _tortype) \
554 HANDLE_OPCODE(_opcode /*vA, vB*/) \
555 { \
556 /* spec defines specific handling for +/- inf and NaN values */ \
557 _fromvtype val; \
558 _tovtype intMin, intMax, result; \
559 vdst = INST_A(inst); \
560 vsrc1 = INST_B(inst); \
561 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
562 val = GET_REGISTER##_fromrtype(vsrc1); \
563 intMin = (_tovtype) 1 << (sizeof(_tovtype) * 8 -1); \
564 intMax = ~intMin; \
565 result = (_tovtype) val; \
566 if (val >= intMax) /* +inf */ \
567 result = intMax; \
568 else if (val <= intMin) /* -inf */ \
569 result = intMin; \
570 else if (val != val) /* NaN */ \
571 result = 0; \
572 else \
573 result = (_tovtype) val; \
574 SET_REGISTER##_tortype(vdst, result); \
575 } \
576 FINISH(1);
577
578 #define HANDLE_INT_TO_SMALL(_opcode, _opname, _type) \
579 HANDLE_OPCODE(_opcode /*vA, vB*/) \
580 vdst = INST_A(inst); \
581 vsrc1 = INST_B(inst); \
582 ILOGV("|int-to-%s v%d,v%d", (_opname), vdst, vsrc1); \
583 SET_REGISTER(vdst, (_type) GET_REGISTER(vsrc1)); \
584 FINISH(1);
585
586 /* NOTE: the comparison result is always a signed 4-byte integer */
587 #define HANDLE_OP_CMPX(_opcode, _opname, _varType, _type, _nanVal) \
588 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
589 { \
590 int result; \
591 u2 regs; \
592 _varType val1, val2; \
593 vdst = INST_AA(inst); \
594 regs = FETCH(1); \
595 vsrc1 = regs & 0xff; \
596 vsrc2 = regs >> 8; \
597 ILOGV("|cmp%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
598 val1 = GET_REGISTER##_type(vsrc1); \
599 val2 = GET_REGISTER##_type(vsrc2); \
600 if (val1 == val2) \
601 result = 0; \
602 else if (val1 < val2) \
603 result = -1; \
604 else if (val1 > val2) \
605 result = 1; \
606 else \
607 result = (_nanVal); \
608 ILOGV("+ result=%d", result); \
609 SET_REGISTER(vdst, result); \
610 } \
611 FINISH(2);
612
613 #define HANDLE_OP_IF_XX(_opcode, _opname, _cmp) \
614 HANDLE_OPCODE(_opcode /*vA, vB, +CCCC*/) \
615 vsrc1 = INST_A(inst); \
616 vsrc2 = INST_B(inst); \
617 if ((s4) GET_REGISTER(vsrc1) _cmp (s4) GET_REGISTER(vsrc2)) { \
618 int branchOffset = (s2)FETCH(1); /* sign-extended */ \
619 ILOGV("|if-%s v%d,v%d,+0x%04x", (_opname), vsrc1, vsrc2, \
620 branchOffset); \
621 ILOGV("> branch taken"); \
622 if (branchOffset < 0) \
623 PERIODIC_CHECKS(branchOffset); \
624 FINISH(branchOffset); \
625 } else { \
626 ILOGV("|if-%s v%d,v%d,-", (_opname), vsrc1, vsrc2); \
627 FINISH(2); \
628 }
629
630 #define HANDLE_OP_IF_XXZ(_opcode, _opname, _cmp) \
631 HANDLE_OPCODE(_opcode /*vAA, +BBBB*/) \
632 vsrc1 = INST_AA(inst); \
633 if ((s4) GET_REGISTER(vsrc1) _cmp 0) { \
634 int branchOffset = (s2)FETCH(1); /* sign-extended */ \
635 ILOGV("|if-%s v%d,+0x%04x", (_opname), vsrc1, branchOffset); \
636 ILOGV("> branch taken"); \
637 if (branchOffset < 0) \
638 PERIODIC_CHECKS(branchOffset); \
639 FINISH(branchOffset); \
640 } else { \
641 ILOGV("|if-%s v%d,-", (_opname), vsrc1); \
642 FINISH(2); \
643 }
644
645 #define HANDLE_UNOP(_opcode, _opname, _pfx, _sfx, _type) \
646 HANDLE_OPCODE(_opcode /*vA, vB*/) \
647 vdst = INST_A(inst); \
648 vsrc1 = INST_B(inst); \
649 ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \
650 SET_REGISTER##_type(vdst, _pfx GET_REGISTER##_type(vsrc1) _sfx); \
651 FINISH(1);
652
653 #define HANDLE_OP_X_INT(_opcode, _opname, _op, _chkdiv) \
654 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
655 { \
656 u2 srcRegs; \
657 vdst = INST_AA(inst); \
658 srcRegs = FETCH(1); \
659 vsrc1 = srcRegs & 0xff; \
660 vsrc2 = srcRegs >> 8; \
661 ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \
662 if (_chkdiv != 0) { \
663 s4 firstVal, secondVal, result; \
664 firstVal = GET_REGISTER(vsrc1); \
665 secondVal = GET_REGISTER(vsrc2); \
666 if (secondVal == 0) { \
667 EXPORT_PC(); \
668 dvmThrowArithmeticException("divide by zero"); \
669 GOTO_exceptionThrown(); \
670 } \
671 if ((u4)firstVal == 0x80000000 && secondVal == -1) { \
672 if (_chkdiv == 1) \
673 result = firstVal; /* division */ \
674 else \
675 result = 0; /* remainder */ \
676 } else { \
677 result = firstVal _op secondVal; \
678 } \
679 SET_REGISTER(vdst, result); \
680 } else { \
681 /* non-div/rem case */ \
682 SET_REGISTER(vdst, \
683 (s4) GET_REGISTER(vsrc1) _op (s4) GET_REGISTER(vsrc2)); \
684 } \
685 } \
686 FINISH(2);
687
688 #define HANDLE_OP_SHX_INT(_opcode, _opname, _cast, _op) \
689 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
690 { \
691 u2 srcRegs; \
692 vdst = INST_AA(inst); \
693 srcRegs = FETCH(1); \
694 vsrc1 = srcRegs & 0xff; \
695 vsrc2 = srcRegs >> 8; \
696 ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \
697 SET_REGISTER(vdst, \
698 _cast GET_REGISTER(vsrc1) _op (GET_REGISTER(vsrc2) & 0x1f)); \
699 } \
700 FINISH(2);
701
702 #define HANDLE_OP_X_INT_LIT16(_opcode, _opname, _op, _chkdiv) \
703 HANDLE_OPCODE(_opcode /*vA, vB, #+CCCC*/) \
704 vdst = INST_A(inst); \
705 vsrc1 = INST_B(inst); \
706 vsrc2 = FETCH(1); \
707 ILOGV("|%s-int/lit16 v%d,v%d,#+0x%04x", \
708 (_opname), vdst, vsrc1, vsrc2); \
709 if (_chkdiv != 0) { \
710 s4 firstVal, result; \
711 firstVal = GET_REGISTER(vsrc1); \
712 if ((s2) vsrc2 == 0) { \
713 EXPORT_PC(); \
714 dvmThrowArithmeticException("divide by zero"); \
715 GOTO_exceptionThrown(); \
716 } \
717 if ((u4)firstVal == 0x80000000 && ((s2) vsrc2) == -1) { \
718 /* won't generate /lit16 instr for this; check anyway */ \
719 if (_chkdiv == 1) \
720 result = firstVal; /* division */ \
721 else \
722 result = 0; /* remainder */ \
723 } else { \
724 result = firstVal _op (s2) vsrc2; \
725 } \
726 SET_REGISTER(vdst, result); \
727 } else { \
728 /* non-div/rem case */ \
729 SET_REGISTER(vdst, GET_REGISTER(vsrc1) _op (s2) vsrc2); \
730 } \
731 FINISH(2);
732
733 #define HANDLE_OP_X_INT_LIT8(_opcode, _opname, _op, _chkdiv) \
734 HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \
735 { \
736 u2 litInfo; \
737 vdst = INST_AA(inst); \
738 litInfo = FETCH(1); \
739 vsrc1 = litInfo & 0xff; \
740 vsrc2 = litInfo >> 8; /* constant */ \
741 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \
742 (_opname), vdst, vsrc1, vsrc2); \
743 if (_chkdiv != 0) { \
744 s4 firstVal, result; \
745 firstVal = GET_REGISTER(vsrc1); \
746 if ((s1) vsrc2 == 0) { \
747 EXPORT_PC(); \
748 dvmThrowArithmeticException("divide by zero"); \
749 GOTO_exceptionThrown(); \
750 } \
751 if ((u4)firstVal == 0x80000000 && ((s1) vsrc2) == -1) { \
752 if (_chkdiv == 1) \
753 result = firstVal; /* division */ \
754 else \
755 result = 0; /* remainder */ \
756 } else { \
757 result = firstVal _op ((s1) vsrc2); \
758 } \
759 SET_REGISTER(vdst, result); \
760 } else { \
761 SET_REGISTER(vdst, \
762 (s4) GET_REGISTER(vsrc1) _op (s1) vsrc2); \
763 } \
764 } \
765 FINISH(2);
766
767 #define HANDLE_OP_SHX_INT_LIT8(_opcode, _opname, _cast, _op) \
768 HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \
769 { \
770 u2 litInfo; \
771 vdst = INST_AA(inst); \
772 litInfo = FETCH(1); \
773 vsrc1 = litInfo & 0xff; \
774 vsrc2 = litInfo >> 8; /* constant */ \
775 ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \
776 (_opname), vdst, vsrc1, vsrc2); \
777 SET_REGISTER(vdst, \
778 _cast GET_REGISTER(vsrc1) _op (vsrc2 & 0x1f)); \
779 } \
780 FINISH(2);
781
782 #define HANDLE_OP_X_INT_2ADDR(_opcode, _opname, _op, _chkdiv) \
783 HANDLE_OPCODE(_opcode /*vA, vB*/) \
784 vdst = INST_A(inst); \
785 vsrc1 = INST_B(inst); \
786 ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \
787 if (_chkdiv != 0) { \
788 s4 firstVal, secondVal, result; \
789 firstVal = GET_REGISTER(vdst); \
790 secondVal = GET_REGISTER(vsrc1); \
791 if (secondVal == 0) { \
792 EXPORT_PC(); \
793 dvmThrowArithmeticException("divide by zero"); \
794 GOTO_exceptionThrown(); \
795 } \
796 if ((u4)firstVal == 0x80000000 && secondVal == -1) { \
797 if (_chkdiv == 1) \
798 result = firstVal; /* division */ \
799 else \
800 result = 0; /* remainder */ \
801 } else { \
802 result = firstVal _op secondVal; \
803 } \
804 SET_REGISTER(vdst, result); \
805 } else { \
806 SET_REGISTER(vdst, \
807 (s4) GET_REGISTER(vdst) _op (s4) GET_REGISTER(vsrc1)); \
808 } \
809 FINISH(1);
810
811 #define HANDLE_OP_SHX_INT_2ADDR(_opcode, _opname, _cast, _op) \
812 HANDLE_OPCODE(_opcode /*vA, vB*/) \
813 vdst = INST_A(inst); \
814 vsrc1 = INST_B(inst); \
815 ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \
816 SET_REGISTER(vdst, \
817 _cast GET_REGISTER(vdst) _op (GET_REGISTER(vsrc1) & 0x1f)); \
818 FINISH(1);
819
820 #define HANDLE_OP_X_LONG(_opcode, _opname, _op, _chkdiv) \
821 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
822 { \
823 u2 srcRegs; \
824 vdst = INST_AA(inst); \
825 srcRegs = FETCH(1); \
826 vsrc1 = srcRegs & 0xff; \
827 vsrc2 = srcRegs >> 8; \
828 ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
829 if (_chkdiv != 0) { \
830 s8 firstVal, secondVal, result; \
831 firstVal = GET_REGISTER_WIDE(vsrc1); \
832 secondVal = GET_REGISTER_WIDE(vsrc2); \
833 if (secondVal == 0LL) { \
834 EXPORT_PC(); \
835 dvmThrowArithmeticException("divide by zero"); \
836 GOTO_exceptionThrown(); \
837 } \
838 if ((u8)firstVal == 0x8000000000000000ULL && \
839 secondVal == -1LL) \
840 { \
841 if (_chkdiv == 1) \
842 result = firstVal; /* division */ \
843 else \
844 result = 0; /* remainder */ \
845 } else { \
846 result = firstVal _op secondVal; \
847 } \
848 SET_REGISTER_WIDE(vdst, result); \
849 } else { \
850 SET_REGISTER_WIDE(vdst, \
851 (s8) GET_REGISTER_WIDE(vsrc1) _op (s8) GET_REGISTER_WIDE(vsrc2)); \
852 } \
853 } \
854 FINISH(2);
855
856 #define HANDLE_OP_SHX_LONG(_opcode, _opname, _cast, _op) \
857 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
858 { \
859 u2 srcRegs; \
860 vdst = INST_AA(inst); \
861 srcRegs = FETCH(1); \
862 vsrc1 = srcRegs & 0xff; \
863 vsrc2 = srcRegs >> 8; \
864 ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
865 SET_REGISTER_WIDE(vdst, \
866 _cast GET_REGISTER_WIDE(vsrc1) _op (GET_REGISTER(vsrc2) & 0x3f)); \
867 } \
868 FINISH(2);
869
870 #define HANDLE_OP_X_LONG_2ADDR(_opcode, _opname, _op, _chkdiv) \
871 HANDLE_OPCODE(_opcode /*vA, vB*/) \
872 vdst = INST_A(inst); \
873 vsrc1 = INST_B(inst); \
874 ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \
875 if (_chkdiv != 0) { \
876 s8 firstVal, secondVal, result; \
877 firstVal = GET_REGISTER_WIDE(vdst); \
878 secondVal = GET_REGISTER_WIDE(vsrc1); \
879 if (secondVal == 0LL) { \
880 EXPORT_PC(); \
881 dvmThrowArithmeticException("divide by zero"); \
882 GOTO_exceptionThrown(); \
883 } \
884 if ((u8)firstVal == 0x8000000000000000ULL && \
885 secondVal == -1LL) \
886 { \
887 if (_chkdiv == 1) \
888 result = firstVal; /* division */ \
889 else \
890 result = 0; /* remainder */ \
891 } else { \
892 result = firstVal _op secondVal; \
893 } \
894 SET_REGISTER_WIDE(vdst, result); \
895 } else { \
896 SET_REGISTER_WIDE(vdst, \
897 (s8) GET_REGISTER_WIDE(vdst) _op (s8)GET_REGISTER_WIDE(vsrc1));\
898 } \
899 FINISH(1);
900
901 #define HANDLE_OP_SHX_LONG_2ADDR(_opcode, _opname, _cast, _op) \
902 HANDLE_OPCODE(_opcode /*vA, vB*/) \
903 vdst = INST_A(inst); \
904 vsrc1 = INST_B(inst); \
905 ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \
906 SET_REGISTER_WIDE(vdst, \
907 _cast GET_REGISTER_WIDE(vdst) _op (GET_REGISTER(vsrc1) & 0x3f)); \
908 FINISH(1);
909
910 #define HANDLE_OP_X_FLOAT(_opcode, _opname, _op) \
911 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
912 { \
913 u2 srcRegs; \
914 vdst = INST_AA(inst); \
915 srcRegs = FETCH(1); \
916 vsrc1 = srcRegs & 0xff; \
917 vsrc2 = srcRegs >> 8; \
918 ILOGV("|%s-float v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
919 SET_REGISTER_FLOAT(vdst, \
920 GET_REGISTER_FLOAT(vsrc1) _op GET_REGISTER_FLOAT(vsrc2)); \
921 } \
922 FINISH(2);
923
924 #define HANDLE_OP_X_DOUBLE(_opcode, _opname, _op) \
925 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
926 { \
927 u2 srcRegs; \
928 vdst = INST_AA(inst); \
929 srcRegs = FETCH(1); \
930 vsrc1 = srcRegs & 0xff; \
931 vsrc2 = srcRegs >> 8; \
932 ILOGV("|%s-double v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
933 SET_REGISTER_DOUBLE(vdst, \
934 GET_REGISTER_DOUBLE(vsrc1) _op GET_REGISTER_DOUBLE(vsrc2)); \
935 } \
936 FINISH(2);
937
938 #define HANDLE_OP_X_FLOAT_2ADDR(_opcode, _opname, _op) \
939 HANDLE_OPCODE(_opcode /*vA, vB*/) \
940 vdst = INST_A(inst); \
941 vsrc1 = INST_B(inst); \
942 ILOGV("|%s-float-2addr v%d,v%d", (_opname), vdst, vsrc1); \
943 SET_REGISTER_FLOAT(vdst, \
944 GET_REGISTER_FLOAT(vdst) _op GET_REGISTER_FLOAT(vsrc1)); \
945 FINISH(1);
946
947 #define HANDLE_OP_X_DOUBLE_2ADDR(_opcode, _opname, _op) \
948 HANDLE_OPCODE(_opcode /*vA, vB*/) \
949 vdst = INST_A(inst); \
950 vsrc1 = INST_B(inst); \
951 ILOGV("|%s-double-2addr v%d,v%d", (_opname), vdst, vsrc1); \
952 SET_REGISTER_DOUBLE(vdst, \
953 GET_REGISTER_DOUBLE(vdst) _op GET_REGISTER_DOUBLE(vsrc1)); \
954 FINISH(1);
955
956 #define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \
957 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
958 { \
959 ArrayObject* arrayObj; \
960 u2 arrayInfo; \
961 EXPORT_PC(); \
962 vdst = INST_AA(inst); \
963 arrayInfo = FETCH(1); \
964 vsrc1 = arrayInfo & 0xff; /* array ptr */ \
965 vsrc2 = arrayInfo >> 8; /* index */ \
966 ILOGV("|aget%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
967 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \
968 if (!checkForNull((Object*) arrayObj)) \
969 GOTO_exceptionThrown(); \
970 if (GET_REGISTER(vsrc2) >= arrayObj->length) { \
971 dvmThrowArrayIndexOutOfBoundsException( \
972 arrayObj->length, GET_REGISTER(vsrc2)); \
973 GOTO_exceptionThrown(); \
974 } \
975 SET_REGISTER##_regsize(vdst, \
976 ((_type*)(void*)arrayObj->contents)[GET_REGISTER(vsrc2)]); \
977 ILOGV("+ AGET[%d]=%#x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \
978 } \
979 FINISH(2);
980
981 #define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \
982 HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
983 { \
984 ArrayObject* arrayObj; \
985 u2 arrayInfo; \
986 EXPORT_PC(); \
987 vdst = INST_AA(inst); /* AA: source value */ \
988 arrayInfo = FETCH(1); \
989 vsrc1 = arrayInfo & 0xff; /* BB: array ptr */ \
990 vsrc2 = arrayInfo >> 8; /* CC: index */ \
991 ILOGV("|aput%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \
992 arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \
993 if (!checkForNull((Object*) arrayObj)) \
994 GOTO_exceptionThrown(); \
995 if (GET_REGISTER(vsrc2) >= arrayObj->length) { \
996 dvmThrowArrayIndexOutOfBoundsException( \
997 arrayObj->length, GET_REGISTER(vsrc2)); \
998 GOTO_exceptionThrown(); \
999 } \
1000 ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
1001 ((_type*)(void*)arrayObj->contents)[GET_REGISTER(vsrc2)] = \
1002 GET_REGISTER##_regsize(vdst); \
1003 } \
1004 FINISH(2);
1005
1006 /*
1007 * It's possible to get a bad value out of a field with sub-32-bit stores
1008 * because the -quick versions always operate on 32 bits. Consider:
1009 * short foo = -1 (sets a 32-bit register to 0xffffffff)
1010 * iput-quick foo (writes all 32 bits to the field)
1011 * short bar = 1 (sets a 32-bit register to 0x00000001)
1012 * iput-short (writes the low 16 bits to the field)
1013 * iget-quick foo (reads all 32 bits from the field, yielding 0xffff0001)
1014 * This can only happen when optimized and non-optimized code has interleaved
1015 * access to the same field. This is unlikely but possible.
1016 *
1017 * The easiest way to fix this is to always read/write 32 bits at a time. On
1018 * a device with a 16-bit data bus this is sub-optimal. (The alternative
1019 * approach is to have sub-int versions of iget-quick, but now we're wasting
1020 * Dalvik instruction space and making it less likely that handler code will
1021 * already be in the CPU i-cache.)
1022 */
1023 #define HANDLE_IGET_X(_opcode, _opname, _ftype, _regsize) \
1024 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1025 { \
1026 InstField* ifield; \
1027 Object* obj; \
1028 EXPORT_PC(); \
1029 vdst = INST_A(inst); \
1030 vsrc1 = INST_B(inst); /* object ptr */ \
1031 ref = FETCH(1); /* field ref */ \
1032 ILOGV("|iget%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1033 obj = (Object*) GET_REGISTER(vsrc1); \
1034 if (!checkForNull(obj)) \
1035 GOTO_exceptionThrown(); \
1036 ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \
1037 if (ifield == NULL) { \
1038 ifield = dvmResolveInstField(curMethod->clazz, ref); \
1039 if (ifield == NULL) \
1040 GOTO_exceptionThrown(); \
1041 } \
1042 SET_REGISTER##_regsize(vdst, \
1043 dvmGetField##_ftype(obj, ifield->byteOffset)); \
1044 ILOGV("+ IGET '%s'=0x%08llx", ifield->name, \
1045 (u8) GET_REGISTER##_regsize(vdst)); \
1046 } \
1047 FINISH(2);
1048
1049 #define HANDLE_IGET_X_QUICK(_opcode, _opname, _ftype, _regsize) \
1050 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1051 { \
1052 Object* obj; \
1053 vdst = INST_A(inst); \
1054 vsrc1 = INST_B(inst); /* object ptr */ \
1055 ref = FETCH(1); /* field offset */ \
1056 ILOGV("|iget%s-quick v%d,v%d,field@+%u", \
1057 (_opname), vdst, vsrc1, ref); \
1058 obj = (Object*) GET_REGISTER(vsrc1); \
1059 if (!checkForNullExportPC(obj, fp, pc)) \
1060 GOTO_exceptionThrown(); \
1061 SET_REGISTER##_regsize(vdst, dvmGetField##_ftype(obj, ref)); \
1062 ILOGV("+ IGETQ %d=0x%08llx", ref, \
1063 (u8) GET_REGISTER##_regsize(vdst)); \
1064 } \
1065 FINISH(2);
1066
1067 #define HANDLE_IPUT_X(_opcode, _opname, _ftype, _regsize) \
1068 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1069 { \
1070 InstField* ifield; \
1071 Object* obj; \
1072 EXPORT_PC(); \
1073 vdst = INST_A(inst); \
1074 vsrc1 = INST_B(inst); /* object ptr */ \
1075 ref = FETCH(1); /* field ref */ \
1076 ILOGV("|iput%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1077 obj = (Object*) GET_REGISTER(vsrc1); \
1078 if (!checkForNull(obj)) \
1079 GOTO_exceptionThrown(); \
1080 ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \
1081 if (ifield == NULL) { \
1082 ifield = dvmResolveInstField(curMethod->clazz, ref); \
1083 if (ifield == NULL) \
1084 GOTO_exceptionThrown(); \
1085 } \
1086 dvmSetField##_ftype(obj, ifield->byteOffset, \
1087 GET_REGISTER##_regsize(vdst)); \
1088 ILOGV("+ IPUT '%s'=0x%08llx", ifield->name, \
1089 (u8) GET_REGISTER##_regsize(vdst)); \
1090 } \
1091 FINISH(2);
1092
1093 #define HANDLE_IPUT_X_QUICK(_opcode, _opname, _ftype, _regsize) \
1094 HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \
1095 { \
1096 Object* obj; \
1097 vdst = INST_A(inst); \
1098 vsrc1 = INST_B(inst); /* object ptr */ \
1099 ref = FETCH(1); /* field offset */ \
1100 ILOGV("|iput%s-quick v%d,v%d,field@0x%04x", \
1101 (_opname), vdst, vsrc1, ref); \
1102 obj = (Object*) GET_REGISTER(vsrc1); \
1103 if (!checkForNullExportPC(obj, fp, pc)) \
1104 GOTO_exceptionThrown(); \
1105 dvmSetField##_ftype(obj, ref, GET_REGISTER##_regsize(vdst)); \
1106 ILOGV("+ IPUTQ %d=0x%08llx", ref, \
1107 (u8) GET_REGISTER##_regsize(vdst)); \
1108 } \
1109 FINISH(2);
1110
1111 /*
1112 * The JIT needs dvmDexGetResolvedField() to return non-null.
1113 * Because the portable interpreter is not involved with the JIT
1114 * and trace building, we only need the extra check here when this
1115 * code is massaged into a stub called from an assembly interpreter.
1116 * This is controlled by the JIT_STUB_HACK maco.
1117 */
1118
1119 #define HANDLE_SGET_X(_opcode, _opname, _ftype, _regsize) \
1120 HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \
1121 { \
1122 StaticField* sfield; \
1123 vdst = INST_AA(inst); \
1124 ref = FETCH(1); /* field ref */ \
1125 ILOGV("|sget%s v%d,sfield@0x%04x", (_opname), vdst, ref); \
1126 sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1127 if (sfield == NULL) { \
1128 EXPORT_PC(); \
1129 sfield = dvmResolveStaticField(curMethod->clazz, ref); \
1130 if (sfield == NULL) \
1131 GOTO_exceptionThrown(); \
1132 if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) { \
1133 JIT_STUB_HACK(dvmJitEndTraceSelect(self,pc)); \
1134 } \
1135 } \
1136 SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield)); \
1137 ILOGV("+ SGET '%s'=0x%08llx", \
1138 sfield->name, (u8)GET_REGISTER##_regsize(vdst)); \
1139 } \
1140 FINISH(2);
1141
1142 #define HANDLE_SPUT_X(_opcode, _opname, _ftype, _regsize) \
1143 HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \
1144 { \
1145 StaticField* sfield; \
1146 vdst = INST_AA(inst); \
1147 ref = FETCH(1); /* field ref */ \
1148 ILOGV("|sput%s v%d,sfield@0x%04x", (_opname), vdst, ref); \
1149 sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1150 if (sfield == NULL) { \
1151 EXPORT_PC(); \
1152 sfield = dvmResolveStaticField(curMethod->clazz, ref); \
1153 if (sfield == NULL) \
1154 GOTO_exceptionThrown(); \
1155 if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) { \
1156 JIT_STUB_HACK(dvmJitEndTraceSelect(self,pc)); \
1157 } \
1158 } \
1159 dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst)); \
1160 ILOGV("+ SPUT '%s'=0x%08llx", \
1161 sfield->name, (u8)GET_REGISTER##_regsize(vdst)); \
1162 } \
1163 FINISH(2);
1164
1165 /* File: c/OP_BREAKPOINT.cpp */
HANDLE_OPCODE(OP_BREAKPOINT)1166 HANDLE_OPCODE(OP_BREAKPOINT)
1167 {
1168 /*
1169 * Restart this instruction with the original opcode. We do
1170 * this by simply jumping to the handler.
1171 *
1172 * It's probably not necessary to update "inst", but we do it
1173 * for the sake of anything that needs to do disambiguation in a
1174 * common handler with INST_INST.
1175 *
1176 * The breakpoint itself is handled over in updateDebugger(),
1177 * because we need to detect other events (method entry, single
1178 * step) and report them in the same event packet, and we're not
1179 * yet handling those through breakpoint instructions. By the
1180 * time we get here, the breakpoint has already been handled and
1181 * the thread resumed.
1182 */
1183 u1 originalOpcode = dvmGetOriginalOpcode(pc);
1184 ALOGV("+++ break 0x%02x (0x%04x -> 0x%04x)", originalOpcode, inst,
1185 INST_REPLACE_OP(inst, originalOpcode));
1186 inst = INST_REPLACE_OP(inst, originalOpcode);
1187 FINISH_BKPT(originalOpcode);
1188 }
1189 OP_END
1190
1191 /* File: c/gotoTargets.cpp */
1192 /*
1193 * C footer. This has some common code shared by the various targets.
1194 */
1195
1196 /*
1197 * Everything from here on is a "goto target". In the basic interpreter
1198 * we jump into these targets and then jump directly to the handler for
1199 * next instruction. Here, these are subroutines that return to the caller.
1200 */
1201
GOTO_TARGET(filledNewArray,bool methodCallRange,bool)1202 GOTO_TARGET(filledNewArray, bool methodCallRange, bool)
1203 {
1204 ClassObject* arrayClass;
1205 ArrayObject* newArray;
1206 u4* contents;
1207 char typeCh;
1208 int i;
1209 u4 arg5;
1210
1211 EXPORT_PC();
1212
1213 ref = FETCH(1); /* class ref */
1214 vdst = FETCH(2); /* first 4 regs -or- range base */
1215
1216 if (methodCallRange) {
1217 vsrc1 = INST_AA(inst); /* #of elements */
1218 arg5 = -1; /* silence compiler warning */
1219 ILOGV("|filled-new-array-range args=%d @0x%04x {regs=v%d-v%d}",
1220 vsrc1, ref, vdst, vdst+vsrc1-1);
1221 } else {
1222 arg5 = INST_A(inst);
1223 vsrc1 = INST_B(inst); /* #of elements */
1224 ILOGV("|filled-new-array args=%d @0x%04x {regs=0x%04x %x}",
1225 vsrc1, ref, vdst, arg5);
1226 }
1227
1228 /*
1229 * Resolve the array class.
1230 */
1231 arrayClass = dvmDexGetResolvedClass(methodClassDex, ref);
1232 if (arrayClass == NULL) {
1233 arrayClass = dvmResolveClass(curMethod->clazz, ref, false);
1234 if (arrayClass == NULL)
1235 GOTO_exceptionThrown();
1236 }
1237 /*
1238 if (!dvmIsArrayClass(arrayClass)) {
1239 dvmThrowRuntimeException(
1240 "filled-new-array needs array class");
1241 GOTO_exceptionThrown();
1242 }
1243 */
1244 /* verifier guarantees this is an array class */
1245 assert(dvmIsArrayClass(arrayClass));
1246 assert(dvmIsClassInitialized(arrayClass));
1247
1248 /*
1249 * Create an array of the specified type.
1250 */
1251 LOGVV("+++ filled-new-array type is '%s'", arrayClass->descriptor);
1252 typeCh = arrayClass->descriptor[1];
1253 if (typeCh == 'D' || typeCh == 'J') {
1254 /* category 2 primitives not allowed */
1255 dvmThrowRuntimeException("bad filled array req");
1256 GOTO_exceptionThrown();
1257 } else if (typeCh != 'L' && typeCh != '[' && typeCh != 'I') {
1258 /* TODO: requires multiple "fill in" loops with different widths */
1259 ALOGE("non-int primitives not implemented");
1260 dvmThrowInternalError(
1261 "filled-new-array not implemented for anything but 'int'");
1262 GOTO_exceptionThrown();
1263 }
1264
1265 newArray = dvmAllocArrayByClass(arrayClass, vsrc1, ALLOC_DONT_TRACK);
1266 if (newArray == NULL)
1267 GOTO_exceptionThrown();
1268
1269 /*
1270 * Fill in the elements. It's legal for vsrc1 to be zero.
1271 */
1272 contents = (u4*)(void*)newArray->contents;
1273 if (methodCallRange) {
1274 for (i = 0; i < vsrc1; i++)
1275 contents[i] = GET_REGISTER(vdst+i);
1276 } else {
1277 assert(vsrc1 <= 5);
1278 if (vsrc1 == 5) {
1279 contents[4] = GET_REGISTER(arg5);
1280 vsrc1--;
1281 }
1282 for (i = 0; i < vsrc1; i++) {
1283 contents[i] = GET_REGISTER(vdst & 0x0f);
1284 vdst >>= 4;
1285 }
1286 }
1287 if (typeCh == 'L' || typeCh == '[') {
1288 dvmWriteBarrierArray(newArray, 0, newArray->length);
1289 }
1290
1291 retval.l = (Object*)newArray;
1292 }
1293 FINISH(3);
1294 GOTO_TARGET_END
1295
1296
GOTO_TARGET(invokeVirtual,bool methodCallRange,bool)1297 GOTO_TARGET(invokeVirtual, bool methodCallRange, bool)
1298 {
1299 Method* baseMethod;
1300 Object* thisPtr;
1301
1302 EXPORT_PC();
1303
1304 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1305 ref = FETCH(1); /* method ref */
1306 vdst = FETCH(2); /* 4 regs -or- first reg */
1307
1308 /*
1309 * The object against which we are executing a method is always
1310 * in the first argument.
1311 */
1312 if (methodCallRange) {
1313 assert(vsrc1 > 0);
1314 ILOGV("|invoke-virtual-range args=%d @0x%04x {regs=v%d-v%d}",
1315 vsrc1, ref, vdst, vdst+vsrc1-1);
1316 thisPtr = (Object*) GET_REGISTER(vdst);
1317 } else {
1318 assert((vsrc1>>4) > 0);
1319 ILOGV("|invoke-virtual args=%d @0x%04x {regs=0x%04x %x}",
1320 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1321 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
1322 }
1323
1324 if (!checkForNull(thisPtr))
1325 GOTO_exceptionThrown();
1326
1327 /*
1328 * Resolve the method. This is the correct method for the static
1329 * type of the object. We also verify access permissions here.
1330 */
1331 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
1332 if (baseMethod == NULL) {
1333 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
1334 if (baseMethod == NULL) {
1335 ILOGV("+ unknown method or access denied");
1336 GOTO_exceptionThrown();
1337 }
1338 }
1339
1340 /*
1341 * Combine the object we found with the vtable offset in the
1342 * method.
1343 */
1344 assert(baseMethod->methodIndex < thisPtr->clazz->vtableCount);
1345 methodToCall = thisPtr->clazz->vtable[baseMethod->methodIndex];
1346
1347 #if defined(WITH_JIT) && defined(MTERP_STUB)
1348 self->methodToCall = methodToCall;
1349 self->callsiteClass = thisPtr->clazz;
1350 #endif
1351
1352 #if 0
1353 if (dvmIsAbstractMethod(methodToCall)) {
1354 /*
1355 * This can happen if you create two classes, Base and Sub, where
1356 * Sub is a sub-class of Base. Declare a protected abstract
1357 * method foo() in Base, and invoke foo() from a method in Base.
1358 * Base is an "abstract base class" and is never instantiated
1359 * directly. Now, Override foo() in Sub, and use Sub. This
1360 * Works fine unless Sub stops providing an implementation of
1361 * the method.
1362 */
1363 dvmThrowAbstractMethodError("abstract method not implemented");
1364 GOTO_exceptionThrown();
1365 }
1366 #else
1367 assert(!dvmIsAbstractMethod(methodToCall) ||
1368 methodToCall->nativeFunc != NULL);
1369 #endif
1370
1371 LOGVV("+++ base=%s.%s virtual[%d]=%s.%s",
1372 baseMethod->clazz->descriptor, baseMethod->name,
1373 (u4) baseMethod->methodIndex,
1374 methodToCall->clazz->descriptor, methodToCall->name);
1375 assert(methodToCall != NULL);
1376
1377 #if 0
1378 if (vsrc1 != methodToCall->insSize) {
1379 ALOGW("WRONG METHOD: base=%s.%s virtual[%d]=%s.%s",
1380 baseMethod->clazz->descriptor, baseMethod->name,
1381 (u4) baseMethod->methodIndex,
1382 methodToCall->clazz->descriptor, methodToCall->name);
1383 //dvmDumpClass(baseMethod->clazz);
1384 //dvmDumpClass(methodToCall->clazz);
1385 dvmDumpAllClasses(0);
1386 }
1387 #endif
1388
1389 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1390 }
1391 GOTO_TARGET_END
1392
GOTO_TARGET(invokeSuper,bool methodCallRange)1393 GOTO_TARGET(invokeSuper, bool methodCallRange)
1394 {
1395 Method* baseMethod;
1396 u2 thisReg;
1397
1398 EXPORT_PC();
1399
1400 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1401 ref = FETCH(1); /* method ref */
1402 vdst = FETCH(2); /* 4 regs -or- first reg */
1403
1404 if (methodCallRange) {
1405 ILOGV("|invoke-super-range args=%d @0x%04x {regs=v%d-v%d}",
1406 vsrc1, ref, vdst, vdst+vsrc1-1);
1407 thisReg = vdst;
1408 } else {
1409 ILOGV("|invoke-super args=%d @0x%04x {regs=0x%04x %x}",
1410 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1411 thisReg = vdst & 0x0f;
1412 }
1413
1414 /* impossible in well-formed code, but we must check nevertheless */
1415 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
1416 GOTO_exceptionThrown();
1417
1418 /*
1419 * Resolve the method. This is the correct method for the static
1420 * type of the object. We also verify access permissions here.
1421 * The first arg to dvmResolveMethod() is just the referring class
1422 * (used for class loaders and such), so we don't want to pass
1423 * the superclass into the resolution call.
1424 */
1425 baseMethod = dvmDexGetResolvedMethod(methodClassDex, ref);
1426 if (baseMethod == NULL) {
1427 baseMethod = dvmResolveMethod(curMethod->clazz, ref,METHOD_VIRTUAL);
1428 if (baseMethod == NULL) {
1429 ILOGV("+ unknown method or access denied");
1430 GOTO_exceptionThrown();
1431 }
1432 }
1433
1434 /*
1435 * Combine the object we found with the vtable offset in the
1436 * method's class.
1437 *
1438 * We're using the current method's class' superclass, not the
1439 * superclass of "this". This is because we might be executing
1440 * in a method inherited from a superclass, and we want to run
1441 * in that class' superclass.
1442 */
1443 if (baseMethod->methodIndex >= curMethod->clazz->super->vtableCount) {
1444 /*
1445 * Method does not exist in the superclass. Could happen if
1446 * superclass gets updated.
1447 */
1448 dvmThrowNoSuchMethodError(baseMethod->name);
1449 GOTO_exceptionThrown();
1450 }
1451 methodToCall = curMethod->clazz->super->vtable[baseMethod->methodIndex];
1452
1453 #if 0
1454 if (dvmIsAbstractMethod(methodToCall)) {
1455 dvmThrowAbstractMethodError("abstract method not implemented");
1456 GOTO_exceptionThrown();
1457 }
1458 #else
1459 assert(!dvmIsAbstractMethod(methodToCall) ||
1460 methodToCall->nativeFunc != NULL);
1461 #endif
1462 LOGVV("+++ base=%s.%s super-virtual=%s.%s",
1463 baseMethod->clazz->descriptor, baseMethod->name,
1464 methodToCall->clazz->descriptor, methodToCall->name);
1465 assert(methodToCall != NULL);
1466
1467 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1468 }
1469 GOTO_TARGET_END
1470
GOTO_TARGET(invokeInterface,bool methodCallRange)1471 GOTO_TARGET(invokeInterface, bool methodCallRange)
1472 {
1473 Object* thisPtr;
1474 ClassObject* thisClass;
1475
1476 EXPORT_PC();
1477
1478 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1479 ref = FETCH(1); /* method ref */
1480 vdst = FETCH(2); /* 4 regs -or- first reg */
1481
1482 /*
1483 * The object against which we are executing a method is always
1484 * in the first argument.
1485 */
1486 if (methodCallRange) {
1487 assert(vsrc1 > 0);
1488 ILOGV("|invoke-interface-range args=%d @0x%04x {regs=v%d-v%d}",
1489 vsrc1, ref, vdst, vdst+vsrc1-1);
1490 thisPtr = (Object*) GET_REGISTER(vdst);
1491 } else {
1492 assert((vsrc1>>4) > 0);
1493 ILOGV("|invoke-interface args=%d @0x%04x {regs=0x%04x %x}",
1494 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1495 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
1496 }
1497
1498 if (!checkForNull(thisPtr))
1499 GOTO_exceptionThrown();
1500
1501 thisClass = thisPtr->clazz;
1502
1503 /*
1504 * Given a class and a method index, find the Method* with the
1505 * actual code we want to execute.
1506 */
1507 methodToCall = dvmFindInterfaceMethodInCache(thisClass, ref, curMethod,
1508 methodClassDex);
1509 #if defined(WITH_JIT) && defined(MTERP_STUB)
1510 self->callsiteClass = thisClass;
1511 self->methodToCall = methodToCall;
1512 #endif
1513 if (methodToCall == NULL) {
1514 assert(dvmCheckException(self));
1515 GOTO_exceptionThrown();
1516 }
1517
1518 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1519 }
1520 GOTO_TARGET_END
1521
GOTO_TARGET(invokeDirect,bool methodCallRange)1522 GOTO_TARGET(invokeDirect, bool methodCallRange)
1523 {
1524 u2 thisReg;
1525
1526 EXPORT_PC();
1527
1528 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1529 ref = FETCH(1); /* method ref */
1530 vdst = FETCH(2); /* 4 regs -or- first reg */
1531
1532 if (methodCallRange) {
1533 ILOGV("|invoke-direct-range args=%d @0x%04x {regs=v%d-v%d}",
1534 vsrc1, ref, vdst, vdst+vsrc1-1);
1535 thisReg = vdst;
1536 } else {
1537 ILOGV("|invoke-direct args=%d @0x%04x {regs=0x%04x %x}",
1538 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1539 thisReg = vdst & 0x0f;
1540 }
1541
1542 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
1543 GOTO_exceptionThrown();
1544
1545 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
1546 if (methodToCall == NULL) {
1547 methodToCall = dvmResolveMethod(curMethod->clazz, ref,
1548 METHOD_DIRECT);
1549 if (methodToCall == NULL) {
1550 ILOGV("+ unknown direct method"); // should be impossible
1551 GOTO_exceptionThrown();
1552 }
1553 }
1554 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1555 }
1556 GOTO_TARGET_END
1557
1558 GOTO_TARGET(invokeStatic, bool methodCallRange)
1559 EXPORT_PC();
1560
1561 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1562 ref = FETCH(1); /* method ref */
1563 vdst = FETCH(2); /* 4 regs -or- first reg */
1564
1565 if (methodCallRange)
1566 ILOGV("|invoke-static-range args=%d @0x%04x {regs=v%d-v%d}",
1567 vsrc1, ref, vdst, vdst+vsrc1-1);
1568 else
1569 ILOGV("|invoke-static args=%d @0x%04x {regs=0x%04x %x}",
1570 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1571
1572 methodToCall = dvmDexGetResolvedMethod(methodClassDex, ref);
1573 if (methodToCall == NULL) {
1574 methodToCall = dvmResolveMethod(curMethod->clazz, ref, METHOD_STATIC);
1575 if (methodToCall == NULL) {
1576 ILOGV("+ unknown method");
1577 GOTO_exceptionThrown();
1578 }
1579
1580 #if defined(WITH_JIT) && defined(MTERP_STUB)
1581 /*
1582 * The JIT needs dvmDexGetResolvedMethod() to return non-null.
1583 * Include the check if this code is being used as a stub
1584 * called from the assembly interpreter.
1585 */
1586 if ((self->interpBreak.ctl.subMode & kSubModeJitTraceBuild) &&
1587 (dvmDexGetResolvedMethod(methodClassDex, ref) == NULL)) {
1588 /* Class initialization is still ongoing */
1589 dvmJitEndTraceSelect(self,pc);
1590 }
1591 #endif
1592 }
1593 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1594 GOTO_TARGET_END
1595
GOTO_TARGET(invokeVirtualQuick,bool methodCallRange)1596 GOTO_TARGET(invokeVirtualQuick, bool methodCallRange)
1597 {
1598 Object* thisPtr;
1599
1600 EXPORT_PC();
1601
1602 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1603 ref = FETCH(1); /* vtable index */
1604 vdst = FETCH(2); /* 4 regs -or- first reg */
1605
1606 /*
1607 * The object against which we are executing a method is always
1608 * in the first argument.
1609 */
1610 if (methodCallRange) {
1611 assert(vsrc1 > 0);
1612 ILOGV("|invoke-virtual-quick-range args=%d @0x%04x {regs=v%d-v%d}",
1613 vsrc1, ref, vdst, vdst+vsrc1-1);
1614 thisPtr = (Object*) GET_REGISTER(vdst);
1615 } else {
1616 assert((vsrc1>>4) > 0);
1617 ILOGV("|invoke-virtual-quick args=%d @0x%04x {regs=0x%04x %x}",
1618 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1619 thisPtr = (Object*) GET_REGISTER(vdst & 0x0f);
1620 }
1621
1622 if (!checkForNull(thisPtr))
1623 GOTO_exceptionThrown();
1624
1625
1626 /*
1627 * Combine the object we found with the vtable offset in the
1628 * method.
1629 */
1630 assert(ref < (unsigned int) thisPtr->clazz->vtableCount);
1631 methodToCall = thisPtr->clazz->vtable[ref];
1632 #if defined(WITH_JIT) && defined(MTERP_STUB)
1633 self->callsiteClass = thisPtr->clazz;
1634 self->methodToCall = methodToCall;
1635 #endif
1636
1637 #if 0
1638 if (dvmIsAbstractMethod(methodToCall)) {
1639 dvmThrowAbstractMethodError("abstract method not implemented");
1640 GOTO_exceptionThrown();
1641 }
1642 #else
1643 assert(!dvmIsAbstractMethod(methodToCall) ||
1644 methodToCall->nativeFunc != NULL);
1645 #endif
1646
1647 LOGVV("+++ virtual[%d]=%s.%s",
1648 ref, methodToCall->clazz->descriptor, methodToCall->name);
1649 assert(methodToCall != NULL);
1650
1651 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1652 }
1653 GOTO_TARGET_END
1654
GOTO_TARGET(invokeSuperQuick,bool methodCallRange)1655 GOTO_TARGET(invokeSuperQuick, bool methodCallRange)
1656 {
1657 u2 thisReg;
1658
1659 EXPORT_PC();
1660
1661 vsrc1 = INST_AA(inst); /* AA (count) or BA (count + arg 5) */
1662 ref = FETCH(1); /* vtable index */
1663 vdst = FETCH(2); /* 4 regs -or- first reg */
1664
1665 if (methodCallRange) {
1666 ILOGV("|invoke-super-quick-range args=%d @0x%04x {regs=v%d-v%d}",
1667 vsrc1, ref, vdst, vdst+vsrc1-1);
1668 thisReg = vdst;
1669 } else {
1670 ILOGV("|invoke-super-quick args=%d @0x%04x {regs=0x%04x %x}",
1671 vsrc1 >> 4, ref, vdst, vsrc1 & 0x0f);
1672 thisReg = vdst & 0x0f;
1673 }
1674 /* impossible in well-formed code, but we must check nevertheless */
1675 if (!checkForNull((Object*) GET_REGISTER(thisReg)))
1676 GOTO_exceptionThrown();
1677
1678 #if 0 /* impossible in optimized + verified code */
1679 if (ref >= curMethod->clazz->super->vtableCount) {
1680 dvmThrowNoSuchMethodError(NULL);
1681 GOTO_exceptionThrown();
1682 }
1683 #else
1684 assert(ref < (unsigned int) curMethod->clazz->super->vtableCount);
1685 #endif
1686
1687 /*
1688 * Combine the object we found with the vtable offset in the
1689 * method's class.
1690 *
1691 * We're using the current method's class' superclass, not the
1692 * superclass of "this". This is because we might be executing
1693 * in a method inherited from a superclass, and we want to run
1694 * in the method's class' superclass.
1695 */
1696 methodToCall = curMethod->clazz->super->vtable[ref];
1697
1698 #if 0
1699 if (dvmIsAbstractMethod(methodToCall)) {
1700 dvmThrowAbstractMethodError("abstract method not implemented");
1701 GOTO_exceptionThrown();
1702 }
1703 #else
1704 assert(!dvmIsAbstractMethod(methodToCall) ||
1705 methodToCall->nativeFunc != NULL);
1706 #endif
1707 LOGVV("+++ super-virtual[%d]=%s.%s",
1708 ref, methodToCall->clazz->descriptor, methodToCall->name);
1709 assert(methodToCall != NULL);
1710 GOTO_invokeMethod(methodCallRange, methodToCall, vsrc1, vdst);
1711 }
1712 GOTO_TARGET_END
1713
1714
1715 /*
1716 * General handling for return-void, return, and return-wide. Put the
1717 * return value in "retval" before jumping here.
1718 */
GOTO_TARGET(returnFromMethod)1719 GOTO_TARGET(returnFromMethod)
1720 {
1721 StackSaveArea* saveArea;
1722
1723 /*
1724 * We must do this BEFORE we pop the previous stack frame off, so
1725 * that the GC can see the return value (if any) in the local vars.
1726 *
1727 * Since this is now an interpreter switch point, we must do it before
1728 * we do anything at all.
1729 */
1730 PERIODIC_CHECKS(0);
1731
1732 ILOGV("> retval=0x%llx (leaving %s.%s %s)",
1733 retval.j, curMethod->clazz->descriptor, curMethod->name,
1734 curMethod->shorty);
1735 //DUMP_REGS(curMethod, fp);
1736
1737 saveArea = SAVEAREA_FROM_FP(fp);
1738
1739 #ifdef EASY_GDB
1740 debugSaveArea = saveArea;
1741 #endif
1742
1743 /* back up to previous frame and see if we hit a break */
1744 fp = (u4*)saveArea->prevFrame;
1745 assert(fp != NULL);
1746
1747 /* Handle any special subMode requirements */
1748 if (self->interpBreak.ctl.subMode != 0) {
1749 PC_FP_TO_SELF();
1750 dvmReportReturn(self);
1751 }
1752
1753 if (dvmIsBreakFrame(fp)) {
1754 /* bail without popping the method frame from stack */
1755 LOGVV("+++ returned into break frame");
1756 GOTO_bail();
1757 }
1758
1759 /* update thread FP, and reset local variables */
1760 self->interpSave.curFrame = fp;
1761 curMethod = SAVEAREA_FROM_FP(fp)->method;
1762 self->interpSave.method = curMethod;
1763 //methodClass = curMethod->clazz;
1764 methodClassDex = curMethod->clazz->pDvmDex;
1765 pc = saveArea->savedPc;
1766 ILOGD("> (return to %s.%s %s)", curMethod->clazz->descriptor,
1767 curMethod->name, curMethod->shorty);
1768
1769 /* use FINISH on the caller's invoke instruction */
1770 //u2 invokeInstr = INST_INST(FETCH(0));
1771 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
1772 invokeInstr <= OP_INVOKE_INTERFACE*/)
1773 {
1774 FINISH(3);
1775 } else {
1776 //ALOGE("Unknown invoke instr %02x at %d",
1777 // invokeInstr, (int) (pc - curMethod->insns));
1778 assert(false);
1779 }
1780 }
1781 GOTO_TARGET_END
1782
1783
1784 /*
1785 * Jump here when the code throws an exception.
1786 *
1787 * By the time we get here, the Throwable has been created and the stack
1788 * trace has been saved off.
1789 */
GOTO_TARGET(exceptionThrown)1790 GOTO_TARGET(exceptionThrown)
1791 {
1792 Object* exception;
1793 int catchRelPc;
1794
1795 PERIODIC_CHECKS(0);
1796
1797 /*
1798 * We save off the exception and clear the exception status. While
1799 * processing the exception we might need to load some Throwable
1800 * classes, and we don't want class loader exceptions to get
1801 * confused with this one.
1802 */
1803 assert(dvmCheckException(self));
1804 exception = dvmGetException(self);
1805 dvmAddTrackedAlloc(exception, self);
1806 dvmClearException(self);
1807
1808 ALOGV("Handling exception %s at %s:%d",
1809 exception->clazz->descriptor, curMethod->name,
1810 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
1811
1812 /*
1813 * Report the exception throw to any "subMode" watchers.
1814 *
1815 * TODO: if the exception was thrown by interpreted code, control
1816 * fell through native, and then back to us, we will report the
1817 * exception at the point of the throw and again here. We can avoid
1818 * this by not reporting exceptions when we jump here directly from
1819 * the native call code above, but then we won't report exceptions
1820 * that were thrown *from* the JNI code (as opposed to *through* it).
1821 *
1822 * The correct solution is probably to ignore from-native exceptions
1823 * here, and have the JNI exception code do the reporting to the
1824 * debugger.
1825 */
1826 if (self->interpBreak.ctl.subMode != 0) {
1827 PC_FP_TO_SELF();
1828 dvmReportExceptionThrow(self, exception);
1829 }
1830
1831 /*
1832 * We need to unroll to the catch block or the nearest "break"
1833 * frame.
1834 *
1835 * A break frame could indicate that we have reached an intermediate
1836 * native call, or have gone off the top of the stack and the thread
1837 * needs to exit. Either way, we return from here, leaving the
1838 * exception raised.
1839 *
1840 * If we do find a catch block, we want to transfer execution to
1841 * that point.
1842 *
1843 * Note this can cause an exception while resolving classes in
1844 * the "catch" blocks.
1845 */
1846 catchRelPc = dvmFindCatchBlock(self, pc - curMethod->insns,
1847 exception, false, (void**)(void*)&fp);
1848
1849 /*
1850 * Restore the stack bounds after an overflow. This isn't going to
1851 * be correct in all circumstances, e.g. if JNI code devours the
1852 * exception this won't happen until some other exception gets
1853 * thrown. If the code keeps pushing the stack bounds we'll end
1854 * up aborting the VM.
1855 *
1856 * Note we want to do this *after* the call to dvmFindCatchBlock,
1857 * because that may need extra stack space to resolve exception
1858 * classes (e.g. through a class loader).
1859 *
1860 * It's possible for the stack overflow handling to cause an
1861 * exception (specifically, class resolution in a "catch" block
1862 * during the call above), so we could see the thread's overflow
1863 * flag raised but actually be running in a "nested" interpreter
1864 * frame. We don't allow doubled-up StackOverflowErrors, so
1865 * we can check for this by just looking at the exception type
1866 * in the cleanup function. Also, we won't unroll past the SOE
1867 * point because the more-recent exception will hit a break frame
1868 * as it unrolls to here.
1869 */
1870 if (self->stackOverflowed)
1871 dvmCleanupStackOverflow(self, exception);
1872
1873 if (catchRelPc < 0) {
1874 /* falling through to JNI code or off the bottom of the stack */
1875 #if DVM_SHOW_EXCEPTION >= 2
1876 ALOGD("Exception %s from %s:%d not caught locally",
1877 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
1878 dvmLineNumFromPC(curMethod, pc - curMethod->insns));
1879 #endif
1880 dvmSetException(self, exception);
1881 dvmReleaseTrackedAlloc(exception, self);
1882 GOTO_bail();
1883 }
1884
1885 #if DVM_SHOW_EXCEPTION >= 3
1886 {
1887 const Method* catchMethod = SAVEAREA_FROM_FP(fp)->method;
1888 ALOGD("Exception %s thrown from %s:%d to %s:%d",
1889 exception->clazz->descriptor, dvmGetMethodSourceFile(curMethod),
1890 dvmLineNumFromPC(curMethod, pc - curMethod->insns),
1891 dvmGetMethodSourceFile(catchMethod),
1892 dvmLineNumFromPC(catchMethod, catchRelPc));
1893 }
1894 #endif
1895
1896 /*
1897 * Adjust local variables to match self->interpSave.curFrame and the
1898 * updated PC.
1899 */
1900 //fp = (u4*) self->interpSave.curFrame;
1901 curMethod = SAVEAREA_FROM_FP(fp)->method;
1902 self->interpSave.method = curMethod;
1903 //methodClass = curMethod->clazz;
1904 methodClassDex = curMethod->clazz->pDvmDex;
1905 pc = curMethod->insns + catchRelPc;
1906 ILOGV("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
1907 curMethod->name, curMethod->shorty);
1908 DUMP_REGS(curMethod, fp, false); // show all regs
1909
1910 /*
1911 * Restore the exception if the handler wants it.
1912 *
1913 * The Dalvik spec mandates that, if an exception handler wants to
1914 * do something with the exception, the first instruction executed
1915 * must be "move-exception". We can pass the exception along
1916 * through the thread struct, and let the move-exception instruction
1917 * clear it for us.
1918 *
1919 * If the handler doesn't call move-exception, we don't want to
1920 * finish here with an exception still pending.
1921 */
1922 if (INST_INST(FETCH(0)) == OP_MOVE_EXCEPTION)
1923 dvmSetException(self, exception);
1924
1925 dvmReleaseTrackedAlloc(exception, self);
1926 FINISH(0);
1927 }
1928 GOTO_TARGET_END
1929
1930
1931
1932 /*
1933 * General handling for invoke-{virtual,super,direct,static,interface},
1934 * including "quick" variants.
1935 *
1936 * Set "methodToCall" to the Method we're calling, and "methodCallRange"
1937 * depending on whether this is a "/range" instruction.
1938 *
1939 * For a range call:
1940 * "vsrc1" holds the argument count (8 bits)
1941 * "vdst" holds the first argument in the range
1942 * For a non-range call:
1943 * "vsrc1" holds the argument count (4 bits) and the 5th argument index
1944 * "vdst" holds four 4-bit register indices
1945 *
1946 * The caller must EXPORT_PC before jumping here, because any method
1947 * call can throw a stack overflow exception.
1948 */
GOTO_TARGET(invokeMethod,bool methodCallRange,const Method * _methodToCall,u2 count,u2 regs)1949 GOTO_TARGET(invokeMethod, bool methodCallRange, const Method* _methodToCall,
1950 u2 count, u2 regs)
1951 {
1952 STUB_HACK(vsrc1 = count; vdst = regs; methodToCall = _methodToCall;);
1953
1954 //printf("range=%d call=%p count=%d regs=0x%04x\n",
1955 // methodCallRange, methodToCall, count, regs);
1956 //printf(" --> %s.%s %s\n", methodToCall->clazz->descriptor,
1957 // methodToCall->name, methodToCall->shorty);
1958
1959 u4* outs;
1960 int i;
1961
1962 /*
1963 * Copy args. This may corrupt vsrc1/vdst.
1964 */
1965 if (methodCallRange) {
1966 // could use memcpy or a "Duff's device"; most functions have
1967 // so few args it won't matter much
1968 assert(vsrc1 <= curMethod->outsSize);
1969 assert(vsrc1 == methodToCall->insSize);
1970 outs = OUTS_FROM_FP(fp, vsrc1);
1971 for (i = 0; i < vsrc1; i++)
1972 outs[i] = GET_REGISTER(vdst+i);
1973 } else {
1974 u4 count = vsrc1 >> 4;
1975
1976 assert(count <= curMethod->outsSize);
1977 assert(count == methodToCall->insSize);
1978 assert(count <= 5);
1979
1980 outs = OUTS_FROM_FP(fp, count);
1981 #if 0
1982 if (count == 5) {
1983 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
1984 count--;
1985 }
1986 for (i = 0; i < (int) count; i++) {
1987 outs[i] = GET_REGISTER(vdst & 0x0f);
1988 vdst >>= 4;
1989 }
1990 #else
1991 // This version executes fewer instructions but is larger
1992 // overall. Seems to be a teensy bit faster.
1993 assert((vdst >> 16) == 0); // 16 bits -or- high 16 bits clear
1994 switch (count) {
1995 case 5:
1996 outs[4] = GET_REGISTER(vsrc1 & 0x0f);
1997 case 4:
1998 outs[3] = GET_REGISTER(vdst >> 12);
1999 case 3:
2000 outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
2001 case 2:
2002 outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
2003 case 1:
2004 outs[0] = GET_REGISTER(vdst & 0x0f);
2005 default:
2006 ;
2007 }
2008 #endif
2009 }
2010 }
2011
2012 /*
2013 * (This was originally a "goto" target; I've kept it separate from the
2014 * stuff above in case we want to refactor things again.)
2015 *
2016 * At this point, we have the arguments stored in the "outs" area of
2017 * the current method's stack frame, and the method to call in
2018 * "methodToCall". Push a new stack frame.
2019 */
2020 {
2021 StackSaveArea* newSaveArea;
2022 u4* newFp;
2023
2024 ILOGV("> %s%s.%s %s",
2025 dvmIsNativeMethod(methodToCall) ? "(NATIVE) " : "",
2026 methodToCall->clazz->descriptor, methodToCall->name,
2027 methodToCall->shorty);
2028
2029 newFp = (u4*) SAVEAREA_FROM_FP(fp) - methodToCall->registersSize;
2030 newSaveArea = SAVEAREA_FROM_FP(newFp);
2031
2032 /* verify that we have enough space */
2033 if (true) {
2034 u1* bottom;
2035 bottom = (u1*) newSaveArea - methodToCall->outsSize * sizeof(u4);
2036 if (bottom < self->interpStackEnd) {
2037 /* stack overflow */
2038 ALOGV("Stack overflow on method call (start=%p end=%p newBot=%p(%d) size=%d '%s')",
2039 self->interpStackStart, self->interpStackEnd, bottom,
2040 (u1*) fp - bottom, self->interpStackSize,
2041 methodToCall->name);
2042 dvmHandleStackOverflow(self, methodToCall);
2043 assert(dvmCheckException(self));
2044 GOTO_exceptionThrown();
2045 }
2046 //ALOGD("+++ fp=%p newFp=%p newSave=%p bottom=%p",
2047 // fp, newFp, newSaveArea, bottom);
2048 }
2049
2050 #ifdef LOG_INSTR
2051 if (methodToCall->registersSize > methodToCall->insSize) {
2052 /*
2053 * This makes valgrind quiet when we print registers that
2054 * haven't been initialized. Turn it off when the debug
2055 * messages are disabled -- we want valgrind to report any
2056 * used-before-initialized issues.
2057 */
2058 memset(newFp, 0xcc,
2059 (methodToCall->registersSize - methodToCall->insSize) * 4);
2060 }
2061 #endif
2062
2063 #ifdef EASY_GDB
2064 newSaveArea->prevSave = SAVEAREA_FROM_FP(fp);
2065 #endif
2066 newSaveArea->prevFrame = fp;
2067 newSaveArea->savedPc = pc;
2068 #if defined(WITH_JIT) && defined(MTERP_STUB)
2069 newSaveArea->returnAddr = 0;
2070 #endif
2071 newSaveArea->method = methodToCall;
2072
2073 if (self->interpBreak.ctl.subMode != 0) {
2074 /*
2075 * We mark ENTER here for both native and non-native
2076 * calls. For native calls, we'll mark EXIT on return.
2077 * For non-native calls, EXIT is marked in the RETURN op.
2078 */
2079 PC_TO_SELF();
2080 dvmReportInvoke(self, methodToCall);
2081 }
2082
2083 if (!dvmIsNativeMethod(methodToCall)) {
2084 /*
2085 * "Call" interpreted code. Reposition the PC, update the
2086 * frame pointer and other local state, and continue.
2087 */
2088 curMethod = methodToCall;
2089 self->interpSave.method = curMethod;
2090 methodClassDex = curMethod->clazz->pDvmDex;
2091 pc = methodToCall->insns;
2092 fp = newFp;
2093 self->interpSave.curFrame = fp;
2094 #ifdef EASY_GDB
2095 debugSaveArea = SAVEAREA_FROM_FP(newFp);
2096 #endif
2097 self->debugIsMethodEntry = true; // profiling, debugging
2098 ILOGD("> pc <-- %s.%s %s", curMethod->clazz->descriptor,
2099 curMethod->name, curMethod->shorty);
2100 DUMP_REGS(curMethod, fp, true); // show input args
2101 FINISH(0); // jump to method start
2102 } else {
2103 /* set this up for JNI locals, even if not a JNI native */
2104 newSaveArea->xtra.localRefCookie = self->jniLocalRefTable.segmentState.all;
2105
2106 self->interpSave.curFrame = newFp;
2107
2108 DUMP_REGS(methodToCall, newFp, true); // show input args
2109
2110 if (self->interpBreak.ctl.subMode != 0) {
2111 dvmReportPreNativeInvoke(methodToCall, self, newSaveArea->prevFrame);
2112 }
2113
2114 ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
2115 methodToCall->name, methodToCall->shorty);
2116
2117 /*
2118 * Jump through native call bridge. Because we leave no
2119 * space for locals on native calls, "newFp" points directly
2120 * to the method arguments.
2121 */
2122 (*methodToCall->nativeFunc)(newFp, &retval, methodToCall, self);
2123
2124 if (self->interpBreak.ctl.subMode != 0) {
2125 dvmReportPostNativeInvoke(methodToCall, self, newSaveArea->prevFrame);
2126 }
2127
2128 /* pop frame off */
2129 dvmPopJniLocals(self, newSaveArea);
2130 self->interpSave.curFrame = newSaveArea->prevFrame;
2131 fp = newSaveArea->prevFrame;
2132
2133 /*
2134 * If the native code threw an exception, or interpreted code
2135 * invoked by the native call threw one and nobody has cleared
2136 * it, jump to our local exception handling.
2137 */
2138 if (dvmCheckException(self)) {
2139 ALOGV("Exception thrown by/below native code");
2140 GOTO_exceptionThrown();
2141 }
2142
2143 ILOGD("> retval=0x%llx (leaving native)", retval.j);
2144 ILOGD("> (return from native %s.%s to %s.%s %s)",
2145 methodToCall->clazz->descriptor, methodToCall->name,
2146 curMethod->clazz->descriptor, curMethod->name,
2147 curMethod->shorty);
2148
2149 //u2 invokeInstr = INST_INST(FETCH(0));
2150 if (true /*invokeInstr >= OP_INVOKE_VIRTUAL &&
2151 invokeInstr <= OP_INVOKE_INTERFACE*/)
2152 {
2153 FINISH(3);
2154 } else {
2155 //ALOGE("Unknown invoke instr %02x at %d",
2156 // invokeInstr, (int) (pc - curMethod->insns));
2157 assert(false);
2158 }
2159 }
2160 }
2161 assert(false); // should not get here
2162 GOTO_TARGET_END
2163
2164 /* File: cstubs/enddefs.cpp */
2165
2166 /* undefine "magic" name remapping */
2167 #undef retval
2168 #undef pc
2169 #undef fp
2170 #undef curMethod
2171 #undef methodClassDex
2172 #undef self
2173 #undef debugTrackedRefStart
2174
2175 /* File: mips/debug.cpp */
2176 /*
2177 * Copyright (C) 2008 The Android Open Source Project
2178 *
2179 * Licensed under the Apache License, Version 2.0 (the "License");
2180 * you may not use this file except in compliance with the License.
2181 * You may obtain a copy of the License at
2182 *
2183 * http://www.apache.org/licenses/LICENSE-2.0
2184 *
2185 * Unless required by applicable law or agreed to in writing, software
2186 * distributed under the License is distributed on an "AS IS" BASIS,
2187 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2188 * See the License for the specific language governing permissions and
2189 * limitations under the License.
2190 */
2191
2192 #include <inttypes.h>
2193
2194 /*
2195 * Dump the fixed-purpose MIPS registers, along with some other info.
2196 *
2197 */
dvmMterpDumpMipsRegs(uint32_t a0,uint32_t a1,uint32_t a2,uint32_t a3)2198 void dvmMterpDumpMipsRegs(uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3)
2199 {
2200 register uint32_t rPC asm("s0");
2201 register uint32_t rFP asm("s1");
2202 register uint32_t rSELF asm("s2");
2203 register uint32_t rIBASE asm("s3");
2204 register uint32_t rINST asm("s4");
2205 register uint32_t rOBJ asm("s5");
2206 register uint32_t rBIX asm("s6");
2207 register uint32_t rTEMP asm("s7");
2208
2209 //extern char dvmAsmInstructionStart[];
2210
2211 printf("REGS: a0=%08x a1=%08x a2=%08x a3=%08x\n", a0, a1, a2, a3);
2212 printf(" : rPC=%08x rFP=%08x rSELF=%08x rIBASE=%08x\n",
2213 rPC, rFP, rSELF, rIBASE);
2214 printf(" : rINST=%08x rOBJ=%08x rBIX=%08x rTEMP=%08x \n", rINST, rOBJ, rBIX, rTEMP);
2215
2216 //Thread* self = (Thread*) rSELF;
2217 //const Method* method = self->method;
2218 printf(" + self is %p\n", dvmThreadSelf());
2219 //printf(" + currently in %s.%s %s\n",
2220 // method->clazz->descriptor, method->name, method->signature);
2221 //printf(" + dvmAsmInstructionStart = %p\n", dvmAsmInstructionStart);
2222 //printf(" + next handler for 0x%02x = %p\n",
2223 // rINST & 0xff, dvmAsmInstructionStart + (rINST & 0xff) * 64);
2224 }
2225
2226 /*
2227 * Dump the StackSaveArea for the specified frame pointer.
2228 */
dvmDumpFp(void * fp,StackSaveArea * otherSaveArea)2229 void dvmDumpFp(void* fp, StackSaveArea* otherSaveArea)
2230 {
2231 StackSaveArea* saveArea = SAVEAREA_FROM_FP(fp);
2232 printf("StackSaveArea for fp %p [%p/%p]:\n", fp, saveArea, otherSaveArea);
2233 #ifdef EASY_GDB
2234 printf(" prevSave=%p, prevFrame=%p savedPc=%p meth=%p curPc=%p\n",
2235 saveArea->prevSave, saveArea->prevFrame, saveArea->savedPc,
2236 saveArea->method, saveArea->xtra.currentPc);
2237 #else
2238 printf(" prevFrame=%p savedPc=%p meth=%p curPc=%p fp[0]=0x%08x\n",
2239 saveArea->prevFrame, saveArea->savedPc,
2240 saveArea->method, saveArea->xtra.currentPc,
2241 *(u4*)fp);
2242 #endif
2243 }
2244
2245 /*
2246 * Does the bulk of the work for common_printMethod().
2247 */
dvmMterpPrintMethod(Method * method)2248 void dvmMterpPrintMethod(Method* method)
2249 {
2250 /*
2251 * It is a direct (non-virtual) method if it is static, private,
2252 * or a constructor.
2253 */
2254 bool isDirect =
2255 ((method->accessFlags & (ACC_STATIC|ACC_PRIVATE)) != 0) ||
2256 (method->name[0] == '<');
2257
2258 char* desc = dexProtoCopyMethodDescriptor(&method->prototype);
2259
2260 printf("<%c:%s.%s %s> ",
2261 isDirect ? 'D' : 'V',
2262 method->clazz->descriptor,
2263 method->name,
2264 desc);
2265
2266 free(desc);
2267 }
2268
2269