src/share/vm/oops/annotations.hpp

Thu, 11 Oct 2012 12:25:42 -0400

author
kamg
date
Thu, 11 Oct 2012 12:25:42 -0400
changeset 4245
4735d2c84362
parent 4037
da91efe96a93
child 4393
35431a769282
permissions
-rw-r--r--

7200776: Implement default methods in interfaces
Summary: Add generic type analysis and default method selection algorithms
Reviewed-by: coleenp, acorn

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_OOPS_ANNOTATIONS_HPP
    26 #define SHARE_VM_OOPS_ANNOTATIONS_HPP
    28 #include "oops/metadata.hpp"
    29 #include "runtime/handles.hpp"
    30 #include "utilities/array.hpp"
    31 #include "utilities/exceptions.hpp"
    32 #include "utilities/globalDefinitions.hpp"
    35 class ClassLoaderData;
    36 class outputStream;
    38 typedef Array<u1> AnnotationArray;
    40 // Class to hold the various types of annotations. The only metadata that points
    41 // to this is InstanceKlass.
    43 class Annotations: public MetaspaceObj {
    45   // Annotations for this class, or null if none.
    46   AnnotationArray*             _class_annotations;
    47   // Annotation objects (byte arrays) for fields, or null if no annotations.
    48   // Indices correspond to entries (not indices) in fields array.
    49   Array<AnnotationArray*>*     _fields_annotations;
    50   // Annotation objects (byte arrays) for methods, or null if no annotations.
    51   // Index is the idnum, which is initially the same as the methods array index.
    52   Array<AnnotationArray*>*     _methods_annotations;
    53   // Annotation objects (byte arrays) for methods' parameters, or null if no
    54   // such annotations.
    55   // Index is the idnum, which is initially the same as the methods array index.
    56   Array<AnnotationArray*>*     _methods_parameter_annotations;
    57   // Annotation objects (byte arrays) for methods' default values, or null if no
    58   // such annotations.
    59   // Index is the idnum, which is initially the same as the methods array index.
    60   Array<AnnotationArray*>*     _methods_default_annotations;
    62   // Constructor where some some values are known to not be null
    63   Annotations(Array<AnnotationArray*>* fa, Array<AnnotationArray*>* ma,
    64               Array<AnnotationArray*>* mpa, Array<AnnotationArray*>* mda) :
    65                  _class_annotations(NULL),
    66                  _fields_annotations(fa),
    67                  _methods_annotations(ma),
    68                  _methods_parameter_annotations(mpa),
    69                  _methods_default_annotations(mda) {}
    71  public:
    72   // Allocate instance of this class
    73   static Annotations* allocate(ClassLoaderData* loader_data, TRAPS);
    74   static Annotations* allocate(ClassLoaderData* loader_data,
    75                                Array<AnnotationArray*>* fa,
    76                                Array<AnnotationArray*>* ma,
    77                                Array<AnnotationArray*>* mpa,
    78                                Array<AnnotationArray*>* mda, TRAPS);
    79   void deallocate_contents(ClassLoaderData* loader_data);
    80   DEBUG_ONLY(bool on_stack() { return false; })  // for template
    81   static int size()    { return sizeof(Annotations) / wordSize; }
    83   // Constructor to initialize to null
    84   Annotations() : _class_annotations(NULL), _fields_annotations(NULL),
    85                   _methods_annotations(NULL),
    86                   _methods_parameter_annotations(NULL),
    87                   _methods_default_annotations(NULL) {}
    89   AnnotationArray* class_annotations() const                       { return _class_annotations; }
    90   Array<AnnotationArray*>* fields_annotations() const              { return _fields_annotations; }
    91   Array<AnnotationArray*>* methods_annotations() const             { return _methods_annotations; }
    92   Array<AnnotationArray*>* methods_parameter_annotations() const   { return _methods_parameter_annotations; }
    93   Array<AnnotationArray*>* methods_default_annotations() const     { return _methods_default_annotations; }
    95   void set_class_annotations(AnnotationArray* md)                     { _class_annotations = md; }
    96   void set_fields_annotations(Array<AnnotationArray*>* md)            { _fields_annotations = md; }
    97   void set_methods_annotations(Array<AnnotationArray*>* md)           { _methods_annotations = md; }
    98   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; }
   101   // Redefine classes support
   102   AnnotationArray* get_method_annotations_of(int idnum)
   103                                                 { return get_method_annotations_from(idnum, _methods_annotations); }
   105   AnnotationArray* get_method_parameter_annotations_of(int idnum)
   106                                                 { return get_method_annotations_from(idnum, _methods_parameter_annotations); }
   107   AnnotationArray* get_method_default_annotations_of(int idnum)
   108                                                 { return get_method_annotations_from(idnum, _methods_default_annotations); }
   111   void set_method_annotations_of(instanceKlassHandle ik,
   112                                  int idnum, AnnotationArray* anno, TRAPS) {
   113     set_methods_annotations_of(ik, idnum, anno, &_methods_annotations, THREAD);
   114   }
   116   void set_method_parameter_annotations_of(instanceKlassHandle ik,
   117                                  int idnum, AnnotationArray* anno, TRAPS) {
   118     set_methods_annotations_of(ik, idnum, anno, &_methods_parameter_annotations, THREAD);
   119   }
   121   void set_method_default_annotations_of(instanceKlassHandle ik,
   122                                  int idnum, AnnotationArray* anno, TRAPS) {
   123     set_methods_annotations_of(ik, idnum, anno, &_methods_default_annotations, THREAD);
   124   }
   126   // Turn metadata annotations into a Java heap object (oop)
   127   static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS);
   129   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; }
   132  private:
   133   void set_methods_annotations_of(instanceKlassHandle ik,
   134                                   int idnum, AnnotationArray* anno,
   135                                   Array<AnnotationArray*>** md_p, TRAPS);
   137  public:
   138   const char* internal_name() const { return "{constant pool}"; }
   139 #ifndef PRODUCT
   140   void print_on(outputStream* st) const;
   141 #endif
   142   void print_value_on(outputStream* st) const;
   143 };
   146 // For method with idnum get the method's Annotations
   147 inline AnnotationArray* Annotations::get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos) {
   148   if (annos == NULL || annos->length() <= idnum) {
   149     return NULL;
   150   }
   151   return annos->at(idnum);
   152 }
   153 #endif // SHARE_VM_OOPS_ANNOTATIONS_HPP

mercurial