• 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 "object.h"
21 #include "string.h"
22 #include "mirror/object_array.h"
23 #include "utils.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 mirror::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 
StaticClass()39   static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
40     return static_class_.Read();
41   }
42 
GetPTypes()43   ObjectArray<Class>* GetPTypes() REQUIRES_SHARED(Locks::mutator_lock_) {
44     return GetFieldObject<ObjectArray<Class>>(OFFSET_OF_OBJECT_MEMBER(MethodType, p_types_));
45   }
46 
47   // Number of virtual registers required to hold the parameters for
48   // this method type.
49   size_t NumberOfVRegs() REQUIRES_SHARED(Locks::mutator_lock_);
50 
GetRType()51   Class* GetRType() REQUIRES_SHARED(Locks::mutator_lock_) {
52     return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(MethodType, r_type_));
53   }
54 
55   static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
56   static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
57   static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
58 
59   // Returns true iff. |this| is an exact match for method type |target|, i.e
60   // iff. they have the same return types and parameter types.
61   bool IsExactMatch(mirror::MethodType* target) REQUIRES_SHARED(Locks::mutator_lock_);
62 
63   // Returns true iff. |this| can be converted to match |target| method type, i.e
64   // iff. they have convertible return types and parameter types.
65   bool IsConvertible(mirror::MethodType* target) REQUIRES_SHARED(Locks::mutator_lock_);
66 
67   // Returns the pretty descriptor for this method type, suitable for display in
68   // exception messages and the like.
69   std::string PrettyDescriptor() REQUIRES_SHARED(Locks::mutator_lock_);
70 
71  private:
FormOffset()72   static MemberOffset FormOffset() {
73     return MemberOffset(OFFSETOF_MEMBER(MethodType, form_));
74   }
75 
MethodDescriptorOffset()76   static MemberOffset MethodDescriptorOffset() {
77     return MemberOffset(OFFSETOF_MEMBER(MethodType, method_descriptor_));
78   }
79 
PTypesOffset()80   static MemberOffset PTypesOffset() {
81     return MemberOffset(OFFSETOF_MEMBER(MethodType, p_types_));
82   }
83 
RTypeOffset()84   static MemberOffset RTypeOffset() {
85     return MemberOffset(OFFSETOF_MEMBER(MethodType, r_type_));
86   }
87 
WrapAltOffset()88   static MemberOffset WrapAltOffset() {
89     return MemberOffset(OFFSETOF_MEMBER(MethodType, wrap_alt_));
90   }
91 
92   HeapReference<mirror::Object> form_;  // Unused in the runtime
93   HeapReference<mirror::String> method_descriptor_;  // Unused in the runtime
94   HeapReference<ObjectArray<mirror::Class>> p_types_;
95   HeapReference<mirror::Class> r_type_;
96   HeapReference<mirror::Object> wrap_alt_;  // Unused in the runtime
97 
98   static GcRoot<mirror::Class> static_class_;  // java.lang.invoke.MethodType.class
99 
100   friend struct art::MethodTypeOffsets;  // for verifying offset information
101   DISALLOW_IMPLICIT_CONSTRUCTORS(MethodType);
102 };
103 
104 }  // namespace mirror
105 }  // namespace art
106 
107 #endif  // ART_RUNTIME_MIRROR_METHOD_TYPE_H_
108