Home | History | Annotate | Download | only in runtime
      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_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 
     24 namespace art {
     25 
     26 namespace mirror {
     27   class ClassLoader;
     28   class DexCache;
     29 }  // namespace mirror
     30 class ArtField;
     31 class ArtMethod;
     32 class ClassLinker;
     33 template<class T> class MutableHandle;
     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 mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method,
     59                                                 uint32_t parameter_idx,
     60                                                 Handle<mirror::Class> annotation_class)
     61     REQUIRES_SHARED(Locks::mutator_lock_);
     62 bool GetParametersMetadataForMethod(ArtMethod* method,
     63                                     MutableHandle<mirror::ObjectArray<mirror::String>>* names,
     64                                     MutableHandle<mirror::IntArray>* access_flags)
     65     REQUIRES_SHARED(Locks::mutator_lock_);
     66 mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method)
     67     REQUIRES_SHARED(Locks::mutator_lock_);
     68 // 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.
     73 bool IsMethodAnnotationPresent(ArtMethod* method,
     74                                Handle<mirror::Class> annotation_class,
     75                                uint32_t visibility = DexFile::kDexVisibilityRuntime,
     76                                bool lookup_in_resolved_boot_classes = false)
     77     REQUIRES_SHARED(Locks::mutator_lock_);
     78 
     79 // Class annotations.
     80 mirror::Object* GetAnnotationForClass(Handle<mirror::Class> klass,
     81                                       Handle<mirror::Class> annotation_class)
     82     REQUIRES_SHARED(Locks::mutator_lock_);
     83 mirror::ObjectArray<mirror::Object>* GetAnnotationsForClass(Handle<mirror::Class> klass)
     84     REQUIRES_SHARED(Locks::mutator_lock_);
     85 mirror::ObjectArray<mirror::Class>* GetDeclaredClasses(Handle<mirror::Class> klass)
     86     REQUIRES_SHARED(Locks::mutator_lock_);
     87 mirror::Class* GetDeclaringClass(Handle<mirror::Class> klass)
     88     REQUIRES_SHARED(Locks::mutator_lock_);
     89 mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass)
     90     REQUIRES_SHARED(Locks::mutator_lock_);
     91 mirror::Object* GetEnclosingMethod(Handle<mirror::Class> klass)
     92     REQUIRES_SHARED(Locks::mutator_lock_);
     93 bool GetInnerClass(Handle<mirror::Class> klass, mirror::String** name)
     94     REQUIRES_SHARED(Locks::mutator_lock_);
     95 bool GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags)
     96     REQUIRES_SHARED(Locks::mutator_lock_);
     97 mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForClass(Handle<mirror::Class> klass)
     98     REQUIRES_SHARED(Locks::mutator_lock_);
     99 const char* GetSourceDebugExtension(Handle<mirror::Class> klass)
    100     REQUIRES_SHARED(Locks::mutator_lock_);
    101 bool 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.
    106 int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t rel_pc)
    107     REQUIRES_SHARED(Locks::mutator_lock_);
    108 
    109 // Annotations iterator.
    110 class 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_
    140