InterpC-armv7-a.cpp revision 47f58250c5177adba475b0b11a36151ac0ce9ab9
1a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
2a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This file was generated automatically by gen-mterp.py for 'armv7-a'.
3a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
4a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * --> DO NOT EDIT <--
5a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
6a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
7a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* File: c/header.c */
8a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
9a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Copyright (C) 2008 The Android Open Source Project
10a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
11a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Licensed under the Apache License, Version 2.0 (the "License");
12a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * you may not use this file except in compliance with the License.
13a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * You may obtain a copy of the License at
14a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
15a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *      http://www.apache.org/licenses/LICENSE-2.0
16a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
17a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Unless required by applicable law or agreed to in writing, software
18a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * distributed under the License is distributed on an "AS IS" BASIS,
19a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * See the License for the specific language governing permissions and
21a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * limitations under the License.
22a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
23a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
24a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* common includes */
25a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "Dalvik.h"
26a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "interp/InterpDefs.h"
27a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "mterp/Mterp.h"
28a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include <math.h>                   // needed for fmod, fmodf
29a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "mterp/common/FindInterface.h"
30a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
31a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
32a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Configuration defines.  These affect the C implementations, i.e. the
33a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * portable interpreter(s) and C stubs.
34a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
35a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Some defines are controlled by the Makefile, e.g.:
36a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   WITH_INSTR_CHECKS
37a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   WITH_TRACKREF_CHECKS
38a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   EASY_GDB
39a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   NDEBUG
40a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
41a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * If THREADED_INTERP is not defined, we use a classic "while true / switch"
42a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * interpreter.  If it is defined, then the tail end of each instruction
43a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * handler fetches the next instruction and jumps directly to the handler.
44a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This increases the size of the "Std" interpreter by about 10%, but
45a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * provides a speedup of about the same magnitude.
46a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
47a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * There's a "hybrid" approach that uses a goto table instead of a switch
48a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * statement, avoiding the "is the opcode in range" tests required for switch.
49a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The performance is close to the threaded version, and without the 10%
50a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * size increase, but the benchmark results are off enough that it's not
51a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * worth adding as a third option.
52a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
53a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define THREADED_INTERP             /* threaded vs. while-loop interpreter */
54a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
55a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef WITH_INSTR_CHECKS            /* instruction-level paranoia (slow!) */
56a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define CHECK_BRANCH_OFFSETS
57a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define CHECK_REGISTER_INDICES
58a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
59a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
60a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
61529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * Some architectures require 64-bit alignment for access to 64-bit data
62529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * types.  We can't just use pointers to copy 64-bit values out of our
63529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * interpreted register set, because gcc may assume the pointer target is
64529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * aligned and generate invalid code.
65a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
66529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * There are two common approaches:
67529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden *  (1) Use a union that defines a 32-bit pair and a 64-bit value.
68529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden *  (2) Call memcpy().
69529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden *
70529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * Depending upon what compiler you're using and what options are specified,
71529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * one may be faster than the other.  For example, the compiler might
72529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * convert a memcpy() of 8 bytes into a series of instructions and omit
73529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * the call.  The union version could cause some strange side-effects,
74529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * e.g. for a while ARM gcc thought it needed separate storage for each
75529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * inlined instance, and generated instructions to zero out ~700 bytes of
76529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * stack space at the top of the interpreter.
77529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden *
78529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * The default is to use memcpy().  The current gcc for ARM seems to do
79529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * better with the union.
80a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
81a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(__ARM_EABI__)
82529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden# define NO_UNALIGN_64__UNION
83a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
84a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
85529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden
86a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden//#define LOG_INSTR                   /* verbose debugging */
87a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* set and adjust ANDROID_LOG_TAGS='*:i jdwp:i dalvikvm:i dalvikvmi:i' */
88a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
89a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
90a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Keep a tally of accesses to fields.  Currently only works if full DEX
91a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * optimization is disabled.
92a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
93a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef PROFILE_FIELD_ACCESS
94a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define UPDATE_FIELD_GET(_field) { (_field)->gets++; }
95a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define UPDATE_FIELD_PUT(_field) { (_field)->puts++; }
96a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
97a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define UPDATE_FIELD_GET(_field) ((void)0)
98a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define UPDATE_FIELD_PUT(_field) ((void)0)
99a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
100a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
101a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
102a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Export another copy of the PC on every instruction; this is largely
103a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * redundant with EXPORT_PC and the debugger code.  This value can be
104a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * compared against what we have stored on the stack with EXPORT_PC to
105a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * help ensure that we aren't missing any export calls.
106a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
107a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if WITH_EXTRA_GC_CHECKS > 1
108a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define EXPORT_EXTRA_PC() (self->currentPc2 = pc)
109a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
110a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define EXPORT_EXTRA_PC()
111a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
112a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
113a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
114a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Adjust the program counter.  "_offset" is a signed int, in 16-bit units.
115a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
116a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes the existence of "const u2* pc" and "const u2* curMethod->insns".
117a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
118a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * We don't advance the program counter until we finish an instruction or
119a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * branch, because we do want to have to unroll the PC if there's an
120a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * exception.
121a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
122a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef CHECK_BRANCH_OFFSETS
123a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ADJUST_PC(_offset) do {                                            \
124a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        int myoff = _offset;        /* deref only once */                   \
125a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (pc + myoff < curMethod->insns ||                                \
126a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            pc + myoff >= curMethod->insns + dvmGetMethodInsnsSize(curMethod)) \
127a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        {                                                                   \
128a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            char* desc;                                                     \
129a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            desc = dexProtoCopyMethodDescriptor(&curMethod->prototype);     \
130a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            LOGE("Invalid branch %d at 0x%04x in %s.%s %s\n",               \
131a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                myoff, (int) (pc - curMethod->insns),                       \
132a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                curMethod->clazz->descriptor, curMethod->name, desc);       \
133a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            free(desc);                                                     \
134a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            dvmAbort();                                                     \
135a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
136a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        pc += myoff;                                                        \
137a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_EXTRA_PC();                                                  \
138a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while (false)
139a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
140a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ADJUST_PC(_offset) do {                                            \
141a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        pc += _offset;                                                      \
142a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_EXTRA_PC();                                                  \
143a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while (false)
144a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
145a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
146a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
147a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * If enabled, log instructions as we execute them.
148a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
149a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef LOG_INSTR
150a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGD(...) ILOG(LOG_DEBUG, __VA_ARGS__)
151a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGV(...) ILOG(LOG_VERBOSE, __VA_ARGS__)
152a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOG(_level, ...) do {                                             \
153a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        char debugStrBuf[128];                                              \
154a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        snprintf(debugStrBuf, sizeof(debugStrBuf), __VA_ARGS__);            \
155a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (curMethod != NULL)                                                 \
156a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            LOG(_level, LOG_TAG"i", "%-2d|%04x%s\n",                        \
157a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                self->threadId, (int)(pc - curMethod->insns), debugStrBuf); \
158a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else                                                                \
159a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            LOG(_level, LOG_TAG"i", "%-2d|####%s\n",                        \
160a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                self->threadId, debugStrBuf);                               \
161a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while(false)
162a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmDumpRegs(const Method* method, const u4* framePtr, bool inOnly);
163a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define DUMP_REGS(_meth, _frame, _inOnly) dvmDumpRegs(_meth, _frame, _inOnly)
164a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic const char kSpacing[] = "            ";
165a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
166a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGD(...) ((void)0)
167a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGV(...) ((void)0)
168a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define DUMP_REGS(_meth, _frame, _inOnly) ((void)0)
169a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
170a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
171a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* get a long from an array of u4 */
172a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline s8 getLongFromArray(const u4* ptr, int idx)
173a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
174a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION)
175a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    union { s8 ll; u4 parts[2]; } conv;
176a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
177a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr += idx;
178a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    conv.parts[0] = ptr[0];
179a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    conv.parts[1] = ptr[1];
180a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    return conv.ll;
181529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden#else
182a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    s8 val;
183a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    memcpy(&val, &ptr[idx], 8);
184a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    return val;
185a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
186a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
187a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
188a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* store a long into an array of u4 */
189a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline void putLongToArray(u4* ptr, int idx, s8 val)
190a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
191a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION)
192a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    union { s8 ll; u4 parts[2]; } conv;
193a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
194a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr += idx;
195a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    conv.ll = val;
196a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr[0] = conv.parts[0];
197a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr[1] = conv.parts[1];
198a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
199529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden    memcpy(&ptr[idx], &val, 8);
200a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
201a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
202a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
203a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* get a double from an array of u4 */
204a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline double getDoubleFromArray(const u4* ptr, int idx)
205a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
206a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION)
207a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    union { double d; u4 parts[2]; } conv;
208a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
209a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr += idx;
210a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    conv.parts[0] = ptr[0];
211a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    conv.parts[1] = ptr[1];
212a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    return conv.d;
213529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden#else
214a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    double dval;
215a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    memcpy(&dval, &ptr[idx], 8);
216a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    return dval;
217a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
218a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
219a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
220a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* store a double into an array of u4 */
221a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline void putDoubleToArray(u4* ptr, int idx, double dval)
222a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
223a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION)
224a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    union { double d; u4 parts[2]; } conv;
225a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
226a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr += idx;
227a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    conv.d = dval;
228a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr[0] = conv.parts[0];
229a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ptr[1] = conv.parts[1];
230a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
231529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden    memcpy(&ptr[idx], &dval, 8);
232a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
233a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
234a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
235a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
236a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * If enabled, validate the register number on every access.  Otherwise,
237a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * just do an array access.
238a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
239a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes the existence of "u4* fp".
240a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
241a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * "_idx" may be referenced more than once.
242a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
243a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef CHECK_REGISTER_INDICES
244a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER(_idx) \
245a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize ? \
246a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        (fp[(_idx)]) : (assert(!"bad reg"),1969) )
247a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER(_idx, _val) \
248a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize ? \
249a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        (fp[(_idx)] = (u4)(_val)) : (assert(!"bad reg"),1969) )
250a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_AS_OBJECT(_idx)       ((Object *)GET_REGISTER(_idx))
251a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_AS_OBJECT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
252a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_INT(_idx) ((s4) GET_REGISTER(_idx))
253a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val)
254a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_WIDE(_idx) \
255a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize-1 ? \
256a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        getLongFromArray(fp, (_idx)) : (assert(!"bad reg"),1969) )
257a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_WIDE(_idx, _val) \
258a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize-1 ? \
259a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        putLongToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969) )
260a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_FLOAT(_idx) \
261a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize ? \
262a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        (*((float*) &fp[(_idx)])) : (assert(!"bad reg"),1969.0f) )
263a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_FLOAT(_idx, _val) \
264a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize ? \
265a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        (*((float*) &fp[(_idx)]) = (_val)) : (assert(!"bad reg"),1969.0f) )
266a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_DOUBLE(_idx) \
267a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize-1 ? \
268a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        getDoubleFromArray(fp, (_idx)) : (assert(!"bad reg"),1969.0) )
269a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_DOUBLE(_idx, _val) \
270a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    ( (_idx) < curMethod->registersSize-1 ? \
271a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        putDoubleToArray(fp, (_idx), (_val)) : (assert(!"bad reg"),1969.0) )
272a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
273a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER(_idx)                 (fp[(_idx)])
274a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER(_idx, _val)           (fp[(_idx)] = (_val))
275a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_AS_OBJECT(_idx)       ((Object*) fp[(_idx)])
276a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_AS_OBJECT(_idx, _val) (fp[(_idx)] = (u4)(_val))
277a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_INT(_idx)             ((s4)GET_REGISTER(_idx))
278a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_INT(_idx, _val)       SET_REGISTER(_idx, (s4)_val)
279a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_WIDE(_idx)            getLongFromArray(fp, (_idx))
280a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_WIDE(_idx, _val)      putLongToArray(fp, (_idx), (_val))
281a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_FLOAT(_idx)           (*((float*) &fp[(_idx)]))
282a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_FLOAT(_idx, _val)     (*((float*) &fp[(_idx)]) = (_val))
283a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_DOUBLE(_idx)          getDoubleFromArray(fp, (_idx))
284a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_DOUBLE(_idx, _val)    putDoubleToArray(fp, (_idx), (_val))
285a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
286a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
287a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
288a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Get 16 bits from the specified offset of the program counter.  We always
289a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * want to load 16 bits at a time from the instruction stream -- it's more
290a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * efficient than 8 and won't have the alignment problems that 32 might.
291a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
292a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes existence of "const u2* pc".
293a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
294a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define FETCH(_offset)     (pc[(_offset)])
295a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
296a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
297a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Extract instruction byte from 16-bit fetch (_inst is a u2).
298a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
299a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_INST(_inst)    ((_inst) & 0xff)
300a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
301a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
30296516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden * Replace the opcode (used when handling breakpoints).  _opcode is a u1.
30396516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden */
30496516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden#define INST_REPLACE_OP(_inst, _opcode) (((_inst) & 0xff00) | _opcode)
30596516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden
30696516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden/*
307a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Extract the "vA, vB" 4-bit registers from the instruction word (_inst is u2).
308a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
309a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_A(_inst)       (((_inst) >> 8) & 0x0f)
310a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_B(_inst)       ((_inst) >> 12)
311a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
312a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
313a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Get the 8-bit "vAA" 8-bit register index from the instruction word.
314a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * (_inst is u2)
315a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
316a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_AA(_inst)      ((_inst) >> 8)
317a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
318a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
319a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The current PC must be available to Throwable constructors, e.g.
32098f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * those created by the various exception throw routines, so that the
32198f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * exception stack trace can be generated correctly.  If we don't do this,
32298f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * the offset within the current method won't be shown correctly.  See the
32398f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * notes in Exception.c.
324a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
325a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This is also used to determine the address for precise GC.
326a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
327a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes existence of "u4* fp" and "const u2* pc".
328a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
329a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define EXPORT_PC()         (SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc)
330a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
331a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
332a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Determine if we need to switch to a different interpreter.  "_current"
333a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * is either INTERP_STD or INTERP_DBG.  It should be fixed for a given
334a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * interpreter generation file, which should remove the outer conditional
335a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * from the following.
336a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
337a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * If we're building without debug and profiling support, we never switch.
338a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
339a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(WITH_JIT)
340a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define NEED_INTERP_SWITCH(_current) (                                     \
341a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    (_current == INTERP_STD) ?                                              \
342e92aa412a6779376911d415d4b790dc14f5f6bddBill Buzbee        dvmJitDebuggerOrProfilerActive() : !dvmJitDebuggerOrProfilerActive() )
343a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
344a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define NEED_INTERP_SWITCH(_current) (                                     \
345a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    (_current == INTERP_STD) ?                                              \
346a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmDebuggerOrProfilerActive() : !dvmDebuggerOrProfilerActive() )
347a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
348a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
349a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
350a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Check to see if "obj" is NULL.  If so, throw an exception.  Assumes the
351a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * pc has already been exported to the stack.
352a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
353a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Perform additional checks on debug builds.
354a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
355a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Use this to check for NULL when the instruction handler calls into
356a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * something that could throw an exception (so we have already called
357a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * EXPORT_PC at the top).
358a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
359a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline bool checkForNull(Object* obj)
360a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
361a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    if (obj == NULL) {
362d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein        dvmThrowNullPointerException(NULL);
363a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return false;
364a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
365a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef WITH_EXTRA_OBJECT_VALIDATION
366a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    if (!dvmIsValidObject(obj)) {
367a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        LOGE("Invalid object %p\n", obj);
368a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmAbort();
369a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
370a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
371a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifndef NDEBUG
372a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
373a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        /* probable heap corruption */
374a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj);
375a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmAbort();
376a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
377a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
378a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    return true;
379a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
380a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
381a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
382a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Check to see if "obj" is NULL.  If so, export the PC into the stack
383a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * frame and throw an exception.
384a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
385a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Perform additional checks on debug builds.
386a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
387a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Use this to check for NULL when the instruction handler doesn't do
388a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * anything else that can throw an exception.
389a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
390a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline bool checkForNullExportPC(Object* obj, u4* fp, const u2* pc)
391a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
392a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    if (obj == NULL) {
393a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_PC();
394d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein        dvmThrowNullPointerException(NULL);
395a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return false;
396a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
397a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef WITH_EXTRA_OBJECT_VALIDATION
398a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    if (!dvmIsValidObject(obj)) {
399a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        LOGE("Invalid object %p\n", obj);
400a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmAbort();
401a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
402a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
403a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifndef NDEBUG
404a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) {
405a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        /* probable heap corruption */
406a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        LOGE("Invalid object class %p (in %p)\n", obj->clazz, obj);
407a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmAbort();
408a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
409a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
410a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    return true;
411a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
412a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
413a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* File: cstubs/stubdefs.c */
414a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* this is a standard (no debug support) interpreter */
415a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INTERP_TYPE INTERP_STD
416a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define CHECK_DEBUG_AND_PROF() ((void)0)
417a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define CHECK_TRACKED_REFS() ((void)0)
418fc075c2d1ae63c26f96e0c6eeb72efc898dbebbfBen Cheng#define CHECK_JIT_BOOL() (false)
419fc075c2d1ae63c26f96e0c6eeb72efc898dbebbfBen Cheng#define CHECK_JIT_VOID()
4201b3da59fff0c63770e10684e243a36f3d0218637Bill Buzbee#define END_JIT_TSELECT() ((void)0)
421a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
422a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
423a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * In the C mterp stubs, "goto" is a function call followed immediately
424a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * by a return.
425a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
426a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
427a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_TARGET_DECL(_target, ...)                                      \
4289f601a917c8878204482c37aec7005054b6776fabuzbee    void dvmMterp_##_target(Thread* self, ## __VA_ARGS__);
429a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
4307520ee7ff226e12e06818561b15741d2575072e3buzbee/* (void)xxx to quiet unused variable compiler warnings. */
431a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_TARGET(_target, ...)                                           \
4329f601a917c8878204482c37aec7005054b6776fabuzbee    void dvmMterp_##_target(Thread* self, ## __VA_ARGS__) {                 \
433a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 ref, vsrc1, vsrc2, vdst;                                         \
434a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 inst = FETCH(0);                                                 \
435a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        const Method* methodToCall;                                         \
4367520ee7ff226e12e06818561b15741d2575072e3buzbee        StackSaveArea* debugSaveArea;                                       \
4377520ee7ff226e12e06818561b15741d2575072e3buzbee        (void)ref; (void)vsrc1; (void)vsrc2; (void)vdst; (void)inst;        \
4387520ee7ff226e12e06818561b15741d2575072e3buzbee        (void)methodToCall; (void)debugSaveArea;
439a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
440a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_TARGET_END }
441a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
442a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
4439f601a917c8878204482c37aec7005054b6776fabuzbee * Redefine what used to be local variable accesses into Thread struct
444a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * references.  (These are undefined down in "footer.c".)
445a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
4469f601a917c8878204482c37aec7005054b6776fabuzbee#define retval                  self->retval
4479f601a917c8878204482c37aec7005054b6776fabuzbee#define pc                      self->interpSave.pc
4489f601a917c8878204482c37aec7005054b6776fabuzbee#define fp                      self->interpSave.fp
4499f601a917c8878204482c37aec7005054b6776fabuzbee#define curMethod               self->interpSave.method
4509f601a917c8878204482c37aec7005054b6776fabuzbee#define methodClassDex          self->interpSave.methodClassDex
4519f601a917c8878204482c37aec7005054b6776fabuzbee#define debugTrackedRefStart    self->interpSave.debugTrackedRefStart
452a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
453a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* ugh */
454a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define STUB_HACK(x) x
455a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
456a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
457a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
458a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Opcode handler framing macros.  Here, each opcode is a separate function
4599f601a917c8878204482c37aec7005054b6776fabuzbee * that takes a "self" argument and returns void.  We can't declare
460a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * these "static" because they may be called from an assembly stub.
4617520ee7ff226e12e06818561b15741d2575072e3buzbee * (void)xxx to quiet unused variable compiler warnings.
462a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
463a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OPCODE(_op)                                                  \
4649f601a917c8878204482c37aec7005054b6776fabuzbee    void dvmMterp_##_op(Thread* self) {                                     \
465a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 ref, vsrc1, vsrc2, vdst;                                         \
4667520ee7ff226e12e06818561b15741d2575072e3buzbee        u2 inst = FETCH(0);                                                 \
4677520ee7ff226e12e06818561b15741d2575072e3buzbee        (void)ref; (void)vsrc1; (void)vsrc2; (void)vdst; (void)inst;
468a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
469a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define OP_END }
470a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
471a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
472a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Like the "portable" FINISH, but don't reload "inst", and return to caller
473a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * when done.
474a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
475a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define FINISH(_offset) {                                                   \
476a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ADJUST_PC(_offset);                                                 \
477a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        CHECK_DEBUG_AND_PROF();                                             \
478a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        CHECK_TRACKED_REFS();                                               \
479a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return;                                                             \
480a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
481a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
482a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
483a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
484a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The "goto label" statements turn into function calls followed by
485a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * return statements.  Some of the functions take arguments, which in the
486a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * portable interpreter are handled by assigning values to globals.
487a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
488a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
489a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_exceptionThrown()                                              \
490a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    do {                                                                    \
4919f601a917c8878204482c37aec7005054b6776fabuzbee        dvmMterp_exceptionThrown(self);                                     \
492a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return;                                                             \
493a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while(false)
494a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
495a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_returnFromMethod()                                             \
496a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    do {                                                                    \
4979f601a917c8878204482c37aec7005054b6776fabuzbee        dvmMterp_returnFromMethod(self);                                    \
498a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return;                                                             \
499a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while(false)
500a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
5016af2ddd107842c3737c04c37343cac9be17f4209Andy McFadden#define GOTO_invoke(_target, _methodCallRange, _jumboFormat)                \
502a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    do {                                                                    \
5039f601a917c8878204482c37aec7005054b6776fabuzbee        dvmMterp_##_target(self, _methodCallRange, _jumboFormat);           \
504a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return;                                                             \
505a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while(false)
506a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
507a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst)   \
508a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    do {                                                                    \
5099f601a917c8878204482c37aec7005054b6776fabuzbee        dvmMterp_invokeMethod(self, _methodCallRange, _methodToCall,        \
510a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            _vsrc1, _vdst);                                                 \
511a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        return;                                                             \
512a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    } while(false)
513a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
514a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
515a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * As a special case, "goto bail" turns into a longjmp.  Use "bail_switch"
516a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * if we need to switch to the other interpreter upon our return.
517a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
518a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_bail()                                                         \
5199f601a917c8878204482c37aec7005054b6776fabuzbee    dvmMterpStdBail(self, false);
520a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_bail_switch()                                                  \
5219f601a917c8878204482c37aec7005054b6776fabuzbee    dvmMterpStdBail(self, true);
522a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
523a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
524a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Periodically check for thread suspension.
525a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
526a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * While we're at it, see if a debugger has attached or the profiler has
527a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * started.  If so, switch to a different "goto" table.
528a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
529a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define PERIODIC_CHECKS(_entryPoint, _pcadj) {                              \
530a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (dvmCheckSuspendQuick(self)) {                                   \
531a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            EXPORT_PC();  /* need for precise GC */                         \
532a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            dvmCheckSuspendPending(self);                                   \
533a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
534a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (NEED_INTERP_SWITCH(INTERP_TYPE)) {                              \
535a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ADJUST_PC(_pcadj);                                              \
5369f601a917c8878204482c37aec7005054b6776fabuzbee            self->entryPoint = _entryPoint;                                 \
537a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            LOGVV("threadid=%d: switch to STD ep=%d adj=%d\n",              \
538080ca4a5498eab5548856a0b8de91e3ab1e89a64Andy McFadden                self->threadId, (_entryPoint), (_pcadj));                   \
539a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_bail_switch();                                             \
540a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
541a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }
542a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
543a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* File: c/opcommon.c */
544a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* forward declarations of goto targets */
54571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(filledNewArray, bool methodCallRange, bool jumboFormat);
54671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeVirtual, bool methodCallRange, bool jumboFormat);
54771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeSuper, bool methodCallRange, bool jumboFormat);
54871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeInterface, bool methodCallRange, bool jumboFormat);
54971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeDirect, bool methodCallRange, bool jumboFormat);
55071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeStatic, bool methodCallRange, bool jumboFormat);
55171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeVirtualQuick, bool methodCallRange, bool jumboFormat);
55271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhaoGOTO_TARGET_DECL(invokeSuperQuick, bool methodCallRange, bool jumboFormat);
553a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenGOTO_TARGET_DECL(invokeMethod, bool methodCallRange, const Method* methodToCall,
554a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    u2 count, u2 regs);
555a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenGOTO_TARGET_DECL(returnFromMethod);
556a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenGOTO_TARGET_DECL(exceptionThrown);
557a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
558a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
559a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * ===========================================================================
560a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
561a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * What follows are opcode definitions shared between multiple opcodes with
562a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * minor substitutions handled by the C pre-processor.  These should probably
563a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * use the mterp substitution mechanism instead, with the code here moved
564a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * into common fragment files (like the asm "binop.S"), although it's hard
565a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * to give up the C preprocessor in favor of the much simpler text subst.
566a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
567a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * ===========================================================================
568a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
569a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
570a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_NUMCONV(_opcode, _opname, _fromtype, _totype)                \
571a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
572a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
573a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
574a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1);                       \
575a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_totype(vdst,                                         \
576a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER##_fromtype(vsrc1));                                \
577a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
578a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
579a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_FLOAT_TO_INT(_opcode, _opname, _fromvtype, _fromrtype,       \
580a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        _tovtype, _tortype)                                                 \
581a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
582a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
583a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        /* spec defines specific handling for +/- inf and NaN values */     \
584a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        _fromvtype val;                                                     \
585a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        _tovtype intMin, intMax, result;                                    \
586a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
587a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
588a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1);                       \
589a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        val = GET_REGISTER##_fromrtype(vsrc1);                              \
590a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        intMin = (_tovtype) 1 << (sizeof(_tovtype) * 8 -1);                 \
591a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        intMax = ~intMin;                                                   \
592a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        result = (_tovtype) val;                                            \
593a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (val >= intMax)          /* +inf */                              \
594a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = intMax;                                                \
595a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else if (val <= intMin)     /* -inf */                              \
596a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = intMin;                                                \
597a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else if (val != val)        /* NaN */                               \
598a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = 0;                                                     \
599a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else                                                                \
600a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = (_tovtype) val;                                        \
601a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_tortype(vdst, result);                               \
602a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
603a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(1);
604a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
605a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_INT_TO_SMALL(_opcode, _opname, _type)                        \
606a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
607a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
608a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
609a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|int-to-%s v%d,v%d", (_opname), vdst, vsrc1);                \
610a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER(vdst, (_type) GET_REGISTER(vsrc1));                    \
611a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
612a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
613a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* NOTE: the comparison result is always a signed 4-byte integer */
614a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_CMPX(_opcode, _opname, _varType, _type, _nanVal)          \
615a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
616a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
617a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        int result;                                                         \
618a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 regs;                                                            \
619a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        _varType val1, val2;                                                \
620a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
621a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        regs = FETCH(1);                                                    \
622a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = regs & 0xff;                                                \
623a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = regs >> 8;                                                  \
624a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|cmp%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);         \
625a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        val1 = GET_REGISTER##_type(vsrc1);                                  \
626a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        val2 = GET_REGISTER##_type(vsrc2);                                  \
627a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (val1 == val2)                                                   \
628a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = 0;                                                     \
629a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else if (val1 < val2)                                               \
630a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = -1;                                                    \
631a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else if (val1 > val2)                                               \
632a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = 1;                                                     \
633a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        else                                                                \
634a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            result = (_nanVal);                                             \
635a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ result=%d\n", result);                                     \
636a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER(vdst, result);                                         \
637a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
638a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
639a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
640a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_IF_XX(_opcode, _opname, _cmp)                             \
641a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB, +CCCC*/)                                \
642a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_A(inst);                                               \
643a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = INST_B(inst);                                               \
644a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if ((s4) GET_REGISTER(vsrc1) _cmp (s4) GET_REGISTER(vsrc2)) {       \
645a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            int branchOffset = (s2)FETCH(1);    /* sign-extended */         \
646a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ILOGV("|if-%s v%d,v%d,+0x%04x", (_opname), vsrc1, vsrc2,        \
647a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                branchOffset);                                              \
648a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ILOGV("> branch taken");                                        \
649a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (branchOffset < 0)                                           \
650a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                PERIODIC_CHECKS(kInterpEntryInstr, branchOffset);           \
651a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            FINISH(branchOffset);                                           \
652a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
653a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ILOGV("|if-%s v%d,v%d,-", (_opname), vsrc1, vsrc2);             \
654a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            FINISH(2);                                                      \
655a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }
656a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
657a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_IF_XXZ(_opcode, _opname, _cmp)                            \
658a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, +BBBB*/)                                   \
659a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_AA(inst);                                              \
660a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if ((s4) GET_REGISTER(vsrc1) _cmp 0) {                              \
661a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            int branchOffset = (s2)FETCH(1);    /* sign-extended */         \
662a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ILOGV("|if-%s v%d,+0x%04x", (_opname), vsrc1, branchOffset);    \
663a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ILOGV("> branch taken");                                        \
664a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (branchOffset < 0)                                           \
665a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                PERIODIC_CHECKS(kInterpEntryInstr, branchOffset);           \
666a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            FINISH(branchOffset);                                           \
667a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
668a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ILOGV("|if-%s v%d,-", (_opname), vsrc1);                        \
669a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            FINISH(2);                                                      \
670a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }
671a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
672a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_UNOP(_opcode, _opname, _pfx, _sfx, _type)                    \
673a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
674a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
675a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
676a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1);                       \
677a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_type(vdst, _pfx GET_REGISTER##_type(vsrc1) _sfx);    \
678a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
679a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
680a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT(_opcode, _opname, _op, _chkdiv)                     \
681a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
682a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
683a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 srcRegs;                                                         \
684a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
685a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        srcRegs = FETCH(1);                                                 \
686a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = srcRegs & 0xff;                                             \
687a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = srcRegs >> 8;                                               \
688a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1);                   \
689a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (_chkdiv != 0) {                                                 \
690a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            s4 firstVal, secondVal, result;                                 \
691a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            firstVal = GET_REGISTER(vsrc1);                                 \
692a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            secondVal = GET_REGISTER(vsrc2);                                \
693a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (secondVal == 0) {                                           \
694a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                EXPORT_PC();                                                \
695d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                dvmThrowArithmeticException("divide by zero");              \
696a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
697a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
698a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((u4)firstVal == 0x80000000 && secondVal == -1) {            \
699a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                if (_chkdiv == 1)                                           \
700a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = firstVal;  /* division */                      \
701a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                else                                                        \
702a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = 0;         /* remainder */                     \
703a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            } else {                                                        \
704a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                result = firstVal _op secondVal;                            \
705a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
706a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst, result);                                     \
707a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
708a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            /* non-div/rem case */                                          \
709a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst,                                              \
710a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                (s4) GET_REGISTER(vsrc1) _op (s4) GET_REGISTER(vsrc2));     \
711a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
712a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
713a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
714a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
715a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_INT(_opcode, _opname, _cast, _op)                     \
716a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
717a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
718a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 srcRegs;                                                         \
719a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
720a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        srcRegs = FETCH(1);                                                 \
721a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = srcRegs & 0xff;                                             \
722a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = srcRegs >> 8;                                               \
723a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1);                   \
724a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER(vdst,                                                  \
725a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            _cast GET_REGISTER(vsrc1) _op (GET_REGISTER(vsrc2) & 0x1f));    \
726a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
727a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
728a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
729a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT_LIT16(_opcode, _opname, _op, _chkdiv)               \
730a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB, #+CCCC*/)                               \
731a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
732a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
733a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = FETCH(1);                                                   \
734a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int/lit16 v%d,v%d,#+0x%04x",                             \
735a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (_opname), vdst, vsrc1, vsrc2);                                 \
736a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (_chkdiv != 0) {                                                 \
737a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            s4 firstVal, result;                                            \
738a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            firstVal = GET_REGISTER(vsrc1);                                 \
739a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((s2) vsrc2 == 0) {                                          \
740a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                EXPORT_PC();                                                \
741d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                dvmThrowArithmeticException("divide by zero");              \
742d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                GOTO_exceptionThrown();                                     \
743a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
744a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((u4)firstVal == 0x80000000 && ((s2) vsrc2) == -1) {         \
745a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                /* won't generate /lit16 instr for this; check anyway */    \
746a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                if (_chkdiv == 1)                                           \
747a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = firstVal;  /* division */                      \
748a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                else                                                        \
749a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = 0;         /* remainder */                     \
750a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            } else {                                                        \
751a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                result = firstVal _op (s2) vsrc2;                           \
752a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
753a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst, result);                                     \
754a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
755a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            /* non-div/rem case */                                          \
756a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst, GET_REGISTER(vsrc1) _op (s2) vsrc2);         \
757a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
758a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(2);
759a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
760a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT_LIT8(_opcode, _opname, _op, _chkdiv)                \
761a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/)                               \
762a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
763a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 litInfo;                                                         \
764a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
765a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        litInfo = FETCH(1);                                                 \
766a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = litInfo & 0xff;                                             \
767a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = litInfo >> 8;       /* constant */                          \
768a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x",                              \
769a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (_opname), vdst, vsrc1, vsrc2);                                 \
770a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (_chkdiv != 0) {                                                 \
771a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            s4 firstVal, result;                                            \
772a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            firstVal = GET_REGISTER(vsrc1);                                 \
773a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((s1) vsrc2 == 0) {                                          \
774a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                EXPORT_PC();                                                \
775d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                dvmThrowArithmeticException("divide by zero");              \
776a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
777a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
778a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((u4)firstVal == 0x80000000 && ((s1) vsrc2) == -1) {         \
779a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                if (_chkdiv == 1)                                           \
780a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = firstVal;  /* division */                      \
781a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                else                                                        \
782a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = 0;         /* remainder */                     \
783a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            } else {                                                        \
784a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                result = firstVal _op ((s1) vsrc2);                         \
785a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
786a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst, result);                                     \
787a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
788a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst,                                              \
789a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                (s4) GET_REGISTER(vsrc1) _op (s1) vsrc2);                   \
790a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
791a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
792a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
793a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
794a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_INT_LIT8(_opcode, _opname, _cast, _op)                \
795a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/)                               \
796a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
797a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 litInfo;                                                         \
798a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
799a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        litInfo = FETCH(1);                                                 \
800a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = litInfo & 0xff;                                             \
801a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = litInfo >> 8;       /* constant */                          \
802a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x",                              \
803a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (_opname), vdst, vsrc1, vsrc2);                                 \
804a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER(vdst,                                                  \
805a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            _cast GET_REGISTER(vsrc1) _op (vsrc2 & 0x1f));                  \
806a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
807a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
808a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
809a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT_2ADDR(_opcode, _opname, _op, _chkdiv)               \
810a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
811a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
812a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
813a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1);             \
814a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (_chkdiv != 0) {                                                 \
815a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            s4 firstVal, secondVal, result;                                 \
816a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            firstVal = GET_REGISTER(vdst);                                  \
817a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            secondVal = GET_REGISTER(vsrc1);                                \
818a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (secondVal == 0) {                                           \
819a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                EXPORT_PC();                                                \
820d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                dvmThrowArithmeticException("divide by zero");              \
821a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
822a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
823a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((u4)firstVal == 0x80000000 && secondVal == -1) {            \
824a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                if (_chkdiv == 1)                                           \
825a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = firstVal;  /* division */                      \
826a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                else                                                        \
827a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = 0;         /* remainder */                     \
828a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            } else {                                                        \
829a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                result = firstVal _op secondVal;                            \
830a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
831a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst, result);                                     \
832a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
833a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER(vdst,                                              \
834a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                (s4) GET_REGISTER(vdst) _op (s4) GET_REGISTER(vsrc1));      \
835a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
836a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
837a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
838a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_INT_2ADDR(_opcode, _opname, _cast, _op)               \
839a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
840a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
841a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
842a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1);             \
843a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER(vdst,                                                  \
844a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            _cast GET_REGISTER(vdst) _op (GET_REGISTER(vsrc1) & 0x1f));     \
845a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
846a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
847a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_LONG(_opcode, _opname, _op, _chkdiv)                    \
848a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
849a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
850a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 srcRegs;                                                         \
851a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
852a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        srcRegs = FETCH(1);                                                 \
853a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = srcRegs & 0xff;                                             \
854a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = srcRegs >> 8;                                               \
855a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);       \
856a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (_chkdiv != 0) {                                                 \
857a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            s8 firstVal, secondVal, result;                                 \
858a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            firstVal = GET_REGISTER_WIDE(vsrc1);                            \
859a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            secondVal = GET_REGISTER_WIDE(vsrc2);                           \
860a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (secondVal == 0LL) {                                         \
861a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                EXPORT_PC();                                                \
862d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                dvmThrowArithmeticException("divide by zero");              \
863a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
864a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
865a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((u8)firstVal == 0x8000000000000000ULL &&                    \
866a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                secondVal == -1LL)                                          \
867a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            {                                                               \
868a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                if (_chkdiv == 1)                                           \
869a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = firstVal;  /* division */                      \
870a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                else                                                        \
871a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = 0;         /* remainder */                     \
872a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            } else {                                                        \
873a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                result = firstVal _op secondVal;                            \
874a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
875a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER_WIDE(vdst, result);                                \
876a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
877a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER_WIDE(vdst,                                         \
878a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                (s8) GET_REGISTER_WIDE(vsrc1) _op (s8) GET_REGISTER_WIDE(vsrc2)); \
879a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
880a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
881a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
882a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
883a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_LONG(_opcode, _opname, _cast, _op)                    \
884a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
885a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
886a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 srcRegs;                                                         \
887a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
888a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        srcRegs = FETCH(1);                                                 \
889a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = srcRegs & 0xff;                                             \
890a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = srcRegs >> 8;                                               \
891a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);       \
892a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER_WIDE(vdst,                                             \
893a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            _cast GET_REGISTER_WIDE(vsrc1) _op (GET_REGISTER(vsrc2) & 0x3f)); \
894a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
895a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
896a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
897a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_LONG_2ADDR(_opcode, _opname, _op, _chkdiv)              \
898a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
899a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
900a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
901a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1);            \
902a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (_chkdiv != 0) {                                                 \
903a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            s8 firstVal, secondVal, result;                                 \
904a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            firstVal = GET_REGISTER_WIDE(vdst);                             \
905a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            secondVal = GET_REGISTER_WIDE(vsrc1);                           \
906a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (secondVal == 0LL) {                                         \
907a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                EXPORT_PC();                                                \
908d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein                dvmThrowArithmeticException("divide by zero");              \
909a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
910a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
911a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if ((u8)firstVal == 0x8000000000000000ULL &&                    \
912a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                secondVal == -1LL)                                          \
913a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            {                                                               \
914a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                if (_chkdiv == 1)                                           \
915a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = firstVal;  /* division */                      \
916a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                else                                                        \
917a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                    result = 0;         /* remainder */                     \
918a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            } else {                                                        \
919a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                result = firstVal _op secondVal;                            \
920a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            }                                                               \
921a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER_WIDE(vdst, result);                                \
922a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        } else {                                                            \
923a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            SET_REGISTER_WIDE(vdst,                                         \
924a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                (s8) GET_REGISTER_WIDE(vdst) _op (s8)GET_REGISTER_WIDE(vsrc1));\
925a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
926a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
927a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
928a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_LONG_2ADDR(_opcode, _opname, _cast, _op)              \
929a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
930a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
931a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
932a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1);            \
933a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER_WIDE(vdst,                                             \
934a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            _cast GET_REGISTER_WIDE(vdst) _op (GET_REGISTER(vsrc1) & 0x3f)); \
935a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
936a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
937a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_FLOAT(_opcode, _opname, _op)                            \
938a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
939a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
940a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 srcRegs;                                                         \
941a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
942a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        srcRegs = FETCH(1);                                                 \
943a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = srcRegs & 0xff;                                             \
944a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = srcRegs >> 8;                                               \
945a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-float v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);      \
946a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER_FLOAT(vdst,                                            \
947a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER_FLOAT(vsrc1) _op GET_REGISTER_FLOAT(vsrc2));       \
948a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
949a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
950a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
951a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_DOUBLE(_opcode, _opname, _op)                           \
952a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
953a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
954a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 srcRegs;                                                         \
955a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
956a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        srcRegs = FETCH(1);                                                 \
957a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = srcRegs & 0xff;                                             \
958a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = srcRegs >> 8;                                               \
959a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-double v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);     \
960a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER_DOUBLE(vdst,                                           \
961a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER_DOUBLE(vsrc1) _op GET_REGISTER_DOUBLE(vsrc2));     \
962a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
963a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
964a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
965a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_FLOAT_2ADDR(_opcode, _opname, _op)                      \
966a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
967a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
968a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
969a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-float-2addr v%d,v%d", (_opname), vdst, vsrc1);           \
970a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER_FLOAT(vdst,                                            \
971a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER_FLOAT(vdst) _op GET_REGISTER_FLOAT(vsrc1));        \
972a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
973a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
974a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_DOUBLE_2ADDR(_opcode, _opname, _op)                     \
975a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB*/)                                       \
976a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
977a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);                                               \
978a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|%s-double-2addr v%d,v%d", (_opname), vdst, vsrc1);          \
979a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER_DOUBLE(vdst,                                           \
980a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER_DOUBLE(vdst) _op GET_REGISTER_DOUBLE(vsrc1));      \
981a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        FINISH(1);
982a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
983a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize)                   \
984a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
985a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
986a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ArrayObject* arrayObj;                                              \
987a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 arrayInfo;                                                       \
988a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_PC();                                                        \
989a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
990a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        arrayInfo = FETCH(1);                                               \
991a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = arrayInfo & 0xff;    /* array ptr */                        \
992a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = arrayInfo >> 8;      /* index */                            \
993a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|aget%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);        \
994a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);                      \
995a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (!checkForNull((Object*) arrayObj))                              \
996a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
997a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
99874501e600dcb5634aa26aee0a3f57f2b45b213f2Dan Bornstein            dvmThrowArrayIndexOutOfBoundsException(                         \
99947f58250c5177adba475b0b11a36151ac0ce9ab9Dan Bornstein                arrayObj->length, GET_REGISTER(vsrc2));                     \
1000a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1001a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
1002a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_regsize(vdst,                                        \
1003a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]);            \
1004a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));  \
1005a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1006a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1007a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1008a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize)                   \
1009a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/)                                \
1010a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1011a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ArrayObject* arrayObj;                                              \
1012a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        u2 arrayInfo;                                                       \
1013a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_PC();                                                        \
1014a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);       /* AA: source value */                  \
1015a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        arrayInfo = FETCH(1);                                               \
1016a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = arrayInfo & 0xff;   /* BB: array ptr */                     \
1017a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc2 = arrayInfo >> 8;     /* CC: index */                         \
1018a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|aput%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2);        \
1019a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        arrayObj = (ArrayObject*) GET_REGISTER(vsrc1);                      \
1020a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (!checkForNull((Object*) arrayObj))                              \
1021a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1022a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
102374501e600dcb5634aa26aee0a3f57f2b45b213f2Dan Bornstein            dvmThrowArrayIndexOutOfBoundsException(                         \
102447f58250c5177adba475b0b11a36151ac0ce9ab9Dan Bornstein                arrayObj->length, GET_REGISTER(vsrc2));                     \
1025a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1026a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
1027a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
1028a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] =                \
1029a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER##_regsize(vdst);                                   \
1030a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1031a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1032a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1033a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
1034a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * It's possible to get a bad value out of a field with sub-32-bit stores
1035a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * because the -quick versions always operate on 32 bits.  Consider:
1036a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   short foo = -1  (sets a 32-bit register to 0xffffffff)
1037a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   iput-quick foo  (writes all 32 bits to the field)
1038a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   short bar = 1   (sets a 32-bit register to 0x00000001)
1039a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   iput-short      (writes the low 16 bits to the field)
1040a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *   iget-quick foo  (reads all 32 bits from the field, yielding 0xffff0001)
1041a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This can only happen when optimized and non-optimized code has interleaved
1042a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * access to the same field.  This is unlikely but possible.
1043a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
1044a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The easiest way to fix this is to always read/write 32 bits at a time.  On
1045a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * a device with a 16-bit data bus this is sub-optimal.  (The alternative
1046a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * approach is to have sub-int versions of iget-quick, but now we're wasting
1047a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Dalvik instruction space and making it less likely that handler code will
1048a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * already be in the CPU i-cache.)
1049a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
1050a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IGET_X(_opcode, _opname, _ftype, _regsize)                   \
1051a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/)                           \
1052a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1053a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        InstField* ifield;                                                  \
1054a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        Object* obj;                                                        \
1055a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_PC();                                                        \
1056a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
1057a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);   /* object ptr */                            \
1058a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ref = FETCH(1);         /* field ref */                             \
1059a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|iget%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1060a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        obj = (Object*) GET_REGISTER(vsrc1);                                \
1061a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (!checkForNull(obj))                                             \
1062a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1063a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref);  \
1064a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (ifield == NULL) {                                               \
1065a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ifield = dvmResolveInstField(curMethod->clazz, ref);            \
1066a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (ifield == NULL)                                             \
1067a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
1068a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
1069a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_regsize(vdst,                                        \
1070a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            dvmGetField##_ftype(obj, ifield->byteOffset));                  \
1071a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ IGET '%s'=0x%08llx", ifield->field.name,                   \
1072a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (u8) GET_REGISTER##_regsize(vdst));                             \
1073a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        UPDATE_FIELD_GET(&ifield->field);                                   \
1074a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1075a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1076a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
107771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao#define HANDLE_IGET_X_JUMBO(_opcode, _opname, _ftype, _regsize)             \
107871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    HANDLE_OPCODE(_opcode /*vBBBB, vCCCC, class@AAAAAAAA*/)                 \
107971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    {                                                                       \
108071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        InstField* ifield;                                                  \
108171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        Object* obj;                                                        \
108271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        EXPORT_PC();                                                        \
108371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ref = FETCH(1) | (u4)FETCH(2) << 16;   /* field ref */              \
108471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        vdst = FETCH(3);                                                    \
108571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        vsrc1 = FETCH(4);                      /* object ptr */             \
108671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("|iget%s/jumbo v%d,v%d,field@0x%08x",                         \
108771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            (_opname), vdst, vsrc1, ref);                                   \
108871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        obj = (Object*) GET_REGISTER(vsrc1);                                \
108971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        if (!checkForNull(obj))                                             \
109071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            GOTO_exceptionThrown();                                         \
109171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref);  \
109271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        if (ifield == NULL) {                                               \
109371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            ifield = dvmResolveInstField(curMethod->clazz, ref);            \
109471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            if (ifield == NULL)                                             \
109571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao                GOTO_exceptionThrown();                                     \
109671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        }                                                                   \
109771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        SET_REGISTER##_regsize(vdst,                                        \
109871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            dvmGetField##_ftype(obj, ifield->byteOffset));                  \
109971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("+ IGET '%s'=0x%08llx", ifield->field.name,                   \
110071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            (u8) GET_REGISTER##_regsize(vdst));                             \
110171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        UPDATE_FIELD_GET(&ifield->field);                                   \
110271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    }                                                                       \
110371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    FINISH(5);
110471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao
1105a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IGET_X_QUICK(_opcode, _opname, _ftype, _regsize)             \
1106a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/)                           \
1107a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1108a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        Object* obj;                                                        \
1109a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
1110a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);   /* object ptr */                            \
1111a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ref = FETCH(1);         /* field offset */                          \
1112a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|iget%s-quick v%d,v%d,field@+%u",                            \
1113a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (_opname), vdst, vsrc1, ref);                                   \
1114a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        obj = (Object*) GET_REGISTER(vsrc1);                                \
1115a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (!checkForNullExportPC(obj, fp, pc))                             \
1116a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1117a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_regsize(vdst, dvmGetField##_ftype(obj, ref));        \
1118a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ IGETQ %d=0x%08llx", ref,                                   \
1119a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (u8) GET_REGISTER##_regsize(vdst));                             \
1120a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1121a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1122a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1123a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IPUT_X(_opcode, _opname, _ftype, _regsize)                   \
1124a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/)                           \
1125a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1126a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        InstField* ifield;                                                  \
1127a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        Object* obj;                                                        \
1128a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        EXPORT_PC();                                                        \
1129a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
1130a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);   /* object ptr */                            \
1131a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ref = FETCH(1);         /* field ref */                             \
1132a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|iput%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \
1133a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        obj = (Object*) GET_REGISTER(vsrc1);                                \
1134a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (!checkForNull(obj))                                             \
1135a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1136a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref);  \
1137a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (ifield == NULL) {                                               \
1138a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            ifield = dvmResolveInstField(curMethod->clazz, ref);            \
1139a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (ifield == NULL)                                             \
1140a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
1141a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
1142a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmSetField##_ftype(obj, ifield->byteOffset,                        \
1143a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GET_REGISTER##_regsize(vdst));                                  \
1144a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ IPUT '%s'=0x%08llx", ifield->field.name,                   \
1145a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (u8) GET_REGISTER##_regsize(vdst));                             \
1146a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        UPDATE_FIELD_PUT(&ifield->field);                                   \
1147a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1148a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1149a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
115071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao#define HANDLE_IPUT_X_JUMBO(_opcode, _opname, _ftype, _regsize)             \
115171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    HANDLE_OPCODE(_opcode /*vBBBB, vCCCC, class@AAAAAAAA*/)                 \
115271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    {                                                                       \
115371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        InstField* ifield;                                                  \
115471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        Object* obj;                                                        \
115571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        EXPORT_PC();                                                        \
115671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ref = FETCH(1) | (u4)FETCH(2) << 16;   /* field ref */              \
115771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        vdst = FETCH(3);                                                    \
115871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        vsrc1 = FETCH(4);                      /* object ptr */             \
115971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("|iput%s/jumbo v%d,v%d,field@0x%08x",                         \
116071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            (_opname), vdst, vsrc1, ref);                                   \
116171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        obj = (Object*) GET_REGISTER(vsrc1);                                \
116271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        if (!checkForNull(obj))                                             \
116371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            GOTO_exceptionThrown();                                         \
116471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref);  \
116571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        if (ifield == NULL) {                                               \
116671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            ifield = dvmResolveInstField(curMethod->clazz, ref);            \
116771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            if (ifield == NULL)                                             \
116871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao                GOTO_exceptionThrown();                                     \
116971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        }                                                                   \
117071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        dvmSetField##_ftype(obj, ifield->byteOffset,                        \
117171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            GET_REGISTER##_regsize(vdst));                                  \
117271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("+ IPUT '%s'=0x%08llx", ifield->field.name,                   \
117371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            (u8) GET_REGISTER##_regsize(vdst));                             \
117471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        UPDATE_FIELD_PUT(&ifield->field);                                   \
117571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    }                                                                       \
117671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    FINISH(5);
117771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao
1178a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IPUT_X_QUICK(_opcode, _opname, _ftype, _regsize)             \
1179a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/)                           \
1180a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1181a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        Object* obj;                                                        \
1182a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_A(inst);                                                \
1183a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vsrc1 = INST_B(inst);   /* object ptr */                            \
1184a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ref = FETCH(1);         /* field offset */                          \
1185a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|iput%s-quick v%d,v%d,field@0x%04x",                         \
1186a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (_opname), vdst, vsrc1, ref);                                   \
1187a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        obj = (Object*) GET_REGISTER(vsrc1);                                \
1188a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (!checkForNullExportPC(obj, fp, pc))                             \
1189a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            GOTO_exceptionThrown();                                         \
1190a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmSetField##_ftype(obj, ref, GET_REGISTER##_regsize(vdst));        \
1191a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ IPUTQ %d=0x%08llx", ref,                                   \
1192a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            (u8) GET_REGISTER##_regsize(vdst));                             \
1193a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1194a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1195a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1196dd6e87095071e4e987910732062545f7303023e5Ben Cheng/*
1197dd6e87095071e4e987910732062545f7303023e5Ben Cheng * The JIT needs dvmDexGetResolvedField() to return non-null.
1198dd6e87095071e4e987910732062545f7303023e5Ben Cheng * Since we use the portable interpreter to build the trace, the extra
1199dd6e87095071e4e987910732062545f7303023e5Ben Cheng * checks in HANDLE_SGET_X and HANDLE_SPUT_X are not needed for mterp.
1200dd6e87095071e4e987910732062545f7303023e5Ben Cheng */
1201a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_SGET_X(_opcode, _opname, _ftype, _regsize)                   \
1202a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/)                              \
1203a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1204a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        StaticField* sfield;                                                \
1205a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
1206a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ref = FETCH(1);         /* field ref */                             \
1207a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|sget%s v%d,sfield@0x%04x", (_opname), vdst, ref);           \
1208a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1209a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (sfield == NULL) {                                               \
1210a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            EXPORT_PC();                                                    \
1211a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            sfield = dvmResolveStaticField(curMethod->clazz, ref);          \
1212a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (sfield == NULL)                                             \
1213a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
1214dd6e87095071e4e987910732062545f7303023e5Ben Cheng            if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) {      \
12151b3da59fff0c63770e10684e243a36f3d0218637Bill Buzbee                END_JIT_TSELECT();                                        \
1216dd6e87095071e4e987910732062545f7303023e5Ben Cheng            }                                                               \
1217a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
1218a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield));    \
1219a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ SGET '%s'=0x%08llx",                                       \
1220a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            sfield->field.name, (u8)GET_REGISTER##_regsize(vdst));          \
1221a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        UPDATE_FIELD_GET(&sfield->field);                                   \
1222a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1223a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1224a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
122571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao#define HANDLE_SGET_X_JUMBO(_opcode, _opname, _ftype, _regsize)             \
122671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    HANDLE_OPCODE(_opcode /*vBBBB, class@AAAAAAAA*/)                        \
122771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    {                                                                       \
122871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        StaticField* sfield;                                                \
122971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ref = FETCH(1) | (u4)FETCH(2) << 16;   /* field ref */              \
123071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        vdst = FETCH(3);                                                    \
123171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("|sget%s/jumbo v%d,sfield@0x%08x", (_opname), vdst, ref);     \
123271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
123371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        if (sfield == NULL) {                                               \
123471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            EXPORT_PC();                                                    \
123571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            sfield = dvmResolveStaticField(curMethod->clazz, ref);          \
123671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            if (sfield == NULL)                                             \
123771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao                GOTO_exceptionThrown();                                     \
123871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) {      \
12391b3da59fff0c63770e10684e243a36f3d0218637Bill Buzbee                END_JIT_TSELECT();                                        \
124071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            }                                                               \
124171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        }                                                                   \
124271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield));    \
124371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("+ SGET '%s'=0x%08llx",                                       \
124471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            sfield->field.name, (u8)GET_REGISTER##_regsize(vdst));          \
124571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        UPDATE_FIELD_GET(&sfield->field);                                   \
124671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    }                                                                       \
124771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    FINISH(4);
124871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao
1249a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_SPUT_X(_opcode, _opname, _ftype, _regsize)                   \
1250a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/)                              \
1251a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    {                                                                       \
1252a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        StaticField* sfield;                                                \
1253a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        vdst = INST_AA(inst);                                               \
1254a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ref = FETCH(1);         /* field ref */                             \
1255a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("|sput%s v%d,sfield@0x%04x", (_opname), vdst, ref);           \
1256a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
1257a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        if (sfield == NULL) {                                               \
1258a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            EXPORT_PC();                                                    \
1259a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            sfield = dvmResolveStaticField(curMethod->clazz, ref);          \
1260a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            if (sfield == NULL)                                             \
1261a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden                GOTO_exceptionThrown();                                     \
1262dd6e87095071e4e987910732062545f7303023e5Ben Cheng            if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) {      \
12631b3da59fff0c63770e10684e243a36f3d0218637Bill Buzbee                END_JIT_TSELECT();                                        \
1264dd6e87095071e4e987910732062545f7303023e5Ben Cheng            }                                                               \
1265a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        }                                                                   \
1266a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst));    \
1267a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ILOGV("+ SPUT '%s'=0x%08llx",                                       \
1268a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            sfield->field.name, (u8)GET_REGISTER##_regsize(vdst));          \
1269a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        UPDATE_FIELD_PUT(&sfield->field);                                   \
1270a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    }                                                                       \
1271a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    FINISH(2);
1272a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
127371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao#define HANDLE_SPUT_X_JUMBO(_opcode, _opname, _ftype, _regsize)             \
127471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    HANDLE_OPCODE(_opcode /*vBBBB, class@AAAAAAAA*/)                        \
127571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    {                                                                       \
127671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        StaticField* sfield;                                                \
127771eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ref = FETCH(1) | (u4)FETCH(2) << 16;   /* field ref */              \
127871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        vdst = FETCH(3);                                                    \
127971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("|sput%s/jumbo v%d,sfield@0x%08x", (_opname), vdst, ref);     \
128071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \
128171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        if (sfield == NULL) {                                               \
128271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            EXPORT_PC();                                                    \
128371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            sfield = dvmResolveStaticField(curMethod->clazz, ref);          \
128471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            if (sfield == NULL)                                             \
128571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao                GOTO_exceptionThrown();                                     \
128671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) {      \
12871b3da59fff0c63770e10684e243a36f3d0218637Bill Buzbee                END_JIT_TSELECT();                                        \
128871eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            }                                                               \
128971eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        }                                                                   \
129071eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst));    \
129171eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        ILOGV("+ SPUT '%s'=0x%08llx",                                       \
129271eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao            sfield->field.name, (u8)GET_REGISTER##_regsize(vdst));          \
129371eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao        UPDATE_FIELD_PUT(&sfield->field);                                   \
129471eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    }                                                                       \
129571eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao    FINISH(4);
129671eee1f0c2eb514585fdbee16730c9c2209e8f68jeffhao
1297a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* File: cstubs/enddefs.c */
1298a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1299a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* undefine "magic" name remapping */
1300a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef retval
1301a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef pc
1302a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef fp
1303a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef curMethod
1304a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef methodClassDex
1305a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef self
1306a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef debugTrackedRefStart
1307a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1308a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* File: armv5te/debug.c */
1309a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include <inttypes.h>
1310a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1311a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
1312a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Dump the fixed-purpose ARM registers, along with some other info.
1313a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
1314a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This function MUST be compiled in ARM mode -- THUMB will yield bogus
1315a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * results.
1316a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *
1317a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This will NOT preserve r0-r3/ip.
1318a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
1319a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmMterpDumpArmRegs(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3)
1320a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
1321a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    register uint32_t rPC       asm("r4");
1322a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    register uint32_t rFP       asm("r5");
13239f601a917c8878204482c37aec7005054b6776fabuzbee    register uint32_t rSELF     asm("r6");
1324a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    register uint32_t rINST     asm("r7");
1325a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    register uint32_t rIBASE    asm("r8");
1326a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    register uint32_t r9        asm("r9");
1327a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    register uint32_t r10       asm("r10");
1328a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1329b31b30131bbf58280a515c40027aa958b81b5cd6Carl Shapiro    //extern char dvmAsmInstructionStart[];
1330a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1331a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
13329f601a917c8878204482c37aec7005054b6776fabuzbee    printf("    : rPC=%08x rFP=%08x rSELF=%08x rINST=%08x\n",
13339f601a917c8878204482c37aec7005054b6776fabuzbee        rPC, rFP, rSELF, rINST);
1334a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
1335a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
13369f601a917c8878204482c37aec7005054b6776fabuzbee    //Thread* self = (Thread*) rSELF;
13379f601a917c8878204482c37aec7005054b6776fabuzbee    //const Method* method = self->method;
1338a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("    + self is %p\n", dvmThreadSelf());
1339a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    //printf("    + currently in %s.%s %s\n",
1340be323ec573918ef1674e4883c8766ddc4ee2a10cJean-Baptiste Queru    //    method->clazz->descriptor, method->name, method->shorty);
1341a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    //printf("    + dvmAsmInstructionStart = %p\n", dvmAsmInstructionStart);
1342a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    //printf("    + next handler for 0x%02x = %p\n",
1343a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    //    rINST & 0xff, dvmAsmInstructionStart + (rINST & 0xff) * 64);
1344a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
1345a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1346a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
1347a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Dump the StackSaveArea for the specified frame pointer.
1348a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
1349a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmDumpFp(void* fp, StackSaveArea* otherSaveArea)
1350a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
1351a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    StackSaveArea* saveArea = SAVEAREA_FROM_FP(fp);
1352a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("StackSaveArea for fp %p [%p/%p]:\n", fp, saveArea, otherSaveArea);
1353a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef EASY_GDB
1354a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("  prevSave=%p, prevFrame=%p savedPc=%p meth=%p curPc=%p\n",
1355a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        saveArea->prevSave, saveArea->prevFrame, saveArea->savedPc,
1356a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        saveArea->method, saveArea->xtra.currentPc);
1357a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else
1358a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("  prevFrame=%p savedPc=%p meth=%p curPc=%p fp[0]=0x%08x\n",
1359a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        saveArea->prevFrame, saveArea->savedPc,
1360a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        saveArea->method, saveArea->xtra.currentPc,
1361a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        *(u4*)fp);
1362a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif
1363a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
1364a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1365a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/*
1366a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Does the bulk of the work for common_printMethod().
1367a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */
1368a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmMterpPrintMethod(Method* method)
1369a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{
1370a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    /*
1371a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden     * It is a direct (non-virtual) method if it is static, private,
1372a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden     * or a constructor.
1373a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden     */
1374a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    bool isDirect =
1375a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        ((method->accessFlags & (ACC_STATIC|ACC_PRIVATE)) != 0) ||
1376a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden        (method->name[0] == '<');
1377a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1378a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    char* desc = dexProtoCopyMethodDescriptor(&method->prototype);
1379a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1380a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    printf("<%c:%s.%s %s> ",
1381a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            isDirect ? 'D' : 'V',
1382a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            method->clazz->descriptor,
1383a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            method->name,
1384a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden            desc);
1385a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1386a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden    free(desc);
1387a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden}
1388a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden
1389