blob: b7e5b301addca2682e9ca2eb9f34008d14e3fbcc [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"
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +000030#include "jit/jit_code_cache.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070031
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070032namespace art {
33namespace interpreter {
34
Ian Rogersfc0e94b2013-09-23 23:51:32 -070035static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty,
Jeff Hao5d917302013-02-27 17:57:33 -080036 Object* receiver, uint32_t* args, JValue* result)
Mathieu Chartier90443472015-07-16 20:32:27 -070037 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers64b6d142012-10-29 16:34:15 -070038 // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler,
39 // it should be removed and JNI compiled stubs used instead.
40 ScopedObjectAccessUnchecked soa(self);
41 if (method->IsStatic()) {
42 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010043 typedef jobject (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080044 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070045 ScopedLocalRef<jclass> klass(soa.Env(),
46 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
Ian Rogers556d6372012-11-20 12:19:36 -080047 jobject jresult;
48 {
49 ScopedThreadStateChange tsc(self, kNative);
50 jresult = fn(soa.Env(), klass.get());
51 }
52 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -070053 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010054 typedef void (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080055 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070056 ScopedLocalRef<jclass> klass(soa.Env(),
57 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
58 ScopedThreadStateChange tsc(self, kNative);
59 fn(soa.Env(), klass.get());
60 } else if (shorty == "Z") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010061 typedef jboolean (fntype)(JNIEnv*, jclass);
Mathieu Chartier2d721012014-11-10 11:08:06 -080062 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070063 ScopedLocalRef<jclass> klass(soa.Env(),
64 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
65 ScopedThreadStateChange tsc(self, kNative);
66 result->SetZ(fn(soa.Env(), klass.get()));
67 } else if (shorty == "BI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010068 typedef jbyte (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -080069 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070070 ScopedLocalRef<jclass> klass(soa.Env(),
71 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
72 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -080073 result->SetB(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -070074 } else if (shorty == "II") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010075 typedef jint (fntype)(JNIEnv*, jclass, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -080076 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070077 ScopedLocalRef<jclass> klass(soa.Env(),
78 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
79 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -080080 result->SetI(fn(soa.Env(), klass.get(), args[0]));
Ian Rogers64b6d142012-10-29 16:34:15 -070081 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010082 typedef jobject (fntype)(JNIEnv*, jclass, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -080083 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070084 ScopedLocalRef<jclass> klass(soa.Env(),
85 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
86 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -070087 soa.AddLocalReference<jobject>(
88 reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -080089 jobject jresult;
90 {
91 ScopedThreadStateChange tsc(self, kNative);
92 jresult = fn(soa.Env(), klass.get(), arg0.get());
93 }
94 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -070095 } else if (shorty == "IIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +010096 typedef jint (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -080097 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -070098 ScopedLocalRef<jclass> klass(soa.Env(),
99 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
100 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800101 result->SetI(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700102 } else if (shorty == "ILI") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100103 typedef jint (fntype)(JNIEnv*, jclass, jobject, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800104 fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>(
105 method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700106 ScopedLocalRef<jclass> klass(soa.Env(),
107 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
108 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700109 soa.AddLocalReference<jobject>(
110 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700111 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800112 result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700113 } else if (shorty == "SIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100114 typedef jshort (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700115 fntype* const fn =
116 reinterpret_cast<fntype*>(const_cast<void*>(method->GetEntryPointFromJni()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700117 ScopedLocalRef<jclass> klass(soa.Env(),
118 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
119 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800120 result->SetS(fn(soa.Env(), klass.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700121 } else if (shorty == "VIZ") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100122 typedef void (fntype)(JNIEnv*, jclass, jint, jboolean);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800123 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700124 ScopedLocalRef<jclass> klass(soa.Env(),
125 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
126 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800127 fn(soa.Env(), klass.get(), args[0], args[1]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700128 } else if (shorty == "ZLL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100129 typedef jboolean (fntype)(JNIEnv*, jclass, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800130 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700131 ScopedLocalRef<jclass> klass(soa.Env(),
132 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
133 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700134 soa.AddLocalReference<jobject>(
135 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700136 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700137 soa.AddLocalReference<jobject>(
138 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700139 ScopedThreadStateChange tsc(self, kNative);
140 result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get()));
141 } else if (shorty == "ZILL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100142 typedef jboolean (fntype)(JNIEnv*, jclass, jint, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800143 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700144 ScopedLocalRef<jclass> klass(soa.Env(),
145 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
146 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700147 soa.AddLocalReference<jobject>(
148 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700149 ScopedLocalRef<jobject> arg2(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700150 soa.AddLocalReference<jobject>(
151 reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700152 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800153 result->SetZ(fn(soa.Env(), klass.get(), args[0], arg1.get(), arg2.get()));
Ian Rogers64b6d142012-10-29 16:34:15 -0700154 } else if (shorty == "VILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100155 typedef void (fntype)(JNIEnv*, jclass, jint, jobject, jint, jint);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800156 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700157 ScopedLocalRef<jclass> klass(soa.Env(),
158 soa.AddLocalReference<jclass>(method->GetDeclaringClass()));
159 ScopedLocalRef<jobject> arg1(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700160 soa.AddLocalReference<jobject>(
161 reinterpret_cast<Object*>(args[1])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700162 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800163 fn(soa.Env(), klass.get(), args[0], arg1.get(), args[2], args[3]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700164 } else if (shorty == "VLILII") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100165 typedef void (fntype)(JNIEnv*, jclass, jobject, jint, jobject, jint, 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 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700170 soa.AddLocalReference<jobject>(
171 reinterpret_cast<Object*>(args[0])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700172 ScopedLocalRef<jobject> arg2(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700173 soa.AddLocalReference<jobject>(
174 reinterpret_cast<Object*>(args[2])));
Ian Rogers64b6d142012-10-29 16:34:15 -0700175 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800176 fn(soa.Env(), klass.get(), arg0.get(), args[1], arg2.get(), args[3], args[4]);
Ian Rogers64b6d142012-10-29 16:34:15 -0700177 } else {
178 LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method)
179 << " shorty: " << shorty;
180 }
181 } else {
182 if (shorty == "L") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100183 typedef jobject (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800184 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700185 ScopedLocalRef<jobject> rcvr(soa.Env(),
186 soa.AddLocalReference<jobject>(receiver));
Ian Rogers556d6372012-11-20 12:19:36 -0800187 jobject jresult;
188 {
189 ScopedThreadStateChange tsc(self, kNative);
190 jresult = fn(soa.Env(), rcvr.get());
191 }
192 result->SetL(soa.Decode<Object*>(jresult));
Jeff Hao3dd9f762013-07-08 13:09:25 -0700193 } else if (shorty == "V") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100194 typedef void (fntype)(JNIEnv*, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800195 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Jeff Hao3dd9f762013-07-08 13:09:25 -0700196 ScopedLocalRef<jobject> rcvr(soa.Env(),
197 soa.AddLocalReference<jobject>(receiver));
198 ScopedThreadStateChange tsc(self, kNative);
199 fn(soa.Env(), rcvr.get());
Ian Rogers64b6d142012-10-29 16:34:15 -0700200 } else if (shorty == "LL") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100201 typedef jobject (fntype)(JNIEnv*, jobject, jobject);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800202 fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni());
Ian Rogers64b6d142012-10-29 16:34:15 -0700203 ScopedLocalRef<jobject> rcvr(soa.Env(),
204 soa.AddLocalReference<jobject>(receiver));
205 ScopedLocalRef<jobject> arg0(soa.Env(),
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700206 soa.AddLocalReference<jobject>(
207 reinterpret_cast<Object*>(args[0])));
Ian Rogers556d6372012-11-20 12:19:36 -0800208 jobject jresult;
209 {
210 ScopedThreadStateChange tsc(self, kNative);
211 jresult = fn(soa.Env(), rcvr.get(), arg0.get());
Ian Rogers556d6372012-11-20 12:19:36 -0800212 }
213 result->SetL(soa.Decode<Object*>(jresult));
Ian Rogers64b6d142012-10-29 16:34:15 -0700214 ScopedThreadStateChange tsc(self, kNative);
Ian Rogers64b6d142012-10-29 16:34:15 -0700215 } else if (shorty == "III") {
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100216 typedef jint (fntype)(JNIEnv*, jobject, jint, jint);
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<jobject> rcvr(soa.Env(),
219 soa.AddLocalReference<jobject>(receiver));
220 ScopedThreadStateChange tsc(self, kNative);
Jeff Hao5d917302013-02-27 17:57:33 -0800221 result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1]));
Ian Rogers64b6d142012-10-29 16:34:15 -0700222 } else {
223 LOG(FATAL) << "Do something with native method: " << PrettyMethod(method)
224 << " shorty: " << shorty;
225 }
226 }
227}
228
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200229enum InterpreterImplKind {
buzbee1452bee2015-03-06 14:43:04 -0800230 kSwitchImplKind, // Switch-based interpreter implementation.
231 kComputedGotoImplKind, // Computed-goto-based interpreter implementation.
232 kMterpImplKind // Assembly interpreter
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200233};
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800234static std::ostream& operator<<(std::ostream& os, const InterpreterImplKind& rhs) {
buzbee1452bee2015-03-06 14:43:04 -0800235 os << ((rhs == kSwitchImplKind)
236 ? "Switch-based interpreter"
237 : (rhs == kComputedGotoImplKind)
238 ? "Computed-goto-based interpreter"
239 : "Asm interpreter");
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700240 return os;
241}
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700242
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200243#if !defined(__clang__)
Serguei Katkov6cbe0812016-03-01 16:10:48 +0600244#if (defined(__arm__) || defined(__i386__) || defined(__aarch64__) || defined(__x86_64__) || (defined(__mips__) && !defined(__LP64__)))
buzbee1452bee2015-03-06 14:43:04 -0800245// TODO: remove when all targets implemented.
246static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
247#else
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800248static constexpr InterpreterImplKind kInterpreterImplKind = kComputedGotoImplKind;
buzbee1452bee2015-03-06 14:43:04 -0800249#endif
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200250#else
251// Clang 3.4 fails to build the goto interpreter implementation.
Serguei Katkov6cbe0812016-03-01 16:10:48 +0600252#if (defined(__arm__) || defined(__i386__) || defined(__aarch64__) || defined(__x86_64__) || (defined(__mips__) && !defined(__LP64__)))
buzbee1452bee2015-03-06 14:43:04 -0800253static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind;
254#else
255static constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImplKind;
256#endif
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200257template<bool do_access_check, bool transaction_active>
Ian Rogerse94652f2014-12-02 11:13:19 -0800258JValue ExecuteGotoImpl(Thread*, const DexFile::CodeItem*, ShadowFrame&, JValue) {
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200259 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -0700260 UNREACHABLE();
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200261}
262// Explicit definitions of ExecuteGotoImpl.
Mathieu Chartier90443472015-07-16 20:32:27 -0700263template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800264JValue ExecuteGotoImpl<true, false>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200265 ShadowFrame& shadow_frame, JValue result_register);
Mathieu Chartier90443472015-07-16 20:32:27 -0700266template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800267JValue ExecuteGotoImpl<false, false>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200268 ShadowFrame& shadow_frame, JValue result_register);
Mathieu Chartier90443472015-07-16 20:32:27 -0700269template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800270JValue ExecuteGotoImpl<true, true>(Thread* self, const DexFile::CodeItem* code_item,
271 ShadowFrame& shadow_frame, JValue result_register);
Mathieu Chartier90443472015-07-16 20:32:27 -0700272template<> SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogerse94652f2014-12-02 11:13:19 -0800273JValue ExecuteGotoImpl<false, true>(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200274 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertzfa888d02014-09-30 12:00:11 +0200275#endif
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700276
Ian Rogerse94652f2014-12-02 11:13:19 -0800277static JValue Execute(Thread* self, const DexFile::CodeItem* code_item, ShadowFrame& shadow_frame,
278 JValue result_register)
Mathieu Chartier90443472015-07-16 20:32:27 -0700279 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200280
Ian Rogerse94652f2014-12-02 11:13:19 -0800281static inline JValue Execute(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200282 ShadowFrame& shadow_frame, JValue result_register) {
buzbee1452bee2015-03-06 14:43:04 -0800283 DCHECK(!shadow_frame.GetMethod()->IsAbstract());
Ian Rogers848871b2013-08-05 10:56:33 -0700284 DCHECK(!shadow_frame.GetMethod()->IsNative());
buzbee734f3aa2016-01-28 14:20:06 -0800285 if (LIKELY(shadow_frame.GetDexPC() == 0)) { // Entering the method, but not via deoptimization.
286 if (kIsDebugBuild) {
287 self->AssertNoPendingException();
288 }
289 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
290 ArtMethod *method = shadow_frame.GetMethod();
291
292 if (UNLIKELY(instrumentation->HasMethodEntryListeners())) {
293 instrumentation->MethodEnterEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
294 method, 0);
295 }
296
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +0000297 jit::Jit* jit = Runtime::Current()->GetJit();
Nicolas Geoffray35122442016-03-02 12:05:30 +0000298 if (jit != nullptr && jit->CanInvokeCompiledCode(method)) {
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);
Bill Buzbeefd522f92016-02-11 22:37:42 +0000321 } else if (UNLIKELY(!Runtime::Current()->IsStarted())) {
322 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
323 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100324 } else {
buzbee1452bee2015-03-06 14:43:04 -0800325 while (true) {
Bill Buzbeefd522f92016-02-11 22:37:42 +0000326 // Mterp does not support all instrumentation/debugging.
327 if (MterpShouldSwitchInterpreters()) {
buzbee1452bee2015-03-06 14:43:04 -0800328#if !defined(__clang__)
329 return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register);
330#else
331 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
332 false);
333#endif
334 }
335 bool returned = ExecuteMterpImpl(self, code_item, &shadow_frame, &result_register);
336 if (returned) {
337 return result_register;
338 } else {
339 // Mterp didn't like that instruction. Single-step it with the reference interpreter.
buzbeed6b48db2016-01-28 15:48:55 -0800340 result_register = ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame,
buzbee1452bee2015-03-06 14:43:04 -0800341 result_register, true);
342 if (shadow_frame.GetDexPC() == DexFile::kDexNoIndex) {
343 // Single-stepped a return or an exception not handled locally. Return to caller.
buzbeed6b48db2016-01-28 15:48:55 -0800344 return result_register;
buzbee1452bee2015-03-06 14:43:04 -0800345 }
346 }
347 }
348 }
349 } else if (kInterpreterImplKind == kSwitchImplKind) {
350 if (transaction_active) {
351 return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register,
352 false);
353 } else {
354 return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register,
355 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100356 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200357 } else {
358 DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100359 if (transaction_active) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800360 return ExecuteGotoImpl<false, true>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100361 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800362 return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100363 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200364 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200365 } else {
366 // Enter the "with access check" interpreter.
buzbee1452bee2015-03-06 14:43:04 -0800367 if (kInterpreterImplKind == kMterpImplKind) {
368 // No access check variants for Mterp. Just use the switch version.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100369 if (transaction_active) {
buzbee1452bee2015-03-06 14:43:04 -0800370 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register,
371 false);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100372 } else {
buzbee1452bee2015-03-06 14:43:04 -0800373 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register,
374 false);
375 }
376 } else if (kInterpreterImplKind == kSwitchImplKind) {
377 if (transaction_active) {
378 return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register,
379 false);
380 } else {
381 return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register,
382 false);
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;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700408 if (code_item != nullptr) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700409 num_regs = code_item->registers_size_;
410 num_ins = code_item->ins_size_;
Alex Light9139e002015-10-09 15:59:48 -0700411 } else if (!method->IsInvokable()) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700412 self->EndAssertNoThreadSuspension(old_cause);
Alex Light9139e002015-10-09 15:59:48 -0700413 method->ThrowInvocationTimeError();
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();
Andreas Gampeb3025922015-09-01 14:45:00 -0700425 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -0700426 CREATE_SHADOW_FRAME(num_regs, last_shadow_frame, method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -0700427 ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get();
Jeff Hao66135192013-05-14 11:02:41 -0700428 self->PushShadowFrame(shadow_frame);
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700429
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700430 size_t cur_reg = num_regs - num_ins;
431 if (!method->IsStatic()) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700432 CHECK(receiver != nullptr);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800433 shadow_frame->SetVRegReference(cur_reg, receiver);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700434 ++cur_reg;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700435 }
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700436 uint32_t shorty_len = 0;
437 const char* shorty = method->GetShorty(&shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800438 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 -0700439 DCHECK_LT(shorty_pos + 1, shorty_len);
Jeff Hao5d917302013-02-27 17:57:33 -0800440 switch (shorty[shorty_pos + 1]) {
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700441 case 'L': {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800442 Object* o = reinterpret_cast<StackReference<Object>*>(&args[arg_pos])->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800443 shadow_frame->SetVRegReference(cur_reg, o);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700444 break;
445 }
Jeff Hao5d917302013-02-27 17:57:33 -0800446 case 'J': case 'D': {
447 uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos];
448 shadow_frame->SetVRegLong(cur_reg, wide_value);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700449 cur_reg++;
Jeff Hao5d917302013-02-27 17:57:33 -0800450 arg_pos++;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700451 break;
Jeff Hao5d917302013-02-27 17:57:33 -0800452 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700453 default:
Jeff Hao5d917302013-02-27 17:57:33 -0800454 shadow_frame->SetVReg(cur_reg, args[arg_pos]);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700455 break;
456 }
457 }
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800458 self->EndAssertNoThreadSuspension(old_cause);
459 // Do this after populating the shadow frame in case EnsureInitialized causes a GC.
Ian Rogers6c5cb212014-06-18 16:07:20 -0700460 if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800461 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700462 StackHandleScope<1> hs(self);
463 Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass()));
Ian Rogers7b078e82014-09-10 14:44:24 -0700464 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800465 CHECK(self->IsExceptionPending());
466 self->PopShadowFrame();
467 return;
468 }
469 }
Ian Rogers64b6d142012-10-29 16:34:15 -0700470 if (LIKELY(!method->IsNative())) {
Ian Rogerse94652f2014-12-02 11:13:19 -0800471 JValue r = Execute(self, code_item, *shadow_frame, JValue());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700472 if (result != nullptr) {
Jeff Hao6474d192013-03-26 14:08:09 -0700473 *result = r;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700474 }
475 } else {
Ian Rogers64b6d142012-10-29 16:34:15 -0700476 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
477 // generated stub) except during testing and image writing.
Mathieu Chartier92246bb2014-02-25 18:22:39 -0800478 // Update args to be the args in the shadow frame since the input ones could hold stale
479 // references pointers due to moving GC.
480 args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1);
Ian Rogers64b6d142012-10-29 16:34:15 -0700481 if (!Runtime::Current()->IsStarted()) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700482 UnstartedRuntime::Jni(self, method, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700483 } else {
Jeff Hao6474d192013-03-26 14:08:09 -0700484 InterpreterJni(self, method, shorty, receiver, args, result);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700485 }
486 }
487 self->PopShadowFrame();
488}
489
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100490void EnterInterpreterFromDeoptimize(Thread* self,
491 ShadowFrame* shadow_frame,
492 bool from_code,
493 JValue* ret_val)
Mathieu Chartier90443472015-07-16 20:32:27 -0700494 SHARED_REQUIRES(Locks::mutator_lock_) {
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800495 JValue value;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700496 // Set value to last known result in case the shadow frame chain is empty.
497 value.SetJ(ret_val->GetJ());
Sebastien Hertz520633b2015-09-08 17:03:36 +0200498 // Are we executing the first shadow frame?
499 bool first = true;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700500 while (shadow_frame != nullptr) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800501 self->SetTopOfShadowStack(shadow_frame);
Ian Rogerse94652f2014-12-02 11:13:19 -0800502 const DexFile::CodeItem* code_item = shadow_frame->GetMethod()->GetCodeItem();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100503 const uint32_t dex_pc = shadow_frame->GetDexPC();
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100504 uint32_t new_dex_pc = dex_pc;
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100505 if (UNLIKELY(self->IsExceptionPending())) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200506 // If we deoptimize from the QuickExceptionHandler, we already reported the exception to
507 // the instrumentation. To prevent from reporting it a second time, we simply pass a
508 // null Instrumentation*.
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100509 const instrumentation::Instrumentation* const instrumentation =
Sebastien Hertz520633b2015-09-08 17:03:36 +0200510 first ? nullptr : Runtime::Current()->GetInstrumentation();
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100511 uint32_t found_dex_pc = FindNextInstructionFollowingException(self, *shadow_frame, dex_pc,
512 instrumentation);
513 new_dex_pc = found_dex_pc; // the dex pc of a matching catch handler
514 // or DexFile::kDexNoIndex if there is none.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100515 } else if (!from_code) {
516 // For the debugger and full deoptimization stack, we must go past the invoke
517 // instruction, as it already executed.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700518 // TODO: should be tested more once b/17586779 is fixed.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100519 const Instruction* instr = Instruction::At(&code_item->insns_[dex_pc]);
520 DCHECK(instr->IsInvoke());
521 new_dex_pc = dex_pc + instr->SizeInCodeUnits();
522 } else {
523 // Nothing to do, the dex_pc is the one at which the code requested
524 // the deoptimization.
Sebastien Hertz270a0e12015-01-16 19:49:09 +0100525 }
526 if (new_dex_pc != DexFile::kDexNoIndex) {
527 shadow_frame->SetDexPC(new_dex_pc);
528 value = Execute(self, code_item, *shadow_frame, value);
529 }
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800530 ShadowFrame* old_frame = shadow_frame;
531 shadow_frame = shadow_frame->GetLink();
Christopher Ferris241a9582015-04-27 15:19:41 -0700532 ShadowFrame::DeleteDeoptimizedFrame(old_frame);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100533 // Following deoptimizations of shadow frames must pass the invoke instruction.
534 from_code = false;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200535 first = false;
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800536 }
537 ret_val->SetJ(value.GetJ());
538}
539
Ian Rogerse94652f2014-12-02 11:13:19 -0800540JValue EnterInterpreterFromEntryPoint(Thread* self, const DexFile::CodeItem* code_item,
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700541 ShadowFrame* shadow_frame) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700542 DCHECK_EQ(self, Thread::Current());
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100543 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
544 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Ian Rogersf3e98552013-03-20 15:49:49 -0700545 ThrowStackOverflowError(self);
546 return JValue();
547 }
548
Ian Rogerse94652f2014-12-02 11:13:19 -0800549 return Execute(self, code_item, *shadow_frame, JValue());
Ian Rogers7db619b2013-01-16 18:35:48 -0800550}
551
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700552void ArtInterpreterToInterpreterBridge(Thread* self, const DexFile::CodeItem* code_item,
553 ShadowFrame* shadow_frame, JValue* result) {
Nicolas Geoffray535a3fb2014-07-22 15:17:38 +0100554 bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks();
555 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) {
Jeff Hao16743632013-05-08 10:59:04 -0700556 ThrowStackOverflowError(self);
Jeff Hao69510672013-05-21 17:34:55 -0700557 return;
Jeff Hao16743632013-05-08 10:59:04 -0700558 }
559
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700560 self->PushShadowFrame(shadow_frame);
Alex Lighteb7c1442015-08-31 13:17:42 -0700561 ArtMethod* method = shadow_frame->GetMethod();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200562 // Ensure static methods are initialized.
Alex Lighteb7c1442015-08-31 13:17:42 -0700563 const bool is_static = method->IsStatic();
Ian Rogerse94652f2014-12-02 11:13:19 -0800564 if (is_static) {
Alex Lighteb7c1442015-08-31 13:17:42 -0700565 mirror::Class* declaring_class = method->GetDeclaringClass();
Ian Rogers6c5cb212014-06-18 16:07:20 -0700566 if (UNLIKELY(!declaring_class->IsInitialized())) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700567 StackHandleScope<1> hs(self);
568 HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class));
569 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(
Ian Rogers7b078e82014-09-10 14:44:24 -0700570 self, h_declaring_class, true, true))) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700571 DCHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700572 self->PopShadowFrame();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200573 return;
574 }
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700575 CHECK(h_declaring_class->IsInitializing());
Jeff Hao16743632013-05-08 10:59:04 -0700576 }
Jeff Hao16743632013-05-08 10:59:04 -0700577 }
Jeff Hao16743632013-05-08 10:59:04 -0700578
Ian Rogerse94652f2014-12-02 11:13:19 -0800579 if (LIKELY(!shadow_frame->GetMethod()->IsNative())) {
580 result->SetJ(Execute(self, code_item, *shadow_frame, JValue()).GetJ());
Jeff Hao16743632013-05-08 10:59:04 -0700581 } else {
582 // We don't expect to be asked to interpret native code (which is entered via a JNI compiler
583 // generated stub) except during testing and image writing.
584 CHECK(!Runtime::Current()->IsStarted());
Ian Rogerse94652f2014-12-02 11:13:19 -0800585 Object* receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0);
586 uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1);
Andreas Gampe799681b2015-05-15 19:24:12 -0700587 UnstartedRuntime::Jni(self, shadow_frame->GetMethod(), receiver, args, result);
Jeff Hao16743632013-05-08 10:59:04 -0700588 }
589
590 self->PopShadowFrame();
Jeff Hao16743632013-05-08 10:59:04 -0700591}
592
buzbee1452bee2015-03-06 14:43:04 -0800593void CheckInterpreterAsmConstants() {
594 CheckMterpAsmConstants();
595}
596
597void InitInterpreterTls(Thread* self) {
598 InitMterpTls(self);
599}
600
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700601} // namespace interpreter
602} // namespace art