annotate src/share/vm/oops/annotations.cpp @ 13584:2dfe246179c0

Merge
author dholmes
date Wed, 20 Sep 2017 23:55:35 -0400
parents 53a41e7cbe05
children
rev   line source
coleenp@3602 1 /*
iklam@13442 2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
coleenp@3602 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@3602 4 *
coleenp@3602 5 * This code is free software; you can redistribute it and/or modify it
coleenp@3602 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@3602 7 * published by the Free Software Foundation.
coleenp@3602 8 *
coleenp@3602 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@3602 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@3602 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@3602 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@3602 13 * accompanied this code).
coleenp@3602 14 *
coleenp@3602 15 * You should have received a copy of the GNU General Public License version
coleenp@3602 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@3602 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@3602 18 *
coleenp@3602 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@3602 20 * or visit www.oracle.com if you need additional information or have any
coleenp@3602 21 * questions.
coleenp@3602 22 *
coleenp@3602 23 */
coleenp@3602 24
coleenp@3602 25 #include "precompiled.hpp"
coleenp@3602 26 #include "classfile/classLoaderData.hpp"
iklam@13442 27 #include "logging/log.hpp"
acorn@4062 28 #include "memory/heapInspection.hpp"
coleenp@3602 29 #include "memory/metadataFactory.hpp"
iklam@13442 30 #include "memory/metaspaceClosure.hpp"
coleenp@3602 31 #include "memory/oopFactory.hpp"
coleenp@3602 32 #include "oops/annotations.hpp"
coleenp@3602 33 #include "oops/instanceKlass.hpp"
coleenp@3602 34 #include "utilities/ostream.hpp"
coleenp@3602 35
coleenp@3602 36 // Allocate annotations in metadata area
coleenp@3602 37 Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
iklam@13442 38 return new (loader_data, size(), MetaspaceObj::AnnotationsType, THREAD) Annotations();
coleenp@3602 39 }
coleenp@3602 40
coleenp@3602 41 // helper
coleenp@4137 42 void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {
coleenp@3602 43 if (p != NULL) {
coleenp@3602 44 for (int i = 0; i < p->length(); i++) {
coleenp@3602 45 MetadataFactory::free_array<u1>(loader_data, p->at(i));
coleenp@3602 46 }
coleenp@3602 47 MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
coleenp@3602 48 }
coleenp@3602 49 }
coleenp@3602 50
coleenp@3602 51 void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
coleenp@3602 52 if (class_annotations() != NULL) {
coleenp@3602 53 MetadataFactory::free_array<u1>(loader_data, class_annotations());
coleenp@3602 54 }
coleenp@3602 55 free_contents(loader_data, fields_annotations());
stefank@3958 56
coleenp@4137 57 if (class_type_annotations() != NULL) {
coleenp@4137 58 MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
coleenp@4137 59 }
coleenp@4137 60 free_contents(loader_data, fields_type_annotations());
coleenp@3602 61 }
coleenp@3602 62
coleenp@3602 63 // Copy annotations to JVM call or reflection to the java heap.
coleenp@4137 64 // The alternative to creating this array and adding to Java heap pressure
coleenp@4137 65 // is to have a hashtable of the already created typeArrayOops
coleenp@3602 66 typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {
coleenp@3602 67 if (annotations != NULL) {
coleenp@3602 68 int length = annotations->length();
coleenp@3602 69 typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);
coleenp@3602 70 for (int i = 0; i< length; i++) {
coleenp@3602 71 copy->byte_at_put(i, annotations->at(i));
coleenp@3602 72 }
coleenp@3602 73 return copy;
coleenp@3602 74 } else {
coleenp@3602 75 return NULL;
coleenp@3602 76 }
coleenp@3602 77 }
coleenp@3602 78
iklam@13442 79 void Annotations::metaspace_pointers_do(MetaspaceClosure* it) {
iklam@13442 80 log_trace(cds)("Iter(Annotations): %p", this);
iklam@13442 81 it->push(&_class_annotations);
iklam@13442 82 it->push(&_fields_annotations);
iklam@13442 83 it->push(&_class_type_annotations);
iklam@13442 84 it->push(&_fields_type_annotations); // FIXME: need a test case where _fields_type_annotations != NULL
iklam@13442 85 }
coleenp@3602 86
coleenp@3602 87 void Annotations::print_value_on(outputStream* st) const {
drchase@6412 88 st->print("Anotations(" INTPTR_FORMAT ")", p2i(this));
coleenp@3602 89 }
coleenp@3602 90
acorn@4062 91 #if INCLUDE_SERVICES
acorn@4062 92 // Size Statistics
acorn@4062 93
acorn@4062 94 julong Annotations::count_bytes(Array<AnnotationArray*>* p) {
acorn@4062 95 julong bytes = 0;
acorn@4062 96 if (p != NULL) {
acorn@4062 97 for (int i = 0; i < p->length(); i++) {
acorn@4062 98 bytes += KlassSizeStats::count_array(p->at(i));
acorn@4062 99 }
acorn@4062 100 bytes += KlassSizeStats::count_array(p);
acorn@4062 101 }
acorn@4062 102 return bytes;
acorn@4062 103 }
acorn@4062 104
acorn@4062 105 void Annotations::collect_statistics(KlassSizeStats *sz) const {
acorn@4062 106 sz->_annotations_bytes = sz->count(this);
acorn@4062 107 sz->_class_annotations_bytes = sz->count(class_annotations());
coleenp@4137 108 sz->_class_type_annotations_bytes = sz->count(class_type_annotations());
acorn@4062 109 sz->_fields_annotations_bytes = count_bytes(fields_annotations());
coleenp@4137 110 sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());
acorn@4062 111
acorn@4062 112 sz->_annotations_bytes +=
acorn@4062 113 sz->_class_annotations_bytes +
coleenp@4137 114 sz->_class_type_annotations_bytes +
acorn@4062 115 sz->_fields_annotations_bytes +
coleenp@4137 116 sz->_fields_type_annotations_bytes;
acorn@4062 117
acorn@4062 118 sz->_ro_bytes += sz->_annotations_bytes;
acorn@4062 119 }
acorn@4062 120 #endif // INCLUDE_SERVICES
acorn@4062 121
coleenp@3602 122 #define BULLET " - "
coleenp@3602 123
coleenp@3602 124 #ifndef PRODUCT
coleenp@3602 125 void Annotations::print_on(outputStream* st) const {
coleenp@3602 126 st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st);
coleenp@3602 127 st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st);
coleenp@4137 128 st->print(BULLET"class_type_annotations "); class_type_annotations()->print_value_on(st);
coleenp@4137 129 st->print(BULLET"fields_type_annotations "); fields_type_annotations()->print_value_on(st);
coleenp@3602 130 }
coleenp@3602 131 #endif // PRODUCT