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