blob: b17f3039c6bf7275fe9ebf3a1fae4f920344ac17 [file] [log] [blame]
Ian Rogers2fa6b2e2012-10-17 00:10:17 -07001/*
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 Hertz8ece0502013-08-07 11:26:41 +020017#include "interpreter_common.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070018
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010019#include <limits>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070021#include "mirror/string-inl.h"
22
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070023namespace art {
24namespace interpreter {
25
Ian Rogers64b6d142012-10-29 16:34:15 -070026// Hand select a number of methods to be run in a not yet started runtime without using JNI.
Brian Carlstromea46f952013-07-30 01:26:50 -070027static void UnstartedRuntimeJni(Thread* self, ArtMethod* method,
Jeff Hao5d917302013-02-27 17:57:33 -080028 Object* receiver, uint32_t* args, JValue* result)
Ian Rogers64b6d142012-10-29 16:34:15 -070029 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
30 std::string name(PrettyMethod(method));
Ian Rogersa4e74132014-05-06 01:14:54 -070031 if (name == "java.lang.Object dalvik.system.VMRuntime.newUnpaddedArray(java.lang.Class, int)") {
32 int32_t length = args[1];
33 DCHECK_GE(length, 0);
34 mirror::Class* element_class = reinterpret_cast<Object*>(args[0])->AsClass();
35 Runtime* runtime = Runtime::Current();
Mathieu Chartierb74cd292014-05-29 14:31:33 -070036 mirror::Class* array_class = runtime->GetClassLinker()->FindArrayClass(self, &element_class);
Ian Rogersa4e74132014-05-06 01:14:54 -070037 DCHECK(array_class != nullptr);
38 gc::AllocatorType allocator = runtime->GetHeap()->GetCurrentAllocator();
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -070039 result->SetL(mirror::Array::Alloc<true, true>(self, array_class, length,
40 array_class->GetComponentSizeShift(), allocator));
Ian Rogersa4e74132014-05-06 01:14:54 -070041 } else if (name == "java.lang.ClassLoader dalvik.system.VMStack.getCallingClassLoader()") {
Ian Rogers64b6d142012-10-29 16:34:15 -070042 result->SetL(NULL);
43 } else if (name == "java.lang.Class dalvik.system.VMStack.getStackClass2()") {
Ian Rogers7a22fa62013-01-23 12:16:16 -080044 NthCallerVisitor visitor(self, 3);
Ian Rogers64b6d142012-10-29 16:34:15 -070045 visitor.WalkStack();
46 result->SetL(visitor.caller->GetDeclaringClass());
47 } else if (name == "double java.lang.Math.log(double)") {
Jeff Hao5d917302013-02-27 17:57:33 -080048 JValue value;
49 value.SetJ((static_cast<uint64_t>(args[1]) << 32) | args[0]);
50 result->SetD(log(value.GetD()));
Ian Rogers64b6d142012-10-29 16:34:15 -070051 } else if (name == "java.lang.String java.lang.Class.getNameNative()") {
Mathieu Chartierf8322842014-05-16 10:59:25 -070052 StackHandleScope<1> hs(self);
53 result->SetL(mirror::Class::ComputeName(hs.NewHandle(receiver->AsClass())));
Ian Rogers64b6d142012-10-29 16:34:15 -070054 } else if (name == "int java.lang.Float.floatToRawIntBits(float)") {
Jeff Hao5d917302013-02-27 17:57:33 -080055 result->SetI(args[0]);
Ian Rogers64b6d142012-10-29 16:34:15 -070056 } else if (name == "float java.lang.Float.intBitsToFloat(int)") {
Jeff Hao5d917302013-02-27 17:57:33 -080057 result->SetI(args[0]);
Ian Rogers64b6d142012-10-29 16:34:15 -070058 } else if (name == "double java.lang.Math.exp(double)") {
Jeff Hao5d917302013-02-27 17:57:33 -080059 JValue value;
60 value.SetJ((static_cast<uint64_t>(args[1]) << 32) | args[0]);
61 result->SetD(exp(value.GetD()));
Ian Rogers64b6d142012-10-29 16:34:15 -070062 } else if (name == "java.lang.Object java.lang.Object.internalClone()") {
63 result->SetL(receiver->Clone(self));
64 } else if (name == "void java.lang.Object.notifyAll()") {
Ian Rogers05f30572013-02-20 12:13:11 -080065 receiver->NotifyAll(self);
Ian Rogers64b6d142012-10-29 16:34:15 -070066 } else if (name == "int java.lang.String.compareTo(java.lang.String)") {
Jeff Hao5d917302013-02-27 17:57:33 -080067 String* rhs = reinterpret_cast<Object*>(args[0])->AsString();
Ian Rogers64b6d142012-10-29 16:34:15 -070068 CHECK(rhs != NULL);
69 result->SetI(receiver->AsString()->CompareTo(rhs));
70 } else if (name == "java.lang.String java.lang.String.intern()") {
71 result->SetL(receiver->AsString()->Intern());
72 } else if (name == "int java.lang.String.fastIndexOf(int, int)") {
Jeff Hao5d917302013-02-27 17:57:33 -080073 result->SetI(receiver->AsString()->FastIndexOf(args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -070074 } else if (name == "java.lang.Object java.lang.reflect.Array.createMultiArray(java.lang.Class, int[])") {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070075 StackHandleScope<2> hs(self);
76 auto h_class(hs.NewHandle(reinterpret_cast<mirror::Class*>(args[0])->AsClass()));
77 auto h_dimensions(hs.NewHandle(reinterpret_cast<mirror::IntArray*>(args[1])->AsIntArray()));
78 result->SetL(Array::CreateMultiArray(self, h_class, h_dimensions));
Ian Rogers64b6d142012-10-29 16:34:15 -070079 } else if (name == "java.lang.Object java.lang.Throwable.nativeFillInStackTrace()") {
80 ScopedObjectAccessUnchecked soa(self);
Ian Rogers5d27faf2014-05-02 17:17:18 -070081 if (Runtime::Current()->IsActiveTransaction()) {
82 result->SetL(soa.Decode<Object*>(self->CreateInternalStackTrace<true>(soa)));
83 } else {
84 result->SetL(soa.Decode<Object*>(self->CreateInternalStackTrace<false>(soa)));
85 }
Sebastien Hertzf48644b2014-02-17 15:16:03 +010086 } else if (name == "int java.lang.System.identityHashCode(java.lang.Object)") {
87 mirror::Object* obj = reinterpret_cast<Object*>(args[0]);
88 result->SetI((obj != nullptr) ? obj->IdentityHashCode() : 0);
Ian Rogers64b6d142012-10-29 16:34:15 -070089 } else if (name == "boolean java.nio.ByteOrder.isLittleEndian()") {
Sebastien Hertzf48644b2014-02-17 15:16:03 +010090 result->SetZ(JNI_TRUE);
Ian Rogers64b6d142012-10-29 16:34:15 -070091 } else if (name == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") {
Jeff Hao5d917302013-02-27 17:57:33 -080092 Object* obj = reinterpret_cast<Object*>(args[0]);
93 jlong offset = (static_cast<uint64_t>(args[2]) << 32) | args[1];
94 jint expectedValue = args[3];
95 jint newValue = args[4];
Ian Rogers5d27faf2014-05-02 17:17:18 -070096 bool success;
97 if (Runtime::Current()->IsActiveTransaction()) {
Hans Boehmd8434432014-07-11 09:56:07 -070098 success = obj->CasFieldStrongSequentiallyConsistent32<true>(MemberOffset(offset),
99 expectedValue, newValue);
Ian Rogers5d27faf2014-05-02 17:17:18 -0700100 } else {
Hans Boehmd8434432014-07-11 09:56:07 -0700101 success = obj->CasFieldStrongSequentiallyConsistent32<false>(MemberOffset(offset),
102 expectedValue, newValue);
Ian Rogers5d27faf2014-05-02 17:17:18 -0700103 }
Sebastien Hertzf48644b2014-02-17 15:16:03 +0100104 result->SetZ(success ? JNI_TRUE : JNI_FALSE);
Ian Rogers64b6d142012-10-29 16:34:15 -0700105 } else if (name == "void sun.misc.Unsafe.putObject(java.lang.Object, long, java.lang.Object)") {
Jeff Hao5d917302013-02-27 17:57:33 -0800106 Object* obj = reinterpret_cast<Object*>(args[0]);
Sebastien Hertzf48644b2014-02-17 15:16:03 +0100107 jlong offset = (static_cast<uint64_t>(args[2]) << 32) | args[1];
Jeff Hao5d917302013-02-27 17:57:33 -0800108 Object* newValue = reinterpret_cast<Object*>(args[3]);
Ian Rogers5d27faf2014-05-02 17:17:18 -0700109 if (Runtime::Current()->IsActiveTransaction()) {
110 obj->SetFieldObject<true>(MemberOffset(offset), newValue);
111 } else {
112 obj->SetFieldObject<false>(MemberOffset(offset), newValue);
113 }
Hiroshi Yamauchi4d2efce2014-02-10 16:19:09 -0800114 } else if (name == "int sun.misc.Unsafe.getArrayBaseOffsetForComponentType(java.lang.Class)") {
115 mirror::Class* component = reinterpret_cast<Object*>(args[0])->AsClass();
116 Primitive::Type primitive_type = component->GetPrimitiveType();
117 result->SetI(mirror::Array::DataOffset(Primitive::ComponentSize(primitive_type)).Int32Value());
118 } else if (name == "int sun.misc.Unsafe.getArrayIndexScaleForComponentType(java.lang.Class)") {
119 mirror::Class* component = reinterpret_cast<Object*>(args[0])->AsClass();
120 Primitive::Type primitive_type = component->GetPrimitiveType();
121 result->SetI(Primitive::ComponentSize(primitive_type));
Ian Rogers5d27faf2014-05-02 17:17:18 -0700122 } else if (Runtime::Current()->IsActiveTransaction()) {
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700123 AbortTransaction(self, "Attempt to invoke native method in non-started runtime: %s",
124 name.c_str());
Ian Rogers5d27faf2014-05-02 17:17:18 -0700125
126 } else {
127 LOG(FATAL) << "Calling native method " << PrettyMethod(method) << " in an unstarted "
128 "non-transactional runtime";
Ian Rogers64b6d142012-10-29 16:34:15 -0700129 }
130}
131
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700132static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty,
Jeff Hao5d917302013-02-27 17:57:33 -0800133 Object* receiver, uint32_t* args, JValue* result)
Ian Rogers64b6d142012-10-29 16:34:15 -0700134 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
135 // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler,
136 // it should be removed and JNI compiled stubs used instead.
137 ScopedObjectAccessUnchecked soa(self);
138 if (method->IsStatic()) {
139 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100140 typedef jobject (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800141 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700142 ScopedLocalRef<jclass> klass(soa.Env(),
143 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
Ian Rogers556d6372012-11-20 12:19:36 -0800144 jobject jresult;
145 {
146 ScopedThreadStateChange tsc(self, kNative);
147 jresult = fn(soa.Env(), klass.get());
148 }
149 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -0700150 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100151 typedef void (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800152 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700153 ScopedLocalRef<jclass> klass(soa.Env(),
154 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
155 ScopedThreadStateChange tsc(self, kNative);
156 fn(soa.Env(), klass.get());
157 } else if (shorty == "Z") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100158 typedef jboolean (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800159 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700160 ScopedLocalRef<jclass> klass(soa.Env(),
161 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
162 ScopedThreadStateChange tsc(self, kNative);
163 result->SetZ(fn(soa.Env(), klass.get()));
164 } else if (shorty == "BI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100165 typedef jbyte (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800166 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700167 ScopedLocalRef<jclass> klass(soa.Env(),
168 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
169 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800170 result->SetB(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700171 } else if (shorty == "II") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100172 typedef jint (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800173 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700174 ScopedLocalRef<jclass> klass(soa.Env(),
175 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
176 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800177 result->SetI(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700178 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100179 typedef jobject (fntype)(JNIEnv*, jclass, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800180 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700181 ScopedLocalRef<jclass> klass(soa.Env(),
182 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
183 ScopedLocalRef<jobject> arg0(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800184 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -0800185 jobject jresult;
186 {
187 ScopedThreadStateChange tsc(self, kNative);
188 jresult = fn(soa.Env(), klass.get(), arg0.get());
189 }
190 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -0700191 } else if (shorty == "IIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100192 typedef jint (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800193 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700194 ScopedLocalRef<jclass> klass(soa.Env(),
195 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
196 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800197 result->SetI(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700198 } else if (shorty == "ILI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100199 typedef jint (fntype)(JNIEnv*, jclass, jobject, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800200 fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>(
201 method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700202 ScopedLocalRef<jclass> klass(soa.Env(),
203 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
204 ScopedLocalRef<jobject> arg0(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800205 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700206 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800207 result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700208 } else if (shorty == "SIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100209 typedef jshort (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800210 fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>(method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700211 ScopedLocalRef<jclass> klass(soa.Env(),
212 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
213 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800214 result->SetS(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700215 } else if (shorty == "VIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100216 typedef void (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800217 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700218 ScopedLocalRef<jclass> klass(soa.Env(),
219 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
220 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800221 fn(soa.Env(), klass.get(), args[0], args[1]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700222 } else if (shorty == "ZLL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100223 typedef jboolean (fntype)(JNIEnv*, jclass, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800224 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700225 ScopedLocalRef<jclass> klass(soa.Env(),
226 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
227 ScopedLocalRef<jobject> arg0(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800228 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700229 ScopedLocalRef<jobject> arg1(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800230 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700231 ScopedThreadStateChange tsc(self, kNative);
232 result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get()));
233 } else if (shorty == "ZILL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100234 typedef jboolean (fntype)(JNIEnv*, jclass, jint, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800235 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700236 ScopedLocalRef<jclass> klass(soa.Env(),
237 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
238 ScopedLocalRef<jobject> arg1(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800239 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700240 ScopedLocalRef<jobject> arg2(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800241 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700242 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800243 result->SetZ(fn(soa.Env(), klass.get(), args[0], arg1.get(), arg2.get()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700244 } else if (shorty == "VILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100245 typedef void (fntype)(JNIEnv*, jclass, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800246 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700247 ScopedLocalRef<jclass> klass(soa.Env(),
248 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
249 ScopedLocalRef<jobject> arg1(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800250 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700251 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800252 fn(soa.Env(), klass.get(), args[0], arg1.get(), args[2], args[3]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700253 } else if (shorty == "VLILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100254 typedef void (fntype)(JNIEnv*, jclass, jobject, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800255 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700256 ScopedLocalRef<jclass> klass(soa.Env(),
257 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
258 ScopedLocalRef<jobject> arg0(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800259 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700260 ScopedLocalRef<jobject> arg2(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800261 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700262 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800263 fn(soa.Env(), klass.get(), arg0.get(), args[1], arg2.get(), args[3], args[4]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700264 } else {
265 LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method)
266 << " shorty: " << shorty;
267 }
268 } else {
269 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100270 typedef jobject (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800271 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700272 ScopedLocalRef<jobject> rcvr(soa.Env(),
273 soa.AddLocalReference<jobject>(receiver));
Ian Rogers556d6372012-11-20 12:19:36 -0800274 jobject jresult;
275 {
276 ScopedThreadStateChange tsc(self, kNative);
277 jresult = fn(soa.Env(), rcvr.get());
278 }
279 result->SetL(soa.Decode<Object*>(jresult));
Jeff Hao3dd9f762013-07-08 13:09:25 -0700280 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100281 typedef void (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800282 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Jeff Hao3dd9f762013-07-08 13:09:25 -0700283 ScopedLocalRef<jobject> rcvr(soa.Env(),
284 soa.AddLocalReference<jobject>(receiver));
285 ScopedThreadStateChange tsc(self, kNative);
286 fn(soa.Env(), rcvr.get());
Ian Rogers64b6d142012-10-29 16:34:15 -0700287 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100288 typedef jobject (fntype)(JNIEnv*, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800289 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700290 ScopedLocalRef<jobject> rcvr(soa.Env(),
291 soa.AddLocalReference<jobject>(receiver));
292 ScopedLocalRef<jobject> arg0(soa.Env(),
Jeff Hao5d917302013-02-27 17:57:33 -0800293 soa.AddLocalReference<jobject>(reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -0800294 jobject jresult;
295 {
296 ScopedThreadStateChange tsc(self, kNative);
297 jresult = fn(soa.Env(), rcvr.get(), arg0.get());
Ian Rogers556d6372012-11-20 12:19:36 -0800298 }
299 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -0700300 ScopedThreadStateChange tsc(self, kNative);
Ian Rogers64b6d142012-10-29 16:34:15 -0700301 } else if (shorty == "III") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100302 typedef jint (fntype)(JNIEnv*, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800303 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700304 ScopedLocalRef<jobject> rcvr(soa.Env(),
305 soa.AddLocalReference<jobject>(receiver));
306 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800307 result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700308 } else {
309 LOG(FATAL) << "Do something with native method: " << PrettyMethod(method)
310 << " shorty: " << shorty;
311 }
312 }
313}
314
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200315enum InterpreterImplKind {
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800316 kSwitchImpl, // Switch-based interpreter implementation.
317 kComputedGotoImplKind // Computed-goto-based interpreter implementation.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200318};
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800319static std::ostream& operator<<(std::ostream& os, const InterpreterImplKind& rhs) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700320 os << ((rhs == kSwitchImpl) ? "Switch-based interpreter" : "Computed-goto-based interpreter");
321 return os;
322}
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700323
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200324#if !defined(__clang__)
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800325static constexpr InterpreterImplKind kInterpreterImplKind = kComputedGotoImplKind;
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200326#else
327// Clang 3.4 fails to build the goto interpreter implementation.
328static constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImpl;
329template<bool do_access_check, bool transaction_active>
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700330JValue ExecuteGotoImpl(Thread*, MethodHelper&, const DexFile::CodeItem*, ShadowFrame&, JValue) {
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200331 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -0700332 UNREACHABLE();
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200333}
334// Explicit definitions of ExecuteGotoImpl.
335template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
336JValue ExecuteGotoImpl<true, false>(Thread* self, MethodHelper& mh,
337 const DexFile::CodeItem* code_item,
338 ShadowFrame& shadow_frame, JValue result_register);
339template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
340JValue ExecuteGotoImpl<false, false>(Thread* self, MethodHelper& mh,
341 const DexFile::CodeItem* code_item,
342 ShadowFrame& shadow_frame, JValue result_register);
343template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
344JValue ExecuteGotoImpl<true, true>(Thread* self, MethodHelper& mh,
345 const DexFile::CodeItem* code_item,
346 ShadowFrame& shadow_frame, JValue result_register);
347template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
348JValue ExecuteGotoImpl<false, true>(Thread* self, MethodHelper& mh,
349 const DexFile::CodeItem* code_item,
350 ShadowFrame& shadow_frame, JValue result_register);
351#endif
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700352
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200353static JValue Execute(Thread* self, MethodHelper& mh, const DexFile::CodeItem* code_item,
354 ShadowFrame& shadow_frame, JValue result_register)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
356
357static inline JValue Execute(Thread* self, MethodHelper& mh, const DexFile::CodeItem* code_item,
358 ShadowFrame& shadow_frame, JValue result_register) {
Ian Rogers848871b2013-08-05 10:56:33 -0700359 DCHECK(shadow_frame.GetMethod() == mh.GetMethod() ||
360 shadow_frame.GetMethod()->GetDeclaringClass()->IsProxyClass());
361 DCHECK(!shadow_frame.GetMethod()->IsAbstract());
362 DCHECK(!shadow_frame.GetMethod()->IsNative());
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200363 shadow_frame.GetMethod()->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200364
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100365 bool transaction_active = Runtime::Current()->IsActiveTransaction();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200366 if (LIKELY(shadow_frame.GetMethod()->IsPreverified())) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200367 // Enter the "without access check" interpreter.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200368 if (kInterpreterImplKind == kSwitchImpl) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100369 if (transaction_active) {
370 return ExecuteSwitchImpl<false, true>(self, mh, code_item, shadow_frame, result_register);
371 } else {
372 return ExecuteSwitchImpl<false, false>(self, mh, code_item, shadow_frame, result_register);
373 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200374 } else {
375 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100376 if (transaction_active) {
377 return ExecuteGotoImpl<false, true>(self, mh, code_item, shadow_frame, result_register);
378 } else {
379 return ExecuteGotoImpl<false, false>(self, mh, code_item, shadow_frame, result_register);
380 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200381 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200382 } else {
383 // Enter the "with access check" interpreter.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200384 if (kInterpreterImplKind == kSwitchImpl) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100385 if (transaction_active) {
386 return ExecuteSwitchImpl<true, true>(self, mh, code_item, shadow_frame, result_register);
387 } else {
388 return ExecuteSwitchImpl<true, false>(self, mh, code_item, shadow_frame, result_register);
389 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200390 } else {
391 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100392 if (transaction_active) {
393 return ExecuteGotoImpl<true, true>(self, mh, code_item, shadow_frame, result_register);
394 } else {
395 return ExecuteGotoImpl<true, false>(self, mh, code_item, shadow_frame, result_register);
396 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200397 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200398 }
399}
400
Brian Carlstromea46f952013-07-30 01:26:50 -0700401void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver,
Jeff Hao6474d192013-03-26 14:08:09 -0700402 uint32_t* args, JValue* result) {
Ian Rogers64b6d142012-10-29 16:34:15 -0700403 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100404 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
405 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
jeffhaod7521322012-11-21 15:38:24 -0800406 ThrowStackOverflowError(self);
407 return;
408 }
409
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700410 const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke");
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700411 const DexFile::CodeItem* code_item = method->GetCodeItem();
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700412 uint16_t num_regs;
413 uint16_t num_ins;
414 if (code_item != NULL) {
415 num_regs = code_item->registers_size_;
416 num_ins = code_item->ins_size_;
jeffhao0a9bb732012-11-26 12:28:49 -0800417 } else if (method->IsAbstract()) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700418 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz56adf602013-07-09 17:27:07 +0200419 ThrowAbstractMethodError(method);
jeffhao0a9bb732012-11-26 12:28:49 -0800420 return;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700421 } else {
422 DCHECK(method->IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700423 num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty());
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700424 if (!method->IsStatic()) {
425 num_regs++;
426 num_ins++;
427 }
428 }
429 // Set up shadow frame with matching number of reference slots to vregs.
430 ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame();
Jeff Hao66135192013-05-14 11:02:41 -0700431 void* memory = alloca(ShadowFrame::ComputeSize(num_regs));
432 ShadowFrame* shadow_frame(ShadowFrame::Create(num_regs, last_shadow_frame, method, 0, memory));
433 self->PushShadowFrame(shadow_frame);
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700434
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700435 size_t cur_reg = num_regs - num_ins;
436 if (!method->IsStatic()) {
437 CHECK(receiver != NULL);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800438 shadow_frame->SetVRegReference(cur_reg, receiver);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700439 ++cur_reg;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700440 }
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700441 uint32_t shorty_len = 0;
442 const char* shorty = method->GetShorty(&shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800443 for (size_t shorty_pos = 0, arg_pos = 0; cur_reg < num_regs; ++shorty_pos, ++arg_pos, cur_reg++) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700444 DCHECK_LT(shorty_pos + 1, shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800445 switch (shorty[shorty_pos + 1]) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700446 case 'L': {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800447 Object* o = reinterpret_cast<StackReference<Object>*>(&args[arg_pos])->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800448 shadow_frame->SetVRegReference(cur_reg, o);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700449 break;
450 }
Jeff Hao5d917302013-02-27 17:57:33 -0800451 case 'J': case 'D': {
452 uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos];
453 shadow_frame->SetVRegLong(cur_reg, wide_value);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700454 cur_reg++;
Jeff Hao5d917302013-02-27 17:57:33 -0800455 arg_pos++;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700456 break;
Jeff Hao5d917302013-02-27 17:57:33 -0800457 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700458 default:
Jeff Hao5d917302013-02-27 17:57:33 -0800459 shadow_frame->SetVReg(cur_reg, args[arg_pos]);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700460 break;
461 }
462 }
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800463 self->EndAssertNoThreadSuspension(old_cause);
464 // Do this after populating the shadow frame in case EnsureInitialized causes a GC.
Ian Rogers6c5cb212014-06-18 16:07:20 -0700465 if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800466 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700467 StackHandleScope<1> hs(self);
468 Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass()));
Ian Rogers7b078e82014-09-10 14:44:24 -0700469 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800470 CHECK(self->IsExceptionPending());
471 self->PopShadowFrame();
472 return;
473 }
474 }
Ian Rogers64b6d142012-10-29 16:34:15 -0700475 if (LIKELY(!method->IsNative())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700476 StackHandleScope<1> hs(self);
477 MethodHelper mh(hs.NewHandle(method));
Jeff Hao66135192013-05-14 11:02:41 -0700478 JValue r = Execute(self, mh, code_item, *shadow_frame, JValue());
Jeff Hao6474d192013-03-26 14:08:09 -0700479 if (result != NULL) {
480 *result = r;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700481 }
482 } else {
Ian Rogers64b6d142012-10-29 16:34:15 -0700483 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
484 // generated stub) except during testing and image writing.
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800485 // Update args to be the args in the shadow frame since the input ones could hold stale
486 // references pointers due to moving GC.
487 args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1);
Ian Rogers64b6d142012-10-29 16:34:15 -0700488 if (!Runtime::Current()->IsStarted()) {
Jeff Hao6474d192013-03-26 14:08:09 -0700489 UnstartedRuntimeJni(self, method, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700490 } else {
Jeff Hao6474d192013-03-26 14:08:09 -0700491 InterpreterJni(self, method, shorty, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700492 }
493 }
494 self->PopShadowFrame();
495}
496
Ian Rogers62d6c772013-02-27 08:32:07 -0800497void EnterInterpreterFromDeoptimize(Thread* self, ShadowFrame* shadow_frame, JValue* ret_val)
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
499 JValue value;
Ian Rogers62d6c772013-02-27 08:32:07 -0800500 value.SetJ(ret_val->GetJ()); // Set value to last known result in case the shadow frame chain is empty.
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800501 while (shadow_frame != NULL) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800502 self->SetTopOfShadowStack(shadow_frame);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700503 StackHandleScope<1> hs(self);
504 MethodHelper mh(hs.NewHandle(shadow_frame->GetMethod()));
505 const DexFile::CodeItem* code_item = mh.GetMethod()->GetCodeItem();
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800506 value = Execute(self, mh, code_item, *shadow_frame, value);
507 ShadowFrame* old_frame = shadow_frame;
508 shadow_frame = shadow_frame->GetLink();
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800509 delete old_frame;
510 }
511 ret_val->SetJ(value.GetJ());
512}
513
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700514JValue EnterInterpreterFromEntryPoint(Thread* self, MethodHelper* mh,
515 const DexFile::CodeItem* code_item,
516 ShadowFrame* shadow_frame) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700517 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100518 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
519 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700520 ThrowStackOverflowError(self);
521 return JValue();
522 }
523
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700524 return Execute(self, *mh, code_item, *shadow_frame, JValue());
Ian Rogers7db619b2013-01-16 18:35:48 -0800525}
526
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700527extern "C" void artInterpreterToInterpreterBridge(Thread* self, MethodHelper* mh,
Ian Rogers848871b2013-08-05 10:56:33 -0700528 const DexFile::CodeItem* code_item,
529 ShadowFrame* shadow_frame, JValue* result) {
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100530 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
531 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Jeff Hao16743632013-05-08 10:59:04 -0700532 ThrowStackOverflowError(self);
Jeff Hao69510672013-05-21 17:34:55 -0700533 return;
Jeff Hao16743632013-05-08 10:59:04 -0700534 }
535
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700536 self->PushShadowFrame(shadow_frame);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700537 DCHECK_EQ(shadow_frame->GetMethod(), mh->Get());
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200538 // Ensure static methods are initialized.
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700539 if (mh->Get()->IsStatic()) {
540 mirror::Class* declaring_class = mh->Get()->GetDeclaringClass();
Ian Rogers6c5cb212014-06-18 16:07:20 -0700541 if (UNLIKELY(!declaring_class->IsInitialized())) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700542 StackHandleScope<1> hs(self);
543 HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class));
544 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
Ian Rogers7b078e82014-09-10 14:44:24 -0700545 self, h_declaring_class, true, true))) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700546 DCHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700547 self->PopShadowFrame();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200548 return;
549 }
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700550 CHECK(h_declaring_class->IsInitializing());
Jeff Hao16743632013-05-08 10:59:04 -0700551 }
Jeff Hao16743632013-05-08 10:59:04 -0700552 }
Jeff Hao16743632013-05-08 10:59:04 -0700553
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700554 if (LIKELY(!mh->Get()->IsNative())) {
555 result->SetJ(Execute(self, *mh, code_item, *shadow_frame, JValue()).GetJ());
Jeff Hao16743632013-05-08 10:59:04 -0700556 } else {
557 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
558 // generated stub) except during testing and image writing.
559 CHECK(!Runtime::Current()->IsStarted());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700560 Object* receiver = mh->Get()->IsStatic() ? nullptr : shadow_frame->GetVRegReference(0);
561 uint32_t* args = shadow_frame->GetVRegArgs(mh->Get()->IsStatic() ? 0 : 1);
562 UnstartedRuntimeJni(self, mh->Get(), receiver, args, result);
Jeff Hao16743632013-05-08 10:59:04 -0700563 }
564
565 self->PopShadowFrame();
Jeff Hao16743632013-05-08 10:59:04 -0700566}
567
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700568} // namespace interpreter
569} // namespace art