| Neil Fuller | 16b21cd | 2016-08-12 09:37:02 +0100 | [diff] [blame] | 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" |
| Vladimir Marko | 0eefb9b | 2019-03-27 15:04:31 +0000 | [diff] [blame] | 21 | #include "object.h" |
| Neil Fuller | 16b21cd | 2016-08-12 09:37:02 +0100 | [diff] [blame] | 22 | #include "read_barrier_option.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | struct ExecutableOffsets; |
| 27 | class ArtMethod; |
| Alex Light | c18eba3 | 2019-09-24 14:36:27 -0700 | [diff] [blame] | 28 | class ReflectiveValueVisitor; |
| Neil Fuller | 16b21cd | 2016-08-12 09:37:02 +0100 | [diff] [blame] | 29 | |
| 30 | namespace mirror { |
| 31 | |
| 32 | // C++ mirror of java.lang.reflect.Executable. |
| 33 | class MANAGED Executable : public AccessibleObject { |
| Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 34 | public: |
| Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 35 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 36 | ArtMethod* GetArtMethod() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 37 | return reinterpret_cast64<ArtMethod*>(GetField64<kVerifyFlags>(ArtMethodOffset())); |
| 38 | } |
| 39 | |
| Alex Light | c18eba3 | 2019-09-24 14:36:27 -0700 | [diff] [blame] | 40 | template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 41 | inline void VisitTarget(ReflectiveValueVisitor* v) REQUIRES(Locks::mutator_lock_); |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 42 | |
| Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 43 | template <bool kTransactionActive = false, |
| 44 | bool kCheckTransaction = true, |
| 45 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| Vladimir Marko | 0eefb9b | 2019-03-27 15:04:31 +0000 | [diff] [blame] | 46 | void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
| Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 47 | |
| Vladimir Marko | 0eefb9b | 2019-03-27 15:04:31 +0000 | [diff] [blame] | 48 | ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_); |
| Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 49 | |
| Vladimir Marko | ca8de0a | 2018-07-04 11:56:08 +0100 | [diff] [blame] | 50 | static MemberOffset ArtMethodOffset() { |
| 51 | return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_)); |
| 52 | } |
| 53 | |
| Vladimir Marko | b6f4c79 | 2020-05-04 15:37:29 +0100 | [diff] [blame] | 54 | protected: |
| 55 | // Called from Constructor::CreateFromArtMethod, Method::CreateFromArtMethod. |
| 56 | template <PointerSize kPointerSize> |
| 57 | void InitializeFromArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) |
| 58 | REQUIRES(!Roles::uninterruptible_); |
| 59 | |
| 60 | |
| Neil Fuller | 16b21cd | 2016-08-12 09:37:02 +0100 | [diff] [blame] | 61 | private: |
| Vladimir Marko | c7993d5 | 2021-01-27 15:20:56 +0000 | [diff] [blame^] | 62 | uint8_t has_real_parameter_data_; |
| 63 | |
| 64 | // Padding required for matching alignment with the Java peer. |
| 65 | uint8_t padding_[2] ATTRIBUTE_UNUSED; |
| 66 | |
| Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 67 | HeapReference<mirror::Class> declaring_class_; |
| 68 | HeapReference<mirror::Class> declaring_class_of_overridden_method_; |
| Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 69 | HeapReference<mirror::Array> parameters_; |
| Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 70 | uint64_t art_method_; |
| 71 | uint32_t access_flags_; |
| 72 | uint32_t dex_method_index_; |
| 73 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 74 | template<bool kTransactionActive = false> |
| 75 | void SetDeclaringClass(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 76 | SetFieldObject<kTransactionActive>(DeclaringClassOffset(), klass); |
| 77 | } |
| 78 | |
| 79 | template<bool kTransactionActive = false> |
| 80 | void SetAccessFlags(uint32_t flags) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 81 | SetField32<kTransactionActive>(AccessFlagsOffset(), flags); |
| 82 | } |
| 83 | |
| 84 | template<bool kTransactionActive = false> |
| 85 | void SetDexMethodIndex(uint32_t idx) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 86 | SetField32<kTransactionActive>(DexMethodIndexOffset(), idx); |
| 87 | } |
| 88 | |
| Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 89 | static MemberOffset DeclaringClassOffset() { |
| 90 | return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_)); |
| 91 | } |
| 92 | static MemberOffset DeclaringClassOfOverriddenMethodOffset() { |
| 93 | return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_of_overridden_method_)); |
| 94 | } |
| 95 | static MemberOffset AccessFlagsOffset() { |
| 96 | return MemberOffset(OFFSETOF_MEMBER(Executable, access_flags_)); |
| 97 | } |
| 98 | static MemberOffset DexMethodIndexOffset() { |
| 99 | return MemberOffset(OFFSETOF_MEMBER(Executable, dex_method_index_)); |
| 100 | } |
| Neil Fuller | 60458a0 | 2016-09-01 15:32:44 +0100 | [diff] [blame] | 101 | |
| Neil Fuller | 16b21cd | 2016-08-12 09:37:02 +0100 | [diff] [blame] | 102 | friend struct art::ExecutableOffsets; // for verifying offset information |
| 103 | DISALLOW_IMPLICIT_CONSTRUCTORS(Executable); |
| 104 | }; |
| 105 | |
| 106 | } // namespace mirror |
| 107 | } // namespace art |
| 108 | |
| 109 | #endif // ART_RUNTIME_MIRROR_EXECUTABLE_H_ |