1 /*
2  * Copyright (c) 2019, 2020, 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_OOPS_RECORDCOMPONENT_HPP
26 #define SHARE_OOPS_RECORDCOMPONENT_HPP
27 
28 #include "oops/annotations.hpp"
29 #include "oops/metadata.hpp"
30 #include "utilities/globalDefinitions.hpp"
31 
32 // This class stores information extracted from the Record class attribute.
33 class RecordComponent: public MetaspaceObj {
34   private:
35     AnnotationArray* _annotations;
36     AnnotationArray* _type_annotations;
37     u2 _name_index;
38     u2 _descriptor_index;
39     u2 _attributes_count;
40 
41     // generic_signature_index gets set if the Record component has a Signature
42     // attribute.  A zero value indicates that there was no Signature attribute.
43     u2 _generic_signature_index;
44 
45   public:
RecordComponent(u2 name_index,u2 descriptor_index,u2 attributes_count,u2 generic_signature_index,AnnotationArray * annotations,AnnotationArray * type_annotations)46     RecordComponent(u2 name_index, u2 descriptor_index, u2 attributes_count,
47                     u2 generic_signature_index, AnnotationArray* annotations,
48                     AnnotationArray* type_annotations):
49                     _annotations(annotations), _type_annotations(type_annotations),
50                     _name_index(name_index), _descriptor_index(descriptor_index),
51                     _attributes_count(attributes_count),
52                     _generic_signature_index(generic_signature_index) { }
53 
54     // Allocate instance of this class
55     static RecordComponent* allocate(ClassLoaderData* loader_data,
56                                      u2 name_index, u2 descriptor_index,
57                                      u2 attributes_count,
58                                      u2 generic_signature_index,
59                                      AnnotationArray* annotations,
60                                      AnnotationArray* type_annotations, TRAPS);
61 
62     void deallocate_contents(ClassLoaderData* loader_data);
63 
name_index() const64     u2 name_index() const { return _name_index; }
set_name_index(u2 name_index)65     void set_name_index(u2 name_index) { _name_index = name_index; }
66 
descriptor_index() const67     u2 descriptor_index() const { return _descriptor_index; }
set_descriptor_index(u2 descriptor_index)68     void set_descriptor_index(u2 descriptor_index) {
69       _descriptor_index = descriptor_index;
70     }
71 
attributes_count() const72     u2 attributes_count() const { return _attributes_count; }
73 
generic_signature_index() const74     u2 generic_signature_index() const { return _generic_signature_index; }
set_generic_signature_index(u2 generic_signature_index)75     void set_generic_signature_index(u2 generic_signature_index) {
76       _generic_signature_index = generic_signature_index;
77     }
78 
annotations() const79     AnnotationArray* annotations() const { return _annotations; }
type_annotations() const80     AnnotationArray* type_annotations() const { return _type_annotations; }
81 
82     // Size of RecordComponent, not including size of any annotations.
size()83     static int size() { return sizeof(RecordComponent) / wordSize; }
84 
85     void metaspace_pointers_do(MetaspaceClosure* it);
type() const86     MetaspaceObj::Type type() const { return RecordComponentType; }
87 
88     // Record_components should be stored in the read-only region of CDS archive.
is_read_only_by_default()89     static bool is_read_only_by_default() { return true; }
DEBUG_ONLY(bool on_stack (){ return false; })90     DEBUG_ONLY(bool on_stack() { return false; })  // for template
91 
92     bool is_klass() const { return false; }
93 
94 #ifndef PRODUCT
95     void print_on(outputStream* st) const;
96 #endif
97     void print_value_on(outputStream* st) const;
98 
99 };
100 
101 #endif // SHARE_OOPS_RECORDCOMPONENT_HPP
102