| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| Andy McFadden | d7bf365 | 2009-04-08 00:33:17 -0700 | [diff] [blame] | 2 | * This file was generated automatically by gen-mterp.py for 'armv4t'. |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 29 | #include "mterp/common/FindInterface.h" |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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_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 | |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 57 | #ifdef WITH_INSTR_CHECKS /* instruction-level paranoia (slow!) */ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 58 | # 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 | /* |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 97 | * 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 Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 109 | * 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; \ |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 132 | EXPORT_EXTRA_PC(); \ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 133 | } while (false) |
| 134 | #else |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 135 | # define ADJUST_PC(_offset) do { \ |
| 136 | pc += _offset; \ |
| 137 | EXPORT_EXTRA_PC(); \ |
| 138 | } while (false) |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 139 | #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) |
| 157 | void dvmDumpRegs(const Method* method, const u4* framePtr, bool inOnly); |
| 158 | # define DUMP_REGS(_meth, _frame, _inOnly) dvmDumpRegs(_meth, _frame, _inOnly) |
| 159 | static 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 */ |
| 167 | static 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 */ |
| 186 | static 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 */ |
| 203 | static 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 */ |
| 222 | static inline void putDoubleToArray(u4* ptr, int idx, double dval) |
| 223 | { |
| 224 | #if defined(NO_UNALIGN_64__UNION) |
| 225 | union { double d; u4 parts[2]; } conv; |
| 226 | |
| 227 | ptr += idx; |
| 228 | conv.d = dval; |
| 229 | ptr[0] = conv.parts[0]; |
| 230 | ptr[1] = conv.parts[1]; |
| 231 | #elif defined(NO_UNALIGN_64__MEMCPY) |
| 232 | memcpy(&ptr[idx], &dval, 8); |
| 233 | #else |
| 234 | *((double*) &ptr[idx]) = dval; |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * If enabled, validate the register number on every access. Otherwise, |
| 240 | * just do an array access. |
| 241 | * |
| 242 | * Assumes the existence of "u4* fp". |
| 243 | * |
| 244 | * "_idx" may be referenced more than once. |
| 245 | */ |
| 246 | #ifdef CHECK_REGISTER_INDICES |
| 247 | # define GET_REGISTER(_idx) \ |
| 248 | ( (_idx) < curMethod->registersSize ? \ |
| 249 | (fp[(_idx)]) : (assert(!"bad reg"),1969) ) |
| 250 | # define SET_REGISTER(_idx, _val) \ |
| 251 | ( (_idx) < curMethod->registersSize ? \ |
| 252 | (fp[(_idx)] = (u4)(_val)) : (assert(!"bad reg"),1969) ) |
| 253 | # define GET_REGISTER_AS_OBJECT(_idx) ((Object *)GET_REGISTER(_idx)) |
| 254 | # define SET_REGISTER_AS_OBJECT(_idx, _val) SET_REGISTER(_idx, (s4)_val) |
| 255 | # define GET_REGISTER_INT(_idx) ((s4) GET_REGISTER(_idx)) |
| 256 | # define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val) |
| 257 | # define GET_REGISTER_WIDE(_idx) \ |
| 258 | ( (_idx) < curMethod->registersSize-1 ? \ |
| 259 | getLongFromArray(fp, (_idx)) : (assert(!"bad reg"),1969) ) |
| 260 | # define SET_REGISTER_WIDE(_idx, _val) \ |
| 261 | ( (_idx) < curMethod->registersSize-1 ? \ |
| 262 | putLongToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969) ) |
| 263 | # define GET_REGISTER_FLOAT(_idx) \ |
| 264 | ( (_idx) < curMethod->registersSize ? \ |
| 265 | (*((float*) &fp[(_idx)])) : (assert(!"bad reg"),1969.0f) ) |
| 266 | # define SET_REGISTER_FLOAT(_idx, _val) \ |
| 267 | ( (_idx) < curMethod->registersSize ? \ |
| 268 | (*((float*) &fp[(_idx)]) = (_val)) : (assert(!"bad reg"),1969.0f) ) |
| 269 | # define GET_REGISTER_DOUBLE(_idx) \ |
| 270 | ( (_idx) < curMethod->registersSize-1 ? \ |
| 271 | getDoubleFromArray(fp, (_idx)) : (assert(!"bad reg"),1969.0) ) |
| 272 | # define SET_REGISTER_DOUBLE(_idx, _val) \ |
| 273 | ( (_idx) < curMethod->registersSize-1 ? \ |
| 274 | putDoubleToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969.0) ) |
| 275 | #else |
| 276 | # define GET_REGISTER(_idx) (fp[(_idx)]) |
| 277 | # define SET_REGISTER(_idx, _val) (fp[(_idx)] = (_val)) |
| 278 | # define GET_REGISTER_AS_OBJECT(_idx) ((Object*) fp[(_idx)]) |
| 279 | # define SET_REGISTER_AS_OBJECT(_idx, _val) (fp[(_idx)] = (u4)(_val)) |
| 280 | # define GET_REGISTER_INT(_idx) ((s4)GET_REGISTER(_idx)) |
| 281 | # define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val) |
| 282 | # define GET_REGISTER_WIDE(_idx) getLongFromArray(fp, (_idx)) |
| 283 | # define SET_REGISTER_WIDE(_idx, _val) putLongToArray(fp, (_idx), (_val)) |
| 284 | # define GET_REGISTER_FLOAT(_idx) (*((float*) &fp[(_idx)])) |
| 285 | # define SET_REGISTER_FLOAT(_idx, _val) (*((float*) &fp[(_idx)]) = (_val)) |
| 286 | # define GET_REGISTER_DOUBLE(_idx) getDoubleFromArray(fp, (_idx)) |
| 287 | # define SET_REGISTER_DOUBLE(_idx, _val) putDoubleToArray(fp, (_idx), (_val)) |
| 288 | #endif |
| 289 | |
| 290 | /* |
| 291 | * Get 16 bits from the specified offset of the program counter. We always |
| 292 | * want to load 16 bits at a time from the instruction stream -- it's more |
| 293 | * efficient than 8 and won't have the alignment problems that 32 might. |
| 294 | * |
| 295 | * Assumes existence of "const u2* pc". |
| 296 | */ |
| 297 | #define FETCH(_offset) (pc[(_offset)]) |
| 298 | |
| 299 | /* |
| 300 | * Extract instruction byte from 16-bit fetch (_inst is a u2). |
| 301 | */ |
| 302 | #define INST_INST(_inst) ((_inst) & 0xff) |
| 303 | |
| 304 | /* |
| Andy McFadden | 9651693 | 2009-10-28 17:39:02 -0700 | [diff] [blame] | 305 | * Replace the opcode (used when handling breakpoints). _opcode is a u1. |
| 306 | */ |
| 307 | #define INST_REPLACE_OP(_inst, _opcode) (((_inst) & 0xff00) | _opcode) |
| 308 | |
| 309 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 310 | * Extract the "vA, vB" 4-bit registers from the instruction word (_inst is u2). |
| 311 | */ |
| 312 | #define INST_A(_inst) (((_inst) >> 8) & 0x0f) |
| 313 | #define INST_B(_inst) ((_inst) >> 12) |
| 314 | |
| 315 | /* |
| 316 | * Get the 8-bit "vAA" 8-bit register index from the instruction word. |
| 317 | * (_inst is u2) |
| 318 | */ |
| 319 | #define INST_AA(_inst) ((_inst) >> 8) |
| 320 | |
| 321 | /* |
| 322 | * The current PC must be available to Throwable constructors, e.g. |
| 323 | * those created by dvmThrowException(), so that the exception stack |
| 324 | * trace can be generated correctly. If we don't do this, the offset |
| 325 | * within the current method won't be shown correctly. See the notes |
| 326 | * in Exception.c. |
| 327 | * |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 328 | * This is also used to determine the address for precise GC. |
| 329 | * |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 330 | * Assumes existence of "u4* fp" and "const u2* pc". |
| 331 | */ |
| 332 | #define EXPORT_PC() (SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc) |
| 333 | |
| 334 | /* |
| 335 | * Determine if we need to switch to a different interpreter. "_current" |
| 336 | * is either INTERP_STD or INTERP_DBG. It should be fixed for a given |
| 337 | * interpreter generation file, which should remove the outer conditional |
| 338 | * from the following. |
| 339 | * |
| 340 | * If we're building without debug and profiling support, we never switch. |
| 341 | */ |
| 342 | #if defined(WITH_PROFILER) || defined(WITH_DEBUGGER) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 343 | #if defined(WITH_JIT) |
| 344 | # define NEED_INTERP_SWITCH(_current) ( \ |
| 345 | (_current == INTERP_STD) ? \ |
| Bill Buzbee | e92aa41 | 2010-02-08 10:41:32 -0800 | [diff] [blame] | 346 | dvmJitDebuggerOrProfilerActive() : !dvmJitDebuggerOrProfilerActive() ) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 347 | #else |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 348 | # define NEED_INTERP_SWITCH(_current) ( \ |
| 349 | (_current == INTERP_STD) ? \ |
| 350 | dvmDebuggerOrProfilerActive() : !dvmDebuggerOrProfilerActive() ) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 351 | #endif |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 352 | #else |
| 353 | # define NEED_INTERP_SWITCH(_current) (false) |
| 354 | #endif |
| 355 | |
| 356 | /* |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 357 | * Check to see if "obj" is NULL. If so, throw an exception. Assumes the |
| 358 | * pc has already been exported to the stack. |
| 359 | * |
| 360 | * Perform additional checks on debug builds. |
| 361 | * |
| 362 | * Use this to check for NULL when the instruction handler calls into |
| 363 | * something that could throw an exception (so we have already called |
| 364 | * EXPORT_PC at the top). |
| 365 | */ |
| 366 | static inline bool checkForNull(Object* obj) |
| 367 | { |
| 368 | if (obj == NULL) { |
| 369 | dvmThrowException("Ljava/lang/NullPointerException;", NULL); |
| 370 | return false; |
| 371 | } |
| 372 | #ifdef WITH_EXTRA_OBJECT_VALIDATION |
| 373 | if (!dvmIsValidObject(obj)) { |
| 374 | LOGE("Invalid object %p\n", obj); |
| 375 | dvmAbort(); |
| 376 | } |
| 377 | #endif |
| 378 | #ifndef NDEBUG |
| 379 | if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) { |
| 380 | /* probable heap corruption */ |
| 381 | LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj); |
| 382 | dvmAbort(); |
| 383 | } |
| 384 | #endif |
| 385 | return true; |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * Check to see if "obj" is NULL. If so, export the PC into the stack |
| 390 | * frame and throw an exception. |
| 391 | * |
| 392 | * Perform additional checks on debug builds. |
| 393 | * |
| 394 | * Use this to check for NULL when the instruction handler doesn't do |
| 395 | * anything else that can throw an exception. |
| 396 | */ |
| 397 | static inline bool checkForNullExportPC(Object* obj, u4* fp, const u2* pc) |
| 398 | { |
| 399 | if (obj == NULL) { |
| 400 | EXPORT_PC(); |
| 401 | dvmThrowException("Ljava/lang/NullPointerException;", NULL); |
| 402 | return false; |
| 403 | } |
| 404 | #ifdef WITH_EXTRA_OBJECT_VALIDATION |
| 405 | if (!dvmIsValidObject(obj)) { |
| 406 | LOGE("Invalid object %p\n", obj); |
| 407 | dvmAbort(); |
| 408 | } |
| 409 | #endif |
| 410 | #ifndef NDEBUG |
| 411 | if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) { |
| 412 | /* probable heap corruption */ |
| 413 | LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj); |
| 414 | dvmAbort(); |
| 415 | } |
| 416 | #endif |
| 417 | return true; |
| 418 | } |
| 419 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 420 | /* File: cstubs/stubdefs.c */ |
| 421 | /* this is a standard (no debug support) interpreter */ |
| 422 | #define INTERP_TYPE INTERP_STD |
| 423 | #define CHECK_DEBUG_AND_PROF() ((void)0) |
| 424 | # define CHECK_TRACKED_REFS() ((void)0) |
| Bill Buzbee | e92aa41 | 2010-02-08 10:41:32 -0800 | [diff] [blame] | 425 | #define CHECK_JIT() (0) |
| 426 | #define ABORT_JIT_TSELECT() ((void)0) |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * In the C mterp stubs, "goto" is a function call followed immediately |
| 430 | * by a return. |
| 431 | */ |
| 432 | |
| 433 | #define GOTO_TARGET_DECL(_target, ...) \ |
| 434 | void dvmMterp_##_target(MterpGlue* glue, ## __VA_ARGS__); |
| 435 | |
| 436 | #define GOTO_TARGET(_target, ...) \ |
| 437 | void dvmMterp_##_target(MterpGlue* glue, ## __VA_ARGS__) { \ |
| 438 | u2 ref, vsrc1, vsrc2, vdst; \ |
| 439 | u2 inst = FETCH(0); \ |
| 440 | const Method* methodToCall; \ |
| 441 | StackSaveArea* debugSaveArea; |
| 442 | |
| 443 | #define GOTO_TARGET_END } |
| 444 | |
| 445 | /* |
| 446 | * Redefine what used to be local variable accesses into MterpGlue struct |
| 447 | * references. (These are undefined down in "footer.c".) |
| 448 | */ |
| 449 | #define retval glue->retval |
| 450 | #define pc glue->pc |
| 451 | #define fp glue->fp |
| 452 | #define curMethod glue->method |
| 453 | #define methodClassDex glue->methodClassDex |
| 454 | #define self glue->self |
| 455 | #define debugTrackedRefStart glue->debugTrackedRefStart |
| 456 | |
| 457 | /* ugh */ |
| 458 | #define STUB_HACK(x) x |
| 459 | |
| 460 | |
| 461 | /* |
| 462 | * Opcode handler framing macros. Here, each opcode is a separate function |
| 463 | * that takes a "glue" argument and returns void. We can't declare |
| 464 | * these "static" because they may be called from an assembly stub. |
| 465 | */ |
| 466 | #define HANDLE_OPCODE(_op) \ |
| 467 | void dvmMterp_##_op(MterpGlue* glue) { \ |
| 468 | u2 ref, vsrc1, vsrc2, vdst; \ |
| 469 | u2 inst = FETCH(0); |
| 470 | |
| 471 | #define OP_END } |
| 472 | |
| 473 | /* |
| 474 | * Like the "portable" FINISH, but don't reload "inst", and return to caller |
| 475 | * when done. |
| 476 | */ |
| 477 | #define FINISH(_offset) { \ |
| 478 | ADJUST_PC(_offset); \ |
| 479 | CHECK_DEBUG_AND_PROF(); \ |
| 480 | CHECK_TRACKED_REFS(); \ |
| 481 | return; \ |
| 482 | } |
| 483 | |
| 484 | |
| 485 | /* |
| 486 | * The "goto label" statements turn into function calls followed by |
| 487 | * return statements. Some of the functions take arguments, which in the |
| 488 | * portable interpreter are handled by assigning values to globals. |
| 489 | */ |
| 490 | |
| 491 | #define GOTO_exceptionThrown() \ |
| 492 | do { \ |
| 493 | dvmMterp_exceptionThrown(glue); \ |
| 494 | return; \ |
| 495 | } while(false) |
| 496 | |
| 497 | #define GOTO_returnFromMethod() \ |
| 498 | do { \ |
| 499 | dvmMterp_returnFromMethod(glue); \ |
| 500 | return; \ |
| 501 | } while(false) |
| 502 | |
| 503 | #define GOTO_invoke(_target, _methodCallRange) \ |
| 504 | do { \ |
| 505 | dvmMterp_##_target(glue, _methodCallRange); \ |
| 506 | return; \ |
| 507 | } while(false) |
| 508 | |
| 509 | #define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst) \ |
| 510 | do { \ |
| 511 | dvmMterp_invokeMethod(glue, _methodCallRange, _methodToCall, \ |
| 512 | _vsrc1, _vdst); \ |
| 513 | return; \ |
| 514 | } while(false) |
| 515 | |
| 516 | /* |
| 517 | * As a special case, "goto bail" turns into a longjmp. Use "bail_switch" |
| 518 | * if we need to switch to the other interpreter upon our return. |
| 519 | */ |
| 520 | #define GOTO_bail() \ |
| 521 | dvmMterpStdBail(glue, false); |
| 522 | #define GOTO_bail_switch() \ |
| 523 | dvmMterpStdBail(glue, true); |
| 524 | |
| 525 | /* |
| 526 | * Periodically check for thread suspension. |
| 527 | * |
| 528 | * While we're at it, see if a debugger has attached or the profiler has |
| 529 | * started. If so, switch to a different "goto" table. |
| 530 | */ |
| 531 | #define PERIODIC_CHECKS(_entryPoint, _pcadj) { \ |
| Andy McFadden | 3a1aedb | 2009-05-07 13:30:23 -0700 | [diff] [blame] | 532 | if (dvmCheckSuspendQuick(self)) { \ |
| 533 | EXPORT_PC(); /* need for precise GC */ \ |
| 534 | dvmCheckSuspendPending(self); \ |
| 535 | } \ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 536 | if (NEED_INTERP_SWITCH(INTERP_TYPE)) { \ |
| 537 | ADJUST_PC(_pcadj); \ |
| 538 | glue->entryPoint = _entryPoint; \ |
| 539 | LOGVV("threadid=%d: switch to STD ep=%d adj=%d\n", \ |
| Andy McFadden | 080ca4a | 2009-08-05 13:20:16 -0700 | [diff] [blame] | 540 | self->threadId, (_entryPoint), (_pcadj)); \ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 541 | GOTO_bail_switch(); \ |
| 542 | } \ |
| 543 | } |
| 544 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 545 | /* File: c/opcommon.c */ |
| 546 | /* forward declarations of goto targets */ |
| 547 | GOTO_TARGET_DECL(filledNewArray, bool methodCallRange); |
| 548 | GOTO_TARGET_DECL(invokeVirtual, bool methodCallRange); |
| 549 | GOTO_TARGET_DECL(invokeSuper, bool methodCallRange); |
| 550 | GOTO_TARGET_DECL(invokeInterface, bool methodCallRange); |
| 551 | GOTO_TARGET_DECL(invokeDirect, bool methodCallRange); |
| 552 | GOTO_TARGET_DECL(invokeStatic, bool methodCallRange); |
| 553 | GOTO_TARGET_DECL(invokeVirtualQuick, bool methodCallRange); |
| 554 | GOTO_TARGET_DECL(invokeSuperQuick, bool methodCallRange); |
| 555 | GOTO_TARGET_DECL(invokeMethod, bool methodCallRange, const Method* methodToCall, |
| 556 | u2 count, u2 regs); |
| 557 | GOTO_TARGET_DECL(returnFromMethod); |
| 558 | GOTO_TARGET_DECL(exceptionThrown); |
| 559 | |
| 560 | /* |
| 561 | * =========================================================================== |
| 562 | * |
| 563 | * What follows are opcode definitions shared between multiple opcodes with |
| 564 | * minor substitutions handled by the C pre-processor. These should probably |
| 565 | * use the mterp substitution mechanism instead, with the code here moved |
| 566 | * into common fragment files (like the asm "binop.S"), although it's hard |
| 567 | * to give up the C preprocessor in favor of the much simpler text subst. |
| 568 | * |
| 569 | * =========================================================================== |
| 570 | */ |
| 571 | |
| 572 | #define HANDLE_NUMCONV(_opcode, _opname, _fromtype, _totype) \ |
| 573 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 574 | vdst = INST_A(inst); \ |
| 575 | vsrc1 = INST_B(inst); \ |
| 576 | ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \ |
| 577 | SET_REGISTER##_totype(vdst, \ |
| 578 | GET_REGISTER##_fromtype(vsrc1)); \ |
| 579 | FINISH(1); |
| 580 | |
| 581 | #define HANDLE_FLOAT_TO_INT(_opcode, _opname, _fromvtype, _fromrtype, \ |
| 582 | _tovtype, _tortype) \ |
| 583 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 584 | { \ |
| 585 | /* spec defines specific handling for +/- inf and NaN values */ \ |
| 586 | _fromvtype val; \ |
| 587 | _tovtype intMin, intMax, result; \ |
| 588 | vdst = INST_A(inst); \ |
| 589 | vsrc1 = INST_B(inst); \ |
| 590 | ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \ |
| 591 | val = GET_REGISTER##_fromrtype(vsrc1); \ |
| 592 | intMin = (_tovtype) 1 << (sizeof(_tovtype) * 8 -1); \ |
| 593 | intMax = ~intMin; \ |
| 594 | result = (_tovtype) val; \ |
| 595 | if (val >= intMax) /* +inf */ \ |
| 596 | result = intMax; \ |
| 597 | else if (val <= intMin) /* -inf */ \ |
| 598 | result = intMin; \ |
| 599 | else if (val != val) /* NaN */ \ |
| 600 | result = 0; \ |
| 601 | else \ |
| 602 | result = (_tovtype) val; \ |
| 603 | SET_REGISTER##_tortype(vdst, result); \ |
| 604 | } \ |
| 605 | FINISH(1); |
| 606 | |
| 607 | #define HANDLE_INT_TO_SMALL(_opcode, _opname, _type) \ |
| 608 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 609 | vdst = INST_A(inst); \ |
| 610 | vsrc1 = INST_B(inst); \ |
| 611 | ILOGV("|int-to-%s v%d,v%d", (_opname), vdst, vsrc1); \ |
| 612 | SET_REGISTER(vdst, (_type) GET_REGISTER(vsrc1)); \ |
| 613 | FINISH(1); |
| 614 | |
| 615 | /* NOTE: the comparison result is always a signed 4-byte integer */ |
| 616 | #define HANDLE_OP_CMPX(_opcode, _opname, _varType, _type, _nanVal) \ |
| 617 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 618 | { \ |
| 619 | int result; \ |
| 620 | u2 regs; \ |
| 621 | _varType val1, val2; \ |
| 622 | vdst = INST_AA(inst); \ |
| 623 | regs = FETCH(1); \ |
| 624 | vsrc1 = regs & 0xff; \ |
| 625 | vsrc2 = regs >> 8; \ |
| 626 | ILOGV("|cmp%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 627 | val1 = GET_REGISTER##_type(vsrc1); \ |
| 628 | val2 = GET_REGISTER##_type(vsrc2); \ |
| 629 | if (val1 == val2) \ |
| 630 | result = 0; \ |
| 631 | else if (val1 < val2) \ |
| 632 | result = -1; \ |
| 633 | else if (val1 > val2) \ |
| 634 | result = 1; \ |
| 635 | else \ |
| 636 | result = (_nanVal); \ |
| 637 | ILOGV("+ result=%d\n", result); \ |
| 638 | SET_REGISTER(vdst, result); \ |
| 639 | } \ |
| 640 | FINISH(2); |
| 641 | |
| 642 | #define HANDLE_OP_IF_XX(_opcode, _opname, _cmp) \ |
| 643 | HANDLE_OPCODE(_opcode /*vA, vB, +CCCC*/) \ |
| 644 | vsrc1 = INST_A(inst); \ |
| 645 | vsrc2 = INST_B(inst); \ |
| 646 | if ((s4) GET_REGISTER(vsrc1) _cmp (s4) GET_REGISTER(vsrc2)) { \ |
| 647 | int branchOffset = (s2)FETCH(1); /* sign-extended */ \ |
| 648 | ILOGV("|if-%s v%d,v%d,+0x%04x", (_opname), vsrc1, vsrc2, \ |
| 649 | branchOffset); \ |
| 650 | ILOGV("> branch taken"); \ |
| 651 | if (branchOffset < 0) \ |
| 652 | PERIODIC_CHECKS(kInterpEntryInstr, branchOffset); \ |
| 653 | FINISH(branchOffset); \ |
| 654 | } else { \ |
| 655 | ILOGV("|if-%s v%d,v%d,-", (_opname), vsrc1, vsrc2); \ |
| 656 | FINISH(2); \ |
| 657 | } |
| 658 | |
| 659 | #define HANDLE_OP_IF_XXZ(_opcode, _opname, _cmp) \ |
| 660 | HANDLE_OPCODE(_opcode /*vAA, +BBBB*/) \ |
| 661 | vsrc1 = INST_AA(inst); \ |
| 662 | if ((s4) GET_REGISTER(vsrc1) _cmp 0) { \ |
| 663 | int branchOffset = (s2)FETCH(1); /* sign-extended */ \ |
| 664 | ILOGV("|if-%s v%d,+0x%04x", (_opname), vsrc1, branchOffset); \ |
| 665 | ILOGV("> branch taken"); \ |
| 666 | if (branchOffset < 0) \ |
| 667 | PERIODIC_CHECKS(kInterpEntryInstr, branchOffset); \ |
| 668 | FINISH(branchOffset); \ |
| 669 | } else { \ |
| 670 | ILOGV("|if-%s v%d,-", (_opname), vsrc1); \ |
| 671 | FINISH(2); \ |
| 672 | } |
| 673 | |
| 674 | #define HANDLE_UNOP(_opcode, _opname, _pfx, _sfx, _type) \ |
| 675 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 676 | vdst = INST_A(inst); \ |
| 677 | vsrc1 = INST_B(inst); \ |
| 678 | ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \ |
| 679 | SET_REGISTER##_type(vdst, _pfx GET_REGISTER##_type(vsrc1) _sfx); \ |
| 680 | FINISH(1); |
| 681 | |
| 682 | #define HANDLE_OP_X_INT(_opcode, _opname, _op, _chkdiv) \ |
| 683 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 684 | { \ |
| 685 | u2 srcRegs; \ |
| 686 | vdst = INST_AA(inst); \ |
| 687 | srcRegs = FETCH(1); \ |
| 688 | vsrc1 = srcRegs & 0xff; \ |
| 689 | vsrc2 = srcRegs >> 8; \ |
| 690 | ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \ |
| 691 | if (_chkdiv != 0) { \ |
| 692 | s4 firstVal, secondVal, result; \ |
| 693 | firstVal = GET_REGISTER(vsrc1); \ |
| 694 | secondVal = GET_REGISTER(vsrc2); \ |
| 695 | if (secondVal == 0) { \ |
| 696 | EXPORT_PC(); \ |
| 697 | dvmThrowException("Ljava/lang/ArithmeticException;", \ |
| 698 | "divide by zero"); \ |
| 699 | GOTO_exceptionThrown(); \ |
| 700 | } \ |
| 701 | if ((u4)firstVal == 0x80000000 && secondVal == -1) { \ |
| 702 | if (_chkdiv == 1) \ |
| 703 | result = firstVal; /* division */ \ |
| 704 | else \ |
| 705 | result = 0; /* remainder */ \ |
| 706 | } else { \ |
| 707 | result = firstVal _op secondVal; \ |
| 708 | } \ |
| 709 | SET_REGISTER(vdst, result); \ |
| 710 | } else { \ |
| 711 | /* non-div/rem case */ \ |
| 712 | SET_REGISTER(vdst, \ |
| 713 | (s4) GET_REGISTER(vsrc1) _op (s4) GET_REGISTER(vsrc2)); \ |
| 714 | } \ |
| 715 | } \ |
| 716 | FINISH(2); |
| 717 | |
| 718 | #define HANDLE_OP_SHX_INT(_opcode, _opname, _cast, _op) \ |
| 719 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 720 | { \ |
| 721 | u2 srcRegs; \ |
| 722 | vdst = INST_AA(inst); \ |
| 723 | srcRegs = FETCH(1); \ |
| 724 | vsrc1 = srcRegs & 0xff; \ |
| 725 | vsrc2 = srcRegs >> 8; \ |
| 726 | ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \ |
| 727 | SET_REGISTER(vdst, \ |
| 728 | _cast GET_REGISTER(vsrc1) _op (GET_REGISTER(vsrc2) & 0x1f)); \ |
| 729 | } \ |
| 730 | FINISH(2); |
| 731 | |
| 732 | #define HANDLE_OP_X_INT_LIT16(_opcode, _opname, _op, _chkdiv) \ |
| 733 | HANDLE_OPCODE(_opcode /*vA, vB, #+CCCC*/) \ |
| 734 | vdst = INST_A(inst); \ |
| 735 | vsrc1 = INST_B(inst); \ |
| 736 | vsrc2 = FETCH(1); \ |
| 737 | ILOGV("|%s-int/lit16 v%d,v%d,#+0x%04x", \ |
| 738 | (_opname), vdst, vsrc1, vsrc2); \ |
| 739 | if (_chkdiv != 0) { \ |
| 740 | s4 firstVal, result; \ |
| 741 | firstVal = GET_REGISTER(vsrc1); \ |
| 742 | if ((s2) vsrc2 == 0) { \ |
| 743 | EXPORT_PC(); \ |
| 744 | dvmThrowException("Ljava/lang/ArithmeticException;", \ |
| 745 | "divide by zero"); \ |
| 746 | GOTO_exceptionThrown(); \ |
| 747 | } \ |
| 748 | if ((u4)firstVal == 0x80000000 && ((s2) vsrc2) == -1) { \ |
| 749 | /* won't generate /lit16 instr for this; check anyway */ \ |
| 750 | if (_chkdiv == 1) \ |
| 751 | result = firstVal; /* division */ \ |
| 752 | else \ |
| 753 | result = 0; /* remainder */ \ |
| 754 | } else { \ |
| 755 | result = firstVal _op (s2) vsrc2; \ |
| 756 | } \ |
| 757 | SET_REGISTER(vdst, result); \ |
| 758 | } else { \ |
| 759 | /* non-div/rem case */ \ |
| 760 | SET_REGISTER(vdst, GET_REGISTER(vsrc1) _op (s2) vsrc2); \ |
| 761 | } \ |
| 762 | FINISH(2); |
| 763 | |
| 764 | #define HANDLE_OP_X_INT_LIT8(_opcode, _opname, _op, _chkdiv) \ |
| 765 | HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \ |
| 766 | { \ |
| 767 | u2 litInfo; \ |
| 768 | vdst = INST_AA(inst); \ |
| 769 | litInfo = FETCH(1); \ |
| 770 | vsrc1 = litInfo & 0xff; \ |
| 771 | vsrc2 = litInfo >> 8; /* constant */ \ |
| 772 | ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \ |
| 773 | (_opname), vdst, vsrc1, vsrc2); \ |
| 774 | if (_chkdiv != 0) { \ |
| 775 | s4 firstVal, result; \ |
| 776 | firstVal = GET_REGISTER(vsrc1); \ |
| 777 | if ((s1) vsrc2 == 0) { \ |
| 778 | EXPORT_PC(); \ |
| 779 | dvmThrowException("Ljava/lang/ArithmeticException;", \ |
| 780 | "divide by zero"); \ |
| 781 | GOTO_exceptionThrown(); \ |
| 782 | } \ |
| 783 | if ((u4)firstVal == 0x80000000 && ((s1) vsrc2) == -1) { \ |
| 784 | if (_chkdiv == 1) \ |
| 785 | result = firstVal; /* division */ \ |
| 786 | else \ |
| 787 | result = 0; /* remainder */ \ |
| 788 | } else { \ |
| 789 | result = firstVal _op ((s1) vsrc2); \ |
| 790 | } \ |
| 791 | SET_REGISTER(vdst, result); \ |
| 792 | } else { \ |
| 793 | SET_REGISTER(vdst, \ |
| 794 | (s4) GET_REGISTER(vsrc1) _op (s1) vsrc2); \ |
| 795 | } \ |
| 796 | } \ |
| 797 | FINISH(2); |
| 798 | |
| 799 | #define HANDLE_OP_SHX_INT_LIT8(_opcode, _opname, _cast, _op) \ |
| 800 | HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \ |
| 801 | { \ |
| 802 | u2 litInfo; \ |
| 803 | vdst = INST_AA(inst); \ |
| 804 | litInfo = FETCH(1); \ |
| 805 | vsrc1 = litInfo & 0xff; \ |
| 806 | vsrc2 = litInfo >> 8; /* constant */ \ |
| 807 | ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \ |
| 808 | (_opname), vdst, vsrc1, vsrc2); \ |
| 809 | SET_REGISTER(vdst, \ |
| 810 | _cast GET_REGISTER(vsrc1) _op (vsrc2 & 0x1f)); \ |
| 811 | } \ |
| 812 | FINISH(2); |
| 813 | |
| 814 | #define HANDLE_OP_X_INT_2ADDR(_opcode, _opname, _op, _chkdiv) \ |
| 815 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 816 | vdst = INST_A(inst); \ |
| 817 | vsrc1 = INST_B(inst); \ |
| 818 | ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \ |
| 819 | if (_chkdiv != 0) { \ |
| 820 | s4 firstVal, secondVal, result; \ |
| 821 | firstVal = GET_REGISTER(vdst); \ |
| 822 | secondVal = GET_REGISTER(vsrc1); \ |
| 823 | if (secondVal == 0) { \ |
| 824 | EXPORT_PC(); \ |
| 825 | dvmThrowException("Ljava/lang/ArithmeticException;", \ |
| 826 | "divide by zero"); \ |
| 827 | GOTO_exceptionThrown(); \ |
| 828 | } \ |
| 829 | if ((u4)firstVal == 0x80000000 && secondVal == -1) { \ |
| 830 | if (_chkdiv == 1) \ |
| 831 | result = firstVal; /* division */ \ |
| 832 | else \ |
| 833 | result = 0; /* remainder */ \ |
| 834 | } else { \ |
| 835 | result = firstVal _op secondVal; \ |
| 836 | } \ |
| 837 | SET_REGISTER(vdst, result); \ |
| 838 | } else { \ |
| 839 | SET_REGISTER(vdst, \ |
| 840 | (s4) GET_REGISTER(vdst) _op (s4) GET_REGISTER(vsrc1)); \ |
| 841 | } \ |
| 842 | FINISH(1); |
| 843 | |
| 844 | #define HANDLE_OP_SHX_INT_2ADDR(_opcode, _opname, _cast, _op) \ |
| 845 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 846 | vdst = INST_A(inst); \ |
| 847 | vsrc1 = INST_B(inst); \ |
| 848 | ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \ |
| 849 | SET_REGISTER(vdst, \ |
| 850 | _cast GET_REGISTER(vdst) _op (GET_REGISTER(vsrc1) & 0x1f)); \ |
| 851 | FINISH(1); |
| 852 | |
| 853 | #define HANDLE_OP_X_LONG(_opcode, _opname, _op, _chkdiv) \ |
| 854 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 855 | { \ |
| 856 | u2 srcRegs; \ |
| 857 | vdst = INST_AA(inst); \ |
| 858 | srcRegs = FETCH(1); \ |
| 859 | vsrc1 = srcRegs & 0xff; \ |
| 860 | vsrc2 = srcRegs >> 8; \ |
| 861 | ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 862 | if (_chkdiv != 0) { \ |
| 863 | s8 firstVal, secondVal, result; \ |
| 864 | firstVal = GET_REGISTER_WIDE(vsrc1); \ |
| 865 | secondVal = GET_REGISTER_WIDE(vsrc2); \ |
| 866 | if (secondVal == 0LL) { \ |
| 867 | EXPORT_PC(); \ |
| 868 | dvmThrowException("Ljava/lang/ArithmeticException;", \ |
| 869 | "divide by zero"); \ |
| 870 | GOTO_exceptionThrown(); \ |
| 871 | } \ |
| 872 | if ((u8)firstVal == 0x8000000000000000ULL && \ |
| 873 | secondVal == -1LL) \ |
| 874 | { \ |
| 875 | if (_chkdiv == 1) \ |
| 876 | result = firstVal; /* division */ \ |
| 877 | else \ |
| 878 | result = 0; /* remainder */ \ |
| 879 | } else { \ |
| 880 | result = firstVal _op secondVal; \ |
| 881 | } \ |
| 882 | SET_REGISTER_WIDE(vdst, result); \ |
| 883 | } else { \ |
| 884 | SET_REGISTER_WIDE(vdst, \ |
| 885 | (s8) GET_REGISTER_WIDE(vsrc1) _op (s8) GET_REGISTER_WIDE(vsrc2)); \ |
| 886 | } \ |
| 887 | } \ |
| 888 | FINISH(2); |
| 889 | |
| 890 | #define HANDLE_OP_SHX_LONG(_opcode, _opname, _cast, _op) \ |
| 891 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 892 | { \ |
| 893 | u2 srcRegs; \ |
| 894 | vdst = INST_AA(inst); \ |
| 895 | srcRegs = FETCH(1); \ |
| 896 | vsrc1 = srcRegs & 0xff; \ |
| 897 | vsrc2 = srcRegs >> 8; \ |
| 898 | ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 899 | SET_REGISTER_WIDE(vdst, \ |
| 900 | _cast GET_REGISTER_WIDE(vsrc1) _op (GET_REGISTER(vsrc2) & 0x3f)); \ |
| 901 | } \ |
| 902 | FINISH(2); |
| 903 | |
| 904 | #define HANDLE_OP_X_LONG_2ADDR(_opcode, _opname, _op, _chkdiv) \ |
| 905 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 906 | vdst = INST_A(inst); \ |
| 907 | vsrc1 = INST_B(inst); \ |
| 908 | ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \ |
| 909 | if (_chkdiv != 0) { \ |
| 910 | s8 firstVal, secondVal, result; \ |
| 911 | firstVal = GET_REGISTER_WIDE(vdst); \ |
| 912 | secondVal = GET_REGISTER_WIDE(vsrc1); \ |
| 913 | if (secondVal == 0LL) { \ |
| 914 | EXPORT_PC(); \ |
| 915 | dvmThrowException("Ljava/lang/ArithmeticException;", \ |
| 916 | "divide by zero"); \ |
| 917 | GOTO_exceptionThrown(); \ |
| 918 | } \ |
| 919 | if ((u8)firstVal == 0x8000000000000000ULL && \ |
| 920 | secondVal == -1LL) \ |
| 921 | { \ |
| 922 | if (_chkdiv == 1) \ |
| 923 | result = firstVal; /* division */ \ |
| 924 | else \ |
| 925 | result = 0; /* remainder */ \ |
| 926 | } else { \ |
| 927 | result = firstVal _op secondVal; \ |
| 928 | } \ |
| 929 | SET_REGISTER_WIDE(vdst, result); \ |
| 930 | } else { \ |
| 931 | SET_REGISTER_WIDE(vdst, \ |
| 932 | (s8) GET_REGISTER_WIDE(vdst) _op (s8)GET_REGISTER_WIDE(vsrc1));\ |
| 933 | } \ |
| 934 | FINISH(1); |
| 935 | |
| 936 | #define HANDLE_OP_SHX_LONG_2ADDR(_opcode, _opname, _cast, _op) \ |
| 937 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 938 | vdst = INST_A(inst); \ |
| 939 | vsrc1 = INST_B(inst); \ |
| 940 | ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \ |
| 941 | SET_REGISTER_WIDE(vdst, \ |
| 942 | _cast GET_REGISTER_WIDE(vdst) _op (GET_REGISTER(vsrc1) & 0x3f)); \ |
| 943 | FINISH(1); |
| 944 | |
| 945 | #define HANDLE_OP_X_FLOAT(_opcode, _opname, _op) \ |
| 946 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 947 | { \ |
| 948 | u2 srcRegs; \ |
| 949 | vdst = INST_AA(inst); \ |
| 950 | srcRegs = FETCH(1); \ |
| 951 | vsrc1 = srcRegs & 0xff; \ |
| 952 | vsrc2 = srcRegs >> 8; \ |
| 953 | ILOGV("|%s-float v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 954 | SET_REGISTER_FLOAT(vdst, \ |
| 955 | GET_REGISTER_FLOAT(vsrc1) _op GET_REGISTER_FLOAT(vsrc2)); \ |
| 956 | } \ |
| 957 | FINISH(2); |
| 958 | |
| 959 | #define HANDLE_OP_X_DOUBLE(_opcode, _opname, _op) \ |
| 960 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 961 | { \ |
| 962 | u2 srcRegs; \ |
| 963 | vdst = INST_AA(inst); \ |
| 964 | srcRegs = FETCH(1); \ |
| 965 | vsrc1 = srcRegs & 0xff; \ |
| 966 | vsrc2 = srcRegs >> 8; \ |
| 967 | ILOGV("|%s-double v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 968 | SET_REGISTER_DOUBLE(vdst, \ |
| 969 | GET_REGISTER_DOUBLE(vsrc1) _op GET_REGISTER_DOUBLE(vsrc2)); \ |
| 970 | } \ |
| 971 | FINISH(2); |
| 972 | |
| 973 | #define HANDLE_OP_X_FLOAT_2ADDR(_opcode, _opname, _op) \ |
| 974 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 975 | vdst = INST_A(inst); \ |
| 976 | vsrc1 = INST_B(inst); \ |
| 977 | ILOGV("|%s-float-2addr v%d,v%d", (_opname), vdst, vsrc1); \ |
| 978 | SET_REGISTER_FLOAT(vdst, \ |
| 979 | GET_REGISTER_FLOAT(vdst) _op GET_REGISTER_FLOAT(vsrc1)); \ |
| 980 | FINISH(1); |
| 981 | |
| 982 | #define HANDLE_OP_X_DOUBLE_2ADDR(_opcode, _opname, _op) \ |
| 983 | HANDLE_OPCODE(_opcode /*vA, vB*/) \ |
| 984 | vdst = INST_A(inst); \ |
| 985 | vsrc1 = INST_B(inst); \ |
| 986 | ILOGV("|%s-double-2addr v%d,v%d", (_opname), vdst, vsrc1); \ |
| 987 | SET_REGISTER_DOUBLE(vdst, \ |
| 988 | GET_REGISTER_DOUBLE(vdst) _op GET_REGISTER_DOUBLE(vsrc1)); \ |
| 989 | FINISH(1); |
| 990 | |
| 991 | #define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \ |
| 992 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 993 | { \ |
| 994 | ArrayObject* arrayObj; \ |
| 995 | u2 arrayInfo; \ |
| 996 | EXPORT_PC(); \ |
| 997 | vdst = INST_AA(inst); \ |
| 998 | arrayInfo = FETCH(1); \ |
| 999 | vsrc1 = arrayInfo & 0xff; /* array ptr */ \ |
| 1000 | vsrc2 = arrayInfo >> 8; /* index */ \ |
| 1001 | ILOGV("|aget%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 1002 | arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \ |
| 1003 | if (!checkForNull((Object*) arrayObj)) \ |
| 1004 | GOTO_exceptionThrown(); \ |
| 1005 | if (GET_REGISTER(vsrc2) >= arrayObj->length) { \ |
| 1006 | LOGV("Invalid array access: %p %d (len=%d)\n", \ |
| 1007 | arrayObj, vsrc2, arrayObj->length); \ |
| 1008 | dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \ |
| 1009 | NULL); \ |
| 1010 | GOTO_exceptionThrown(); \ |
| 1011 | } \ |
| 1012 | SET_REGISTER##_regsize(vdst, \ |
| 1013 | ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]); \ |
| 1014 | ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \ |
| 1015 | } \ |
| 1016 | FINISH(2); |
| 1017 | |
| 1018 | #define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \ |
| 1019 | HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ |
| 1020 | { \ |
| 1021 | ArrayObject* arrayObj; \ |
| 1022 | u2 arrayInfo; \ |
| 1023 | EXPORT_PC(); \ |
| 1024 | vdst = INST_AA(inst); /* AA: source value */ \ |
| 1025 | arrayInfo = FETCH(1); \ |
| 1026 | vsrc1 = arrayInfo & 0xff; /* BB: array ptr */ \ |
| 1027 | vsrc2 = arrayInfo >> 8; /* CC: index */ \ |
| 1028 | ILOGV("|aput%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ |
| 1029 | arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \ |
| 1030 | if (!checkForNull((Object*) arrayObj)) \ |
| 1031 | GOTO_exceptionThrown(); \ |
| 1032 | if (GET_REGISTER(vsrc2) >= arrayObj->length) { \ |
| 1033 | dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \ |
| 1034 | NULL); \ |
| 1035 | GOTO_exceptionThrown(); \ |
| 1036 | } \ |
| 1037 | ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\ |
| 1038 | ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] = \ |
| 1039 | GET_REGISTER##_regsize(vdst); \ |
| 1040 | } \ |
| 1041 | FINISH(2); |
| 1042 | |
| 1043 | /* |
| 1044 | * It's possible to get a bad value out of a field with sub-32-bit stores |
| 1045 | * because the -quick versions always operate on 32 bits. Consider: |
| 1046 | * short foo = -1 (sets a 32-bit register to 0xffffffff) |
| 1047 | * iput-quick foo (writes all 32 bits to the field) |
| 1048 | * short bar = 1 (sets a 32-bit register to 0x00000001) |
| 1049 | * iput-short (writes the low 16 bits to the field) |
| 1050 | * iget-quick foo (reads all 32 bits from the field, yielding 0xffff0001) |
| 1051 | * This can only happen when optimized and non-optimized code has interleaved |
| 1052 | * access to the same field. This is unlikely but possible. |
| 1053 | * |
| 1054 | * The easiest way to fix this is to always read/write 32 bits at a time. On |
| 1055 | * a device with a 16-bit data bus this is sub-optimal. (The alternative |
| 1056 | * approach is to have sub-int versions of iget-quick, but now we're wasting |
| 1057 | * Dalvik instruction space and making it less likely that handler code will |
| 1058 | * already be in the CPU i-cache.) |
| 1059 | */ |
| 1060 | #define HANDLE_IGET_X(_opcode, _opname, _ftype, _regsize) \ |
| 1061 | HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ |
| 1062 | { \ |
| 1063 | InstField* ifield; \ |
| 1064 | Object* obj; \ |
| 1065 | EXPORT_PC(); \ |
| 1066 | vdst = INST_A(inst); \ |
| 1067 | vsrc1 = INST_B(inst); /* object ptr */ \ |
| 1068 | ref = FETCH(1); /* field ref */ \ |
| 1069 | ILOGV("|iget%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \ |
| 1070 | obj = (Object*) GET_REGISTER(vsrc1); \ |
| 1071 | if (!checkForNull(obj)) \ |
| 1072 | GOTO_exceptionThrown(); \ |
| 1073 | ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \ |
| 1074 | if (ifield == NULL) { \ |
| 1075 | ifield = dvmResolveInstField(curMethod->clazz, ref); \ |
| 1076 | if (ifield == NULL) \ |
| 1077 | GOTO_exceptionThrown(); \ |
| 1078 | } \ |
| 1079 | SET_REGISTER##_regsize(vdst, \ |
| 1080 | dvmGetField##_ftype(obj, ifield->byteOffset)); \ |
| 1081 | ILOGV("+ IGET '%s'=0x%08llx", ifield->field.name, \ |
| 1082 | (u8) GET_REGISTER##_regsize(vdst)); \ |
| 1083 | UPDATE_FIELD_GET(&ifield->field); \ |
| 1084 | } \ |
| 1085 | FINISH(2); |
| 1086 | |
| 1087 | #define HANDLE_IGET_X_QUICK(_opcode, _opname, _ftype, _regsize) \ |
| 1088 | HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ |
| 1089 | { \ |
| 1090 | Object* obj; \ |
| 1091 | vdst = INST_A(inst); \ |
| 1092 | vsrc1 = INST_B(inst); /* object ptr */ \ |
| 1093 | ref = FETCH(1); /* field offset */ \ |
| 1094 | ILOGV("|iget%s-quick v%d,v%d,field@+%u", \ |
| 1095 | (_opname), vdst, vsrc1, ref); \ |
| 1096 | obj = (Object*) GET_REGISTER(vsrc1); \ |
| 1097 | if (!checkForNullExportPC(obj, fp, pc)) \ |
| 1098 | GOTO_exceptionThrown(); \ |
| 1099 | SET_REGISTER##_regsize(vdst, dvmGetField##_ftype(obj, ref)); \ |
| 1100 | ILOGV("+ IGETQ %d=0x%08llx", ref, \ |
| 1101 | (u8) GET_REGISTER##_regsize(vdst)); \ |
| 1102 | } \ |
| 1103 | FINISH(2); |
| 1104 | |
| 1105 | #define HANDLE_IPUT_X(_opcode, _opname, _ftype, _regsize) \ |
| 1106 | HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ |
| 1107 | { \ |
| 1108 | InstField* ifield; \ |
| 1109 | Object* obj; \ |
| 1110 | EXPORT_PC(); \ |
| 1111 | vdst = INST_A(inst); \ |
| 1112 | vsrc1 = INST_B(inst); /* object ptr */ \ |
| 1113 | ref = FETCH(1); /* field ref */ \ |
| 1114 | ILOGV("|iput%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \ |
| 1115 | obj = (Object*) GET_REGISTER(vsrc1); \ |
| 1116 | if (!checkForNull(obj)) \ |
| 1117 | GOTO_exceptionThrown(); \ |
| 1118 | ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \ |
| 1119 | if (ifield == NULL) { \ |
| 1120 | ifield = dvmResolveInstField(curMethod->clazz, ref); \ |
| 1121 | if (ifield == NULL) \ |
| 1122 | GOTO_exceptionThrown(); \ |
| 1123 | } \ |
| 1124 | dvmSetField##_ftype(obj, ifield->byteOffset, \ |
| 1125 | GET_REGISTER##_regsize(vdst)); \ |
| 1126 | ILOGV("+ IPUT '%s'=0x%08llx", ifield->field.name, \ |
| 1127 | (u8) GET_REGISTER##_regsize(vdst)); \ |
| 1128 | UPDATE_FIELD_PUT(&ifield->field); \ |
| 1129 | } \ |
| 1130 | FINISH(2); |
| 1131 | |
| 1132 | #define HANDLE_IPUT_X_QUICK(_opcode, _opname, _ftype, _regsize) \ |
| 1133 | HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ |
| 1134 | { \ |
| 1135 | Object* obj; \ |
| 1136 | vdst = INST_A(inst); \ |
| 1137 | vsrc1 = INST_B(inst); /* object ptr */ \ |
| 1138 | ref = FETCH(1); /* field offset */ \ |
| 1139 | ILOGV("|iput%s-quick v%d,v%d,field@0x%04x", \ |
| 1140 | (_opname), vdst, vsrc1, ref); \ |
| 1141 | obj = (Object*) GET_REGISTER(vsrc1); \ |
| 1142 | if (!checkForNullExportPC(obj, fp, pc)) \ |
| 1143 | GOTO_exceptionThrown(); \ |
| 1144 | dvmSetField##_ftype(obj, ref, GET_REGISTER##_regsize(vdst)); \ |
| 1145 | ILOGV("+ IPUTQ %d=0x%08llx", ref, \ |
| 1146 | (u8) GET_REGISTER##_regsize(vdst)); \ |
| 1147 | } \ |
| 1148 | FINISH(2); |
| 1149 | |
| Ben Cheng | dd6e870 | 2010-05-07 13:05:47 -0700 | [diff] [blame] | 1150 | /* |
| 1151 | * The JIT needs dvmDexGetResolvedField() to return non-null. |
| 1152 | * Since we use the portable interpreter to build the trace, the extra |
| 1153 | * checks in HANDLE_SGET_X and HANDLE_SPUT_X are not needed for mterp. |
| 1154 | */ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1155 | #define HANDLE_SGET_X(_opcode, _opname, _ftype, _regsize) \ |
| 1156 | HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \ |
| 1157 | { \ |
| 1158 | StaticField* sfield; \ |
| 1159 | vdst = INST_AA(inst); \ |
| 1160 | ref = FETCH(1); /* field ref */ \ |
| 1161 | ILOGV("|sget%s v%d,sfield@0x%04x", (_opname), vdst, ref); \ |
| 1162 | sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \ |
| 1163 | if (sfield == NULL) { \ |
| 1164 | EXPORT_PC(); \ |
| 1165 | sfield = dvmResolveStaticField(curMethod->clazz, ref); \ |
| 1166 | if (sfield == NULL) \ |
| 1167 | GOTO_exceptionThrown(); \ |
| Ben Cheng | dd6e870 | 2010-05-07 13:05:47 -0700 | [diff] [blame] | 1168 | if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) { \ |
| 1169 | ABORT_JIT_TSELECT(); \ |
| 1170 | } \ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1171 | } \ |
| 1172 | SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield)); \ |
| 1173 | ILOGV("+ SGET '%s'=0x%08llx", \ |
| 1174 | sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \ |
| 1175 | UPDATE_FIELD_GET(&sfield->field); \ |
| 1176 | } \ |
| 1177 | FINISH(2); |
| 1178 | |
| 1179 | #define HANDLE_SPUT_X(_opcode, _opname, _ftype, _regsize) \ |
| 1180 | HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \ |
| 1181 | { \ |
| 1182 | StaticField* sfield; \ |
| 1183 | vdst = INST_AA(inst); \ |
| 1184 | ref = FETCH(1); /* field ref */ \ |
| 1185 | ILOGV("|sput%s v%d,sfield@0x%04x", (_opname), vdst, ref); \ |
| 1186 | sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \ |
| 1187 | if (sfield == NULL) { \ |
| 1188 | EXPORT_PC(); \ |
| 1189 | sfield = dvmResolveStaticField(curMethod->clazz, ref); \ |
| 1190 | if (sfield == NULL) \ |
| 1191 | GOTO_exceptionThrown(); \ |
| Ben Cheng | dd6e870 | 2010-05-07 13:05:47 -0700 | [diff] [blame] | 1192 | if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) { \ |
| 1193 | ABORT_JIT_TSELECT(); \ |
| 1194 | } \ |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1195 | } \ |
| 1196 | dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst)); \ |
| 1197 | ILOGV("+ SPUT '%s'=0x%08llx", \ |
| 1198 | sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \ |
| 1199 | UPDATE_FIELD_PUT(&sfield->field); \ |
| 1200 | } \ |
| 1201 | FINISH(2); |
| 1202 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1203 | /* File: cstubs/enddefs.c */ |
| 1204 | |
| 1205 | /* undefine "magic" name remapping */ |
| 1206 | #undef retval |
| 1207 | #undef pc |
| 1208 | #undef fp |
| 1209 | #undef curMethod |
| 1210 | #undef methodClassDex |
| 1211 | #undef self |
| 1212 | #undef debugTrackedRefStart |
| 1213 | |
| 1214 | /* File: armv5te/debug.c */ |
| 1215 | #include <inttypes.h> |
| 1216 | |
| 1217 | /* |
| 1218 | * Dump the fixed-purpose ARM registers, along with some other info. |
| 1219 | * |
| 1220 | * This function MUST be compiled in ARM mode -- THUMB will yield bogus |
| 1221 | * results. |
| 1222 | * |
| 1223 | * This will NOT preserve r0-r3/ip. |
| 1224 | */ |
| 1225 | void dvmMterpDumpArmRegs(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3) |
| 1226 | { |
| 1227 | register uint32_t rPC asm("r4"); |
| 1228 | register uint32_t rFP asm("r5"); |
| 1229 | register uint32_t rGLUE asm("r6"); |
| Andy McFadden | 1da1216 | 2009-06-05 16:19:13 -0700 | [diff] [blame] | 1230 | register uint32_t rINST asm("r7"); |
| 1231 | register uint32_t rIBASE asm("r8"); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1232 | register uint32_t r9 asm("r9"); |
| 1233 | register uint32_t r10 asm("r10"); |
| 1234 | |
| 1235 | extern char dvmAsmInstructionStart[]; |
| 1236 | |
| 1237 | printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3); |
| Andy McFadden | 1da1216 | 2009-06-05 16:19:13 -0700 | [diff] [blame] | 1238 | printf(" : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n", |
| 1239 | rPC, rFP, rGLUE, rINST); |
| 1240 | printf(" : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1241 | |
| 1242 | MterpGlue* glue = (MterpGlue*) rGLUE; |
| 1243 | const Method* method = glue->method; |
| 1244 | printf(" + self is %p\n", dvmThreadSelf()); |
| 1245 | //printf(" + currently in %s.%s %s\n", |
| Mike Lockwood | 85745e1 | 2009-07-08 12:39:37 -0400 | [diff] [blame] | 1246 | // method->clazz->descriptor, method->name, method->shorty); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1247 | //printf(" + dvmAsmInstructionStart = %p\n", dvmAsmInstructionStart); |
| 1248 | //printf(" + next handler for 0x%02x = %p\n", |
| 1249 | // rINST & 0xff, dvmAsmInstructionStart + (rINST & 0xff) * 64); |
| 1250 | } |
| 1251 | |
| 1252 | /* |
| 1253 | * Dump the StackSaveArea for the specified frame pointer. |
| 1254 | */ |
| 1255 | void dvmDumpFp(void* fp, StackSaveArea* otherSaveArea) |
| 1256 | { |
| 1257 | StackSaveArea* saveArea = SAVEAREA_FROM_FP(fp); |
| 1258 | printf("StackSaveArea for fp %p [%p/%p]:\n", fp, saveArea, otherSaveArea); |
| 1259 | #ifdef EASY_GDB |
| 1260 | printf(" prevSave=%p, prevFrame=%p savedPc=%p meth=%p curPc=%p\n", |
| 1261 | saveArea->prevSave, saveArea->prevFrame, saveArea->savedPc, |
| 1262 | saveArea->method, saveArea->xtra.currentPc); |
| 1263 | #else |
| 1264 | printf(" prevFrame=%p savedPc=%p meth=%p curPc=%p fp[0]=0x%08x\n", |
| 1265 | saveArea->prevFrame, saveArea->savedPc, |
| 1266 | saveArea->method, saveArea->xtra.currentPc, |
| 1267 | *(u4*)fp); |
| 1268 | #endif |
| 1269 | } |
| 1270 | |
| 1271 | /* |
| 1272 | * Does the bulk of the work for common_printMethod(). |
| 1273 | */ |
| 1274 | void dvmMterpPrintMethod(Method* method) |
| 1275 | { |
| 1276 | /* |
| 1277 | * It is a direct (non-virtual) method if it is static, private, |
| 1278 | * or a constructor. |
| 1279 | */ |
| Andy McFadden | a80b765 | 2009-05-18 16:38:01 -0700 | [diff] [blame] | 1280 | bool isDirect = |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1281 | ((method->accessFlags & (ACC_STATIC|ACC_PRIVATE)) != 0) || |
| 1282 | (method->name[0] == '<'); |
| 1283 | |
| 1284 | char* desc = dexProtoCopyMethodDescriptor(&method->prototype); |
| Andy McFadden | a80b765 | 2009-05-18 16:38:01 -0700 | [diff] [blame] | 1285 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1286 | printf("<%c:%s.%s %s> ", |
| 1287 | isDirect ? 'D' : 'V', |
| 1288 | method->clazz->descriptor, |
| 1289 | method->name, |
| 1290 | desc); |
| 1291 | |
| 1292 | free(desc); |
| 1293 | } |
| 1294 | |