blob: 01498a23db7e009678da1daca9be795e92437fff [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"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "mirror/string-inl.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070024#include "scoped_thread_state_change.h"
25#include "ScopedLocalRef.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070026#include "stack.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070027#include "unstarted_runtime.h"
buzbee1452bee2015-03-06 14:43:04 -080028#include "mterp/mterp.h"
buzbee734f3aa2016-01-28 14:20:06 -080029#include "jit/jit.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070030
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070031namespace art {
32namespace interpreter {
33
Ian Rogersfc0e94b2013-09-23 23:51:32 -070034static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty,
Jeff Hao5d917302013-02-27 17:57:33 -080035 Object* receiver, uint32_t* args, JValue* result)
Mathieu Chartier90443472015-07-16 20:32:27 -070036 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers64b6d142012-10-29 16:34:15 -070037 // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler,
38 // it should be removed and JNI compiled stubs used instead.
39 ScopedObjectAccessUnchecked soa(self);
40 if (method->IsStatic()) {
41 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010042 typedef jobject (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080043 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070044 ScopedLocalRef<jclass> klass(soa.Env(),
45 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
Ian Rogers556d6372012-11-20 12:19:36 -080046 jobject jresult;
47 {
48 ScopedThreadStateChange tsc(self, kNative);
49 jresult = fn(soa.Env(), klass.get());
50 }
51 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -070052 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010053 typedef void (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080054 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070055 ScopedLocalRef<jclass> klass(soa.Env(),
56 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
57 ScopedThreadStateChange tsc(self, kNative);
58 fn(soa.Env(), klass.get());
59 } else if (shorty == "Z") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010060 typedef jboolean (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080061 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070062 ScopedLocalRef<jclass> klass(soa.Env(),
63 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
64 ScopedThreadStateChange tsc(self, kNative);
65 result->SetZ(fn(soa.Env(), klass.get()));
66 } else if (shorty == "BI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010067 typedef jbyte (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -080068 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070069 ScopedLocalRef<jclass> klass(soa.Env(),
70 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
71 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -080072 result->SetB(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -070073 } else if (shorty == "II") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010074 typedef jint (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -080075 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070076 ScopedLocalRef<jclass> klass(soa.Env(),
77 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
78 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -080079 result->SetI(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -070080 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010081 typedef jobject (fntype)(JNIEnv*, jclass, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -080082 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070083 ScopedLocalRef<jclass> klass(soa.Env(),
84 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
85 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -070086 soa.AddLocalReference<jobject>(
87 reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -080088 jobject jresult;
89 {
90 ScopedThreadStateChange tsc(self, kNative);
91 jresult = fn(soa.Env(), klass.get(), arg0.get());
92 }
93 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -070094 } else if (shorty == "IIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010095 typedef jint (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -080096 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070097 ScopedLocalRef<jclass> klass(soa.Env(),
98 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
99 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800100 result->SetI(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700101 } else if (shorty == "ILI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100102 typedef jint (fntype)(JNIEnv*, jclass, jobject, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800103 fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>(
104 method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700105 ScopedLocalRef<jclass> klass(soa.Env(),
106 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
107 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700108 soa.AddLocalReference<jobject>(
109 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700110 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800111 result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700112 } else if (shorty == "SIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100113 typedef jshort (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700114 fntype* const fn =
115 reinterpret_cast<fntype*>(const_cast<void*>(method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700116 ScopedLocalRef<jclass> klass(soa.Env(),
117 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
118 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800119 result->SetS(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700120 } else if (shorty == "VIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100121 typedef void (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800122 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700123 ScopedLocalRef<jclass> klass(soa.Env(),
124 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
125 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800126 fn(soa.Env(), klass.get(), args[0], args[1]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700127 } else if (shorty == "ZLL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100128 typedef jboolean (fntype)(JNIEnv*, jclass, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800129 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700130 ScopedLocalRef<jclass> klass(soa.Env(),
131 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
132 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700133 soa.AddLocalReference<jobject>(
134 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700135 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700136 soa.AddLocalReference<jobject>(
137 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700138 ScopedThreadStateChange tsc(self, kNative);
139 result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get()));
140 } else if (shorty == "ZILL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100141 typedef jboolean (fntype)(JNIEnv*, jclass, jint, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800142 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700143 ScopedLocalRef<jclass> klass(soa.Env(),
144 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
145 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700146 soa.AddLocalReference<jobject>(
147 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700148 ScopedLocalRef<jobject> arg2(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700149 soa.AddLocalReference<jobject>(
150 reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700151 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800152 result->SetZ(fn(soa.Env(), klass.get(), args[0], arg1.get(), arg2.get()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700153 } else if (shorty == "VILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100154 typedef void (fntype)(JNIEnv*, jclass, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800155 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700156 ScopedLocalRef<jclass> klass(soa.Env(),
157 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
158 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700159 soa.AddLocalReference<jobject>(
160 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700161 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800162 fn(soa.Env(), klass.get(), args[0], arg1.get(), args[2], args[3]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700163 } else if (shorty == "VLILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100164 typedef void (fntype)(JNIEnv*, jclass, jobject, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800165 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700166 ScopedLocalRef<jclass> klass(soa.Env(),
167 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
168 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700169 soa.AddLocalReference<jobject>(
170 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700171 ScopedLocalRef<jobject> arg2(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700172 soa.AddLocalReference<jobject>(
173 reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700174 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800175 fn(soa.Env(), klass.get(), arg0.get(), args[1], arg2.get(), args[3], args[4]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700176 } else {
177 LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method)
178 << " shorty: " << shorty;
179 }
180 } else {
181 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100182 typedef jobject (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800183 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700184 ScopedLocalRef<jobject> rcvr(soa.Env(),
185 soa.AddLocalReference<jobject>(receiver));
Ian Rogers556d6372012-11-20 12:19:36 -0800186 jobject jresult;
187 {
188 ScopedThreadStateChange tsc(self, kNative);
189 jresult = fn(soa.Env(), rcvr.get());
190 }
191 result->SetL(soa.Decode<Object*>(jresult));
Jeff Hao3dd9f762013-07-08 13:09:25 -0700192 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100193 typedef void (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800194 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Jeff Hao3dd9f762013-07-08 13:09:25 -0700195 ScopedLocalRef<jobject> rcvr(soa.Env(),
196 soa.AddLocalReference<jobject>(receiver));
197 ScopedThreadStateChange tsc(self, kNative);
198 fn(soa.Env(), rcvr.get());
Ian Rogers64b6d142012-10-29 16:34:15 -0700199 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100200 typedef jobject (fntype)(JNIEnv*, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800201 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700202 ScopedLocalRef<jobject> rcvr(soa.Env(),
203 soa.AddLocalReference<jobject>(receiver));
204 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700205 soa.AddLocalReference<jobject>(
206 reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -0800207 jobject jresult;
208 {
209 ScopedThreadStateChange tsc(self, kNative);
210 jresult = fn(soa.Env(), rcvr.get(), arg0.get());
Ian Rogers556d6372012-11-20 12:19:36 -0800211 }
212 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -0700213 ScopedThreadStateChange tsc(self, kNative);
Ian Rogers64b6d142012-10-29 16:34:15 -0700214 } else if (shorty == "III") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100215 typedef jint (fntype)(JNIEnv*, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800216 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700217 ScopedLocalRef<jobject> rcvr(soa.Env(),
218 soa.AddLocalReference<jobject>(receiver));
219 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800220 result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700221 } else {
222 LOG(FATAL) << "Do something with native method: " << PrettyMethod(method)
223 << " shorty: " << shorty;
224 }
225 }
226}
227
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200228enum InterpreterImplKind {
buzbee1452bee2015-03-06 14:43:04 -0800229 kSwitchImplKind, // Switch-based interpreter implementation.
230 kComputedGotoImplKind, // Computed-goto-based interpreter implementation.
231 kMterpImplKind // Assembly interpreter
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200232};
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800233static std::ostream& operator<<(std::ostream& os, const InterpreterImplKind& rhs) {
buzbee1452bee2015-03-06 14:43:04 -0800234 os << ((rhs == kSwitchImplKind)
235 ? "Switch-based interpreter"
236 : (rhs == kComputedGotoImplKind)
237 ? "Computed-goto-based interpreter"
238 : "Asm interpreter");
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700239 return os;
240}
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700241
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200242#if !defined(__clang__)
Bill Buzbee3b0b4b92016-02-02 13:45:36 +0000243#if (defined(__arm__) || defined(__i386__) || defined(__aarch64__))
buzbee1452bee2015-03-06 14:43:04 -0800244// TODO: remove when all targets implemented.
245static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
246#else
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800247static constexpr InterpreterImplKind kInterpreterImplKind = kComputedGotoImplKind;
buzbee1452bee2015-03-06 14:43:04 -0800248#endif
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200249#else
250// Clang 3.4 fails to build the goto interpreter implementation.
Bill Buzbee3b0b4b92016-02-02 13:45:36 +0000251#if (defined(__arm__) || defined(__i386__) || defined(__aarch64__))
buzbee1452bee2015-03-06 14:43:04 -0800252static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
253#else
254static constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImplKind;
255#endif
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200256template<bool do_access_check, bool transaction_active>
Ian Rogerse94652f2014-12-02 11:13:19 -0800257JValue ExecuteGotoImpl(Thread*, const DexFile::CodeItem*, ShadowFrame&, JValue) {
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200258 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -0700259 UNREACHABLE();
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200260}
261// Explicit definitions of ExecuteGotoImpl.
Mathieu Chartier90443472015-07-16 20:32:27 -0700262template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800263JValue ExecuteGotoImpl<true, false>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200264 ShadowFrame& shadow_frame, JValue result_register);
Mathieu Chartier90443472015-07-16 20:32:27 -0700265template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800266JValue ExecuteGotoImpl<false, false>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200267 ShadowFrame& shadow_frame, JValue result_register);
Mathieu Chartier90443472015-07-16 20:32:27 -0700268template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800269JValue ExecuteGotoImpl<true, true>(Thread* self, const DexFile::CodeItem* code_item,
270 ShadowFrame& shadow_frame, JValue result_register);
Mathieu Chartier90443472015-07-16 20:32:27 -0700271template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800272JValue ExecuteGotoImpl<false, true>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200273 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200274#endif
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700275
Ian Rogerse94652f2014-12-02 11:13:19 -0800276static JValue Execute(Thread* self, const DexFile::CodeItem* code_item, ShadowFrame& shadow_frame,
277 JValue result_register)
Mathieu Chartier90443472015-07-16 20:32:27 -0700278 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200279
Ian Rogerse94652f2014-12-02 11:13:19 -0800280static inline JValue Execute(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200281 ShadowFrame& shadow_frame, JValue result_register) {
buzbee1452bee2015-03-06 14:43:04 -0800282 DCHECK(!shadow_frame.GetMethod()->IsAbstract());
Ian Rogers848871b2013-08-05 10:56:33 -0700283 DCHECK(!shadow_frame.GetMethod()->IsNative());
buzbee734f3aa2016-01-28 14:20:06 -0800284 if (LIKELY(shadow_frame.GetDexPC() == 0)) { // Entering the method, but not via deoptimization.
285 if (kIsDebugBuild) {
286 self->AssertNoPendingException();
287 }
288 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
289 ArtMethod *method = shadow_frame.GetMethod();
290
291 if (UNLIKELY(instrumentation->HasMethodEntryListeners())) {
292 instrumentation->MethodEnterEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
293 method, 0);
294 }
295
Tamas Berghammer3a98aae2016-02-08 20:21:54 +0000296 if (UNLIKELY(Runtime::Current()->GetJit() != nullptr &&
297 Runtime::Current()->GetJit()->JitAtFirstUse() &&
298 method->HasAnyCompiledCode())) {
buzbee734f3aa2016-01-28 14:20:06 -0800299 JValue result;
300
301 // Pop the shadow frame before calling into compiled code.
302 self->PopShadowFrame();
303 ArtInterpreterToCompiledCodeBridge(self, code_item, &shadow_frame, &result);
304 // Push the shadow frame back as the caller will expect it.
305 self->PushShadowFrame(&shadow_frame);
306
307 return result;
308 }
309 }
310
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200311 shadow_frame.GetMethod()->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200312
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100313 bool transaction_active = Runtime::Current()->IsActiveTransaction();
Igor Murashkindf707e42016-02-02 16:56:50 -0800314 if (LIKELY(shadow_frame.GetMethod()->SkipAccessChecks())) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200315 // Enter the "without access check" interpreter.
buzbee1452bee2015-03-06 14:43:04 -0800316 if (kInterpreterImplKind == kMterpImplKind) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100317 if (transaction_active) {
buzbee1452bee2015-03-06 14:43:04 -0800318 // No Mterp variant - just use the switch interpreter.
319 return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register,
320 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100321 } else {
buzbee1452bee2015-03-06 14:43:04 -0800322 const instrumentation::Instrumentation* const instrumentation =
323 Runtime::Current()->GetInstrumentation();
324 while (true) {
Bill Buzbee9687f242016-02-05 14:08:10 +0000325 // Mterp does not support all instrumentation.
326 bool unhandled_instrumentation;
327 if ((kRuntimeISA == kArm64) || (kRuntimeISA == kArm)) {
328 unhandled_instrumentation = instrumentation->NonJitProfilingActive();
329 } else {
330 unhandled_instrumentation = instrumentation->IsActive();
331 }
332 if (unhandled_instrumentation || !Runtime::Current()->IsStarted()) {
buzbee1452bee2015-03-06 14:43:04 -0800333#if !defined(__clang__)
334 return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register);
335#else
336 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
337 false);
338#endif
339 }
340 bool returned = ExecuteMterpImpl(self, code_item, &shadow_frame, &result_register);
341 if (returned) {
342 return result_register;
343 } else {
344 // Mterp didn't like that instruction. Single-step it with the reference interpreter.
buzbeed6b48db2016-01-28 15:48:55 -0800345 result_register = ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame,
buzbee1452bee2015-03-06 14:43:04 -0800346 result_register, true);
347 if (shadow_frame.GetDexPC() == DexFile::kDexNoIndex) {
348 // Single-stepped a return or an exception not handled locally. Return to caller.
buzbeed6b48db2016-01-28 15:48:55 -0800349 return result_register;
buzbee1452bee2015-03-06 14:43:04 -0800350 }
351 }
352 }
353 }
354 } else if (kInterpreterImplKind == kSwitchImplKind) {
355 if (transaction_active) {
356 return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register,
357 false);
358 } else {
359 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
360 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100361 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200362 } else {
363 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100364 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800365 return ExecuteGotoImpl<false, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100366 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800367 return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100368 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200369 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200370 } else {
371 // Enter the "with access check" interpreter.
buzbee1452bee2015-03-06 14:43:04 -0800372 if (kInterpreterImplKind == kMterpImplKind) {
373 // No access check variants for Mterp. Just use the switch version.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100374 if (transaction_active) {
buzbee1452bee2015-03-06 14:43:04 -0800375 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register,
376 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100377 } else {
buzbee1452bee2015-03-06 14:43:04 -0800378 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register,
379 false);
380 }
381 } else if (kInterpreterImplKind == kSwitchImplKind) {
382 if (transaction_active) {
383 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register,
384 false);
385 } else {
386 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register,
387 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100388 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200389 } else {
390 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100391 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800392 return ExecuteGotoImpl<true, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100393 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800394 return ExecuteGotoImpl<true, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100395 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200396 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200397 }
398}
399
Brian Carlstromea46f952013-07-30 01:26:50 -0700400void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver,
Jeff Hao6474d192013-03-26 14:08:09 -0700401 uint32_t* args, JValue* result) {
Ian Rogers64b6d142012-10-29 16:34:15 -0700402 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100403 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
404 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
jeffhaod7521322012-11-21 15:38:24 -0800405 ThrowStackOverflowError(self);
406 return;
407 }
408
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700409 const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke");
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700410 const DexFile::CodeItem* code_item = method->GetCodeItem();
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700411 uint16_t num_regs;
412 uint16_t num_ins;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700413 if (code_item != nullptr) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700414 num_regs = code_item->registers_size_;
415 num_ins = code_item->ins_size_;
Alex Light9139e002015-10-09 15:59:48 -0700416 } else if (!method->IsInvokable()) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700417 self->EndAssertNoThreadSuspension(old_cause);
Alex Light9139e002015-10-09 15:59:48 -0700418 method->ThrowInvocationTimeError();
jeffhao0a9bb732012-11-26 12:28:49 -0800419 return;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700420 } else {
421 DCHECK(method->IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700422 num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty());
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700423 if (!method->IsStatic()) {
424 num_regs++;
425 num_ins++;
426 }
427 }
428 // Set up shadow frame with matching number of reference slots to vregs.
429 ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame();
Andreas Gampeb3025922015-09-01 14:45:00 -0700430 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -0700431 CREATE_SHADOW_FRAME(num_regs, last_shadow_frame, method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -0700432 ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get();
Jeff Hao66135192013-05-14 11:02:41 -0700433 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()) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700437 CHECK(receiver != nullptr);
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())) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800476 JValue r = Execute(self, code_item, *shadow_frame, JValue());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700477 if (result != nullptr) {
Jeff Hao6474d192013-03-26 14:08:09 -0700478 *result = r;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700479 }
480 } else {
Ian Rogers64b6d142012-10-29 16:34:15 -0700481 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
482 // generated stub) except during testing and image writing.
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800483 // Update args to be the args in the shadow frame since the input ones could hold stale
484 // references pointers due to moving GC.
485 args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1);
Ian Rogers64b6d142012-10-29 16:34:15 -0700486 if (!Runtime::Current()->IsStarted()) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700487 UnstartedRuntime::Jni(self, method, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700488 } else {
Jeff Hao6474d192013-03-26 14:08:09 -0700489 InterpreterJni(self, method, shorty, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700490 }
491 }
492 self->PopShadowFrame();
493}
494
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100495void EnterInterpreterFromDeoptimize(Thread* self,
496 ShadowFrame* shadow_frame,
497 bool from_code,
498 JValue* ret_val)
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 SHARED_REQUIRES(Locks::mutator_lock_) {
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800500 JValue value;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700501 // Set value to last known result in case the shadow frame chain is empty.
502 value.SetJ(ret_val->GetJ());
Sebastien Hertz520633b2015-09-08 17:03:36 +0200503 // Are we executing the first shadow frame?
504 bool first = true;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700505 while (shadow_frame != nullptr) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800506 self->SetTopOfShadowStack(shadow_frame);
Ian Rogerse94652f2014-12-02 11:13:19 -0800507 const DexFile::CodeItem* code_item = shadow_frame->GetMethod()->GetCodeItem();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100508 const uint32_t dex_pc = shadow_frame->GetDexPC();
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100509 uint32_t new_dex_pc = dex_pc;
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100510 if (UNLIKELY(self->IsExceptionPending())) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200511 // If we deoptimize from the QuickExceptionHandler, we already reported the exception to
512 // the instrumentation. To prevent from reporting it a second time, we simply pass a
513 // null Instrumentation*.
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100514 const instrumentation::Instrumentation* const instrumentation =
Sebastien Hertz520633b2015-09-08 17:03:36 +0200515 first ? nullptr : Runtime::Current()->GetInstrumentation();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100516 uint32_t found_dex_pc = FindNextInstructionFollowingException(self, *shadow_frame, dex_pc,
517 instrumentation);
518 new_dex_pc = found_dex_pc; // the dex pc of a matching catch handler
519 // or DexFile::kDexNoIndex if there is none.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100520 } else if (!from_code) {
521 // For the debugger and full deoptimization stack, we must go past the invoke
522 // instruction, as it already executed.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700523 // TODO: should be tested more once b/17586779 is fixed.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100524 const Instruction* instr = Instruction::At(&code_item->insns_[dex_pc]);
525 DCHECK(instr->IsInvoke());
526 new_dex_pc = dex_pc + instr->SizeInCodeUnits();
527 } else {
528 // Nothing to do, the dex_pc is the one at which the code requested
529 // the deoptimization.
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100530 }
531 if (new_dex_pc != DexFile::kDexNoIndex) {
532 shadow_frame->SetDexPC(new_dex_pc);
533 value = Execute(self, code_item, *shadow_frame, value);
534 }
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800535 ShadowFrame* old_frame = shadow_frame;
536 shadow_frame = shadow_frame->GetLink();
Christopher Ferris241a9582015-04-27 15:19:41 -0700537 ShadowFrame::DeleteDeoptimizedFrame(old_frame);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100538 // Following deoptimizations of shadow frames must pass the invoke instruction.
539 from_code = false;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200540 first = false;
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800541 }
542 ret_val->SetJ(value.GetJ());
543}
544
Ian Rogerse94652f2014-12-02 11:13:19 -0800545JValue EnterInterpreterFromEntryPoint(Thread* self, const DexFile::CodeItem* code_item,
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700546 ShadowFrame* shadow_frame) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700547 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100548 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
549 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700550 ThrowStackOverflowError(self);
551 return JValue();
552 }
553
Ian Rogerse94652f2014-12-02 11:13:19 -0800554 return Execute(self, code_item, *shadow_frame, JValue());
Ian Rogers7db619b2013-01-16 18:35:48 -0800555}
556
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700557void ArtInterpreterToInterpreterBridge(Thread* self, const DexFile::CodeItem* code_item,
558 ShadowFrame* shadow_frame, JValue* result) {
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100559 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
560 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Jeff Hao16743632013-05-08 10:59:04 -0700561 ThrowStackOverflowError(self);
Jeff Hao69510672013-05-21 17:34:55 -0700562 return;
Jeff Hao16743632013-05-08 10:59:04 -0700563 }
564
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700565 self->PushShadowFrame(shadow_frame);
Alex Lighteb7c1442015-08-31 13:17:42 -0700566 ArtMethod* method = shadow_frame->GetMethod();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200567 // Ensure static methods are initialized.
Alex Lighteb7c1442015-08-31 13:17:42 -0700568 const bool is_static = method->IsStatic();
Ian Rogerse94652f2014-12-02 11:13:19 -0800569 if (is_static) {
Alex Lighteb7c1442015-08-31 13:17:42 -0700570 mirror::Class* declaring_class = method->GetDeclaringClass();
Ian Rogers6c5cb212014-06-18 16:07:20 -0700571 if (UNLIKELY(!declaring_class->IsInitialized())) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700572 StackHandleScope<1> hs(self);
573 HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class));
574 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
Ian Rogers7b078e82014-09-10 14:44:24 -0700575 self, h_declaring_class, true, true))) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700576 DCHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700577 self->PopShadowFrame();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200578 return;
579 }
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700580 CHECK(h_declaring_class->IsInitializing());
Jeff Hao16743632013-05-08 10:59:04 -0700581 }
Jeff Hao16743632013-05-08 10:59:04 -0700582 }
Jeff Hao16743632013-05-08 10:59:04 -0700583
Ian Rogerse94652f2014-12-02 11:13:19 -0800584 if (LIKELY(!shadow_frame->GetMethod()->IsNative())) {
585 result->SetJ(Execute(self, code_item, *shadow_frame, JValue()).GetJ());
Jeff Hao16743632013-05-08 10:59:04 -0700586 } else {
587 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
588 // generated stub) except during testing and image writing.
589 CHECK(!Runtime::Current()->IsStarted());
Ian Rogerse94652f2014-12-02 11:13:19 -0800590 Object* receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0);
591 uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1);
Andreas Gampe799681b2015-05-15 19:24:12 -0700592 UnstartedRuntime::Jni(self, shadow_frame->GetMethod(), receiver, args, result);
Jeff Hao16743632013-05-08 10:59:04 -0700593 }
594
595 self->PopShadowFrame();
Jeff Hao16743632013-05-08 10:59:04 -0700596}
597
buzbee1452bee2015-03-06 14:43:04 -0800598void CheckInterpreterAsmConstants() {
599 CheckMterpAsmConstants();
600}
601
602void InitInterpreterTls(Thread* self) {
603 InitMterpTls(self);
604}
605
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700606} // namespace interpreter
607} // namespace art