Thu, 07 Feb 2013 16:05:48 -0500
Merge
1 /*
2 * Copyright (c) 2012, 2013, 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;
37 class KlassSizeStats;
39 typedef Array<u1> AnnotationArray;
41 // Class to hold the various types of annotations. The only metadata that points
42 // to this is InstanceKlass, or another Annotations instance if this is a
43 // a type_annotation instance.
45 class Annotations: public MetaspaceObj {
47 // Annotations for this class, or null if none.
48 AnnotationArray* _class_annotations;
49 // Annotation objects (byte arrays) for fields, or null if no annotations.
50 // Indices correspond to entries (not indices) in fields array.
51 Array<AnnotationArray*>* _fields_annotations;
52 // Annotation objects (byte arrays) for methods, or null if no annotations.
53 // Index is the idnum, which is initially the same as the methods array index.
54 Array<AnnotationArray*>* _methods_annotations;
55 // Annotation objects (byte arrays) for methods' parameters, or null if no
56 // such annotations.
57 // Index is the idnum, which is initially the same as the methods array index.
58 Array<AnnotationArray*>* _methods_parameter_annotations;
59 // Annotation objects (byte arrays) for methods' default values, or null if no
60 // such annotations.
61 // Index is the idnum, which is initially the same as the methods array index.
62 Array<AnnotationArray*>* _methods_default_annotations;
63 // Type annotations for this class, or null if none.
64 Annotations* _type_annotations;
66 // Constructor where some some values are known to not be null
67 Annotations(Array<AnnotationArray*>* fa, Array<AnnotationArray*>* ma,
68 Array<AnnotationArray*>* mpa, Array<AnnotationArray*>* mda) :
69 _class_annotations(NULL),
70 _fields_annotations(fa),
71 _methods_annotations(ma),
72 _methods_parameter_annotations(mpa),
73 _methods_default_annotations(mda),
74 _type_annotations(NULL) {}
76 public:
77 // Allocate instance of this class
78 static Annotations* allocate(ClassLoaderData* loader_data, TRAPS);
79 static Annotations* allocate(ClassLoaderData* loader_data,
80 Array<AnnotationArray*>* fa,
81 Array<AnnotationArray*>* ma,
82 Array<AnnotationArray*>* mpa,
83 Array<AnnotationArray*>* mda, TRAPS);
84 void deallocate_contents(ClassLoaderData* loader_data);
85 DEBUG_ONLY(bool on_stack() { return false; }) // for template
87 // Sizing (in words)
88 static int size() { return sizeof(Annotations) / wordSize; }
89 #if INCLUDE_SERVICES
90 void collect_statistics(KlassSizeStats *sz) const;
91 #endif
93 // Constructor to initialize to null
94 Annotations() : _class_annotations(NULL),
95 _fields_annotations(NULL),
96 _methods_annotations(NULL),
97 _methods_parameter_annotations(NULL),
98 _methods_default_annotations(NULL),
99 _type_annotations(NULL) {}
101 AnnotationArray* class_annotations() const { return _class_annotations; }
102 Array<AnnotationArray*>* fields_annotations() const { return _fields_annotations; }
103 Array<AnnotationArray*>* methods_annotations() const { return _methods_annotations; }
104 Array<AnnotationArray*>* methods_parameter_annotations() const { return _methods_parameter_annotations; }
105 Array<AnnotationArray*>* methods_default_annotations() const { return _methods_default_annotations; }
106 Annotations* type_annotations() const { return _type_annotations; }
108 void set_class_annotations(AnnotationArray* md) { _class_annotations = md; }
109 void set_fields_annotations(Array<AnnotationArray*>* md) { _fields_annotations = md; }
110 void set_methods_annotations(Array<AnnotationArray*>* md) { _methods_annotations = md; }
111 void set_methods_parameter_annotations(Array<AnnotationArray*>* md) { _methods_parameter_annotations = md; }
112 void set_methods_default_annotations(Array<AnnotationArray*>* md) { _methods_default_annotations = md; }
113 void set_type_annotations(Annotations* annos) { _type_annotations = annos; }
115 // Redefine classes support
116 AnnotationArray* get_method_annotations_of(int idnum)
117 { return get_method_annotations_from(idnum, _methods_annotations); }
119 AnnotationArray* get_method_parameter_annotations_of(int idnum)
120 { return get_method_annotations_from(idnum, _methods_parameter_annotations); }
121 AnnotationArray* get_method_default_annotations_of(int idnum)
122 { return get_method_annotations_from(idnum, _methods_default_annotations); }
125 void set_method_annotations_of(instanceKlassHandle ik,
126 int idnum, AnnotationArray* anno, TRAPS) {
127 set_methods_annotations_of(ik, idnum, anno, &_methods_annotations, THREAD);
128 }
130 void set_method_parameter_annotations_of(instanceKlassHandle ik,
131 int idnum, AnnotationArray* anno, TRAPS) {
132 set_methods_annotations_of(ik, idnum, anno, &_methods_parameter_annotations, THREAD);
133 }
135 void set_method_default_annotations_of(instanceKlassHandle ik,
136 int idnum, AnnotationArray* anno, TRAPS) {
137 set_methods_annotations_of(ik, idnum, anno, &_methods_default_annotations, THREAD);
138 }
140 // Turn metadata annotations into a Java heap object (oop)
141 static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS);
143 inline AnnotationArray* get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos);
144 void set_annotations(Array<AnnotationArray*>* md, Array<AnnotationArray*>** md_p) { *md_p = md; }
146 bool is_klass() const { return false; }
147 private:
148 void set_methods_annotations_of(instanceKlassHandle ik,
149 int idnum, AnnotationArray* anno,
150 Array<AnnotationArray*>** md_p, TRAPS);
151 static julong count_bytes(Array<AnnotationArray*>* p);
152 public:
153 const char* internal_name() const { return "{constant pool}"; }
154 #ifndef PRODUCT
155 void print_on(outputStream* st) const;
156 #endif
157 void print_value_on(outputStream* st) const;
158 };
161 // For method with idnum get the method's Annotations
162 inline AnnotationArray* Annotations::get_method_annotations_from(int idnum, Array<AnnotationArray*>* annos) {
163 if (annos == NULL || annos->length() <= idnum) {
164 return NULL;
165 }
166 return annos->at(idnum);
167 }
168 #endif // SHARE_VM_OOPS_ANNOTATIONS_HPP