Home | History | Annotate | Download | only in mirror
      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 "gc_root.h"
     22 #include "handle.h"
     23 #include "obj_ptr.h"
     24 #include "object.h"
     25 
     26 namespace art {
     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   static mirror::MethodHandlesLookup* Create(Thread* const self,
     40                                              Handle<Class> lookup_class)
     41       REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
     42 
     43   static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
     44     return static_class_.Read();
     45   }
     46 
     47   static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
     48   static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
     49   static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
     50 
     51   // Returns the result of java.lang.invoke.MethodHandles.lookup().
     52   static mirror::MethodHandlesLookup* GetDefault(Thread* const self)
     53       REQUIRES_SHARED(Locks::mutator_lock_);
     54 
     55   // Find constructor using java.lang.invoke.MethodHandles$Lookup.findConstructor().
     56   mirror::MethodHandle* FindConstructor(Thread* const self,
     57                                         Handle<Class> klass,
     58                                         Handle<MethodType> method_type)
     59       REQUIRES_SHARED(Locks::mutator_lock_);
     60 
     61  private:
     62   static MemberOffset AllowedModesOffset() {
     63     return MemberOffset(OFFSETOF_MEMBER(MethodHandlesLookup, allowed_modes_));
     64   }
     65 
     66   static MemberOffset LookupClassOffset() {
     67     return MemberOffset(OFFSETOF_MEMBER(MethodHandlesLookup, lookup_class_));
     68   }
     69 
     70   HeapReference<mirror::Class> lookup_class_;
     71 
     72   int32_t allowed_modes_;
     73 
     74   static GcRoot<mirror::Class> static_class_;  // java.lang.invoke.MethodHandles.Lookup.class
     75 
     76   friend struct art::MethodHandlesLookupOffsets;  // for verifying offset information
     77   DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandlesLookup);
     78 };
     79 
     80 }  // namespace mirror
     81 }  // namespace art
     82 
     83 #endif  // ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_
     84