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/typeArrayOop.hpp"
32 #include "utilities/accessFlags.hpp"
33
34 class Annotations;
35 template <typename T>
36 class Array;
37 class ClassFileStream;
38 class ClassLoaderData;
39 class CompressedLineNumberWriteStream;
40 class ConstMethod;
41 class FieldInfo;
42 template <typename T>
43 class GrowableArray;
44 class InstanceKlass;
45 class Symbol;
46 class TempNewSymbol;
47
48 // Parser for for .class files
49 //
50 // The bytes describing the class file structure is read from a Stream object
51
52 class ClassFileParser {
53
54 class ClassAnnotationCollector;
55 class FieldAllocationCount;
56 class FieldAnnotationCollector;
57 class FieldLayoutInfo;
58
61 // It is used to control which subsystems (if any)
62 // will observe the parsing (logging, events, tracing).
63 // Default level is "BROADCAST", which is equivalent to
64 // a "public" parsing attempt.
65 //
66 // "INTERNAL" level should be entirely private to the
67 // caller - this allows for internal reuse of ClassFileParser
68 //
69 enum Publicity {
70 INTERNAL,
71 BROADCAST
72 };
73
74 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
75
76 private:
77 // Potentially unaligned pointer to various 16-bit entries in the class file
78 typedef void unsafe_u2;
79
80 const ClassFileStream* _stream; // Actual input stream
81 const Symbol* _requested_name;
82 Symbol* _class_name;
83 mutable ClassLoaderData* _loader_data;
84 const InstanceKlass* _unsafe_anonymous_host;
85 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
86 int _num_patched_klasses;
87 int _max_num_patched_klasses;
88 int _orig_cp_size;
89 int _first_patched_klass_resolved_index;
90
91 // Metadata created before the instance klass is created. Must be deallocated
92 // if not transferred to the InstanceKlass upon successful class loading
93 // in which case these pointers have been set to NULL.
94 const InstanceKlass* _super_klass;
95 ConstantPool* _cp;
96 Array<u2>* _fields;
97 Array<Method*>* _methods;
98 Array<u2>* _inner_classes;
99 Array<u2>* _nest_members;
100 u2 _nest_host;
101 Array<InstanceKlass*>* _local_interfaces;
102 Array<InstanceKlass*>* _transitive_interfaces;
103 Annotations* _combined_annotations;
104 AnnotationArray* _class_annotations;
105 AnnotationArray* _class_type_annotations;
158
159 bool _has_nonstatic_concrete_methods;
160 bool _declares_nonstatic_concrete_methods;
161 bool _has_final_method;
162
163 // precomputed flags
164 bool _has_finalizer;
165 bool _has_empty_finalizer;
166 bool _has_vanilla_constructor;
167 int _max_bootstrap_specifier_index; // detects BSS values
168
169 void parse_stream(const ClassFileStream* const stream, TRAPS);
170
171 void post_process_parsed_stream(const ClassFileStream* const stream,
172 ConstantPool* cp,
173 TRAPS);
174
175 void prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS);
176 void fix_unsafe_anonymous_class_name(TRAPS);
177
178 void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH, TRAPS);
179 void set_klass(InstanceKlass* instance);
180
181 void set_class_bad_constant_seen(short bad_constant);
182 short class_bad_constant_seen() { return _bad_constant_seen; }
183 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
184 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
185 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
186 void set_class_sde_buffer(const char* x, int len) { _sde_buffer = x; _sde_length = len; }
187
188 void create_combined_annotations(TRAPS);
189 void apply_parsed_class_attributes(InstanceKlass* k); // update k
190 void apply_parsed_class_metadata(InstanceKlass* k, int fields_count, TRAPS);
191 void clear_class_metadata();
192
193 // Constant pool parsing
194 void parse_constant_pool_entries(const ClassFileStream* const stream,
195 ConstantPool* cp,
196 const int length,
197 TRAPS);
198
470 int runtime_invisible_annotations_length,
471 const u1* runtime_visible_parameter_annotations,
472 int runtime_visible_parameter_annotations_length,
473 const u1* runtime_invisible_parameter_annotations,
474 int runtime_invisible_parameter_annotations_length,
475 const u1* runtime_visible_type_annotations,
476 int runtime_visible_type_annotations_length,
477 const u1* runtime_invisible_type_annotations,
478 int runtime_invisible_type_annotations_length,
479 const u1* annotation_default,
480 int annotation_default_length,
481 TRAPS);
482
483 // lays out fields in class and returns the total oopmap count
484 void layout_fields(ConstantPool* cp,
485 const FieldAllocationCount* fac,
486 const ClassAnnotationCollector* parsed_annotations,
487 FieldLayoutInfo* info,
488 TRAPS);
489
490 void update_class_name(Symbol* new_name);
491
492 public:
493 ClassFileParser(ClassFileStream* stream,
494 Symbol* name,
495 ClassLoaderData* loader_data,
496 Handle protection_domain,
497 const InstanceKlass* unsafe_anonymous_host,
498 GrowableArray<Handle>* cp_patches,
499 Publicity pub_level,
500 TRAPS);
501
502 ~ClassFileParser();
503
504 InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, TRAPS);
505
506 const ClassFileStream* clone_stream() const;
507
508 void set_klass_to_deallocate(InstanceKlass* klass);
509
510 int static_field_size() const;
511 int total_oop_map_count() const;
512 jint layout_size() const;
513
514 int vtable_size() const { return _vtable_size; }
515 int itable_size() const { return _itable_size; }
516
517 u2 this_class_index() const { return _this_class_index; }
518
519 bool is_unsafe_anonymous() const { return _unsafe_anonymous_host != NULL; }
520 bool is_interface() const { return _access_flags.is_interface(); }
521
522 const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; }
523 const GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
524 ClassLoaderData* loader_data() const { return _loader_data; }
525 const Symbol* class_name() const { return _class_name; }
526 const InstanceKlass* super_klass() const { return _super_klass; }
527
528 ReferenceType reference_type() const { return _rt; }
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 };
|
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/typeArrayOop.hpp"
32 #include "utilities/accessFlags.hpp"
33
34 class Annotations;
35 template <typename T>
36 class Array;
37 class ClassFileStream;
38 class ClassLoaderData;
39 class ClassInstanceInfo;
40 class CompressedLineNumberWriteStream;
41 class ConstMethod;
42 class FieldInfo;
43 template <typename T>
44 class GrowableArray;
45 class InstanceKlass;
46 class Symbol;
47 class TempNewSymbol;
48
49 // Parser for for .class files
50 //
51 // The bytes describing the class file structure is read from a Stream object
52
53 class ClassFileParser {
54
55 class ClassAnnotationCollector;
56 class FieldAllocationCount;
57 class FieldAnnotationCollector;
58 class FieldLayoutInfo;
59
62 // It is used to control which subsystems (if any)
63 // will observe the parsing (logging, events, tracing).
64 // Default level is "BROADCAST", which is equivalent to
65 // a "public" parsing attempt.
66 //
67 // "INTERNAL" level should be entirely private to the
68 // caller - this allows for internal reuse of ClassFileParser
69 //
70 enum Publicity {
71 INTERNAL,
72 BROADCAST
73 };
74
75 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
76
77 private:
78 // Potentially unaligned pointer to various 16-bit entries in the class file
79 typedef void unsafe_u2;
80
81 const ClassFileStream* _stream; // Actual input stream
82 Symbol* _class_name;
83 mutable ClassLoaderData* _loader_data;
84 const InstanceKlass* _unsafe_anonymous_host;
85 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
86 const bool _is_hidden;
87 const bool _can_access_vm_annotations;
88 int _num_patched_klasses;
89 int _max_num_patched_klasses;
90 int _orig_cp_size;
91 int _first_patched_klass_resolved_index;
92
93 // Metadata created before the instance klass is created. Must be deallocated
94 // if not transferred to the InstanceKlass upon successful class loading
95 // in which case these pointers have been set to NULL.
96 const InstanceKlass* _super_klass;
97 ConstantPool* _cp;
98 Array<u2>* _fields;
99 Array<Method*>* _methods;
100 Array<u2>* _inner_classes;
101 Array<u2>* _nest_members;
102 u2 _nest_host;
103 Array<InstanceKlass*>* _local_interfaces;
104 Array<InstanceKlass*>* _transitive_interfaces;
105 Annotations* _combined_annotations;
106 AnnotationArray* _class_annotations;
107 AnnotationArray* _class_type_annotations;
160
161 bool _has_nonstatic_concrete_methods;
162 bool _declares_nonstatic_concrete_methods;
163 bool _has_final_method;
164
165 // precomputed flags
166 bool _has_finalizer;
167 bool _has_empty_finalizer;
168 bool _has_vanilla_constructor;
169 int _max_bootstrap_specifier_index; // detects BSS values
170
171 void parse_stream(const ClassFileStream* const stream, TRAPS);
172
173 void post_process_parsed_stream(const ClassFileStream* const stream,
174 ConstantPool* cp,
175 TRAPS);
176
177 void prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS);
178 void fix_unsafe_anonymous_class_name(TRAPS);
179
180 void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH,
181 const ClassInstanceInfo& cl_inst_info, TRAPS);
182
183 void set_klass(InstanceKlass* instance);
184
185 void set_class_bad_constant_seen(short bad_constant);
186 short class_bad_constant_seen() { return _bad_constant_seen; }
187 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
188 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
189 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
190 void set_class_sde_buffer(const char* x, int len) { _sde_buffer = x; _sde_length = len; }
191
192 void create_combined_annotations(TRAPS);
193 void apply_parsed_class_attributes(InstanceKlass* k); // update k
194 void apply_parsed_class_metadata(InstanceKlass* k, int fields_count, TRAPS);
195 void clear_class_metadata();
196
197 // Constant pool parsing
198 void parse_constant_pool_entries(const ClassFileStream* const stream,
199 ConstantPool* cp,
200 const int length,
201 TRAPS);
202
474 int runtime_invisible_annotations_length,
475 const u1* runtime_visible_parameter_annotations,
476 int runtime_visible_parameter_annotations_length,
477 const u1* runtime_invisible_parameter_annotations,
478 int runtime_invisible_parameter_annotations_length,
479 const u1* runtime_visible_type_annotations,
480 int runtime_visible_type_annotations_length,
481 const u1* runtime_invisible_type_annotations,
482 int runtime_invisible_type_annotations_length,
483 const u1* annotation_default,
484 int annotation_default_length,
485 TRAPS);
486
487 // lays out fields in class and returns the total oopmap count
488 void layout_fields(ConstantPool* cp,
489 const FieldAllocationCount* fac,
490 const ClassAnnotationCollector* parsed_annotations,
491 FieldLayoutInfo* info,
492 TRAPS);
493
494 public:
495 ClassFileParser(ClassFileStream* stream,
496 Symbol* name,
497 ClassLoaderData* loader_data,
498 Handle protection_domain,
499 const InstanceKlass* unsafe_anonymous_host,
500 GrowableArray<Handle>* cp_patches,
501 const bool is_hidden,
502 const bool can_access_vm_annotations,
503 Publicity pub_level,
504 TRAPS);
505
506 ~ClassFileParser();
507
508 InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, const ClassInstanceInfo& cl_inst_info, TRAPS);
509
510 const ClassFileStream* clone_stream() const;
511
512 void set_klass_to_deallocate(InstanceKlass* klass);
513
514 int static_field_size() const;
515 int total_oop_map_count() const;
516 jint layout_size() const;
517
518 int vtable_size() const { return _vtable_size; }
519 int itable_size() const { return _itable_size; }
520
521 u2 this_class_index() const { return _this_class_index; }
522
523 bool is_unsafe_anonymous() const { return _unsafe_anonymous_host != NULL; }
524 bool is_hidden() const { return _is_hidden; }
525 bool is_interface() const { return _access_flags.is_interface(); }
526
527 const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; }
528 const GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
529 ClassLoaderData* loader_data() const { return _loader_data; }
530 const Symbol* class_name() const { return _class_name; }
531 const InstanceKlass* super_klass() const { return _super_klass; }
532
533 ReferenceType reference_type() const { return _rt; }
534 AccessFlags access_flags() const { return _access_flags; }
535
536 bool is_internal() const { return INTERNAL == _pub_level; }
537
538 static bool verify_unqualified_name(const char* name, unsigned int length, int type);
539
540 #ifdef ASSERT
541 static bool is_internal_format(Symbol* class_name);
542 #endif
543
544 };
|