comparison src/share/vm/oops/annotations.cpp @ 8031:927a311d00f9

8007320: NPG: move method annotations Summary: allocate method annotations and attach to ConstMethod if present Reviewed-by: dcubed, jiangli, sspitsyn, iklam
author coleenp
date Mon, 11 Feb 2013 14:06:22 -0500
parents 16fb9f942703
children a1ebd310d5c1
comparison
equal deleted inserted replaced
8030:f989aff6946f 8031:927a311d00f9
34 // Allocate annotations in metadata area 34 // Allocate annotations in metadata area
35 Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) { 35 Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
36 return new (loader_data, size(), true, THREAD) Annotations(); 36 return new (loader_data, size(), true, THREAD) Annotations();
37 } 37 }
38 38
39 Annotations* Annotations::allocate(ClassLoaderData* loader_data,
40 Array<AnnotationArray*>* fa,
41 Array<AnnotationArray*>* ma,
42 Array<AnnotationArray*>* mpa,
43 Array<AnnotationArray*>* mda, TRAPS) {
44 return new (loader_data, size(), true, THREAD) Annotations(fa, ma, mpa, mda);
45 }
46
47 // helper 39 // helper
48 static void free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) { 40 void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {
49 if (p != NULL) { 41 if (p != NULL) {
50 for (int i = 0; i < p->length(); i++) { 42 for (int i = 0; i < p->length(); i++) {
51 MetadataFactory::free_array<u1>(loader_data, p->at(i)); 43 MetadataFactory::free_array<u1>(loader_data, p->at(i));
52 } 44 }
53 MetadataFactory::free_array<AnnotationArray*>(loader_data, p); 45 MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
57 void Annotations::deallocate_contents(ClassLoaderData* loader_data) { 49 void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
58 if (class_annotations() != NULL) { 50 if (class_annotations() != NULL) {
59 MetadataFactory::free_array<u1>(loader_data, class_annotations()); 51 MetadataFactory::free_array<u1>(loader_data, class_annotations());
60 } 52 }
61 free_contents(loader_data, fields_annotations()); 53 free_contents(loader_data, fields_annotations());
62 free_contents(loader_data, methods_annotations());
63 free_contents(loader_data, methods_parameter_annotations());
64 free_contents(loader_data, methods_default_annotations());
65 54
66 // Recursively deallocate optional Annotations linked through this one 55 if (class_type_annotations() != NULL) {
67 MetadataFactory::free_metadata(loader_data, type_annotations()); 56 MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
57 }
58 free_contents(loader_data, fields_type_annotations());
68 } 59 }
69 60
70 // Set the annotation at 'idnum' to 'anno'.
71 // We don't want to create or extend the array if 'anno' is NULL, since that is the
72 // default value. However, if the array exists and is long enough, we must set NULL values.
73 void Annotations::set_methods_annotations_of(instanceKlassHandle ik,
74 int idnum, AnnotationArray* anno,
75 Array<AnnotationArray*>** md_p,
76 TRAPS) {
77 Array<AnnotationArray*>* md = *md_p;
78 if (md != NULL && md->length() > idnum) {
79 md->at_put(idnum, anno);
80 } else if (anno != NULL) {
81 // create the array
82 int length = MAX2(idnum+1, (int)ik->idnum_allocated_count());
83 md = MetadataFactory::new_array<AnnotationArray*>(ik->class_loader_data(), length, CHECK);
84 if (*md_p != NULL) {
85 // copy the existing entries
86 for (int index = 0; index < (*md_p)->length(); index++) {
87 md->at_put(index, (*md_p)->at(index));
88 }
89 }
90 set_annotations(md, md_p);
91 md->at_put(idnum, anno);
92 } // if no array and idnum isn't included there is nothing to do
93 }
94
95 // Keep created annotations in a global growable array (should be hashtable)
96 // need to add, search, delete when class is unloaded.
97 // Does it need a lock? yes. This sucks.
98
99 // Copy annotations to JVM call or reflection to the java heap. 61 // Copy annotations to JVM call or reflection to the java heap.
62 // The alternative to creating this array and adding to Java heap pressure
63 // is to have a hashtable of the already created typeArrayOops
100 typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) { 64 typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {
101 if (annotations != NULL) { 65 if (annotations != NULL) {
102 int length = annotations->length(); 66 int length = annotations->length();
103 typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL); 67 typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);
104 for (int i = 0; i< length; i++) { 68 for (int i = 0; i< length; i++) {
130 } 94 }
131 95
132 void Annotations::collect_statistics(KlassSizeStats *sz) const { 96 void Annotations::collect_statistics(KlassSizeStats *sz) const {
133 sz->_annotations_bytes = sz->count(this); 97 sz->_annotations_bytes = sz->count(this);
134 sz->_class_annotations_bytes = sz->count(class_annotations()); 98 sz->_class_annotations_bytes = sz->count(class_annotations());
99 sz->_class_type_annotations_bytes = sz->count(class_type_annotations());
135 sz->_fields_annotations_bytes = count_bytes(fields_annotations()); 100 sz->_fields_annotations_bytes = count_bytes(fields_annotations());
136 sz->_methods_annotations_bytes = count_bytes(methods_annotations()); 101 sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());
137 sz->_methods_parameter_annotations_bytes =
138 count_bytes(methods_parameter_annotations());
139 sz->_methods_default_annotations_bytes =
140 count_bytes(methods_default_annotations());
141
142 const Annotations* type_anno = type_annotations();
143 if (type_anno != NULL) {
144 sz->_type_annotations_bytes = sz->count(type_anno);
145 sz->_type_annotations_bytes += sz->count(type_anno->class_annotations());
146 sz->_type_annotations_bytes += count_bytes(type_anno->fields_annotations());
147 sz->_type_annotations_bytes += count_bytes(type_anno->methods_annotations());
148 }
149 102
150 sz->_annotations_bytes += 103 sz->_annotations_bytes +=
151 sz->_class_annotations_bytes + 104 sz->_class_annotations_bytes +
105 sz->_class_type_annotations_bytes +
152 sz->_fields_annotations_bytes + 106 sz->_fields_annotations_bytes +
153 sz->_methods_annotations_bytes + 107 sz->_fields_type_annotations_bytes;
154 sz->_methods_parameter_annotations_bytes +
155 sz->_methods_default_annotations_bytes +
156 sz->_type_annotations_bytes;
157 108
158 sz->_ro_bytes += sz->_annotations_bytes; 109 sz->_ro_bytes += sz->_annotations_bytes;
159 } 110 }
160 #endif // INCLUDE_SERVICES 111 #endif // INCLUDE_SERVICES
161 112
163 114
164 #ifndef PRODUCT 115 #ifndef PRODUCT
165 void Annotations::print_on(outputStream* st) const { 116 void Annotations::print_on(outputStream* st) const {
166 st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st); 117 st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st);
167 st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st); 118 st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st);
168 st->print(BULLET"methods_annotations "); methods_annotations()->print_value_on(st); 119 st->print(BULLET"class_type_annotations "); class_type_annotations()->print_value_on(st);
169 st->print(BULLET"methods_parameter_annotations"); methods_parameter_annotations()->print_value_on(st); 120 st->print(BULLET"fields_type_annotations "); fields_type_annotations()->print_value_on(st);
170 st->print(BULLET"methods_default_annotations "); methods_default_annotations()->print_value_on(st);
171 } 121 }
172 #endif // PRODUCT 122 #endif // PRODUCT