Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 17 | #include "method_handle_impl-inl.h" |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 18 | |
Andreas Gampe | 70f5fd0 | 2018-10-24 19:58:37 -0700 | [diff] [blame] | 19 | #include "class-alloc-inl.h" |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 20 | #include "class_root.h" |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | namespace mirror { |
| 24 | |
Orion Hodson | fe92d12 | 2018-01-02 10:45:17 +0000 | [diff] [blame] | 25 | const char* MethodHandle::GetReturnTypeDescriptor(const char* invoke_method_name) { |
| 26 | if (strcmp(invoke_method_name, "invoke") == 0 || strcmp(invoke_method_name, "invokeExact") == 0) { |
| 27 | return "Ljava/lang/Object;"; |
| 28 | } else { |
| 29 | return nullptr; |
| 30 | } |
| 31 | } |
| 32 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 33 | void MethodHandle::Initialize(uintptr_t art_field_or_method, |
| 34 | Kind kind, |
| 35 | Handle<MethodType> method_type) |
| 36 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 37 | CHECK(!Runtime::Current()->IsActiveTransaction()); |
| 38 | SetFieldObject<false>(CachedSpreadInvokerOffset(), nullptr); |
| 39 | SetFieldObject<false>(NominalTypeOffset(), nullptr); |
| 40 | SetFieldObject<false>(MethodTypeOffset(), method_type.Get()); |
| 41 | SetField32<false>(HandleKindOffset(), static_cast<uint32_t>(kind)); |
| 42 | SetField64<false>(ArtFieldOrMethodOffset(), art_field_or_method); |
| 43 | } |
| 44 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 45 | mirror::MethodHandleImpl* MethodHandleImpl::Create(Thread* const self, |
| 46 | uintptr_t art_field_or_method, |
| 47 | MethodHandle::Kind kind, |
| 48 | Handle<MethodType> method_type) |
| 49 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) { |
| 50 | StackHandleScope<1> hs(self); |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 51 | Handle<mirror::MethodHandleImpl> mh(hs.NewHandle(ObjPtr<MethodHandleImpl>::DownCast( |
| 52 | GetClassRoot<MethodHandleImpl>()->AllocObject(self)))); |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 53 | mh->Initialize(art_field_or_method, kind, method_type); |
| 54 | return mh.Get(); |
| 55 | } |
| 56 | |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 57 | } // namespace mirror |
| 58 | } // namespace art |