< prev index next >

src/hotspot/share/oops/fieldInfo.hpp

Print this page

  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_FIELDINFO_HPP
 26 #define SHARE_OOPS_FIELDINFO_HPP
 27 
 28 #include "memory/allocation.hpp"

 29 #include "oops/typeArrayOop.hpp"
 30 #include "utilities/accessFlags.hpp"
 31 #include "utilities/unsigned5.hpp"
 32 #include "utilities/vmEnums.hpp"
 33 
 34 static constexpr u4 flag_mask(int pos) {
 35   return (u4)1 << pos;
 36 }
 37 
 38 
 39 // Helper class for access to the underlying Array<u1> used to
 40 // store the compressed stream of FieldInfo
 41 template<typename ARR, typename OFF>
 42 struct ArrayHelper {
 43   uint8_t operator()(ARR a, OFF i) const { return a->at(i); };
 44   void operator()(ARR a, OFF i, uint8_t b) const { a->at_put(i,b); };
 45   // So, an expression ArrayWriterHelper() acts like these lambdas:
 46   // auto get = [&](ARR a, OFF i){ return a[i]; };
 47   // auto set = [&](ARR a, OFF i, uint8_t x){ a[i] = x; };
 48 };
 49 
 50 // This class represents the field information contained in the fields
 51 // array of an InstanceKlass.  Currently it's laid on top an array of
 52 // Java shorts but in the future it could simply be used as a real
 53 // array type.  FieldInfo generally shouldn't be used directly.
 54 // Fields should be queried either through InstanceKlass or through
 55 // the various FieldStreams.
 56 class FieldInfo {
 57   friend class fieldDescriptor;
 58   friend class JavaFieldStream;
 59   friend class ClassFileParser;
 60   friend class FieldInfoStream;
 61   friend class FieldStreamBase;
 62   friend class FieldInfoReader;
 63   friend class VMStructs;
 64 
 65  public:
 66 
 67   class FieldFlags {
 68     friend class VMStructs;
 69     friend class JVMCIVMStructs;

 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_initialized,  // has ConstantValue initializer attribute
 76       _ff_injected,     // internal field injected by the JVM
 77       _ff_generic,      // has a generic signature
 78       _ff_stable,       // trust as stable b/c declared as @Stable
 79       _ff_contended,    // is contended, may have contention-group
 80     };
 81 
 82     // Some but not all of the flag bits signal the presence of an
 83     // additional 32-bit item in the field record.
 84     static const u4 _optional_item_bit_mask =
 85       flag_mask((int)_ff_initialized) |
 86       flag_mask((int)_ff_generic)     |
 87       flag_mask((int)_ff_contended);


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


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

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


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

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


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


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


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










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

280  public:
281   static int num_java_fields(const Array<u1>* fis);
282   static int num_injected_java_fields(const Array<u1>* fis);
283   static int num_total_fields(const Array<u1>* fis);
284 
285   static Array<u1>* create_FieldInfoStream(GrowableArray<FieldInfo>* fields, int java_fields, int injected_fields,
286                                            ClassLoaderData* loader_data, TRAPS);
287   static Array<u1>* create_search_table(ConstantPool* cp, const Array<u1>* fis, ClassLoaderData* loader_data, TRAPS);
288   static GrowableArray<FieldInfo>* create_FieldInfoArray(const Array<u1>* fis, int* java_fields_count, int* injected_fields_count);
289   static void print_from_fieldinfo_stream(Array<u1>* fis, outputStream* os, ConstantPool* cp);
290 
291   DEBUG_ONLY(static void validate_search_table(ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);)
292 
293   static void print_search_table(outputStream* st, ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);
294 };
295 
296 class FieldStatus {
297   enum FieldStatusBitPosition {
298     _fs_access_watched,       // field access is watched by JVMTI
299     _fs_modification_watched, // field modification is watched by JVMTI


300     _initialized_final_update // (static) final field updated outside (class) initializer
301   };
302 
303   // boilerplate:
304   u1 _flags;
305   static constexpr u1 flag_mask(FieldStatusBitPosition pos) { return (u1)1 << (int)pos; }
306   bool test_flag(FieldStatusBitPosition pos) { return (_flags & flag_mask(pos)) != 0; }
307   // this performs an atomic update on a live status byte!
308   void update_flag(FieldStatusBitPosition pos, bool z);
309   // out-of-line functions do a CAS-loop
310   static void atomic_set_bits(u1& flags, u1 mask);
311   static void atomic_clear_bits(u1& flags, u1 mask);
312 
313   public:
314   FieldStatus() { _flags = 0; }
315   FieldStatus(u1 flags) { _flags = flags; }
316   u1 as_uint() { return _flags; }
317 
318   bool is_access_watched()        { return test_flag(_fs_access_watched); }
319   bool is_modification_watched()  { return test_flag(_fs_modification_watched); }


320   bool is_initialized_final_update() { return test_flag(_initialized_final_update); }
321 
322   void update_access_watched(bool z);
323   void update_modification_watched(bool z);


324   void update_initialized_final_update(bool z);
325 };
326 
327 #endif // SHARE_OOPS_FIELDINFO_HPP

  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_FIELDINFO_HPP
 26 #define SHARE_OOPS_FIELDINFO_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 #include "oops/layoutKind.hpp"
 30 #include "oops/typeArrayOop.hpp"
 31 #include "utilities/accessFlags.hpp"
 32 #include "utilities/unsigned5.hpp"
 33 #include "utilities/vmEnums.hpp"
 34 
 35 static constexpr u4 flag_mask(int pos) {
 36   return (u4)1 << pos;
 37 }
 38 

 39 // Helper class for access to the underlying Array<u1> used to
 40 // store the compressed stream of FieldInfo
 41 template<typename ARR, typename OFF>
 42 struct ArrayHelper {
 43   uint8_t operator()(ARR a, OFF i) const { return a->at(i); };
 44   void operator()(ARR a, OFF i, uint8_t b) const { a->at_put(i,b); };
 45   // So, an expression ArrayWriterHelper() acts like these lambdas:
 46   // auto get = [&](ARR a, OFF i){ return a[i]; };
 47   // auto set = [&](ARR a, OFF i, uint8_t x){ a[i] = x; };
 48 };
 49 
 50 // This class represents the field information contained in the fields
 51 // array of an InstanceKlass.  Currently it's laid on top an array of
 52 // Java shorts but in the future it could simply be used as a real
 53 // array type.  FieldInfo generally shouldn't be used directly.
 54 // Fields should be queried either through InstanceKlass or through
 55 // the various FieldStreams.
 56 class FieldInfo {
 57   friend class fieldDescriptor;
 58   friend class JavaFieldStream;
 59   friend class ClassFileParser;
 60   friend class FieldInfoStream;
 61   friend class FieldStreamBase;
 62   friend class FieldInfoReader;
 63   friend class VMStructs;
 64 
 65  public:
 66 
 67   class FieldFlags {
 68     friend class VMStructs;
 69     friend class JVMCIVMStructs;
 70     friend class FieldDesc;
 71 
 72     // The ordering of this enum is totally internal.  More frequent
 73     // flags should come earlier than less frequent ones, because
 74     // earlier ones compress better.
 75     enum FieldFlagBitPosition {
 76       _ff_null_free_inline_type,  // field's type is an inline type and the field is null free
 77       _ff_flat,         // field is a flat field, optional section includes a layout kind
 78       _ff_null_marker,  // field has a null marker, optional section includes the null marker offset
 79       _ff_initialized,  // has ConstantValue initializer attribute
 80       _ff_injected,     // internal field injected by the JVM
 81       _ff_generic,      // has a generic signature
 82       _ff_stable,       // trust as stable b/c declared as @Stable
 83       _ff_contended    // is contended, may have contention-group
 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_flat)        |
 93       flag_mask((int)_ff_null_marker);
 94 
 95     // boilerplate:
 96     u4 _flags;
 97 
 98     bool test_flag(FieldFlagBitPosition pos) const {
 99       return (_flags & flag_mask(pos)) != 0;
100     }
101     void update_flag(FieldFlagBitPosition pos, bool z) {
102       if (z)    _flags |=  flag_mask(pos);
103       else      _flags &= ~flag_mask(pos);
104     }
105 
106    public:
107     FieldFlags(u4 flags) {
108       _flags = flags;
109     }
110     u4 as_uint() const { return _flags; }
111     bool has_any_optionals() const {
112       return (_flags & _optional_item_bit_mask) != 0;
113     }
114 
115     bool is_initialized() const     { return test_flag(_ff_initialized); }
116     bool is_null_free_inline_type() const { return test_flag(_ff_null_free_inline_type); }
117     bool is_flat() const            { return test_flag(_ff_flat); }
118     bool is_injected() const        { return test_flag(_ff_injected); }
119     bool is_generic() const         { return test_flag(_ff_generic); }
120     bool is_stable() const          { return test_flag(_ff_stable); }
121     bool is_contended() const       { return test_flag(_ff_contended); }
122     bool has_null_marker() const    { return test_flag(_ff_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   };
133 
134  private:
135   // The following items are the unpacked bitwise information content
136   // of a field record.  Per-field metadata extracted from the class
137   // file are stored logically as a group of these items.  The
138   // classfile parser produces these records in a temporary array, and
139   // then compresses them into a FieldInfoStream.
140   //
141   u4 _index;                    // which field it is
142   u2 _name_index;               // index in CP of name
143   u2 _signature_index;          // index in CP of descriptor
144   u4 _offset;                   // offset in object layout
145   AccessFlags _access_flags;    // access flags (JVM spec)
146   FieldFlags _field_flags;      // VM defined flags (not JVM spec)
147   LayoutKind _layout_kind;      // LayoutKind if the field is flat
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() : _index(0),
156                 _name_index(0),
157                 _signature_index(0),
158                 _offset(0),
159                 _access_flags(AccessFlags(0)),
160                 _field_flags(FieldFlags(0)),
161                 _layout_kind(LayoutKind::UNKNOWN),
162                 _null_marker_offset(0),
163                 _initializer_index(0),
164                 _generic_signature_index(0),
165                 _contention_group(0) { }
166 
167   FieldInfo(AccessFlags access_flags, u2 name_index, u2 signature_index, u2 initval_index, FieldInfo::FieldFlags fflags) :
168             _index(0),
169             _name_index(name_index),
170             _signature_index(signature_index),
171             _offset(0),
172             _access_flags(access_flags),
173             _field_flags(fflags),
174             _layout_kind(LayoutKind::UNKNOWN),
175             _null_marker_offset(0),
176             _initializer_index(initval_index),
177             _generic_signature_index(0),
178             _contention_group(0) {
179               if (initval_index != 0) {
180                 _field_flags.update_initialized(true);
181               }
182             }
183 
184   u4 index() const                           { return _index; }
185   void set_index(u4 index)                   { _index = index; }
186   u2 name_index() const                      { return _name_index; }
187   void set_name_index(u2 index)              { _name_index = index; }
188   u2 signature_index() const                 { return _signature_index; }
189   void set_signature_index(u2 index)         { _signature_index = index; }
190   u4 offset() const                          { return _offset; }
191   void set_offset(u4 offset)                 { _offset = offset; }
192   AccessFlags access_flags() const           { return _access_flags; }
193   FieldFlags field_flags() const             { return _field_flags; }
194   FieldFlags* field_flags_addr()             { return &_field_flags; }
195   LayoutKind layout_kind() const             { return _layout_kind; }
196   void set_layout_kind(LayoutKind lk) {
197     assert(_field_flags.is_flat(), "Must be");
198     _layout_kind = lk;
199   }
200   u4 null_marker_offset() const              { return _null_marker_offset; }
201   void set_null_marker_offset(u4 offset) {
202     _field_flags.update_null_marker(true);
203     _null_marker_offset = offset;
204   }
205   u2 initializer_index() const               { return _initializer_index; }
206   void set_initializer_index(u2 index)       { _initializer_index = index; }
207   u2 generic_signature_index() const         { return _generic_signature_index; }
208   void set_generic_signature_index(u2 index) { _generic_signature_index = index; }
209   u2 contention_group() const                { return _contention_group; }
210 
211   bool is_contended() const {
212     return _field_flags.is_contended();
213   }
214 
215   u2 contended_group() const {
216     assert(is_contended(), "");
217     return _contention_group;
218   }
219 
220   void set_contended_group(u2 group) {
221     _field_flags.update_contended(true);
222     _contention_group = group;
223   }
224 

308  public:
309   static int num_java_fields(const Array<u1>* fis);
310   static int num_injected_java_fields(const Array<u1>* fis);
311   static int num_total_fields(const Array<u1>* fis);
312 
313   static Array<u1>* create_FieldInfoStream(GrowableArray<FieldInfo>* fields, int java_fields, int injected_fields,
314                                            ClassLoaderData* loader_data, TRAPS);
315   static Array<u1>* create_search_table(ConstantPool* cp, const Array<u1>* fis, ClassLoaderData* loader_data, TRAPS);
316   static GrowableArray<FieldInfo>* create_FieldInfoArray(const Array<u1>* fis, int* java_fields_count, int* injected_fields_count);
317   static void print_from_fieldinfo_stream(Array<u1>* fis, outputStream* os, ConstantPool* cp);
318 
319   DEBUG_ONLY(static void validate_search_table(ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);)
320 
321   static void print_search_table(outputStream* st, ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);
322 };
323 
324 class FieldStatus {
325   enum FieldStatusBitPosition {
326     _fs_access_watched,       // field access is watched by JVMTI
327     _fs_modification_watched, // field modification is watched by JVMTI
328     _fs_strict_static_unset,  // JVM_ACC_STRICT static field has not yet been set
329     _fs_strict_static_unread, // SS field has not yet been read
330     _initialized_final_update // (static) final field updated outside (class) initializer
331   };
332 
333   // boilerplate:
334   u1 _flags;
335   static constexpr u1 flag_mask(FieldStatusBitPosition pos) { return (u1)1 << (int)pos; }
336   bool test_flag(FieldStatusBitPosition pos) { return (_flags & flag_mask(pos)) != 0; }
337   // this performs an atomic update on a live status byte!
338   void update_flag(FieldStatusBitPosition pos, bool z);
339   // out-of-line functions do a CAS-loop
340   static void atomic_set_bits(u1& flags, u1 mask);
341   static void atomic_clear_bits(u1& flags, u1 mask);
342 
343   public:
344   FieldStatus() { _flags = 0; }
345   FieldStatus(u1 flags) { _flags = flags; }
346   u1 as_uint() { return _flags; }
347 
348   bool is_access_watched()           { return test_flag(_fs_access_watched); }
349   bool is_modification_watched()     { return test_flag(_fs_modification_watched); }
350   bool is_strict_static_unset()      { return test_flag(_fs_strict_static_unset); }
351   bool is_strict_static_unread()     { return test_flag(_fs_strict_static_unread); }
352   bool is_initialized_final_update() { return test_flag(_initialized_final_update); }
353 
354   void update_access_watched(bool z);
355   void update_modification_watched(bool z);
356   void update_strict_static_unset(bool z);
357   void update_strict_static_unread(bool z);
358   void update_initialized_final_update(bool z);
359 };
360 
361 #endif // SHARE_OOPS_FIELDINFO_HPP
< prev index next >