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