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 #ifndef ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_
18 #define ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_
19 
20 #include "base/utils.h"
21 #include "handle.h"
22 #include "obj_ptr.h"
23 #include "object.h"
24 
25 namespace art {
26 
27 struct MethodHandlesLookupOffsets;
28 class RootVisitor;
29 
30 namespace mirror {
31 
32 class MethodHandle;
33 class MethodType;
34 
35 // C++ mirror of java.lang.invoke.MethodHandles.Lookup
36 class MANAGED MethodHandlesLookup : public Object {
37  public:
38   static ObjPtr<mirror::MethodHandlesLookup> Create(Thread* const self, Handle<Class> lookup_class)
39       REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
40 
41   // Returns the result of java.lang.invoke.MethodHandles.lookup().
42   static ObjPtr<mirror::MethodHandlesLookup> GetDefault(Thread* const self)
43       REQUIRES_SHARED(Locks::mutator_lock_);
44 
45   // Find constructor using java.lang.invoke.MethodHandles$Lookup.findConstructor().
46   ObjPtr<mirror::MethodHandle> FindConstructor(Thread* const self,
47                                                Handle<Class> klass,
48                                                Handle<MethodType> method_type)
49       REQUIRES_SHARED(Locks::mutator_lock_);
50 
51  private:
AllowedModesOffset()52   static MemberOffset AllowedModesOffset() {
53     return MemberOffset(OFFSETOF_MEMBER(MethodHandlesLookup, allowed_modes_));
54   }
55 
LookupClassOffset()56   static MemberOffset LookupClassOffset() {
57     return MemberOffset(OFFSETOF_MEMBER(MethodHandlesLookup, lookup_class_));
58   }
59 
60   HeapReference<mirror::Class> lookup_class_;
61 
62   int32_t allowed_modes_;
63 
64   friend struct art::MethodHandlesLookupOffsets;  // for verifying offset information
65   DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandlesLookup);
66 };
67 
68 }  // namespace mirror
69 }  // namespace art
70 
71 #endif  // ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_
72