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