blob: e1088823c3506e681c7d3e2d283a96b3328f3e6e [file] [log] [blame]
David Sehr9323e6e2016-09-13 08:58:35 -07001/*
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_DEX_FILE_ANNOTATIONS_H_
18#define ART_RUNTIME_DEX_FILE_ANNOTATIONS_H_
19
20#include "dex_file.h"
21
22#include "mirror/object_array.h"
23
24namespace art {
25
26namespace mirror {
27 class ClassLoader;
28 class DexCache;
29} // namespace mirror
30class ArtField;
31class ArtMethod;
32class ClassLinker;
Neil Fuller79a21e72016-09-09 14:24:51 +010033template<class T> class MutableHandle;
David Sehr9323e6e2016-09-13 08:58:35 -070034
35namespace annotations {
36
37// Field annotations.
38mirror::Object* GetAnnotationForField(ArtField* field, Handle<mirror::Class> annotation_class)
39 REQUIRES_SHARED(Locks::mutator_lock_);
40mirror::ObjectArray<mirror::Object>* GetAnnotationsForField(ArtField* field)
41 REQUIRES_SHARED(Locks::mutator_lock_);
42mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForField(ArtField* field)
43 REQUIRES_SHARED(Locks::mutator_lock_);
44bool IsFieldAnnotationPresent(ArtField* field, Handle<mirror::Class> annotation_class)
45 REQUIRES_SHARED(Locks::mutator_lock_);
46
47// Method annotations.
48mirror::Object* GetAnnotationDefaultValue(ArtMethod* method)
49 REQUIRES_SHARED(Locks::mutator_lock_);
50mirror::Object* GetAnnotationForMethod(ArtMethod* method, Handle<mirror::Class> annotation_class)
51 REQUIRES_SHARED(Locks::mutator_lock_);
52mirror::ObjectArray<mirror::Object>* GetAnnotationsForMethod(ArtMethod* method)
53 REQUIRES_SHARED(Locks::mutator_lock_);
54mirror::ObjectArray<mirror::Class>* GetExceptionTypesForMethod(ArtMethod* method)
55 REQUIRES_SHARED(Locks::mutator_lock_);
56mirror::ObjectArray<mirror::Object>* GetParameterAnnotations(ArtMethod* method)
57 REQUIRES_SHARED(Locks::mutator_lock_);
58mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method,
59 uint32_t parameter_idx,
60 Handle<mirror::Class> annotation_class)
61 REQUIRES_SHARED(Locks::mutator_lock_);
Neil Fuller79a21e72016-09-09 14:24:51 +010062bool GetParametersMetadataForMethod(ArtMethod* method,
63 MutableHandle<mirror::ObjectArray<mirror::String>>* names,
64 MutableHandle<mirror::IntArray>* access_flags)
65 REQUIRES_SHARED(Locks::mutator_lock_);
David Sehr9323e6e2016-09-13 08:58:35 -070066mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method)
67 REQUIRES_SHARED(Locks::mutator_lock_);
Roland Levillain35e42f02017-06-26 18:14:39 +010068// Check whether `method` is annotated with `annotation_class`.
69// If `lookup_in_resolved_boot_classes` is true, look up any of the
70// method's annotations' classes in the bootstrap class loader's
71// resolved types; if it is false (default value), resolve them as a
72// side effect.
73bool IsMethodAnnotationPresent(ArtMethod* method,
74 Handle<mirror::Class> annotation_class,
75 uint32_t visibility = DexFile::kDexVisibilityRuntime,
76 bool lookup_in_resolved_boot_classes = false)
David Sehr9323e6e2016-09-13 08:58:35 -070077 REQUIRES_SHARED(Locks::mutator_lock_);
78
79// Class annotations.
80mirror::Object* GetAnnotationForClass(Handle<mirror::Class> klass,
81 Handle<mirror::Class> annotation_class)
82 REQUIRES_SHARED(Locks::mutator_lock_);
83mirror::ObjectArray<mirror::Object>* GetAnnotationsForClass(Handle<mirror::Class> klass)
84 REQUIRES_SHARED(Locks::mutator_lock_);
85mirror::ObjectArray<mirror::Class>* GetDeclaredClasses(Handle<mirror::Class> klass)
86 REQUIRES_SHARED(Locks::mutator_lock_);
87mirror::Class* GetDeclaringClass(Handle<mirror::Class> klass)
88 REQUIRES_SHARED(Locks::mutator_lock_);
89mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass)
90 REQUIRES_SHARED(Locks::mutator_lock_);
91mirror::Object* GetEnclosingMethod(Handle<mirror::Class> klass)
92 REQUIRES_SHARED(Locks::mutator_lock_);
93bool GetInnerClass(Handle<mirror::Class> klass, mirror::String** name)
94 REQUIRES_SHARED(Locks::mutator_lock_);
95bool GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags)
96 REQUIRES_SHARED(Locks::mutator_lock_);
97mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForClass(Handle<mirror::Class> klass)
98 REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson77d8a1c2017-04-24 14:53:19 +010099const char* GetSourceDebugExtension(Handle<mirror::Class> klass)
100 REQUIRES_SHARED(Locks::mutator_lock_);
David Sehr9323e6e2016-09-13 08:58:35 -0700101bool IsClassAnnotationPresent(Handle<mirror::Class> klass,
102 Handle<mirror::Class> annotation_class)
103 REQUIRES_SHARED(Locks::mutator_lock_);
104
105// Map back from a PC to the line number in a method.
106int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t rel_pc)
107 REQUIRES_SHARED(Locks::mutator_lock_);
108
109// Annotations iterator.
110class RuntimeEncodedStaticFieldValueIterator : public EncodedStaticFieldValueIterator {
111 public:
112 // A constructor meant to be called from runtime code.
113 RuntimeEncodedStaticFieldValueIterator(const DexFile& dex_file,
114 Handle<mirror::DexCache>* dex_cache,
115 Handle<mirror::ClassLoader>* class_loader,
116 ClassLinker* linker,
117 const DexFile::ClassDef& class_def)
118 REQUIRES_SHARED(Locks::mutator_lock_)
119 : EncodedStaticFieldValueIterator(dex_file, class_def),
120 dex_cache_(dex_cache),
121 class_loader_(class_loader),
122 linker_(linker) {
123 }
124
125 template<bool kTransactionActive>
126 void ReadValueToField(ArtField* field) const REQUIRES_SHARED(Locks::mutator_lock_);
127
128 private:
129 Handle<mirror::DexCache>* const dex_cache_; // Dex cache to resolve literal objects.
130 Handle<mirror::ClassLoader>* const class_loader_; // ClassLoader to resolve types.
131 ClassLinker* linker_; // Linker to resolve literal objects.
132 DISALLOW_IMPLICIT_CONSTRUCTORS(RuntimeEncodedStaticFieldValueIterator);
133};
134
135} // namespace annotations
136
137} // namespace art
138
139#endif // ART_RUNTIME_DEX_FILE_ANNOTATIONS_H_