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 "gc_root.h"
22 #include "object.h"
23 #include "read_barrier_option.h"
24 
25 namespace art {
26 
27 struct ExecutableOffsets;
28 class ArtMethod;
29 
30 namespace mirror {
31 
32 // C++ mirror of java.lang.reflect.Executable.
33 class MANAGED Executable : public AccessibleObject {
34  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 
40   ArtMethod* GetArtMethod() REQUIRES_SHARED(Locks::mutator_lock_);
41   // Only used by the image writer.
42   template <bool kTransactionActive = false>
43   void SetArtMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
44   mirror::Class* GetDeclaringClass() REQUIRES_SHARED(Locks::mutator_lock_);
45 
46  private:
47   uint16_t has_real_parameter_data_;
48   HeapReference<mirror::Class> declaring_class_;
49   HeapReference<mirror::Class> declaring_class_of_overridden_method_;
50   HeapReference<mirror::Array> parameters_;
51   uint64_t art_method_;
52   uint32_t access_flags_;
53   uint32_t dex_method_index_;
54 
ArtMethodOffset()55   static MemberOffset ArtMethodOffset() {
56     return MemberOffset(OFFSETOF_MEMBER(Executable, art_method_));
57   }
DeclaringClassOffset()58   static MemberOffset DeclaringClassOffset() {
59     return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_));
60   }
DeclaringClassOfOverriddenMethodOffset()61   static MemberOffset DeclaringClassOfOverriddenMethodOffset() {
62     return MemberOffset(OFFSETOF_MEMBER(Executable, declaring_class_of_overridden_method_));
63   }
AccessFlagsOffset()64   static MemberOffset AccessFlagsOffset() {
65     return MemberOffset(OFFSETOF_MEMBER(Executable, access_flags_));
66   }
DexMethodIndexOffset()67   static MemberOffset DexMethodIndexOffset() {
68     return MemberOffset(OFFSETOF_MEMBER(Executable, dex_method_index_));
69   }
70 
71   friend struct art::ExecutableOffsets;  // for verifying offset information
72   DISALLOW_IMPLICIT_CONSTRUCTORS(Executable);
73 };
74 
75 }  // namespace mirror
76 }  // namespace art
77 
78 #endif  // ART_RUNTIME_MIRROR_EXECUTABLE_H_
79