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/unsigned5.hpp"
31 #include "utilities/vmEnums.hpp"
32
33 static constexpr u4 flag_mask(int pos) {
34 return (u4)1 << pos;
35 }
36
37
38 // Helper class for access to the underlying Array<u1> used to
39 // store the compressed stream of FieldInfo
40 template<typename ARR, typename OFF>
41 struct ArrayHelper {
42 uint8_t operator()(ARR a, OFF i) const { return a->at(i); };
43 void operator()(ARR a, OFF i, uint8_t b) const { a->at_put(i,b); };
44 // So, an expression ArrayWriterHelper() acts like these lambdas:
45 // auto get = [&](ARR a, OFF i){ return a[i]; };
46 // auto set = [&](ARR a, OFF i, uint8_t x){ a[i] = x; };
47 };
48
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() : _index(0),
141 _name_index(0),
142 _signature_index(0),
143 _offset(0),
144 _access_flags(AccessFlags(0)),
145 _field_flags(FieldFlags(0)),
146 _initializer_index(0),
147 _generic_signature_index(0),
148 _contention_group(0) { }
149
150 FieldInfo(AccessFlags access_flags, u2 name_index, u2 signature_index, u2 initval_index, FieldInfo::FieldFlags fflags) :
151 _index(0),
152 _name_index(name_index),
153 _signature_index(signature_index),
154 _offset(0),
155 _access_flags(access_flags),
156 _field_flags(fflags),
157 _initializer_index(initval_index),
158 _generic_signature_index(0),
159 _contention_group(0) {
160 if (initval_index != 0) {
161 _field_flags.update_initialized(true);
162 }
163 }
164
165 u4 index() const { return _index; }
166 void set_index(u4 index) { _index = index; }
167 u2 name_index() const { return _name_index; }
168 void set_name_index(u2 index) { _name_index = index; }
169 u2 signature_index() const { return _signature_index; }
170 void set_signature_index(u2 index) { _signature_index = index; }
171 u4 offset() const { return _offset; }
172 void set_offset(u4 offset) { _offset = offset; }
173 AccessFlags access_flags() const { return _access_flags; }
174 FieldFlags field_flags() const { return _field_flags; }
175 FieldFlags* field_flags_addr() { return &_field_flags; }
176 u2 initializer_index() const { return _initializer_index; }
177 void set_initializer_index(u2 index) { _initializer_index = index; }
178 u2 generic_signature_index() const { return _generic_signature_index; }
179 void set_generic_signature_index(u2 index) { _generic_signature_index = index; }
180 u2 contention_group() const { return _contention_group; }
181
182 bool is_contended() const {
183 return _field_flags.is_contended();
184 }
185
186 u2 contended_group() const {
187 assert(is_contended(), "");
188 return _contention_group;
189 }
190
191 void set_contended_group(u2 group) {
192 _field_flags.update_contended(true);
193 _contention_group = group;
194 }
195
279 public:
280 static int num_java_fields(const Array<u1>* fis);
281 static int num_injected_java_fields(const Array<u1>* fis);
282 static int num_total_fields(const Array<u1>* fis);
283
284 static Array<u1>* create_FieldInfoStream(GrowableArray<FieldInfo>* fields, int java_fields, int injected_fields,
285 ClassLoaderData* loader_data, TRAPS);
286 static Array<u1>* create_search_table(ConstantPool* cp, const Array<u1>* fis, ClassLoaderData* loader_data, TRAPS);
287 static GrowableArray<FieldInfo>* create_FieldInfoArray(const Array<u1>* fis, int* java_fields_count, int* injected_fields_count);
288 static void print_from_fieldinfo_stream(Array<u1>* fis, outputStream* os, ConstantPool* cp);
289
290 DEBUG_ONLY(static void validate_search_table(ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);)
291
292 static void print_search_table(outputStream* st, ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);
293 };
294
295 class FieldStatus {
296 enum FieldStatusBitPosition {
297 _fs_access_watched, // field access is watched by JVMTI
298 _fs_modification_watched, // field modification is watched by JVMTI
299 _initialized_final_update // (static) final field updated outside (class) initializer
300 };
301
302 // boilerplate:
303 u1 _flags;
304 static constexpr u1 flag_mask(FieldStatusBitPosition pos) { return (u1)1 << (int)pos; }
305 bool test_flag(FieldStatusBitPosition pos) { return (_flags & flag_mask(pos)) != 0; }
306 // this performs an atomic update on a live status byte!
307 void update_flag(FieldStatusBitPosition pos, bool z);
308 // out-of-line functions do a CAS-loop
309 static void atomic_set_bits(u1& flags, u1 mask);
310 static void atomic_clear_bits(u1& flags, u1 mask);
311
312 public:
313 FieldStatus() { _flags = 0; }
314 FieldStatus(u1 flags) { _flags = flags; }
315 u1 as_uint() { return _flags; }
316
317 bool is_access_watched() { return test_flag(_fs_access_watched); }
318 bool is_modification_watched() { return test_flag(_fs_modification_watched); }
319 bool is_initialized_final_update() { return test_flag(_initialized_final_update); }
320
321 void update_access_watched(bool z);
322 void update_modification_watched(bool z);
323 void update_initialized_final_update(bool z);
324 };
325
326 #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/unsigned5.hpp"
32 #include "utilities/vmEnums.hpp"
33
34 static constexpr u4 flag_mask(int pos) {
35 return (u4)1 << pos;
36 }
37
38 // Helper class for access to the underlying Array<u1> used to
39 // store the compressed stream of FieldInfo
40 template<typename ARR, typename OFF>
41 struct ArrayHelper {
42 uint8_t operator()(ARR a, OFF i) const { return a->at(i); };
43 void operator()(ARR a, OFF i, uint8_t b) const { a->at_put(i,b); };
44 // So, an expression ArrayWriterHelper() acts like these lambdas:
45 // auto get = [&](ARR a, OFF i){ return a[i]; };
46 // auto set = [&](ARR a, OFF i, uint8_t x){ a[i] = x; };
47 };
48
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, optional section includes a layout kind
77 _ff_null_marker, // field has a null marker, optional section includes the null marker offset
78 _ff_initialized, // has ConstantValue initializer attribute
79 _ff_injected, // internal field injected by the JVM
80 _ff_generic, // has a generic signature
81 _ff_stable, // trust as stable b/c declared as @Stable
82 _ff_contended // is contended, may have contention-group
83 };
84
85 // Some but not all of the flag bits signal the presence of an
86 // additional 32-bit item in the field record.
87 static const u4 _optional_item_bit_mask =
88 flag_mask((int)_ff_initialized) |
89 flag_mask((int)_ff_generic) |
90 flag_mask((int)_ff_contended) |
91 flag_mask((int)_ff_flat) |
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
123 void update_initialized(bool z) { update_flag(_ff_initialized, z); }
124 void update_null_free_inline_type(bool z) { update_flag(_ff_null_free_inline_type, z); }
125 void update_flat(bool z) { update_flag(_ff_flat, z); }
126 void update_injected(bool z) { update_flag(_ff_injected, z); }
127 void update_generic(bool z) { update_flag(_ff_generic, z); }
128 void update_stable(bool z) { update_flag(_ff_stable, z); }
129 void update_contended(bool z) { update_flag(_ff_contended, z); }
130 void update_null_marker(bool z) { update_flag(_ff_null_marker, z); }
131 };
132
133 private:
134 // The following items are the unpacked bitwise information content
135 // of a field record. Per-field metadata extracted from the class
136 // file are stored logically as a group of these items. The
137 // classfile parser produces these records in a temporary array, and
138 // then compresses them into a FieldInfoStream.
139 //
140 u4 _index; // which field it is
141 u2 _name_index; // index in CP of name
142 u2 _signature_index; // index in CP of descriptor
143 u4 _offset; // offset in object layout
144 AccessFlags _access_flags; // access flags (JVM spec)
145 FieldFlags _field_flags; // VM defined flags (not JVM spec)
146 LayoutKind _layout_kind; // LayoutKind if the field is flat
147 u4 _null_marker_offset; // null marker offset for this field in the object layout
148 u2 _initializer_index; // index from ConstantValue attr (or 0)
149 u2 _generic_signature_index; // index from GenericSignature attr (or 0)
150 u2 _contention_group; // index from @Contended group item (or 0)
151
152 public:
153
154 FieldInfo() : _index(0),
155 _name_index(0),
156 _signature_index(0),
157 _offset(0),
158 _access_flags(AccessFlags(0)),
159 _field_flags(FieldFlags(0)),
160 _layout_kind(LayoutKind::UNKNOWN),
161 _null_marker_offset(0),
162 _initializer_index(0),
163 _generic_signature_index(0),
164 _contention_group(0) { }
165
166 FieldInfo(AccessFlags access_flags, u2 name_index, u2 signature_index, u2 initval_index, FieldInfo::FieldFlags fflags) :
167 _index(0),
168 _name_index(name_index),
169 _signature_index(signature_index),
170 _offset(0),
171 _access_flags(access_flags),
172 _field_flags(fflags),
173 _layout_kind(LayoutKind::UNKNOWN),
174 _null_marker_offset(0),
175 _initializer_index(initval_index),
176 _generic_signature_index(0),
177 _contention_group(0) {
178 if (initval_index != 0) {
179 _field_flags.update_initialized(true);
180 }
181 }
182
183 u4 index() const { return _index; }
184 void set_index(u4 index) { _index = index; }
185 u2 name_index() const { return _name_index; }
186 void set_name_index(u2 index) { _name_index = index; }
187 u2 signature_index() const { return _signature_index; }
188 void set_signature_index(u2 index) { _signature_index = index; }
189 u4 offset() const { return _offset; }
190 void set_offset(u4 offset) { _offset = offset; }
191 AccessFlags access_flags() const { return _access_flags; }
192 FieldFlags field_flags() const { return _field_flags; }
193 FieldFlags* field_flags_addr() { return &_field_flags; }
194 LayoutKind layout_kind() const { return _layout_kind; }
195 void set_layout_kind(LayoutKind lk) {
196 assert(_field_flags.is_flat(), "Must be");
197 _layout_kind = lk;
198 }
199 u4 null_marker_offset() const { return _null_marker_offset; }
200 void set_null_marker_offset(u4 offset) {
201 _field_flags.update_null_marker(true);
202 _null_marker_offset = offset;
203 }
204 u2 initializer_index() const { return _initializer_index; }
205 void set_initializer_index(u2 index) { _initializer_index = index; }
206 u2 generic_signature_index() const { return _generic_signature_index; }
207 void set_generic_signature_index(u2 index) { _generic_signature_index = index; }
208 u2 contention_group() const { return _contention_group; }
209
210 bool is_contended() const {
211 return _field_flags.is_contended();
212 }
213
214 u2 contended_group() const {
215 assert(is_contended(), "");
216 return _contention_group;
217 }
218
219 void set_contended_group(u2 group) {
220 _field_flags.update_contended(true);
221 _contention_group = group;
222 }
223
307 public:
308 static int num_java_fields(const Array<u1>* fis);
309 static int num_injected_java_fields(const Array<u1>* fis);
310 static int num_total_fields(const Array<u1>* fis);
311
312 static Array<u1>* create_FieldInfoStream(GrowableArray<FieldInfo>* fields, int java_fields, int injected_fields,
313 ClassLoaderData* loader_data, TRAPS);
314 static Array<u1>* create_search_table(ConstantPool* cp, const Array<u1>* fis, ClassLoaderData* loader_data, TRAPS);
315 static GrowableArray<FieldInfo>* create_FieldInfoArray(const Array<u1>* fis, int* java_fields_count, int* injected_fields_count);
316 static void print_from_fieldinfo_stream(Array<u1>* fis, outputStream* os, ConstantPool* cp);
317
318 DEBUG_ONLY(static void validate_search_table(ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);)
319
320 static void print_search_table(outputStream* st, ConstantPool* cp, const Array<u1>* fis, const Array<u1>* search_table);
321 };
322
323 class FieldStatus {
324 enum FieldStatusBitPosition {
325 _fs_access_watched, // field access is watched by JVMTI
326 _fs_modification_watched, // field modification is watched by JVMTI
327 _fs_strict_static_unset, // JVM_ACC_STRICT static field has not yet been set
328 _fs_strict_static_unread, // SS field has not yet been read
329 _initialized_final_update // (static) final field updated outside (class) initializer
330 };
331
332 // boilerplate:
333 u1 _flags;
334 static constexpr u1 flag_mask(FieldStatusBitPosition pos) { return (u1)1 << (int)pos; }
335 bool test_flag(FieldStatusBitPosition pos) { return (_flags & flag_mask(pos)) != 0; }
336 // this performs an atomic update on a live status byte!
337 void update_flag(FieldStatusBitPosition pos, bool z);
338 // out-of-line functions do a CAS-loop
339 static void atomic_set_bits(u1& flags, u1 mask);
340 static void atomic_clear_bits(u1& flags, u1 mask);
341
342 public:
343 FieldStatus() { _flags = 0; }
344 FieldStatus(u1 flags) { _flags = flags; }
345 u1 as_uint() { return _flags; }
346
347 bool is_access_watched() { return test_flag(_fs_access_watched); }
348 bool is_modification_watched() { return test_flag(_fs_modification_watched); }
349 bool is_strict_static_unset() { return test_flag(_fs_strict_static_unset); }
350 bool is_strict_static_unread() { return test_flag(_fs_strict_static_unread); }
351 bool is_initialized_final_update() { return test_flag(_initialized_final_update); }
352
353 void update_access_watched(bool z);
354 void update_modification_watched(bool z);
355 void update_strict_static_unset(bool z);
356 void update_strict_static_unread(bool z);
357 void update_initialized_final_update(bool z);
358 };
359
360 #endif // SHARE_OOPS_FIELDINFO_HPP
|