| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | /* |
| Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 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 | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 17 | #include <android-base/logging.h> |
| 18 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method-inl.h" |
| Andreas Gampe | e03662b | 2016-10-13 17:12:56 -0700 | [diff] [blame] | 20 | #include "base/casts.h" |
| Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 21 | #include "entrypoints/entrypoint_utils-inl.h" |
| Andreas Gampe | e03662b | 2016-10-13 17:12:56 -0700 | [diff] [blame] | 22 | #include "indirect_reference_table.h" |
| Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "mirror/object-inl.h" |
| Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 24 | #include "thread-inl.h" |
| Andreas Gampe | 90b936d | 2017-01-31 08:58:55 -0800 | [diff] [blame] | 25 | #include "verify_object.h" |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
| Andreas Gampe | e03662b | 2016-10-13 17:12:56 -0700 | [diff] [blame] | 29 | static_assert(sizeof(IRTSegmentState) == sizeof(uint32_t), "IRTSegmentState size unexpected"); |
| 30 | static_assert(std::is_trivial<IRTSegmentState>::value, "IRTSegmentState not trivial"); |
| 31 | |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 32 | static inline void GoToRunnableFast(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 33 | |
| Vladimir Marko | cedec9d | 2021-02-08 16:16:13 +0000 | [diff] [blame^] | 34 | extern void ReadBarrierJni(mirror::CompressedReference<mirror::Class>* declaring_class, |
| Hiroshi Yamauchi | 1cc71eb | 2015-05-07 10:47:27 -0700 | [diff] [blame] | 35 | Thread* self ATTRIBUTE_UNUSED) { |
| Hiroshi Yamauchi | 043eb9a | 2016-10-14 11:21:38 -0700 | [diff] [blame] | 36 | DCHECK(kUseReadBarrier); |
| 37 | if (kUseBakerReadBarrier) { |
| Vladimir Marko | cedec9d | 2021-02-08 16:16:13 +0000 | [diff] [blame^] | 38 | DCHECK(declaring_class->AsMirrorPtr() != nullptr) |
| Hiroshi Yamauchi | 043eb9a | 2016-10-14 11:21:38 -0700 | [diff] [blame] | 39 | << "The class of a static jni call must not be null"; |
| 40 | // Check the mark bit and return early if it's already marked. |
| Vladimir Marko | cedec9d | 2021-02-08 16:16:13 +0000 | [diff] [blame^] | 41 | if (LIKELY(declaring_class->AsMirrorPtr()->GetMarkBit() != 0)) { |
| Hiroshi Yamauchi | 043eb9a | 2016-10-14 11:21:38 -0700 | [diff] [blame] | 42 | return; |
| 43 | } |
| 44 | } |
| Hiroshi Yamauchi | 1cc71eb | 2015-05-07 10:47:27 -0700 | [diff] [blame] | 45 | // Call the read barrier and update the handle. |
| Vladimir Marko | cedec9d | 2021-02-08 16:16:13 +0000 | [diff] [blame^] | 46 | mirror::Class* to_ref = ReadBarrier::BarrierForRoot(declaring_class); |
| 47 | declaring_class->Assign(to_ref); |
| Hiroshi Yamauchi | 1cc71eb | 2015-05-07 10:47:27 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 50 | // Called on entry to fast JNI, push a new local reference table only. |
| 51 | extern uint32_t JniMethodFastStart(Thread* self) { |
| 52 | JNIEnvExt* env = self->GetJniEnv(); |
| 53 | DCHECK(env != nullptr); |
| Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 54 | uint32_t saved_local_ref_cookie = bit_cast<uint32_t>(env->GetLocalRefCookie()); |
| 55 | env->SetLocalRefCookie(env->GetLocalsSegmentState()); |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 56 | |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 57 | if (kIsDebugBuild) { |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 58 | ArtMethod* native_method = *self->GetManagedStack()->GetTopQuickFrame(); |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 59 | CHECK(native_method->IsFastNative()) << native_method->PrettyMethod(); |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | return saved_local_ref_cookie; |
| 63 | } |
| 64 | |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 65 | // Called on entry to JNI, transition out of Runnable and release share of mutator_lock_. |
| Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 66 | extern uint32_t JniMethodStart(Thread* self) { |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 67 | JNIEnvExt* env = self->GetJniEnv(); |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 68 | DCHECK(env != nullptr); |
| Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 69 | uint32_t saved_local_ref_cookie = bit_cast<uint32_t>(env->GetLocalRefCookie()); |
| 70 | env->SetLocalRefCookie(env->GetLocalsSegmentState()); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 71 | ArtMethod* native_method = *self->GetManagedStack()->GetTopQuickFrame(); |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 72 | // TODO: Introduce special entrypoint for synchronized @FastNative methods? |
| 73 | // Or ban synchronized @FastNative outright to avoid the extra check here? |
| 74 | DCHECK(!native_method->IsFastNative() || native_method->IsSynchronized()); |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 75 | if (!native_method->IsFastNative()) { |
| 76 | // When not fast JNI we transition out of runnable. |
| 77 | self->TransitionFromRunnableToSuspended(kNative); |
| 78 | } |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 79 | return saved_local_ref_cookie; |
| 80 | } |
| Elliott Hughes | b264f08 | 2012-04-06 17:10:10 -0700 | [diff] [blame] | 81 | |
| Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 82 | extern uint32_t JniMethodStartSynchronized(jobject to_lock, Thread* self) { |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 83 | self->DecodeJObject(to_lock)->MonitorEnter(self); |
| 84 | return JniMethodStart(self); |
| 85 | } |
| 86 | |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 87 | // TODO: NO_THREAD_SAFETY_ANALYSIS due to different control paths depending on fast JNI. |
| 88 | static void GoToRunnable(Thread* self) NO_THREAD_SAFETY_ANALYSIS { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 89 | ArtMethod* native_method = *self->GetManagedStack()->GetTopQuickFrame(); |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 90 | bool is_fast = native_method->IsFastNative(); |
| 91 | if (!is_fast) { |
| 92 | self->TransitionFromSuspendedToRunnable(); |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 93 | } else { |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 94 | GoToRunnableFast(self); |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 98 | ALWAYS_INLINE static inline void GoToRunnableFast(Thread* self) { |
| 99 | if (kIsDebugBuild) { |
| 100 | // Should only enter here if the method is @FastNative. |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 101 | ArtMethod* native_method = *self->GetManagedStack()->GetTopQuickFrame(); |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 102 | CHECK(native_method->IsFastNative()) << native_method->PrettyMethod(); |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 105 | // When we are in @FastNative, we are already Runnable. |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 106 | // Only do a suspend check on the way out of JNI. |
| 107 | if (UNLIKELY(self->TestAllFlags())) { |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 108 | // In fast JNI mode we never transitioned out of runnable. Perform a suspend check if there |
| 109 | // is a flag raised. |
| 110 | DCHECK(Locks::mutator_lock_->IsSharedHeld(self)); |
| Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 111 | self->CheckSuspend(); |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| Yevgeny Rouban | 35aef2c | 2014-05-19 16:19:36 +0700 | [diff] [blame] | 115 | static void PopLocalReferences(uint32_t saved_local_ref_cookie, Thread* self) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 116 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 117 | JNIEnvExt* env = self->GetJniEnv(); |
| Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 118 | if (UNLIKELY(env->IsCheckJniEnabled())) { |
| Andreas Gampe | 5f4a09a | 2015-09-28 13:16:33 -0700 | [diff] [blame] | 119 | env->CheckNoHeldMonitors(); |
| 120 | } |
| Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 121 | env->SetLocalSegmentState(env->GetLocalRefCookie()); |
| 122 | env->SetLocalRefCookie(bit_cast<IRTSegmentState>(saved_local_ref_cookie)); |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| Vladimir Marko | 5c33d35 | 2020-02-10 12:29:13 +0000 | [diff] [blame] | 125 | // TODO: annotalysis disabled as monitor semantics are maintained in Java code. |
| 126 | static inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) |
| 127 | NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_) { |
| 128 | // Save any pending exception over monitor exit call. |
| 129 | ObjPtr<mirror::Throwable> saved_exception = nullptr; |
| 130 | if (UNLIKELY(self->IsExceptionPending())) { |
| 131 | saved_exception = self->GetException(); |
| 132 | self->ClearException(); |
| 133 | } |
| 134 | // Decode locked object and unlock, before popping local references. |
| 135 | self->DecodeJObject(locked)->MonitorExit(self); |
| 136 | if (UNLIKELY(self->IsExceptionPending())) { |
| 137 | LOG(FATAL) << "Synchronized JNI code returning with an exception:\n" |
| 138 | << saved_exception->Dump() |
| 139 | << "\nEncountered second exception during implicit MonitorExit:\n" |
| 140 | << self->GetException()->Dump(); |
| 141 | } |
| 142 | // Restore pending exception. |
| 143 | if (saved_exception != nullptr) { |
| 144 | self->SetException(saved_exception); |
| 145 | } |
| 146 | } |
| 147 | |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 148 | // TODO: These should probably be templatized or macro-ized. |
| 149 | // Otherwise there's just too much repetitive boilerplate. |
| 150 | |
| Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 151 | extern void JniMethodEnd(uint32_t saved_local_ref_cookie, Thread* self) { |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 152 | GoToRunnable(self); |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 153 | PopLocalReferences(saved_local_ref_cookie, self); |
| 154 | } |
| 155 | |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 156 | extern void JniMethodFastEnd(uint32_t saved_local_ref_cookie, Thread* self) { |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 157 | GoToRunnableFast(self); |
| Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 158 | PopLocalReferences(saved_local_ref_cookie, self); |
| 159 | } |
| 160 | |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 161 | extern void JniMethodEndSynchronized(uint32_t saved_local_ref_cookie, |
| 162 | jobject locked, |
| Ian Rogers | 693ff61 | 2013-02-01 10:56:12 -0800 | [diff] [blame] | 163 | Thread* self) { |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 164 | GoToRunnable(self); |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 165 | UnlockJniSynchronizedMethod(locked, self); // Must decode before pop. |
| 166 | PopLocalReferences(saved_local_ref_cookie, self); |
| 167 | } |
| 168 | |
| Andreas Gampe | 48ee356 | 2015-04-10 19:57:29 -0700 | [diff] [blame] | 169 | // Common result handling for EndWithReference. |
| 170 | static mirror::Object* JniMethodEndWithReferenceHandleResult(jobject result, |
| 171 | uint32_t saved_local_ref_cookie, |
| 172 | Thread* self) |
| 173 | NO_THREAD_SAFETY_ANALYSIS { |
| 174 | // Must decode before pop. The 'result' may not be valid in case of an exception, though. |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 175 | ObjPtr<mirror::Object> o; |
| 176 | if (!self->IsExceptionPending()) { |
| 177 | o = self->DecodeJObject(result); |
| 178 | } |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 179 | PopLocalReferences(saved_local_ref_cookie, self); |
| 180 | // Process result. |
| Ian Rogers | 55256cb | 2017-12-21 17:07:11 -0800 | [diff] [blame] | 181 | if (UNLIKELY(self->GetJniEnv()->IsCheckJniEnabled())) { |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 182 | // CheckReferenceResult can resolve types. |
| 183 | StackHandleScope<1> hs(self); |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 184 | HandleWrapperObjPtr<mirror::Object> h_obj(hs.NewHandleWrapper(&o)); |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 185 | CheckReferenceResult(h_obj, self); |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 186 | } |
| Mathieu Chartier | 9d156d5 | 2016-10-06 17:44:26 -0700 | [diff] [blame] | 187 | VerifyObject(o); |
| Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 188 | return o.Ptr(); |
| Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 191 | extern mirror::Object* JniMethodFastEndWithReference(jobject result, |
| 192 | uint32_t saved_local_ref_cookie, |
| 193 | Thread* self) { |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 194 | GoToRunnableFast(self); |
| Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 195 | return JniMethodEndWithReferenceHandleResult(result, saved_local_ref_cookie, self); |
| 196 | } |
| 197 | |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 198 | extern mirror::Object* JniMethodEndWithReference(jobject result, |
| 199 | uint32_t saved_local_ref_cookie, |
| Andreas Gampe | 48ee356 | 2015-04-10 19:57:29 -0700 | [diff] [blame] | 200 | Thread* self) { |
| 201 | GoToRunnable(self); |
| 202 | return JniMethodEndWithReferenceHandleResult(result, saved_local_ref_cookie, self); |
| 203 | } |
| 204 | |
| Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 205 | extern mirror::Object* JniMethodEndWithReferenceSynchronized(jobject result, |
| 206 | uint32_t saved_local_ref_cookie, |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 207 | jobject locked, |
| 208 | Thread* self) { |
| Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 209 | GoToRunnable(self); |
| Andreas Gampe | 48ee356 | 2015-04-10 19:57:29 -0700 | [diff] [blame] | 210 | UnlockJniSynchronizedMethod(locked, self); |
| 211 | return JniMethodEndWithReferenceHandleResult(result, saved_local_ref_cookie, self); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 214 | extern uint64_t GenericJniMethodEnd(Thread* self, |
| 215 | uint32_t saved_local_ref_cookie, |
| 216 | jvalue result, |
| 217 | uint64_t result_f, |
| Vladimir Marko | 6e043bb | 2020-02-10 16:56:54 +0000 | [diff] [blame] | 218 | ArtMethod* called) |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 219 | // TODO: NO_THREAD_SAFETY_ANALYSIS as GoToRunnable() is NO_THREAD_SAFETY_ANALYSIS |
| 220 | NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 221 | bool critical_native = called->IsCriticalNative(); |
| 222 | bool fast_native = called->IsFastNative(); |
| Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 223 | bool normal_native = !critical_native && !fast_native; |
| 224 | |
| 225 | // @Fast and @CriticalNative do not do a state transition. |
| 226 | if (LIKELY(normal_native)) { |
| 227 | GoToRunnable(self); |
| 228 | } |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 229 | // We need the mutator lock (i.e., calling GoToRunnable()) before accessing the shorty or the |
| 230 | // locked object. |
| Vladimir Marko | 5c33d35 | 2020-02-10 12:29:13 +0000 | [diff] [blame] | 231 | if (called->IsSynchronized()) { |
| 232 | DCHECK(normal_native) << "@FastNative/@CriticalNative and synchronize is not supported"; |
| Vladimir Marko | cedec9d | 2021-02-08 16:16:13 +0000 | [diff] [blame^] | 233 | jobject lock = GetGenericJniSynchronizationObject(self, called); |
| Vladimir Marko | 5c33d35 | 2020-02-10 12:29:13 +0000 | [diff] [blame] | 234 | DCHECK(lock != nullptr); |
| 235 | UnlockJniSynchronizedMethod(lock, self); |
| 236 | } |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 237 | char return_shorty_char = called->GetShorty()[0]; |
| 238 | if (return_shorty_char == 'L') { |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 239 | return reinterpret_cast<uint64_t>(JniMethodEndWithReferenceHandleResult( |
| 240 | result.l, saved_local_ref_cookie, self)); |
| 241 | } else { |
| Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 242 | if (LIKELY(!critical_native)) { |
| Vladimir Marko | cedec9d | 2021-02-08 16:16:13 +0000 | [diff] [blame^] | 243 | PopLocalReferences(saved_local_ref_cookie, self); |
| Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 244 | } |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 245 | switch (return_shorty_char) { |
| 246 | case 'F': { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 247 | if (kRuntimeISA == InstructionSet::kX86) { |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 248 | // Convert back the result to float. |
| 249 | double d = bit_cast<double, uint64_t>(result_f); |
| 250 | return bit_cast<uint32_t, float>(static_cast<float>(d)); |
| 251 | } else { |
| 252 | return result_f; |
| 253 | } |
| 254 | } |
| 255 | case 'D': |
| 256 | return result_f; |
| 257 | case 'Z': |
| 258 | return result.z; |
| 259 | case 'B': |
| 260 | return result.b; |
| 261 | case 'C': |
| 262 | return result.c; |
| 263 | case 'S': |
| 264 | return result.s; |
| 265 | case 'I': |
| 266 | return result.i; |
| 267 | case 'J': |
| 268 | return result.j; |
| 269 | case 'V': |
| 270 | return 0; |
| 271 | default: |
| 272 | LOG(FATAL) << "Unexpected return shorty character " << return_shorty_char; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 273 | UNREACHABLE(); |
| Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 278 | } // namespace art |