blob: 6f9fc0bc16b990e828505dd05ce6d9d87793fcaf [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:
Vladimir Marko4df2d802018-09-27 16:42:44 +000035 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
36 ArtMethod* GetArtMethod() REQUIRES_SHARED(Locks::mutator_lock_) {
37 return reinterpret_cast64<ArtMethod*>(GetField64<kVerifyFlags>(ArtMethodOffset()));
38 }
39
Alex Lightc18eba32019-09-24 14:36:27 -070040 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
41 inline void VisitTarget(ReflectiveValueVisitor* v) REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000042
Vladimir Marko4df2d802018-09-27 16:42:44 +000043 template <bool kTransactionActive = false,
44 bool kCheckTransaction = true,
45 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Vladimir Marko0eefb9b2019-03-27 15:04:31 +000046 void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko4df2d802018-09-27 16:42:44 +000047
Vladimir Marko0eefb9b2019-03-27 15:04:31 +000048 ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
Neil Fuller0e844392016-09-08 13:43:31 +010049
Vladimir Markoca8de0a2018-07-04 11:56:08 +010050 static MemberOffset ArtMethodOffset() {
51 return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_));
52 }
53
Vladimir Markob6f4c792020-05-04 15:37:29 +010054 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 Fuller16b21cd2016-08-12 09:37:02 +010061 private:
Vladimir Markoc7993d52021-01-27 15:20:56 +000062 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 Fuller0e844392016-09-08 13:43:31 +010067 HeapReference<mirror::Class> declaring_class_;
68 HeapReference<mirror::Class> declaring_class_of_overridden_method_;
Neil Fuller60458a02016-09-01 15:32:44 +010069 HeapReference<mirror::Array> parameters_;
Neil Fuller0e844392016-09-08 13:43:31 +010070 uint64_t art_method_;
71 uint32_t access_flags_;
72 uint32_t dex_method_index_;
73
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000074 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 Fuller0e844392016-09-08 13:43:31 +010089 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 Fuller60458a02016-09-01 15:32:44 +0100101
Neil Fuller16b21cd2016-08-12 09:37:02 +0100102 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_