blob: de17c8d056409f0724f6e6b7a162ade661f526f6 [file] [log] [blame]
Orion Hodsonc069a302017-01-18 09:23:12 +00001/*
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 Gampe70f5fd02018-10-24 19:58:37 -070019#include "class-alloc-inl.h"
Vladimir Markoc7aa87e2018-05-24 15:19:52 +010020#include "class_root.h"
David Sehr8c0961f2018-01-23 16:11:38 -080021#include "dex/modifiers.h"
Orion Hodsonc069a302017-01-18 09:23:12 +000022#include "handle_scope.h"
Vladimir Markoa3ad0cd2018-05-04 10:06:38 +010023#include "jni/jni_internal.h"
Orion Hodsonf8db2c32017-07-07 20:07:12 +010024#include "mirror/method_handle_impl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070025#include "object-inl.h"
Orion Hodsonf8db2c32017-07-07 20:07:12 +010026#include "well_known_classes.h"
Orion Hodsonc069a302017-01-18 09:23:12 +000027
28namespace art {
29namespace mirror {
30
Orion Hodsonc069a302017-01-18 09:23:12 +000031MethodHandlesLookup* 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 Markoc7aa87e2018-05-24 15:19:52 +010035 ObjPtr<MethodHandlesLookup> mhl = ObjPtr<MethodHandlesLookup>::DownCast(
36 GetClassRoot<MethodHandlesLookup>()->AllocObject(self));
Orion Hodsonc069a302017-01-18 09:23:12 +000037 mhl->SetFieldObject<false>(LookupClassOffset(), lookup_class.Get());
38 mhl->SetField32<false>(AllowedModesOffset(), kAllModes);
Vladimir Markoc7aa87e2018-05-24 15:19:52 +010039 return mhl.Ptr();
Orion Hodsonc069a302017-01-18 09:23:12 +000040}
41
Orion Hodsonf8db2c32017-07-07 20:07:12 +010042MethodHandlesLookup* 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
49MethodHandle* 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 Hodsonc069a302017-01-18 09:23:12 +000064} // namespace mirror
65} // namespace art