Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/oops/annotations.cpp
32285 views
/*1* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/classLoaderData.hpp"26#include "memory/heapInspection.hpp"27#include "memory/metadataFactory.hpp"28#include "memory/oopFactory.hpp"29#include "oops/annotations.hpp"30#include "oops/instanceKlass.hpp"31#include "utilities/ostream.hpp"3233// Allocate annotations in metadata area34Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {35return new (loader_data, size(), true, MetaspaceObj::AnnotationType, THREAD) Annotations();36}3738// helper39void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {40if (p != NULL) {41for (int i = 0; i < p->length(); i++) {42MetadataFactory::free_array<u1>(loader_data, p->at(i));43}44MetadataFactory::free_array<AnnotationArray*>(loader_data, p);45}46}4748void Annotations::deallocate_contents(ClassLoaderData* loader_data) {49if (class_annotations() != NULL) {50MetadataFactory::free_array<u1>(loader_data, class_annotations());51}52free_contents(loader_data, fields_annotations());5354if (class_type_annotations() != NULL) {55MetadataFactory::free_array<u1>(loader_data, class_type_annotations());56}57free_contents(loader_data, fields_type_annotations());58}5960// Copy annotations to JVM call or reflection to the java heap.61// The alternative to creating this array and adding to Java heap pressure62// is to have a hashtable of the already created typeArrayOops63typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {64if (annotations != NULL) {65int length = annotations->length();66typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);67for (int i = 0; i< length; i++) {68copy->byte_at_put(i, annotations->at(i));69}70return copy;71} else {72return NULL;73}74}757677void Annotations::print_value_on(outputStream* st) const {78st->print("Anotations(" INTPTR_FORMAT ")", p2i(this));79}8081#if INCLUDE_SERVICES82// Size Statistics8384julong Annotations::count_bytes(Array<AnnotationArray*>* p) {85julong bytes = 0;86if (p != NULL) {87for (int i = 0; i < p->length(); i++) {88bytes += KlassSizeStats::count_array(p->at(i));89}90bytes += KlassSizeStats::count_array(p);91}92return bytes;93}9495void Annotations::collect_statistics(KlassSizeStats *sz) const {96sz->_annotations_bytes = sz->count(this);97sz->_class_annotations_bytes = sz->count(class_annotations());98sz->_class_type_annotations_bytes = sz->count(class_type_annotations());99sz->_fields_annotations_bytes = count_bytes(fields_annotations());100sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());101102sz->_annotations_bytes +=103sz->_class_annotations_bytes +104sz->_class_type_annotations_bytes +105sz->_fields_annotations_bytes +106sz->_fields_type_annotations_bytes;107108sz->_ro_bytes += sz->_annotations_bytes;109}110#endif // INCLUDE_SERVICES111112#define BULLET " - "113114#ifndef PRODUCT115void Annotations::print_on(outputStream* st) const {116st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st);117st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st);118st->print(BULLET"class_type_annotations "); class_type_annotations()->print_value_on(st);119st->print(BULLET"fields_type_annotations "); fields_type_annotations()->print_value_on(st);120}121#endif // PRODUCT122123124