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 | 103992b | 2016-01-04 15:32:43 -0800 | [diff] [blame] | 21 | #include "common_throws.h" |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 22 | #include "interpreter_common.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "mirror/string-inl.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 24 | #include "scoped_thread_state_change.h" |
| 25 | #include "ScopedLocalRef.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 26 | #include "stack.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 27 | #include "unstarted_runtime.h" |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 28 | #include "mterp/mterp.h" |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 29 | #include "jit/jit.h" |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 30 | #include "jit/jit_code_cache.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 31 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 32 | namespace art { |
| 33 | namespace interpreter { |
| 34 | |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 35 | static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty, |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 36 | Object* receiver, uint32_t* args, JValue* result) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 37 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 38 | // 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änzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 43 | typedef jobject (fntype)(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 44 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 45 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 46 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 47 | jobject jresult; |
| 48 | { |
| 49 | ScopedThreadStateChange tsc(self, kNative); |
| 50 | jresult = fn(soa.Env(), klass.get()); |
| 51 | } |
| 52 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 53 | } else if (shorty == "V") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 54 | typedef void (fntype)(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 55 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 56 | 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änzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 61 | typedef jboolean (fntype)(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 62 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 63 | 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änzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 68 | typedef jbyte (fntype)(JNIEnv*, jclass, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 69 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 70 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 71 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 72 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 73 | result->SetB(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 74 | } else if (shorty == "II") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 75 | typedef jint (fntype)(JNIEnv*, jclass, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 76 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 77 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 78 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 79 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 80 | result->SetI(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 81 | } else if (shorty == "LL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 82 | typedef jobject (fntype)(JNIEnv*, jclass, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 83 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 84 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 85 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 86 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 87 | soa.AddLocalReference<jobject>( |
| 88 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 89 | 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 Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 95 | } else if (shorty == "IIZ") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 96 | typedef jint (fntype)(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 97 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 98 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 99 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 100 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 101 | result->SetI(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 102 | } else if (shorty == "ILI") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 103 | typedef jint (fntype)(JNIEnv*, jclass, jobject, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 104 | fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>( |
| 105 | method->GetEntryPointFromJni())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 106 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 107 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 108 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 109 | soa.AddLocalReference<jobject>( |
| 110 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 111 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 112 | result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 113 | } else if (shorty == "SIZ") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 114 | typedef jshort (fntype)(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 115 | fntype* const fn = |
| 116 | reinterpret_cast<fntype*>(const_cast<void*>(method->GetEntryPointFromJni())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 117 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 118 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 119 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 120 | result->SetS(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 121 | } else if (shorty == "VIZ") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 122 | typedef void (fntype)(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 123 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 124 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 125 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 126 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 127 | fn(soa.Env(), klass.get(), args[0], args[1]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 128 | } else if (shorty == "ZLL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 129 | typedef jboolean (fntype)(JNIEnv*, jclass, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 130 | fntype* const fn = reinterpret_cast<fntype*>(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 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 134 | soa.AddLocalReference<jobject>( |
| 135 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 136 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 137 | soa.AddLocalReference<jobject>( |
| 138 | reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 139 | ScopedThreadStateChange tsc(self, kNative); |
| 140 | result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get())); |
| 141 | } else if (shorty == "ZILL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 142 | typedef jboolean (fntype)(JNIEnv*, jclass, jint, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 143 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 144 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 145 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 146 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 147 | soa.AddLocalReference<jobject>( |
| 148 | reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 149 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 150 | soa.AddLocalReference<jobject>( |
| 151 | reinterpret_cast<Object*>(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 152 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 153 | 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] | 154 | } else if (shorty == "VILII") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 155 | typedef void (fntype)(JNIEnv*, jclass, jint, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 156 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 157 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 158 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 159 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 160 | soa.AddLocalReference<jobject>( |
| 161 | reinterpret_cast<Object*>(args[1]))); |
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 | 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] | 164 | } else if (shorty == "VLILII") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 165 | typedef void (fntype)(JNIEnv*, jclass, jobject, 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> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 170 | soa.AddLocalReference<jobject>( |
| 171 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 172 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 173 | soa.AddLocalReference<jobject>( |
| 174 | reinterpret_cast<Object*>(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 175 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 176 | 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] | 177 | } else { |
| 178 | LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method) |
| 179 | << " shorty: " << shorty; |
| 180 | } |
| 181 | } else { |
| 182 | if (shorty == "L") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 183 | typedef jobject (fntype)(JNIEnv*, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 184 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 185 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 186 | soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 187 | jobject jresult; |
| 188 | { |
| 189 | ScopedThreadStateChange tsc(self, kNative); |
| 190 | jresult = fn(soa.Env(), rcvr.get()); |
| 191 | } |
| 192 | result->SetL(soa.Decode<Object*>(jresult)); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 193 | } else if (shorty == "V") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 194 | typedef void (fntype)(JNIEnv*, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 195 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 196 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 197 | soa.AddLocalReference<jobject>(receiver)); |
| 198 | ScopedThreadStateChange tsc(self, kNative); |
| 199 | fn(soa.Env(), rcvr.get()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 200 | } else if (shorty == "LL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 201 | typedef jobject (fntype)(JNIEnv*, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 202 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 203 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 204 | soa.AddLocalReference<jobject>(receiver)); |
| 205 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 206 | soa.AddLocalReference<jobject>( |
| 207 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 208 | jobject jresult; |
| 209 | { |
| 210 | ScopedThreadStateChange tsc(self, kNative); |
| 211 | jresult = fn(soa.Env(), rcvr.get(), arg0.get()); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 212 | } |
| 213 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 214 | ScopedThreadStateChange tsc(self, kNative); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 215 | } else if (shorty == "III") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 216 | typedef jint (fntype)(JNIEnv*, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 217 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 218 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 219 | soa.AddLocalReference<jobject>(receiver)); |
| 220 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 221 | result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 222 | } else { |
| 223 | LOG(FATAL) << "Do something with native method: " << PrettyMethod(method) |
| 224 | << " shorty: " << shorty; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 229 | enum InterpreterImplKind { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 230 | kSwitchImplKind, // Switch-based interpreter implementation. |
| 231 | kComputedGotoImplKind, // Computed-goto-based interpreter implementation. |
| 232 | kMterpImplKind // Assembly interpreter |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 233 | }; |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 234 | static std::ostream& operator<<(std::ostream& os, const InterpreterImplKind& rhs) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 235 | os << ((rhs == kSwitchImplKind) |
| 236 | ? "Switch-based interpreter" |
| 237 | : (rhs == kComputedGotoImplKind) |
| 238 | ? "Computed-goto-based interpreter" |
| 239 | : "Asm interpreter"); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 240 | return os; |
| 241 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 242 | |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 243 | static constexpr InterpreterImplKind kInterpreterImplKind = kMterpImplKind; |
Alexey Frunze | 00b53b7 | 2016-02-02 20:25:45 -0800 | [diff] [blame] | 244 | |
| 245 | #if defined(__clang__) |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 246 | // Clang 3.4 fails to build the goto interpreter implementation. |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 247 | template<bool do_access_check, bool transaction_active> |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 248 | JValue ExecuteGotoImpl(Thread*, const DexFile::CodeItem*, ShadowFrame&, JValue) { |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 249 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 250 | UNREACHABLE(); |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 251 | } |
| 252 | // Explicit definitions of ExecuteGotoImpl. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 253 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 254 | JValue ExecuteGotoImpl<true, false>(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 255 | ShadowFrame& shadow_frame, JValue result_register); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 256 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 257 | JValue ExecuteGotoImpl<false, false>(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 258 | ShadowFrame& shadow_frame, JValue result_register); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 259 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 260 | JValue ExecuteGotoImpl<true, true>(Thread* self, const DexFile::CodeItem* code_item, |
| 261 | ShadowFrame& shadow_frame, JValue result_register); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 262 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 263 | JValue ExecuteGotoImpl<false, true>(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 264 | ShadowFrame& shadow_frame, JValue result_register); |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 265 | #endif |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 266 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 267 | static JValue Execute(Thread* self, const DexFile::CodeItem* code_item, ShadowFrame& shadow_frame, |
| 268 | JValue result_register) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 269 | SHARED_REQUIRES(Locks::mutator_lock_); |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 270 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 271 | static inline JValue Execute(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 272 | ShadowFrame& shadow_frame, JValue result_register) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 273 | DCHECK(!shadow_frame.GetMethod()->IsAbstract()); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 274 | DCHECK(!shadow_frame.GetMethod()->IsNative()); |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 275 | if (LIKELY(shadow_frame.GetDexPC() == 0)) { // Entering the method, but not via deoptimization. |
| 276 | if (kIsDebugBuild) { |
| 277 | self->AssertNoPendingException(); |
| 278 | } |
| 279 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 280 | ArtMethod *method = shadow_frame.GetMethod(); |
| 281 | |
| 282 | if (UNLIKELY(instrumentation->HasMethodEntryListeners())) { |
| 283 | instrumentation->MethodEnterEvent(self, shadow_frame.GetThisObject(code_item->ins_size_), |
| 284 | method, 0); |
| 285 | } |
| 286 | |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 287 | jit::Jit* jit = Runtime::Current()->GetJit(); |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame^] | 288 | if (jit != nullptr) { |
| 289 | jit->MethodEntered(self, shadow_frame.GetMethod()); |
| 290 | if (jit->CanInvokeCompiledCode(method)) { |
| 291 | JValue result; |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 292 | |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame^] | 293 | // Pop the shadow frame before calling into compiled code. |
| 294 | self->PopShadowFrame(); |
| 295 | ArtInterpreterToCompiledCodeBridge(self, code_item, &shadow_frame, &result); |
| 296 | // Push the shadow frame back as the caller will expect it. |
| 297 | self->PushShadowFrame(&shadow_frame); |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 298 | |
Nicolas Geoffray | 274fe4a | 2016-04-12 16:33:24 +0100 | [diff] [blame^] | 299 | return result; |
| 300 | } |
buzbee | 734f3aa | 2016-01-28 14:20:06 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Sebastien Hertz | 4e99b3d | 2014-06-24 14:35:40 +0200 | [diff] [blame] | 304 | shadow_frame.GetMethod()->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 305 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 306 | bool transaction_active = Runtime::Current()->IsActiveTransaction(); |
Igor Murashkin | df707e4 | 2016-02-02 16:56:50 -0800 | [diff] [blame] | 307 | if (LIKELY(shadow_frame.GetMethod()->SkipAccessChecks())) { |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 308 | // Enter the "without access check" interpreter. |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 309 | if (kInterpreterImplKind == kMterpImplKind) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 310 | if (transaction_active) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 311 | // No Mterp variant - just use the switch interpreter. |
| 312 | return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register, |
| 313 | false); |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 314 | } else if (UNLIKELY(!Runtime::Current()->IsStarted())) { |
| 315 | return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register, |
| 316 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 317 | } else { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 318 | while (true) { |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 319 | // Mterp does not support all instrumentation/debugging. |
| 320 | if (MterpShouldSwitchInterpreters()) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 321 | return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register, |
| 322 | false); |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 323 | } |
| 324 | bool returned = ExecuteMterpImpl(self, code_item, &shadow_frame, &result_register); |
| 325 | if (returned) { |
| 326 | return result_register; |
| 327 | } else { |
| 328 | // Mterp didn't like that instruction. Single-step it with the reference interpreter. |
buzbee | d6b48db | 2016-01-28 15:48:55 -0800 | [diff] [blame] | 329 | result_register = ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 330 | result_register, true); |
| 331 | if (shadow_frame.GetDexPC() == DexFile::kDexNoIndex) { |
| 332 | // Single-stepped a return or an exception not handled locally. Return to caller. |
buzbee | d6b48db | 2016-01-28 15:48:55 -0800 | [diff] [blame] | 333 | return result_register; |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } else if (kInterpreterImplKind == kSwitchImplKind) { |
| 339 | if (transaction_active) { |
| 340 | return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register, |
| 341 | false); |
| 342 | } else { |
| 343 | return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register, |
| 344 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 345 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 346 | } else { |
| 347 | DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 348 | if (transaction_active) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 349 | return ExecuteGotoImpl<false, true>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 350 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 351 | return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 352 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 353 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 354 | } else { |
| 355 | // Enter the "with access check" interpreter. |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 356 | if (kInterpreterImplKind == kMterpImplKind) { |
| 357 | // No access check variants for Mterp. Just use the switch version. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 358 | if (transaction_active) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 359 | return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register, |
| 360 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 361 | } else { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 362 | return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register, |
| 363 | false); |
| 364 | } |
| 365 | } else if (kInterpreterImplKind == kSwitchImplKind) { |
| 366 | if (transaction_active) { |
| 367 | return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register, |
| 368 | false); |
| 369 | } else { |
| 370 | return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register, |
| 371 | false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 372 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 373 | } else { |
| 374 | DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 375 | if (transaction_active) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 376 | return ExecuteGotoImpl<true, true>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 377 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 378 | return ExecuteGotoImpl<true, false>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 379 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 380 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 384 | void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver, |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 385 | uint32_t* args, JValue* result) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 386 | DCHECK_EQ(self, Thread::Current()); |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 387 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 388 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 389 | ThrowStackOverflowError(self); |
| 390 | return; |
| 391 | } |
| 392 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 393 | const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke"); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 394 | const DexFile::CodeItem* code_item = method->GetCodeItem(); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 395 | uint16_t num_regs; |
| 396 | uint16_t num_ins; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 397 | if (code_item != nullptr) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 398 | num_regs = code_item->registers_size_; |
| 399 | num_ins = code_item->ins_size_; |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 400 | } else if (!method->IsInvokable()) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 401 | self->EndAssertNoThreadSuspension(old_cause); |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 402 | method->ThrowInvocationTimeError(); |
jeffhao | 0a9bb73 | 2012-11-26 12:28:49 -0800 | [diff] [blame] | 403 | return; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 404 | } else { |
| 405 | DCHECK(method->IsNative()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 406 | num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 407 | if (!method->IsStatic()) { |
| 408 | num_regs++; |
| 409 | num_ins++; |
| 410 | } |
| 411 | } |
| 412 | // Set up shadow frame with matching number of reference slots to vregs. |
| 413 | ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame(); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 414 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 415 | CREATE_SHADOW_FRAME(num_regs, last_shadow_frame, method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 416 | ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get(); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 417 | self->PushShadowFrame(shadow_frame); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 418 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 419 | size_t cur_reg = num_regs - num_ins; |
| 420 | if (!method->IsStatic()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 421 | CHECK(receiver != nullptr); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 422 | shadow_frame->SetVRegReference(cur_reg, receiver); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 423 | ++cur_reg; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 424 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 425 | uint32_t shorty_len = 0; |
| 426 | const char* shorty = method->GetShorty(&shorty_len); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 427 | 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] | 428 | DCHECK_LT(shorty_pos + 1, shorty_len); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 429 | switch (shorty[shorty_pos + 1]) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 430 | case 'L': { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 431 | Object* o = reinterpret_cast<StackReference<Object>*>(&args[arg_pos])->AsMirrorPtr(); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 432 | shadow_frame->SetVRegReference(cur_reg, o); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 433 | break; |
| 434 | } |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 435 | case 'J': case 'D': { |
| 436 | uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos]; |
| 437 | shadow_frame->SetVRegLong(cur_reg, wide_value); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 438 | cur_reg++; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 439 | arg_pos++; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 440 | break; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 441 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 442 | default: |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 443 | shadow_frame->SetVReg(cur_reg, args[arg_pos]); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 444 | break; |
| 445 | } |
| 446 | } |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 447 | self->EndAssertNoThreadSuspension(old_cause); |
| 448 | // 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] | 449 | if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) { |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 450 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 451 | StackHandleScope<1> hs(self); |
| 452 | Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass())); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 453 | if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) { |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 454 | CHECK(self->IsExceptionPending()); |
| 455 | self->PopShadowFrame(); |
| 456 | return; |
| 457 | } |
| 458 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 459 | if (LIKELY(!method->IsNative())) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 460 | JValue r = Execute(self, code_item, *shadow_frame, JValue()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 461 | if (result != nullptr) { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 462 | *result = r; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 463 | } |
| 464 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 465 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 466 | // generated stub) except during testing and image writing. |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 467 | // Update args to be the args in the shadow frame since the input ones could hold stale |
| 468 | // references pointers due to moving GC. |
| 469 | args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 470 | if (!Runtime::Current()->IsStarted()) { |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 471 | UnstartedRuntime::Jni(self, method, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 472 | } else { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 473 | InterpreterJni(self, method, shorty, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | self->PopShadowFrame(); |
| 477 | } |
| 478 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 479 | void EnterInterpreterFromDeoptimize(Thread* self, |
| 480 | ShadowFrame* shadow_frame, |
| 481 | bool from_code, |
| 482 | JValue* ret_val) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 483 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 484 | JValue value; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 485 | // Set value to last known result in case the shadow frame chain is empty. |
| 486 | value.SetJ(ret_val->GetJ()); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 487 | // Are we executing the first shadow frame? |
| 488 | bool first = true; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 489 | while (shadow_frame != nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 490 | self->SetTopOfShadowStack(shadow_frame); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 491 | const DexFile::CodeItem* code_item = shadow_frame->GetMethod()->GetCodeItem(); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 492 | const uint32_t dex_pc = shadow_frame->GetDexPC(); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 493 | uint32_t new_dex_pc = dex_pc; |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 494 | if (UNLIKELY(self->IsExceptionPending())) { |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 495 | // If we deoptimize from the QuickExceptionHandler, we already reported the exception to |
| 496 | // the instrumentation. To prevent from reporting it a second time, we simply pass a |
| 497 | // null Instrumentation*. |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 498 | const instrumentation::Instrumentation* const instrumentation = |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 499 | first ? nullptr : Runtime::Current()->GetInstrumentation(); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 500 | uint32_t found_dex_pc = FindNextInstructionFollowingException(self, *shadow_frame, dex_pc, |
| 501 | instrumentation); |
| 502 | new_dex_pc = found_dex_pc; // the dex pc of a matching catch handler |
| 503 | // or DexFile::kDexNoIndex if there is none. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 504 | } else if (!from_code) { |
| 505 | // For the debugger and full deoptimization stack, we must go past the invoke |
| 506 | // instruction, as it already executed. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 507 | // TODO: should be tested more once b/17586779 is fixed. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 508 | const Instruction* instr = Instruction::At(&code_item->insns_[dex_pc]); |
| 509 | DCHECK(instr->IsInvoke()); |
| 510 | new_dex_pc = dex_pc + instr->SizeInCodeUnits(); |
| 511 | } else { |
| 512 | // Nothing to do, the dex_pc is the one at which the code requested |
| 513 | // the deoptimization. |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 514 | } |
| 515 | if (new_dex_pc != DexFile::kDexNoIndex) { |
| 516 | shadow_frame->SetDexPC(new_dex_pc); |
| 517 | value = Execute(self, code_item, *shadow_frame, value); |
| 518 | } |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 519 | ShadowFrame* old_frame = shadow_frame; |
| 520 | shadow_frame = shadow_frame->GetLink(); |
Christopher Ferris | 241a958 | 2015-04-27 15:19:41 -0700 | [diff] [blame] | 521 | ShadowFrame::DeleteDeoptimizedFrame(old_frame); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 522 | // Following deoptimizations of shadow frames must pass the invoke instruction. |
| 523 | from_code = false; |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 524 | first = false; |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 525 | } |
| 526 | ret_val->SetJ(value.GetJ()); |
| 527 | } |
| 528 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 529 | JValue EnterInterpreterFromEntryPoint(Thread* self, const DexFile::CodeItem* code_item, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 530 | ShadowFrame* shadow_frame) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 531 | DCHECK_EQ(self, Thread::Current()); |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 532 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 533 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 534 | ThrowStackOverflowError(self); |
| 535 | return JValue(); |
| 536 | } |
| 537 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 538 | return Execute(self, code_item, *shadow_frame, JValue()); |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 541 | void ArtInterpreterToInterpreterBridge(Thread* self, const DexFile::CodeItem* code_item, |
| 542 | ShadowFrame* shadow_frame, JValue* result) { |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 543 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 544 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 545 | ThrowStackOverflowError(self); |
Jeff Hao | 6951067 | 2013-05-21 17:34:55 -0700 | [diff] [blame] | 546 | return; |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 549 | self->PushShadowFrame(shadow_frame); |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 550 | ArtMethod* method = shadow_frame->GetMethod(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 551 | // Ensure static methods are initialized. |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 552 | const bool is_static = method->IsStatic(); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 553 | if (is_static) { |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 554 | mirror::Class* declaring_class = method->GetDeclaringClass(); |
Ian Rogers | 6c5cb21 | 2014-06-18 16:07:20 -0700 | [diff] [blame] | 555 | if (UNLIKELY(!declaring_class->IsInitialized())) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 556 | StackHandleScope<1> hs(self); |
| 557 | HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class)); |
| 558 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized( |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 559 | self, h_declaring_class, true, true))) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 560 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 561 | self->PopShadowFrame(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 562 | return; |
| 563 | } |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 564 | CHECK(h_declaring_class->IsInitializing()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 565 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 566 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 567 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 568 | if (LIKELY(!shadow_frame->GetMethod()->IsNative())) { |
| 569 | result->SetJ(Execute(self, code_item, *shadow_frame, JValue()).GetJ()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 570 | } else { |
| 571 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 572 | // generated stub) except during testing and image writing. |
| 573 | CHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 574 | Object* receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0); |
| 575 | uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 576 | UnstartedRuntime::Jni(self, shadow_frame->GetMethod(), receiver, args, result); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | self->PopShadowFrame(); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 580 | } |
| 581 | |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 582 | void CheckInterpreterAsmConstants() { |
| 583 | CheckMterpAsmConstants(); |
| 584 | } |
| 585 | |
| 586 | void InitInterpreterTls(Thread* self) { |
| 587 | InitMterpTls(self); |
| 588 | } |
| 589 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 590 | } // namespace interpreter |
| 591 | } // namespace art |