Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1 | /* |
| 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 Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 17 | #include "interpreter.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 18 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 19 | #include <limits> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 20 | |
Andreas Gampe | 580667b | 2017-10-23 11:20:39 -0700 | [diff] [blame] | 21 | #include "common_dex_operations.h" |
Andreas Gampe | 103992b | 2016-01-04 15:32:43 -0800 | [diff] [blame] | 22 | #include "common_throws.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 23 | #include "dex/dex_file_types.h" |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 24 | #include "interpreter_common.h" |
Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [diff] [blame] | 25 | #include "interpreter_mterp_impl.h" |
| 26 | #include "interpreter_switch_impl.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 27 | #include "jit/jit.h" |
| 28 | #include "jit/jit_code_cache.h" |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 29 | #include "jvalue-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 30 | #include "mirror/string-inl.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 31 | #include "mterp/mterp.h" |
Andreas Gampe | 373a9b5 | 2017-10-18 09:01:57 -0700 | [diff] [blame] | 32 | #include "nativehelper/scoped_local_ref.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 33 | #include "scoped_thread_state_change-inl.h" |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 34 | #include "shadow_frame-inl.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 35 | #include "stack.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 36 | #include "thread-inl.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 37 | #include "unstarted_runtime.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 38 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 39 | namespace art { |
| 40 | namespace interpreter { |
| 41 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 42 | ALWAYS_INLINE static ObjPtr<mirror::Object> ObjArg(uint32_t arg) |
| 43 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 44 | return ObjPtr<mirror::Object>(reinterpret_cast<mirror::Object*>(arg)); |
| 45 | } |
| 46 | |
| 47 | static void InterpreterJni(Thread* self, |
| 48 | ArtMethod* method, |
| 49 | const StringPiece& shorty, |
| 50 | ObjPtr<mirror::Object> receiver, |
| 51 | uint32_t* args, |
| 52 | JValue* result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 53 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 54 | // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler, |
| 55 | // it should be removed and JNI compiled stubs used instead. |
| 56 | ScopedObjectAccessUnchecked soa(self); |
| 57 | if (method->IsStatic()) { |
| 58 | if (shorty == "L") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 59 | using fntype = jobject(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 60 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 61 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 62 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 63 | jobject jresult; |
| 64 | { |
| 65 | ScopedThreadStateChange tsc(self, kNative); |
| 66 | jresult = fn(soa.Env(), klass.get()); |
| 67 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 68 | result->SetL(soa.Decode<mirror::Object>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 69 | } else if (shorty == "V") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 70 | using fntype = void(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 71 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 72 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 73 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 74 | ScopedThreadStateChange tsc(self, kNative); |
| 75 | fn(soa.Env(), klass.get()); |
| 76 | } else if (shorty == "Z") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 77 | using fntype = jboolean(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 78 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 79 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 80 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 81 | ScopedThreadStateChange tsc(self, kNative); |
| 82 | result->SetZ(fn(soa.Env(), klass.get())); |
| 83 | } else if (shorty == "BI") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 84 | using fntype = jbyte(JNIEnv*, jclass, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 85 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 86 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 87 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 88 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 89 | result->SetB(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 90 | } else if (shorty == "II") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 91 | using fntype = jint(JNIEnv*, jclass, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 92 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 93 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 94 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 95 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 96 | result->SetI(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 97 | } else if (shorty == "LL") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 98 | using fntype = jobject(JNIEnv*, jclass, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 99 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 100 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 101 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 102 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 103 | soa.AddLocalReference<jobject>(ObjArg(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 104 | jobject jresult; |
| 105 | { |
| 106 | ScopedThreadStateChange tsc(self, kNative); |
| 107 | jresult = fn(soa.Env(), klass.get(), arg0.get()); |
| 108 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 109 | result->SetL(soa.Decode<mirror::Object>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 110 | } else if (shorty == "IIZ") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 111 | using fntype = jint(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 112 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 113 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 114 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 115 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 116 | result->SetI(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 117 | } else if (shorty == "ILI") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 118 | using fntype = jint(JNIEnv*, jclass, jobject, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 119 | fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>( |
| 120 | method->GetEntryPointFromJni())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 121 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 122 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 123 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 124 | soa.AddLocalReference<jobject>(ObjArg(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 125 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 126 | result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 127 | } else if (shorty == "SIZ") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 128 | using fntype = jshort(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 129 | fntype* const fn = |
| 130 | reinterpret_cast<fntype*>(const_cast<void*>(method->GetEntryPointFromJni())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 131 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 132 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 133 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 134 | result->SetS(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 135 | } else if (shorty == "VIZ") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 136 | using fntype = void(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 137 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 138 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 139 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 140 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 141 | fn(soa.Env(), klass.get(), args[0], args[1]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 142 | } else if (shorty == "ZLL") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 143 | using fntype = jboolean(JNIEnv*, jclass, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 144 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 145 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 146 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 147 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 148 | soa.AddLocalReference<jobject>(ObjArg(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 149 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 150 | soa.AddLocalReference<jobject>(ObjArg(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 151 | ScopedThreadStateChange tsc(self, kNative); |
| 152 | result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get())); |
| 153 | } else if (shorty == "ZILL") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 154 | using fntype = jboolean(JNIEnv*, jclass, jint, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 155 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 156 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 157 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 158 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 159 | soa.AddLocalReference<jobject>(ObjArg(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 160 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 161 | soa.AddLocalReference<jobject>(ObjArg(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 162 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 163 | result->SetZ(fn(soa.Env(), klass.get(), args[0], arg1.get(), arg2.get())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 164 | } else if (shorty == "VILII") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 165 | using fntype = void(JNIEnv*, jclass, jint, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 166 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 167 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 168 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 169 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 170 | soa.AddLocalReference<jobject>(ObjArg(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 171 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 172 | fn(soa.Env(), klass.get(), args[0], arg1.get(), args[2], args[3]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 173 | } else if (shorty == "VLILII") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 174 | using fntype = void(JNIEnv*, jclass, jobject, jint, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 175 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 176 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 177 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 178 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 179 | soa.AddLocalReference<jobject>(ObjArg(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 180 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 181 | soa.AddLocalReference<jobject>(ObjArg(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 182 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 183 | fn(soa.Env(), klass.get(), arg0.get(), args[1], arg2.get(), args[3], args[4]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 184 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 185 | LOG(FATAL) << "Do something with static native method: " << method->PrettyMethod() |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 186 | << " shorty: " << shorty; |
| 187 | } |
| 188 | } else { |
| 189 | if (shorty == "L") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 190 | using fntype = jobject(JNIEnv*, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 191 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 192 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 193 | soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 194 | jobject jresult; |
| 195 | { |
| 196 | ScopedThreadStateChange tsc(self, kNative); |
| 197 | jresult = fn(soa.Env(), rcvr.get()); |
| 198 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 199 | result->SetL(soa.Decode<mirror::Object>(jresult)); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 200 | } else if (shorty == "V") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 201 | using fntype = void(JNIEnv*, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 202 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 203 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 204 | soa.AddLocalReference<jobject>(receiver)); |
| 205 | ScopedThreadStateChange tsc(self, kNative); |
| 206 | fn(soa.Env(), rcvr.get()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 207 | } else if (shorty == "LL") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 208 | using fntype = jobject(JNIEnv*, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 209 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 210 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 211 | soa.AddLocalReference<jobject>(receiver)); |
| 212 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 213 | soa.AddLocalReference<jobject>(ObjArg(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 214 | jobject jresult; |
| 215 | { |
| 216 | ScopedThreadStateChange tsc(self, kNative); |
| 217 | jresult = fn(soa.Env(), rcvr.get(), arg0.get()); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 218 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 219 | result->SetL(soa.Decode<mirror::Object>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 220 | ScopedThreadStateChange tsc(self, kNative); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 221 | } else if (shorty == "III") { |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 222 | using fntype = jint(JNIEnv*, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 223 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 224 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 225 | soa.AddLocalReference<jobject>(receiver)); |
| 226 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 227 | result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 228 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 229 | LOG(FATAL) << "Do something with native method: " << method->PrettyMethod() |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 230 | << " shorty: " << shorty; |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 235 | enum InterpreterImplKind { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 236 | kSwitchImplKind, // Switch-based interpreter implementation. |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 237 | kMterpImplKind // Assembly interpreter |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 238 | }; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 239 | |
David Srbecky | 8ed45c8 | 2018-11-08 15:08:57 +0000 | [diff] [blame^] | 240 | #if ART_USE_CXX_INTERPRETER |
| 241 | static constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImplKind; |
| 242 | #else |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 243 | static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind; |
David Srbecky | 8ed45c8 | 2018-11-08 15:08:57 +0000 | [diff] [blame^] | 244 | #endif |
Alexey Frunze | 00b53b7 | 2016-02-02 20:25:45 -0800 | [diff] [blame] | 245 | |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 246 | static inline JValue Execute( |
| 247 | Thread* self, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 248 | const CodeItemDataAccessor& accessor, |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 249 | ShadowFrame& shadow_frame, |
| 250 | JValue result_register, |
Vladimir Marko | fe94875 | 2018-03-23 18:11:43 +0000 | [diff] [blame] | 251 | bool stay_in_interpreter = false, |
| 252 | bool from_deoptimize = false) REQUIRES_SHARED(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 253 | DCHECK(!shadow_frame.GetMethod()->IsAbstract()); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 254 | DCHECK(!shadow_frame.GetMethod()->IsNative()); |
David Srbecky | cb4f09e | 2018-10-21 08:45:22 +0100 | [diff] [blame] | 255 | |
| 256 | // Check that we are using the right interpreter. |
| 257 | if (kIsDebugBuild && self->UseMterp() != CanUseMterp()) { |
| 258 | // The flag might be currently being updated on all threads. Retry with lock. |
| 259 | MutexLock tll_mu(self, *Locks::thread_list_lock_); |
| 260 | DCHECK_EQ(self->UseMterp(), CanUseMterp()); |
| 261 | } |
| 262 | |
Vladimir Marko | fe94875 | 2018-03-23 18:11:43 +0000 | [diff] [blame] | 263 | if (LIKELY(!from_deoptimize)) { // Entering the method, but not via deoptimization. |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 264 | if (kIsDebugBuild) { |
Vladimir Marko | fe94875 | 2018-03-23 18:11:43 +0000 | [diff] [blame] | 265 | CHECK_EQ(shadow_frame.GetDexPC(), 0u); |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 266 | self->AssertNoPendingException(); |
| 267 | } |
| 268 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 269 | ArtMethod *method = shadow_frame.GetMethod(); |
| 270 | |
| 271 | if (UNLIKELY(instrumentation->HasMethodEntryListeners())) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 272 | instrumentation->MethodEnterEvent(self, |
| 273 | shadow_frame.GetThisObject(accessor.InsSize()), |
| 274 | method, |
| 275 | 0); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 276 | if (UNLIKELY(shadow_frame.GetForcePopFrame())) { |
| 277 | // The caller will retry this invoke. Just return immediately without any value. |
| 278 | DCHECK(Runtime::Current()->AreNonStandardExitsEnabled()); |
| 279 | DCHECK(PrevFrameWillRetry(self, shadow_frame)); |
| 280 | return JValue(); |
| 281 | } |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 282 | if (UNLIKELY(self->IsExceptionPending())) { |
| 283 | instrumentation->MethodUnwindEvent(self, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 284 | shadow_frame.GetThisObject(accessor.InsSize()), |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 285 | method, |
| 286 | 0); |
| 287 | return JValue(); |
| 288 | } |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 291 | if (!stay_in_interpreter) { |
| 292 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 293 | if (jit != nullptr) { |
| 294 | jit->MethodEntered(self, shadow_frame.GetMethod()); |
| 295 | if (jit->CanInvokeCompiledCode(method)) { |
| 296 | JValue result; |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 297 | |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 298 | // Pop the shadow frame before calling into compiled code. |
| 299 | self->PopShadowFrame(); |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 300 | // Calculate the offset of the first input reg. The input registers are in the high regs. |
| 301 | // It's ok to access the code item here since JIT code will have been touched by the |
| 302 | // interpreter and compiler already. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 303 | uint16_t arg_offset = accessor.RegistersSize() - accessor.InsSize(); |
Jeff Hao | 5ea8413 | 2017-05-05 16:59:29 -0700 | [diff] [blame] | 304 | ArtInterpreterToCompiledCodeBridge(self, nullptr, &shadow_frame, arg_offset, &result); |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 305 | // Push the shadow frame back as the caller will expect it. |
| 306 | self->PushShadowFrame(&shadow_frame); |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 307 | |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 308 | return result; |
| 309 | } |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame] | 310 | } |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Andreas Gampe | 580667b | 2017-10-23 11:20:39 -0700 | [diff] [blame] | 314 | ArtMethod* method = shadow_frame.GetMethod(); |
| 315 | |
| 316 | DCheckStaticState(self, method); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 317 | |
Andreas Gampe | 56fdd0e | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 318 | // Lock counting is a special version of accessibility checks, and for simplicity and |
| 319 | // reduction of template parameters, we gate it behind access-checks mode. |
Andreas Gampe | 56fdd0e | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 320 | DCHECK(!method->SkipAccessChecks() || !method->MustCountLocks()); |
| 321 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 322 | bool transaction_active = Runtime::Current()->IsActiveTransaction(); |
Andreas Gampe | 56fdd0e | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 323 | if (LIKELY(method->SkipAccessChecks())) { |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 324 | // Enter the "without access check" interpreter. |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 325 | if (kInterpreterImplKind == kMterpImplKind) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 326 | if (transaction_active) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 327 | // No Mterp variant - just use the switch interpreter. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 328 | return ExecuteSwitchImpl<false, true>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 329 | false); |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 330 | } else if (UNLIKELY(!Runtime::Current()->IsStarted())) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 331 | return ExecuteSwitchImpl<false, false>(self, accessor, shadow_frame, result_register, |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 332 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 333 | } else { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 334 | while (true) { |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 335 | // Mterp does not support all instrumentation/debugging. |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 336 | if (!self->UseMterp()) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 337 | return ExecuteSwitchImpl<false, false>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 338 | false); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 339 | } |
Mathieu Chartier | fc9555d | 2017-11-05 16:32:19 -0800 | [diff] [blame] | 340 | bool returned = ExecuteMterpImpl(self, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 341 | accessor.Insns(), |
Mathieu Chartier | fc9555d | 2017-11-05 16:32:19 -0800 | [diff] [blame] | 342 | &shadow_frame, |
| 343 | &result_register); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 344 | if (returned) { |
| 345 | return result_register; |
| 346 | } else { |
| 347 | // Mterp didn't like that instruction. Single-step it with the reference interpreter. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 348 | result_register = ExecuteSwitchImpl<false, false>(self, accessor, shadow_frame, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 349 | result_register, true); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 350 | if (shadow_frame.GetDexPC() == dex::kDexNoIndex) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 351 | // Single-stepped a return or an exception not handled locally. Return to caller. |
buzbee | d6b48db | 2016-01-28 15:48:55 -0800 | [diff] [blame] | 352 | return result_register; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
buzbee | f61df9b | 2016-09-07 07:12:29 -0700 | [diff] [blame] | 357 | } else { |
| 358 | DCHECK_EQ(kInterpreterImplKind, kSwitchImplKind); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 359 | if (transaction_active) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 360 | return ExecuteSwitchImpl<false, true>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 361 | false); |
| 362 | } else { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 363 | return ExecuteSwitchImpl<false, false>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 364 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 365 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 366 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 367 | } else { |
| 368 | // Enter the "with access check" interpreter. |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 369 | if (kInterpreterImplKind == kMterpImplKind) { |
| 370 | // No access check variants for Mterp. Just use the switch version. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 371 | if (transaction_active) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 372 | return ExecuteSwitchImpl<true, true>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 373 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 374 | } else { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 375 | return ExecuteSwitchImpl<true, false>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 376 | false); |
| 377 | } |
buzbee | f61df9b | 2016-09-07 07:12:29 -0700 | [diff] [blame] | 378 | } else { |
| 379 | DCHECK_EQ(kInterpreterImplKind, kSwitchImplKind); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 380 | if (transaction_active) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 381 | return ExecuteSwitchImpl<true, true>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 382 | false); |
| 383 | } else { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 384 | return ExecuteSwitchImpl<true, false>(self, accessor, shadow_frame, result_register, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 385 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 386 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 387 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 391 | void EnterInterpreterFromInvoke(Thread* self, |
| 392 | ArtMethod* method, |
| 393 | ObjPtr<mirror::Object> receiver, |
| 394 | uint32_t* args, |
| 395 | JValue* result, |
Aart Bik | 0122320 | 2016-05-05 15:10:42 -0700 | [diff] [blame] | 396 | bool stay_in_interpreter) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 397 | DCHECK_EQ(self, Thread::Current()); |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 398 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 399 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 400 | ThrowStackOverflowError(self); |
| 401 | return; |
| 402 | } |
| 403 | |
Alex Light | db01a09 | 2017-04-03 15:39:55 -0700 | [diff] [blame] | 404 | // This can happen if we are in forced interpreter mode and an obsolete method is called using |
| 405 | // reflection. |
| 406 | if (UNLIKELY(method->IsObsolete())) { |
| 407 | ThrowInternalError("Attempting to invoke obsolete version of '%s'.", |
| 408 | method->PrettyMethod().c_str()); |
| 409 | return; |
| 410 | } |
| 411 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 412 | const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke"); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 413 | CodeItemDataAccessor accessor(method->DexInstructionData()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 414 | uint16_t num_regs; |
| 415 | uint16_t num_ins; |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 416 | if (accessor.HasCodeItem()) { |
| 417 | num_regs = accessor.RegistersSize(); |
| 418 | num_ins = accessor.InsSize(); |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 419 | } else if (!method->IsInvokable()) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 420 | self->EndAssertNoThreadSuspension(old_cause); |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 421 | method->ThrowInvocationTimeError(); |
jeffhao | 0a9bb73 | 2012-11-26 12:28:49 -0800 | [diff] [blame] | 422 | return; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 423 | } else { |
| 424 | DCHECK(method->IsNative()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 425 | num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 426 | if (!method->IsStatic()) { |
| 427 | num_regs++; |
| 428 | num_ins++; |
| 429 | } |
| 430 | } |
| 431 | // Set up shadow frame with matching number of reference slots to vregs. |
| 432 | ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame(); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 433 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 434 | CREATE_SHADOW_FRAME(num_regs, last_shadow_frame, method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 435 | ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get(); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 436 | self->PushShadowFrame(shadow_frame); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 437 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 438 | size_t cur_reg = num_regs - num_ins; |
| 439 | if (!method->IsStatic()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 440 | CHECK(receiver != nullptr); |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 441 | shadow_frame->SetVRegReference(cur_reg, receiver); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 442 | ++cur_reg; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 443 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 444 | uint32_t shorty_len = 0; |
| 445 | const char* shorty = method->GetShorty(&shorty_len); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 446 | for (size_t shorty_pos = 0, arg_pos = 0; cur_reg < num_regs; ++shorty_pos, ++arg_pos, cur_reg++) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 447 | DCHECK_LT(shorty_pos + 1, shorty_len); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 448 | switch (shorty[shorty_pos + 1]) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 449 | case 'L': { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 450 | ObjPtr<mirror::Object> o = |
| 451 | reinterpret_cast<StackReference<mirror::Object>*>(&args[arg_pos])->AsMirrorPtr(); |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 452 | shadow_frame->SetVRegReference(cur_reg, o); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 453 | break; |
| 454 | } |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 455 | case 'J': case 'D': { |
| 456 | uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos]; |
| 457 | shadow_frame->SetVRegLong(cur_reg, wide_value); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 458 | cur_reg++; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 459 | arg_pos++; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 460 | break; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 461 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 462 | default: |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 463 | shadow_frame->SetVReg(cur_reg, args[arg_pos]); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 464 | break; |
| 465 | } |
| 466 | } |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 467 | self->EndAssertNoThreadSuspension(old_cause); |
| 468 | // Do this after populating the shadow frame in case EnsureInitialized causes a GC. |
Ian Rogers | 6c5cb21 | 2014-06-18 16:07:20 -0700 | [diff] [blame] | 469 | if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) { |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 470 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 471 | StackHandleScope<1> hs(self); |
| 472 | Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass())); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 473 | if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) { |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 474 | CHECK(self->IsExceptionPending()); |
| 475 | self->PopShadowFrame(); |
| 476 | return; |
| 477 | } |
| 478 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 479 | if (LIKELY(!method->IsNative())) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 480 | JValue r = Execute(self, accessor, *shadow_frame, JValue(), stay_in_interpreter); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 481 | if (result != nullptr) { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 482 | *result = r; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 483 | } |
| 484 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 485 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 486 | // generated stub) except during testing and image writing. |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 487 | // Update args to be the args in the shadow frame since the input ones could hold stale |
| 488 | // references pointers due to moving GC. |
| 489 | args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 490 | if (!Runtime::Current()->IsStarted()) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 491 | UnstartedRuntime::Jni(self, method, receiver.Ptr(), args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 492 | } else { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 493 | InterpreterJni(self, method, shorty, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | self->PopShadowFrame(); |
| 497 | } |
| 498 | |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 499 | static int16_t GetReceiverRegisterForStringInit(const Instruction* instr) { |
| 500 | DCHECK(instr->Opcode() == Instruction::INVOKE_DIRECT_RANGE || |
| 501 | instr->Opcode() == Instruction::INVOKE_DIRECT); |
| 502 | return (instr->Opcode() == Instruction::INVOKE_DIRECT_RANGE) ? |
| 503 | instr->VRegC_3rc() : instr->VRegC_35c(); |
| 504 | } |
| 505 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 506 | void EnterInterpreterFromDeoptimize(Thread* self, |
| 507 | ShadowFrame* shadow_frame, |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 508 | JValue* ret_val, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 509 | bool from_code, |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 510 | DeoptimizationMethodType deopt_method_type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 511 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 512 | JValue value; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 513 | // Set value to last known result in case the shadow frame chain is empty. |
| 514 | value.SetJ(ret_val->GetJ()); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 515 | // How many frames we have executed. |
| 516 | size_t frame_cnt = 0; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 517 | while (shadow_frame != nullptr) { |
Andreas Gampe | 56fdd0e | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 518 | // We do not want to recover lock state for lock counting when deoptimizing. Currently, |
| 519 | // the compiler should not have compiled a method that failed structured-locking checks. |
| 520 | DCHECK(!shadow_frame->GetMethod()->MustCountLocks()); |
| 521 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 522 | self->SetTopOfShadowStack(shadow_frame); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 523 | CodeItemDataAccessor accessor(shadow_frame->GetMethod()->DexInstructionData()); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 524 | const uint32_t dex_pc = shadow_frame->GetDexPC(); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 525 | uint32_t new_dex_pc = dex_pc; |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 526 | if (UNLIKELY(self->IsExceptionPending())) { |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 527 | // If we deoptimize from the QuickExceptionHandler, we already reported the exception to |
| 528 | // the instrumentation. To prevent from reporting it a second time, we simply pass a |
| 529 | // null Instrumentation*. |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 530 | const instrumentation::Instrumentation* const instrumentation = |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 531 | frame_cnt == 0 ? nullptr : Runtime::Current()->GetInstrumentation(); |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 532 | new_dex_pc = MoveToExceptionHandler( |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 533 | self, *shadow_frame, instrumentation) ? shadow_frame->GetDexPC() : dex::kDexNoIndex; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 534 | } else if (!from_code) { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 535 | // Deoptimization is not called from code directly. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 536 | const Instruction* instr = &accessor.InstructionAt(dex_pc); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 537 | if (deopt_method_type == DeoptimizationMethodType::kKeepDexPc || |
| 538 | shadow_frame->GetForceRetryInstruction()) { |
| 539 | DCHECK(frame_cnt == 0 || (frame_cnt == 1 && shadow_frame->GetForceRetryInstruction())) |
| 540 | << "frame_cnt: " << frame_cnt |
| 541 | << " force-retry: " << shadow_frame->GetForceRetryInstruction(); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 542 | // Need to re-execute the dex instruction. |
| 543 | // (1) An invocation might be split into class initialization and invoke. |
| 544 | // In this case, the invoke should not be skipped. |
| 545 | // (2) A suspend check should also execute the dex instruction at the |
| 546 | // corresponding dex pc. |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 547 | // If the ForceRetryInstruction bit is set this must be the second frame (the first being |
| 548 | // the one that is being popped). |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 549 | DCHECK_EQ(new_dex_pc, dex_pc); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 550 | shadow_frame->SetForceRetryInstruction(false); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 551 | } else if (instr->Opcode() == Instruction::MONITOR_ENTER || |
| 552 | instr->Opcode() == Instruction::MONITOR_EXIT) { |
| 553 | DCHECK(deopt_method_type == DeoptimizationMethodType::kDefault); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 554 | DCHECK_EQ(frame_cnt, 0u); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 555 | // Non-idempotent dex instruction should not be re-executed. |
| 556 | // On the other hand, if a MONITOR_ENTER is at the dex_pc of a suspend |
| 557 | // check, that MONITOR_ENTER should be executed. That case is handled |
| 558 | // above. |
| 559 | new_dex_pc = dex_pc + instr->SizeInCodeUnits(); |
| 560 | } else if (instr->IsInvoke()) { |
| 561 | DCHECK(deopt_method_type == DeoptimizationMethodType::kDefault); |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 562 | if (IsStringInit(instr, shadow_frame->GetMethod())) { |
| 563 | uint16_t this_obj_vreg = GetReceiverRegisterForStringInit(instr); |
| 564 | // Move the StringFactory.newStringFromChars() result into the register representing |
| 565 | // "this object" when invoking the string constructor in the original dex instruction. |
| 566 | // Also move the result into all aliases. |
| 567 | DCHECK(value.GetL()->IsString()); |
| 568 | SetStringInitValueToAllAliases(shadow_frame, this_obj_vreg, value); |
| 569 | // Calling string constructor in the original dex code doesn't generate a result value. |
| 570 | value.SetJ(0); |
| 571 | } |
Mingyao Yang | 504a690 | 2016-04-28 16:23:01 -0700 | [diff] [blame] | 572 | new_dex_pc = dex_pc + instr->SizeInCodeUnits(); |
| 573 | } else if (instr->Opcode() == Instruction::NEW_INSTANCE) { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 574 | // A NEW_INSTANCE is simply re-executed, including |
| 575 | // "new-instance String" which is compiled into a call into |
| 576 | // StringFactory.newEmptyString(). |
| 577 | DCHECK_EQ(new_dex_pc, dex_pc); |
Mingyao Yang | 504a690 | 2016-04-28 16:23:01 -0700 | [diff] [blame] | 578 | } else { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 579 | DCHECK(deopt_method_type == DeoptimizationMethodType::kDefault); |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 580 | DCHECK_EQ(frame_cnt, 0u); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 581 | // By default, we re-execute the dex instruction since if they are not |
| 582 | // an invoke, so that we don't have to decode the dex instruction to move |
| 583 | // result into the right vreg. All slow paths have been audited to be |
| 584 | // idempotent except monitor-enter/exit and invocation stubs. |
| 585 | // TODO: move result and advance dex pc. That also requires that we |
| 586 | // can tell the return type of a runtime method, possibly by decoding |
| 587 | // the dex instruction at the caller. |
| 588 | DCHECK_EQ(new_dex_pc, dex_pc); |
Mingyao Yang | 504a690 | 2016-04-28 16:23:01 -0700 | [diff] [blame] | 589 | } |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 590 | } else { |
| 591 | // Nothing to do, the dex_pc is the one at which the code requested |
| 592 | // the deoptimization. |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 593 | DCHECK_EQ(frame_cnt, 0u); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 594 | DCHECK_EQ(new_dex_pc, dex_pc); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 595 | } |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 596 | if (new_dex_pc != dex::kDexNoIndex) { |
Nicolas Geoffray | 9597424 | 2017-09-04 08:45:51 +0000 | [diff] [blame] | 597 | shadow_frame->SetDexPC(new_dex_pc); |
Vladimir Marko | fe94875 | 2018-03-23 18:11:43 +0000 | [diff] [blame] | 598 | value = Execute(self, |
| 599 | accessor, |
| 600 | *shadow_frame, |
| 601 | value, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 602 | /* stay_in_interpreter= */ true, |
| 603 | /* from_deoptimize= */ true); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 604 | } |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 605 | ShadowFrame* old_frame = shadow_frame; |
| 606 | shadow_frame = shadow_frame->GetLink(); |
Christopher Ferris | 241a958 | 2015-04-27 15:19:41 -0700 | [diff] [blame] | 607 | ShadowFrame::DeleteDeoptimizedFrame(old_frame); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 608 | // Following deoptimizations of shadow frames must be at invocation point |
| 609 | // and should advance dex pc past the invoke instruction. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 610 | from_code = false; |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 611 | deopt_method_type = DeoptimizationMethodType::kDefault; |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 612 | frame_cnt++; |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 613 | } |
| 614 | ret_val->SetJ(value.GetJ()); |
| 615 | } |
| 616 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 617 | JValue EnterInterpreterFromEntryPoint(Thread* self, const CodeItemDataAccessor& accessor, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 618 | ShadowFrame* shadow_frame) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 619 | DCHECK_EQ(self, Thread::Current()); |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 620 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 621 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 622 | ThrowStackOverflowError(self); |
| 623 | return JValue(); |
| 624 | } |
| 625 | |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 626 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 627 | if (jit != nullptr) { |
| 628 | jit->NotifyCompiledCodeToInterpreterTransition(self, shadow_frame->GetMethod()); |
| 629 | } |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 630 | return Execute(self, accessor, *shadow_frame, JValue()); |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 633 | void ArtInterpreterToInterpreterBridge(Thread* self, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 634 | const CodeItemDataAccessor& accessor, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 635 | ShadowFrame* shadow_frame, |
| 636 | JValue* result) { |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 637 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 638 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 639 | ThrowStackOverflowError(self); |
Jeff Hao | 6951067 | 2013-05-21 17:34:55 -0700 | [diff] [blame] | 640 | return; |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 643 | self->PushShadowFrame(shadow_frame); |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 644 | ArtMethod* method = shadow_frame->GetMethod(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 645 | // Ensure static methods are initialized. |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 646 | const bool is_static = method->IsStatic(); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 647 | if (is_static) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 648 | ObjPtr<mirror::Class> declaring_class = method->GetDeclaringClass(); |
Ian Rogers | 6c5cb21 | 2014-06-18 16:07:20 -0700 | [diff] [blame] | 649 | if (UNLIKELY(!declaring_class->IsInitialized())) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 650 | StackHandleScope<1> hs(self); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 651 | HandleWrapperObjPtr<mirror::Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class)); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 652 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized( |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 653 | self, h_declaring_class, true, true))) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 654 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 655 | self->PopShadowFrame(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 656 | return; |
| 657 | } |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 658 | CHECK(h_declaring_class->IsInitializing()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 659 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 660 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 661 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 662 | if (LIKELY(!shadow_frame->GetMethod()->IsNative())) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 663 | result->SetJ(Execute(self, accessor, *shadow_frame, JValue()).GetJ()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 664 | } else { |
| 665 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 666 | // generated stub) except during testing and image writing. |
| 667 | CHECK(!Runtime::Current()->IsStarted()); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 668 | ObjPtr<mirror::Object> receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 669 | uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 670 | UnstartedRuntime::Jni(self, shadow_frame->GetMethod(), receiver.Ptr(), args, result); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | self->PopShadowFrame(); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 674 | } |
| 675 | |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 676 | void CheckInterpreterAsmConstants() { |
| 677 | CheckMterpAsmConstants(); |
| 678 | } |
| 679 | |
| 680 | void InitInterpreterTls(Thread* self) { |
| 681 | InitMterpTls(self); |
| 682 | } |
| 683 | |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 684 | bool PrevFrameWillRetry(Thread* self, const ShadowFrame& frame) { |
| 685 | ShadowFrame* prev_frame = frame.GetLink(); |
| 686 | if (prev_frame == nullptr) { |
| 687 | NthCallerVisitor vis(self, 1, false); |
| 688 | vis.WalkStack(); |
| 689 | prev_frame = vis.GetCurrentShadowFrame(); |
| 690 | if (prev_frame == nullptr) { |
| 691 | prev_frame = self->FindDebuggerShadowFrame(vis.GetFrameId()); |
| 692 | } |
| 693 | } |
| 694 | return prev_frame != nullptr && prev_frame->GetForceRetryInstruction(); |
| 695 | } |
| 696 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 697 | } // namespace interpreter |
| 698 | } // namespace art |