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