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