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 | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 21 | #include "interpreter_common.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 22 | #include "mirror/string-inl.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 23 | #include "scoped_thread_state_change.h" |
| 24 | #include "ScopedLocalRef.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 25 | #include "stack.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 26 | #include "unstarted_runtime.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 27 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 28 | namespace art { |
| 29 | namespace interpreter { |
| 30 | |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 31 | static void InterpreterJni(Thread* self, ArtMethod* method, const StringPiece& shorty, |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 32 | Object* receiver, uint32_t* args, JValue* result) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 33 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 34 | // TODO: The following enters JNI code using a typedef-ed function rather than the JNI compiler, |
| 35 | // it should be removed and JNI compiled stubs used instead. |
| 36 | ScopedObjectAccessUnchecked soa(self); |
| 37 | if (method->IsStatic()) { |
| 38 | if (shorty == "L") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 39 | typedef jobject (fntype)(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 40 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 41 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 42 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 43 | jobject jresult; |
| 44 | { |
| 45 | ScopedThreadStateChange tsc(self, kNative); |
| 46 | jresult = fn(soa.Env(), klass.get()); |
| 47 | } |
| 48 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 49 | } else if (shorty == "V") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 50 | typedef void (fntype)(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 51 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 52 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 53 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 54 | ScopedThreadStateChange tsc(self, kNative); |
| 55 | fn(soa.Env(), klass.get()); |
| 56 | } else if (shorty == "Z") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 57 | typedef jboolean (fntype)(JNIEnv*, jclass); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 58 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 59 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 60 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 61 | ScopedThreadStateChange tsc(self, kNative); |
| 62 | result->SetZ(fn(soa.Env(), klass.get())); |
| 63 | } else if (shorty == "BI") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 64 | typedef jbyte (fntype)(JNIEnv*, jclass, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 65 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 66 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 67 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 68 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 69 | result->SetB(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 70 | } else if (shorty == "II") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 71 | typedef jint (fntype)(JNIEnv*, jclass, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 72 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 73 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 74 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 75 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 76 | result->SetI(fn(soa.Env(), klass.get(), args[0])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 77 | } else if (shorty == "LL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 78 | typedef jobject (fntype)(JNIEnv*, jclass, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 79 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 80 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 81 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 82 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 83 | soa.AddLocalReference<jobject>( |
| 84 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 85 | jobject jresult; |
| 86 | { |
| 87 | ScopedThreadStateChange tsc(self, kNative); |
| 88 | jresult = fn(soa.Env(), klass.get(), arg0.get()); |
| 89 | } |
| 90 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 91 | } else if (shorty == "IIZ") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 92 | typedef jint (fntype)(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 93 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 94 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 95 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 96 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 97 | result->SetI(fn(soa.Env(), klass.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 98 | } else if (shorty == "ILI") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 99 | typedef jint (fntype)(JNIEnv*, jclass, jobject, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 100 | fntype* const fn = reinterpret_cast<fntype*>(const_cast<void*>( |
| 101 | method->GetEntryPointFromJni())); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 102 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 103 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 104 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 105 | soa.AddLocalReference<jobject>( |
| 106 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 107 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 108 | result->SetI(fn(soa.Env(), klass.get(), arg0.get(), args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 109 | } else if (shorty == "SIZ") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 110 | typedef jshort (fntype)(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 111 | fntype* const fn = |
| 112 | reinterpret_cast<fntype*>(const_cast<void*>(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->SetS(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 == "VIZ") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 118 | typedef void (fntype)(JNIEnv*, jclass, jint, jboolean); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 119 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 120 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 121 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 122 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 123 | fn(soa.Env(), klass.get(), args[0], args[1]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 124 | } else if (shorty == "ZLL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 125 | typedef jboolean (fntype)(JNIEnv*, jclass, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 126 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 127 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 128 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 129 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 130 | soa.AddLocalReference<jobject>( |
| 131 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 132 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 133 | soa.AddLocalReference<jobject>( |
| 134 | reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 135 | ScopedThreadStateChange tsc(self, kNative); |
| 136 | result->SetZ(fn(soa.Env(), klass.get(), arg0.get(), arg1.get())); |
| 137 | } else if (shorty == "ZILL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 138 | typedef jboolean (fntype)(JNIEnv*, jclass, jint, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 139 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 140 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 141 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 142 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 143 | soa.AddLocalReference<jobject>( |
| 144 | reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 145 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 146 | soa.AddLocalReference<jobject>( |
| 147 | reinterpret_cast<Object*>(args[2]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 148 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 149 | 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] | 150 | } else if (shorty == "VILII") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 151 | typedef void (fntype)(JNIEnv*, jclass, jint, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 152 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 153 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 154 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 155 | ScopedLocalRef<jobject> arg1(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 156 | soa.AddLocalReference<jobject>( |
| 157 | reinterpret_cast<Object*>(args[1]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 158 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 159 | 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] | 160 | } else if (shorty == "VLILII") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 161 | typedef void (fntype)(JNIEnv*, jclass, jobject, jint, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 162 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 163 | ScopedLocalRef<jclass> klass(soa.Env(), |
| 164 | soa.AddLocalReference<jclass>(method->GetDeclaringClass())); |
| 165 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 166 | soa.AddLocalReference<jobject>( |
| 167 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 168 | ScopedLocalRef<jobject> arg2(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 169 | soa.AddLocalReference<jobject>( |
| 170 | reinterpret_cast<Object*>(args[2]))); |
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(), arg0.get(), args[1], arg2.get(), args[3], args[4]); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 173 | } else { |
| 174 | LOG(FATAL) << "Do something with static native method: " << PrettyMethod(method) |
| 175 | << " shorty: " << shorty; |
| 176 | } |
| 177 | } else { |
| 178 | if (shorty == "L") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 179 | typedef jobject (fntype)(JNIEnv*, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 180 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 181 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 182 | soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 183 | jobject jresult; |
| 184 | { |
| 185 | ScopedThreadStateChange tsc(self, kNative); |
| 186 | jresult = fn(soa.Env(), rcvr.get()); |
| 187 | } |
| 188 | result->SetL(soa.Decode<Object*>(jresult)); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 189 | } else if (shorty == "V") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 190 | typedef void (fntype)(JNIEnv*, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 191 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Jeff Hao | 3dd9f76 | 2013-07-08 13:09:25 -0700 | [diff] [blame] | 192 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 193 | soa.AddLocalReference<jobject>(receiver)); |
| 194 | ScopedThreadStateChange tsc(self, kNative); |
| 195 | fn(soa.Env(), rcvr.get()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 196 | } else if (shorty == "LL") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 197 | typedef jobject (fntype)(JNIEnv*, jobject, jobject); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 198 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 199 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 200 | soa.AddLocalReference<jobject>(receiver)); |
| 201 | ScopedLocalRef<jobject> arg0(soa.Env(), |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 202 | soa.AddLocalReference<jobject>( |
| 203 | reinterpret_cast<Object*>(args[0]))); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 204 | jobject jresult; |
| 205 | { |
| 206 | ScopedThreadStateChange tsc(self, kNative); |
| 207 | jresult = fn(soa.Env(), rcvr.get(), arg0.get()); |
Ian Rogers | 556d637 | 2012-11-20 12:19:36 -0800 | [diff] [blame] | 208 | } |
| 209 | result->SetL(soa.Decode<Object*>(jresult)); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 210 | ScopedThreadStateChange tsc(self, kNative); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 211 | } else if (shorty == "III") { |
Bernhard Rosenkränzer | 4605362 | 2013-12-12 02:15:52 +0100 | [diff] [blame] | 212 | typedef jint (fntype)(JNIEnv*, jobject, jint, jint); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 213 | fntype* const fn = reinterpret_cast<fntype*>(method->GetEntryPointFromJni()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 214 | ScopedLocalRef<jobject> rcvr(soa.Env(), |
| 215 | soa.AddLocalReference<jobject>(receiver)); |
| 216 | ScopedThreadStateChange tsc(self, kNative); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 217 | result->SetI(fn(soa.Env(), rcvr.get(), args[0], args[1])); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 218 | } else { |
| 219 | LOG(FATAL) << "Do something with native method: " << PrettyMethod(method) |
| 220 | << " shorty: " << shorty; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 225 | enum InterpreterImplKind { |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 226 | kSwitchImpl, // Switch-based interpreter implementation. |
| 227 | kComputedGotoImplKind // Computed-goto-based interpreter implementation. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 228 | }; |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 229 | static std::ostream& operator<<(std::ostream& os, const InterpreterImplKind& rhs) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 230 | os << ((rhs == kSwitchImpl) ? "Switch-based interpreter" : "Computed-goto-based interpreter"); |
| 231 | return os; |
| 232 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 233 | |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 234 | #if !defined(__clang__) |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 235 | static constexpr InterpreterImplKind kInterpreterImplKind = kComputedGotoImplKind; |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 236 | #else |
| 237 | // Clang 3.4 fails to build the goto interpreter implementation. |
| 238 | static constexpr InterpreterImplKind kInterpreterImplKind = kSwitchImpl; |
| 239 | template<bool do_access_check, bool transaction_active> |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 240 | JValue ExecuteGotoImpl(Thread*, const DexFile::CodeItem*, ShadowFrame&, JValue) { |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 241 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 242 | UNREACHABLE(); |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 243 | } |
| 244 | // Explicit definitions of ExecuteGotoImpl. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 245 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 246 | JValue ExecuteGotoImpl<true, false>(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 247 | ShadowFrame& shadow_frame, JValue result_register); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 248 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 249 | JValue ExecuteGotoImpl<false, false>(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 250 | ShadowFrame& shadow_frame, JValue result_register); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 251 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 252 | JValue ExecuteGotoImpl<true, true>(Thread* self, const DexFile::CodeItem* code_item, |
| 253 | ShadowFrame& shadow_frame, JValue result_register); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 254 | template<> SHARED_REQUIRES(Locks::mutator_lock_) |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 255 | JValue ExecuteGotoImpl<false, true>(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 256 | ShadowFrame& shadow_frame, JValue result_register); |
Sebastien Hertz | fa888d0 | 2014-09-30 12:00:11 +0200 | [diff] [blame] | 257 | #endif |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 258 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 259 | static JValue Execute(Thread* self, const DexFile::CodeItem* code_item, ShadowFrame& shadow_frame, |
| 260 | JValue result_register) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 261 | SHARED_REQUIRES(Locks::mutator_lock_); |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 262 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 263 | static inline JValue Execute(Thread* self, const DexFile::CodeItem* code_item, |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 264 | ShadowFrame& shadow_frame, JValue result_register) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 265 | DCHECK(!shadow_frame.GetMethod()->IsAbstract()); |
| 266 | DCHECK(!shadow_frame.GetMethod()->IsNative()); |
Sebastien Hertz | 4e99b3d | 2014-06-24 14:35:40 +0200 | [diff] [blame] | 267 | shadow_frame.GetMethod()->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 268 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 269 | bool transaction_active = Runtime::Current()->IsActiveTransaction(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 270 | if (LIKELY(shadow_frame.GetMethod()->IsPreverified())) { |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 271 | // Enter the "without access check" interpreter. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 272 | if (kInterpreterImplKind == kSwitchImpl) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 273 | if (transaction_active) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 274 | return ExecuteSwitchImpl<false, true>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 275 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 276 | return ExecuteSwitchImpl<false, false>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 277 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 278 | } else { |
| 279 | DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 280 | if (transaction_active) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 281 | return ExecuteGotoImpl<false, true>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 282 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 283 | return ExecuteGotoImpl<false, false>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 284 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 285 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 286 | } else { |
| 287 | // Enter the "with access check" interpreter. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 288 | if (kInterpreterImplKind == kSwitchImpl) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 289 | if (transaction_active) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 290 | return ExecuteSwitchImpl<true, true>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 291 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 292 | return ExecuteSwitchImpl<true, false>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 293 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 294 | } else { |
| 295 | DCHECK_EQ(kInterpreterImplKind, kComputedGotoImplKind); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 296 | if (transaction_active) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 297 | return ExecuteGotoImpl<true, true>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 298 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 299 | return ExecuteGotoImpl<true, false>(self, code_item, shadow_frame, result_register); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 300 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 301 | } |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 305 | void EnterInterpreterFromInvoke(Thread* self, ArtMethod* method, Object* receiver, |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 306 | uint32_t* args, JValue* result) { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 307 | DCHECK_EQ(self, Thread::Current()); |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 308 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 309 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 310 | ThrowStackOverflowError(self); |
| 311 | return; |
| 312 | } |
| 313 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 314 | const char* old_cause = self->StartAssertNoThreadSuspension("EnterInterpreterFromInvoke"); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 315 | const DexFile::CodeItem* code_item = method->GetCodeItem(); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 316 | uint16_t num_regs; |
| 317 | uint16_t num_ins; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 318 | if (code_item != nullptr) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 319 | num_regs = code_item->registers_size_; |
| 320 | num_ins = code_item->ins_size_; |
jeffhao | 0a9bb73 | 2012-11-26 12:28:49 -0800 | [diff] [blame] | 321 | } else if (method->IsAbstract()) { |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 322 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 56adf60 | 2013-07-09 17:27:07 +0200 | [diff] [blame] | 323 | ThrowAbstractMethodError(method); |
jeffhao | 0a9bb73 | 2012-11-26 12:28:49 -0800 | [diff] [blame] | 324 | return; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 325 | } else { |
| 326 | DCHECK(method->IsNative()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 327 | num_regs = num_ins = ArtMethod::NumArgRegisters(method->GetShorty()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 328 | if (!method->IsStatic()) { |
| 329 | num_regs++; |
| 330 | num_ins++; |
| 331 | } |
| 332 | } |
| 333 | // Set up shadow frame with matching number of reference slots to vregs. |
| 334 | ShadowFrame* last_shadow_frame = self->GetManagedStack()->GetTopShadowFrame(); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 335 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 336 | CREATE_SHADOW_FRAME(num_regs, last_shadow_frame, method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 337 | ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get(); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 338 | self->PushShadowFrame(shadow_frame); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 339 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 340 | size_t cur_reg = num_regs - num_ins; |
| 341 | if (!method->IsStatic()) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 342 | CHECK(receiver != nullptr); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 343 | shadow_frame->SetVRegReference(cur_reg, receiver); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 344 | ++cur_reg; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 345 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 346 | uint32_t shorty_len = 0; |
| 347 | const char* shorty = method->GetShorty(&shorty_len); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 348 | 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] | 349 | DCHECK_LT(shorty_pos + 1, shorty_len); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 350 | switch (shorty[shorty_pos + 1]) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 351 | case 'L': { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 352 | Object* o = reinterpret_cast<StackReference<Object>*>(&args[arg_pos])->AsMirrorPtr(); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 353 | shadow_frame->SetVRegReference(cur_reg, o); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 354 | break; |
| 355 | } |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 356 | case 'J': case 'D': { |
| 357 | uint64_t wide_value = (static_cast<uint64_t>(args[arg_pos + 1]) << 32) | args[arg_pos]; |
| 358 | shadow_frame->SetVRegLong(cur_reg, wide_value); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 359 | cur_reg++; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 360 | arg_pos++; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 361 | break; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 362 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 363 | default: |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 364 | shadow_frame->SetVReg(cur_reg, args[arg_pos]); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 365 | break; |
| 366 | } |
| 367 | } |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 368 | self->EndAssertNoThreadSuspension(old_cause); |
| 369 | // 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] | 370 | if (method->IsStatic() && UNLIKELY(!method->GetDeclaringClass()->IsInitialized())) { |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 371 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 372 | StackHandleScope<1> hs(self); |
| 373 | Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass())); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 374 | if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) { |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 375 | CHECK(self->IsExceptionPending()); |
| 376 | self->PopShadowFrame(); |
| 377 | return; |
| 378 | } |
| 379 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 380 | if (LIKELY(!method->IsNative())) { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 381 | JValue r = Execute(self, code_item, *shadow_frame, JValue()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 382 | if (result != nullptr) { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 383 | *result = r; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 384 | } |
| 385 | } else { |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 386 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 387 | // generated stub) except during testing and image writing. |
Mathieu Chartier | 92246bb | 2014-02-25 18:22:39 -0800 | [diff] [blame] | 388 | // Update args to be the args in the shadow frame since the input ones could hold stale |
| 389 | // references pointers due to moving GC. |
| 390 | args = shadow_frame->GetVRegArgs(method->IsStatic() ? 0 : 1); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 391 | if (!Runtime::Current()->IsStarted()) { |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 392 | UnstartedRuntime::Jni(self, method, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 393 | } else { |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 394 | InterpreterJni(self, method, shorty, receiver, args, result); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | self->PopShadowFrame(); |
| 398 | } |
| 399 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 400 | void EnterInterpreterFromDeoptimize(Thread* self, ShadowFrame* shadow_frame, JValue* ret_val) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 401 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 402 | JValue value; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 403 | // Set value to last known result in case the shadow frame chain is empty. |
| 404 | value.SetJ(ret_val->GetJ()); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 405 | // Are we executing the first shadow frame? |
| 406 | bool first = true; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 407 | while (shadow_frame != nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 408 | self->SetTopOfShadowStack(shadow_frame); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 409 | const DexFile::CodeItem* code_item = shadow_frame->GetMethod()->GetCodeItem(); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 410 | const uint32_t dex_pc = shadow_frame->GetDexPC(); |
| 411 | uint32_t new_dex_pc; |
| 412 | if (UNLIKELY(self->IsExceptionPending())) { |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 413 | // If we deoptimize from the QuickExceptionHandler, we already reported the exception to |
| 414 | // the instrumentation. To prevent from reporting it a second time, we simply pass a |
| 415 | // null Instrumentation*. |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 416 | const instrumentation::Instrumentation* const instrumentation = |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 417 | first ? nullptr : Runtime::Current()->GetInstrumentation(); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 418 | uint32_t found_dex_pc = FindNextInstructionFollowingException(self, *shadow_frame, dex_pc, |
| 419 | instrumentation); |
| 420 | new_dex_pc = found_dex_pc; // the dex pc of a matching catch handler |
| 421 | // or DexFile::kDexNoIndex if there is none. |
| 422 | } else { |
| 423 | const Instruction* instr = Instruction::At(&code_item->insns_[dex_pc]); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 424 | // For an invoke, use the dex pc of the next instruction. |
| 425 | // TODO: should be tested more once b/17586779 is fixed. |
| 426 | new_dex_pc = dex_pc + (instr->IsInvoke() ? instr->SizeInCodeUnits() : 0); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 427 | } |
| 428 | if (new_dex_pc != DexFile::kDexNoIndex) { |
| 429 | shadow_frame->SetDexPC(new_dex_pc); |
| 430 | value = Execute(self, code_item, *shadow_frame, value); |
| 431 | } |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 432 | ShadowFrame* old_frame = shadow_frame; |
| 433 | shadow_frame = shadow_frame->GetLink(); |
Christopher Ferris | 241a958 | 2015-04-27 15:19:41 -0700 | [diff] [blame] | 434 | ShadowFrame::DeleteDeoptimizedFrame(old_frame); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 435 | first = false; |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 436 | } |
| 437 | ret_val->SetJ(value.GetJ()); |
| 438 | } |
| 439 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 440 | JValue EnterInterpreterFromEntryPoint(Thread* self, const DexFile::CodeItem* code_item, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 441 | ShadowFrame* shadow_frame) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 442 | DCHECK_EQ(self, Thread::Current()); |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 443 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 444 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 445 | ThrowStackOverflowError(self); |
| 446 | return JValue(); |
| 447 | } |
| 448 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 449 | return Execute(self, code_item, *shadow_frame, JValue()); |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 452 | void ArtInterpreterToInterpreterBridge(Thread* self, const DexFile::CodeItem* code_item, |
| 453 | ShadowFrame* shadow_frame, JValue* result) { |
Nicolas Geoffray | 535a3fb | 2014-07-22 15:17:38 +0100 | [diff] [blame] | 454 | bool implicit_check = !Runtime::Current()->ExplicitStackOverflowChecks(); |
| 455 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEndForInterpreter(implicit_check))) { |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 456 | ThrowStackOverflowError(self); |
Jeff Hao | 6951067 | 2013-05-21 17:34:55 -0700 | [diff] [blame] | 457 | return; |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 460 | self->PushShadowFrame(shadow_frame); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 461 | // Ensure static methods are initialized. |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 462 | const bool is_static = shadow_frame->GetMethod()->IsStatic(); |
| 463 | if (is_static) { |
| 464 | mirror::Class* declaring_class = shadow_frame->GetMethod()->GetDeclaringClass(); |
Ian Rogers | 6c5cb21 | 2014-06-18 16:07:20 -0700 | [diff] [blame] | 465 | if (UNLIKELY(!declaring_class->IsInitialized())) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 466 | StackHandleScope<1> hs(self); |
| 467 | HandleWrapper<Class> h_declaring_class(hs.NewHandleWrapper(&declaring_class)); |
| 468 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized( |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 469 | self, h_declaring_class, true, true))) { |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 470 | DCHECK(self->IsExceptionPending()); |
Mathieu Chartier | e861ebd | 2013-10-09 15:01:21 -0700 | [diff] [blame] | 471 | self->PopShadowFrame(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 472 | return; |
| 473 | } |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 474 | CHECK(h_declaring_class->IsInitializing()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 475 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 476 | } |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 477 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 478 | if (LIKELY(!shadow_frame->GetMethod()->IsNative())) { |
| 479 | result->SetJ(Execute(self, code_item, *shadow_frame, JValue()).GetJ()); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 480 | } else { |
| 481 | // We don't expect to be asked to interpret native code (which is entered via a JNI compiler |
| 482 | // generated stub) except during testing and image writing. |
| 483 | CHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 484 | Object* receiver = is_static ? nullptr : shadow_frame->GetVRegReference(0); |
| 485 | uint32_t* args = shadow_frame->GetVRegArgs(is_static ? 0 : 1); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 486 | UnstartedRuntime::Jni(self, shadow_frame->GetMethod(), receiver, args, result); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | self->PopShadowFrame(); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 492 | } // namespace interpreter |
| 493 | } // namespace art |