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_EXECUTABLE_H_ 18 #define ART_RUNTIME_MIRROR_EXECUTABLE_H_ 19 20 #include "accessible_object.h" 21 #include "object.h" 22 #include "read_barrier_option.h" 23 24 namespace art { 25 26 struct ExecutableOffsets; 27 class ArtMethod; 28 class ReflectiveValueVisitor; 29 30 namespace mirror { 31 32 // C++ mirror of java.lang.reflect.Executable. 33 class MANAGED Executable : public AccessibleObject { 34 public: 35 MIRROR_CLASS("Ljava/lang/reflect/Executable;"); 36 37 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> GetArtMethod()38 ArtMethod* GetArtMethod() REQUIRES_SHARED(Locks::mutator_lock_) { 39 return reinterpret_cast64<ArtMethod*>(GetField64<kVerifyFlags>(ArtMethodOffset())); 40 } 41 42 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> 43 inline void VisitTarget(ReflectiveValueVisitor* v) REQUIRES(Locks::mutator_lock_); 44 45 template <bool kTransactionActive = false, 46 bool kCheckTransaction = true, 47 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> 48 void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 49 50 ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_); 51 ArtMethodOffset()52 static MemberOffset ArtMethodOffset() { 53 return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_)); 54 } 55 56 protected: 57 // Called from Constructor::CreateFromArtMethod, Method::CreateFromArtMethod. 58 template <PointerSize kPointerSize> 59 void InitializeFromArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) 60 REQUIRES(!Roles::uninterruptible_); 61 62 63 private: 64 uint8_t has_real_parameter_data_; 65 66 // Padding required for matching alignment with the Java peer. 67 uint8_t padding_[2] ATTRIBUTE_UNUSED; 68 69 HeapReference<mirror::Class> declaring_class_; 70 HeapReference<mirror::Class> declaring_class_of_overridden_method_; 71 HeapReference<mirror::Array> parameters_; 72 uint64_t art_method_; 73 uint32_t access_flags_; 74 uint32_t dex_method_index_; 75 76 template<bool kTransactionActive = false> SetDeclaringClass(ObjPtr<mirror::Class> klass)77 void SetDeclaringClass(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { 78 SetFieldObject<kTransactionActive>(DeclaringClassOffset(), klass); 79 } 80 81 template<bool kTransactionActive = false> SetAccessFlags(uint32_t flags)82 void SetAccessFlags(uint32_t flags) REQUIRES_SHARED(Locks::mutator_lock_) { 83 SetField32<kTransactionActive>(AccessFlagsOffset(), flags); 84 } 85 86 template<bool kTransactionActive = false> SetDexMethodIndex(uint32_t idx)87 void SetDexMethodIndex(uint32_t idx) REQUIRES_SHARED(Locks::mutator_lock_) { 88 SetField32<kTransactionActive>(DexMethodIndexOffset(), idx); 89 } 90 DeclaringClassOffset()91 static MemberOffset DeclaringClassOffset() { 92 return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_)); 93 } DeclaringClassOfOverriddenMethodOffset()94 static MemberOffset DeclaringClassOfOverriddenMethodOffset() { 95 return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_of_overridden_method_)); 96 } AccessFlagsOffset()97 static MemberOffset AccessFlagsOffset() { 98 return MemberOffset(OFFSETOF_MEMBER(Executable, access_flags_)); 99 } DexMethodIndexOffset()100 static MemberOffset DexMethodIndexOffset() { 101 return MemberOffset(OFFSETOF_MEMBER(Executable, dex_method_index_)); 102 } 103 104 friend struct art::ExecutableOffsets; // for verifying offset information 105 DISALLOW_IMPLICIT_CONSTRUCTORS(Executable); 106 }; 107 108 } // namespace mirror 109 } // namespace art 110 111 #endif // ART_RUNTIME_MIRROR_EXECUTABLE_H_ 112