< prev index next >

src/hotspot/share/classfile/classFileParser.hpp

Print this page

  1 /*
  2  * Copyright (c) 1997, 2021, 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  *

 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 FieldAllocationCount;
 90   class FieldAnnotationCollector;
 91 
 92  public:
 93   // The ClassFileParser has an associated "publicity" level
 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.

111   typedef void unsafe_u2;
112 
113   const ClassFileStream* _stream; // Actual input stream
114   Symbol* _class_name;
115   mutable ClassLoaderData* _loader_data;
116   const bool _is_hidden;
117   const bool _can_access_vm_annotations;
118   int _orig_cp_size;
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<u2>* _fields;
126   Array<Method*>* _methods;
127   Array<u2>* _inner_classes;
128   Array<u2>* _nest_members;
129   u2 _nest_host;
130   Array<u2>* _permitted_subclasses;

131   Array<RecordComponent*>* _record_components;

132   Array<InstanceKlass*>* _local_interfaces;
133   Array<InstanceKlass*>* _transitive_interfaces;
134   Annotations* _combined_annotations;
135   AnnotationArray* _class_annotations;
136   AnnotationArray* _class_type_annotations;
137   Array<AnnotationArray*>* _fields_annotations;
138   Array<AnnotationArray*>* _fields_type_annotations;
139   InstanceKlass* _klass;  // InstanceKlass* once created.
140   InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
141 
142   ClassAnnotationCollector* _parsed_annotations;
143   FieldAllocationCount* _fac;
144   FieldLayoutInfo* _field_info;

145   const intArray* _method_ordering;
146   GrowableArray<Method*>* _all_mirandas;
147 
148   enum { fixed_buffer_size = 128 };
149   u_char _linenumbertable_buffer[fixed_buffer_size];
150 
151   // Size of Java vtable (in words)
152   int _vtable_size;
153   int _itable_size;
154 
155   int _num_miranda_methods;
156 




157   ReferenceType _rt;
158   Handle _protection_domain;
159   AccessFlags _access_flags;
160 
161   // for tracing and notifications
162   Publicity _pub_level;
163 
164   // Used to keep track of whether a constant pool item 19 or 20 is found.  These
165   // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
166   // in regular class files.  For class file version >= 53, a CFE cannot be thrown
167   // immediately when these are seen because a NCDFE must be thrown if the class's
168   // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
169   // at yet.  So, the bad constant pool item is cached here.  A value of zero
170   // means that no constant pool item 19 or 20 was found.
171   short _bad_constant_seen;
172 
173   // class attributes parsed before the instance klass is created:
174   bool _synthetic_flag;
175   int _sde_length;
176   const char* _sde_buffer;
177   u2 _sourcefile_index;
178   u2 _generic_signature_index;
179 
180   u2 _major_version;
181   u2 _minor_version;
182   u2 _this_class_index;
183   u2 _super_class_index;
184   u2 _itfs_len;
185   u2 _java_fields_count;
186 
187   bool _need_verify;
188   bool _relax_verify;
189 
190   bool _has_nonstatic_concrete_methods;
191   bool _declares_nonstatic_concrete_methods;
192   bool _has_final_method;
193   bool _has_contended_fields;
194 








195   // precomputed flags
196   bool _has_finalizer;
197   bool _has_empty_finalizer;
198   bool _has_vanilla_constructor;
199   int _max_bootstrap_specifier_index;  // detects BSS values
200 
201   void parse_stream(const ClassFileStream* const stream, TRAPS);
202 
203   void mangle_hidden_class_name(InstanceKlass* const ik);
204 
205   void post_process_parsed_stream(const ClassFileStream* const stream,
206                                   ConstantPool* cp,
207                                   TRAPS);
208 
209   void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH,
210                            const ClassInstanceInfo& cl_inst_info, TRAPS);
211 
212   void set_klass(InstanceKlass* instance);
213 
214   void set_class_bad_constant_seen(short bad_constant);

222   void apply_parsed_class_attributes(InstanceKlass* k);  // update k
223   void apply_parsed_class_metadata(InstanceKlass* k, int fields_count);
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 
232   void parse_constant_pool(const ClassFileStream* const cfs,
233                            ConstantPool* const cp,
234                            const int length,
235                            TRAPS);
236 
237   // Interface parsing
238   void parse_interfaces(const ClassFileStream* const stream,
239                         const int itfs_len,
240                         ConstantPool* const cp,
241                         bool* has_nonstatic_concrete_methods,

242                         TRAPS);
243 
244   const InstanceKlass* parse_super_class(ConstantPool* const cp,
245                                          const int super_class_index,
246                                          const bool need_verify,
247                                          TRAPS);
248 
249   // Field parsing
250   void parse_field_attributes(const ClassFileStream* const cfs,
251                               u2 attributes_count,
252                               bool is_static,
253                               u2 signature_index,
254                               u2* const constantvalue_index_addr,
255                               bool* const is_synthetic_addr,
256                               u2* const generic_signature_index_addr,
257                               FieldAnnotationCollector* parsed_annotations,
258                               TRAPS);
259 
260   void parse_fields(const ClassFileStream* const cfs,
261                     bool is_interface,


262                     FieldAllocationCount* const fac,
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                        AccessFlags* const promoted_flags,
273                        TRAPS);
274 
275   void parse_methods(const ClassFileStream* const cfs,
276                      bool is_interface,


277                      AccessFlags* const promoted_flags,
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   u2 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* assemble_annotations(const u1* const runtime_visible_annotations,
350                                         int runtime_visible_annotations_length,

429   inline void guarantee_property(bool b,
430                                  const char* msg,
431                                  const char *name,
432                                  TRAPS) const {
433     if (!b) { classfile_parse_error(msg, name, THREAD); return; }
434   }
435 
436   inline void guarantee_property(bool b,
437                                  const char* msg,
438                                  int index,
439                                  const char *name,
440                                  TRAPS) const {
441     if (!b) { classfile_parse_error(msg, index, name, THREAD); return; }
442   }
443 
444   void throwIllegalSignature(const char* type,
445                              const Symbol* name,
446                              const Symbol* sig,
447                              TRAPS) const;
448 





449   void verify_constantvalue(const ConstantPool* const cp,
450                             int constantvalue_index,
451                             int signature_index,
452                             TRAPS) const;
453 
454   void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
455   void verify_legal_class_name(const Symbol* name, TRAPS) const;
456   void verify_legal_field_name(const Symbol* name, TRAPS) const;
457   void verify_legal_method_name(const Symbol* name, TRAPS) const;
458 
459   void verify_legal_field_signature(const Symbol* fieldname,
460                                     const Symbol* signature,
461                                     TRAPS) const;
462   int  verify_legal_method_signature(const Symbol* methodname,
463                                      const Symbol* signature,
464                                      TRAPS) const;
465   void verify_legal_name_with_signature(const Symbol* name,
466                                         const Symbol* signature,
467                                         TRAPS) const;
468 
469   void verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS);
470 
471   void verify_legal_class_modifiers(jint flags, TRAPS) const;
472   void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS) const;




473   void verify_legal_method_modifiers(jint flags,
474                                      bool is_interface,


475                                      const Symbol* name,
476                                      TRAPS) const;
477 
478   void check_super_class_access(const InstanceKlass* this_klass,
479                                 TRAPS);
480 
481   void check_super_interface_access(const InstanceKlass* this_klass,
482                                     TRAPS);
483 
484   const char* skip_over_field_signature(const char* signature,
485                                         bool void_ok,
486                                         unsigned int length,
487                                         TRAPS) const;
488 
489   // Wrapper for constantTag.is_klass_[or_]reference.
490   // In older versions of the VM, Klass*s cannot sneak into early phases of
491   // constant pool construction, but in later versions they can.
492   // %%% Let's phase out the old is_klass_reference.
493   bool valid_klass_reference_at(int index) const {
494     return _cp->is_within_bounds(index) &&

512 
513   void copy_method_annotations(ConstMethod* cm,
514                                const u1* runtime_visible_annotations,
515                                int runtime_visible_annotations_length,
516                                const u1* runtime_invisible_annotations,
517                                int runtime_invisible_annotations_length,
518                                const u1* runtime_visible_parameter_annotations,
519                                int runtime_visible_parameter_annotations_length,
520                                const u1* runtime_invisible_parameter_annotations,
521                                int runtime_invisible_parameter_annotations_length,
522                                const u1* runtime_visible_type_annotations,
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   void update_class_name(Symbol* new_name);
531 



532  public:
533   ClassFileParser(ClassFileStream* stream,
534                   Symbol* name,
535                   ClassLoaderData* loader_data,
536                   const ClassLoadInfo* cl_info,
537                   Publicity pub_level,
538                   TRAPS);
539 
540   ~ClassFileParser();
541 
542   InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, const ClassInstanceInfo& cl_inst_info, TRAPS);
543 
544   const ClassFileStream* clone_stream() const;
545 
546   void set_klass_to_deallocate(InstanceKlass* klass);
547 
548   int static_field_size() const;
549   int total_oop_map_count() const;
550   jint layout_size() const;
551 
552   int vtable_size() const { return _vtable_size; }
553   int itable_size() const { return _itable_size; }
554 
555   u2 this_class_index() const { return _this_class_index; }
556 
557   bool is_hidden() const { return _is_hidden; }
558   bool is_interface() const { return _access_flags.is_interface(); }












559 
560   ClassLoaderData* loader_data() const { return _loader_data; }
561   const Symbol* class_name() const { return _class_name; }
562   const InstanceKlass* super_klass() const { return _super_klass; }
563 
564   ReferenceType reference_type() const { return _rt; }
565   AccessFlags access_flags() const { return _access_flags; }
566 
567   bool is_internal() const { return INTERNAL == _pub_level; }
568 
569   static bool verify_unqualified_name(const char* name, unsigned int length, int type);
570 
571 #ifdef ASSERT
572   static bool is_internal_format(Symbol* class_name);
573 #endif
574 
575 };
576 
577 #endif // SHARE_CLASSFILE_CLASSFILEPARSER_HPP

  1 /*
  2  * Copyright (c) 1997, 2022, 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  *

 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   bool  _is_naturally_atomic;
 79   bool _has_inline_fields;
 80 };
 81 
 82 // Parser for for .class files
 83 //
 84 // The bytes describing the class file structure is read from a Stream object
 85 
 86 class ClassFileParser {
 87   friend class FieldLayoutBuilder;
 88   friend class FieldLayout;
 89 
 90   class ClassAnnotationCollector;
 91   class FieldAllocationCount;
 92   class FieldAnnotationCollector;
 93 
 94  public:
 95   // The ClassFileParser has an associated "publicity" level
 96   // It is used to control which subsystems (if any)
 97   // will observe the parsing (logging, events, tracing).
 98   // Default level is "BROADCAST", which is equivalent to
 99   // a "public" parsing attempt.

113   typedef void unsafe_u2;
114 
115   const ClassFileStream* _stream; // Actual input stream
116   Symbol* _class_name;
117   mutable ClassLoaderData* _loader_data;
118   const bool _is_hidden;
119   const bool _can_access_vm_annotations;
120   int _orig_cp_size;
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<u2>* _permitted_subclasses;
133   Array<u2>* _preload_classes;
134   Array<RecordComponent*>* _record_components;
135   GrowableArray<InstanceKlass*>* _temp_local_interfaces;
136   Array<InstanceKlass*>* _local_interfaces;
137   Array<InstanceKlass*>* _transitive_interfaces;
138   Annotations* _combined_annotations;
139   AnnotationArray* _class_annotations;
140   AnnotationArray* _class_type_annotations;
141   Array<AnnotationArray*>* _fields_annotations;
142   Array<AnnotationArray*>* _fields_type_annotations;
143   InstanceKlass* _klass;  // InstanceKlass* once created.
144   InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
145 
146   ClassAnnotationCollector* _parsed_annotations;
147   FieldAllocationCount* _fac;
148   FieldLayoutInfo* _field_info;
149   Array<InlineKlass*>* _inline_type_field_klasses;
150   const intArray* _method_ordering;
151   GrowableArray<Method*>* _all_mirandas;
152 
153   enum { fixed_buffer_size = 128 };
154   u_char _linenumbertable_buffer[fixed_buffer_size];
155 
156   // Size of Java vtable (in words)
157   int _vtable_size;
158   int _itable_size;
159 
160   int _num_miranda_methods;
161 
162   int _alignment;
163   int _first_field_offset;
164   int _exact_size_in_bytes;
165 
166   ReferenceType _rt;
167   Handle _protection_domain;
168   AccessFlags _access_flags;
169 
170   // for tracing and notifications
171   Publicity _pub_level;
172 
173   // Used to keep track of whether a constant pool item 19 or 20 is found.  These
174   // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
175   // in regular class files.  For class file version >= 53, a CFE cannot be thrown
176   // immediately when these are seen because a NCDFE must be thrown if the class's
177   // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
178   // at yet.  So, the bad constant pool item is cached here.  A value of zero
179   // means that no constant pool item 19 or 20 was found.
180   short _bad_constant_seen;
181 
182   // class attributes parsed before the instance klass is created:
183   bool _synthetic_flag;
184   int _sde_length;
185   const char* _sde_buffer;
186   u2 _sourcefile_index;
187   u2 _generic_signature_index;
188 
189   u2 _major_version;
190   u2 _minor_version;
191   u2 _this_class_index;
192   u2 _super_class_index;
193   u2 _itfs_len;
194   u2 _java_fields_count;
195 
196   bool _need_verify;
197   bool _relax_verify;
198 
199   bool _has_nonstatic_concrete_methods;
200   bool _declares_nonstatic_concrete_methods;
201   bool _has_final_method;
202   bool _has_contended_fields;
203 
204   bool _has_inline_type_fields;
205   bool _has_nonstatic_fields;
206   bool _is_empty_inline_type;
207   bool _is_naturally_atomic;
208   bool _is_declared_atomic;
209   bool _invalid_inline_super;   // if true, invalid super type for an inline type.
210   bool _invalid_identity_super; // if true, invalid super type for an identity type.
211 
212   // precomputed flags
213   bool _has_finalizer;
214   bool _has_empty_finalizer;
215   bool _has_vanilla_constructor;
216   int _max_bootstrap_specifier_index;  // detects BSS values
217 
218   void parse_stream(const ClassFileStream* const stream, TRAPS);
219 
220   void mangle_hidden_class_name(InstanceKlass* const ik);
221 
222   void post_process_parsed_stream(const ClassFileStream* const stream,
223                                   ConstantPool* cp,
224                                   TRAPS);
225 
226   void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH,
227                            const ClassInstanceInfo& cl_inst_info, TRAPS);
228 
229   void set_klass(InstanceKlass* instance);
230 
231   void set_class_bad_constant_seen(short bad_constant);

239   void apply_parsed_class_attributes(InstanceKlass* k);  // update k
240   void apply_parsed_class_metadata(InstanceKlass* k, int fields_count);
241   void clear_class_metadata();
242 
243   // Constant pool parsing
244   void parse_constant_pool_entries(const ClassFileStream* const stream,
245                                    ConstantPool* cp,
246                                    const int length,
247                                    TRAPS);
248 
249   void parse_constant_pool(const ClassFileStream* const cfs,
250                            ConstantPool* const cp,
251                            const int length,
252                            TRAPS);
253 
254   // Interface parsing
255   void parse_interfaces(const ClassFileStream* const stream,
256                         const int itfs_len,
257                         ConstantPool* const cp,
258                         bool* has_nonstatic_concrete_methods,
259                         bool* is_declared_atomic,
260                         TRAPS);
261 
262   const InstanceKlass* parse_super_class(ConstantPool* const cp,
263                                          const int super_class_index,
264                                          const bool need_verify,
265                                          TRAPS);
266 
267   // Field parsing
268   void parse_field_attributes(const ClassFileStream* const cfs,
269                               u2 attributes_count,
270                               bool is_static,
271                               u2 signature_index,
272                               u2* const constantvalue_index_addr,
273                               bool* const is_synthetic_addr,
274                               u2* const generic_signature_index_addr,
275                               FieldAnnotationCollector* parsed_annotations,
276                               TRAPS);
277 
278   void parse_fields(const ClassFileStream* const cfs,
279                     bool is_interface,
280                     bool is_inline_type,
281                     bool is_permits_value_class,
282                     FieldAllocationCount* const fac,
283                     ConstantPool* cp,
284                     const int cp_size,
285                     u2* const java_fields_count_ptr,
286                     TRAPS);
287 
288   // Method parsing
289   Method* parse_method(const ClassFileStream* const cfs,
290                        bool is_interface,
291                        bool is_inline_type,
292                        bool is_permits_value_class,
293                        const ConstantPool* cp,
294                        AccessFlags* const promoted_flags,
295                        TRAPS);
296 
297   void parse_methods(const ClassFileStream* const cfs,
298                      bool is_interface,
299                      bool is_inline_type,
300                      bool is_permits_value_class,
301                      AccessFlags* const promoted_flags,
302                      bool* const has_final_method,
303                      bool* const declares_nonstatic_concrete_methods,
304                      TRAPS);
305 
306   const unsafe_u2* parse_exception_table(const ClassFileStream* const stream,
307                                          u4 code_length,
308                                          u4 exception_table_length,
309                                          TRAPS);
310 
311   void parse_linenumber_table(u4 code_attribute_length,
312                               u4 code_length,
313                               CompressedLineNumberWriteStream**const write_stream,
314                               TRAPS);
315 
316   const unsafe_u2* parse_localvariable_table(const ClassFileStream* const cfs,
317                                              u4 code_length,
318                                              u2 max_locals,
319                                              u4 code_attribute_length,
320                                              u2* const localvariable_table_length,

335 
336   // Check for circularity in InnerClasses attribute.
337   bool check_inner_classes_circularity(const ConstantPool* cp, int length, TRAPS);
338 
339   u2   parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs,
340                                                const ConstantPool* cp,
341                                                const u1* const inner_classes_attribute_start,
342                                                bool parsed_enclosingmethod_attribute,
343                                                u2 enclosing_method_class_index,
344                                                u2 enclosing_method_method_index,
345                                                TRAPS);
346 
347   u2 parse_classfile_nest_members_attribute(const ClassFileStream* const cfs,
348                                             const u1* const nest_members_attribute_start,
349                                             TRAPS);
350 
351   u2 parse_classfile_permitted_subclasses_attribute(const ClassFileStream* const cfs,
352                                                     const u1* const permitted_subclasses_attribute_start,
353                                                     TRAPS);
354 
355   u2 parse_classfile_preload_attribute(const ClassFileStream* const cfs,
356                                                     const u1* const preload_attribute_start,
357                                                     TRAPS);
358 
359   u2 parse_classfile_record_attribute(const ClassFileStream* const cfs,
360                                       const ConstantPool* cp,
361                                       const u1* const record_attribute_start,
362                                       TRAPS);
363 
364   void parse_classfile_attributes(const ClassFileStream* const cfs,
365                                   ConstantPool* cp,
366                                   ClassAnnotationCollector* parsed_annotations,
367                                   TRAPS);
368 
369   void parse_classfile_synthetic_attribute();
370   void parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS);
371   void parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs,
372                                                    ConstantPool* cp,
373                                                    u4 attribute_length,
374                                                    TRAPS);
375 
376   // Annotations handling
377   AnnotationArray* assemble_annotations(const u1* const runtime_visible_annotations,
378                                         int runtime_visible_annotations_length,

457   inline void guarantee_property(bool b,
458                                  const char* msg,
459                                  const char *name,
460                                  TRAPS) const {
461     if (!b) { classfile_parse_error(msg, name, THREAD); return; }
462   }
463 
464   inline void guarantee_property(bool b,
465                                  const char* msg,
466                                  int index,
467                                  const char *name,
468                                  TRAPS) const {
469     if (!b) { classfile_parse_error(msg, index, name, THREAD); return; }
470   }
471 
472   void throwIllegalSignature(const char* type,
473                              const Symbol* name,
474                              const Symbol* sig,
475                              TRAPS) const;
476 
477   void throwInlineTypeLimitation(THREAD_AND_LOCATION_DECL,
478                                  const char* msg,
479                                  const Symbol* name = NULL,
480                                  const Symbol* sig  = NULL) const;
481 
482   void verify_constantvalue(const ConstantPool* const cp,
483                             int constantvalue_index,
484                             int signature_index,
485                             TRAPS) const;
486 
487   void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
488   void verify_legal_class_name(const Symbol* name, TRAPS) const;
489   void verify_legal_field_name(const Symbol* name, TRAPS) const;
490   void verify_legal_method_name(const Symbol* name, TRAPS) const;
491 
492   void verify_legal_field_signature(const Symbol* fieldname,
493                                     const Symbol* signature,
494                                     TRAPS) const;
495   int  verify_legal_method_signature(const Symbol* methodname,
496                                      const Symbol* signature,
497                                      TRAPS) const;
498   void verify_legal_name_with_signature(const Symbol* name,
499                                         const Symbol* signature,
500                                         TRAPS) const;
501 
502   void verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS);
503 
504   void verify_legal_class_modifiers(jint flags, TRAPS) const;
505   void verify_legal_field_modifiers(jint flags,
506                                     bool is_interface,
507                                     bool is_inline_type,
508                                     bool is_permits_value_class,
509                                     TRAPS) const;
510   void verify_legal_method_modifiers(jint flags,
511                                      bool is_interface,
512                                      bool is_inline_type,
513                                      bool is_permits_value_class,
514                                      const Symbol* name,
515                                      TRAPS) const;
516 
517   void check_super_class_access(const InstanceKlass* this_klass,
518                                 TRAPS);
519 
520   void check_super_interface_access(const InstanceKlass* this_klass,
521                                     TRAPS);
522 
523   const char* skip_over_field_signature(const char* signature,
524                                         bool void_ok,
525                                         unsigned int length,
526                                         TRAPS) const;
527 
528   // Wrapper for constantTag.is_klass_[or_]reference.
529   // In older versions of the VM, Klass*s cannot sneak into early phases of
530   // constant pool construction, but in later versions they can.
531   // %%% Let's phase out the old is_klass_reference.
532   bool valid_klass_reference_at(int index) const {
533     return _cp->is_within_bounds(index) &&

551 
552   void copy_method_annotations(ConstMethod* cm,
553                                const u1* runtime_visible_annotations,
554                                int runtime_visible_annotations_length,
555                                const u1* runtime_invisible_annotations,
556                                int runtime_invisible_annotations_length,
557                                const u1* runtime_visible_parameter_annotations,
558                                int runtime_visible_parameter_annotations_length,
559                                const u1* runtime_invisible_parameter_annotations,
560                                int runtime_invisible_parameter_annotations_length,
561                                const u1* runtime_visible_type_annotations,
562                                int runtime_visible_type_annotations_length,
563                                const u1* runtime_invisible_type_annotations,
564                                int runtime_invisible_type_annotations_length,
565                                const u1* annotation_default,
566                                int annotation_default_length,
567                                TRAPS);
568 
569   void update_class_name(Symbol* new_name);
570 
571   // Check if the class file supports inline types
572   bool supports_inline_types() const;
573 
574  public:
575   ClassFileParser(ClassFileStream* stream,
576                   Symbol* name,
577                   ClassLoaderData* loader_data,
578                   const ClassLoadInfo* cl_info,
579                   Publicity pub_level,
580                   TRAPS);
581 
582   ~ClassFileParser();
583 
584   InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, const ClassInstanceInfo& cl_inst_info, TRAPS);
585 
586   const ClassFileStream* clone_stream() const;
587 
588   void set_klass_to_deallocate(InstanceKlass* klass);
589 
590   int static_field_size() const;
591   int total_oop_map_count() const;
592   jint layout_size() const;
593 
594   int vtable_size() const { return _vtable_size; }
595   int itable_size() const { return _itable_size; }
596 
597   u2 this_class_index() const { return _this_class_index; }
598 
599   bool is_hidden() const { return _is_hidden; }
600   bool is_interface() const { return _access_flags.is_interface(); }
601   bool is_inline_type() const { return _access_flags.is_value_class(); }
602   bool is_permits_value_class() const { return _access_flags.is_permits_value_class(); }
603   bool is_identity_class() const { return _access_flags.is_identity_class(); }
604   bool is_value_capable_class() const;
605   bool has_inline_fields() const { return _has_inline_type_fields; }
606   bool invalid_inline_super() const { return _invalid_inline_super; }
607   void set_invalid_inline_super() { _invalid_inline_super = true; }
608   bool invalid_identity_super() const { return _invalid_identity_super; }
609   void set_invalid_identity_super() { _invalid_identity_super = true; }
610   bool is_invalid_super_for_inline_type();
611 
612   u2 java_fields_count() const { return _java_fields_count; }
613 
614   ClassLoaderData* loader_data() const { return _loader_data; }
615   const Symbol* class_name() const { return _class_name; }
616   const InstanceKlass* super_klass() const { return _super_klass; }
617 
618   ReferenceType reference_type() const { return _rt; }
619   AccessFlags access_flags() const { return _access_flags; }
620 
621   bool is_internal() const { return INTERNAL == _pub_level; }
622 
623   static bool verify_unqualified_name(const char* name, unsigned int length, int type);
624 
625 #ifdef ASSERT
626   static bool is_internal_format(Symbol* class_name);
627 #endif
628 
629 };
630 
631 #endif // SHARE_CLASSFILE_CLASSFILEPARSER_HPP
< prev index next >