< prev index next >

src/hotspot/share/oops/fieldInfo.hpp

Print this page

 49 // This class represents the field information contained in the fields
 50 // array of an InstanceKlass.  Currently it's laid on top an array of
 51 // Java shorts but in the future it could simply be used as a real
 52 // array type.  FieldInfo generally shouldn't be used directly.
 53 // Fields should be queried either through InstanceKlass or through
 54 // the various FieldStreams.
 55 class FieldInfo {
 56   friend class fieldDescriptor;
 57   friend class JavaFieldStream;
 58   friend class ClassFileParser;
 59   friend class FieldInfoStream;
 60   friend class FieldStreamBase;
 61   friend class FieldInfoReader;
 62   friend class VMStructs;
 63 
 64  public:
 65 
 66   class FieldFlags {
 67     friend class VMStructs;
 68     friend class JVMCIVMStructs;

 69 
 70     // The ordering of this enum is totally internal.  More frequent
 71     // flags should come earlier than less frequent ones, because
 72     // earlier ones compress better.
 73     enum FieldFlagBitPosition {


 74       _ff_initialized,  // has ConstantValue initializer attribute
 75       _ff_injected,     // internal field injected by the JVM
 76       _ff_generic,      // has a generic signature
 77       _ff_stable,       // trust as stable b/c declared as @Stable
 78       _ff_contended,    // is contended, may have contention-group


 79     };
 80 
 81     // Some but not all of the flag bits signal the presence of an
 82     // additional 32-bit item in the field record.
 83     static const u4 _optional_item_bit_mask =
 84       flag_mask((int)_ff_initialized) |
 85       flag_mask((int)_ff_generic)     |
 86       flag_mask((int)_ff_contended);

 87 
 88     // boilerplate:
 89     u4 _flags;
 90 
 91     bool test_flag(FieldFlagBitPosition pos) const {
 92       return (_flags & flag_mask(pos)) != 0;
 93     }
 94     void update_flag(FieldFlagBitPosition pos, bool z) {
 95       if (z)    _flags |=  flag_mask(pos);
 96       else      _flags &= ~flag_mask(pos);
 97     }
 98 
 99    public:
100     FieldFlags(u4 flags) {
101       _flags = flags;
102     }
103     u4 as_uint() const { return _flags; }
104     bool has_any_optionals() const {
105       return (_flags & _optional_item_bit_mask) != 0;
106     }
107 
108     bool is_initialized() const     { return test_flag(_ff_initialized); }


109     bool is_injected() const        { return test_flag(_ff_injected); }
110     bool is_generic() const         { return test_flag(_ff_generic); }
111     bool is_stable() const          { return test_flag(_ff_stable); }
112     bool is_contended() const       { return test_flag(_ff_contended); }


113 
114     void update_initialized(bool z) { update_flag(_ff_initialized, z); }


115     void update_injected(bool z)    { update_flag(_ff_injected, z); }
116     void update_generic(bool z)     { update_flag(_ff_generic, z); }
117     void update_stable(bool z)      { update_flag(_ff_stable, z); }
118     void update_contended(bool z)   { update_flag(_ff_contended, z); }


119   };
120 
121  private:
122   // The following items are the unpacked bitwise information content
123   // of a field record.  Per-field metadata extracted from the class
124   // file are stored logically as a group of these items.  The
125   // classfile parser produces these records in a temporary array, and
126   // then compresses them into a FieldInfoStream.
127   //
128   u4 _index;                    // which field it is
129   u2 _name_index;               // index in CP of name
130   u2 _signature_index;          // index in CP of descriptor
131   u4 _offset;                   // offset in object layout
132   AccessFlags _access_flags;    // access flags (JVM spec)
133   FieldFlags _field_flags;      // VM defined flags (not JVM spec)

134   u2 _initializer_index;        // index from ConstantValue attr (or 0)
135   u2 _generic_signature_index;  // index from GenericSignature attr (or 0)
136   u2 _contention_group;         // index from @Contended group item (or 0)
137 
138  public:
139 
140   FieldInfo() : _name_index(0),
141                 _signature_index(0),
142                 _offset(0),
143                 _access_flags(AccessFlags(0)),
144                 _field_flags(FieldFlags(0)),

145                 _initializer_index(0),
146                 _generic_signature_index(0),
147                 _contention_group(0) { }
148 
149   FieldInfo(AccessFlags access_flags, u2 name_index, u2 signature_index, u2 initval_index, FieldInfo::FieldFlags fflags) :
150             _name_index(name_index),
151             _signature_index(signature_index),
152             _offset(0),
153             _access_flags(access_flags),
154             _field_flags(fflags),

155             _initializer_index(initval_index),
156             _generic_signature_index(0),
157             _contention_group(0) {
158               if (initval_index != 0) {
159                 _field_flags.update_initialized(true);
160               }
161             }
162 
163   u4 index() const                           { return _index; }
164   void set_index(u4 index)                   { _index = index; }
165   u2 name_index() const                      { return _name_index; }
166   void set_name_index(u2 index)              { _name_index = index; }
167   u2 signature_index() const                 { return _signature_index; }
168   void set_signature_index(u2 index)         { _signature_index = index; }
169   u4 offset() const                          { return _offset; }
170   void set_offset(u4 offset)                 { _offset = offset; }
171   AccessFlags access_flags() const           { return _access_flags; }
172   FieldFlags field_flags() const             { return _field_flags; }
173   FieldFlags* field_flags_addr()             { return &_field_flags; }


174   u2 initializer_index() const               { return _initializer_index; }
175   void set_initializer_index(u2 index)       { _initializer_index = index; }
176   u2 generic_signature_index() const         { return _generic_signature_index; }
177   void set_generic_signature_index(u2 index) { _generic_signature_index = index; }
178   u2 contention_group() const                { return _contention_group; }
179 
180   bool is_contended() const {
181     return _field_flags.is_contended();
182   }
183 
184   u2 contended_group() const {
185     assert(is_contended(), "");
186     return _contention_group;
187   }
188 
189   void set_contended_group(u2 group) {
190     _field_flags.update_contended(true);
191     _contention_group = group;
192   }
193 

 49 // This class represents the field information contained in the fields
 50 // array of an InstanceKlass.  Currently it's laid on top an array of
 51 // Java shorts but in the future it could simply be used as a real
 52 // array type.  FieldInfo generally shouldn't be used directly.
 53 // Fields should be queried either through InstanceKlass or through
 54 // the various FieldStreams.
 55 class FieldInfo {
 56   friend class fieldDescriptor;
 57   friend class JavaFieldStream;
 58   friend class ClassFileParser;
 59   friend class FieldInfoStream;
 60   friend class FieldStreamBase;
 61   friend class FieldInfoReader;
 62   friend class VMStructs;
 63 
 64  public:
 65 
 66   class FieldFlags {
 67     friend class VMStructs;
 68     friend class JVMCIVMStructs;
 69     friend class FieldDesc;
 70 
 71     // The ordering of this enum is totally internal.  More frequent
 72     // flags should come earlier than less frequent ones, because
 73     // earlier ones compress better.
 74     enum FieldFlagBitPosition {
 75       _ff_null_free_inline_type,  // field's type is an inline type and the field is null free
 76       _ff_flat,         // field is a flat field
 77       _ff_initialized,  // has ConstantValue initializer attribute
 78       _ff_injected,     // internal field injected by the JVM
 79       _ff_generic,      // has a generic signature
 80       _ff_stable,       // trust as stable b/c declared as @Stable
 81       _ff_contended,    // is contended, may have contention-group
 82       _ff_null_marker,  // field has a null marker, optional section include the null marker offset
 83       _ff_internal_null_marker // null marker is internal (inside the layout of a flat field)
 84     };
 85 
 86     // Some but not all of the flag bits signal the presence of an
 87     // additional 32-bit item in the field record.
 88     static const u4 _optional_item_bit_mask =
 89       flag_mask((int)_ff_initialized) |
 90       flag_mask((int)_ff_generic)     |
 91       flag_mask((int)_ff_contended)   |
 92       flag_mask((int)_ff_null_marker);
 93 
 94     // boilerplate:
 95     u4 _flags;
 96 
 97     bool test_flag(FieldFlagBitPosition pos) const {
 98       return (_flags & flag_mask(pos)) != 0;
 99     }
100     void update_flag(FieldFlagBitPosition pos, bool z) {
101       if (z)    _flags |=  flag_mask(pos);
102       else      _flags &= ~flag_mask(pos);
103     }
104 
105    public:
106     FieldFlags(u4 flags) {
107       _flags = flags;
108     }
109     u4 as_uint() const { return _flags; }
110     bool has_any_optionals() const {
111       return (_flags & _optional_item_bit_mask) != 0;
112     }
113 
114     bool is_initialized() const     { return test_flag(_ff_initialized); }
115     bool is_null_free_inline_type() const { return test_flag(_ff_null_free_inline_type); }
116     bool is_flat() const            { return test_flag(_ff_flat); }
117     bool is_injected() const        { return test_flag(_ff_injected); }
118     bool is_generic() const         { return test_flag(_ff_generic); }
119     bool is_stable() const          { return test_flag(_ff_stable); }
120     bool is_contended() const       { return test_flag(_ff_contended); }
121     bool has_null_marker() const    { return test_flag(_ff_null_marker); }
122     bool is_null_marker_internal() const {return test_flag(_ff_internal_null_marker); }
123 
124     void update_initialized(bool z) { update_flag(_ff_initialized, z); }
125     void update_null_free_inline_type(bool z) { update_flag(_ff_null_free_inline_type, z); }
126     void update_flat(bool z)        { update_flag(_ff_flat, z); }
127     void update_injected(bool z)    { update_flag(_ff_injected, z); }
128     void update_generic(bool z)     { update_flag(_ff_generic, z); }
129     void update_stable(bool z)      { update_flag(_ff_stable, z); }
130     void update_contended(bool z)   { update_flag(_ff_contended, z); }
131     void update_null_marker(bool z) { update_flag(_ff_null_marker, z); }
132     void update_internal_null_marker(bool z) { update_flag(_ff_internal_null_marker, z); }
133   };
134 
135  private:
136   // The following items are the unpacked bitwise information content
137   // of a field record.  Per-field metadata extracted from the class
138   // file are stored logically as a group of these items.  The
139   // classfile parser produces these records in a temporary array, and
140   // then compresses them into a FieldInfoStream.
141   //
142   u4 _index;                    // which field it is
143   u2 _name_index;               // index in CP of name
144   u2 _signature_index;          // index in CP of descriptor
145   u4 _offset;                   // offset in object layout
146   AccessFlags _access_flags;    // access flags (JVM spec)
147   FieldFlags _field_flags;      // VM defined flags (not JVM spec)
148   u4 _null_marker_offset;       // null marker offset for this field in the object layout
149   u2 _initializer_index;        // index from ConstantValue attr (or 0)
150   u2 _generic_signature_index;  // index from GenericSignature attr (or 0)
151   u2 _contention_group;         // index from @Contended group item (or 0)
152 
153  public:
154 
155   FieldInfo() : _name_index(0),
156                 _signature_index(0),
157                 _offset(0),
158                 _access_flags(AccessFlags(0)),
159                 _field_flags(FieldFlags(0)),
160                 _null_marker_offset(0),
161                 _initializer_index(0),
162                 _generic_signature_index(0),
163                 _contention_group(0) { }
164 
165   FieldInfo(AccessFlags access_flags, u2 name_index, u2 signature_index, u2 initval_index, FieldInfo::FieldFlags fflags) :
166             _name_index(name_index),
167             _signature_index(signature_index),
168             _offset(0),
169             _access_flags(access_flags),
170             _field_flags(fflags),
171             _null_marker_offset(0),
172             _initializer_index(initval_index),
173             _generic_signature_index(0),
174             _contention_group(0) {
175               if (initval_index != 0) {
176                 _field_flags.update_initialized(true);
177               }
178             }
179 
180   u4 index() const                           { return _index; }
181   void set_index(u4 index)                   { _index = index; }
182   u2 name_index() const                      { return _name_index; }
183   void set_name_index(u2 index)              { _name_index = index; }
184   u2 signature_index() const                 { return _signature_index; }
185   void set_signature_index(u2 index)         { _signature_index = index; }
186   u4 offset() const                          { return _offset; }
187   void set_offset(u4 offset)                 { _offset = offset; }
188   AccessFlags access_flags() const           { return _access_flags; }
189   FieldFlags field_flags() const             { return _field_flags; }
190   FieldFlags* field_flags_addr()             { return &_field_flags; }
191   u4 null_marker_offset() const              { return _null_marker_offset; }
192   void set_null_marker_offset(u4 offset)     { _null_marker_offset = offset; }
193   u2 initializer_index() const               { return _initializer_index; }
194   void set_initializer_index(u2 index)       { _initializer_index = index; }
195   u2 generic_signature_index() const         { return _generic_signature_index; }
196   void set_generic_signature_index(u2 index) { _generic_signature_index = index; }
197   u2 contention_group() const                { return _contention_group; }
198 
199   bool is_contended() const {
200     return _field_flags.is_contended();
201   }
202 
203   u2 contended_group() const {
204     assert(is_contended(), "");
205     return _contention_group;
206   }
207 
208   void set_contended_group(u2 group) {
209     _field_flags.update_contended(true);
210     _contention_group = group;
211   }
212 
< prev index next >