Path: blob/master/src/hotspot/share/oops/annotations.cpp
40951 views
/*1* Copyright (c) 2012, 2020, 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 "logging/log.hpp"27#include "memory/metadataFactory.hpp"28#include "memory/metaspaceClosure.hpp"29#include "memory/oopFactory.hpp"30#include "oops/annotations.hpp"31#include "oops/instanceKlass.hpp"32#include "oops/typeArrayOop.inline.hpp"33#include "utilities/ostream.hpp"3435// Allocate annotations in metadata area36Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {37return new (loader_data, size(), MetaspaceObj::AnnotationsType, THREAD) Annotations();38}3940// helper41void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {42if (p != NULL) {43for (int i = 0; i < p->length(); i++) {44MetadataFactory::free_array<u1>(loader_data, p->at(i));45}46MetadataFactory::free_array<AnnotationArray*>(loader_data, p);47}48}4950void Annotations::deallocate_contents(ClassLoaderData* loader_data) {51if (class_annotations() != NULL) {52MetadataFactory::free_array<u1>(loader_data, class_annotations());53}54free_contents(loader_data, fields_annotations());5556if (class_type_annotations() != NULL) {57MetadataFactory::free_array<u1>(loader_data, class_type_annotations());58}59free_contents(loader_data, fields_type_annotations());60}6162// Copy annotations to JVM call or reflection to the java heap.63// The alternative to creating this array and adding to Java heap pressure64// is to have a hashtable of the already created typeArrayOops65typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {66if (annotations != NULL) {67int length = annotations->length();68typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);69for (int i = 0; i< length; i++) {70copy->byte_at_put(i, annotations->at(i));71}72return copy;73} else {74return NULL;75}76}7778void Annotations::metaspace_pointers_do(MetaspaceClosure* it) {79log_trace(cds)("Iter(Annotations): %p", this);80it->push(&_class_annotations);81it->push(&_fields_annotations);82it->push(&_class_type_annotations);83it->push(&_fields_type_annotations); // FIXME: need a test case where _fields_type_annotations != NULL84}8586void Annotations::print_value_on(outputStream* st) const {87st->print("Annotations(" INTPTR_FORMAT ")", p2i(this));88}8990#define BULLET " - "9192#ifndef PRODUCT93void Annotations::print_on(outputStream* st) const {94st->print(BULLET"class_annotations "); class_annotations()->print_value_on(st);95st->print(BULLET"fields_annotations "); fields_annotations()->print_value_on(st);96st->print(BULLET"class_type_annotations "); class_type_annotations()->print_value_on(st);97st->print(BULLET"fields_type_annotations "); fields_type_annotations()->print_value_on(st);98}99#endif // PRODUCT100101102