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
19 #include "class-alloc-inl.h"
20 #include "class_root-inl.h"
21 #include "dex/modifiers.h"
22 #include "handle_scope.h"
23 #include "mirror/method_handle_impl.h"
24 #include "obj_ptr-inl.h"
25 #include "object-inl.h"
26 #include "well_known_classes.h"
27
28 namespace art {
29 namespace mirror {
30
Create(Thread * const self,Handle<Class> lookup_class)31 ObjPtr<MethodHandlesLookup> MethodHandlesLookup::Create(Thread* const self,
32 Handle<Class> lookup_class)
33 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) {
34 static constexpr uint32_t kAllModes = kAccPublic | kAccPrivate | kAccProtected | kAccStatic;
35
36 ObjPtr<MethodHandlesLookup> mhl = ObjPtr<MethodHandlesLookup>::DownCast(
37 GetClassRoot<MethodHandlesLookup>()->AllocObject(self));
38 mhl->SetFieldObject<false>(LookupClassOffset(), lookup_class.Get());
39 mhl->SetField32<false>(AllowedModesOffset(), kAllModes);
40 return mhl;
41 }
42
GetDefault(Thread * const self)43 ObjPtr<MethodHandlesLookup> MethodHandlesLookup::GetDefault(Thread* const self) {
44 ArtMethod* lookup = WellKnownClasses::java_lang_invoke_MethodHandles_lookup;
45 return ObjPtr<MethodHandlesLookup>::DownCast(lookup->InvokeStatic<'L'>(self));
46 }
47
FindConstructor(Thread * const self,Handle<Class> klass,Handle<MethodType> method_type)48 ObjPtr<MethodHandle> MethodHandlesLookup::FindConstructor(Thread* const self,
49 Handle<Class> klass,
50 Handle<MethodType> method_type) {
51 ArtMethod* find_constructor =
52 WellKnownClasses::java_lang_invoke_MethodHandles_Lookup_findConstructor;
53 return ObjPtr<MethodHandle>::DownCast(
54 find_constructor->InvokeFinal<'L', 'L', 'L'>(self, this, klass.Get(), method_type.Get()));
55 }
56
57 } // namespace mirror
58 } // namespace art
59