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_array.h" 21 #include "object.h" 22 #include "string.h" 23 24 namespace art { 25 26 struct MethodTypeOffsets; 27 28 namespace mirror { 29 30 // C++ mirror of java.lang.invoke.MethodType 31 class MANAGED MethodType : public Object { 32 public: 33 MIRROR_CLASS("Ljava/lang/invoke/MethodType;"); 34 35 static ObjPtr<MethodType> Create(Thread* const self, 36 Handle<Class> return_type, 37 Handle<ObjectArray<Class>> param_types) 38 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); 39 40 static ObjPtr<MethodType> CloneWithoutLeadingParameter(Thread* const self, 41 ObjPtr<MethodType> method_type) 42 REQUIRES_SHARED(Locks::mutator_lock_); 43 44 // Collects trailing parameter types into an array. Assumes caller 45 // has checked trailing arguments are all of the same type. 46 static ObjPtr<MethodType> CollectTrailingArguments(Thread* const self, 47 ObjPtr<MethodType> method_type, 48 ObjPtr<Class> collector_array_class, 49 int32_t start_index) 50 REQUIRES_SHARED(Locks::mutator_lock_); 51 52 ObjPtr<ObjectArray<Class>> GetPTypes() REQUIRES_SHARED(Locks::mutator_lock_); 53 54 int GetNumberOfPTypes() REQUIRES_SHARED(Locks::mutator_lock_); 55 56 // Number of virtual registers required to hold the parameters for 57 // this method type. 58 size_t NumberOfVRegs() REQUIRES_SHARED(Locks::mutator_lock_); 59 60 ObjPtr<Class> GetRType() REQUIRES_SHARED(Locks::mutator_lock_); 61 62 // Returns true iff. |this| is an exact match for method type |target|, i.e 63 // iff. they have the same return types and parameter types. 64 bool IsExactMatch(ObjPtr<MethodType> target) REQUIRES_SHARED(Locks::mutator_lock_); 65 66 // Returns true iff. |this| can be converted to match |target| method type, i.e 67 // iff. they have convertible return types and parameter types. 68 bool IsConvertible(ObjPtr<MethodType> target) REQUIRES_SHARED(Locks::mutator_lock_); 69 70 // Returns the pretty descriptor for this method type, suitable for display in 71 // exception messages and the like. 72 std::string PrettyDescriptor() REQUIRES_SHARED(Locks::mutator_lock_); 73 74 private: FormOffset()75 static MemberOffset FormOffset() { 76 return MemberOffset(OFFSETOF_MEMBER(MethodType, form_)); 77 } 78 MethodDescriptorOffset()79 static MemberOffset MethodDescriptorOffset() { 80 return MemberOffset(OFFSETOF_MEMBER(MethodType, method_descriptor_)); 81 } 82 PTypesOffset()83 static MemberOffset PTypesOffset() { 84 return MemberOffset(OFFSETOF_MEMBER(MethodType, p_types_)); 85 } 86 RTypeOffset()87 static MemberOffset RTypeOffset() { 88 return MemberOffset(OFFSETOF_MEMBER(MethodType, r_type_)); 89 } 90 WrapAltOffset()91 static MemberOffset WrapAltOffset() { 92 return MemberOffset(OFFSETOF_MEMBER(MethodType, wrap_alt_)); 93 } 94 95 HeapReference<Object> form_; // Unused in the runtime 96 HeapReference<String> method_descriptor_; // Unused in the runtime 97 HeapReference<ObjectArray<Class>> p_types_; 98 HeapReference<Class> r_type_; 99 HeapReference<Object> wrap_alt_; // Unused in the runtime 100 101 friend struct art::MethodTypeOffsets; // for verifying offset information 102 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodType); 103 }; 104 105 } // namespace mirror 106 } // namespace art 107 108 #endif // ART_RUNTIME_MIRROR_METHOD_TYPE_H_ 109