Mercurial > hg > truffle
comparison src/share/vm/oops/annotations.hpp @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | |
children | 35431a769282 |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
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 */ | |
24 | |
25 #ifndef SHARE_VM_OOPS_ANNOTATIONS_HPP | |
26 #define SHARE_VM_OOPS_ANNOTATIONS_HPP | |
27 | |
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" | |
33 | |
34 | |
35 class ClassLoaderData; | |
36 class outputStream; | |
37 | |
38 typedef Array<u1> AnnotationArray; | |
39 | |
40 // Class to hold the various types of annotations. The only metadata that points | |
41 // to this is InstanceKlass. | |
42 | |
43 class Annotations: public MetaspaceObj { | |
44 | |
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; | |
61 | |
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) {} | |
70 | |
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; } | |
82 | |
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) {} | |
88 | |
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; } | |
94 | |
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; } | |
100 | |
101 // Redefine classes support | |
102 AnnotationArray* get_method_annotations_of(int idnum) | |
103 { return get_method_annotations_from(idnum, _methods_annotations); } | |
104 | |
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); } | |
109 | |
110 | |
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 } | |
115 | |
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 } | |
120 | |
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 } | |
125 | |
126 // Turn metadata annotations into a Java heap object (oop) | |
127 static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS); | |
128 | |
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; } | |
131 | |
132 private: | |
133 void set_methods_annotations_of(instanceKlassHandle ik, | |
134 int idnum, AnnotationArray* anno, | |
135 Array<AnnotationArray*>** md_p, TRAPS); | |
136 | |
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 }; | |
144 | |
145 | |
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 |