blob: 9d988e978d0dce92423e93e9521ceec2d856f22f [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 Rogerse94652f2014-12-02 11:13:19 -0800330JValue ExecuteGotoImpl(Thread*, 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_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800336JValue ExecuteGotoImpl<true, false>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200337 ShadowFrame& shadow_frame, JValue result_register);
338template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800339JValue ExecuteGotoImpl<false, false>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200340 ShadowFrame& shadow_frame, JValue result_register);
341template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800342JValue ExecuteGotoImpl<true, true>(Thread* self, const DexFile::CodeItem* code_item,
343 ShadowFrame& shadow_frame, JValue result_register);
344template<> SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
345JValue ExecuteGotoImpl<false, true>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200346 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200347#endif
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700348
Ian Rogerse94652f2014-12-02 11:13:19 -0800349static JValue Execute(Thread* self, const DexFile::CodeItem* code_item, ShadowFrame& shadow_frame,
350 JValue result_register)
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
352
Ian Rogerse94652f2014-12-02 11:13:19 -0800353static inline JValue Execute(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200354 ShadowFrame& shadow_frame, JValue result_register) {
Ian Rogers848871b2013-08-05 10:56:33 -0700355 DCHECK(!shadow_frame.GetMethod()->IsAbstract());
356 DCHECK(!shadow_frame.GetMethod()->IsNative());
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200357 shadow_frame.GetMethod()->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200358
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100359 bool transaction_active = Runtime::Current()->IsActiveTransaction();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200360 if (LIKELY(shadow_frame.GetMethod()->IsPreverified())) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200361 // Enter the "without access check" interpreter.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200362 if (kInterpreterImplKind == kSwitchImpl) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100363 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800364 return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100365 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800366 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100367 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200368 } else {
369 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100370 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800371 return ExecuteGotoImpl<false, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100372 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800373 return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100374 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200375 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200376 } else {
377 // Enter the "with access check" interpreter.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200378 if (kInterpreterImplKind == kSwitchImpl) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100379 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800380 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100381 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800382 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100383 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200384 } else {
385 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100386 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800387 return ExecuteGotoImpl<true, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100388 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800389 return ExecuteGotoImpl<true, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100390 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200391 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200392 }
393}
394
Brian Carlstromea46f952013-07-30 01:26:50 -0700395void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver,
Jeff Hao6474d192013-03-26 14:08:09 -0700396 uint32_t* args, JValue* result) {
Ian Rogers64b6d142012-10-29 16:34:15 -0700397 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100398 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
399 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
jeffhaod7521322012-11-21 15:38:24 -0800400 ThrowStackOverflowError(self);
401 return;
402 }
403
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700404 const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke");
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700405 const DexFile::CodeItem* code_item = method->GetCodeItem();
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700406 uint16_t num_regs;
407 uint16_t num_ins;
408 if (code_item != NULL) {
409 num_regs = code_item->registers_size_;
410 num_ins = code_item->ins_size_;
jeffhao0a9bb732012-11-26 12:28:49 -0800411 } else if (method->IsAbstract()) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700412 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz56adf602013-07-09 17:27:07 +0200413 ThrowAbstractMethodError(method);
jeffhao0a9bb732012-11-26 12:28:49 -0800414 return;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700415 } else {
416 DCHECK(method->IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700417 num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty());
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700418 if (!method->IsStatic()) {
419 num_regs++;
420 num_ins++;
421 }
422 }
423 // Set up shadow frame with matching number of reference slots to vregs.
424 ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame();
Jeff Hao66135192013-05-14 11:02:41 -0700425 void* memory = alloca(ShadowFrame::ComputeSize(num_regs));
426 ShadowFrame* shadow_frame(ShadowFrame::Create(num_regs, last_shadow_frame, method, 0, memory));
427 self->PushShadowFrame(shadow_frame);
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700428
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700429 size_t cur_reg = num_regs - num_ins;
430 if (!method->IsStatic()) {
431 CHECK(receiver != NULL);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800432 shadow_frame->SetVRegReference(cur_reg, receiver);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700433 ++cur_reg;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700434 }
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700435 uint32_t shorty_len = 0;
436 const char* shorty = method->GetShorty(&shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800437 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 -0700438 DCHECK_LT(shorty_pos + 1, shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800439 switch (shorty[shorty_pos + 1]) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700440 case 'L': {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800441 Object* o = reinterpret_cast<StackReference<Object>*>(&args[arg_pos])->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800442 shadow_frame->SetVRegReference(cur_reg, o);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700443 break;
444 }
Jeff Hao5d917302013-02-27 17:57:33 -0800445 case 'J': case 'D': {
446 uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos];
447 shadow_frame->SetVRegLong(cur_reg, wide_value);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700448 cur_reg++;
Jeff Hao5d917302013-02-27 17:57:33 -0800449 arg_pos++;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700450 break;
Jeff Hao5d917302013-02-27 17:57:33 -0800451 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700452 default:
Jeff Hao5d917302013-02-27 17:57:33 -0800453 shadow_frame->SetVReg(cur_reg, args[arg_pos]);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700454 break;
455 }
456 }
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800457 self->EndAssertNoThreadSuspension(old_cause);
458 // Do this after populating the shadow frame in case EnsureInitialized causes a GC.
Ian Rogers6c5cb212014-06-18 16:07:20 -0700459 if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800460 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700461 StackHandleScope<1> hs(self);
462 Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass()));
Ian Rogers7b078e82014-09-10 14:44:24 -0700463 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800464 CHECK(self->IsExceptionPending());
465 self->PopShadowFrame();
466 return;
467 }
468 }
Ian Rogers64b6d142012-10-29 16:34:15 -0700469 if (LIKELY(!method->IsNative())) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800470 JValue r = Execute(self, code_item, *shadow_frame, JValue());
Jeff Hao6474d192013-03-26 14:08:09 -0700471 if (result != NULL) {
472 *result = r;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700473 }
474 } else {
Ian Rogers64b6d142012-10-29 16:34:15 -0700475 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
476 // generated stub) except during testing and image writing.
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800477 // Update args to be the args in the shadow frame since the input ones could hold stale
478 // references pointers due to moving GC.
479 args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1);
Ian Rogers64b6d142012-10-29 16:34:15 -0700480 if (!Runtime::Current()->IsStarted()) {
Jeff Hao6474d192013-03-26 14:08:09 -0700481 UnstartedRuntimeJni(self, method, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700482 } else {
Jeff Hao6474d192013-03-26 14:08:09 -0700483 InterpreterJni(self, method, shorty, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700484 }
485 }
486 self->PopShadowFrame();
487}
488
Ian Rogers62d6c772013-02-27 08:32:07 -0800489void EnterInterpreterFromDeoptimize(Thread* self, ShadowFrame* shadow_frame, JValue* ret_val)
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
491 JValue value;
Ian Rogers62d6c772013-02-27 08:32:07 -0800492 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 -0800493 while (shadow_frame != NULL) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800494 self->SetTopOfShadowStack(shadow_frame);
Ian Rogerse94652f2014-12-02 11:13:19 -0800495 const DexFile::CodeItem* code_item = shadow_frame->GetMethod()->GetCodeItem();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100496 const uint32_t dex_pc = shadow_frame->GetDexPC();
497 uint32_t new_dex_pc;
498 if (UNLIKELY(self->IsExceptionPending())) {
499 const instrumentation::Instrumentation* const instrumentation =
500 Runtime::Current()->GetInstrumentation();
501 uint32_t found_dex_pc = FindNextInstructionFollowingException(self, *shadow_frame, dex_pc,
502 instrumentation);
503 new_dex_pc = found_dex_pc; // the dex pc of a matching catch handler
504 // or DexFile::kDexNoIndex if there is none.
505 } else {
506 const Instruction* instr = Instruction::At(&code_item->insns_[dex_pc]);
507 new_dex_pc = dex_pc + instr->SizeInCodeUnits(); // the dex pc of the next instruction.
508 }
509 if (new_dex_pc != DexFile::kDexNoIndex) {
510 shadow_frame->SetDexPC(new_dex_pc);
511 value = Execute(self, code_item, *shadow_frame, value);
512 }
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800513 ShadowFrame* old_frame = shadow_frame;
514 shadow_frame = shadow_frame->GetLink();
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800515 delete old_frame;
516 }
517 ret_val->SetJ(value.GetJ());
518}
519
Ian Rogerse94652f2014-12-02 11:13:19 -0800520JValue EnterInterpreterFromEntryPoint(Thread* self, const DexFile::CodeItem* code_item,
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700521 ShadowFrame* shadow_frame) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700522 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100523 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
524 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700525 ThrowStackOverflowError(self);
526 return JValue();
527 }
528
Ian Rogerse94652f2014-12-02 11:13:19 -0800529 return Execute(self, code_item, *shadow_frame, JValue());
Ian Rogers7db619b2013-01-16 18:35:48 -0800530}
531
Ian Rogerse94652f2014-12-02 11:13:19 -0800532extern "C" void artInterpreterToInterpreterBridge(Thread* self, const DexFile::CodeItem* code_item,
Ian Rogers848871b2013-08-05 10:56:33 -0700533 ShadowFrame* shadow_frame, JValue* result) {
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100534 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
535 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Jeff Hao16743632013-05-08 10:59:04 -0700536 ThrowStackOverflowError(self);
Jeff Hao69510672013-05-21 17:34:55 -0700537 return;
Jeff Hao16743632013-05-08 10:59:04 -0700538 }
539
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700540 self->PushShadowFrame(shadow_frame);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200541 // Ensure static methods are initialized.
Ian Rogerse94652f2014-12-02 11:13:19 -0800542 const bool is_static = shadow_frame->GetMethod()->IsStatic();
543 if (is_static) {
544 mirror::Class* declaring_class = shadow_frame->GetMethod()->GetDeclaringClass();
Ian Rogers6c5cb212014-06-18 16:07:20 -0700545 if (UNLIKELY(!declaring_class->IsInitialized())) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700546 StackHandleScope<1> hs(self);
547 HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class));
548 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
Ian Rogers7b078e82014-09-10 14:44:24 -0700549 self, h_declaring_class, true, true))) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700550 DCHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700551 self->PopShadowFrame();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200552 return;
553 }
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700554 CHECK(h_declaring_class->IsInitializing());
Jeff Hao16743632013-05-08 10:59:04 -0700555 }
Jeff Hao16743632013-05-08 10:59:04 -0700556 }
Jeff Hao16743632013-05-08 10:59:04 -0700557
Ian Rogerse94652f2014-12-02 11:13:19 -0800558 if (LIKELY(!shadow_frame->GetMethod()->IsNative())) {
559 result->SetJ(Execute(self, code_item, *shadow_frame, JValue()).GetJ());
Jeff Hao16743632013-05-08 10:59:04 -0700560 } else {
561 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
562 // generated stub) except during testing and image writing.
563 CHECK(!Runtime::Current()->IsStarted());
Ian Rogerse94652f2014-12-02 11:13:19 -0800564 Object* receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0);
565 uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1);
566 UnstartedRuntimeJni(self, shadow_frame->GetMethod(), receiver, args, result);
Jeff Hao16743632013-05-08 10:59:04 -0700567 }
568
569 self->PopShadowFrame();
Jeff Hao16743632013-05-08 10:59:04 -0700570}
571
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700572} // namespace interpreter
573} // namespace art