< prev index next >

src/hotspot/share/oops/annotations.cpp

Print this page

  1 /*
  2  * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *

 24 
 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"
 34 
 35 // Allocate annotations in metadata area
 36 Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
 37   return new (loader_data, size(), MetaspaceObj::AnnotationsType, THREAD) Annotations();
 38 }
 39 
 40 // helper
 41 void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {
 42   if (p != nullptr) {
 43     for (int i = 0; i < p->length(); i++) {
 44       MetadataFactory::free_array<u1>(loader_data, p->at(i));


 45     }
 46     MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
 47   }
 48 }
 49 
 50 void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
 51   if (class_annotations() != nullptr) {
 52     MetadataFactory::free_array<u1>(loader_data, class_annotations());
 53   }
 54   free_contents(loader_data, fields_annotations());
 55 
 56   if (class_type_annotations() != nullptr) {
 57     MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
 58   }
 59   free_contents(loader_data, fields_type_annotations());
 60 }
 61 
 62 // Copy annotations to JVM call or reflection to the java heap.
 63 // The alternative to creating this array and adding to Java heap pressure
 64 // is to have a hashtable of the already created typeArrayOops

  1 /*
  2  * Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *

 24 
 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"
 34 
 35 // Allocate annotations in metadata area
 36 Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
 37   return new (loader_data, size(), MetaspaceObj::AnnotationsType, THREAD) Annotations();
 38 }
 39 
 40 // helper
 41 void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {
 42   if (p != nullptr) {
 43     for (int i = 0; i < p->length(); i++) {
 44       if (p->at(i) != nullptr) {
 45         MetadataFactory::free_array<u1>(loader_data, p->at(i));
 46       }
 47     }
 48     MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
 49   }
 50 }
 51 
 52 void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
 53   if (class_annotations() != nullptr) {
 54     MetadataFactory::free_array<u1>(loader_data, class_annotations());
 55   }
 56   free_contents(loader_data, fields_annotations());
 57 
 58   if (class_type_annotations() != nullptr) {
 59     MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
 60   }
 61   free_contents(loader_data, fields_type_annotations());
 62 }
 63 
 64 // Copy annotations to JVM call or reflection to the java heap.
 65 // The alternative to creating this array and adding to Java heap pressure
 66 // is to have a hashtable of the already created typeArrayOops
< prev index next >