hotspot/src/share/vm/oops/annotations.hpp
changeset 15097 9db149412e0e
parent 13728 882756847a04
child 15437 eabd4555d072
equal deleted inserted replaced
15096:3db45569f8c0 15097:9db149412e0e
    36 class outputStream;
    36 class outputStream;
    37 
    37 
    38 typedef Array<u1> AnnotationArray;
    38 typedef Array<u1> AnnotationArray;
    39 
    39 
    40 // Class to hold the various types of annotations. The only metadata that points
    40 // Class to hold the various types of annotations. The only metadata that points
    41 // to this is InstanceKlass.
    41 // to this is InstanceKlass, or another Annotations instance if this is a
       
    42 // a type_annotation instance.
    42 
    43 
    43 class Annotations: public MetaspaceObj {
    44 class Annotations: public MetaspaceObj {
    44 
    45 
    45   // Annotations for this class, or null if none.
    46   // Annotations for this class, or null if none.
    46   AnnotationArray*             _class_annotations;
    47   AnnotationArray*             _class_annotations;
    56   Array<AnnotationArray*>*     _methods_parameter_annotations;
    57   Array<AnnotationArray*>*     _methods_parameter_annotations;
    57   // Annotation objects (byte arrays) for methods' default values, or null if no
    58   // Annotation objects (byte arrays) for methods' default values, or null if no
    58   // such annotations.
    59   // such annotations.
    59   // Index is the idnum, which is initially the same as the methods array index.
    60   // Index is the idnum, which is initially the same as the methods array index.
    60   Array<AnnotationArray*>*     _methods_default_annotations;
    61   Array<AnnotationArray*>*     _methods_default_annotations;
       
    62   // Type annotations for this class, or null if none.
       
    63   Annotations*                 _type_annotations;
    61 
    64 
    62   // Constructor where some some values are known to not be null
    65   // Constructor where some some values are known to not be null
    63   Annotations(Array<AnnotationArray*>* fa, Array<AnnotationArray*>* ma,
    66   Annotations(Array<AnnotationArray*>* fa, Array<AnnotationArray*>* ma,
    64               Array<AnnotationArray*>* mpa, Array<AnnotationArray*>* mda) :
    67               Array<AnnotationArray*>* mpa, Array<AnnotationArray*>* mda) :
    65                  _class_annotations(NULL),
    68                  _class_annotations(NULL),
    66                  _fields_annotations(fa),
    69                  _fields_annotations(fa),
    67                  _methods_annotations(ma),
    70                  _methods_annotations(ma),
    68                  _methods_parameter_annotations(mpa),
    71                  _methods_parameter_annotations(mpa),
    69                  _methods_default_annotations(mda) {}
    72                  _methods_default_annotations(mda),
       
    73                  _type_annotations(NULL) {}
    70 
    74 
    71  public:
    75  public:
    72   // Allocate instance of this class
    76   // Allocate instance of this class
    73   static Annotations* allocate(ClassLoaderData* loader_data, TRAPS);
    77   static Annotations* allocate(ClassLoaderData* loader_data, TRAPS);
    74   static Annotations* allocate(ClassLoaderData* loader_data,
    78   static Annotations* allocate(ClassLoaderData* loader_data,
    79   void deallocate_contents(ClassLoaderData* loader_data);
    83   void deallocate_contents(ClassLoaderData* loader_data);
    80   DEBUG_ONLY(bool on_stack() { return false; })  // for template
    84   DEBUG_ONLY(bool on_stack() { return false; })  // for template
    81   static int size()    { return sizeof(Annotations) / wordSize; }
    85   static int size()    { return sizeof(Annotations) / wordSize; }
    82 
    86 
    83   // Constructor to initialize to null
    87   // Constructor to initialize to null
    84   Annotations() : _class_annotations(NULL), _fields_annotations(NULL),
    88   Annotations() : _class_annotations(NULL),
       
    89                   _fields_annotations(NULL),
    85                   _methods_annotations(NULL),
    90                   _methods_annotations(NULL),
    86                   _methods_parameter_annotations(NULL),
    91                   _methods_parameter_annotations(NULL),
    87                   _methods_default_annotations(NULL) {}
    92                   _methods_default_annotations(NULL),
       
    93                   _type_annotations(NULL) {}
    88 
    94 
    89   AnnotationArray* class_annotations() const                       { return _class_annotations; }
    95   AnnotationArray* class_annotations() const                       { return _class_annotations; }
    90   Array<AnnotationArray*>* fields_annotations() const              { return _fields_annotations; }
    96   Array<AnnotationArray*>* fields_annotations() const              { return _fields_annotations; }
    91   Array<AnnotationArray*>* methods_annotations() const             { return _methods_annotations; }
    97   Array<AnnotationArray*>* methods_annotations() const             { return _methods_annotations; }
    92   Array<AnnotationArray*>* methods_parameter_annotations() const   { return _methods_parameter_annotations; }
    98   Array<AnnotationArray*>* methods_parameter_annotations() const   { return _methods_parameter_annotations; }
    93   Array<AnnotationArray*>* methods_default_annotations() const     { return _methods_default_annotations; }
    99   Array<AnnotationArray*>* methods_default_annotations() const     { return _methods_default_annotations; }
       
   100   Annotations* type_annotations() const                            { return _type_annotations; }
    94 
   101 
    95   void set_class_annotations(AnnotationArray* md)                     { _class_annotations = md; }
   102   void set_class_annotations(AnnotationArray* md)                     { _class_annotations = md; }
    96   void set_fields_annotations(Array<AnnotationArray*>* md)            { _fields_annotations = md; }
   103   void set_fields_annotations(Array<AnnotationArray*>* md)            { _fields_annotations = md; }
    97   void set_methods_annotations(Array<AnnotationArray*>* md)           { _methods_annotations = md; }
   104   void set_methods_annotations(Array<AnnotationArray*>* md)           { _methods_annotations = md; }
    98   void set_methods_parameter_annotations(Array<AnnotationArray*>* md) { _methods_parameter_annotations = md; }
   105   void set_methods_parameter_annotations(Array<AnnotationArray*>* md) { _methods_parameter_annotations = md; }
    99   void set_methods_default_annotations(Array<AnnotationArray*>* md)   { _methods_default_annotations = md; }
   106   void set_methods_default_annotations(Array<AnnotationArray*>* md)   { _methods_default_annotations = md; }
       
   107   void set_type_annotations(Annotations* annos)                       { _type_annotations = annos; }
   100 
   108 
   101   // Redefine classes support
   109   // Redefine classes support
   102   AnnotationArray* get_method_annotations_of(int idnum)
   110   AnnotationArray* get_method_annotations_of(int idnum)
   103                                                 { return get_method_annotations_from(idnum, _methods_annotations); }
   111                                                 { return get_method_annotations_from(idnum, _methods_annotations); }
   104 
   112 
   127   static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS);
   135   static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS);
   128 
   136 
   129   inline AnnotationArray* get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos);
   137   inline AnnotationArray* get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos);
   130   void set_annotations(Array<AnnotationArray*>* md, Array<AnnotationArray*>** md_p)  { *md_p = md; }
   138   void set_annotations(Array<AnnotationArray*>* md, Array<AnnotationArray*>** md_p)  { *md_p = md; }
   131 
   139 
       
   140   bool is_klass() const { return false; }
   132  private:
   141  private:
   133   void set_methods_annotations_of(instanceKlassHandle ik,
   142   void set_methods_annotations_of(instanceKlassHandle ik,
   134                                   int idnum, AnnotationArray* anno,
   143                                   int idnum, AnnotationArray* anno,
   135                                   Array<AnnotationArray*>** md_p, TRAPS);
   144                                   Array<AnnotationArray*>** md_p, TRAPS);
   136 
   145