coleenp@4037: /* acorn@4497: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. coleenp@4037: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. coleenp@4037: * coleenp@4037: * This code is free software; you can redistribute it and/or modify it coleenp@4037: * under the terms of the GNU General Public License version 2 only, as coleenp@4037: * published by the Free Software Foundation. coleenp@4037: * coleenp@4037: * This code is distributed in the hope that it will be useful, but WITHOUT coleenp@4037: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or coleenp@4037: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License coleenp@4037: * version 2 for more details (a copy is included in the LICENSE file that coleenp@4037: * accompanied this code). coleenp@4037: * coleenp@4037: * You should have received a copy of the GNU General Public License version coleenp@4037: * 2 along with this work; if not, write to the Free Software Foundation, coleenp@4037: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. coleenp@4037: * coleenp@4037: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA coleenp@4037: * or visit www.oracle.com if you need additional information or have any coleenp@4037: * questions. coleenp@4037: * coleenp@4037: */ coleenp@4037: coleenp@4037: #include "precompiled.hpp" coleenp@4037: #include "classfile/classLoaderData.hpp" acorn@4497: #include "memory/heapInspection.hpp" coleenp@4037: #include "memory/metadataFactory.hpp" coleenp@4037: #include "memory/oopFactory.hpp" coleenp@4037: #include "oops/annotations.hpp" coleenp@4037: #include "oops/instanceKlass.hpp" coleenp@4037: #include "utilities/ostream.hpp" coleenp@4037: coleenp@4037: // Allocate annotations in metadata area coleenp@4037: Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) { iklam@5208: return new (loader_data, size(), true, MetaspaceObj::AnnotationType, THREAD) Annotations(); coleenp@4037: } coleenp@4037: coleenp@4037: // helper coleenp@4572: void Annotations::free_contents(ClassLoaderData* loader_data, Array* p) { coleenp@4037: if (p != NULL) { coleenp@4037: for (int i = 0; i < p->length(); i++) { coleenp@4037: MetadataFactory::free_array(loader_data, p->at(i)); coleenp@4037: } coleenp@4037: MetadataFactory::free_array(loader_data, p); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void Annotations::deallocate_contents(ClassLoaderData* loader_data) { coleenp@4037: if (class_annotations() != NULL) { coleenp@4037: MetadataFactory::free_array(loader_data, class_annotations()); coleenp@4037: } coleenp@4037: free_contents(loader_data, fields_annotations()); stefank@4393: coleenp@4572: if (class_type_annotations() != NULL) { coleenp@4572: MetadataFactory::free_array(loader_data, class_type_annotations()); coleenp@4572: } coleenp@4572: free_contents(loader_data, fields_type_annotations()); coleenp@4037: } coleenp@4037: coleenp@4037: // Copy annotations to JVM call or reflection to the java heap. coleenp@4572: // The alternative to creating this array and adding to Java heap pressure coleenp@4572: // is to have a hashtable of the already created typeArrayOops coleenp@4037: typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) { coleenp@4037: if (annotations != NULL) { coleenp@4037: int length = annotations->length(); coleenp@4037: typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL); coleenp@4037: for (int i = 0; i< length; i++) { coleenp@4037: copy->byte_at_put(i, annotations->at(i)); coleenp@4037: } coleenp@4037: return copy; coleenp@4037: } else { coleenp@4037: return NULL; coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: coleenp@4037: void Annotations::print_value_on(outputStream* st) const { coleenp@4037: st->print("Anotations(" INTPTR_FORMAT ")", this); coleenp@4037: } coleenp@4037: acorn@4497: #if INCLUDE_SERVICES acorn@4497: // Size Statistics acorn@4497: acorn@4497: julong Annotations::count_bytes(Array* p) { acorn@4497: julong bytes = 0; acorn@4497: if (p != NULL) { acorn@4497: for (int i = 0; i < p->length(); i++) { acorn@4497: bytes += KlassSizeStats::count_array(p->at(i)); acorn@4497: } acorn@4497: bytes += KlassSizeStats::count_array(p); acorn@4497: } acorn@4497: return bytes; acorn@4497: } acorn@4497: acorn@4497: void Annotations::collect_statistics(KlassSizeStats *sz) const { acorn@4497: sz->_annotations_bytes = sz->count(this); acorn@4497: sz->_class_annotations_bytes = sz->count(class_annotations()); coleenp@4572: sz->_class_type_annotations_bytes = sz->count(class_type_annotations()); acorn@4497: sz->_fields_annotations_bytes = count_bytes(fields_annotations()); coleenp@4572: sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations()); acorn@4497: acorn@4497: sz->_annotations_bytes += acorn@4497: sz->_class_annotations_bytes + coleenp@4572: sz->_class_type_annotations_bytes + acorn@4497: sz->_fields_annotations_bytes + coleenp@4572: sz->_fields_type_annotations_bytes; acorn@4497: acorn@4497: sz->_ro_bytes += sz->_annotations_bytes; acorn@4497: } acorn@4497: #endif // INCLUDE_SERVICES acorn@4497: coleenp@4037: #define BULLET " - " coleenp@4037: coleenp@4037: #ifndef PRODUCT coleenp@4037: void Annotations::print_on(outputStream* st) const { coleenp@4037: st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st); coleenp@4037: st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st); coleenp@4572: st->print(BULLET"class_type_annotations "); class_type_annotations()->print_value_on(st); coleenp@4572: st->print(BULLET"fields_type_annotations "); fields_type_annotations()->print_value_on(st); coleenp@4037: } coleenp@4037: #endif // PRODUCT