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 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 17 | #include "interpreter_common.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 18 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 19 | namespace art { |
| 20 | namespace interpreter { |
| 21 | |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 22 | // Hand select a number of methods to be run in a not yet started runtime without using JNI. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 23 | static void UnstartedRuntimeJni(Thread* self, ArtMethod* method, |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 24 | Object* receiver, uint32_t* args, JValue* result) |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 25 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 26 | std::string name(PrettyMethod(method)); |
| 27 | if (name == "java.lang.ClassLoader dalvik.system.VMStack.getCallingClassLoader()") { |
| 28 | result->SetL(NULL); |
| 29 | } else if (name == "java.lang.Class dalvik.system.VMStack.getStackClass2()") { |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 30 | NthCallerVisitor visitor(self, 3); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 31 | visitor.WalkStack(); |
| 32 | result->SetL(visitor.caller->GetDeclaringClass()); |
| 33 | } else if (name == "double java.lang.Math.log(double)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 34 | JValue value; |
| 35 | value.SetJ((static_cast<uint64_t>(args[1]) << 32) | args[0]); |
| 36 | result->SetD(log(value.GetD())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 37 | } else if (name == "java.lang.String java.lang.Class.getNameNative()") { |
| 38 | result->SetL(receiver->AsClass()->ComputeName()); |
| 39 | } else if (name == "int java.lang.Float.floatToRawIntBits(float)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 40 | result->SetI(args[0]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 41 | } else if (name == "float java.lang.Float.intBitsToFloat(int)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 42 | result->SetI(args[0]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 43 | } else if (name == "double java.lang.Math.exp(double)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 44 | JValue value; |
| 45 | value.SetJ((static_cast<uint64_t>(args[1]) << 32) | args[0]); |
| 46 | result->SetD(exp(value.GetD())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 47 | } else if (name == "java.lang.Object java.lang.Object.internalClone()") { |
| 48 | result->SetL(receiver->Clone(self)); |
| 49 | } else if (name == "void java.lang.Object.notifyAll()") { |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 50 | receiver->NotifyAll(self); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 51 | } else if (name == "int java.lang.String.compareTo(java.lang.String)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 52 | String* rhs = reinterpret_cast<Object*>(args[0])->AsString(); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 53 | CHECK(rhs != NULL); |
| 54 | result->SetI(receiver->AsString()->CompareTo(rhs)); |
| 55 | } else if (name == "java.lang.String java.lang.String.intern()") { |
| 56 | result->SetL(receiver->AsString()->Intern()); |
| 57 | } else if (name == "int java.lang.String.fastIndexOf(int, int)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 58 | result->SetI(receiver->AsString()->FastIndexOf(args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 59 | } else if (name == "java.lang.Object java.lang.reflect.Array.createMultiArray(java.lang.Class, int[])") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 60 | result->SetL(Array::CreateMultiArray(self, reinterpret_cast<Object*>(args[0])->AsClass(), reinterpret_cast<Object*>(args[1])->AsIntArray())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 61 | } else if (name == "java.lang.Object java.lang.Throwable.nativeFillInStackTrace()") { |
| 62 | ScopedObjectAccessUnchecked soa(self); |
| 63 | result->SetL(soa.Decode<Object*>(self->CreateInternalStackTrace(soa))); |
| 64 | } else if (name == "boolean java.nio.ByteOrder.isLittleEndian()") { |
| 65 | result->SetJ(JNI_TRUE); |
| 66 | } else if (name == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 67 | Object* obj = reinterpret_cast<Object*>(args[0]); |
| 68 | jlong offset = (static_cast<uint64_t>(args[2]) << 32) | args[1]; |
| 69 | jint expectedValue = args[3]; |
| 70 | jint newValue = args[4]; |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 71 | byte* raw_addr = reinterpret_cast<byte*>(obj) + offset; |
| 72 | volatile int32_t* address = reinterpret_cast<volatile int32_t*>(raw_addr); |
| 73 | // Note: android_atomic_release_cas() returns 0 on success, not failure. |
| 74 | int r = android_atomic_release_cas(expectedValue, newValue, address); |
| 75 | result->SetZ(r == 0); |
| 76 | } else if (name == "void sun.misc.Unsafe.putObject(java.lang.Object, long, java.lang.Object)") { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 77 | Object* obj = reinterpret_cast<Object*>(args[0]); |
| 78 | Object* newValue = reinterpret_cast<Object*>(args[3]); |
| 79 | obj->SetFieldObject(MemberOffset((static_cast<uint64_t>(args[2]) << 32) | args[1]), newValue, false); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 80 | } else { |
| 81 | LOG(FATAL) << "Attempt to invoke native method in non-started runtime: " << name; |
| 82 | } |
| 83 | } |
| 84 | |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 85 | static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty, |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 86 | Object* receiver, uint32_t* args, JValue* result) |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 87 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 88 | // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler, |
| 89 | // it should be removed and JNI compiled stubs used instead. |
| 90 | ScopedObjectAccessUnchecked soa(self); |
| 91 | if (method->IsStatic()) { |
| 92 | if (shorty == "L") { |
| 93 | typedef jobject (fnptr)(JNIEnv*, jclass); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 94 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 95 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 96 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 97 | jobject jresult; |
| 98 | { |
| 99 | ScopedThreadStateChange tsc(self, kNative); |
| 100 | jresult = fn(soa.Env(), klass.get()); |
| 101 | } |
| 102 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 103 | } else if (shorty == "V") { |
| 104 | typedef void (fnptr)(JNIEnv*, jclass); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 105 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 106 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 107 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 108 | ScopedThreadStateChange tsc(self, kNative); |
| 109 | fn(soa.Env(), klass.get()); |
| 110 | } else if (shorty == "Z") { |
| 111 | typedef jboolean (fnptr)(JNIEnv*, jclass); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 112 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 113 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 114 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 115 | ScopedThreadStateChange tsc(self, kNative); |
| 116 | result->SetZ(fn(soa.Env(), klass.get())); |
| 117 | } else if (shorty == "BI") { |
| 118 | typedef jbyte (fnptr)(JNIEnv*, jclass, jint); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 119 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 120 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 121 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 122 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 123 | result->SetB(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 124 | } else if (shorty == "II") { |
| 125 | typedef jint (fnptr)(JNIEnv*, jclass, jint); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 126 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 127 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 128 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 129 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 130 | result->SetI(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 131 | } else if (shorty == "LL") { |
| 132 | typedef jobject (fnptr)(JNIEnv*, jclass, jobject); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 133 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 134 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 135 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 136 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 137 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 138 | jobject jresult; |
| 139 | { |
| 140 | ScopedThreadStateChange tsc(self, kNative); |
| 141 | jresult = fn(soa.Env(), klass.get(), arg0.get()); |
| 142 | } |
| 143 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 144 | } else if (shorty == "IIZ") { |
| 145 | typedef jint (fnptr)(JNIEnv*, jclass, jint, jboolean); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 146 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 147 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 148 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 149 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 150 | result->SetI(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 151 | } else if (shorty == "ILI") { |
| 152 | typedef jint (fnptr)(JNIEnv*, jclass, jobject, jint); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 153 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 154 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 155 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 156 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 157 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 158 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 159 | result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 160 | } else if (shorty == "SIZ") { |
| 161 | typedef jshort (fnptr)(JNIEnv*, jclass, jint, jboolean); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 162 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 163 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 164 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 165 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 166 | result->SetS(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 167 | } else if (shorty == "VIZ") { |
| 168 | typedef void (fnptr)(JNIEnv*, jclass, jint, jboolean); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 169 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 170 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 171 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 172 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 173 | fn(soa.Env(), klass.get(), args[0], args[1]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 174 | } else if (shorty == "ZLL") { |
| 175 | typedef jboolean (fnptr)(JNIEnv*, jclass, jobject, jobject); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 176 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 177 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 178 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 179 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 180 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 181 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 182 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 183 | ScopedThreadStateChange tsc(self, kNative); |
| 184 | result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get())); |
| 185 | } else if (shorty == "ZILL") { |
| 186 | typedef jboolean (fnptr)(JNIEnv*, jclass, jint, jobject, jobject); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 187 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 188 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 189 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 190 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 191 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 192 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 193 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 194 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 195 | result->SetZ(fn(soa.Env(), klass.get(), args[0], arg1.get(), arg2.get())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 196 | } else if (shorty == "VILII") { |
| 197 | typedef void (fnptr)(JNIEnv*, jclass, jint, jobject, jint, jint); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 198 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 199 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 200 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 201 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 202 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 203 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 204 | fn(soa.Env(), klass.get(), args[0], arg1.get(), args[2], args[3]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 205 | } else if (shorty == "VLILII") { |
| 206 | typedef void (fnptr)(JNIEnv*, jclass, jobject, jint, jobject, jint, jint); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 207 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 208 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 209 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 210 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 211 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 212 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 213 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 214 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 215 | fn(soa.Env(), klass.get(), arg0.get(), args[1], arg2.get(), args[3], args[4]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 216 | } else { |
| 217 | LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method) |
| 218 | << " shorty: " << shorty; |
| 219 | } |
| 220 | } else { |
| 221 | if (shorty == "L") { |
| 222 | typedef jobject (fnptr)(JNIEnv*, jobject); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 223 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 224 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 225 | soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 226 | jobject jresult; |
| 227 | { |
| 228 | ScopedThreadStateChange tsc(self, kNative); |
| 229 | jresult = fn(soa.Env(), rcvr.get()); |
| 230 | } |
| 231 | result->SetL(soa.Decode<Object*>(jresult)); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 232 | } else if (shorty == "V") { |
| 233 | typedef void (fnptr)(JNIEnv*, jobject); |
| 234 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
| 235 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 236 | soa.AddLocalReference<jobject>(receiver)); |
| 237 | ScopedThreadStateChange tsc(self, kNative); |
| 238 | fn(soa.Env(), rcvr.get()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 239 | } else if (shorty == "LL") { |
| 240 | typedef jobject (fnptr)(JNIEnv*, jobject, jobject); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 241 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 242 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 243 | soa.AddLocalReference<jobject>(receiver)); |
| 244 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 245 | soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 246 | jobject jresult; |
| 247 | { |
| 248 | ScopedThreadStateChange tsc(self, kNative); |
| 249 | jresult = fn(soa.Env(), rcvr.get(), arg0.get()); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 250 | } |
| 251 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 252 | ScopedThreadStateChange tsc(self, kNative); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 253 | } else if (shorty == "III") { |
| 254 | typedef jint (fnptr)(JNIEnv*, jobject, jint, jint); |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 255 | const fnptr* fn = reinterpret_cast<const fnptr*>(method->GetNativeMethod()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 256 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 257 | soa.AddLocalReference<jobject>(receiver)); |
| 258 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 259 | result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 260 | } else { |
| 261 | LOG(FATAL) << "Do something with native method: " << PrettyMethod(method) |
| 262 | << " shorty: " << shorty; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 267 | enum InterpreterImplKind { |
| 268 | kSwitchImpl, // switch-based interpreter implementation. |
| 269 | kComputedGotoImplKind // computed-goto-based interpreter implementation. |
| 270 | }; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 271 | |
Sebastien Hertz | 2c88b38 | 2013-10-18 10:35:39 +0200 | [diff] [blame^] | 272 | static const InterpreterImplKind kInterpreterImplKind = kComputedGotoImplKind; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 273 | |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 274 | static JValue Execute(Thread* self, MethodHelper& mh, const DexFile::CodeItem* code_item, |
| 275 | ShadowFrame& shadow_frame, JValue result_register) |
| 276 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 277 | |
| 278 | static inline JValue Execute(Thread* self, MethodHelper& mh, const DexFile::CodeItem* code_item, |
| 279 | ShadowFrame& shadow_frame, JValue result_register) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 280 | DCHECK(shadow_frame.GetMethod() == mh.GetMethod() || |
| 281 | shadow_frame.GetMethod()->GetDeclaringClass()->IsProxyClass()); |
| 282 | DCHECK(!shadow_frame.GetMethod()->IsAbstract()); |
| 283 | DCHECK(!shadow_frame.GetMethod()->IsNative()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 284 | |
| 285 | if (LIKELY(shadow_frame.GetMethod()->IsPreverified())) { |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 286 | // Enter the "without access check" interpreter. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 287 | if (kInterpreterImplKind == kSwitchImpl) { |
| 288 | return ExecuteSwitchImpl<false>(self, mh, code_item, shadow_frame, result_register); |
| 289 | } else { |
| 290 | DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind); |
| 291 | return ExecuteGotoImpl<false>(self, mh, code_item, shadow_frame, result_register); |
| 292 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 293 | } else { |
| 294 | // Enter the "with access check" interpreter. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 295 | if (kInterpreterImplKind == kSwitchImpl) { |
| 296 | return ExecuteSwitchImpl<true>(self, mh, code_item, shadow_frame, result_register); |
| 297 | } else { |
| 298 | DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind); |
| 299 | return ExecuteGotoImpl<true>(self, mh, code_item, shadow_frame, result_register); |
| 300 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 304 | void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver, |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 305 | uint32_t* args, JValue* result) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 306 | DCHECK_EQ(self, Thread::Current()); |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 307 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEnd())) { |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 308 | ThrowStackOverflowError(self); |
| 309 | return; |
| 310 | } |
| 311 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 312 | const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke"); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 313 | MethodHelper mh(method); |
| 314 | const DexFile::CodeItem* code_item = mh.GetCodeItem(); |
| 315 | uint16_t num_regs; |
| 316 | uint16_t num_ins; |
| 317 | if (code_item != NULL) { |
| 318 | num_regs = code_item->registers_size_; |
| 319 | num_ins = code_item->ins_size_; |
jeffhao | 0a9bb73 | 2012-11-26 12:28:49 -0800 | [diff] [blame] | 320 | } else if (method->IsAbstract()) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 321 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 56adf60 | 2013-07-09 17:27:07 +0200 | [diff] [blame] | 322 | ThrowAbstractMethodError(method); |
jeffhao | 0a9bb73 | 2012-11-26 12:28:49 -0800 | [diff] [blame] | 323 | return; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 324 | } else { |
| 325 | DCHECK(method->IsNative()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 326 | num_regs = num_ins = ArtMethod::NumArgRegisters(mh.GetShorty()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 327 | if (!method->IsStatic()) { |
| 328 | num_regs++; |
| 329 | num_ins++; |
| 330 | } |
| 331 | } |
| 332 | // Set up shadow frame with matching number of reference slots to vregs. |
| 333 | ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame(); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 334 | void* memory = alloca(ShadowFrame::ComputeSize(num_regs)); |
| 335 | ShadowFrame* shadow_frame(ShadowFrame::Create(num_regs, last_shadow_frame, method, 0, memory)); |
| 336 | self->PushShadowFrame(shadow_frame); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 337 | self->EndAssertNoThreadSuspension(old_cause); |
| 338 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 339 | size_t cur_reg = num_regs - num_ins; |
| 340 | if (!method->IsStatic()) { |
| 341 | CHECK(receiver != NULL); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 342 | shadow_frame->SetVRegReference(cur_reg, receiver); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 343 | ++cur_reg; |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 344 | } else if (UNLIKELY(!method->GetDeclaringClass()->IsInitializing())) { |
| 345 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 346 | if (UNLIKELY(!class_linker->EnsureInitialized(method->GetDeclaringClass(), true, true))) { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 347 | CHECK(self->IsExceptionPending()); |
| 348 | self->PopShadowFrame(); |
jeffhao | 94d6df4 | 2012-11-26 16:02:12 -0800 | [diff] [blame] | 349 | return; |
| 350 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 351 | CHECK(method->GetDeclaringClass()->IsInitializing()); |
| 352 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 353 | const char* shorty = mh.GetShorty(); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 354 | for (size_t shorty_pos = 0, arg_pos = 0; cur_reg < num_regs; ++shorty_pos, ++arg_pos, cur_reg++) { |
| 355 | DCHECK_LT(shorty_pos + 1, mh.GetShortyLength()); |
| 356 | switch (shorty[shorty_pos + 1]) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 357 | case 'L': { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 358 | Object* o = reinterpret_cast<Object*>(args[arg_pos]); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 359 | shadow_frame->SetVRegReference(cur_reg, o); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 360 | break; |
| 361 | } |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 362 | case 'J': case 'D': { |
| 363 | uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos]; |
| 364 | shadow_frame->SetVRegLong(cur_reg, wide_value); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 365 | cur_reg++; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 366 | arg_pos++; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 367 | break; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 368 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 369 | default: |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 370 | shadow_frame->SetVReg(cur_reg, args[arg_pos]); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 374 | if (LIKELY(!method->IsNative())) { |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 375 | JValue r = Execute(self, mh, code_item, *shadow_frame, JValue()); |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 376 | if (result != NULL) { |
| 377 | *result = r; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 378 | } |
| 379 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 380 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 381 | // generated stub) except during testing and image writing. |
| 382 | if (!Runtime::Current()->IsStarted()) { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 383 | UnstartedRuntimeJni(self, method, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 384 | } else { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 385 | InterpreterJni(self, method, shorty, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | self->PopShadowFrame(); |
| 389 | } |
| 390 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 391 | void EnterInterpreterFromDeoptimize(Thread* self, ShadowFrame* shadow_frame, JValue* ret_val) |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 392 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 393 | JValue value; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 394 | value.SetJ(ret_val->GetJ()); // Set value to last known result in case the shadow frame chain is empty. |
| 395 | MethodHelper mh; |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 396 | while (shadow_frame != NULL) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 397 | self->SetTopOfShadowStack(shadow_frame); |
| 398 | mh.ChangeMethod(shadow_frame->GetMethod()); |
| 399 | const DexFile::CodeItem* code_item = mh.GetCodeItem(); |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 400 | value = Execute(self, mh, code_item, *shadow_frame, value); |
| 401 | ShadowFrame* old_frame = shadow_frame; |
| 402 | shadow_frame = shadow_frame->GetLink(); |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 403 | delete old_frame; |
| 404 | } |
| 405 | ret_val->SetJ(value.GetJ()); |
| 406 | } |
| 407 | |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 408 | JValue EnterInterpreterFromStub(Thread* self, MethodHelper& mh, const DexFile::CodeItem* code_item, |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 409 | ShadowFrame& shadow_frame) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 410 | DCHECK_EQ(self, Thread::Current()); |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 411 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEnd())) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 412 | ThrowStackOverflowError(self); |
| 413 | return JValue(); |
| 414 | } |
| 415 | |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 416 | return Execute(self, mh, code_item, shadow_frame, JValue()); |
| 417 | } |
| 418 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 419 | extern "C" void artInterpreterToInterpreterBridge(Thread* self, MethodHelper& mh, |
| 420 | const DexFile::CodeItem* code_item, |
| 421 | ShadowFrame* shadow_frame, JValue* result) { |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 422 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEnd())) { |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 423 | ThrowStackOverflowError(self); |
Jeff Hao | 6951067 | 2013-05-21 17:34:55 -0700 | [diff] [blame] | 424 | return; |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 427 | self->PushShadowFrame(shadow_frame); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 428 | ArtMethod* method = shadow_frame->GetMethod(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 429 | // Ensure static methods are initialized. |
| 430 | if (method->IsStatic()) { |
| 431 | Class* declaringClass = method->GetDeclaringClass(); |
| 432 | if (UNLIKELY(!declaringClass->IsInitializing())) { |
| 433 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(declaringClass, |
| 434 | true, true))) { |
| 435 | DCHECK(Thread::Current()->IsExceptionPending()); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 436 | self->PopShadowFrame(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | CHECK(declaringClass->IsInitializing()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 440 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 441 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 442 | |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 443 | if (LIKELY(!method->IsNative())) { |
Jeff Hao | 6951067 | 2013-05-21 17:34:55 -0700 | [diff] [blame] | 444 | result->SetJ(Execute(self, mh, code_item, *shadow_frame, JValue()).GetJ()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 445 | } else { |
| 446 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 447 | // generated stub) except during testing and image writing. |
| 448 | CHECK(!Runtime::Current()->IsStarted()); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 449 | Object* receiver = method->IsStatic() ? nullptr : shadow_frame->GetVRegReference(0); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 450 | uint32_t* args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1); |
Jeff Hao | 6951067 | 2013-05-21 17:34:55 -0700 | [diff] [blame] | 451 | UnstartedRuntimeJni(self, method, receiver, args, result); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | self->PopShadowFrame(); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 457 | } // namespace interpreter |
| 458 | } // namespace art |