src/share/vm/oops/annotations.cpp

Thu, 07 Feb 2013 16:05:48 -0500

author
bpittore
date
Thu, 07 Feb 2013 16:05:48 -0500
changeset 4544
3c9bc17b9403
parent 4497
16fb9f942703
child 4572
927a311d00f9
permissions
-rw-r--r--

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 #include "precompiled.hpp"
coleenp@4037 26 #include "classfile/classLoaderData.hpp"
acorn@4497 27 #include "memory/heapInspection.hpp"
coleenp@4037 28 #include "memory/metadataFactory.hpp"
coleenp@4037 29 #include "memory/oopFactory.hpp"
coleenp@4037 30 #include "oops/annotations.hpp"
coleenp@4037 31 #include "oops/instanceKlass.hpp"
coleenp@4037 32 #include "utilities/ostream.hpp"
coleenp@4037 33
coleenp@4037 34 // Allocate annotations in metadata area
coleenp@4037 35 Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
coleenp@4037 36 return new (loader_data, size(), true, THREAD) Annotations();
coleenp@4037 37 }
coleenp@4037 38
coleenp@4037 39 Annotations* Annotations::allocate(ClassLoaderData* loader_data,
coleenp@4037 40 Array<AnnotationArray*>* fa,
coleenp@4037 41 Array<AnnotationArray*>* ma,
coleenp@4037 42 Array<AnnotationArray*>* mpa,
coleenp@4037 43 Array<AnnotationArray*>* mda, TRAPS) {
coleenp@4037 44 return new (loader_data, size(), true, THREAD) Annotations(fa, ma, mpa, mda);
coleenp@4037 45 }
coleenp@4037 46
coleenp@4037 47 // helper
coleenp@4037 48 static void free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {
coleenp@4037 49 if (p != NULL) {
coleenp@4037 50 for (int i = 0; i < p->length(); i++) {
coleenp@4037 51 MetadataFactory::free_array<u1>(loader_data, p->at(i));
coleenp@4037 52 }
coleenp@4037 53 MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
coleenp@4037 54 }
coleenp@4037 55 }
coleenp@4037 56
coleenp@4037 57 void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
coleenp@4037 58 if (class_annotations() != NULL) {
coleenp@4037 59 MetadataFactory::free_array<u1>(loader_data, class_annotations());
coleenp@4037 60 }
coleenp@4037 61 free_contents(loader_data, fields_annotations());
coleenp@4037 62 free_contents(loader_data, methods_annotations());
coleenp@4037 63 free_contents(loader_data, methods_parameter_annotations());
coleenp@4037 64 free_contents(loader_data, methods_default_annotations());
stefank@4393 65
stefank@4393 66 // Recursively deallocate optional Annotations linked through this one
stefank@4393 67 MetadataFactory::free_metadata(loader_data, type_annotations());
coleenp@4037 68 }
coleenp@4037 69
coleenp@4037 70 // Set the annotation at 'idnum' to 'anno'.
coleenp@4037 71 // We don't want to create or extend the array if 'anno' is NULL, since that is the
coleenp@4037 72 // default value. However, if the array exists and is long enough, we must set NULL values.
coleenp@4037 73 void Annotations::set_methods_annotations_of(instanceKlassHandle ik,
coleenp@4037 74 int idnum, AnnotationArray* anno,
coleenp@4037 75 Array<AnnotationArray*>** md_p,
coleenp@4037 76 TRAPS) {
coleenp@4037 77 Array<AnnotationArray*>* md = *md_p;
coleenp@4037 78 if (md != NULL && md->length() > idnum) {
coleenp@4037 79 md->at_put(idnum, anno);
coleenp@4037 80 } else if (anno != NULL) {
coleenp@4037 81 // create the array
coleenp@4037 82 int length = MAX2(idnum+1, (int)ik->idnum_allocated_count());
coleenp@4037 83 md = MetadataFactory::new_array<AnnotationArray*>(ik->class_loader_data(), length, CHECK);
coleenp@4037 84 if (*md_p != NULL) {
coleenp@4037 85 // copy the existing entries
coleenp@4037 86 for (int index = 0; index < (*md_p)->length(); index++) {
coleenp@4037 87 md->at_put(index, (*md_p)->at(index));
coleenp@4037 88 }
coleenp@4037 89 }
coleenp@4037 90 set_annotations(md, md_p);
coleenp@4037 91 md->at_put(idnum, anno);
coleenp@4037 92 } // if no array and idnum isn't included there is nothing to do
coleenp@4037 93 }
coleenp@4037 94
coleenp@4037 95 // Keep created annotations in a global growable array (should be hashtable)
coleenp@4037 96 // need to add, search, delete when class is unloaded.
coleenp@4037 97 // Does it need a lock? yes. This sucks.
coleenp@4037 98
coleenp@4037 99 // Copy annotations to JVM call or reflection to the java heap.
coleenp@4037 100 typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {
coleenp@4037 101 if (annotations != NULL) {
coleenp@4037 102 int length = annotations->length();
coleenp@4037 103 typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);
coleenp@4037 104 for (int i = 0; i< length; i++) {
coleenp@4037 105 copy->byte_at_put(i, annotations->at(i));
coleenp@4037 106 }
coleenp@4037 107 return copy;
coleenp@4037 108 } else {
coleenp@4037 109 return NULL;
coleenp@4037 110 }
coleenp@4037 111 }
coleenp@4037 112
coleenp@4037 113
coleenp@4037 114 void Annotations::print_value_on(outputStream* st) const {
coleenp@4037 115 st->print("Anotations(" INTPTR_FORMAT ")", this);
coleenp@4037 116 }
coleenp@4037 117
acorn@4497 118 #if INCLUDE_SERVICES
acorn@4497 119 // Size Statistics
acorn@4497 120
acorn@4497 121 julong Annotations::count_bytes(Array<AnnotationArray*>* p) {
acorn@4497 122 julong bytes = 0;
acorn@4497 123 if (p != NULL) {
acorn@4497 124 for (int i = 0; i < p->length(); i++) {
acorn@4497 125 bytes += KlassSizeStats::count_array(p->at(i));
acorn@4497 126 }
acorn@4497 127 bytes += KlassSizeStats::count_array(p);
acorn@4497 128 }
acorn@4497 129 return bytes;
acorn@4497 130 }
acorn@4497 131
acorn@4497 132 void Annotations::collect_statistics(KlassSizeStats *sz) const {
acorn@4497 133 sz->_annotations_bytes = sz->count(this);
acorn@4497 134 sz->_class_annotations_bytes = sz->count(class_annotations());
acorn@4497 135 sz->_fields_annotations_bytes = count_bytes(fields_annotations());
acorn@4497 136 sz->_methods_annotations_bytes = count_bytes(methods_annotations());
acorn@4497 137 sz->_methods_parameter_annotations_bytes =
acorn@4497 138 count_bytes(methods_parameter_annotations());
acorn@4497 139 sz->_methods_default_annotations_bytes =
acorn@4497 140 count_bytes(methods_default_annotations());
acorn@4497 141
acorn@4497 142 const Annotations* type_anno = type_annotations();
acorn@4497 143 if (type_anno != NULL) {
acorn@4497 144 sz->_type_annotations_bytes = sz->count(type_anno);
acorn@4497 145 sz->_type_annotations_bytes += sz->count(type_anno->class_annotations());
acorn@4497 146 sz->_type_annotations_bytes += count_bytes(type_anno->fields_annotations());
acorn@4497 147 sz->_type_annotations_bytes += count_bytes(type_anno->methods_annotations());
acorn@4497 148 }
acorn@4497 149
acorn@4497 150 sz->_annotations_bytes +=
acorn@4497 151 sz->_class_annotations_bytes +
acorn@4497 152 sz->_fields_annotations_bytes +
acorn@4497 153 sz->_methods_annotations_bytes +
acorn@4497 154 sz->_methods_parameter_annotations_bytes +
acorn@4497 155 sz->_methods_default_annotations_bytes +
acorn@4497 156 sz->_type_annotations_bytes;
acorn@4497 157
acorn@4497 158 sz->_ro_bytes += sz->_annotations_bytes;
acorn@4497 159 }
acorn@4497 160 #endif // INCLUDE_SERVICES
acorn@4497 161
coleenp@4037 162 #define BULLET " - "
coleenp@4037 163
coleenp@4037 164 #ifndef PRODUCT
coleenp@4037 165 void Annotations::print_on(outputStream* st) const {
coleenp@4037 166 st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st);
coleenp@4037 167 st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st);
coleenp@4037 168 st->print(BULLET"methods_annotations "); methods_annotations()->print_value_on(st);
coleenp@4037 169 st->print(BULLET"methods_parameter_annotations"); methods_parameter_annotations()->print_value_on(st);
coleenp@4037 170 st->print(BULLET"methods_default_annotations "); methods_default_annotations()->print_value_on(st);
coleenp@4037 171 }
coleenp@4037 172 #endif // PRODUCT

mercurial