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