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