coleenp@4037: /* acorn@4497: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. coleenp@4037: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. coleenp@4037: * coleenp@4037: * This code is free software; you can redistribute it and/or modify it coleenp@4037: * under the terms of the GNU General Public License version 2 only, as coleenp@4037: * published by the Free Software Foundation. coleenp@4037: * coleenp@4037: * This code is distributed in the hope that it will be useful, but WITHOUT coleenp@4037: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or coleenp@4037: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License coleenp@4037: * version 2 for more details (a copy is included in the LICENSE file that coleenp@4037: * accompanied this code). coleenp@4037: * coleenp@4037: * You should have received a copy of the GNU General Public License version coleenp@4037: * 2 along with this work; if not, write to the Free Software Foundation, coleenp@4037: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. coleenp@4037: * coleenp@4037: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA coleenp@4037: * or visit www.oracle.com if you need additional information or have any coleenp@4037: * questions. coleenp@4037: * coleenp@4037: */ coleenp@4037: coleenp@4037: #ifndef SHARE_VM_OOPS_ANNOTATIONS_HPP coleenp@4037: #define SHARE_VM_OOPS_ANNOTATIONS_HPP coleenp@4037: coleenp@4037: #include "oops/metadata.hpp" coleenp@4037: #include "runtime/handles.hpp" coleenp@4037: #include "utilities/array.hpp" coleenp@4037: #include "utilities/exceptions.hpp" coleenp@4037: #include "utilities/globalDefinitions.hpp" coleenp@4037: coleenp@4037: coleenp@4037: class ClassLoaderData; coleenp@4037: class outputStream; acorn@4497: class KlassSizeStats; coleenp@4037: coleenp@4037: typedef Array AnnotationArray; coleenp@4037: coleenp@4037: // Class to hold the various types of annotations. The only metadata that points stefank@4393: // to this is InstanceKlass, or another Annotations instance if this is a stefank@4393: // a type_annotation instance. coleenp@4037: coleenp@4037: class Annotations: public MetaspaceObj { coleenp@4037: coleenp@4037: // Annotations for this class, or null if none. coleenp@4037: AnnotationArray* _class_annotations; coleenp@4037: // Annotation objects (byte arrays) for fields, or null if no annotations. coleenp@4037: // Indices correspond to entries (not indices) in fields array. coleenp@4037: Array* _fields_annotations; coleenp@4037: // Annotation objects (byte arrays) for methods, or null if no annotations. coleenp@4037: // Index is the idnum, which is initially the same as the methods array index. coleenp@4037: Array* _methods_annotations; coleenp@4037: // Annotation objects (byte arrays) for methods' parameters, or null if no coleenp@4037: // such annotations. coleenp@4037: // Index is the idnum, which is initially the same as the methods array index. coleenp@4037: Array* _methods_parameter_annotations; coleenp@4037: // Annotation objects (byte arrays) for methods' default values, or null if no coleenp@4037: // such annotations. coleenp@4037: // Index is the idnum, which is initially the same as the methods array index. coleenp@4037: Array* _methods_default_annotations; stefank@4393: // Type annotations for this class, or null if none. stefank@4393: Annotations* _type_annotations; coleenp@4037: coleenp@4037: // Constructor where some some values are known to not be null coleenp@4037: Annotations(Array* fa, Array* ma, coleenp@4037: Array* mpa, Array* mda) : coleenp@4037: _class_annotations(NULL), coleenp@4037: _fields_annotations(fa), coleenp@4037: _methods_annotations(ma), coleenp@4037: _methods_parameter_annotations(mpa), stefank@4393: _methods_default_annotations(mda), stefank@4393: _type_annotations(NULL) {} coleenp@4037: coleenp@4037: public: coleenp@4037: // Allocate instance of this class coleenp@4037: static Annotations* allocate(ClassLoaderData* loader_data, TRAPS); coleenp@4037: static Annotations* allocate(ClassLoaderData* loader_data, coleenp@4037: Array* fa, coleenp@4037: Array* ma, coleenp@4037: Array* mpa, coleenp@4037: Array* mda, TRAPS); coleenp@4037: void deallocate_contents(ClassLoaderData* loader_data); coleenp@4037: DEBUG_ONLY(bool on_stack() { return false; }) // for template acorn@4497: acorn@4497: // Sizing (in words) coleenp@4037: static int size() { return sizeof(Annotations) / wordSize; } acorn@4497: #if INCLUDE_SERVICES acorn@4497: void collect_statistics(KlassSizeStats *sz) const; acorn@4497: #endif coleenp@4037: coleenp@4037: // Constructor to initialize to null stefank@4393: Annotations() : _class_annotations(NULL), stefank@4393: _fields_annotations(NULL), coleenp@4037: _methods_annotations(NULL), coleenp@4037: _methods_parameter_annotations(NULL), stefank@4393: _methods_default_annotations(NULL), stefank@4393: _type_annotations(NULL) {} coleenp@4037: coleenp@4037: AnnotationArray* class_annotations() const { return _class_annotations; } coleenp@4037: Array* fields_annotations() const { return _fields_annotations; } coleenp@4037: Array* methods_annotations() const { return _methods_annotations; } coleenp@4037: Array* methods_parameter_annotations() const { return _methods_parameter_annotations; } coleenp@4037: Array* methods_default_annotations() const { return _methods_default_annotations; } stefank@4393: Annotations* type_annotations() const { return _type_annotations; } coleenp@4037: coleenp@4037: void set_class_annotations(AnnotationArray* md) { _class_annotations = md; } coleenp@4037: void set_fields_annotations(Array* md) { _fields_annotations = md; } coleenp@4037: void set_methods_annotations(Array* md) { _methods_annotations = md; } coleenp@4037: void set_methods_parameter_annotations(Array* md) { _methods_parameter_annotations = md; } coleenp@4037: void set_methods_default_annotations(Array* md) { _methods_default_annotations = md; } stefank@4393: void set_type_annotations(Annotations* annos) { _type_annotations = annos; } coleenp@4037: coleenp@4037: // Redefine classes support coleenp@4037: AnnotationArray* get_method_annotations_of(int idnum) coleenp@4037: { return get_method_annotations_from(idnum, _methods_annotations); } coleenp@4037: coleenp@4037: AnnotationArray* get_method_parameter_annotations_of(int idnum) coleenp@4037: { return get_method_annotations_from(idnum, _methods_parameter_annotations); } coleenp@4037: AnnotationArray* get_method_default_annotations_of(int idnum) coleenp@4037: { return get_method_annotations_from(idnum, _methods_default_annotations); } coleenp@4037: coleenp@4037: coleenp@4037: void set_method_annotations_of(instanceKlassHandle ik, coleenp@4037: int idnum, AnnotationArray* anno, TRAPS) { coleenp@4037: set_methods_annotations_of(ik, idnum, anno, &_methods_annotations, THREAD); coleenp@4037: } coleenp@4037: coleenp@4037: void set_method_parameter_annotations_of(instanceKlassHandle ik, coleenp@4037: int idnum, AnnotationArray* anno, TRAPS) { coleenp@4037: set_methods_annotations_of(ik, idnum, anno, &_methods_parameter_annotations, THREAD); coleenp@4037: } coleenp@4037: coleenp@4037: void set_method_default_annotations_of(instanceKlassHandle ik, coleenp@4037: int idnum, AnnotationArray* anno, TRAPS) { coleenp@4037: set_methods_annotations_of(ik, idnum, anno, &_methods_default_annotations, THREAD); coleenp@4037: } coleenp@4037: coleenp@4037: // Turn metadata annotations into a Java heap object (oop) coleenp@4037: static typeArrayOop make_java_array(AnnotationArray* annotations, TRAPS); coleenp@4037: coleenp@4037: inline AnnotationArray* get_method_annotations_from(int idnum, Array* annos); coleenp@4037: void set_annotations(Array* md, Array** md_p) { *md_p = md; } coleenp@4037: stefank@4393: bool is_klass() const { return false; } coleenp@4037: private: coleenp@4037: void set_methods_annotations_of(instanceKlassHandle ik, coleenp@4037: int idnum, AnnotationArray* anno, coleenp@4037: Array** md_p, TRAPS); acorn@4497: static julong count_bytes(Array* p); coleenp@4037: public: coleenp@4037: const char* internal_name() const { return "{constant pool}"; } coleenp@4037: #ifndef PRODUCT coleenp@4037: void print_on(outputStream* st) const; coleenp@4037: #endif coleenp@4037: void print_value_on(outputStream* st) const; coleenp@4037: }; coleenp@4037: coleenp@4037: coleenp@4037: // For method with idnum get the method's Annotations coleenp@4037: inline AnnotationArray* Annotations::get_method_annotations_from(int idnum, Array* annos) { coleenp@4037: if (annos == NULL || annos->length() <= idnum) { coleenp@4037: return NULL; coleenp@4037: } coleenp@4037: return annos->at(idnum); coleenp@4037: } coleenp@4037: #endif // SHARE_VM_OOPS_ANNOTATIONS_HPP