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_DEX_DEX_FILE_ANNOTATIONS_H_ 18 #define ART_RUNTIME_DEX_DEX_FILE_ANNOTATIONS_H_ 19 20 #include "dex/dex_file.h" 21 22 #include "handle.h" 23 #include "mirror/dex_cache.h" 24 #include "mirror/object_array.h" 25 26 namespace art { 27 28 namespace mirror { 29 class ClassLoader; 30 } // namespace mirror 31 class ArtField; 32 class ArtMethod; 33 class ClassLinker; 34 35 namespace annotations { 36 37 // Field annotations. 38 mirror::Object* GetAnnotationForField(ArtField* field, Handle<mirror::Class> annotation_class) 39 REQUIRES_SHARED(Locks::mutator_lock_); 40 mirror::ObjectArray<mirror::Object>* GetAnnotationsForField(ArtField* field) 41 REQUIRES_SHARED(Locks::mutator_lock_); 42 mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForField(ArtField* field) 43 REQUIRES_SHARED(Locks::mutator_lock_); 44 bool IsFieldAnnotationPresent(ArtField* field, Handle<mirror::Class> annotation_class) 45 REQUIRES_SHARED(Locks::mutator_lock_); 46 47 // Method annotations. 48 mirror::Object* GetAnnotationDefaultValue(ArtMethod* method) 49 REQUIRES_SHARED(Locks::mutator_lock_); 50 mirror::Object* GetAnnotationForMethod(ArtMethod* method, Handle<mirror::Class> annotation_class) 51 REQUIRES_SHARED(Locks::mutator_lock_); 52 mirror::ObjectArray<mirror::Object>* GetAnnotationsForMethod(ArtMethod* method) 53 REQUIRES_SHARED(Locks::mutator_lock_); 54 mirror::ObjectArray<mirror::Class>* GetExceptionTypesForMethod(ArtMethod* method) 55 REQUIRES_SHARED(Locks::mutator_lock_); 56 mirror::ObjectArray<mirror::Object>* GetParameterAnnotations(ArtMethod* method) 57 REQUIRES_SHARED(Locks::mutator_lock_); 58 uint32_t GetNumberOfAnnotatedMethodParameters(ArtMethod* method) 59 REQUIRES_SHARED(Locks::mutator_lock_); 60 mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method, 61 uint32_t parameter_idx, 62 Handle<mirror::Class> annotation_class) 63 REQUIRES_SHARED(Locks::mutator_lock_); 64 bool GetParametersMetadataForMethod(ArtMethod* method, 65 MutableHandle<mirror::ObjectArray<mirror::String>>* names, 66 MutableHandle<mirror::IntArray>* access_flags) 67 REQUIRES_SHARED(Locks::mutator_lock_); 68 mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method) 69 REQUIRES_SHARED(Locks::mutator_lock_); 70 // Check whether `method` is annotated with `annotation_class`. 71 // If `lookup_in_resolved_boot_classes` is true, look up any of the 72 // method's annotations' classes in the bootstrap class loader's 73 // resolved types; if it is false (default value), resolve them as a 74 // side effect. 75 bool IsMethodAnnotationPresent(ArtMethod* method, 76 Handle<mirror::Class> annotation_class, 77 uint32_t visibility = DexFile::kDexVisibilityRuntime) 78 REQUIRES_SHARED(Locks::mutator_lock_); 79 // Check whether a method from the `dex_file` with the given `method_index` 80 // is annotated with @dalvik.annotation.optimization.FastNative or 81 // @dalvik.annotation.optimization.CriticalNative with build visibility. 82 // If yes, return the associated access flags, i.e. kAccFastNative or kAccCriticalNative. 83 uint32_t GetNativeMethodAnnotationAccessFlags(const DexFile& dex_file, 84 const DexFile::ClassDef& class_def, 85 uint32_t method_index); 86 87 // Class annotations. 88 mirror::Object* GetAnnotationForClass(Handle<mirror::Class> klass, 89 Handle<mirror::Class> annotation_class) 90 REQUIRES_SHARED(Locks::mutator_lock_); 91 mirror::ObjectArray<mirror::Object>* GetAnnotationsForClass(Handle<mirror::Class> klass) 92 REQUIRES_SHARED(Locks::mutator_lock_); 93 mirror::ObjectArray<mirror::Class>* GetDeclaredClasses(Handle<mirror::Class> klass) 94 REQUIRES_SHARED(Locks::mutator_lock_); 95 mirror::Class* GetDeclaringClass(Handle<mirror::Class> klass) 96 REQUIRES_SHARED(Locks::mutator_lock_); 97 mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass) 98 REQUIRES_SHARED(Locks::mutator_lock_); 99 mirror::Object* GetEnclosingMethod(Handle<mirror::Class> klass) 100 REQUIRES_SHARED(Locks::mutator_lock_); 101 bool GetInnerClass(Handle<mirror::Class> klass, mirror::String** name) 102 REQUIRES_SHARED(Locks::mutator_lock_); 103 bool GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags) 104 REQUIRES_SHARED(Locks::mutator_lock_); 105 mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForClass(Handle<mirror::Class> klass) 106 REQUIRES_SHARED(Locks::mutator_lock_); 107 const char* GetSourceDebugExtension(Handle<mirror::Class> klass) 108 REQUIRES_SHARED(Locks::mutator_lock_); 109 bool IsClassAnnotationPresent(Handle<mirror::Class> klass, 110 Handle<mirror::Class> annotation_class) 111 REQUIRES_SHARED(Locks::mutator_lock_); 112 113 // Map back from a PC to the line number in a method. 114 int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t rel_pc) 115 REQUIRES_SHARED(Locks::mutator_lock_); 116 117 // Annotations iterator. 118 class RuntimeEncodedStaticFieldValueIterator : public EncodedStaticFieldValueIterator { 119 public: 120 // A constructor meant to be called from runtime code. RuntimeEncodedStaticFieldValueIterator(Handle<mirror::DexCache> dex_cache,Handle<mirror::ClassLoader> class_loader,ClassLinker * linker,const DexFile::ClassDef & class_def)121 RuntimeEncodedStaticFieldValueIterator(Handle<mirror::DexCache> dex_cache, 122 Handle<mirror::ClassLoader> class_loader, 123 ClassLinker* linker, 124 const DexFile::ClassDef& class_def) 125 REQUIRES_SHARED(Locks::mutator_lock_) 126 : EncodedStaticFieldValueIterator(*dex_cache->GetDexFile(), class_def), 127 dex_cache_(dex_cache), 128 class_loader_(class_loader), 129 linker_(linker) { 130 } 131 132 template<bool kTransactionActive> 133 void ReadValueToField(ArtField* field) const REQUIRES_SHARED(Locks::mutator_lock_); 134 135 private: 136 const Handle<mirror::DexCache> dex_cache_; // Dex cache to resolve literal objects. 137 const Handle<mirror::ClassLoader> class_loader_; // ClassLoader to resolve types. 138 ClassLinker* const linker_; // Linker to resolve literal objects. 139 DISALLOW_IMPLICIT_CONSTRUCTORS(RuntimeEncodedStaticFieldValueIterator); 140 }; 141 142 } // namespace annotations 143 144 } // namespace art 145 146 #endif // ART_RUNTIME_DEX_DEX_FILE_ANNOTATIONS_H_ 147