1 /* 2 * Copyright (c) 2012, 2018, 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 * 23 */ 24 25 #ifndef SHARE_VM_OOPS_ANNOTATIONS_HPP 26 #define SHARE_VM_OOPS_ANNOTATIONS_HPP 27 28 #include "oops/array.hpp" 29 #include "oops/metadata.hpp" 30 #include "utilities/exceptions.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 34 class ClassLoaderData; 35 class outputStream; 36 class KlassSizeStats; 37 38 typedef Array<u1> AnnotationArray; 39 40 // Class to hold the various types of annotations. The only metadata that points 41 // to this is InstanceKlass, or another Annotations instance if this is a 42 // a type_annotation instance. 43 44 class Annotations: public MetaspaceObj { 45 // If you add a new field that points to any metaspace object, you 46 // must add this field to Annotations::metaspace_pointers_do(). 47 48 // Annotations for this class, or null if none. 49 AnnotationArray* _class_annotations; 50 // Annotation objects (byte arrays) for fields, or null if no annotations. 51 // Indices correspond to entries (not indices) in fields array. 52 Array<AnnotationArray*>* _fields_annotations; 53 // Type annotations for this class, or null if none. 54 AnnotationArray* _class_type_annotations; 55 Array<AnnotationArray*>* _fields_type_annotations; 56 57 public: 58 // Allocate instance of this class 59 static Annotations* allocate(ClassLoaderData* loader_data, TRAPS); 60 61 static void free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p); 62 void deallocate_contents(ClassLoaderData* loader_data); DEBUG_ONLY(bool on_stack (){ return false; })63 DEBUG_ONLY(bool on_stack() { return false; }) // for template 64 65 // Sizing (in words) 66 static int size() { return sizeof(Annotations) / wordSize; } 67 68 // Annotations should be stored in the read-only region of CDS archive. is_read_only_by_default()69 static bool is_read_only_by_default() { return true; } 70 71 #if INCLUDE_SERVICES 72 void collect_statistics(KlassSizeStats *sz) const; 73 #endif 74 75 // Constructor to initialize to null Annotations()76 Annotations() : _class_annotations(NULL), 77 _fields_annotations(NULL), 78 _class_type_annotations(NULL), 79 _fields_type_annotations(NULL) {} 80 class_annotations() const81 AnnotationArray* class_annotations() const { return _class_annotations; } fields_annotations() const82 Array<AnnotationArray*>* fields_annotations() const { return _fields_annotations; } class_type_annotations() const83 AnnotationArray* class_type_annotations() const { return _class_type_annotations; } fields_type_annotations() const84 Array<AnnotationArray*>* fields_type_annotations() const { return _fields_type_annotations; } 85 set_class_annotations(AnnotationArray * md)86 void set_class_annotations(AnnotationArray* md) { _class_annotations = md; } set_fields_annotations(Array<AnnotationArray * > * md)87 void set_fields_annotations(Array<AnnotationArray*>* md) { _fields_annotations = md; } set_class_type_annotations(AnnotationArray * cta)88 void set_class_type_annotations(AnnotationArray* cta) { _class_type_annotations = cta; } set_fields_type_annotations(Array<AnnotationArray * > * fta)89 void set_fields_type_annotations(Array<AnnotationArray*>* fta) { _fields_type_annotations = fta; } 90 91 // Turn metadata annotations into a Java heap object (oop) 92 static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS); 93 is_klass() const94 bool is_klass() const { return false; } 95 void metaspace_pointers_do(MetaspaceClosure* it); type() const96 MetaspaceObj::Type type() const { return AnnotationsType; } 97 98 private: 99 static julong count_bytes(Array<AnnotationArray*>* p); 100 public: internal_name() const101 const char* internal_name() const { return "{constant pool}"; } 102 #ifndef PRODUCT 103 void print_on(outputStream* st) const; 104 #endif 105 void print_value_on(outputStream* st) const; 106 }; 107 #endif // SHARE_VM_OOPS_ANNOTATIONS_HPP 108