Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "interpreter.h" |
| 18 | |
| 19 | #include <math.h> |
| 20 | |
| 21 | #include "common_throws.h" |
jeffhao | 373c52f | 2012-11-20 16:11:52 -0800 | [diff] [blame] | 22 | #include "debugger.h" |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 23 | #include "dex_instruction.h" |
| 24 | #include "invoke_arg_array_builder.h" |
| 25 | #include "logging.h" |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 26 | #include "nth_caller_visitor.h" |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 27 | #include "object.h" |
| 28 | #include "object_utils.h" |
| 29 | #include "runtime_support.h" |
| 30 | #include "ScopedLocalRef.h" |
| 31 | #include "scoped_thread_state_change.h" |
| 32 | #include "thread.h" |
| 33 | |
| 34 | namespace art { |
| 35 | namespace interpreter { |
| 36 | |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 37 | static void UnstartedRuntimeInvoke(Thread* self, AbstractMethod* target_method, |
| 38 | Object* receiver, JValue* args, JValue* result) |
| 39 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 40 | // In a runtime that's not started we intercept certain methods to avoid complicated dependency |
| 41 | // problems in core libraries. |
| 42 | std::string name(PrettyMethod(target_method)); |
| 43 | if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)") { |
| 44 | std::string descriptor(DotToDescriptor(args[0].GetL()->AsString()->ToModifiedUtf8().c_str())); |
| 45 | ClassLoader* class_loader = NULL; // shadow_frame.GetMethod()->GetDeclaringClass()->GetClassLoader(); |
| 46 | Class* found = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str(), |
| 47 | class_loader); |
| 48 | CHECK(found != NULL) << "Class.forName failed in un-started runtime for class: " |
| 49 | << PrettyDescriptor(descriptor); |
| 50 | result->SetL(found); |
| 51 | } else if (name == "java.lang.Object java.lang.Class.newInstance()") { |
| 52 | Class* klass = receiver->AsClass(); |
| 53 | AbstractMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V"); |
| 54 | CHECK(c != NULL); |
| 55 | Object* obj = klass->AllocObject(self); |
| 56 | CHECK(obj != NULL); |
| 57 | EnterInterpreterFromInvoke(self, c, obj, NULL, NULL); |
| 58 | result->SetL(obj); |
| 59 | } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") { |
| 60 | // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail |
| 61 | // going the reflective Dex way. |
| 62 | Class* klass = receiver->AsClass(); |
| 63 | String* name = args[0].GetL()->AsString(); |
| 64 | Field* found = NULL; |
| 65 | FieldHelper fh; |
| 66 | ObjectArray<Field>* fields = klass->GetIFields(); |
| 67 | for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) { |
| 68 | Field* f = fields->Get(i); |
| 69 | fh.ChangeField(f); |
| 70 | if (name->Equals(fh.GetName())) { |
| 71 | found = f; |
| 72 | } |
| 73 | } |
| 74 | if (found == NULL) { |
| 75 | fields = klass->GetSFields(); |
| 76 | for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) { |
| 77 | Field* f = fields->Get(i); |
| 78 | fh.ChangeField(f); |
| 79 | if (name->Equals(fh.GetName())) { |
| 80 | found = f; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | CHECK(found != NULL) |
| 85 | << "Failed to find field in Class.getDeclaredField in un-started runtime. name=" |
| 86 | << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass); |
| 87 | // TODO: getDeclaredField calls GetType once the field is found to ensure a |
| 88 | // NoClassDefFoundError is thrown if the field's type cannot be resolved. |
| 89 | result->SetL(found); |
| 90 | } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)") { |
| 91 | // Special case array copying without initializing System. |
| 92 | Class* ctype = args[0].GetL()->GetClass()->GetComponentType(); |
| 93 | jint srcPos = args[1].GetI(); |
| 94 | jint dstPos = args[3].GetI(); |
| 95 | jint length = args[4].GetI(); |
| 96 | if (!ctype->IsPrimitive()) { |
| 97 | ObjectArray<Object>* src = args[0].GetL()->AsObjectArray<Object>(); |
| 98 | ObjectArray<Object>* dst = args[2].GetL()->AsObjectArray<Object>(); |
| 99 | for (jint i = 0; i < length; ++i) { |
| 100 | dst->Set(dstPos + i, src->Get(srcPos + i)); |
| 101 | } |
| 102 | } else if (ctype->IsPrimitiveChar()) { |
| 103 | CharArray* src = args[0].GetL()->AsCharArray(); |
| 104 | CharArray* dst = args[2].GetL()->AsCharArray(); |
| 105 | for (jint i = 0; i < length; ++i) { |
| 106 | dst->Set(dstPos + i, src->Get(srcPos + i)); |
| 107 | } |
| 108 | } else if (ctype->IsPrimitiveInt()) { |
| 109 | IntArray* src = args[0].GetL()->AsIntArray(); |
| 110 | IntArray* dst = args[2].GetL()->AsIntArray(); |
| 111 | for (jint i = 0; i < length; ++i) { |
| 112 | dst->Set(dstPos + i, src->Get(srcPos + i)); |
| 113 | } |
| 114 | } else { |
| 115 | UNIMPLEMENTED(FATAL) << "System.arraycopy of unexpected type: " << PrettyDescriptor(ctype); |
| 116 | } |
| 117 | } else { |
| 118 | // Not special, continue with regular interpreter execution. |
| 119 | EnterInterpreterFromInvoke(self, target_method, receiver, args, result); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Hand select a number of methods to be run in a not yet started runtime without using JNI. |
| 124 | static void UnstartedRuntimeJni(Thread* self, AbstractMethod* method, |
| 125 | Object* receiver, JValue* args, JValue* result) |
| 126 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 127 | std::string name(PrettyMethod(method)); |
| 128 | if (name == "java.lang.ClassLoader dalvik.system.VMStack.getCallingClassLoader()") { |
| 129 | result->SetL(NULL); |
| 130 | } else if (name == "java.lang.Class dalvik.system.VMStack.getStackClass2()") { |
| 131 | NthCallerVisitor visitor(self->GetManagedStack(), NULL, 3); |
| 132 | visitor.WalkStack(); |
| 133 | result->SetL(visitor.caller->GetDeclaringClass()); |
| 134 | } else if (name == "double java.lang.Math.log(double)") { |
| 135 | result->SetD(log(args[0].GetD())); |
| 136 | } else if (name == "java.lang.String java.lang.Class.getNameNative()") { |
| 137 | result->SetL(receiver->AsClass()->ComputeName()); |
| 138 | } else if (name == "int java.lang.Float.floatToRawIntBits(float)") { |
| 139 | result->SetI(args[0].GetI()); |
| 140 | } else if (name == "float java.lang.Float.intBitsToFloat(int)") { |
| 141 | result->SetF(args[0].GetF()); |
| 142 | } else if (name == "double java.lang.Math.exp(double)") { |
| 143 | result->SetD(exp(args[0].GetD())); |
| 144 | } else if (name == "java.lang.Object java.lang.Object.internalClone()") { |
| 145 | result->SetL(receiver->Clone(self)); |
| 146 | } else if (name == "void java.lang.Object.notifyAll()") { |
| 147 | receiver->NotifyAll(); |
| 148 | } else if (name == "int java.lang.String.compareTo(java.lang.String)") { |
| 149 | String* rhs = args[0].GetL()->AsString(); |
| 150 | CHECK(rhs != NULL); |
| 151 | result->SetI(receiver->AsString()->CompareTo(rhs)); |
| 152 | } else if (name == "java.lang.String java.lang.String.intern()") { |
| 153 | result->SetL(receiver->AsString()->Intern()); |
| 154 | } else if (name == "int java.lang.String.fastIndexOf(int, int)") { |
| 155 | result->SetI(receiver->AsString()->FastIndexOf(args[0].GetI(), args[1].GetI())); |
| 156 | } else if (name == "java.lang.Object java.lang.reflect.Array.createMultiArray(java.lang.Class, int[])") { |
| 157 | result->SetL(Array::CreateMultiArray(self, args[0].GetL()->AsClass(), args[1].GetL()->AsIntArray())); |
| 158 | } else if (name == "java.lang.Object java.lang.Throwable.nativeFillInStackTrace()") { |
| 159 | ScopedObjectAccessUnchecked soa(self); |
| 160 | result->SetL(soa.Decode<Object*>(self->CreateInternalStackTrace(soa))); |
| 161 | } else if (name == "boolean java.nio.ByteOrder.isLittleEndian()") { |
| 162 | result->SetJ(JNI_TRUE); |
| 163 | } else if (name == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") { |
| 164 | Object* obj = args[0].GetL(); |
| 165 | jlong offset = args[1].GetJ(); |
| 166 | jint expectedValue = args[2].GetI(); |
| 167 | jint newValue = args[3].GetI(); |
| 168 | byte* raw_addr = reinterpret_cast<byte*>(obj) + offset; |
| 169 | volatile int32_t* address = reinterpret_cast<volatile int32_t*>(raw_addr); |
| 170 | // Note: android_atomic_release_cas() returns 0 on success, not failure. |
| 171 | int r = android_atomic_release_cas(expectedValue, newValue, address); |
| 172 | result->SetZ(r == 0); |
| 173 | } else if (name == "void sun.misc.Unsafe.putObject(java.lang.Object, long, java.lang.Object)") { |
| 174 | Object* obj = args[0].GetL(); |
| 175 | Object* newValue = args[2].GetL(); |
| 176 | obj->SetFieldObject(MemberOffset(args[1].GetJ()), newValue, false); |
| 177 | } else { |
| 178 | LOG(FATAL) << "Attempt to invoke native method in non-started runtime: " << name; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | static void InterpreterJni(Thread* self, AbstractMethod* method, StringPiece shorty, |
| 183 | Object* receiver, JValue* args, JValue* result) |
| 184 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 185 | // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler, |
| 186 | // it should be removed and JNI compiled stubs used instead. |
| 187 | ScopedObjectAccessUnchecked soa(self); |
| 188 | if (method->IsStatic()) { |
| 189 | if (shorty == "L") { |
| 190 | typedef jobject (fnptr)(JNIEnv*, jclass); |
| 191 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 192 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 193 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 194 | jobject jresult; |
| 195 | { |
| 196 | ScopedThreadStateChange tsc(self, kNative); |
| 197 | jresult = fn(soa.Env(), klass.get()); |
| 198 | } |
| 199 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 200 | } else if (shorty == "V") { |
| 201 | typedef void (fnptr)(JNIEnv*, jclass); |
| 202 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 203 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 204 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 205 | ScopedThreadStateChange tsc(self, kNative); |
| 206 | fn(soa.Env(), klass.get()); |
| 207 | } else if (shorty == "Z") { |
| 208 | typedef jboolean (fnptr)(JNIEnv*, jclass); |
| 209 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 210 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 211 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 212 | ScopedThreadStateChange tsc(self, kNative); |
| 213 | result->SetZ(fn(soa.Env(), klass.get())); |
| 214 | } else if (shorty == "BI") { |
| 215 | typedef jbyte (fnptr)(JNIEnv*, jclass, jint); |
| 216 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 217 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 218 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 219 | ScopedThreadStateChange tsc(self, kNative); |
| 220 | result->SetB(fn(soa.Env(), klass.get(), args[0].GetI())); |
| 221 | } else if (shorty == "II") { |
| 222 | typedef jint (fnptr)(JNIEnv*, jclass, jint); |
| 223 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 224 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 225 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 226 | ScopedThreadStateChange tsc(self, kNative); |
| 227 | result->SetI(fn(soa.Env(), klass.get(), args[0].GetI())); |
| 228 | } else if (shorty == "LL") { |
| 229 | typedef jobject (fnptr)(JNIEnv*, jclass, jobject); |
| 230 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 231 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 232 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 233 | ScopedLocalRef<jobject> arg0(soa.Env(), |
| 234 | soa.AddLocalReference<jobject>(args[0].GetL())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 235 | jobject jresult; |
| 236 | { |
| 237 | ScopedThreadStateChange tsc(self, kNative); |
| 238 | jresult = fn(soa.Env(), klass.get(), arg0.get()); |
| 239 | } |
| 240 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 241 | } else if (shorty == "IIZ") { |
| 242 | typedef jint (fnptr)(JNIEnv*, jclass, jint, jboolean); |
| 243 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 244 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 245 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 246 | ScopedThreadStateChange tsc(self, kNative); |
| 247 | result->SetI(fn(soa.Env(), klass.get(), args[0].GetI(), args[1].GetZ())); |
| 248 | } else if (shorty == "ILI") { |
| 249 | typedef jint (fnptr)(JNIEnv*, jclass, jobject, jint); |
| 250 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 251 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 252 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 253 | ScopedLocalRef<jobject> arg0(soa.Env(), |
| 254 | soa.AddLocalReference<jobject>(args[0].GetL())); |
| 255 | ScopedThreadStateChange tsc(self, kNative); |
| 256 | result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1].GetI())); |
| 257 | } else if (shorty == "SIZ") { |
| 258 | typedef jshort (fnptr)(JNIEnv*, jclass, jint, jboolean); |
| 259 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 260 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 261 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 262 | ScopedThreadStateChange tsc(self, kNative); |
| 263 | result->SetS(fn(soa.Env(), klass.get(), args[0].GetI(), args[1].GetZ())); |
| 264 | } else if (shorty == "VIZ") { |
| 265 | typedef void (fnptr)(JNIEnv*, jclass, jint, jboolean); |
| 266 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 267 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 268 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 269 | ScopedThreadStateChange tsc(self, kNative); |
| 270 | fn(soa.Env(), klass.get(), args[0].GetI(), args[1].GetZ()); |
| 271 | } else if (shorty == "ZLL") { |
| 272 | typedef jboolean (fnptr)(JNIEnv*, jclass, jobject, jobject); |
| 273 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 274 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 275 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 276 | ScopedLocalRef<jobject> arg0(soa.Env(), |
| 277 | soa.AddLocalReference<jobject>(args[0].GetL())); |
| 278 | ScopedLocalRef<jobject> arg1(soa.Env(), |
| 279 | soa.AddLocalReference<jobject>(args[1].GetL())); |
| 280 | ScopedThreadStateChange tsc(self, kNative); |
| 281 | result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get())); |
| 282 | } else if (shorty == "ZILL") { |
| 283 | typedef jboolean (fnptr)(JNIEnv*, jclass, jint, jobject, jobject); |
| 284 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 285 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 286 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 287 | ScopedLocalRef<jobject> arg1(soa.Env(), |
| 288 | soa.AddLocalReference<jobject>(args[1].GetL())); |
| 289 | ScopedLocalRef<jobject> arg2(soa.Env(), |
| 290 | soa.AddLocalReference<jobject>(args[2].GetL())); |
| 291 | ScopedThreadStateChange tsc(self, kNative); |
| 292 | result->SetZ(fn(soa.Env(), klass.get(), args[0].GetI(), arg1.get(), arg2.get())); |
| 293 | } else if (shorty == "VILII") { |
| 294 | typedef void (fnptr)(JNIEnv*, jclass, jint, jobject, jint, jint); |
| 295 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 296 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 297 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 298 | ScopedLocalRef<jobject> arg1(soa.Env(), |
| 299 | soa.AddLocalReference<jobject>(args[1].GetL())); |
| 300 | ScopedThreadStateChange tsc(self, kNative); |
| 301 | fn(soa.Env(), klass.get(), args[0].GetI(), arg1.get(), args[2].GetI(), args[3].GetI()); |
| 302 | } else if (shorty == "VLILII") { |
| 303 | typedef void (fnptr)(JNIEnv*, jclass, jobject, jint, jobject, jint, jint); |
| 304 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 305 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 306 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 307 | ScopedLocalRef<jobject> arg0(soa.Env(), |
| 308 | soa.AddLocalReference<jobject>(args[0].GetL())); |
| 309 | ScopedLocalRef<jobject> arg2(soa.Env(), |
| 310 | soa.AddLocalReference<jobject>(args[2].GetL())); |
| 311 | ScopedThreadStateChange tsc(self, kNative); |
| 312 | fn(soa.Env(), klass.get(), arg0.get(), args[1].GetI(), arg2.get(), args[3].GetI(), |
| 313 | args[4].GetI()); |
| 314 | } else { |
| 315 | LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method) |
| 316 | << " shorty: " << shorty; |
| 317 | } |
| 318 | } else { |
| 319 | if (shorty == "L") { |
| 320 | typedef jobject (fnptr)(JNIEnv*, jobject); |
| 321 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 322 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 323 | soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 324 | jobject jresult; |
| 325 | { |
| 326 | ScopedThreadStateChange tsc(self, kNative); |
| 327 | jresult = fn(soa.Env(), rcvr.get()); |
| 328 | } |
| 329 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 330 | } else if (shorty == "LL") { |
| 331 | typedef jobject (fnptr)(JNIEnv*, jobject, jobject); |
| 332 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 333 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 334 | soa.AddLocalReference<jobject>(receiver)); |
| 335 | ScopedLocalRef<jobject> arg0(soa.Env(), |
| 336 | soa.AddLocalReference<jobject>(args[0].GetL())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 337 | jobject jresult; |
| 338 | { |
| 339 | ScopedThreadStateChange tsc(self, kNative); |
| 340 | jresult = fn(soa.Env(), rcvr.get(), arg0.get()); |
| 341 | |
| 342 | } |
| 343 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 344 | ScopedThreadStateChange tsc(self, kNative); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 345 | } else if (shorty == "III") { |
| 346 | typedef jint (fnptr)(JNIEnv*, jobject, jint, jint); |
| 347 | fnptr* fn = reinterpret_cast<fnptr*>(method->GetNativeMethod()); |
| 348 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 349 | soa.AddLocalReference<jobject>(receiver)); |
| 350 | ScopedThreadStateChange tsc(self, kNative); |
| 351 | result->SetI(fn(soa.Env(), rcvr.get(), args[0].GetI(), args[1].GetI())); |
| 352 | } else { |
| 353 | LOG(FATAL) << "Do something with native method: " << PrettyMethod(method) |
| 354 | << " shorty: " << shorty; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 359 | static void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS { |
| 360 | ref->MonitorEnter(self); |
| 361 | } |
| 362 | |
| 363 | static void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS { |
| 364 | ref->MonitorExit(self); |
| 365 | } |
| 366 | |
| 367 | static void DoInvoke(Thread* self, MethodHelper& mh, ShadowFrame& shadow_frame, |
| 368 | const DecodedInstruction& dec_insn, InvokeType type, bool is_range, |
| 369 | JValue* result) |
| 370 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 371 | Object* receiver; |
| 372 | if (type == kStatic) { |
| 373 | receiver = NULL; |
| 374 | } else { |
| 375 | receiver = shadow_frame.GetReference(dec_insn.vC); |
| 376 | if (UNLIKELY(receiver == NULL)) { |
| 377 | ThrowNullPointerExceptionForMethodAccess(shadow_frame.GetMethod(), dec_insn.vB, type); |
| 378 | result->SetJ(0); |
| 379 | return; |
| 380 | } |
| 381 | } |
| 382 | uint32_t method_idx = dec_insn.vB; |
| 383 | AbstractMethod* target_method = FindMethodFromCode(method_idx, receiver, |
| 384 | shadow_frame.GetMethod(), self, true, |
| 385 | type); |
| 386 | if (UNLIKELY(target_method == NULL)) { |
| 387 | CHECK(self->IsExceptionPending()); |
| 388 | result->SetJ(0); |
| 389 | return; |
| 390 | } |
| 391 | mh.ChangeMethod(target_method); |
| 392 | ArgArray arg_array(mh.GetShorty(), mh.GetShortyLength()); |
| 393 | if (is_range) { |
| 394 | arg_array.BuildArgArray(shadow_frame, dec_insn.vC + (type != kStatic ? 1 : 0)); |
| 395 | } else { |
| 396 | arg_array.BuildArgArray(shadow_frame, dec_insn.arg + (type != kStatic ? 1 : 0)); |
| 397 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 398 | if (LIKELY(Runtime::Current()->IsStarted())) { |
| 399 | target_method->Invoke(self, receiver, arg_array.get(), result); |
| 400 | } else { |
| 401 | UnstartedRuntimeInvoke(self, target_method, receiver, arg_array.get(), result); |
| 402 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 403 | if (!mh.GetReturnType()->IsPrimitive() && result->GetL() != NULL) { |
| 404 | CHECK(mh.GetReturnType()->IsAssignableFrom(result->GetL()->GetClass())); |
| 405 | } |
| 406 | mh.ChangeMethod(shadow_frame.GetMethod()); |
| 407 | } |
| 408 | |
| 409 | static void DoFieldGet(Thread* self, ShadowFrame& shadow_frame, |
| 410 | const DecodedInstruction& dec_insn, FindFieldType find_type, |
| 411 | Primitive::Type field_type) |
| 412 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 413 | bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead); |
| 414 | uint32_t field_idx = is_static ? dec_insn.vB : dec_insn.vC; |
| 415 | Field* f = FindFieldFromCode(field_idx, shadow_frame.GetMethod(), self, |
| 416 | find_type, Primitive::FieldSize(field_type)); |
| 417 | if (LIKELY(f != NULL)) { |
| 418 | Object* obj; |
| 419 | if (is_static) { |
| 420 | obj = f->GetDeclaringClass(); |
| 421 | } else { |
| 422 | obj = shadow_frame.GetReference(dec_insn.vB); |
| 423 | if (UNLIKELY(obj == NULL)) { |
| 424 | ThrowNullPointerExceptionForFieldAccess(f, true); |
Ian Rogers | 689d9f0 | 2012-11-20 16:30:29 -0800 | [diff] [blame] | 425 | return; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | switch (field_type) { |
| 429 | case Primitive::kPrimBoolean: |
| 430 | shadow_frame.SetVReg(dec_insn.vA, f->GetBoolean(obj)); |
| 431 | break; |
| 432 | case Primitive::kPrimByte: |
| 433 | shadow_frame.SetVReg(dec_insn.vA, f->GetByte(obj)); |
| 434 | break; |
| 435 | case Primitive::kPrimChar: |
| 436 | shadow_frame.SetVReg(dec_insn.vA, f->GetChar(obj)); |
| 437 | break; |
| 438 | case Primitive::kPrimShort: |
| 439 | shadow_frame.SetVReg(dec_insn.vA, f->GetShort(obj)); |
| 440 | break; |
| 441 | case Primitive::kPrimInt: |
| 442 | shadow_frame.SetVReg(dec_insn.vA, f->GetInt(obj)); |
| 443 | break; |
| 444 | case Primitive::kPrimLong: |
| 445 | shadow_frame.SetVRegLong(dec_insn.vA, f->GetLong(obj)); |
| 446 | break; |
| 447 | case Primitive::kPrimNot: |
| 448 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, f->GetObject(obj)); |
| 449 | break; |
| 450 | default: |
| 451 | LOG(FATAL) << "Unreachable: " << field_type; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | static void DoFieldPut(Thread* self, ShadowFrame& shadow_frame, |
| 457 | const DecodedInstruction& dec_insn, FindFieldType find_type, |
| 458 | Primitive::Type field_type) |
| 459 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 460 | bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite); |
| 461 | uint32_t field_idx = is_static ? dec_insn.vB : dec_insn.vC; |
| 462 | Field* f = FindFieldFromCode(field_idx, shadow_frame.GetMethod(), self, |
| 463 | find_type, Primitive::FieldSize(field_type)); |
| 464 | if (LIKELY(f != NULL)) { |
| 465 | Object* obj; |
| 466 | if (is_static) { |
| 467 | obj = f->GetDeclaringClass(); |
| 468 | } else { |
| 469 | obj = shadow_frame.GetReference(dec_insn.vB); |
| 470 | if (UNLIKELY(obj == NULL)) { |
| 471 | ThrowNullPointerExceptionForFieldAccess(f, false); |
Ian Rogers | 689d9f0 | 2012-11-20 16:30:29 -0800 | [diff] [blame] | 472 | return; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | switch (field_type) { |
| 476 | case Primitive::kPrimBoolean: |
| 477 | f->SetBoolean(obj, shadow_frame.GetVReg(dec_insn.vA)); |
| 478 | break; |
| 479 | case Primitive::kPrimByte: |
| 480 | f->SetByte(obj, shadow_frame.GetVReg(dec_insn.vA)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 481 | break; |
| 482 | case Primitive::kPrimChar: |
| 483 | f->SetChar(obj, shadow_frame.GetVReg(dec_insn.vA)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 484 | break; |
| 485 | case Primitive::kPrimShort: |
| 486 | f->SetShort(obj, shadow_frame.GetVReg(dec_insn.vA)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 487 | break; |
| 488 | case Primitive::kPrimInt: |
| 489 | f->SetInt(obj, shadow_frame.GetVReg(dec_insn.vA)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 490 | break; |
| 491 | case Primitive::kPrimLong: |
| 492 | f->SetLong(obj, shadow_frame.GetVRegLong(dec_insn.vA)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 493 | break; |
| 494 | case Primitive::kPrimNot: |
| 495 | f->SetObj(obj, shadow_frame.GetReference(dec_insn.vA)); |
| 496 | break; |
| 497 | default: |
| 498 | LOG(FATAL) << "Unreachable: " << field_type; |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 503 | static void DoIntDivide(Thread* self, ShadowFrame& shadow_frame, size_t result_reg, |
| 504 | int32_t dividend, int32_t divisor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 505 | const int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
| 506 | if (UNLIKELY(divisor == 0)) { |
| 507 | self->ThrowNewException("Ljava/lang/ArithmeticException;", "divide by zero"); |
| 508 | } else if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 509 | shadow_frame.SetVReg(result_reg, kMinInt); |
| 510 | } else { |
| 511 | shadow_frame.SetVReg(result_reg, dividend / divisor); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | static void DoIntRemainder(Thread* self, ShadowFrame& shadow_frame, size_t result_reg, |
| 516 | int32_t dividend, int32_t divisor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 517 | const int32_t kMinInt = std::numeric_limits<int32_t>::min(); |
| 518 | if (UNLIKELY(divisor == 0)) { |
| 519 | self->ThrowNewException("Ljava/lang/ArithmeticException;", "divide by zero"); |
| 520 | } else if (UNLIKELY(dividend == kMinInt && divisor == -1)) { |
| 521 | shadow_frame.SetVReg(result_reg, 0); |
| 522 | } else { |
| 523 | shadow_frame.SetVReg(result_reg, dividend % divisor); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | static void DoLongDivide(Thread* self, ShadowFrame& shadow_frame, size_t result_reg, |
| 528 | int64_t dividend, int64_t divisor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 529 | const int32_t kMinLong = std::numeric_limits<int64_t>::min(); |
| 530 | if (UNLIKELY(divisor == 0)) { |
| 531 | self->ThrowNewException("Ljava/lang/ArithmeticException;", "divide by zero"); |
| 532 | } else if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 533 | shadow_frame.SetVRegLong(result_reg, kMinLong); |
| 534 | } else { |
| 535 | shadow_frame.SetVRegLong(result_reg, dividend / divisor); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | static void DoLongRemainder(Thread* self, ShadowFrame& shadow_frame, size_t result_reg, |
| 540 | int64_t dividend, int64_t divisor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 541 | const int32_t kMinLong = std::numeric_limits<int64_t>::min(); |
| 542 | if (UNLIKELY(divisor == 0)) { |
| 543 | self->ThrowNewException("Ljava/lang/ArithmeticException;", "divide by zero"); |
| 544 | } else if (UNLIKELY(dividend == kMinLong && divisor == -1)) { |
| 545 | shadow_frame.SetVRegLong(result_reg, 0); |
| 546 | } else { |
| 547 | shadow_frame.SetVRegLong(result_reg, dividend % divisor); |
| 548 | } |
| 549 | } |
| 550 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 551 | static JValue Execute(Thread* self, MethodHelper& mh, const DexFile::CodeItem* code_item, |
| 552 | ShadowFrame& shadow_frame) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 553 | const uint16_t* insns = code_item->insns_; |
| 554 | const Instruction* inst = Instruction::At(insns + shadow_frame.GetDexPC()); |
| 555 | JValue result_register; |
| 556 | while (true) { |
jeffhao | 373c52f | 2012-11-20 16:11:52 -0800 | [diff] [blame] | 557 | CheckSuspend(self); |
| 558 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 559 | shadow_frame.SetDexPC(dex_pc); |
| 560 | Dbg::UpdateDebugger(dex_pc, self); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 561 | DecodedInstruction dec_insn(inst); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 562 | const bool kTracing = false; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 563 | if (kTracing) { |
| 564 | LOG(INFO) << PrettyMethod(shadow_frame.GetMethod()) |
| 565 | << StringPrintf("\n0x%x: %s\nReferences:", |
| 566 | inst->GetDexPc(insns), inst->DumpString(&mh.GetDexFile()).c_str()); |
| 567 | for (size_t i = 0; i < shadow_frame.NumberOfReferences(); ++i) { |
| 568 | Object* o = shadow_frame.GetReference(i); |
| 569 | if (o != NULL) { |
| 570 | if (o->GetClass()->IsStringClass() && o->AsString()->GetCharArray() != NULL) { |
| 571 | LOG(INFO) << i << ": java.lang.String " << static_cast<void*>(o) |
| 572 | << " \"" << o->AsString()->ToModifiedUtf8() << "\""; |
| 573 | } else { |
| 574 | LOG(INFO) << i << ": " << PrettyTypeOf(o) << " " << static_cast<void*>(o); |
| 575 | } |
| 576 | } else { |
| 577 | LOG(INFO) << i << ": null"; |
| 578 | } |
| 579 | } |
| 580 | LOG(INFO) << "vregs:"; |
| 581 | for (size_t i = 0; i < shadow_frame.NumberOfReferences(); ++i) { |
| 582 | LOG(INFO) << StringPrintf("%d: %08x", i, shadow_frame.GetVReg(i)); |
| 583 | } |
| 584 | } |
| 585 | const Instruction* next_inst = inst->Next(); |
| 586 | switch (dec_insn.opcode) { |
| 587 | case Instruction::NOP: |
| 588 | break; |
| 589 | case Instruction::MOVE: |
| 590 | case Instruction::MOVE_FROM16: |
| 591 | case Instruction::MOVE_16: |
| 592 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB)); |
| 593 | break; |
| 594 | case Instruction::MOVE_WIDE: |
| 595 | case Instruction::MOVE_WIDE_FROM16: |
| 596 | case Instruction::MOVE_WIDE_16: |
| 597 | shadow_frame.SetVRegLong(dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vB)); |
| 598 | break; |
| 599 | case Instruction::MOVE_OBJECT: |
| 600 | case Instruction::MOVE_OBJECT_FROM16: |
| 601 | case Instruction::MOVE_OBJECT_16: |
| 602 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB)); |
| 603 | shadow_frame.SetReference(dec_insn.vA, shadow_frame.GetReference(dec_insn.vB)); |
| 604 | break; |
| 605 | case Instruction::MOVE_RESULT: |
| 606 | shadow_frame.SetVReg(dec_insn.vA, result_register.GetI()); |
| 607 | break; |
| 608 | case Instruction::MOVE_RESULT_WIDE: |
| 609 | shadow_frame.SetVRegLong(dec_insn.vA, result_register.GetJ()); |
| 610 | break; |
| 611 | case Instruction::MOVE_RESULT_OBJECT: |
| 612 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, result_register.GetL()); |
| 613 | break; |
| 614 | case Instruction::MOVE_EXCEPTION: { |
| 615 | Throwable* exception = self->GetException(); |
| 616 | self->ClearException(); |
| 617 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, exception); |
| 618 | break; |
| 619 | } |
| 620 | case Instruction::RETURN_VOID: { |
| 621 | JValue result; |
| 622 | result.SetJ(0); |
| 623 | return result; |
| 624 | } |
| 625 | case Instruction::RETURN: { |
| 626 | JValue result; |
| 627 | result.SetJ(0); |
| 628 | result.SetI(shadow_frame.GetVReg(dec_insn.vA)); |
| 629 | return result; |
| 630 | } |
| 631 | case Instruction::RETURN_WIDE: { |
| 632 | JValue result; |
| 633 | result.SetJ(shadow_frame.GetVRegLong(dec_insn.vA)); |
| 634 | return result; |
| 635 | } |
| 636 | case Instruction::RETURN_OBJECT: { |
| 637 | JValue result; |
| 638 | result.SetJ(0); |
| 639 | result.SetL(shadow_frame.GetReference(dec_insn.vA)); |
| 640 | return result; |
| 641 | } |
| 642 | case Instruction::CONST_4: { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 643 | int32_t val = static_cast<int32_t>(dec_insn.vB << 28) >> 28; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 644 | shadow_frame.SetVReg(dec_insn.vA, val); |
| 645 | if (val == 0) { |
| 646 | shadow_frame.SetReference(dec_insn.vA, NULL); |
| 647 | } |
| 648 | break; |
| 649 | } |
| 650 | case Instruction::CONST_16: { |
| 651 | int32_t val = static_cast<int16_t>(dec_insn.vB); |
| 652 | shadow_frame.SetVReg(dec_insn.vA, val); |
| 653 | if (val == 0) { |
| 654 | shadow_frame.SetReference(dec_insn.vA, NULL); |
| 655 | } |
| 656 | break; |
| 657 | } |
| 658 | case Instruction::CONST: { |
| 659 | int32_t val = dec_insn.vB; |
| 660 | shadow_frame.SetVReg(dec_insn.vA, val); |
| 661 | if (val == 0) { |
| 662 | shadow_frame.SetReference(dec_insn.vA, NULL); |
| 663 | } |
| 664 | break; |
| 665 | } |
| 666 | case Instruction::CONST_HIGH16: { |
| 667 | int32_t val = dec_insn.vB << 16; |
| 668 | shadow_frame.SetVReg(dec_insn.vA, val); |
| 669 | if (val == 0) { |
| 670 | shadow_frame.SetReference(dec_insn.vA, NULL); |
| 671 | } |
| 672 | break; |
| 673 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 674 | case Instruction::CONST_WIDE_16: |
| 675 | shadow_frame.SetVRegLong(dec_insn.vA, static_cast<int16_t>(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 676 | break; |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 677 | case Instruction::CONST_WIDE_32: |
| 678 | shadow_frame.SetVRegLong(dec_insn.vA, static_cast<int32_t>(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 679 | break; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 680 | case Instruction::CONST_WIDE: |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 681 | shadow_frame.SetVRegLong(dec_insn.vA, dec_insn.vB_wide); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 682 | break; |
| 683 | case Instruction::CONST_WIDE_HIGH16: |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 684 | shadow_frame.SetVRegLong(dec_insn.vA, static_cast<uint64_t>(dec_insn.vB) << 48); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 685 | break; |
| 686 | case Instruction::CONST_STRING: |
| 687 | case Instruction::CONST_STRING_JUMBO: { |
| 688 | if (UNLIKELY(!String::GetJavaLangString()->IsInitialized())) { |
| 689 | Runtime::Current()->GetClassLinker()->EnsureInitialized(String::GetJavaLangString(), |
| 690 | true, true); |
| 691 | } |
| 692 | String* s = mh.ResolveString(dec_insn.vB); |
| 693 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, s); |
| 694 | break; |
| 695 | } |
| 696 | case Instruction::CONST_CLASS: |
Ian Rogers | 17ffcab | 2012-11-20 15:27:41 -0800 | [diff] [blame] | 697 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, mh.ResolveClass(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 698 | break; |
| 699 | case Instruction::MONITOR_ENTER: |
| 700 | DoMonitorEnter(self, shadow_frame.GetReference(dec_insn.vA)); |
| 701 | break; |
| 702 | case Instruction::MONITOR_EXIT: |
| 703 | DoMonitorExit(self, shadow_frame.GetReference(dec_insn.vA)); |
| 704 | break; |
| 705 | case Instruction::CHECK_CAST: { |
| 706 | Class* c = mh.ResolveClass(dec_insn.vB); |
| 707 | Object* obj = shadow_frame.GetReference(dec_insn.vA); |
| 708 | if (UNLIKELY(obj != NULL && !obj->InstanceOf(c))) { |
| 709 | self->ThrowNewExceptionF("Ljava/lang/ClassCastException;", |
| 710 | "%s cannot be cast to %s", |
| 711 | PrettyDescriptor(obj->GetClass()).c_str(), |
| 712 | PrettyDescriptor(c).c_str()); |
| 713 | } |
| 714 | break; |
| 715 | } |
| 716 | case Instruction::INSTANCE_OF: { |
| 717 | Class* c = mh.ResolveClass(dec_insn.vC); |
| 718 | Object* obj = shadow_frame.GetReference(dec_insn.vB); |
| 719 | shadow_frame.SetVReg(dec_insn.vA, (obj != NULL && obj->InstanceOf(c)) ? 1 : 0); |
| 720 | break; |
| 721 | } |
| 722 | case Instruction::ARRAY_LENGTH: { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 723 | Object* array = shadow_frame.GetReference(dec_insn.vB); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 724 | if (UNLIKELY(array == NULL)) { |
| 725 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 726 | break; |
| 727 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 728 | shadow_frame.SetVReg(dec_insn.vA, array->AsArray()->GetLength()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 729 | break; |
| 730 | } |
| 731 | case Instruction::NEW_INSTANCE: { |
| 732 | Object* obj = AllocObjectFromCode(dec_insn.vB, shadow_frame.GetMethod(), self, true); |
| 733 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, obj); |
| 734 | break; |
| 735 | } |
| 736 | case Instruction::NEW_ARRAY: { |
| 737 | int32_t length = shadow_frame.GetVReg(dec_insn.vB); |
| 738 | Object* obj = AllocArrayFromCode(dec_insn.vC, shadow_frame.GetMethod(), length, self, true); |
| 739 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, obj); |
| 740 | break; |
| 741 | } |
| 742 | case Instruction::FILLED_NEW_ARRAY: |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 743 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 744 | bool is_range = (dec_insn.opcode == Instruction::FILLED_NEW_ARRAY_RANGE); |
| 745 | int32_t length = dec_insn.vA; |
| 746 | CHECK(is_range || length <= 5); |
| 747 | Class* arrayClass = mh.ResolveClass(dec_insn.vB); |
| 748 | CHECK(arrayClass->IsArrayClass()); |
| 749 | if (arrayClass->GetComponentType()->IsPrimitiveInt()) { |
| 750 | IntArray* newArray = IntArray::Alloc(self, length); |
| 751 | if (newArray != NULL) { |
| 752 | for (int32_t i = 0; i < length; ++i) { |
| 753 | if (is_range) { |
| 754 | newArray->Set(i, shadow_frame.GetVReg(dec_insn.vC + i)); |
| 755 | } else { |
| 756 | newArray->Set(i, shadow_frame.GetVReg(dec_insn.arg[i])); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | result_register.SetL(newArray); |
| 761 | } else { |
| 762 | UNIMPLEMENTED(FATAL) << inst->DumpString(&mh.GetDexFile()) |
| 763 | << " for array type: " << PrettyDescriptor(arrayClass); |
| 764 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 765 | break; |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 766 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 767 | case Instruction::CMPL_FLOAT: { |
| 768 | float val1 = shadow_frame.GetVRegFloat(dec_insn.vB); |
| 769 | float val2 = shadow_frame.GetVRegFloat(dec_insn.vC); |
| 770 | int32_t result; |
| 771 | if (val1 == val2) { |
| 772 | result = 0; |
| 773 | } else if (val1 > val2) { |
| 774 | result = 1; |
| 775 | } else { |
| 776 | result = -1; |
| 777 | } |
| 778 | shadow_frame.SetVReg(dec_insn.vA, result); |
| 779 | break; |
| 780 | } |
| 781 | case Instruction::CMPG_FLOAT: { |
| 782 | float val1 = shadow_frame.GetVRegFloat(dec_insn.vB); |
| 783 | float val2 = shadow_frame.GetVRegFloat(dec_insn.vC); |
| 784 | int32_t result; |
| 785 | if (val1 == val2) { |
| 786 | result = 0; |
| 787 | } else if (val1 < val2) { |
| 788 | result = -1; |
| 789 | } else { |
| 790 | result = 1; |
| 791 | } |
| 792 | shadow_frame.SetVReg(dec_insn.vA, result); |
| 793 | break; |
| 794 | } |
| 795 | case Instruction::CMPL_DOUBLE: { |
| 796 | double val1 = shadow_frame.GetVRegDouble(dec_insn.vB); |
| 797 | double val2 = shadow_frame.GetVRegDouble(dec_insn.vC); |
| 798 | int32_t result; |
| 799 | if (val1 == val2) { |
| 800 | result = 0; |
Ian Rogers | 58bf0c6 | 2012-11-20 16:24:12 -0800 | [diff] [blame] | 801 | } else if (val1 > val2) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 802 | result = 1; |
| 803 | } else { |
| 804 | result = -1; |
| 805 | } |
| 806 | shadow_frame.SetVReg(dec_insn.vA, result); |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | case Instruction::CMPG_DOUBLE: { |
| 811 | double val1 = shadow_frame.GetVRegDouble(dec_insn.vB); |
| 812 | double val2 = shadow_frame.GetVRegDouble(dec_insn.vC); |
| 813 | int32_t result; |
| 814 | if (val1 == val2) { |
| 815 | result = 0; |
Ian Rogers | 58bf0c6 | 2012-11-20 16:24:12 -0800 | [diff] [blame] | 816 | } else if (val1 < val2) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 817 | result = -1; |
| 818 | } else { |
| 819 | result = 1; |
| 820 | } |
| 821 | shadow_frame.SetVReg(dec_insn.vA, result); |
| 822 | break; |
| 823 | } |
| 824 | case Instruction::CMP_LONG: { |
| 825 | int64_t val1 = shadow_frame.GetVRegLong(dec_insn.vB); |
| 826 | int64_t val2 = shadow_frame.GetVRegLong(dec_insn.vC); |
| 827 | int32_t result; |
| 828 | if (val1 < val2) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 829 | result = 1; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 830 | } else if (val1 == val2) { |
| 831 | result = 0; |
| 832 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 833 | result = -1; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 834 | } |
| 835 | shadow_frame.SetVReg(dec_insn.vA, result); |
| 836 | break; |
| 837 | } |
| 838 | case Instruction::THROW: { |
| 839 | Throwable* t = shadow_frame.GetReference(dec_insn.vA)->AsThrowable(); |
| 840 | self->SetException(t); |
| 841 | break; |
| 842 | } |
| 843 | case Instruction::GOTO: |
| 844 | case Instruction::GOTO_16: |
| 845 | case Instruction::GOTO_32: { |
| 846 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 847 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vA); |
| 848 | break; |
| 849 | } |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 850 | case Instruction::PACKED_SWITCH: { |
| 851 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 852 | const uint16_t* switch_data = insns + dex_pc + dec_insn.vB; |
| 853 | int32_t test_val = shadow_frame.GetVReg(dec_insn.vA); |
| 854 | CHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 855 | uint16_t size = switch_data[1]; |
| 856 | CHECK_GT(size, 0); |
| 857 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
| 858 | CHECK(IsAligned<4>(keys)); |
| 859 | int32_t first_key = keys[0]; |
| 860 | const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]); |
| 861 | CHECK(IsAligned<4>(targets)); |
| 862 | int32_t index = test_val - first_key; |
| 863 | if (index >= 0 && index < size) { |
| 864 | next_inst = Instruction::At(insns + dex_pc + targets[index]); |
| 865 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 866 | break; |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 867 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 868 | case Instruction::SPARSE_SWITCH: { |
| 869 | uint32_t dex_pc = inst->GetDexPc(insns); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 870 | const uint16_t* switch_data = insns + dex_pc + dec_insn.vB; |
| 871 | int32_t test_val = shadow_frame.GetVReg(dec_insn.vA); |
| 872 | CHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 873 | uint16_t size = switch_data[1]; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 874 | CHECK_GT(size, 0); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 875 | const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 876 | CHECK(IsAligned<4>(keys)); |
| 877 | const int32_t* entries = keys + size; |
| 878 | CHECK(IsAligned<4>(entries)); |
| 879 | int lo = 0; |
| 880 | int hi = size - 1; |
| 881 | while (lo <= hi) { |
| 882 | int mid = (lo + hi) / 2; |
| 883 | int32_t foundVal = keys[mid]; |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 884 | if (test_val < foundVal) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 885 | hi = mid - 1; |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 886 | } else if (test_val > foundVal) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 887 | lo = mid + 1; |
| 888 | } else { |
| 889 | next_inst = Instruction::At(insns + dex_pc + entries[mid]); |
| 890 | break; |
| 891 | } |
| 892 | } |
| 893 | break; |
| 894 | } |
| 895 | case Instruction::FILL_ARRAY_DATA: { |
| 896 | Array* array = shadow_frame.GetReference(dec_insn.vA)->AsArray(); |
| 897 | if (UNLIKELY(array == NULL)) { |
| 898 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/NullPointerException;", |
| 899 | "null array in FILL_ARRAY_DATA"); |
| 900 | break; |
| 901 | } |
| 902 | DCHECK(array->IsArrayInstance() && !array->IsObjectArray()); |
| 903 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 904 | const Instruction::ArrayDataPayload* payload = |
| 905 | reinterpret_cast<const Instruction::ArrayDataPayload*>(insns + dex_pc + dec_insn.vB); |
| 906 | if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { |
| 907 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", |
| 908 | "failed FILL_ARRAY_DATA; length=%d, index=%d", |
| 909 | array->GetLength(), payload->element_count); |
| 910 | break; |
| 911 | } |
| 912 | uint32_t size_in_bytes = payload->element_count * payload->element_width; |
| 913 | memcpy(array->GetRawData(payload->element_width), payload->data, size_in_bytes); |
| 914 | break; |
| 915 | } |
| 916 | case Instruction::IF_EQ: { |
| 917 | if (shadow_frame.GetVReg(dec_insn.vA) == shadow_frame.GetVReg(dec_insn.vB)) { |
| 918 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 919 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vC); |
| 920 | } |
| 921 | break; |
| 922 | } |
| 923 | case Instruction::IF_NE: { |
| 924 | if (shadow_frame.GetVReg(dec_insn.vA) != shadow_frame.GetVReg(dec_insn.vB)) { |
| 925 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 926 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vC); |
| 927 | } |
| 928 | break; |
| 929 | } |
| 930 | case Instruction::IF_LT: { |
| 931 | if (shadow_frame.GetVReg(dec_insn.vA) < shadow_frame.GetVReg(dec_insn.vB)) { |
| 932 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 933 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vC); |
| 934 | } |
| 935 | break; |
| 936 | } |
| 937 | case Instruction::IF_GE: { |
| 938 | if (shadow_frame.GetVReg(dec_insn.vA) >= shadow_frame.GetVReg(dec_insn.vB)) { |
| 939 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 940 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vC); |
| 941 | } |
| 942 | break; |
| 943 | } |
| 944 | case Instruction::IF_GT: { |
| 945 | if (shadow_frame.GetVReg(dec_insn.vA) > shadow_frame.GetVReg(dec_insn.vB)) { |
| 946 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 947 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vC); |
| 948 | } |
| 949 | break; |
| 950 | } |
| 951 | case Instruction::IF_LE: { |
| 952 | if (shadow_frame.GetVReg(dec_insn.vA) <= shadow_frame.GetVReg(dec_insn.vB)) { |
| 953 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 954 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vC); |
| 955 | } |
| 956 | break; |
| 957 | } |
| 958 | case Instruction::IF_EQZ: { |
| 959 | if (shadow_frame.GetVReg(dec_insn.vA) == 0) { |
| 960 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 961 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vB); |
| 962 | } |
| 963 | break; |
| 964 | } |
| 965 | case Instruction::IF_NEZ: { |
| 966 | if (shadow_frame.GetVReg(dec_insn.vA) != 0) { |
| 967 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 968 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vB); |
| 969 | } |
| 970 | break; |
| 971 | } |
| 972 | case Instruction::IF_LTZ: { |
| 973 | if (shadow_frame.GetVReg(dec_insn.vA) < 0) { |
| 974 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 975 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vB); |
| 976 | } |
| 977 | break; |
| 978 | } |
| 979 | case Instruction::IF_GEZ: { |
| 980 | if (shadow_frame.GetVReg(dec_insn.vA) >= 0) { |
| 981 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 982 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vB); |
| 983 | } |
| 984 | break; |
| 985 | } |
| 986 | case Instruction::IF_GTZ: { |
| 987 | if (shadow_frame.GetVReg(dec_insn.vA) > 0) { |
| 988 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 989 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vB); |
| 990 | } |
| 991 | break; |
| 992 | } |
| 993 | case Instruction::IF_LEZ: { |
| 994 | if (shadow_frame.GetVReg(dec_insn.vA) <= 0) { |
| 995 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 996 | next_inst = Instruction::At(insns + dex_pc + dec_insn.vB); |
| 997 | } |
| 998 | break; |
| 999 | } |
| 1000 | case Instruction::AGET_BOOLEAN: { |
| 1001 | BooleanArray* a = shadow_frame.GetReference(dec_insn.vB)->AsBooleanArray(); |
| 1002 | if (UNLIKELY(a == NULL)) { |
| 1003 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1004 | break; |
| 1005 | } |
| 1006 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1007 | shadow_frame.SetVReg(dec_insn.vA, a->Get(index)); |
| 1008 | break; |
| 1009 | } |
| 1010 | case Instruction::AGET_BYTE: { |
| 1011 | ByteArray* a = shadow_frame.GetReference(dec_insn.vB)->AsByteArray(); |
| 1012 | if (UNLIKELY(a == NULL)) { |
| 1013 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1014 | break; |
| 1015 | } |
| 1016 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1017 | shadow_frame.SetVReg(dec_insn.vA, a->Get(index)); |
| 1018 | break; |
| 1019 | } |
| 1020 | case Instruction::AGET_CHAR: { |
| 1021 | CharArray* a = shadow_frame.GetReference(dec_insn.vB)->AsCharArray(); |
| 1022 | if (UNLIKELY(a == NULL)) { |
| 1023 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1024 | break; |
| 1025 | } |
| 1026 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1027 | shadow_frame.SetVReg(dec_insn.vA, a->Get(index)); |
| 1028 | break; |
| 1029 | } |
| 1030 | case Instruction::AGET_SHORT: { |
| 1031 | ShortArray* a = shadow_frame.GetReference(dec_insn.vB)->AsShortArray(); |
| 1032 | if (UNLIKELY(a == NULL)) { |
| 1033 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1034 | break; |
| 1035 | } |
| 1036 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1037 | shadow_frame.SetVReg(dec_insn.vA, a->Get(index)); |
| 1038 | break; |
| 1039 | } |
| 1040 | case Instruction::AGET: { |
| 1041 | IntArray* a = shadow_frame.GetReference(dec_insn.vB)->AsIntArray(); |
| 1042 | if (UNLIKELY(a == NULL)) { |
| 1043 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1044 | break; |
| 1045 | } |
| 1046 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1047 | shadow_frame.SetVReg(dec_insn.vA, a->Get(index)); |
| 1048 | break; |
| 1049 | } |
| 1050 | case Instruction::AGET_WIDE: { |
| 1051 | LongArray* a = shadow_frame.GetReference(dec_insn.vB)->AsLongArray(); |
| 1052 | if (UNLIKELY(a == NULL)) { |
| 1053 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1054 | break; |
| 1055 | } |
| 1056 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1057 | shadow_frame.SetVRegLong(dec_insn.vA, a->Get(index)); |
| 1058 | break; |
| 1059 | } |
| 1060 | case Instruction::AGET_OBJECT: { |
| 1061 | ObjectArray<Object>* a = shadow_frame.GetReference(dec_insn.vB)->AsObjectArray<Object>(); |
| 1062 | if (UNLIKELY(a == NULL)) { |
| 1063 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1064 | break; |
| 1065 | } |
| 1066 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1067 | Object* o = a->Get(index); |
| 1068 | shadow_frame.SetReferenceAndVReg(dec_insn.vA, o); |
| 1069 | break; |
| 1070 | } |
| 1071 | case Instruction::APUT_BOOLEAN: { |
| 1072 | uint8_t val = shadow_frame.GetVReg(dec_insn.vA); |
| 1073 | BooleanArray* a = shadow_frame.GetReference(dec_insn.vB)->AsBooleanArray(); |
| 1074 | if (UNLIKELY(a == NULL)) { |
| 1075 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1076 | break; |
| 1077 | } |
| 1078 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1079 | a->Set(index, val); |
| 1080 | break; |
| 1081 | } |
| 1082 | case Instruction::APUT_BYTE: { |
| 1083 | int8_t val = shadow_frame.GetVReg(dec_insn.vA); |
| 1084 | ByteArray* a = shadow_frame.GetReference(dec_insn.vB)->AsByteArray(); |
| 1085 | if (UNLIKELY(a == NULL)) { |
| 1086 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1087 | break; |
| 1088 | } |
| 1089 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1090 | a->Set(index, val); |
| 1091 | break; |
| 1092 | } |
| 1093 | case Instruction::APUT_CHAR: { |
| 1094 | uint16_t val = shadow_frame.GetVReg(dec_insn.vA); |
| 1095 | CharArray* a = shadow_frame.GetReference(dec_insn.vB)->AsCharArray(); |
| 1096 | if (UNLIKELY(a == NULL)) { |
| 1097 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1098 | break; |
| 1099 | } |
| 1100 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1101 | a->Set(index, val); |
| 1102 | break; |
| 1103 | } |
| 1104 | case Instruction::APUT_SHORT: { |
| 1105 | int16_t val = shadow_frame.GetVReg(dec_insn.vA); |
| 1106 | ShortArray* a = shadow_frame.GetReference(dec_insn.vB)->AsShortArray(); |
| 1107 | if (UNLIKELY(a == NULL)) { |
| 1108 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1109 | break; |
| 1110 | } |
| 1111 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1112 | a->Set(index, val); |
| 1113 | break; |
| 1114 | } |
| 1115 | case Instruction::APUT: { |
| 1116 | int32_t val = shadow_frame.GetVReg(dec_insn.vA); |
| 1117 | IntArray* a = shadow_frame.GetReference(dec_insn.vB)->AsIntArray(); |
| 1118 | if (UNLIKELY(a == NULL)) { |
| 1119 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1120 | break; |
| 1121 | } |
| 1122 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1123 | a->Set(index, val); |
| 1124 | break; |
| 1125 | } |
| 1126 | case Instruction::APUT_WIDE: { |
| 1127 | int64_t val = shadow_frame.GetVRegLong(dec_insn.vA); |
| 1128 | LongArray* a = shadow_frame.GetReference(dec_insn.vB)->AsLongArray(); |
| 1129 | if (UNLIKELY(a == NULL)) { |
| 1130 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1131 | break; |
| 1132 | } |
| 1133 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1134 | a->Set(index, val); |
| 1135 | break; |
| 1136 | } |
| 1137 | case Instruction::APUT_OBJECT: { |
| 1138 | Object* val = shadow_frame.GetReference(dec_insn.vA); |
| 1139 | ObjectArray<Object>* a = shadow_frame.GetReference(dec_insn.vB)->AsObjectArray<Object>(); |
| 1140 | if (UNLIKELY(a == NULL)) { |
| 1141 | ThrowNullPointerExceptionFromDexPC(shadow_frame.GetMethod(), inst->GetDexPc(insns)); |
| 1142 | break; |
| 1143 | } |
| 1144 | int32_t index = shadow_frame.GetVReg(dec_insn.vC); |
| 1145 | a->Set(index, val); |
| 1146 | break; |
| 1147 | } |
| 1148 | case Instruction::IGET_BOOLEAN: |
| 1149 | DoFieldGet(self, shadow_frame, dec_insn, InstancePrimitiveRead, Primitive::kPrimBoolean); |
| 1150 | break; |
| 1151 | case Instruction::IGET_BYTE: |
| 1152 | DoFieldGet(self, shadow_frame, dec_insn, InstancePrimitiveRead, Primitive::kPrimByte); |
| 1153 | break; |
| 1154 | case Instruction::IGET_CHAR: |
| 1155 | DoFieldGet(self, shadow_frame, dec_insn, InstancePrimitiveRead, Primitive::kPrimChar); |
| 1156 | break; |
| 1157 | case Instruction::IGET_SHORT: |
| 1158 | DoFieldGet(self, shadow_frame, dec_insn, InstancePrimitiveRead, Primitive::kPrimShort); |
| 1159 | break; |
| 1160 | case Instruction::IGET: |
| 1161 | DoFieldGet(self, shadow_frame, dec_insn, InstancePrimitiveRead, Primitive::kPrimInt); |
| 1162 | break; |
| 1163 | case Instruction::IGET_WIDE: |
| 1164 | DoFieldGet(self, shadow_frame, dec_insn, InstancePrimitiveRead, Primitive::kPrimLong); |
| 1165 | break; |
| 1166 | case Instruction::IGET_OBJECT: |
| 1167 | DoFieldGet(self, shadow_frame, dec_insn, InstanceObjectRead, Primitive::kPrimNot); |
| 1168 | break; |
| 1169 | case Instruction::SGET_BOOLEAN: |
| 1170 | DoFieldGet(self, shadow_frame, dec_insn, StaticPrimitiveRead, Primitive::kPrimBoolean); |
| 1171 | break; |
| 1172 | case Instruction::SGET_BYTE: |
| 1173 | DoFieldGet(self, shadow_frame, dec_insn, StaticPrimitiveRead, Primitive::kPrimByte); |
| 1174 | break; |
| 1175 | case Instruction::SGET_CHAR: |
| 1176 | DoFieldGet(self, shadow_frame, dec_insn, StaticPrimitiveRead, Primitive::kPrimChar); |
| 1177 | break; |
| 1178 | case Instruction::SGET_SHORT: |
| 1179 | DoFieldGet(self, shadow_frame, dec_insn, StaticPrimitiveRead, Primitive::kPrimShort); |
| 1180 | break; |
| 1181 | case Instruction::SGET: |
| 1182 | DoFieldGet(self, shadow_frame, dec_insn, StaticPrimitiveRead, Primitive::kPrimInt); |
| 1183 | break; |
| 1184 | case Instruction::SGET_WIDE: |
| 1185 | DoFieldGet(self, shadow_frame, dec_insn, StaticPrimitiveRead, Primitive::kPrimLong); |
| 1186 | break; |
| 1187 | case Instruction::SGET_OBJECT: |
| 1188 | DoFieldGet(self, shadow_frame, dec_insn, StaticObjectRead, Primitive::kPrimNot); |
| 1189 | break; |
| 1190 | case Instruction::IPUT_BOOLEAN: |
| 1191 | DoFieldPut(self, shadow_frame, dec_insn, InstancePrimitiveWrite, Primitive::kPrimBoolean); |
| 1192 | break; |
| 1193 | case Instruction::IPUT_BYTE: |
| 1194 | DoFieldPut(self, shadow_frame, dec_insn, InstancePrimitiveWrite, Primitive::kPrimByte); |
| 1195 | break; |
| 1196 | case Instruction::IPUT_CHAR: |
| 1197 | DoFieldPut(self, shadow_frame, dec_insn, InstancePrimitiveWrite, Primitive::kPrimChar); |
| 1198 | break; |
| 1199 | case Instruction::IPUT_SHORT: |
| 1200 | DoFieldPut(self, shadow_frame, dec_insn, InstancePrimitiveWrite, Primitive::kPrimShort); |
| 1201 | break; |
| 1202 | case Instruction::IPUT: |
| 1203 | DoFieldPut(self, shadow_frame, dec_insn, InstancePrimitiveWrite, Primitive::kPrimInt); |
| 1204 | break; |
| 1205 | case Instruction::IPUT_WIDE: |
| 1206 | DoFieldPut(self, shadow_frame, dec_insn, InstancePrimitiveWrite, Primitive::kPrimLong); |
| 1207 | break; |
| 1208 | case Instruction::IPUT_OBJECT: |
| 1209 | DoFieldPut(self, shadow_frame, dec_insn, InstanceObjectWrite, Primitive::kPrimNot); |
| 1210 | break; |
| 1211 | case Instruction::SPUT_BOOLEAN: |
| 1212 | DoFieldPut(self, shadow_frame, dec_insn, StaticPrimitiveWrite, Primitive::kPrimBoolean); |
| 1213 | break; |
| 1214 | case Instruction::SPUT_BYTE: |
| 1215 | DoFieldPut(self, shadow_frame, dec_insn, StaticPrimitiveWrite, Primitive::kPrimByte); |
| 1216 | break; |
| 1217 | case Instruction::SPUT_CHAR: |
| 1218 | DoFieldPut(self, shadow_frame, dec_insn, StaticPrimitiveWrite, Primitive::kPrimChar); |
| 1219 | break; |
| 1220 | case Instruction::SPUT_SHORT: |
| 1221 | DoFieldPut(self, shadow_frame, dec_insn, StaticPrimitiveWrite, Primitive::kPrimShort); |
| 1222 | break; |
| 1223 | case Instruction::SPUT: |
| 1224 | DoFieldPut(self, shadow_frame, dec_insn, StaticPrimitiveWrite, Primitive::kPrimInt); |
| 1225 | break; |
| 1226 | case Instruction::SPUT_WIDE: |
| 1227 | DoFieldPut(self, shadow_frame, dec_insn, StaticPrimitiveWrite, Primitive::kPrimLong); |
| 1228 | break; |
| 1229 | case Instruction::SPUT_OBJECT: |
| 1230 | DoFieldPut(self, shadow_frame, dec_insn, StaticObjectWrite, Primitive::kPrimNot); |
| 1231 | break; |
| 1232 | case Instruction::INVOKE_VIRTUAL: |
| 1233 | DoInvoke(self, mh, shadow_frame, dec_insn, kVirtual, false, &result_register); |
| 1234 | break; |
| 1235 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 1236 | DoInvoke(self, mh, shadow_frame, dec_insn, kVirtual, true, &result_register); |
| 1237 | break; |
| 1238 | case Instruction::INVOKE_SUPER: |
| 1239 | DoInvoke(self, mh, shadow_frame, dec_insn, kSuper, false, &result_register); |
| 1240 | break; |
| 1241 | case Instruction::INVOKE_SUPER_RANGE: |
| 1242 | DoInvoke(self, mh, shadow_frame, dec_insn, kSuper, true, &result_register); |
| 1243 | break; |
| 1244 | case Instruction::INVOKE_DIRECT: |
| 1245 | DoInvoke(self, mh, shadow_frame, dec_insn, kDirect, false, &result_register); |
| 1246 | break; |
| 1247 | case Instruction::INVOKE_DIRECT_RANGE: |
| 1248 | DoInvoke(self, mh, shadow_frame, dec_insn, kDirect, true, &result_register); |
| 1249 | break; |
| 1250 | case Instruction::INVOKE_INTERFACE: |
| 1251 | DoInvoke(self, mh, shadow_frame, dec_insn, kInterface, false, &result_register); |
| 1252 | break; |
| 1253 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1254 | DoInvoke(self, mh, shadow_frame, dec_insn, kInterface, true, &result_register); |
| 1255 | break; |
| 1256 | case Instruction::INVOKE_STATIC: |
| 1257 | DoInvoke(self, mh, shadow_frame, dec_insn, kStatic, false, &result_register); |
| 1258 | break; |
| 1259 | case Instruction::INVOKE_STATIC_RANGE: |
| 1260 | DoInvoke(self, mh, shadow_frame, dec_insn, kStatic, true, &result_register); |
| 1261 | break; |
| 1262 | case Instruction::NEG_INT: |
| 1263 | shadow_frame.SetVReg(dec_insn.vA, -shadow_frame.GetVReg(dec_insn.vB)); |
| 1264 | break; |
| 1265 | case Instruction::NOT_INT: |
| 1266 | shadow_frame.SetVReg(dec_insn.vA, 0 ^ shadow_frame.GetVReg(dec_insn.vB)); |
| 1267 | break; |
| 1268 | case Instruction::NEG_LONG: |
| 1269 | shadow_frame.SetVRegLong(dec_insn.vA, -shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1270 | break; |
| 1271 | case Instruction::NOT_LONG: |
| 1272 | shadow_frame.SetVRegLong(dec_insn.vA, 0 ^ shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1273 | break; |
| 1274 | case Instruction::NEG_FLOAT: |
| 1275 | shadow_frame.SetVRegFloat(dec_insn.vA, -shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1276 | break; |
| 1277 | case Instruction::NEG_DOUBLE: |
| 1278 | shadow_frame.SetVRegDouble(dec_insn.vA, -shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1279 | break; |
| 1280 | case Instruction::INT_TO_LONG: |
| 1281 | shadow_frame.SetVRegLong(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB)); |
| 1282 | break; |
| 1283 | case Instruction::INT_TO_FLOAT: |
| 1284 | shadow_frame.SetVRegFloat(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB)); |
| 1285 | break; |
| 1286 | case Instruction::INT_TO_DOUBLE: |
| 1287 | shadow_frame.SetVRegDouble(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB)); |
| 1288 | break; |
| 1289 | case Instruction::LONG_TO_INT: |
| 1290 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1291 | break; |
| 1292 | case Instruction::LONG_TO_FLOAT: |
| 1293 | shadow_frame.SetVRegFloat(dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1294 | break; |
| 1295 | case Instruction::LONG_TO_DOUBLE: |
| 1296 | shadow_frame.SetVRegDouble(dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1297 | break; |
| 1298 | case Instruction::FLOAT_TO_INT: |
| 1299 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1300 | break; |
| 1301 | case Instruction::FLOAT_TO_LONG: |
| 1302 | shadow_frame.SetVRegLong(dec_insn.vA, shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1303 | break; |
| 1304 | case Instruction::FLOAT_TO_DOUBLE: |
| 1305 | shadow_frame.SetVRegDouble(dec_insn.vA, shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1306 | break; |
| 1307 | case Instruction::DOUBLE_TO_INT: |
| 1308 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1309 | break; |
| 1310 | case Instruction::DOUBLE_TO_LONG: |
| 1311 | shadow_frame.SetVRegLong(dec_insn.vA, shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1312 | break; |
| 1313 | case Instruction::DOUBLE_TO_FLOAT: |
| 1314 | shadow_frame.SetVRegFloat(dec_insn.vA, shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1315 | break; |
| 1316 | case Instruction::INT_TO_BYTE: |
| 1317 | shadow_frame.SetVReg(dec_insn.vA, static_cast<int8_t>(shadow_frame.GetVReg(dec_insn.vB))); |
| 1318 | break; |
| 1319 | case Instruction::INT_TO_CHAR: |
| 1320 | shadow_frame.SetVReg(dec_insn.vA, static_cast<uint16_t>(shadow_frame.GetVReg(dec_insn.vB))); |
| 1321 | break; |
| 1322 | case Instruction::INT_TO_SHORT: |
| 1323 | shadow_frame.SetVReg(dec_insn.vA, static_cast<int16_t>(shadow_frame.GetVReg(dec_insn.vB))); |
| 1324 | break; |
| 1325 | case Instruction::ADD_INT: |
| 1326 | shadow_frame.SetVReg(dec_insn.vA, |
| 1327 | shadow_frame.GetVReg(dec_insn.vB) + shadow_frame.GetVReg(dec_insn.vC)); |
| 1328 | break; |
| 1329 | case Instruction::SUB_INT: |
| 1330 | shadow_frame.SetVReg(dec_insn.vA, |
| 1331 | shadow_frame.GetVReg(dec_insn.vB) - shadow_frame.GetVReg(dec_insn.vC)); |
| 1332 | break; |
| 1333 | case Instruction::MUL_INT: |
| 1334 | shadow_frame.SetVReg(dec_insn.vA, |
| 1335 | shadow_frame.GetVReg(dec_insn.vB) * shadow_frame.GetVReg(dec_insn.vC)); |
| 1336 | break; |
| 1337 | case Instruction::REM_INT: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1338 | DoIntRemainder(self, shadow_frame, dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB), |
| 1339 | shadow_frame.GetVReg(dec_insn.vC)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1340 | break; |
| 1341 | case Instruction::DIV_INT: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1342 | DoIntDivide(self, shadow_frame, dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB), |
| 1343 | shadow_frame.GetVReg(dec_insn.vC)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1344 | break; |
| 1345 | case Instruction::SHL_INT: |
| 1346 | shadow_frame.SetVReg(dec_insn.vA, |
| 1347 | shadow_frame.GetVReg(dec_insn.vB) << shadow_frame.GetVReg(dec_insn.vC)); |
| 1348 | break; |
| 1349 | case Instruction::SHR_INT: |
| 1350 | shadow_frame.SetVReg(dec_insn.vA, |
| 1351 | shadow_frame.GetVReg(dec_insn.vB) >> shadow_frame.GetVReg(dec_insn.vC)); |
| 1352 | break; |
| 1353 | case Instruction::USHR_INT: |
| 1354 | shadow_frame.SetVReg(dec_insn.vA, |
| 1355 | static_cast<uint32_t>(shadow_frame.GetVReg(dec_insn.vB)) >> |
| 1356 | shadow_frame.GetVReg(dec_insn.vC)); |
| 1357 | break; |
| 1358 | case Instruction::AND_INT: |
| 1359 | shadow_frame.SetVReg(dec_insn.vA, |
| 1360 | shadow_frame.GetVReg(dec_insn.vB) & shadow_frame.GetVReg(dec_insn.vC)); |
| 1361 | break; |
| 1362 | case Instruction::OR_INT: |
| 1363 | shadow_frame.SetVReg(dec_insn.vA, |
| 1364 | shadow_frame.GetVReg(dec_insn.vB) | shadow_frame.GetVReg(dec_insn.vC)); |
| 1365 | break; |
| 1366 | case Instruction::XOR_INT: |
| 1367 | shadow_frame.SetVReg(dec_insn.vA, |
| 1368 | shadow_frame.GetVReg(dec_insn.vB) ^ shadow_frame.GetVReg(dec_insn.vC)); |
| 1369 | break; |
| 1370 | case Instruction::ADD_LONG: |
| 1371 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1372 | shadow_frame.GetVRegLong(dec_insn.vB) + |
| 1373 | shadow_frame.GetVRegLong(dec_insn.vC)); |
| 1374 | break; |
| 1375 | case Instruction::SUB_LONG: |
| 1376 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1377 | shadow_frame.GetVRegLong(dec_insn.vB) - |
| 1378 | shadow_frame.GetVRegLong(dec_insn.vC)); |
| 1379 | break; |
| 1380 | case Instruction::MUL_LONG: |
| 1381 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1382 | shadow_frame.GetVRegLong(dec_insn.vB) * |
| 1383 | shadow_frame.GetVRegLong(dec_insn.vC)); |
| 1384 | break; |
| 1385 | case Instruction::DIV_LONG: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1386 | DoLongDivide(self, shadow_frame, dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vB), |
| 1387 | shadow_frame.GetVRegLong(dec_insn.vC)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1388 | break; |
| 1389 | case Instruction::REM_LONG: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1390 | DoLongRemainder(self, shadow_frame, dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vB), |
| 1391 | shadow_frame.GetVRegLong(dec_insn.vC)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1392 | break; |
| 1393 | case Instruction::AND_LONG: |
| 1394 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1395 | shadow_frame.GetVRegLong(dec_insn.vB) & |
| 1396 | shadow_frame.GetVRegLong(dec_insn.vC)); |
| 1397 | break; |
| 1398 | case Instruction::OR_LONG: |
| 1399 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1400 | shadow_frame.GetVRegLong(dec_insn.vB) | |
| 1401 | shadow_frame.GetVRegLong(dec_insn.vC)); |
| 1402 | break; |
| 1403 | case Instruction::XOR_LONG: |
| 1404 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1405 | shadow_frame.GetVRegLong(dec_insn.vB) ^ |
| 1406 | shadow_frame.GetVRegLong(dec_insn.vC)); |
| 1407 | break; |
| 1408 | case Instruction::SHL_LONG: |
| 1409 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1410 | shadow_frame.GetVRegLong(dec_insn.vB) << |
| 1411 | shadow_frame.GetVReg(dec_insn.vC)); |
| 1412 | break; |
| 1413 | case Instruction::SHR_LONG: |
| 1414 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1415 | shadow_frame.GetVRegLong(dec_insn.vB) >> |
| 1416 | shadow_frame.GetVReg(dec_insn.vC)); |
| 1417 | break; |
| 1418 | case Instruction::USHR_LONG: |
| 1419 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1420 | static_cast<uint64_t>(shadow_frame.GetVRegLong(dec_insn.vB)) >> |
| 1421 | shadow_frame.GetVReg(dec_insn.vC)); |
| 1422 | break; |
| 1423 | case Instruction::ADD_FLOAT: |
| 1424 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1425 | shadow_frame.GetVRegFloat(dec_insn.vB) + |
| 1426 | shadow_frame.GetVRegFloat(dec_insn.vC)); |
| 1427 | break; |
| 1428 | case Instruction::SUB_FLOAT: |
| 1429 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1430 | shadow_frame.GetVRegFloat(dec_insn.vB) - |
| 1431 | shadow_frame.GetVRegFloat(dec_insn.vC)); |
| 1432 | break; |
| 1433 | case Instruction::MUL_FLOAT: |
| 1434 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1435 | shadow_frame.GetVRegFloat(dec_insn.vB) * |
| 1436 | shadow_frame.GetVRegFloat(dec_insn.vC)); |
| 1437 | break; |
| 1438 | case Instruction::DIV_FLOAT: |
| 1439 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1440 | shadow_frame.GetVRegFloat(dec_insn.vB) / |
| 1441 | shadow_frame.GetVRegFloat(dec_insn.vC)); |
| 1442 | break; |
| 1443 | case Instruction::REM_FLOAT: |
| 1444 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1445 | fmodf(shadow_frame.GetVRegFloat(dec_insn.vB), |
| 1446 | shadow_frame.GetVRegFloat(dec_insn.vC))); |
| 1447 | break; |
| 1448 | case Instruction::ADD_DOUBLE: |
| 1449 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1450 | shadow_frame.GetVRegDouble(dec_insn.vB) + |
| 1451 | shadow_frame.GetVRegDouble(dec_insn.vC)); |
| 1452 | break; |
| 1453 | case Instruction::SUB_DOUBLE: |
| 1454 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1455 | shadow_frame.GetVRegDouble(dec_insn.vB) - |
| 1456 | shadow_frame.GetVRegDouble(dec_insn.vC)); |
| 1457 | break; |
| 1458 | case Instruction::MUL_DOUBLE: |
| 1459 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1460 | shadow_frame.GetVRegDouble(dec_insn.vB) * |
| 1461 | shadow_frame.GetVRegDouble(dec_insn.vC)); |
| 1462 | break; |
| 1463 | case Instruction::DIV_DOUBLE: |
| 1464 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1465 | shadow_frame.GetVRegDouble(dec_insn.vB) / |
| 1466 | shadow_frame.GetVRegDouble(dec_insn.vC)); |
| 1467 | break; |
| 1468 | case Instruction::REM_DOUBLE: |
| 1469 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1470 | fmod(shadow_frame.GetVRegDouble(dec_insn.vB), |
| 1471 | shadow_frame.GetVRegDouble(dec_insn.vC))); |
| 1472 | break; |
| 1473 | case Instruction::ADD_INT_2ADDR: |
| 1474 | shadow_frame.SetVReg(dec_insn.vA, |
| 1475 | shadow_frame.GetVReg(dec_insn.vA) + shadow_frame.GetVReg(dec_insn.vB)); |
| 1476 | break; |
| 1477 | case Instruction::SUB_INT_2ADDR: |
| 1478 | shadow_frame.SetVReg(dec_insn.vA, |
| 1479 | shadow_frame.GetVReg(dec_insn.vA) - shadow_frame.GetVReg(dec_insn.vB)); |
| 1480 | break; |
| 1481 | case Instruction::MUL_INT_2ADDR: |
| 1482 | shadow_frame.SetVReg(dec_insn.vA, |
| 1483 | shadow_frame.GetVReg(dec_insn.vA) * shadow_frame.GetVReg(dec_insn.vB)); |
| 1484 | break; |
| 1485 | case Instruction::REM_INT_2ADDR: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1486 | DoIntRemainder(self, shadow_frame, dec_insn.vA, shadow_frame.GetVReg(dec_insn.vA), |
| 1487 | shadow_frame.GetVReg(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1488 | break; |
| 1489 | case Instruction::SHL_INT_2ADDR: |
| 1490 | shadow_frame.SetVReg(dec_insn.vA, |
| 1491 | shadow_frame.GetVReg(dec_insn.vA) << shadow_frame.GetVReg(dec_insn.vB)); |
| 1492 | break; |
| 1493 | case Instruction::SHR_INT_2ADDR: |
| 1494 | shadow_frame.SetVReg(dec_insn.vA, |
| 1495 | shadow_frame.GetVReg(dec_insn.vA) >> shadow_frame.GetVReg(dec_insn.vB)); |
| 1496 | break; |
| 1497 | case Instruction::USHR_INT_2ADDR: |
| 1498 | shadow_frame.SetVReg(dec_insn.vA, |
| 1499 | static_cast<uint32_t>(shadow_frame.GetVReg(dec_insn.vA)) >> |
| 1500 | shadow_frame.GetVReg(dec_insn.vB)); |
| 1501 | break; |
| 1502 | case Instruction::AND_INT_2ADDR: |
| 1503 | shadow_frame.SetVReg(dec_insn.vA, |
| 1504 | shadow_frame.GetVReg(dec_insn.vA) & shadow_frame.GetVReg(dec_insn.vB)); |
| 1505 | break; |
| 1506 | case Instruction::OR_INT_2ADDR: |
| 1507 | shadow_frame.SetVReg(dec_insn.vA, |
| 1508 | shadow_frame.GetVReg(dec_insn.vA) | shadow_frame.GetVReg(dec_insn.vB)); |
| 1509 | break; |
| 1510 | case Instruction::XOR_INT_2ADDR: |
| 1511 | shadow_frame.SetVReg(dec_insn.vA, |
| 1512 | shadow_frame.GetVReg(dec_insn.vA) ^ shadow_frame.GetVReg(dec_insn.vB)); |
| 1513 | break; |
| 1514 | case Instruction::DIV_INT_2ADDR: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1515 | DoIntDivide(self, shadow_frame, dec_insn.vA, shadow_frame.GetVReg(dec_insn.vA), |
| 1516 | shadow_frame.GetVReg(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1517 | break; |
| 1518 | case Instruction::ADD_LONG_2ADDR: |
| 1519 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1520 | shadow_frame.GetVRegLong(dec_insn.vA) + |
| 1521 | shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1522 | break; |
| 1523 | case Instruction::SUB_LONG_2ADDR: |
| 1524 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1525 | shadow_frame.GetVRegLong(dec_insn.vA) - |
| 1526 | shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1527 | break; |
| 1528 | case Instruction::MUL_LONG_2ADDR: |
| 1529 | shadow_frame.SetVRegLong(dec_insn.vA, |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1530 | shadow_frame.GetVRegLong(dec_insn.vA) * |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1531 | shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1532 | break; |
| 1533 | case Instruction::DIV_LONG_2ADDR: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1534 | DoLongDivide(self, shadow_frame, dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vA), |
| 1535 | shadow_frame.GetVRegLong(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1536 | break; |
| 1537 | case Instruction::REM_LONG_2ADDR: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1538 | DoLongRemainder(self, shadow_frame, dec_insn.vA, shadow_frame.GetVRegLong(dec_insn.vA), |
| 1539 | shadow_frame.GetVRegLong(dec_insn.vB)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1540 | break; |
| 1541 | case Instruction::AND_LONG_2ADDR: |
| 1542 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1543 | shadow_frame.GetVRegLong(dec_insn.vA) & |
| 1544 | shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1545 | break; |
| 1546 | case Instruction::OR_LONG_2ADDR: |
| 1547 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1548 | shadow_frame.GetVRegLong(dec_insn.vA) | |
| 1549 | shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1550 | break; |
| 1551 | case Instruction::XOR_LONG_2ADDR: |
| 1552 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1553 | shadow_frame.GetVRegLong(dec_insn.vA) ^ |
| 1554 | shadow_frame.GetVRegLong(dec_insn.vB)); |
| 1555 | break; |
| 1556 | case Instruction::SHL_LONG_2ADDR: |
| 1557 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1558 | shadow_frame.GetVRegLong(dec_insn.vA) << |
| 1559 | shadow_frame.GetVReg(dec_insn.vB)); |
| 1560 | break; |
| 1561 | case Instruction::SHR_LONG_2ADDR: |
| 1562 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1563 | shadow_frame.GetVRegLong(dec_insn.vA) >> |
| 1564 | shadow_frame.GetVReg(dec_insn.vB)); |
| 1565 | break; |
| 1566 | case Instruction::USHR_LONG_2ADDR: |
| 1567 | shadow_frame.SetVRegLong(dec_insn.vA, |
| 1568 | static_cast<uint64_t>(shadow_frame.GetVRegLong(dec_insn.vA)) >> |
| 1569 | shadow_frame.GetVReg(dec_insn.vB)); |
| 1570 | break; |
| 1571 | case Instruction::ADD_FLOAT_2ADDR: |
| 1572 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1573 | shadow_frame.GetVRegFloat(dec_insn.vA) + |
| 1574 | shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1575 | break; |
| 1576 | case Instruction::SUB_FLOAT_2ADDR: |
| 1577 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1578 | shadow_frame.GetVRegFloat(dec_insn.vA) - |
| 1579 | shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1580 | break; |
| 1581 | case Instruction::MUL_FLOAT_2ADDR: |
| 1582 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1583 | shadow_frame.GetVRegFloat(dec_insn.vA) * |
| 1584 | shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1585 | break; |
| 1586 | case Instruction::DIV_FLOAT_2ADDR: |
| 1587 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1588 | shadow_frame.GetVRegFloat(dec_insn.vA) / |
| 1589 | shadow_frame.GetVRegFloat(dec_insn.vB)); |
| 1590 | break; |
| 1591 | case Instruction::REM_FLOAT_2ADDR: |
| 1592 | shadow_frame.SetVRegFloat(dec_insn.vA, |
| 1593 | fmodf(shadow_frame.GetVRegFloat(dec_insn.vA), |
| 1594 | shadow_frame.GetVRegFloat(dec_insn.vB))); |
| 1595 | break; |
| 1596 | case Instruction::ADD_DOUBLE_2ADDR: |
| 1597 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1598 | shadow_frame.GetVRegDouble(dec_insn.vA) + |
| 1599 | shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1600 | break; |
| 1601 | case Instruction::SUB_DOUBLE_2ADDR: |
| 1602 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1603 | shadow_frame.GetVRegDouble(dec_insn.vA) - |
| 1604 | shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1605 | break; |
| 1606 | case Instruction::MUL_DOUBLE_2ADDR: |
| 1607 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1608 | shadow_frame.GetVRegDouble(dec_insn.vA) * |
| 1609 | shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1610 | break; |
| 1611 | case Instruction::DIV_DOUBLE_2ADDR: |
| 1612 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1613 | shadow_frame.GetVRegDouble(dec_insn.vA) / |
| 1614 | shadow_frame.GetVRegDouble(dec_insn.vB)); |
| 1615 | break; |
| 1616 | case Instruction::REM_DOUBLE_2ADDR: |
| 1617 | shadow_frame.SetVRegDouble(dec_insn.vA, |
| 1618 | fmod(shadow_frame.GetVRegDouble(dec_insn.vA), |
| 1619 | shadow_frame.GetVRegDouble(dec_insn.vB))); |
| 1620 | break; |
| 1621 | case Instruction::ADD_INT_LIT16: |
| 1622 | case Instruction::ADD_INT_LIT8: |
| 1623 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) + dec_insn.vC); |
| 1624 | break; |
| 1625 | case Instruction::RSUB_INT: |
| 1626 | case Instruction::RSUB_INT_LIT8: |
| 1627 | shadow_frame.SetVReg(dec_insn.vA, dec_insn.vC - shadow_frame.GetVReg(dec_insn.vB)); |
| 1628 | break; |
| 1629 | case Instruction::MUL_INT_LIT16: |
| 1630 | case Instruction::MUL_INT_LIT8: |
| 1631 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) * dec_insn.vC); |
| 1632 | break; |
| 1633 | case Instruction::DIV_INT_LIT16: |
| 1634 | case Instruction::DIV_INT_LIT8: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1635 | DoIntDivide(self, shadow_frame, dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB), |
| 1636 | dec_insn.vC); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1637 | break; |
| 1638 | case Instruction::REM_INT_LIT16: |
| 1639 | case Instruction::REM_INT_LIT8: |
jeffhao | d91398c | 2012-11-20 17:17:33 -0800 | [diff] [blame^] | 1640 | DoIntRemainder(self, shadow_frame, dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB), |
| 1641 | dec_insn.vC); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1642 | break; |
| 1643 | case Instruction::AND_INT_LIT16: |
| 1644 | case Instruction::AND_INT_LIT8: |
| 1645 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) & dec_insn.vC); |
| 1646 | break; |
| 1647 | case Instruction::OR_INT_LIT16: |
| 1648 | case Instruction::OR_INT_LIT8: |
| 1649 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) | dec_insn.vC); |
| 1650 | break; |
| 1651 | case Instruction::XOR_INT_LIT16: |
| 1652 | case Instruction::XOR_INT_LIT8: |
| 1653 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) ^ dec_insn.vC); |
| 1654 | break; |
| 1655 | case Instruction::SHL_INT_LIT8: |
| 1656 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) << dec_insn.vC); |
| 1657 | break; |
| 1658 | case Instruction::SHR_INT_LIT8: |
| 1659 | shadow_frame.SetVReg(dec_insn.vA, shadow_frame.GetVReg(dec_insn.vB) >> dec_insn.vC); |
| 1660 | break; |
| 1661 | case Instruction::USHR_INT_LIT8: |
| 1662 | shadow_frame.SetVReg(dec_insn.vA, |
| 1663 | static_cast<uint32_t>(shadow_frame.GetVReg(dec_insn.vB)) >> |
| 1664 | dec_insn.vC); |
| 1665 | break; |
| 1666 | default: |
| 1667 | LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile()); |
| 1668 | break; |
| 1669 | } |
| 1670 | if (UNLIKELY(self->IsExceptionPending())) { |
| 1671 | uint32_t found_dex_pc = |
| 1672 | shadow_frame.GetMethod()->FindCatchBlock(self->GetException()->GetClass(), |
| 1673 | inst->GetDexPc(insns)); |
| 1674 | if (found_dex_pc == DexFile::kDexNoIndex) { |
| 1675 | JValue result; |
| 1676 | result.SetJ(0); |
| 1677 | return result; // Handler in caller. |
| 1678 | } else { |
| 1679 | next_inst = Instruction::At(insns + found_dex_pc); |
| 1680 | } |
| 1681 | } |
| 1682 | inst = next_inst; |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | void EnterInterpreterFromInvoke(Thread* self, AbstractMethod* method, Object* receiver, |
| 1687 | JValue* args, JValue* result) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1688 | DCHECK_EQ(self, Thread::Current()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1689 | MethodHelper mh(method); |
| 1690 | const DexFile::CodeItem* code_item = mh.GetCodeItem(); |
| 1691 | uint16_t num_regs; |
| 1692 | uint16_t num_ins; |
| 1693 | if (code_item != NULL) { |
| 1694 | num_regs = code_item->registers_size_; |
| 1695 | num_ins = code_item->ins_size_; |
| 1696 | } else { |
| 1697 | DCHECK(method->IsNative()); |
| 1698 | num_regs = num_ins = AbstractMethod::NumArgRegisters(mh.GetShorty()); |
| 1699 | if (!method->IsStatic()) { |
| 1700 | num_regs++; |
| 1701 | num_ins++; |
| 1702 | } |
| 1703 | } |
| 1704 | // Set up shadow frame with matching number of reference slots to vregs. |
| 1705 | ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame(); |
| 1706 | UniquePtr<ShadowFrame> shadow_frame(ShadowFrame::Create(num_regs, num_regs, |
| 1707 | (last_shadow_frame == NULL) ? NULL : last_shadow_frame->GetLink(), |
| 1708 | method, 0)); |
| 1709 | self->PushShadowFrame(shadow_frame.get()); |
| 1710 | size_t cur_reg = num_regs - num_ins; |
| 1711 | if (!method->IsStatic()) { |
| 1712 | CHECK(receiver != NULL); |
| 1713 | shadow_frame->SetReferenceAndVReg(cur_reg, receiver); |
| 1714 | ++cur_reg; |
| 1715 | } else if (!method->GetDeclaringClass()->IsInitializing()) { |
| 1716 | Runtime::Current()->GetClassLinker()->EnsureInitialized(method->GetDeclaringClass(), |
| 1717 | true, true); |
| 1718 | CHECK(method->GetDeclaringClass()->IsInitializing()); |
| 1719 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1720 | const char* shorty = mh.GetShorty(); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1721 | size_t arg_pos = 0; |
| 1722 | for (; cur_reg < num_regs; ++cur_reg, ++arg_pos) { |
| 1723 | DCHECK_LT(arg_pos + 1, mh.GetShortyLength()); |
| 1724 | switch (shorty[arg_pos + 1]) { |
| 1725 | case 'L': { |
| 1726 | Object* o = args[arg_pos].GetL(); |
| 1727 | shadow_frame->SetReferenceAndVReg(cur_reg, o); |
| 1728 | break; |
| 1729 | } |
| 1730 | case 'J': case 'D': |
| 1731 | shadow_frame->SetVRegLong(cur_reg, args[arg_pos].GetJ()); |
| 1732 | cur_reg++; |
| 1733 | break; |
| 1734 | default: |
| 1735 | shadow_frame->SetVReg(cur_reg, args[arg_pos].GetI()); |
| 1736 | break; |
| 1737 | } |
| 1738 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1739 | if (LIKELY(!method->IsNative())) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1740 | JValue r = Execute(self, mh, code_item, *shadow_frame.get()); |
| 1741 | if (result != NULL) { |
| 1742 | *result = r; |
| 1743 | } |
| 1744 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1745 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 1746 | // generated stub) except during testing and image writing. |
| 1747 | if (!Runtime::Current()->IsStarted()) { |
| 1748 | UnstartedRuntimeJni(self, method, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1749 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1750 | InterpreterJni(self, method, shorty, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1751 | } |
| 1752 | } |
| 1753 | self->PopShadowFrame(); |
| 1754 | } |
| 1755 | |
| 1756 | } // namespace interpreter |
| 1757 | } // namespace art |