1 /*
2 * Copyright (c) 1997, 2025, 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_CLASSFILE_CLASSFILEPARSER_HPP
26 #define SHARE_CLASSFILE_CLASSFILEPARSER_HPP
27
28 #include "memory/referenceType.hpp"
29 #include "oops/annotations.hpp"
30 #include "oops/constantPool.hpp"
31 #include "oops/fieldInfo.hpp"
32 #include "oops/instanceKlass.hpp"
33 #include "oops/typeArrayOop.hpp"
34 #include "utilities/accessFlags.hpp"
35
36 class Annotations;
37 template <typename T>
38 class Array;
39 class ClassFileStream;
40 class ClassLoaderData;
41 class ClassLoadInfo;
42 class ClassInstanceInfo;
43 class CompressedLineNumberWriteStream;
44 class ConstMethod;
45 class FieldInfo;
46 template <typename T>
47 class GrowableArray;
48 class InstanceKlass;
49 class RecordComponent;
50 class Symbol;
51 class FieldLayoutBuilder;
52
53 // Utility to collect and compact oop maps during layout
54 class OopMapBlocksBuilder : public ResourceObj {
55 public:
56 OopMapBlock* _nonstatic_oop_maps;
57 unsigned int _nonstatic_oop_map_count;
58 unsigned int _max_nonstatic_oop_maps;
59
60 OopMapBlocksBuilder(unsigned int max_blocks);
61 OopMapBlock* last_oop_map() const;
62 void initialize_inherited_blocks(OopMapBlock* blocks, unsigned int nof_blocks);
63 void add(int offset, int count);
64 void copy(OopMapBlock* dst);
65 void compact();
66 void print_on(outputStream* st) const;
67 void print_value_on(outputStream* st) const;
68 };
69
70 // Values needed for oopmap and InstanceKlass creation
71 class FieldLayoutInfo : public ResourceObj {
72 public:
73 OopMapBlocksBuilder* oop_map_blocks;
74 int _instance_size;
75 int _nonstatic_field_size;
76 int _static_field_size;
77 bool _has_nonstatic_fields;
78 };
79
80 // Parser for for .class files
81 //
82 // The bytes describing the class file structure is read from a Stream object
83
84 class ClassFileParser {
85 friend class FieldLayoutBuilder;
86 friend class FieldLayout;
87
88 class ClassAnnotationCollector;
89 class FieldAnnotationCollector;
90
91 public:
92 // The ClassFileParser has an associated "publicity" level
93 // It is used to control which subsystems (if any)
94 // will observe the parsing (logging, events, tracing).
95 // Default level is "BROADCAST", which is equivalent to
96 // a "public" parsing attempt.
97 //
113 Symbol* _class_name;
114 mutable ClassLoaderData* _loader_data;
115 const bool _is_hidden;
116 const bool _can_access_vm_annotations;
117 int _orig_cp_size;
118 unsigned int _static_oop_count;
119
120 // Metadata created before the instance klass is created. Must be deallocated
121 // if not transferred to the InstanceKlass upon successful class loading
122 // in which case these pointers have been set to null.
123 const InstanceKlass* _super_klass;
124 ConstantPool* _cp;
125 Array<u1>* _fieldinfo_stream;
126 Array<u1>* _fieldinfo_search_table;
127 Array<FieldStatus>* _fields_status;
128 Array<Method*>* _methods;
129 Array<u2>* _inner_classes;
130 Array<u2>* _nest_members;
131 u2 _nest_host;
132 Array<u2>* _permitted_subclasses;
133 Array<RecordComponent*>* _record_components;
134 Array<InstanceKlass*>* _local_interfaces;
135 Array<InstanceKlass*>* _transitive_interfaces;
136 Annotations* _combined_annotations;
137 AnnotationArray* _class_annotations;
138 AnnotationArray* _class_type_annotations;
139 Array<AnnotationArray*>* _fields_annotations;
140 Array<AnnotationArray*>* _fields_type_annotations;
141 InstanceKlass* _klass; // InstanceKlass* once created.
142 InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
143
144 ClassAnnotationCollector* _parsed_annotations;
145 FieldLayoutInfo* _field_info;
146 GrowableArray<FieldInfo>* _temp_field_info;
147 const intArray* _method_ordering;
148 GrowableArray<Method*>* _all_mirandas;
149
150 enum { fixed_buffer_size = 128 };
151 u_char _linenumbertable_buffer[fixed_buffer_size];
152
153 // Size of Java vtable (in words)
154 int _vtable_size;
155 int _itable_size;
156
157 int _num_miranda_methods;
158
159 Handle _protection_domain;
160 AccessFlags _access_flags;
161
162 // for tracing and notifications
163 Publicity _pub_level;
164
165 // Used to keep track of whether a constant pool item 19 or 20 is found. These
166 // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
167 // in regular class files. For class file version >= 53, a CFE cannot be thrown
168 // immediately when these are seen because a NCDFE must be thrown if the class's
169 // access_flags have ACC_MODULE set. But, the access_flags haven't been looked
170 // at yet. So, the bad constant pool item is cached here. A value of zero
171 // means that no constant pool item 19 or 20 was found.
172 short _bad_constant_seen;
173
174 // class attributes parsed before the instance klass is created:
175 bool _synthetic_flag;
176 int _sde_length;
177 const char* _sde_buffer;
178 u2 _sourcefile_index;
179 u2 _generic_signature_index;
180
181 u2 _major_version;
182 u2 _minor_version;
183 u2 _this_class_index;
184 u2 _super_class_index;
185 u2 _itfs_len;
186 u2 _java_fields_count;
187
188 bool _need_verify;
189
190 bool _has_nonstatic_concrete_methods;
191 bool _declares_nonstatic_concrete_methods;
192 bool _has_localvariable_table;
193 bool _has_final_method;
194 bool _has_contended_fields;
195 bool _has_aot_runtime_setup_method;
196
197 // precomputed flags
198 bool _has_finalizer;
199 bool _has_empty_finalizer;
200 int _max_bootstrap_specifier_index; // detects BSS values
201
202 void parse_stream(const ClassFileStream* const stream, TRAPS);
203
204 void mangle_hidden_class_name(InstanceKlass* const ik);
205
206 void post_process_parsed_stream(const ClassFileStream* const stream,
207 ConstantPool* cp,
208 TRAPS);
209
210 void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH,
211 const ClassInstanceInfo& cl_inst_info, TRAPS);
212
213 void set_klass(InstanceKlass* instance);
214
215 void set_class_bad_constant_seen(short bad_constant);
216 short class_bad_constant_seen() { return _bad_constant_seen; }
217 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
218 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
219 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
220 void set_class_sde_buffer(const char* x, int len) { _sde_buffer = x; _sde_length = len; }
221
222 void create_combined_annotations(TRAPS);
223 void apply_parsed_class_attributes(InstanceKlass* k); // update k
224 void apply_parsed_class_metadata(InstanceKlass* k, int fields_count);
225 void clear_class_metadata();
226
227 // Constant pool parsing
228 void parse_constant_pool_entries(const ClassFileStream* const stream,
229 ConstantPool* cp,
230 const int length,
231 TRAPS);
232
233 void parse_constant_pool(const ClassFileStream* const cfs,
234 ConstantPool* const cp,
242 bool* has_nonstatic_concrete_methods,
243 TRAPS);
244
245 void check_super_class(ConstantPool* const cp,
246 const int super_class_index,
247 const bool need_verify,
248 TRAPS);
249
250 // Field parsing
251 void parse_field_attributes(const ClassFileStream* const cfs,
252 u2 attributes_count,
253 bool is_static,
254 u2 signature_index,
255 u2* const constantvalue_index_addr,
256 bool* const is_synthetic_addr,
257 u2* const generic_signature_index_addr,
258 FieldAnnotationCollector* parsed_annotations,
259 TRAPS);
260
261 void parse_fields(const ClassFileStream* const cfs,
262 bool is_interface,
263 ConstantPool* cp,
264 const int cp_size,
265 u2* const java_fields_count_ptr,
266 TRAPS);
267
268 // Method parsing
269 Method* parse_method(const ClassFileStream* const cfs,
270 bool is_interface,
271 const ConstantPool* cp,
272 bool* const has_localvariable_table,
273 TRAPS);
274
275 void parse_methods(const ClassFileStream* const cfs,
276 bool is_interface,
277 bool* const has_localvariable_table,
278 bool* const has_final_method,
279 bool* const declares_nonstatic_concrete_methods,
280 TRAPS);
281
282 const unsafe_u2* parse_exception_table(const ClassFileStream* const stream,
283 u4 code_length,
284 u4 exception_table_length,
285 TRAPS);
286
287 void parse_linenumber_table(u4 code_attribute_length,
288 u4 code_length,
289 CompressedLineNumberWriteStream**const write_stream,
290 TRAPS);
291
292 const unsafe_u2* parse_localvariable_table(const ClassFileStream* const cfs,
293 u4 code_length,
294 u2 max_locals,
295 u4 code_attribute_length,
296 u2* const localvariable_table_length,
311
312 // Check for circularity in InnerClasses attribute.
313 bool check_inner_classes_circularity(const ConstantPool* cp, int length, TRAPS);
314
315 u2 parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs,
316 const ConstantPool* cp,
317 const u1* const inner_classes_attribute_start,
318 bool parsed_enclosingmethod_attribute,
319 u2 enclosing_method_class_index,
320 u2 enclosing_method_method_index,
321 TRAPS);
322
323 u2 parse_classfile_nest_members_attribute(const ClassFileStream* const cfs,
324 const u1* const nest_members_attribute_start,
325 TRAPS);
326
327 u2 parse_classfile_permitted_subclasses_attribute(const ClassFileStream* const cfs,
328 const u1* const permitted_subclasses_attribute_start,
329 TRAPS);
330
331 u4 parse_classfile_record_attribute(const ClassFileStream* const cfs,
332 const ConstantPool* cp,
333 const u1* const record_attribute_start,
334 TRAPS);
335
336 void parse_classfile_attributes(const ClassFileStream* const cfs,
337 ConstantPool* cp,
338 ClassAnnotationCollector* parsed_annotations,
339 TRAPS);
340
341 void parse_classfile_synthetic_attribute();
342 void parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS);
343 void parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs,
344 ConstantPool* cp,
345 u4 attribute_length,
346 TRAPS);
347
348 // Annotations handling
349 AnnotationArray* allocate_annotations(const u1* const anno,
350 int anno_length,
403 const char *name,
404 TRAPS) const {
405 if (!b) { classfile_parse_error(msg, index, name, THREAD); return; }
406 }
407
408 void throwIllegalSignature(const char* type,
409 const Symbol* name,
410 const Symbol* sig,
411 TRAPS) const;
412
413 void verify_constantvalue(const ConstantPool* const cp,
414 int constantvalue_index,
415 int signature_index,
416 TRAPS) const;
417
418 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
419 void verify_legal_class_name(const Symbol* name, TRAPS) const;
420 void verify_legal_field_name(const Symbol* name, TRAPS) const;
421 void verify_legal_method_name(const Symbol* name, TRAPS) const;
422
423 void verify_legal_field_signature(const Symbol* fieldname,
424 const Symbol* signature,
425 TRAPS) const;
426 int verify_legal_method_signature(const Symbol* methodname,
427 const Symbol* signature,
428 TRAPS) const;
429 void verify_legal_name_with_signature(const Symbol* name,
430 const Symbol* signature,
431 TRAPS) const;
432
433 void verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS);
434
435 void verify_legal_class_modifiers(jint flags, Symbol* inner_name,
436 bool is_anonymous_inner_class, TRAPS) const;
437 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS) const;
438 void verify_legal_method_modifiers(jint flags,
439 bool is_interface,
440 const Symbol* name,
441 TRAPS) const;
442
443 void check_super_class_access(const InstanceKlass* this_klass,
444 TRAPS);
445
446 void check_super_interface_access(const InstanceKlass* this_klass,
447 TRAPS);
448
449 const char* skip_over_field_signature(const char* signature,
450 bool void_ok,
451 unsigned int length,
452 TRAPS) const;
453
454 // Wrapper for constantTag.is_klass_[or_]reference.
455 // In older versions of the VM, Klass*s cannot sneak into early phases of
456 // constant pool construction, but in later versions they can.
457 // %%% Let's phase out the old is_klass_reference.
458 bool valid_klass_reference_at(int index) const {
459 return _cp->is_within_bounds(index) &&
471 u2* const localvariable_table_length,
472 const unsafe_u2** const localvariable_table_start,
473 int lvtt_cnt,
474 u2* const localvariable_type_table_length,
475 const unsafe_u2** const localvariable_type_table_start,
476 TRAPS);
477
478 void copy_method_annotations(ConstMethod* cm,
479 const u1* runtime_visible_annotations,
480 int runtime_visible_annotations_length,
481 const u1* runtime_visible_parameter_annotations,
482 int runtime_visible_parameter_annotations_length,
483 const u1* runtime_visible_type_annotations,
484 int runtime_visible_type_annotations_length,
485 const u1* annotation_default,
486 int annotation_default_length,
487 TRAPS);
488
489 void update_class_name(Symbol* new_name);
490
491 public:
492 ClassFileParser(ClassFileStream* stream,
493 Symbol* name,
494 ClassLoaderData* loader_data,
495 const ClassLoadInfo* cl_info,
496 Publicity pub_level,
497 TRAPS);
498
499 ~ClassFileParser();
500
501 InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, const ClassInstanceInfo& cl_inst_info, TRAPS);
502
503 const ClassFileStream& stream() const { return *_stream; }
504
505 const ClassFileStream* clone_stream() const;
506
507 void set_klass_to_deallocate(InstanceKlass* klass);
508
509 int static_field_size() const;
510 int total_oop_map_count() const;
511 jint layout_size() const;
512
513 int vtable_size() const { return _vtable_size; }
514 int itable_size() const { return _itable_size; }
515
516 u2 this_class_index() const { return _this_class_index; }
517
518 bool is_hidden() const { return _is_hidden; }
519 bool is_interface() const { return _access_flags.is_interface(); }
520
521 ClassLoaderData* loader_data() const { return _loader_data; }
522 const Symbol* class_name() const { return _class_name; }
523 const InstanceKlass* super_klass() const { return _super_klass; }
524
525 ReferenceType super_reference_type() const;
526 bool is_instance_ref_klass() const;
527 bool is_java_lang_ref_Reference_subclass() const;
528
529 AccessFlags access_flags() const { return _access_flags; }
530
531 bool is_internal() const { return INTERNAL == _pub_level; }
532
533 static bool verify_unqualified_name(const char* name, unsigned int length, int type);
534
535 #ifdef ASSERT
536 static bool is_internal_format(Symbol* class_name);
537 #endif
538
539 };
540
541 #endif // SHARE_CLASSFILE_CLASSFILEPARSER_HPP
|
1 /*
2 * Copyright (c) 1997, 2026, 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_CLASSFILE_CLASSFILEPARSER_HPP
26 #define SHARE_CLASSFILE_CLASSFILEPARSER_HPP
27
28 #include "memory/referenceType.hpp"
29 #include "oops/annotations.hpp"
30 #include "oops/constantPool.hpp"
31 #include "oops/fieldInfo.hpp"
32 #include "oops/instanceKlass.hpp"
33 #include "oops/typeArrayOop.hpp"
34 #include "utilities/accessFlags.hpp"
35 #include "utilities/pair.hpp"
36
37 class Annotations;
38 template <typename T>
39 class Array;
40 class ClassFileStream;
41 class ClassLoaderData;
42 class ClassLoadInfo;
43 class ClassInstanceInfo;
44 class CompressedLineNumberWriteStream;
45 class ConstMethod;
46 class FieldInfo;
47 template <typename T>
48 class GrowableArray;
49 class InstanceKlass;
50 class RecordComponent;
51 class Symbol;
52 class FieldLayoutBuilder;
53
54 // Utility to collect and compact oop maps during layout
55 class OopMapBlocksBuilder : public ResourceObj {
56 public:
57 OopMapBlock* _nonstatic_oop_maps;
58 unsigned int _nonstatic_oop_map_count;
59 unsigned int _max_nonstatic_oop_maps;
60
61 OopMapBlocksBuilder(unsigned int max_blocks);
62 OopMapBlock* last_oop_map() const;
63 void initialize_inherited_blocks(OopMapBlock* blocks, unsigned int nof_blocks);
64 void add(int offset, int count);
65 void copy(OopMapBlock* dst);
66 void compact();
67 void print_on(outputStream* st) const;
68 void print_value_on(outputStream* st) const;
69 };
70
71 // Values needed for oopmap and InstanceKlass creation
72 class FieldLayoutInfo : public ResourceObj {
73 public:
74 OopMapBlocksBuilder* oop_map_blocks;
75 GrowableArray<Pair<int,int>>* _nonoop_acmp_map;
76 GrowableArray<int>* _oop_acmp_map;
77 int _instance_size;
78 int _nonstatic_field_size;
79 int _static_field_size;
80 int _payload_alignment;
81 int _payload_offset;
82 int _payload_size_in_bytes;
83 int _null_free_non_atomic_size_in_bytes;
84 int _null_free_non_atomic_alignment;
85 int _null_free_atomic_layout_size_in_bytes;
86 int _nullable_atomic_layout_size_in_bytes;
87 int _nullable_non_atomic_layout_size_in_bytes;
88 int _null_marker_offset;
89 int _null_reset_value_offset;
90 int _acmp_maps_offset;
91 bool _has_nonstatic_fields;
92 bool _is_naturally_atomic;
93 bool _must_be_atomic;
94 bool _has_inlined_fields;
95 bool _is_empty_inline_klass;
96 FieldLayoutInfo() : oop_map_blocks(nullptr), _nonoop_acmp_map(nullptr), _oop_acmp_map(nullptr),
97 _instance_size(-1), _nonstatic_field_size(-1), _static_field_size(-1),
98 _payload_alignment(-1), _payload_offset(-1), _payload_size_in_bytes(-1),
99 _null_free_non_atomic_size_in_bytes(-1), _null_free_non_atomic_alignment(-1),
100 _null_free_atomic_layout_size_in_bytes(-1), _nullable_atomic_layout_size_in_bytes(-1),
101 _nullable_non_atomic_layout_size_in_bytes(-1),
102 _null_marker_offset(-1), _null_reset_value_offset(-1), _acmp_maps_offset(-1),
103 _has_nonstatic_fields(false), _is_naturally_atomic(false), _must_be_atomic(false),
104 _has_inlined_fields(false), _is_empty_inline_klass(false) { }
105 };
106
107 // Parser for for .class files
108 //
109 // The bytes describing the class file structure is read from a Stream object
110
111 class ClassFileParser {
112 friend class FieldLayoutBuilder;
113 friend class FieldLayout;
114
115 class ClassAnnotationCollector;
116 class FieldAnnotationCollector;
117
118 public:
119 // The ClassFileParser has an associated "publicity" level
120 // It is used to control which subsystems (if any)
121 // will observe the parsing (logging, events, tracing).
122 // Default level is "BROADCAST", which is equivalent to
123 // a "public" parsing attempt.
124 //
140 Symbol* _class_name;
141 mutable ClassLoaderData* _loader_data;
142 const bool _is_hidden;
143 const bool _can_access_vm_annotations;
144 int _orig_cp_size;
145 unsigned int _static_oop_count;
146
147 // Metadata created before the instance klass is created. Must be deallocated
148 // if not transferred to the InstanceKlass upon successful class loading
149 // in which case these pointers have been set to null.
150 const InstanceKlass* _super_klass;
151 ConstantPool* _cp;
152 Array<u1>* _fieldinfo_stream;
153 Array<u1>* _fieldinfo_search_table;
154 Array<FieldStatus>* _fields_status;
155 Array<Method*>* _methods;
156 Array<u2>* _inner_classes;
157 Array<u2>* _nest_members;
158 u2 _nest_host;
159 Array<u2>* _permitted_subclasses;
160 Array<u2>* _loadable_descriptors;
161 Array<RecordComponent*>* _record_components;
162 Array<InstanceKlass*>* _local_interfaces;
163 GrowableArray<u2>* _local_interface_indexes;
164 Array<InstanceKlass*>* _transitive_interfaces;
165 Annotations* _combined_annotations;
166 AnnotationArray* _class_annotations;
167 AnnotationArray* _class_type_annotations;
168 Array<AnnotationArray*>* _fields_annotations;
169 Array<AnnotationArray*>* _fields_type_annotations;
170 InstanceKlass* _klass; // InstanceKlass* once created.
171 InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
172
173 ClassAnnotationCollector* _parsed_annotations;
174 FieldLayoutInfo* _layout_info;
175 Array<InlineLayoutInfo>* _inline_layout_info_array;
176 GrowableArray<FieldInfo>* _temp_field_info;
177 const intArray* _method_ordering;
178 GrowableArray<Method*>* _all_mirandas;
179
180 enum { fixed_buffer_size = 128 };
181 u_char _linenumbertable_buffer[fixed_buffer_size];
182
183 // Size of Java vtable (in words)
184 int _vtable_size;
185 int _itable_size;
186
187 int _num_miranda_methods;
188
189
190 Handle _protection_domain;
191 AccessFlags _access_flags;
192
193 // for tracing and notifications
194 Publicity _pub_level;
195
196 // Used to keep track of whether a constant pool item 19 or 20 is found. These
197 // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
198 // in regular class files. For class file version >= 53, a CFE cannot be thrown
199 // immediately when these are seen because a NCDFE must be thrown if the class's
200 // access_flags have ACC_MODULE set. But, the access_flags haven't been looked
201 // at yet. So, the bad constant pool item is cached here. A value of zero
202 // means that no constant pool item 19 or 20 was found.
203 short _bad_constant_seen;
204
205 // class attributes parsed before the instance klass is created:
206 bool _synthetic_flag;
207 int _sde_length;
208 const char* _sde_buffer;
209 u2 _sourcefile_index;
210 u2 _generic_signature_index;
211
212 u2 _major_version;
213 u2 _minor_version;
214 u2 _this_class_index;
215 u2 _super_class_index;
216 u2 _itfs_len;
217 u2 _java_fields_count;
218
219 bool _need_verify;
220
221 bool _has_nonstatic_concrete_methods;
222 bool _declares_nonstatic_concrete_methods;
223 bool _has_localvariable_table;
224 bool _has_final_method;
225 bool _has_contended_fields;
226 bool _has_aot_runtime_setup_method;
227 bool _has_strict_static_fields;
228
229 bool _is_naturally_atomic;
230 bool _must_be_atomic;
231 bool _has_loosely_consistent_annotation;
232
233 // precomputed flags
234 bool _has_finalizer;
235 bool _has_empty_finalizer;
236 int _max_bootstrap_specifier_index; // detects BSS values
237
238 void parse_stream(const ClassFileStream* const stream, TRAPS);
239
240 void mangle_hidden_class_name(InstanceKlass* const ik);
241
242 void post_process_parsed_stream(const ClassFileStream* const stream,
243 ConstantPool* cp,
244 TRAPS);
245 void fetch_field_classes(ConstantPool* cp, TRAPS);
246
247 void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH,
248 const ClassInstanceInfo& cl_inst_info, TRAPS);
249
250 void set_klass(InstanceKlass* instance);
251
252 void set_inline_layout_info_klass(int field_index, InlineKlass* ik, TRAPS);
253
254 void set_class_bad_constant_seen(short bad_constant);
255 short class_bad_constant_seen() { return _bad_constant_seen; }
256 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
257 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
258 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
259 void set_class_sde_buffer(const char* x, int len) { _sde_buffer = x; _sde_length = len; }
260
261 void create_combined_annotations(TRAPS);
262 void apply_parsed_class_attributes(InstanceKlass* k); // update k
263 void apply_parsed_class_metadata(InstanceKlass* k, int fields_count);
264 void clear_class_metadata();
265
266 // Constant pool parsing
267 void parse_constant_pool_entries(const ClassFileStream* const stream,
268 ConstantPool* cp,
269 const int length,
270 TRAPS);
271
272 void parse_constant_pool(const ClassFileStream* const cfs,
273 ConstantPool* const cp,
281 bool* has_nonstatic_concrete_methods,
282 TRAPS);
283
284 void check_super_class(ConstantPool* const cp,
285 const int super_class_index,
286 const bool need_verify,
287 TRAPS);
288
289 // Field parsing
290 void parse_field_attributes(const ClassFileStream* const cfs,
291 u2 attributes_count,
292 bool is_static,
293 u2 signature_index,
294 u2* const constantvalue_index_addr,
295 bool* const is_synthetic_addr,
296 u2* const generic_signature_index_addr,
297 FieldAnnotationCollector* parsed_annotations,
298 TRAPS);
299
300 void parse_fields(const ClassFileStream* const cfs,
301 AccessFlags class_access_flags,
302 ConstantPool* cp,
303 const int cp_size,
304 u2* const java_fields_count_ptr,
305 TRAPS);
306
307 // Method parsing
308 Method* parse_method(const ClassFileStream* const cfs,
309 bool is_interface,
310 bool is_value_class,
311 bool is_abstract_class,
312 const ConstantPool* cp,
313 bool* const has_localvariable_table,
314 TRAPS);
315
316 void parse_methods(const ClassFileStream* const cfs,
317 bool is_interface,
318 bool is_value_class,
319 bool is_abstract_class,
320 bool* const has_localvariable_table,
321 bool* const has_final_method,
322 bool* const declares_nonstatic_concrete_methods,
323 TRAPS);
324
325 const unsafe_u2* parse_exception_table(const ClassFileStream* const stream,
326 u4 code_length,
327 u4 exception_table_length,
328 TRAPS);
329
330 void parse_linenumber_table(u4 code_attribute_length,
331 u4 code_length,
332 CompressedLineNumberWriteStream**const write_stream,
333 TRAPS);
334
335 const unsafe_u2* parse_localvariable_table(const ClassFileStream* const cfs,
336 u4 code_length,
337 u2 max_locals,
338 u4 code_attribute_length,
339 u2* const localvariable_table_length,
354
355 // Check for circularity in InnerClasses attribute.
356 bool check_inner_classes_circularity(const ConstantPool* cp, int length, TRAPS);
357
358 u2 parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs,
359 const ConstantPool* cp,
360 const u1* const inner_classes_attribute_start,
361 bool parsed_enclosingmethod_attribute,
362 u2 enclosing_method_class_index,
363 u2 enclosing_method_method_index,
364 TRAPS);
365
366 u2 parse_classfile_nest_members_attribute(const ClassFileStream* const cfs,
367 const u1* const nest_members_attribute_start,
368 TRAPS);
369
370 u2 parse_classfile_permitted_subclasses_attribute(const ClassFileStream* const cfs,
371 const u1* const permitted_subclasses_attribute_start,
372 TRAPS);
373
374 u2 parse_classfile_loadable_descriptors_attribute(const ClassFileStream* const cfs,
375 const u1* const loadable_descriptors_attribute_start,
376 TRAPS);
377
378 u4 parse_classfile_record_attribute(const ClassFileStream* const cfs,
379 const ConstantPool* cp,
380 const u1* const record_attribute_start,
381 TRAPS);
382
383 void parse_classfile_attributes(const ClassFileStream* const cfs,
384 ConstantPool* cp,
385 ClassAnnotationCollector* parsed_annotations,
386 TRAPS);
387
388 void parse_classfile_synthetic_attribute();
389 void parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS);
390 void parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs,
391 ConstantPool* cp,
392 u4 attribute_length,
393 TRAPS);
394
395 // Annotations handling
396 AnnotationArray* allocate_annotations(const u1* const anno,
397 int anno_length,
450 const char *name,
451 TRAPS) const {
452 if (!b) { classfile_parse_error(msg, index, name, THREAD); return; }
453 }
454
455 void throwIllegalSignature(const char* type,
456 const Symbol* name,
457 const Symbol* sig,
458 TRAPS) const;
459
460 void verify_constantvalue(const ConstantPool* const cp,
461 int constantvalue_index,
462 int signature_index,
463 TRAPS) const;
464
465 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
466 void verify_legal_class_name(const Symbol* name, TRAPS) const;
467 void verify_legal_field_name(const Symbol* name, TRAPS) const;
468 void verify_legal_method_name(const Symbol* name, TRAPS) const;
469
470 bool legal_field_signature(const Symbol* signature, TRAPS) const;
471
472 void verify_legal_field_signature(const Symbol* fieldname,
473 const Symbol* signature,
474 TRAPS) const;
475 int verify_legal_method_signature(const Symbol* methodname,
476 const Symbol* signature,
477 TRAPS) const;
478 void verify_legal_name_with_signature(const Symbol* name,
479 const Symbol* signature,
480 TRAPS) const;
481
482 void verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS);
483
484 void verify_legal_class_modifiers(jint flags, Symbol* inner_name,
485 bool is_anonymous_inner_class, TRAPS) const;
486 void verify_legal_field_modifiers(jint flags, AccessFlags class_access_flags, TRAPS) const;
487 void verify_legal_method_modifiers(jint flags,
488 AccessFlags class_access_flags,
489 const Symbol* name,
490 TRAPS) const;
491
492 void check_super_class_access(const InstanceKlass* this_klass,
493 TRAPS);
494
495 void check_super_interface_access(const InstanceKlass* this_klass,
496 TRAPS);
497
498 const char* skip_over_field_signature(const char* signature,
499 bool void_ok,
500 unsigned int length,
501 TRAPS) const;
502
503 // Wrapper for constantTag.is_klass_[or_]reference.
504 // In older versions of the VM, Klass*s cannot sneak into early phases of
505 // constant pool construction, but in later versions they can.
506 // %%% Let's phase out the old is_klass_reference.
507 bool valid_klass_reference_at(int index) const {
508 return _cp->is_within_bounds(index) &&
520 u2* const localvariable_table_length,
521 const unsafe_u2** const localvariable_table_start,
522 int lvtt_cnt,
523 u2* const localvariable_type_table_length,
524 const unsafe_u2** const localvariable_type_table_start,
525 TRAPS);
526
527 void copy_method_annotations(ConstMethod* cm,
528 const u1* runtime_visible_annotations,
529 int runtime_visible_annotations_length,
530 const u1* runtime_visible_parameter_annotations,
531 int runtime_visible_parameter_annotations_length,
532 const u1* runtime_visible_type_annotations,
533 int runtime_visible_type_annotations_length,
534 const u1* annotation_default,
535 int annotation_default_length,
536 TRAPS);
537
538 void update_class_name(Symbol* new_name);
539
540 // Check if the class file supports inline types
541 bool supports_inline_types() const;
542
543 public:
544 ClassFileParser(ClassFileStream* stream,
545 Symbol* name,
546 ClassLoaderData* loader_data,
547 const ClassLoadInfo* cl_info,
548 Publicity pub_level,
549 TRAPS);
550
551 ~ClassFileParser();
552
553 InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, const ClassInstanceInfo& cl_inst_info, TRAPS);
554
555 const ClassFileStream& stream() const { return *_stream; }
556
557 const ClassFileStream* clone_stream() const;
558
559 void set_klass_to_deallocate(InstanceKlass* klass);
560
561 int static_field_size() const;
562 int total_oop_map_count() const;
563 jint layout_size() const;
564
565 int vtable_size() const { return _vtable_size; }
566 int itable_size() const { return _itable_size; }
567
568 u2 this_class_index() const { return _this_class_index; }
569
570 bool is_hidden() const { return _is_hidden; }
571 bool is_interface() const { return _access_flags.is_interface(); }
572 // Being an inline type means being a concrete value class
573 bool is_inline_type() const { return !_access_flags.is_identity_class() && !_access_flags.is_interface() && !_access_flags.is_abstract(); }
574 bool is_abstract_class() const { return _access_flags.is_abstract(); }
575 bool is_identity_class() const { return _access_flags.is_identity_class(); }
576 bool has_inlined_fields() const { return _layout_info->_has_inlined_fields; }
577
578 u2 java_fields_count() const { return _java_fields_count; }
579 bool is_abstract() const { return _access_flags.is_abstract(); }
580
581 ClassLoaderData* loader_data() const { return _loader_data; }
582 const Symbol* class_name() const { return _class_name; }
583 const InstanceKlass* super_klass() const { return _super_klass; }
584
585 ReferenceType super_reference_type() const;
586 bool is_instance_ref_klass() const;
587 bool is_java_lang_ref_Reference_subclass() const;
588
589 AccessFlags access_flags() const { return _access_flags; }
590
591 bool is_internal() const { return INTERNAL == _pub_level; }
592
593 bool is_class_in_loadable_descriptors_attribute(Symbol *klass);
594
595 static bool verify_unqualified_name(const char* name, unsigned int length, int type);
596
597 #ifdef ASSERT
598 static bool is_internal_format(Symbol* class_name);
599 #endif
600
601 };
602
603 #endif // SHARE_CLASSFILE_CLASSFILEPARSER_HPP
|