blob: dc4ec9524341f4661de08c9bcd2242e2fe72af8b [file] [log] [blame]
Neil Fuller16b21cd2016-08-12 09:37:02 +01001/*
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 Marko0eefb9b2019-03-27 15:04:31 +000021#include "object.h"
Neil Fuller16b21cd2016-08-12 09:37:02 +010022#include "read_barrier_option.h"
23
24namespace art {
25
26struct ExecutableOffsets;
27class ArtMethod;
Alex Lightc18eba32019-09-24 14:36:27 -070028class ReflectiveValueVisitor;
Neil Fuller16b21cd2016-08-12 09:37:02 +010029
30namespace mirror {
31
32// C++ mirror of java.lang.reflect.Executable.
33class MANAGED Executable : public AccessibleObject {
Neil Fuller0e844392016-09-08 13:43:31 +010034 public:
Alex Light8f187c32021-04-20 14:29:00 -070035 MIRROR_CLASS("Ljava/lang/reflect/Executable;");
36
Vladimir Marko4df2d802018-09-27 16:42:44 +000037 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
38 ArtMethod* GetArtMethod() REQUIRES_SHARED(Locks::mutator_lock_) {
39 return reinterpret_cast64<ArtMethod*>(GetField64<kVerifyFlags>(ArtMethodOffset()));
40 }
41
Alex Lightc18eba32019-09-24 14:36:27 -070042 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
43 inline void VisitTarget(ReflectiveValueVisitor* v) REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000044
Vladimir Marko4df2d802018-09-27 16:42:44 +000045 template <bool kTransactionActive = false,
46 bool kCheckTransaction = true,
47 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Vladimir Marko0eefb9b2019-03-27 15:04:31 +000048 void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko4df2d802018-09-27 16:42:44 +000049
Vladimir Marko0eefb9b2019-03-27 15:04:31 +000050 ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
Neil Fuller0e844392016-09-08 13:43:31 +010051
Vladimir Markoca8de0a2018-07-04 11:56:08 +010052 static MemberOffset ArtMethodOffset() {
53 return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_));
54 }
55
Vladimir Markob6f4c792020-05-04 15:37:29 +010056 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
Neil Fuller16b21cd2016-08-12 09:37:02 +010063 private:
Vladimir Markoc7993d52021-01-27 15:20:56 +000064 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
Neil Fuller0e844392016-09-08 13:43:31 +010069 HeapReference<mirror::Class> declaring_class_;
70 HeapReference<mirror::Class> declaring_class_of_overridden_method_;
Neil Fuller60458a02016-09-01 15:32:44 +010071 HeapReference<mirror::Array> parameters_;
Neil Fuller0e844392016-09-08 13:43:31 +010072 uint64_t art_method_;
73 uint32_t access_flags_;
74 uint32_t dex_method_index_;
75
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000076 template<bool kTransactionActive = false>
77 void SetDeclaringClass(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) {
78 SetFieldObject<kTransactionActive>(DeclaringClassOffset(), klass);
79 }
80
81 template<bool kTransactionActive = false>
82 void SetAccessFlags(uint32_t flags) REQUIRES_SHARED(Locks::mutator_lock_) {
83 SetField32<kTransactionActive>(AccessFlagsOffset(), flags);
84 }
85
86 template<bool kTransactionActive = false>
87 void SetDexMethodIndex(uint32_t idx) REQUIRES_SHARED(Locks::mutator_lock_) {
88 SetField32<kTransactionActive>(DexMethodIndexOffset(), idx);
89 }
90
Neil Fuller0e844392016-09-08 13:43:31 +010091 static MemberOffset DeclaringClassOffset() {
92 return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_));
93 }
94 static MemberOffset DeclaringClassOfOverriddenMethodOffset() {
95 return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_of_overridden_method_));
96 }
97 static MemberOffset AccessFlagsOffset() {
98 return MemberOffset(OFFSETOF_MEMBER(Executable, access_flags_));
99 }
100 static MemberOffset DexMethodIndexOffset() {
101 return MemberOffset(OFFSETOF_MEMBER(Executable, dex_method_index_));
102 }
Neil Fuller60458a02016-09-01 15:32:44 +0100103
Neil Fuller16b21cd2016-08-12 09:37:02 +0100104 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_