• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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_TYPE_H_
18 #define ART_RUNTIME_MIRROR_METHOD_TYPE_H_
19 
20 #include "base/utils.h"
21 #include "object_array.h"
22 #include "object.h"
23 #include "string.h"
24 
25 namespace art {
26 
27 struct MethodTypeOffsets;
28 
29 namespace mirror {
30 
31 // C++ mirror of java.lang.invoke.MethodType
32 class MANAGED MethodType : public Object {
33  public:
34   static MethodType* Create(Thread* const self,
35                             Handle<Class> return_type,
36                             Handle<ObjectArray<Class>> param_types)
37       REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
38 
39   static MethodType* CloneWithoutLeadingParameter(Thread* const self,
40                                                   ObjPtr<MethodType> method_type)
41       REQUIRES_SHARED(Locks::mutator_lock_);
42 
StaticClass()43   static Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
44     return static_class_.Read();
45   }
46 
GetPTypes()47   ObjectArray<Class>* GetPTypes() REQUIRES_SHARED(Locks::mutator_lock_) {
48     return GetFieldObject<ObjectArray<Class>>(OFFSET_OF_OBJECT_MEMBER(MethodType, p_types_));
49   }
50 
GetNumberOfPTypes()51   int GetNumberOfPTypes() REQUIRES_SHARED(Locks::mutator_lock_) {
52     return GetPTypes()->GetLength();
53   }
54 
55   // Number of virtual registers required to hold the parameters for
56   // this method type.
57   size_t NumberOfVRegs() REQUIRES_SHARED(Locks::mutator_lock_);
58 
GetRType()59   Class* GetRType() REQUIRES_SHARED(Locks::mutator_lock_) {
60     return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(MethodType, r_type_));
61   }
62 
63   static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
64   static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
65   static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
66 
67   // Returns true iff. |this| is an exact match for method type |target|, i.e
68   // iff. they have the same return types and parameter types.
69   bool IsExactMatch(MethodType* target) REQUIRES_SHARED(Locks::mutator_lock_);
70 
71   // Returns true iff. |this| can be converted to match |target| method type, i.e
72   // iff. they have convertible return types and parameter types.
73   bool IsConvertible(MethodType* target) REQUIRES_SHARED(Locks::mutator_lock_);
74 
75   // Returns the pretty descriptor for this method type, suitable for display in
76   // exception messages and the like.
77   std::string PrettyDescriptor() REQUIRES_SHARED(Locks::mutator_lock_);
78 
79  private:
FormOffset()80   static MemberOffset FormOffset() {
81     return MemberOffset(OFFSETOF_MEMBER(MethodType, form_));
82   }
83 
MethodDescriptorOffset()84   static MemberOffset MethodDescriptorOffset() {
85     return MemberOffset(OFFSETOF_MEMBER(MethodType, method_descriptor_));
86   }
87 
PTypesOffset()88   static MemberOffset PTypesOffset() {
89     return MemberOffset(OFFSETOF_MEMBER(MethodType, p_types_));
90   }
91 
RTypeOffset()92   static MemberOffset RTypeOffset() {
93     return MemberOffset(OFFSETOF_MEMBER(MethodType, r_type_));
94   }
95 
WrapAltOffset()96   static MemberOffset WrapAltOffset() {
97     return MemberOffset(OFFSETOF_MEMBER(MethodType, wrap_alt_));
98   }
99 
100   HeapReference<Object> form_;  // Unused in the runtime
101   HeapReference<String> method_descriptor_;  // Unused in the runtime
102   HeapReference<ObjectArray<Class>> p_types_;
103   HeapReference<Class> r_type_;
104   HeapReference<Object> wrap_alt_;  // Unused in the runtime
105 
106   static GcRoot<Class> static_class_;  // java.lang.invoke.MethodType.class
107 
108   friend struct art::MethodTypeOffsets;  // for verifying offset information
109   DISALLOW_IMPLICIT_CONSTRUCTORS(MethodType);
110 };
111 
112 }  // namespace mirror
113 }  // namespace art
114 
115 #endif  // ART_RUNTIME_MIRROR_METHOD_TYPE_H_
116