src/share/vm/oops/annotations.hpp

changeset 4037
da91efe96a93
child 4393
35431a769282
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/oops/annotations.hpp	Sat Sep 01 13:25:18 2012 -0400
     1.3 @@ -0,0 +1,153 @@
     1.4 +/*
     1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_OOPS_ANNOTATIONS_HPP
    1.29 +#define SHARE_VM_OOPS_ANNOTATIONS_HPP
    1.30 +
    1.31 +#include "oops/metadata.hpp"
    1.32 +#include "runtime/handles.hpp"
    1.33 +#include "utilities/array.hpp"
    1.34 +#include "utilities/exceptions.hpp"
    1.35 +#include "utilities/globalDefinitions.hpp"
    1.36 +
    1.37 +
    1.38 +class ClassLoaderData;
    1.39 +class outputStream;
    1.40 +
    1.41 +typedef Array<u1> AnnotationArray;
    1.42 +
    1.43 +// Class to hold the various types of annotations. The only metadata that points
    1.44 +// to this is InstanceKlass.
    1.45 +
    1.46 +class Annotations: public MetaspaceObj {
    1.47 +
    1.48 +  // Annotations for this class, or null if none.
    1.49 +  AnnotationArray*             _class_annotations;
    1.50 +  // Annotation objects (byte arrays) for fields, or null if no annotations.
    1.51 +  // Indices correspond to entries (not indices) in fields array.
    1.52 +  Array<AnnotationArray*>*     _fields_annotations;
    1.53 +  // Annotation objects (byte arrays) for methods, or null if no annotations.
    1.54 +  // Index is the idnum, which is initially the same as the methods array index.
    1.55 +  Array<AnnotationArray*>*     _methods_annotations;
    1.56 +  // Annotation objects (byte arrays) for methods' parameters, or null if no
    1.57 +  // such annotations.
    1.58 +  // Index is the idnum, which is initially the same as the methods array index.
    1.59 +  Array<AnnotationArray*>*     _methods_parameter_annotations;
    1.60 +  // Annotation objects (byte arrays) for methods' default values, or null if no
    1.61 +  // such annotations.
    1.62 +  // Index is the idnum, which is initially the same as the methods array index.
    1.63 +  Array<AnnotationArray*>*     _methods_default_annotations;
    1.64 +
    1.65 +  // Constructor where some some values are known to not be null
    1.66 +  Annotations(Array<AnnotationArray*>* fa, Array<AnnotationArray*>* ma,
    1.67 +              Array<AnnotationArray*>* mpa, Array<AnnotationArray*>* mda) :
    1.68 +                 _class_annotations(NULL),
    1.69 +                 _fields_annotations(fa),
    1.70 +                 _methods_annotations(ma),
    1.71 +                 _methods_parameter_annotations(mpa),
    1.72 +                 _methods_default_annotations(mda) {}
    1.73 +
    1.74 + public:
    1.75 +  // Allocate instance of this class
    1.76 +  static Annotations* allocate(ClassLoaderData* loader_data, TRAPS);
    1.77 +  static Annotations* allocate(ClassLoaderData* loader_data,
    1.78 +                               Array<AnnotationArray*>* fa,
    1.79 +                               Array<AnnotationArray*>* ma,
    1.80 +                               Array<AnnotationArray*>* mpa,
    1.81 +                               Array<AnnotationArray*>* mda, TRAPS);
    1.82 +  void deallocate_contents(ClassLoaderData* loader_data);
    1.83 +  DEBUG_ONLY(bool on_stack() { return false; })  // for template
    1.84 +  static int size()    { return sizeof(Annotations) / wordSize; }
    1.85 +
    1.86 +  // Constructor to initialize to null
    1.87 +  Annotations() : _class_annotations(NULL), _fields_annotations(NULL),
    1.88 +                  _methods_annotations(NULL),
    1.89 +                  _methods_parameter_annotations(NULL),
    1.90 +                  _methods_default_annotations(NULL) {}
    1.91 +
    1.92 +  AnnotationArray* class_annotations() const                       { return _class_annotations; }
    1.93 +  Array<AnnotationArray*>* fields_annotations() const              { return _fields_annotations; }
    1.94 +  Array<AnnotationArray*>* methods_annotations() const             { return _methods_annotations; }
    1.95 +  Array<AnnotationArray*>* methods_parameter_annotations() const   { return _methods_parameter_annotations; }
    1.96 +  Array<AnnotationArray*>* methods_default_annotations() const     { return _methods_default_annotations; }
    1.97 +
    1.98 +  void set_class_annotations(AnnotationArray* md)                     { _class_annotations = md; }
    1.99 +  void set_fields_annotations(Array<AnnotationArray*>* md)            { _fields_annotations = md; }
   1.100 +  void set_methods_annotations(Array<AnnotationArray*>* md)           { _methods_annotations = md; }
   1.101 +  void set_methods_parameter_annotations(Array<AnnotationArray*>* md) { _methods_parameter_annotations = md; }
   1.102 +  void set_methods_default_annotations(Array<AnnotationArray*>* md)   { _methods_default_annotations = md; }
   1.103 +
   1.104 +  // Redefine classes support
   1.105 +  AnnotationArray* get_method_annotations_of(int idnum)
   1.106 +                                                { return get_method_annotations_from(idnum, _methods_annotations); }
   1.107 +
   1.108 +  AnnotationArray* get_method_parameter_annotations_of(int idnum)
   1.109 +                                                { return get_method_annotations_from(idnum, _methods_parameter_annotations); }
   1.110 +  AnnotationArray* get_method_default_annotations_of(int idnum)
   1.111 +                                                { return get_method_annotations_from(idnum, _methods_default_annotations); }
   1.112 +
   1.113 +
   1.114 +  void set_method_annotations_of(instanceKlassHandle ik,
   1.115 +                                 int idnum, AnnotationArray* anno, TRAPS) {
   1.116 +    set_methods_annotations_of(ik, idnum, anno, &_methods_annotations, THREAD);
   1.117 +  }
   1.118 +
   1.119 +  void set_method_parameter_annotations_of(instanceKlassHandle ik,
   1.120 +                                 int idnum, AnnotationArray* anno, TRAPS) {
   1.121 +    set_methods_annotations_of(ik, idnum, anno, &_methods_parameter_annotations, THREAD);
   1.122 +  }
   1.123 +
   1.124 +  void set_method_default_annotations_of(instanceKlassHandle ik,
   1.125 +                                 int idnum, AnnotationArray* anno, TRAPS) {
   1.126 +    set_methods_annotations_of(ik, idnum, anno, &_methods_default_annotations, THREAD);
   1.127 +  }
   1.128 +
   1.129 +  // Turn metadata annotations into a Java heap object (oop)
   1.130 +  static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS);
   1.131 +
   1.132 +  inline AnnotationArray* get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos);
   1.133 +  void set_annotations(Array<AnnotationArray*>* md, Array<AnnotationArray*>** md_p)  { *md_p = md; }
   1.134 +
   1.135 + private:
   1.136 +  void set_methods_annotations_of(instanceKlassHandle ik,
   1.137 +                                  int idnum, AnnotationArray* anno,
   1.138 +                                  Array<AnnotationArray*>** md_p, TRAPS);
   1.139 +
   1.140 + public:
   1.141 +  const char* internal_name() const { return "{constant pool}"; }
   1.142 +#ifndef PRODUCT
   1.143 +  void print_on(outputStream* st) const;
   1.144 +#endif
   1.145 +  void print_value_on(outputStream* st) const;
   1.146 +};
   1.147 +
   1.148 +
   1.149 +// For method with idnum get the method's Annotations
   1.150 +inline AnnotationArray* Annotations::get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos) {
   1.151 +  if (annos == NULL || annos->length() <= idnum) {
   1.152 +    return NULL;
   1.153 +  }
   1.154 +  return annos->at(idnum);
   1.155 +}
   1.156 +#endif // SHARE_VM_OOPS_ANNOTATIONS_HPP

mercurial