blob: 750a16741d15073017766c20709b721c95b16863 [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:
35 // Called from Constructor::CreateFromArtMethod, Method::CreateFromArtMethod.
36 template <PointerSize kPointerSize, bool kTransactionActive>
37 bool CreateFromArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_)
38 REQUIRES(!Roles::uninterruptible_);
39
Vladimir Marko4df2d802018-09-27 16:42:44 +000040 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
41 ArtMethod* GetArtMethod() REQUIRES_SHARED(Locks::mutator_lock_) {
42 return reinterpret_cast64<ArtMethod*>(GetField64<kVerifyFlags>(ArtMethodOffset()));
43 }
44
Alex Lightc18eba32019-09-24 14:36:27 -070045 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
46 inline void VisitTarget(ReflectiveValueVisitor* v) REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000047
Vladimir Marko4df2d802018-09-27 16:42:44 +000048 template <bool kTransactionActive = false,
49 bool kCheckTransaction = true,
50 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Vladimir Marko0eefb9b2019-03-27 15:04:31 +000051 void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko4df2d802018-09-27 16:42:44 +000052
Vladimir Marko0eefb9b2019-03-27 15:04:31 +000053 ObjPtr<mirror::Class> GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
Neil Fuller0e844392016-09-08 13:43:31 +010054
Vladimir Markoca8de0a2018-07-04 11:56:08 +010055 static MemberOffset ArtMethodOffset() {
56 return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_));
57 }
58
Neil Fuller16b21cd2016-08-12 09:37:02 +010059 private:
Neil Fuller60458a02016-09-01 15:32:44 +010060 uint16_t has_real_parameter_data_;
Neil Fuller0e844392016-09-08 13:43:31 +010061 HeapReference<mirror::Class> declaring_class_;
62 HeapReference<mirror::Class> declaring_class_of_overridden_method_;
Neil Fuller60458a02016-09-01 15:32:44 +010063 HeapReference<mirror::Array> parameters_;
Neil Fuller0e844392016-09-08 13:43:31 +010064 uint64_t art_method_;
65 uint32_t access_flags_;
66 uint32_t dex_method_index_;
67
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000068 template<bool kTransactionActive = false>
69 void SetDeclaringClass(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) {
70 SetFieldObject<kTransactionActive>(DeclaringClassOffset(), klass);
71 }
72
73 template<bool kTransactionActive = false>
74 void SetAccessFlags(uint32_t flags) REQUIRES_SHARED(Locks::mutator_lock_) {
75 SetField32<kTransactionActive>(AccessFlagsOffset(), flags);
76 }
77
78 template<bool kTransactionActive = false>
79 void SetDexMethodIndex(uint32_t idx) REQUIRES_SHARED(Locks::mutator_lock_) {
80 SetField32<kTransactionActive>(DexMethodIndexOffset(), idx);
81 }
82
Neil Fuller0e844392016-09-08 13:43:31 +010083 static MemberOffset DeclaringClassOffset() {
84 return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_));
85 }
86 static MemberOffset DeclaringClassOfOverriddenMethodOffset() {
87 return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_of_overridden_method_));
88 }
89 static MemberOffset AccessFlagsOffset() {
90 return MemberOffset(OFFSETOF_MEMBER(Executable, access_flags_));
91 }
92 static MemberOffset DexMethodIndexOffset() {
93 return MemberOffset(OFFSETOF_MEMBER(Executable, dex_method_index_));
94 }
Neil Fuller60458a02016-09-01 15:32:44 +010095
Neil Fuller16b21cd2016-08-12 09:37:02 +010096 friend struct art::ExecutableOffsets; // for verifying offset information
97 DISALLOW_IMPLICIT_CONSTRUCTORS(Executable);
98};
99
100} // namespace mirror
101} // namespace art
102
103#endif // ART_RUNTIME_MIRROR_EXECUTABLE_H_