| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
| 17 | #include "method_handles_lookup.h" |
| 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" |
| David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 21 | #include "dex/modifiers.h" |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 22 | #include "handle_scope.h" |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 23 | #include "jni/jni_internal.h" |
| Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 24 | #include "mirror/method_handle_impl.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | #include "object-inl.h" |
| Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 26 | #include "well_known_classes.h" |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | namespace mirror { |
| 30 | |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 31 | MethodHandlesLookup* MethodHandlesLookup::Create(Thread* const self, Handle<Class> lookup_class) |
| 32 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) { |
| 33 | static constexpr uint32_t kAllModes = kAccPublic | kAccPrivate | kAccProtected | kAccStatic; |
| 34 | |
| Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 35 | ObjPtr<MethodHandlesLookup> mhl = ObjPtr<MethodHandlesLookup>::DownCast( |
| 36 | GetClassRoot<MethodHandlesLookup>()->AllocObject(self)); |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 37 | mhl->SetFieldObject<false>(LookupClassOffset(), lookup_class.Get()); |
| 38 | mhl->SetField32<false>(AllowedModesOffset(), kAllModes); |
| Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame] | 39 | return mhl.Ptr(); |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 42 | MethodHandlesLookup* MethodHandlesLookup::GetDefault(Thread* const self) { |
| 43 | ArtMethod* lookup = jni::DecodeArtMethod(WellKnownClasses::java_lang_invoke_MethodHandles_lookup); |
| 44 | JValue result; |
| 45 | lookup->Invoke(self, nullptr, 0, &result, "L"); |
| 46 | return down_cast<MethodHandlesLookup*>(result.GetL()); |
| 47 | } |
| 48 | |
| 49 | MethodHandle* MethodHandlesLookup::FindConstructor(Thread* const self, |
| 50 | Handle<Class> klass, |
| 51 | Handle<MethodType> method_type) { |
| 52 | ArtMethod* findConstructor = |
| 53 | jni::DecodeArtMethod(WellKnownClasses::java_lang_invoke_MethodHandles_Lookup_findConstructor); |
| 54 | uint32_t args[] = { |
| 55 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this)), |
| 56 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(klass.Get())), |
| 57 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(method_type.Get())) |
| 58 | }; |
| 59 | JValue result; |
| 60 | findConstructor->Invoke(self, args, sizeof(args), &result, "LLL"); |
| 61 | return down_cast<MethodHandle*>(result.GetL()); |
| 62 | } |
| 63 | |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 64 | } // namespace mirror |
| 65 | } // namespace art |