Path: blob/master/src/hotspot/share/oops/annotations.hpp
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#ifndef SHARE_OOPS_ANNOTATIONS_HPP25#define SHARE_OOPS_ANNOTATIONS_HPP2627#include "oops/array.hpp"28#include "oops/metadata.hpp"29#include "utilities/exceptions.hpp"30#include "utilities/globalDefinitions.hpp"313233class ClassLoaderData;34class outputStream;3536typedef Array<u1> AnnotationArray;3738// Class to hold the various types of annotations. The only metadata that points39// to this is InstanceKlass, or another Annotations instance if this is a40// a type_annotation instance.4142class Annotations: public MetaspaceObj {43friend class JVMCIVMStructs;4445// If you add a new field that points to any metaspace object, you46// must add this field to Annotations::metaspace_pointers_do().4748// Annotations for this class, or null if none.49AnnotationArray* _class_annotations;50// Annotation objects (byte arrays) for fields, or null if no annotations.51// Indices correspond to entries (not indices) in fields array.52Array<AnnotationArray*>* _fields_annotations;53// Type annotations for this class, or null if none.54AnnotationArray* _class_type_annotations;55Array<AnnotationArray*>* _fields_type_annotations;5657public:58// Allocate instance of this class59static Annotations* allocate(ClassLoaderData* loader_data, TRAPS);6061static void free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p);62void deallocate_contents(ClassLoaderData* loader_data);63DEBUG_ONLY(bool on_stack() { return false; }) // for template6465// Sizing (in words)66static int size() { return sizeof(Annotations) / wordSize; }6768// Annotations should be stored in the read-only region of CDS archive.69static bool is_read_only_by_default() { return true; }7071// Constructor to initialize to null72Annotations() : _class_annotations(NULL),73_fields_annotations(NULL),74_class_type_annotations(NULL),75_fields_type_annotations(NULL) {}7677AnnotationArray* class_annotations() const { return _class_annotations; }78Array<AnnotationArray*>* fields_annotations() const { return _fields_annotations; }79AnnotationArray* class_type_annotations() const { return _class_type_annotations; }80Array<AnnotationArray*>* fields_type_annotations() const { return _fields_type_annotations; }8182void set_class_annotations(AnnotationArray* md) { _class_annotations = md; }83void set_fields_annotations(Array<AnnotationArray*>* md) { _fields_annotations = md; }84void set_class_type_annotations(AnnotationArray* cta) { _class_type_annotations = cta; }85void set_fields_type_annotations(Array<AnnotationArray*>* fta) { _fields_type_annotations = fta; }8687// Turn metadata annotations into a Java heap object (oop)88static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS);8990bool is_klass() const { return false; }91void metaspace_pointers_do(MetaspaceClosure* it);92MetaspaceObj::Type type() const { return AnnotationsType; }9394private:95static julong count_bytes(Array<AnnotationArray*>* p);96public:97const char* internal_name() const { return "{annotations}"; }98#ifndef PRODUCT99void print_on(outputStream* st) const;100#endif101void print_value_on(outputStream* st) const;102};103#endif // SHARE_OOPS_ANNOTATIONS_HPP104105106