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/instanceKlass.hpp"
32 #include "oops/typeArrayOop.hpp"
33 #include "utilities/accessFlags.hpp"
34
35 class Annotations;
36 template <typename T>
37 class Array;
38 class ClassFileStream;
39 class ClassLoaderData;
40 class CompressedLineNumberWriteStream;
41 class ConstMethod;
42 class FieldInfo;
43 template <typename T>
44 class GrowableArray;
45 class InstanceKlass;
46 class RecordComponent;
47 class Symbol;
48 class TempNewSymbol;
49 class FieldLayoutBuilder;
50
51 // Utility to collect and compact oop maps during layout
52 class OopMapBlocksBuilder : public ResourceObj {
53 public:
54 OopMapBlock* _nonstatic_oop_maps;
55 unsigned int _nonstatic_oop_map_count;
56 unsigned int _max_nonstatic_oop_maps;
57
58 OopMapBlocksBuilder(unsigned int max_blocks);
59 OopMapBlock* last_oop_map() const;
92 // It is used to control which subsystems (if any)
93 // will observe the parsing (logging, events, tracing).
94 // Default level is "BROADCAST", which is equivalent to
95 // a "public" parsing attempt.
96 //
97 // "INTERNAL" level should be entirely private to the
98 // caller - this allows for internal reuse of ClassFileParser
99 //
100 enum Publicity {
101 INTERNAL,
102 BROADCAST
103 };
104
105 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
106
107 private:
108 // Potentially unaligned pointer to various 16-bit entries in the class file
109 typedef void unsafe_u2;
110
111 const ClassFileStream* _stream; // Actual input stream
112 const Symbol* _requested_name;
113 Symbol* _class_name;
114 mutable ClassLoaderData* _loader_data;
115 const InstanceKlass* _unsafe_anonymous_host;
116 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
117 int _num_patched_klasses;
118 int _max_num_patched_klasses;
119 int _orig_cp_size;
120 int _first_patched_klass_resolved_index;
121
122 // Metadata created before the instance klass is created. Must be deallocated
123 // if not transferred to the InstanceKlass upon successful class loading
124 // in which case these pointers have been set to NULL.
125 const InstanceKlass* _super_klass;
126 ConstantPool* _cp;
127 Array<u2>* _fields;
128 Array<Method*>* _methods;
129 Array<u2>* _inner_classes;
130 Array<u2>* _nest_members;
131 u2 _nest_host;
132 Array<RecordComponent*>* _record_components;
133 Array<InstanceKlass*>* _local_interfaces;
134 Array<InstanceKlass*>* _transitive_interfaces;
135 Annotations* _combined_annotations;
136 AnnotationArray* _class_annotations;
184 u2 _super_class_index;
185 u2 _itfs_len;
186 u2 _java_fields_count;
187
188 bool _need_verify;
189 bool _relax_verify;
190
191 bool _has_nonstatic_concrete_methods;
192 bool _declares_nonstatic_concrete_methods;
193 bool _has_final_method;
194 bool _has_contended_fields;
195
196 // precomputed flags
197 bool _has_finalizer;
198 bool _has_empty_finalizer;
199 bool _has_vanilla_constructor;
200 int _max_bootstrap_specifier_index; // detects BSS values
201
202 void parse_stream(const ClassFileStream* const stream, TRAPS);
203
204 void post_process_parsed_stream(const ClassFileStream* const stream,
205 ConstantPool* cp,
206 TRAPS);
207
208 void prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS);
209 void fix_unsafe_anonymous_class_name(TRAPS);
210
211 void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH, TRAPS);
212 void set_klass(InstanceKlass* instance);
213
214 void set_class_bad_constant_seen(short bad_constant);
215 short class_bad_constant_seen() { return _bad_constant_seen; }
216 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
217 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
218 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
219 void set_class_sde_buffer(const char* x, int len) { _sde_buffer = x; _sde_length = len; }
220
221 void create_combined_annotations(TRAPS);
222 void apply_parsed_class_attributes(InstanceKlass* k); // update k
223 void apply_parsed_class_metadata(InstanceKlass* k, int fields_count, TRAPS);
224 void clear_class_metadata();
225
226 // Constant pool parsing
227 void parse_constant_pool_entries(const ClassFileStream* const stream,
228 ConstantPool* cp,
229 const int length,
230 TRAPS);
231
516 int runtime_visible_type_annotations_length,
517 const u1* runtime_invisible_type_annotations,
518 int runtime_invisible_type_annotations_length,
519 const u1* annotation_default,
520 int annotation_default_length,
521 TRAPS);
522
523 // lays out fields in class and returns the total oopmap count
524 void layout_fields(ConstantPool* cp,
525 const FieldAllocationCount* fac,
526 const ClassAnnotationCollector* parsed_annotations,
527 FieldLayoutInfo* info,
528 TRAPS);
529
530 void update_class_name(Symbol* new_name);
531
532 public:
533 ClassFileParser(ClassFileStream* stream,
534 Symbol* name,
535 ClassLoaderData* loader_data,
536 Handle protection_domain,
537 const InstanceKlass* unsafe_anonymous_host,
538 GrowableArray<Handle>* cp_patches,
539 Publicity pub_level,
540 TRAPS);
541
542 ~ClassFileParser();
543
544 InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, TRAPS);
545
546 const ClassFileStream* clone_stream() const;
547
548 void set_klass_to_deallocate(InstanceKlass* klass);
549
550 int static_field_size() const;
551 int total_oop_map_count() const;
552 jint layout_size() const;
553
554 int vtable_size() const { return _vtable_size; }
555 int itable_size() const { return _itable_size; }
556
557 u2 this_class_index() const { return _this_class_index; }
558
559 bool is_unsafe_anonymous() const { return _unsafe_anonymous_host != NULL; }
560 bool is_interface() const { return _access_flags.is_interface(); }
561
562 const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; }
563 const GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
564 ClassLoaderData* loader_data() const { return _loader_data; }
565 const Symbol* class_name() const { return _class_name; }
566 const InstanceKlass* super_klass() const { return _super_klass; }
567
568 ReferenceType reference_type() const { return _rt; }
569 AccessFlags access_flags() const { return _access_flags; }
570
571 bool is_internal() const { return INTERNAL == _pub_level; }
572
573 static bool verify_unqualified_name(const char* name, unsigned int length, int type);
574
575 #ifdef ASSERT
576 static bool is_internal_format(Symbol* class_name);
577 #endif
578
579 };
|
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/instanceKlass.hpp"
32 #include "oops/typeArrayOop.hpp"
33 #include "utilities/accessFlags.hpp"
34
35 class Annotations;
36 template <typename T>
37 class Array;
38 class ClassFileStream;
39 class ClassLoaderData;
40 class ClassLoadInfo;
41 class ClassInstanceInfo;
42 class CompressedLineNumberWriteStream;
43 class ConstMethod;
44 class FieldInfo;
45 template <typename T>
46 class GrowableArray;
47 class InstanceKlass;
48 class RecordComponent;
49 class Symbol;
50 class TempNewSymbol;
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;
94 // It is used to control which subsystems (if any)
95 // will observe the parsing (logging, events, tracing).
96 // Default level is "BROADCAST", which is equivalent to
97 // a "public" parsing attempt.
98 //
99 // "INTERNAL" level should be entirely private to the
100 // caller - this allows for internal reuse of ClassFileParser
101 //
102 enum Publicity {
103 INTERNAL,
104 BROADCAST
105 };
106
107 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
108
109 private:
110 // Potentially unaligned pointer to various 16-bit entries in the class file
111 typedef void unsafe_u2;
112
113 const ClassFileStream* _stream; // Actual input stream
114 Symbol* _class_name;
115 mutable ClassLoaderData* _loader_data;
116 const InstanceKlass* _unsafe_anonymous_host;
117 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
118 const bool _is_hidden;
119 const bool _can_access_vm_annotations;
120 int _num_patched_klasses;
121 int _max_num_patched_klasses;
122 int _orig_cp_size;
123 int _first_patched_klass_resolved_index;
124
125 // Metadata created before the instance klass is created. Must be deallocated
126 // if not transferred to the InstanceKlass upon successful class loading
127 // in which case these pointers have been set to NULL.
128 const InstanceKlass* _super_klass;
129 ConstantPool* _cp;
130 Array<u2>* _fields;
131 Array<Method*>* _methods;
132 Array<u2>* _inner_classes;
133 Array<u2>* _nest_members;
134 u2 _nest_host;
135 Array<RecordComponent*>* _record_components;
136 Array<InstanceKlass*>* _local_interfaces;
137 Array<InstanceKlass*>* _transitive_interfaces;
138 Annotations* _combined_annotations;
139 AnnotationArray* _class_annotations;
187 u2 _super_class_index;
188 u2 _itfs_len;
189 u2 _java_fields_count;
190
191 bool _need_verify;
192 bool _relax_verify;
193
194 bool _has_nonstatic_concrete_methods;
195 bool _declares_nonstatic_concrete_methods;
196 bool _has_final_method;
197 bool _has_contended_fields;
198
199 // precomputed flags
200 bool _has_finalizer;
201 bool _has_empty_finalizer;
202 bool _has_vanilla_constructor;
203 int _max_bootstrap_specifier_index; // detects BSS values
204
205 void parse_stream(const ClassFileStream* const stream, TRAPS);
206
207 void mangle_hidden_class_name(InstanceKlass* const ik);
208
209 void post_process_parsed_stream(const ClassFileStream* const stream,
210 ConstantPool* cp,
211 TRAPS);
212
213 void prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS);
214 void fix_unsafe_anonymous_class_name(TRAPS);
215
216 void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH,
217 const ClassInstanceInfo& cl_inst_info, TRAPS);
218
219 void set_klass(InstanceKlass* instance);
220
221 void set_class_bad_constant_seen(short bad_constant);
222 short class_bad_constant_seen() { return _bad_constant_seen; }
223 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
224 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
225 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
226 void set_class_sde_buffer(const char* x, int len) { _sde_buffer = x; _sde_length = len; }
227
228 void create_combined_annotations(TRAPS);
229 void apply_parsed_class_attributes(InstanceKlass* k); // update k
230 void apply_parsed_class_metadata(InstanceKlass* k, int fields_count, TRAPS);
231 void clear_class_metadata();
232
233 // Constant pool parsing
234 void parse_constant_pool_entries(const ClassFileStream* const stream,
235 ConstantPool* cp,
236 const int length,
237 TRAPS);
238
523 int runtime_visible_type_annotations_length,
524 const u1* runtime_invisible_type_annotations,
525 int runtime_invisible_type_annotations_length,
526 const u1* annotation_default,
527 int annotation_default_length,
528 TRAPS);
529
530 // lays out fields in class and returns the total oopmap count
531 void layout_fields(ConstantPool* cp,
532 const FieldAllocationCount* fac,
533 const ClassAnnotationCollector* parsed_annotations,
534 FieldLayoutInfo* info,
535 TRAPS);
536
537 void update_class_name(Symbol* new_name);
538
539 public:
540 ClassFileParser(ClassFileStream* stream,
541 Symbol* name,
542 ClassLoaderData* loader_data,
543 const ClassLoadInfo* cl_info,
544 Publicity pub_level,
545 TRAPS);
546
547 ~ClassFileParser();
548
549 InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, const ClassInstanceInfo& cl_inst_info, TRAPS);
550
551 const ClassFileStream* clone_stream() const;
552
553 void set_klass_to_deallocate(InstanceKlass* klass);
554
555 int static_field_size() const;
556 int total_oop_map_count() const;
557 jint layout_size() const;
558
559 int vtable_size() const { return _vtable_size; }
560 int itable_size() const { return _itable_size; }
561
562 u2 this_class_index() const { return _this_class_index; }
563
564 bool is_unsafe_anonymous() const { return _unsafe_anonymous_host != NULL; }
565 bool is_hidden() const { return _is_hidden; }
566 bool is_interface() const { return _access_flags.is_interface(); }
567
568 const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; }
569 const GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
570 ClassLoaderData* loader_data() const { return _loader_data; }
571 const Symbol* class_name() const { return _class_name; }
572 const InstanceKlass* super_klass() const { return _super_klass; }
573
574 ReferenceType reference_type() const { return _rt; }
575 AccessFlags access_flags() const { return _access_flags; }
576
577 bool is_internal() const { return INTERNAL == _pub_level; }
578
579 static bool verify_unqualified_name(const char* name, unsigned int length, int type);
580
581 #ifdef ASSERT
582 static bool is_internal_format(Symbol* class_name);
583 #endif
584
585 };
|