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 true iff. |this| can be converted to match |target| method type within the 71 // current frame of the current MethodType. This limits conversions to assignability check 72 // for references and between scalar 32-bit types. 73 bool IsInPlaceConvertible(ObjPtr<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 friend struct art::MethodTypeOffsets; // for verifying offset information 107 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodType); 108 }; 109 110 } // namespace mirror 111 } // namespace art 112 113 #endif // ART_RUNTIME_MIRROR_METHOD_TYPE_H_ 114