blob: 0003e7242844719667c154c13174cd19a5c25cde [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
Andreas Gampe3cfa4d02015-10-06 17:04:01 -070017#include "interpreter.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
Andreas Gampe103992b2016-01-04 15:32:43 -080021#include "common_throws.h"
Andreas Gampe3cfa4d02015-10-06 17:04:01 -070022#include "interpreter_common.h"
Andreas Gampe5e26eb12016-08-22 17:54:17 -070023#include "interpreter_mterp_impl.h"
24#include "interpreter_switch_impl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070025#include "mirror/string-inl.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070026#include "scoped_thread_state_change.h"
27#include "ScopedLocalRef.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070028#include "stack.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070029#include "unstarted_runtime.h"
buzbee1452bee2015-03-06 14:43:04 -080030#include "mterp/mterp.h"
buzbee734f3aa2016-01-28 14:20:06 -080031#include "jit/jit.h"
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +000032#include "jit/jit_code_cache.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070033
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070034namespace art {
35namespace interpreter {
36
Ian Rogersfc0e94b2013-09-23 23:51:32 -070037static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty,
Jeff Hao5d917302013-02-27 17:57:33 -080038 Object* receiver, uint32_t* args, JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070039 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers64b6d142012-10-29 16:34:15 -070040 // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler,
41 // it should be removed and JNI compiled stubs used instead.
42 ScopedObjectAccessUnchecked soa(self);
43 if (method->IsStatic()) {
44 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010045 typedef jobject (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080046 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070047 ScopedLocalRef<jclass> klass(soa.Env(),
48 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
Ian Rogers556d6372012-11-20 12:19:36 -080049 jobject jresult;
50 {
51 ScopedThreadStateChange tsc(self, kNative);
52 jresult = fn(soa.Env(), klass.get());
53 }
54 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -070055 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010056 typedef void (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080057 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070058 ScopedLocalRef<jclass> klass(soa.Env(),
59 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
60 ScopedThreadStateChange tsc(self, kNative);
61 fn(soa.Env(), klass.get());
62 } else if (shorty == "Z") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010063 typedef jboolean (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080064 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070065 ScopedLocalRef<jclass> klass(soa.Env(),
66 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
67 ScopedThreadStateChange tsc(self, kNative);
68 result->SetZ(fn(soa.Env(), klass.get()));
69 } else if (shorty == "BI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010070 typedef jbyte (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -080071 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070072 ScopedLocalRef<jclass> klass(soa.Env(),
73 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
74 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -080075 result->SetB(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -070076 } else if (shorty == "II") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010077 typedef jint (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -080078 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070079 ScopedLocalRef<jclass> klass(soa.Env(),
80 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
81 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -080082 result->SetI(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -070083 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010084 typedef jobject (fntype)(JNIEnv*, jclass, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -080085 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070086 ScopedLocalRef<jclass> klass(soa.Env(),
87 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
88 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -070089 soa.AddLocalReference<jobject>(
90 reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -080091 jobject jresult;
92 {
93 ScopedThreadStateChange tsc(self, kNative);
94 jresult = fn(soa.Env(), klass.get(), arg0.get());
95 }
96 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -070097 } else if (shorty == "IIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010098 typedef jint (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -080099 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700100 ScopedLocalRef<jclass> klass(soa.Env(),
101 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
102 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800103 result->SetI(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700104 } else if (shorty == "ILI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100105 typedef jint (fntype)(JNIEnv*, jclass, jobject, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800106 fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>(
107 method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700108 ScopedLocalRef<jclass> klass(soa.Env(),
109 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
110 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700111 soa.AddLocalReference<jobject>(
112 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700113 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800114 result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700115 } else if (shorty == "SIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100116 typedef jshort (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700117 fntype* const fn =
118 reinterpret_cast<fntype*>(const_cast<void*>(method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700119 ScopedLocalRef<jclass> klass(soa.Env(),
120 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
121 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800122 result->SetS(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700123 } else if (shorty == "VIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100124 typedef void (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800125 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700126 ScopedLocalRef<jclass> klass(soa.Env(),
127 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
128 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800129 fn(soa.Env(), klass.get(), args[0], args[1]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700130 } else if (shorty == "ZLL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100131 typedef jboolean (fntype)(JNIEnv*, jclass, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800132 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700133 ScopedLocalRef<jclass> klass(soa.Env(),
134 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
135 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700136 soa.AddLocalReference<jobject>(
137 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700138 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700139 soa.AddLocalReference<jobject>(
140 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700141 ScopedThreadStateChange tsc(self, kNative);
142 result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get()));
143 } else if (shorty == "ZILL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100144 typedef jboolean (fntype)(JNIEnv*, jclass, jint, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800145 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700146 ScopedLocalRef<jclass> klass(soa.Env(),
147 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
148 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700149 soa.AddLocalReference<jobject>(
150 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700151 ScopedLocalRef<jobject> arg2(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700152 soa.AddLocalReference<jobject>(
153 reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700154 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800155 result->SetZ(fn(soa.Env(), klass.get(), args[0], arg1.get(), arg2.get()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700156 } else if (shorty == "VILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100157 typedef void (fntype)(JNIEnv*, jclass, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800158 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700159 ScopedLocalRef<jclass> klass(soa.Env(),
160 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
161 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700162 soa.AddLocalReference<jobject>(
163 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700164 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800165 fn(soa.Env(), klass.get(), args[0], arg1.get(), args[2], args[3]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700166 } else if (shorty == "VLILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100167 typedef void (fntype)(JNIEnv*, jclass, jobject, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800168 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700169 ScopedLocalRef<jclass> klass(soa.Env(),
170 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
171 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700172 soa.AddLocalReference<jobject>(
173 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700174 ScopedLocalRef<jobject> arg2(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700175 soa.AddLocalReference<jobject>(
176 reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700177 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800178 fn(soa.Env(), klass.get(), arg0.get(), args[1], arg2.get(), args[3], args[4]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700179 } else {
180 LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method)
181 << " shorty: " << shorty;
182 }
183 } else {
184 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100185 typedef jobject (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800186 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700187 ScopedLocalRef<jobject> rcvr(soa.Env(),
188 soa.AddLocalReference<jobject>(receiver));
Ian Rogers556d6372012-11-20 12:19:36 -0800189 jobject jresult;
190 {
191 ScopedThreadStateChange tsc(self, kNative);
192 jresult = fn(soa.Env(), rcvr.get());
193 }
194 result->SetL(soa.Decode<Object*>(jresult));
Jeff Hao3dd9f762013-07-08 13:09:25 -0700195 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100196 typedef void (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800197 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Jeff Hao3dd9f762013-07-08 13:09:25 -0700198 ScopedLocalRef<jobject> rcvr(soa.Env(),
199 soa.AddLocalReference<jobject>(receiver));
200 ScopedThreadStateChange tsc(self, kNative);
201 fn(soa.Env(), rcvr.get());
Ian Rogers64b6d142012-10-29 16:34:15 -0700202 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100203 typedef jobject (fntype)(JNIEnv*, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800204 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700205 ScopedLocalRef<jobject> rcvr(soa.Env(),
206 soa.AddLocalReference<jobject>(receiver));
207 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700208 soa.AddLocalReference<jobject>(
209 reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -0800210 jobject jresult;
211 {
212 ScopedThreadStateChange tsc(self, kNative);
213 jresult = fn(soa.Env(), rcvr.get(), arg0.get());
Ian Rogers556d6372012-11-20 12:19:36 -0800214 }
215 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -0700216 ScopedThreadStateChange tsc(self, kNative);
Ian Rogers64b6d142012-10-29 16:34:15 -0700217 } else if (shorty == "III") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100218 typedef jint (fntype)(JNIEnv*, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800219 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700220 ScopedLocalRef<jobject> rcvr(soa.Env(),
221 soa.AddLocalReference<jobject>(receiver));
222 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800223 result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700224 } else {
225 LOG(FATAL) << "Do something with native method: " << PrettyMethod(method)
226 << " shorty: " << shorty;
227 }
228 }
229}
230
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200231enum InterpreterImplKind {
buzbee1452bee2015-03-06 14:43:04 -0800232 kSwitchImplKind, // Switch-based interpreter implementation.
buzbee1452bee2015-03-06 14:43:04 -0800233 kMterpImplKind // Assembly interpreter
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200234};
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800235static std::ostream& operator<<(std::ostream& os, const InterpreterImplKind& rhs) {
buzbee1452bee2015-03-06 14:43:04 -0800236 os << ((rhs == kSwitchImplKind)
237 ? "Switch-based interpreter"
buzbeef61df9b2016-09-07 07:12:29 -0700238 : "Asm interpreter");
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700239 return os;
240}
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700241
buzbee1452bee2015-03-06 14:43:04 -0800242static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
Alexey Frunze00b53b72016-02-02 20:25:45 -0800243
Aart Bik01223202016-05-05 15:10:42 -0700244static inline JValue Execute(
245 Thread* self,
246 const DexFile::CodeItem* code_item,
247 ShadowFrame& shadow_frame,
248 JValue result_register,
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700249 bool stay_in_interpreter = false) REQUIRES_SHARED(Locks::mutator_lock_) {
buzbee1452bee2015-03-06 14:43:04 -0800250 DCHECK(!shadow_frame.GetMethod()->IsAbstract());
Ian Rogers848871b2013-08-05 10:56:33 -0700251 DCHECK(!shadow_frame.GetMethod()->IsNative());
buzbee734f3aa2016-01-28 14:20:06 -0800252 if (LIKELY(shadow_frame.GetDexPC() == 0)) { // Entering the method, but not via deoptimization.
253 if (kIsDebugBuild) {
254 self->AssertNoPendingException();
255 }
256 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
257 ArtMethod *method = shadow_frame.GetMethod();
258
259 if (UNLIKELY(instrumentation->HasMethodEntryListeners())) {
260 instrumentation->MethodEnterEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
261 method, 0);
262 }
263
Aart Bik01223202016-05-05 15:10:42 -0700264 if (!stay_in_interpreter) {
265 jit::Jit* jit = Runtime::Current()->GetJit();
266 if (jit != nullptr) {
267 jit->MethodEntered(self, shadow_frame.GetMethod());
268 if (jit->CanInvokeCompiledCode(method)) {
269 JValue result;
buzbee734f3aa2016-01-28 14:20:06 -0800270
Aart Bik01223202016-05-05 15:10:42 -0700271 // Pop the shadow frame before calling into compiled code.
272 self->PopShadowFrame();
273 ArtInterpreterToCompiledCodeBridge(self, nullptr, code_item, &shadow_frame, &result);
274 // Push the shadow frame back as the caller will expect it.
275 self->PushShadowFrame(&shadow_frame);
buzbee734f3aa2016-01-28 14:20:06 -0800276
Aart Bik01223202016-05-05 15:10:42 -0700277 return result;
278 }
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100279 }
buzbee734f3aa2016-01-28 14:20:06 -0800280 }
281 }
282
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200283 shadow_frame.GetMethod()->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200284
Andreas Gampe56fdd0e2016-04-28 14:56:54 -0700285 // Lock counting is a special version of accessibility checks, and for simplicity and
286 // reduction of template parameters, we gate it behind access-checks mode.
287 ArtMethod* method = shadow_frame.GetMethod();
288 DCHECK(!method->SkipAccessChecks() || !method->MustCountLocks());
289
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100290 bool transaction_active = Runtime::Current()->IsActiveTransaction();
Andreas Gampe56fdd0e2016-04-28 14:56:54 -0700291 if (LIKELY(method->SkipAccessChecks())) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200292 // Enter the "without access check" interpreter.
buzbee1452bee2015-03-06 14:43:04 -0800293 if (kInterpreterImplKind == kMterpImplKind) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100294 if (transaction_active) {
buzbee1452bee2015-03-06 14:43:04 -0800295 // No Mterp variant - just use the switch interpreter.
296 return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register,
297 false);
Bill Buzbeefd522f92016-02-11 22:37:42 +0000298 } else if (UNLIKELY(!Runtime::Current()->IsStarted())) {
299 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
300 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100301 } else {
buzbee1452bee2015-03-06 14:43:04 -0800302 while (true) {
Bill Buzbeefd522f92016-02-11 22:37:42 +0000303 // Mterp does not support all instrumentation/debugging.
Andreas Gampe67409972016-07-19 22:34:53 -0700304 if (MterpShouldSwitchInterpreters() != 0) {
buzbee1452bee2015-03-06 14:43:04 -0800305 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
306 false);
buzbee1452bee2015-03-06 14:43:04 -0800307 }
308 bool returned = ExecuteMterpImpl(self, code_item, &shadow_frame, &result_register);
309 if (returned) {
310 return result_register;
311 } else {
312 // Mterp didn't like that instruction. Single-step it with the reference interpreter.
buzbeed6b48db2016-01-28 15:48:55 -0800313 result_register = ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame,
buzbee1452bee2015-03-06 14:43:04 -0800314 result_register, true);
315 if (shadow_frame.GetDexPC() == DexFile::kDexNoIndex) {
316 // Single-stepped a return or an exception not handled locally. Return to caller.
buzbeed6b48db2016-01-28 15:48:55 -0800317 return result_register;
buzbee1452bee2015-03-06 14:43:04 -0800318 }
319 }
320 }
321 }
buzbeef61df9b2016-09-07 07:12:29 -0700322 } else {
323 DCHECK_EQ(kInterpreterImplKind, kSwitchImplKind);
buzbee1452bee2015-03-06 14:43:04 -0800324 if (transaction_active) {
325 return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register,
326 false);
327 } else {
328 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
329 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100330 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200331 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200332 } else {
333 // Enter the "with access check" interpreter.
buzbee1452bee2015-03-06 14:43:04 -0800334 if (kInterpreterImplKind == kMterpImplKind) {
335 // No access check variants for Mterp. Just use the switch version.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100336 if (transaction_active) {
buzbee1452bee2015-03-06 14:43:04 -0800337 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register,
338 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100339 } else {
buzbee1452bee2015-03-06 14:43:04 -0800340 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register,
341 false);
342 }
buzbeef61df9b2016-09-07 07:12:29 -0700343 } else {
344 DCHECK_EQ(kInterpreterImplKind, kSwitchImplKind);
buzbee1452bee2015-03-06 14:43:04 -0800345 if (transaction_active) {
346 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register,
347 false);
348 } else {
349 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register,
350 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100351 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200352 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200353 }
354}
355
Brian Carlstromea46f952013-07-30 01:26:50 -0700356void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver,
Aart Bik01223202016-05-05 15:10:42 -0700357 uint32_t* args, JValue* result,
358 bool stay_in_interpreter) {
Ian Rogers64b6d142012-10-29 16:34:15 -0700359 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100360 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
361 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
jeffhaod7521322012-11-21 15:38:24 -0800362 ThrowStackOverflowError(self);
363 return;
364 }
365
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700366 const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke");
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700367 const DexFile::CodeItem* code_item = method->GetCodeItem();
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700368 uint16_t num_regs;
369 uint16_t num_ins;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700370 if (code_item != nullptr) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700371 num_regs = code_item->registers_size_;
372 num_ins = code_item->ins_size_;
Alex Light9139e002015-10-09 15:59:48 -0700373 } else if (!method->IsInvokable()) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700374 self->EndAssertNoThreadSuspension(old_cause);
Alex Light9139e002015-10-09 15:59:48 -0700375 method->ThrowInvocationTimeError();
jeffhao0a9bb732012-11-26 12:28:49 -0800376 return;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700377 } else {
378 DCHECK(method->IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700379 num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty());
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700380 if (!method->IsStatic()) {
381 num_regs++;
382 num_ins++;
383 }
384 }
385 // Set up shadow frame with matching number of reference slots to vregs.
386 ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame();
Andreas Gampeb3025922015-09-01 14:45:00 -0700387 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -0700388 CREATE_SHADOW_FRAME(num_regs, last_shadow_frame, method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -0700389 ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get();
Jeff Hao66135192013-05-14 11:02:41 -0700390 self->PushShadowFrame(shadow_frame);
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700391
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700392 size_t cur_reg = num_regs - num_ins;
393 if (!method->IsStatic()) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700394 CHECK(receiver != nullptr);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800395 shadow_frame->SetVRegReference(cur_reg, receiver);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700396 ++cur_reg;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700397 }
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700398 uint32_t shorty_len = 0;
399 const char* shorty = method->GetShorty(&shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800400 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 -0700401 DCHECK_LT(shorty_pos + 1, shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800402 switch (shorty[shorty_pos + 1]) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700403 case 'L': {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800404 Object* o = reinterpret_cast<StackReference<Object>*>(&args[arg_pos])->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800405 shadow_frame->SetVRegReference(cur_reg, o);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700406 break;
407 }
Jeff Hao5d917302013-02-27 17:57:33 -0800408 case 'J': case 'D': {
409 uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos];
410 shadow_frame->SetVRegLong(cur_reg, wide_value);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700411 cur_reg++;
Jeff Hao5d917302013-02-27 17:57:33 -0800412 arg_pos++;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700413 break;
Jeff Hao5d917302013-02-27 17:57:33 -0800414 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700415 default:
Jeff Hao5d917302013-02-27 17:57:33 -0800416 shadow_frame->SetVReg(cur_reg, args[arg_pos]);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700417 break;
418 }
419 }
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800420 self->EndAssertNoThreadSuspension(old_cause);
421 // Do this after populating the shadow frame in case EnsureInitialized causes a GC.
Ian Rogers6c5cb212014-06-18 16:07:20 -0700422 if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800423 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700424 StackHandleScope<1> hs(self);
425 Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass()));
Ian Rogers7b078e82014-09-10 14:44:24 -0700426 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800427 CHECK(self->IsExceptionPending());
428 self->PopShadowFrame();
429 return;
430 }
431 }
Ian Rogers64b6d142012-10-29 16:34:15 -0700432 if (LIKELY(!method->IsNative())) {
Aart Bik01223202016-05-05 15:10:42 -0700433 JValue r = Execute(self, code_item, *shadow_frame, JValue(), stay_in_interpreter);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700434 if (result != nullptr) {
Jeff Hao6474d192013-03-26 14:08:09 -0700435 *result = r;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700436 }
437 } else {
Ian Rogers64b6d142012-10-29 16:34:15 -0700438 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
439 // generated stub) except during testing and image writing.
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800440 // Update args to be the args in the shadow frame since the input ones could hold stale
441 // references pointers due to moving GC.
442 args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1);
Ian Rogers64b6d142012-10-29 16:34:15 -0700443 if (!Runtime::Current()->IsStarted()) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700444 UnstartedRuntime::Jni(self, method, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700445 } else {
Jeff Hao6474d192013-03-26 14:08:09 -0700446 InterpreterJni(self, method, shorty, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700447 }
448 }
449 self->PopShadowFrame();
450}
451
Mingyao Yangffedec52016-05-19 10:48:40 -0700452static bool IsStringInit(const Instruction* instr, ArtMethod* caller)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700453 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangffedec52016-05-19 10:48:40 -0700454 if (instr->Opcode() == Instruction::INVOKE_DIRECT ||
455 instr->Opcode() == Instruction::INVOKE_DIRECT_RANGE) {
456 // Instead of calling ResolveMethod() which has suspend point and can trigger
457 // GC, look up the callee method symbolically.
458 uint16_t callee_method_idx = (instr->Opcode() == Instruction::INVOKE_DIRECT_RANGE) ?
459 instr->VRegB_3rc() : instr->VRegB_35c();
460 const DexFile* dex_file = caller->GetDexFile();
461 const DexFile::MethodId& method_id = dex_file->GetMethodId(callee_method_idx);
462 const char* class_name = dex_file->StringByTypeIdx(method_id.class_idx_);
463 const char* method_name = dex_file->GetMethodName(method_id);
464 // Compare method's class name and method name against string init.
465 // It's ok since it's not allowed to create your own java/lang/String.
466 // TODO: verify that assumption.
467 if ((strcmp(class_name, "Ljava/lang/String;") == 0) &&
468 (strcmp(method_name, "<init>") == 0)) {
469 return true;
470 }
471 }
472 return false;
473}
474
475static int16_t GetReceiverRegisterForStringInit(const Instruction* instr) {
476 DCHECK(instr->Opcode() == Instruction::INVOKE_DIRECT_RANGE ||
477 instr->Opcode() == Instruction::INVOKE_DIRECT);
478 return (instr->Opcode() == Instruction::INVOKE_DIRECT_RANGE) ?
479 instr->VRegC_3rc() : instr->VRegC_35c();
480}
481
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100482void EnterInterpreterFromDeoptimize(Thread* self,
483 ShadowFrame* shadow_frame,
484 bool from_code,
485 JValue* ret_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700486 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800487 JValue value;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700488 // Set value to last known result in case the shadow frame chain is empty.
489 value.SetJ(ret_val->GetJ());
Sebastien Hertz520633b2015-09-08 17:03:36 +0200490 // Are we executing the first shadow frame?
491 bool first = true;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700492 while (shadow_frame != nullptr) {
Andreas Gampe56fdd0e2016-04-28 14:56:54 -0700493 // We do not want to recover lock state for lock counting when deoptimizing. Currently,
494 // the compiler should not have compiled a method that failed structured-locking checks.
495 DCHECK(!shadow_frame->GetMethod()->MustCountLocks());
496
Ian Rogers62d6c772013-02-27 08:32:07 -0800497 self->SetTopOfShadowStack(shadow_frame);
Ian Rogerse94652f2014-12-02 11:13:19 -0800498 const DexFile::CodeItem* code_item = shadow_frame->GetMethod()->GetCodeItem();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100499 const uint32_t dex_pc = shadow_frame->GetDexPC();
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100500 uint32_t new_dex_pc = dex_pc;
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100501 if (UNLIKELY(self->IsExceptionPending())) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200502 // If we deoptimize from the QuickExceptionHandler, we already reported the exception to
503 // the instrumentation. To prevent from reporting it a second time, we simply pass a
504 // null Instrumentation*.
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100505 const instrumentation::Instrumentation* const instrumentation =
Sebastien Hertz520633b2015-09-08 17:03:36 +0200506 first ? nullptr : Runtime::Current()->GetInstrumentation();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100507 uint32_t found_dex_pc = FindNextInstructionFollowingException(self, *shadow_frame, dex_pc,
508 instrumentation);
509 new_dex_pc = found_dex_pc; // the dex pc of a matching catch handler
510 // or DexFile::kDexNoIndex if there is none.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100511 } else if (!from_code) {
512 // For the debugger and full deoptimization stack, we must go past the invoke
513 // instruction, as it already executed.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700514 // TODO: should be tested more once b/17586779 is fixed.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100515 const Instruction* instr = Instruction::At(&code_item->insns_[dex_pc]);
Mingyao Yang504a6902016-04-28 16:23:01 -0700516 if (instr->IsInvoke()) {
Mingyao Yangffedec52016-05-19 10:48:40 -0700517 if (IsStringInit(instr, shadow_frame->GetMethod())) {
518 uint16_t this_obj_vreg = GetReceiverRegisterForStringInit(instr);
519 // Move the StringFactory.newStringFromChars() result into the register representing
520 // "this object" when invoking the string constructor in the original dex instruction.
521 // Also move the result into all aliases.
522 DCHECK(value.GetL()->IsString());
523 SetStringInitValueToAllAliases(shadow_frame, this_obj_vreg, value);
524 // Calling string constructor in the original dex code doesn't generate a result value.
525 value.SetJ(0);
526 }
Mingyao Yang504a6902016-04-28 16:23:01 -0700527 new_dex_pc = dex_pc + instr->SizeInCodeUnits();
528 } else if (instr->Opcode() == Instruction::NEW_INSTANCE) {
529 // It's possible to deoptimize at a NEW_INSTANCE dex instruciton that's for a
530 // java string, which is turned into a call into StringFactory.newEmptyString();
Mingyao Yangffedec52016-05-19 10:48:40 -0700531 // Move the StringFactory.newEmptyString() result into the destination register.
532 DCHECK(value.GetL()->IsString());
533 shadow_frame->SetVRegReference(instr->VRegA_21c(), value.GetL());
534 // new-instance doesn't generate a result value.
535 value.SetJ(0);
536 // Skip the dex instruction since we essentially come back from an invocation.
537 new_dex_pc = dex_pc + instr->SizeInCodeUnits();
Mingyao Yang504a6902016-04-28 16:23:01 -0700538 if (kIsDebugBuild) {
539 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mingyao Yangffedec52016-05-19 10:48:40 -0700540 // This is a suspend point. But it's ok since value has been set into shadow_frame.
Mingyao Yang504a6902016-04-28 16:23:01 -0700541 mirror::Class* klass = class_linker->ResolveType(
542 instr->VRegB_21c(), shadow_frame->GetMethod());
543 DCHECK(klass->IsStringClass());
544 }
Mingyao Yang504a6902016-04-28 16:23:01 -0700545 } else {
Mingyao Yangffedec52016-05-19 10:48:40 -0700546 CHECK(false) << "Unexpected instruction opcode " << instr->Opcode()
547 << " at dex_pc " << dex_pc
548 << " of method: " << PrettyMethod(shadow_frame->GetMethod(), false);
Mingyao Yang504a6902016-04-28 16:23:01 -0700549 }
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100550 } else {
551 // Nothing to do, the dex_pc is the one at which the code requested
552 // the deoptimization.
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100553 }
554 if (new_dex_pc != DexFile::kDexNoIndex) {
555 shadow_frame->SetDexPC(new_dex_pc);
556 value = Execute(self, code_item, *shadow_frame, value);
557 }
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800558 ShadowFrame* old_frame = shadow_frame;
559 shadow_frame = shadow_frame->GetLink();
Christopher Ferris241a9582015-04-27 15:19:41 -0700560 ShadowFrame::DeleteDeoptimizedFrame(old_frame);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100561 // Following deoptimizations of shadow frames must pass the invoke instruction.
562 from_code = false;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200563 first = false;
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800564 }
565 ret_val->SetJ(value.GetJ());
566}
567
Ian Rogerse94652f2014-12-02 11:13:19 -0800568JValue EnterInterpreterFromEntryPoint(Thread* self, const DexFile::CodeItem* code_item,
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700569 ShadowFrame* shadow_frame) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700570 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100571 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
572 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700573 ThrowStackOverflowError(self);
574 return JValue();
575 }
576
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100577 jit::Jit* jit = Runtime::Current()->GetJit();
578 if (jit != nullptr) {
579 jit->NotifyCompiledCodeToInterpreterTransition(self, shadow_frame->GetMethod());
580 }
Ian Rogerse94652f2014-12-02 11:13:19 -0800581 return Execute(self, code_item, *shadow_frame, JValue());
Ian Rogers7db619b2013-01-16 18:35:48 -0800582}
583
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700584void ArtInterpreterToInterpreterBridge(Thread* self, const DexFile::CodeItem* code_item,
585 ShadowFrame* shadow_frame, JValue* result) {
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100586 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
587 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Jeff Hao16743632013-05-08 10:59:04 -0700588 ThrowStackOverflowError(self);
Jeff Hao69510672013-05-21 17:34:55 -0700589 return;
Jeff Hao16743632013-05-08 10:59:04 -0700590 }
591
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700592 self->PushShadowFrame(shadow_frame);
Alex Lighteb7c1442015-08-31 13:17:42 -0700593 ArtMethod* method = shadow_frame->GetMethod();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200594 // Ensure static methods are initialized.
Alex Lighteb7c1442015-08-31 13:17:42 -0700595 const bool is_static = method->IsStatic();
Ian Rogerse94652f2014-12-02 11:13:19 -0800596 if (is_static) {
Alex Lighteb7c1442015-08-31 13:17:42 -0700597 mirror::Class* declaring_class = method->GetDeclaringClass();
Ian Rogers6c5cb212014-06-18 16:07:20 -0700598 if (UNLIKELY(!declaring_class->IsInitialized())) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700599 StackHandleScope<1> hs(self);
600 HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class));
601 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
Ian Rogers7b078e82014-09-10 14:44:24 -0700602 self, h_declaring_class, true, true))) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700603 DCHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700604 self->PopShadowFrame();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200605 return;
606 }
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700607 CHECK(h_declaring_class->IsInitializing());
Jeff Hao16743632013-05-08 10:59:04 -0700608 }
Jeff Hao16743632013-05-08 10:59:04 -0700609 }
Jeff Hao16743632013-05-08 10:59:04 -0700610
Ian Rogerse94652f2014-12-02 11:13:19 -0800611 if (LIKELY(!shadow_frame->GetMethod()->IsNative())) {
612 result->SetJ(Execute(self, code_item, *shadow_frame, JValue()).GetJ());
Jeff Hao16743632013-05-08 10:59:04 -0700613 } else {
614 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
615 // generated stub) except during testing and image writing.
616 CHECK(!Runtime::Current()->IsStarted());
Ian Rogerse94652f2014-12-02 11:13:19 -0800617 Object* receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0);
618 uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1);
Andreas Gampe799681b2015-05-15 19:24:12 -0700619 UnstartedRuntime::Jni(self, shadow_frame->GetMethod(), receiver, args, result);
Jeff Hao16743632013-05-08 10:59:04 -0700620 }
621
622 self->PopShadowFrame();
Jeff Hao16743632013-05-08 10:59:04 -0700623}
624
buzbee1452bee2015-03-06 14:43:04 -0800625void CheckInterpreterAsmConstants() {
626 CheckMterpAsmConstants();
627}
628
629void InitInterpreterTls(Thread* self) {
630 InitMterpTls(self);
631}
632
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700633} // namespace interpreter
634} // namespace art