< prev index next >

src/hotspot/share/classfile/classFileParser.hpp

Print this page




  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/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 
  59  public:
  60   // The ClassFileParser has an associated "publicity" level
  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


 106   Array<AnnotationArray*>* _fields_annotations;
 107   Array<AnnotationArray*>* _fields_type_annotations;
 108   InstanceKlass* _klass;  // InstanceKlass* once created.
 109   InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
 110 
 111   ClassAnnotationCollector* _parsed_annotations;
 112   FieldAllocationCount* _fac;
 113   FieldLayoutInfo* _field_info;
 114   const intArray* _method_ordering;
 115   GrowableArray<Method*>* _all_mirandas;
 116 
 117   enum { fixed_buffer_size = 128 };
 118   u_char _linenumbertable_buffer[fixed_buffer_size];
 119 
 120   // Size of Java vtable (in words)
 121   int _vtable_size;
 122   int _itable_size;
 123 
 124   int _num_miranda_methods;
 125 




 126   ReferenceType _rt;
 127   Handle _protection_domain;
 128   AccessFlags _access_flags;
 129 
 130   // for tracing and notifications
 131   Publicity _pub_level;
 132 
 133   // Used to keep track of whether a constant pool item 19 or 20 is found.  These
 134   // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
 135   // in regular class files.  For class file version >= 53, a CFE cannot be thrown
 136   // immediately when these are seen because a NCDFE must be thrown if the class's
 137   // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
 138   // at yet.  So, the bad constant pool item is cached here.  A value of zero
 139   // means that no constant pool item 19 or 20 was found.
 140   short _bad_constant_seen;
 141 
 142   // class attributes parsed before the instance klass is created:
 143   bool _synthetic_flag;
 144   int _sde_length;
 145   const char* _sde_buffer;
 146   u2 _sourcefile_index;
 147   u2 _generic_signature_index;
 148 
 149   u2 _major_version;
 150   u2 _minor_version;
 151   u2 _this_class_index;
 152   u2 _super_class_index;
 153   u2 _itfs_len;
 154   u2 _java_fields_count;
 155 
 156   bool _need_verify;
 157   bool _relax_verify;
 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);


 209                         TRAPS);
 210 
 211   const InstanceKlass* parse_super_class(ConstantPool* const cp,
 212                                          const int super_class_index,
 213                                          const bool need_verify,
 214                                          TRAPS);
 215 
 216   // Field parsing
 217   void parse_field_attributes(const ClassFileStream* const cfs,
 218                               u2 attributes_count,
 219                               bool is_static,
 220                               u2 signature_index,
 221                               u2* const constantvalue_index_addr,
 222                               bool* const is_synthetic_addr,
 223                               u2* const generic_signature_index_addr,
 224                               FieldAnnotationCollector* parsed_annotations,
 225                               TRAPS);
 226 
 227   void parse_fields(const ClassFileStream* const cfs,
 228                     bool is_interface,

 229                     FieldAllocationCount* const fac,
 230                     ConstantPool* cp,
 231                     const int cp_size,
 232                     u2* const java_fields_count_ptr,
 233                     TRAPS);
 234 
 235   // Method parsing
 236   Method* parse_method(const ClassFileStream* const cfs,
 237                        bool is_interface,

 238                        const ConstantPool* cp,
 239                        AccessFlags* const promoted_flags,
 240                        TRAPS);
 241 
 242   void parse_methods(const ClassFileStream* const cfs,
 243                      bool is_interface,

 244                      AccessFlags* const promoted_flags,
 245                      bool* const has_final_method,
 246                      bool* const declares_nonstatic_concrete_methods,
 247                      TRAPS);
 248 
 249   const unsafe_u2* parse_exception_table(const ClassFileStream* const stream,
 250                                          u4 code_length,
 251                                          u4 exception_table_length,
 252                                          TRAPS);
 253 
 254   void parse_linenumber_table(u4 code_attribute_length,
 255                               u4 code_length,
 256                               CompressedLineNumberWriteStream**const write_stream,
 257                               TRAPS);
 258 
 259   const unsafe_u2* parse_localvariable_table(const ClassFileStream* const cfs,
 260                                              u4 code_length,
 261                                              u2 max_locals,
 262                                              u4 code_attribute_length,
 263                                              u2* const localvariable_table_length,


 289 
 290   void parse_classfile_attributes(const ClassFileStream* const cfs,
 291                                   ConstantPool* cp,
 292                                   ClassAnnotationCollector* parsed_annotations,
 293                                   TRAPS);
 294 
 295   void parse_classfile_synthetic_attribute(TRAPS);
 296   void parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS);
 297   void parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs,
 298                                                    ConstantPool* cp,
 299                                                    u4 attribute_length,
 300                                                    TRAPS);
 301 
 302   // Annotations handling
 303   AnnotationArray* assemble_annotations(const u1* const runtime_visible_annotations,
 304                                         int runtime_visible_annotations_length,
 305                                         const u1* const runtime_invisible_annotations,
 306                                         int runtime_invisible_annotations_length,
 307                                         TRAPS);
 308 
 309   void set_precomputed_flags(InstanceKlass* k);
 310 
 311   // Format checker methods
 312   void classfile_parse_error(const char* msg, TRAPS) const;
 313   void classfile_parse_error(const char* msg, int index, TRAPS) const;
 314   void classfile_parse_error(const char* msg, const char *name, TRAPS) const;
 315   void classfile_parse_error(const char* msg,
 316                              int index,
 317                              const char *name,
 318                              TRAPS) const;
 319   void classfile_parse_error(const char* msg,
 320                              const char* name,
 321                              const char* signature,
 322                              TRAPS) const;
 323 
 324   inline void guarantee_property(bool b, const char* msg, TRAPS) const {
 325     if (!b) { classfile_parse_error(msg, CHECK); }
 326   }
 327 
 328   void report_assert_property_failure(const char* msg, TRAPS) const PRODUCT_RETURN;
 329   void report_assert_property_failure(const char* msg, int index, TRAPS) const PRODUCT_RETURN;


 373   inline void guarantee_property(bool b,
 374                                  const char* msg,
 375                                  const char *name,
 376                                  TRAPS) const {
 377     if (!b) { classfile_parse_error(msg, name, CHECK); }
 378   }
 379 
 380   inline void guarantee_property(bool b,
 381                                  const char* msg,
 382                                  int index,
 383                                  const char *name,
 384                                  TRAPS) const {
 385     if (!b) { classfile_parse_error(msg, index, name, CHECK); }
 386   }
 387 
 388   void throwIllegalSignature(const char* type,
 389                              const Symbol* name,
 390                              const Symbol* sig,
 391                              TRAPS) const;
 392 





 393   void verify_constantvalue(const ConstantPool* const cp,
 394                             int constantvalue_index,
 395                             int signature_index,
 396                             TRAPS) const;
 397 
 398   void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
 399   void verify_legal_class_name(const Symbol* name, TRAPS) const;
 400   void verify_legal_field_name(const Symbol* name, TRAPS) const;
 401   void verify_legal_method_name(const Symbol* name, TRAPS) const;
 402 
 403   void verify_legal_field_signature(const Symbol* fieldname,
 404                                     const Symbol* signature,
 405                                     TRAPS) const;
 406   int  verify_legal_method_signature(const Symbol* methodname,
 407                                      const Symbol* signature,
 408                                      TRAPS) const;
 409 
 410   void verify_legal_class_modifiers(jint flags, TRAPS) const;
 411   void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS) const;



 412   void verify_legal_method_modifiers(jint flags,
 413                                      bool is_interface,

 414                                      const Symbol* name,
 415                                      TRAPS) const;
 416 
 417   const char* skip_over_field_signature(const char* signature,
 418                                         bool void_ok,
 419                                         unsigned int length,
 420                                         TRAPS) const;
 421 
 422   bool has_cp_patch_at(int index) const {
 423     assert(index >= 0, "oob");
 424     return (_cp_patches != NULL
 425             && index < _cp_patches->length()
 426             && _cp_patches->adr_at(index)->not_null());
 427   }
 428 
 429   Handle cp_patch_at(int index) const {
 430     assert(has_cp_patch_at(index), "oob");
 431     return _cp_patches->at(index);
 432   }
 433 


 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 };
 540 


  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/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 Symbol;
  47 class TempNewSymbol;
  48 class FieldLayoutBuilder;
  49 
  50 
  51 class AnnotationCollector : public ResourceObj{
  52 public:
  53   enum Location { _in_field, _in_method, _in_class };
  54   enum ID {
  55     _unknown = 0,
  56     _method_CallerSensitive,
  57     _method_ForceInline,
  58     _method_DontInline,
  59     _method_InjectedProfile,
  60     _method_LambdaForm_Compiled,
  61     _method_Hidden,
  62     _method_HotSpotIntrinsicCandidate,
  63     _jdk_internal_vm_annotation_Contended,
  64     _field_Stable,
  65     _jdk_internal_vm_annotation_ReservedStackAccess,
  66     _annotation_LIMIT
  67   };
  68   const Location _location;
  69   int _annotations_present;
  70   u2 _contended_group;
  71 
  72   AnnotationCollector(Location location)
  73     : _location(location), _annotations_present(0)
  74   {
  75     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
  76   }
  77   // If this annotation name has an ID, report it (or _none).
  78   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
  79   // Set the annotation name:
  80   void set_annotation(ID id) {
  81     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
  82     _annotations_present |= nth_bit((int)id);
  83   }
  84 
  85   void remove_annotation(ID id) {
  86     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
  87     _annotations_present &= ~nth_bit((int)id);
  88   }
  89 
  90   // Report if the annotation is present.
  91   bool has_any_annotations() const { return _annotations_present != 0; }
  92   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
  93 
  94   void set_contended_group(u2 group) { _contended_group = group; }
  95   u2 contended_group() const { return _contended_group; }
  96 
  97   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
  98 
  99   void set_stable(bool stable) { set_annotation(_field_Stable); }
 100   bool is_stable() const { return has_annotation(_field_Stable); }
 101 };
 102 
 103 // Utility to collect and compact oop maps during layout
 104 class OopMapBlocksBuilder : public ResourceObj {
 105 public:
 106   OopMapBlock*  nonstatic_oop_maps;
 107   unsigned int  nonstatic_oop_map_count;
 108   unsigned int  max_nonstatic_oop_maps;
 109 
 110  public:
 111   OopMapBlocksBuilder(unsigned int  max_blocks, TRAPS);
 112   OopMapBlock* last_oop_map() const;
 113   void initialize_inherited_blocks(OopMapBlock* blocks, unsigned int nof_blocks);
 114   void add(int offset, int count);
 115   void copy(OopMapBlock* dst);
 116   void compact(TRAPS);
 117   void print_on(outputStream* st) const;
 118   void print_value_on(outputStream* st) const;
 119 };
 120 
 121 // Values needed for oopmap and InstanceKlass creation
 122 class FieldLayoutInfo : public ResourceObj {
 123  public:
 124   OopMapBlocksBuilder* oop_map_blocks;
 125   int           instance_size;
 126   int           nonstatic_field_size;
 127   int           static_field_size;
 128   bool          has_nonstatic_fields;
 129 };
 130 
 131 // Parser for for .class files
 132 //
 133 // The bytes describing the class file structure is read from a Stream object
 134 
 135 class ClassFileParser {
 136  friend class FieldLayoutBuilder;
 137  friend class FieldLayout;
 138 
 139 
 140  class ClassAnnotationCollector : public AnnotationCollector {
 141  public:
 142    ClassAnnotationCollector() : AnnotationCollector(_in_class) { }
 143    void apply_to(InstanceKlass* ik);
 144  };
 145  class FieldAllocationCount;
 146  class FieldAnnotationCollector;

 147 
 148  public:
 149   // The ClassFileParser has an associated "publicity" level
 150   // It is used to control which subsystems (if any)
 151   // will observe the parsing (logging, events, tracing).
 152   // Default level is "BROADCAST", which is equivalent to
 153   // a "public" parsing attempt.
 154   //
 155   // "INTERNAL" level should be entirely private to the
 156   // caller - this allows for internal reuse of ClassFileParser
 157   //
 158   enum Publicity {
 159     INTERNAL,
 160     BROADCAST
 161   };
 162 
 163   enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
 164 
 165  private:
 166   // Potentially unaligned pointer to various 16-bit entries in the class file


 195   Array<AnnotationArray*>* _fields_annotations;
 196   Array<AnnotationArray*>* _fields_type_annotations;
 197   InstanceKlass* _klass;  // InstanceKlass* once created.
 198   InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
 199 
 200   ClassAnnotationCollector* _parsed_annotations;
 201   FieldAllocationCount* _fac;
 202   FieldLayoutInfo* _field_info;
 203   const intArray* _method_ordering;
 204   GrowableArray<Method*>* _all_mirandas;
 205 
 206   enum { fixed_buffer_size = 128 };
 207   u_char _linenumbertable_buffer[fixed_buffer_size];
 208 
 209   // Size of Java vtable (in words)
 210   int _vtable_size;
 211   int _itable_size;
 212 
 213   int _num_miranda_methods;
 214 
 215   int _alignment;
 216   int _first_field_offset;
 217   int _exact_size_in_bytes;
 218 
 219   ReferenceType _rt;
 220   Handle _protection_domain;
 221   AccessFlags _access_flags;
 222 
 223   // for tracing and notifications
 224   Publicity _pub_level;
 225 
 226   // Used to keep track of whether a constant pool item 19 or 20 is found.  These
 227   // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
 228   // in regular class files.  For class file version >= 53, a CFE cannot be thrown
 229   // immediately when these are seen because a NCDFE must be thrown if the class's
 230   // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
 231   // at yet.  So, the bad constant pool item is cached here.  A value of zero
 232   // means that no constant pool item 19 or 20 was found.
 233   short _bad_constant_seen;
 234 
 235   // class attributes parsed before the instance klass is created:
 236   bool _synthetic_flag;
 237   int _sde_length;
 238   const char* _sde_buffer;
 239   u2 _sourcefile_index;
 240   u2 _generic_signature_index;
 241 
 242   u2 _major_version;
 243   u2 _minor_version;
 244   u2 _this_class_index;
 245   u2 _super_class_index;
 246   u2 _itfs_len;
 247   u2 _java_fields_count;
 248 
 249   bool _need_verify;
 250   bool _relax_verify;
 251 
 252   bool _has_nonstatic_concrete_methods;
 253   bool _declares_nonstatic_concrete_methods;
 254   bool _has_final_method;
 255   bool _has_flattenable_fields;
 256   bool _is_empty_value;
 257 
 258   // precomputed flags
 259   bool _has_finalizer;
 260   bool _has_empty_finalizer;
 261   bool _has_vanilla_constructor;
 262   int _max_bootstrap_specifier_index;  // detects BSS values
 263 
 264   void parse_stream(const ClassFileStream* const stream, TRAPS);
 265 
 266   void post_process_parsed_stream(const ClassFileStream* const stream,
 267                                   ConstantPool* cp,
 268                                   TRAPS);
 269 
 270   void prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS);
 271   void fix_unsafe_anonymous_class_name(TRAPS);
 272 
 273   void fill_instance_klass(InstanceKlass* ik, bool cf_changed_in_CFLH, TRAPS);
 274   void set_klass(InstanceKlass* instance);
 275 
 276   void set_class_bad_constant_seen(short bad_constant);


 304                         TRAPS);
 305 
 306   const InstanceKlass* parse_super_class(ConstantPool* const cp,
 307                                          const int super_class_index,
 308                                          const bool need_verify,
 309                                          TRAPS);
 310 
 311   // Field parsing
 312   void parse_field_attributes(const ClassFileStream* const cfs,
 313                               u2 attributes_count,
 314                               bool is_static,
 315                               u2 signature_index,
 316                               u2* const constantvalue_index_addr,
 317                               bool* const is_synthetic_addr,
 318                               u2* const generic_signature_index_addr,
 319                               FieldAnnotationCollector* parsed_annotations,
 320                               TRAPS);
 321 
 322   void parse_fields(const ClassFileStream* const cfs,
 323                     bool is_interface,
 324                     bool is_value_type,
 325                     FieldAllocationCount* const fac,
 326                     ConstantPool* cp,
 327                     const int cp_size,
 328                     u2* const java_fields_count_ptr,
 329                     TRAPS);
 330 
 331   // Method parsing
 332   Method* parse_method(const ClassFileStream* const cfs,
 333                        bool is_interface,
 334                        bool is_value_type,
 335                        const ConstantPool* cp,
 336                        AccessFlags* const promoted_flags,
 337                        TRAPS);
 338 
 339   void parse_methods(const ClassFileStream* const cfs,
 340                      bool is_interface,
 341                      bool is_value_type,
 342                      AccessFlags* const promoted_flags,
 343                      bool* const has_final_method,
 344                      bool* const declares_nonstatic_concrete_methods,
 345                      TRAPS);
 346 
 347   const unsafe_u2* parse_exception_table(const ClassFileStream* const stream,
 348                                          u4 code_length,
 349                                          u4 exception_table_length,
 350                                          TRAPS);
 351 
 352   void parse_linenumber_table(u4 code_attribute_length,
 353                               u4 code_length,
 354                               CompressedLineNumberWriteStream**const write_stream,
 355                               TRAPS);
 356 
 357   const unsafe_u2* parse_localvariable_table(const ClassFileStream* const cfs,
 358                                              u4 code_length,
 359                                              u2 max_locals,
 360                                              u4 code_attribute_length,
 361                                              u2* const localvariable_table_length,


 387 
 388   void parse_classfile_attributes(const ClassFileStream* const cfs,
 389                                   ConstantPool* cp,
 390                                   ClassAnnotationCollector* parsed_annotations,
 391                                   TRAPS);
 392 
 393   void parse_classfile_synthetic_attribute(TRAPS);
 394   void parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS);
 395   void parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs,
 396                                                    ConstantPool* cp,
 397                                                    u4 attribute_length,
 398                                                    TRAPS);
 399 
 400   // Annotations handling
 401   AnnotationArray* assemble_annotations(const u1* const runtime_visible_annotations,
 402                                         int runtime_visible_annotations_length,
 403                                         const u1* const runtime_invisible_annotations,
 404                                         int runtime_invisible_annotations_length,
 405                                         TRAPS);
 406 
 407   void set_precomputed_flags(InstanceKlass* k, TRAPS);
 408 
 409   // Format checker methods
 410   void classfile_parse_error(const char* msg, TRAPS) const;
 411   void classfile_parse_error(const char* msg, int index, TRAPS) const;
 412   void classfile_parse_error(const char* msg, const char *name, TRAPS) const;
 413   void classfile_parse_error(const char* msg,
 414                              int index,
 415                              const char *name,
 416                              TRAPS) const;
 417   void classfile_parse_error(const char* msg,
 418                              const char* name,
 419                              const char* signature,
 420                              TRAPS) const;
 421 
 422   inline void guarantee_property(bool b, const char* msg, TRAPS) const {
 423     if (!b) { classfile_parse_error(msg, CHECK); }
 424   }
 425 
 426   void report_assert_property_failure(const char* msg, TRAPS) const PRODUCT_RETURN;
 427   void report_assert_property_failure(const char* msg, int index, TRAPS) const PRODUCT_RETURN;


 471   inline void guarantee_property(bool b,
 472                                  const char* msg,
 473                                  const char *name,
 474                                  TRAPS) const {
 475     if (!b) { classfile_parse_error(msg, name, CHECK); }
 476   }
 477 
 478   inline void guarantee_property(bool b,
 479                                  const char* msg,
 480                                  int index,
 481                                  const char *name,
 482                                  TRAPS) const {
 483     if (!b) { classfile_parse_error(msg, index, name, CHECK); }
 484   }
 485 
 486   void throwIllegalSignature(const char* type,
 487                              const Symbol* name,
 488                              const Symbol* sig,
 489                              TRAPS) const;
 490 
 491   void throwValueTypeLimitation(THREAD_AND_LOCATION_DECL,
 492                                 const char* msg,
 493                                 const Symbol* name = NULL,
 494                                 const Symbol* sig  = NULL) const;
 495 
 496   void verify_constantvalue(const ConstantPool* const cp,
 497                             int constantvalue_index,
 498                             int signature_index,
 499                             TRAPS) const;
 500 
 501   void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
 502   void verify_legal_class_name(const Symbol* name, TRAPS) const;
 503   void verify_legal_field_name(const Symbol* name, TRAPS) const;
 504   void verify_legal_method_name(const Symbol* name, TRAPS) const;
 505 
 506   void verify_legal_field_signature(const Symbol* fieldname,
 507                                     const Symbol* signature,
 508                                     TRAPS) const;
 509   int  verify_legal_method_signature(const Symbol* methodname,
 510                                      const Symbol* signature,
 511                                      TRAPS) const;
 512 
 513   void verify_legal_class_modifiers(jint flags, TRAPS) const;
 514   void verify_legal_field_modifiers(jint flags,
 515                                     bool is_interface,
 516                                     bool is_value_type,
 517                                     TRAPS) const;
 518   void verify_legal_method_modifiers(jint flags,
 519                                      bool is_interface,
 520                                      bool is_value_type,
 521                                      const Symbol* name,
 522                                      TRAPS) const;
 523 
 524   const char* skip_over_field_signature(const char* signature,
 525                                         bool void_ok,
 526                                         unsigned int length,
 527                                         TRAPS) const;
 528 
 529   bool has_cp_patch_at(int index) const {
 530     assert(index >= 0, "oob");
 531     return (_cp_patches != NULL
 532             && index < _cp_patches->length()
 533             && _cp_patches->adr_at(index)->not_null());
 534   }
 535 
 536   Handle cp_patch_at(int index) const {
 537     assert(has_cp_patch_at(index), "oob");
 538     return _cp_patches->at(index);
 539   }
 540 


 579                                int runtime_visible_parameter_annotations_length,
 580                                const u1* runtime_invisible_parameter_annotations,
 581                                int runtime_invisible_parameter_annotations_length,
 582                                const u1* runtime_visible_type_annotations,
 583                                int runtime_visible_type_annotations_length,
 584                                const u1* runtime_invisible_type_annotations,
 585                                int runtime_invisible_type_annotations_length,
 586                                const u1* annotation_default,
 587                                int annotation_default_length,
 588                                TRAPS);
 589 
 590   // lays out fields in class and returns the total oopmap count
 591   void layout_fields(ConstantPool* cp,
 592                      const FieldAllocationCount* fac,
 593                      const ClassAnnotationCollector* parsed_annotations,
 594                      FieldLayoutInfo* info,
 595                      TRAPS);
 596 
 597    void update_class_name(Symbol* new_name);
 598 
 599   // Check if the class file supports value types
 600   bool supports_value_types() const;
 601 
 602  public:
 603   ClassFileParser(ClassFileStream* stream,
 604                   Symbol* name,
 605                   ClassLoaderData* loader_data,
 606                   Handle protection_domain,
 607                   const InstanceKlass* unsafe_anonymous_host,
 608                   GrowableArray<Handle>* cp_patches,
 609                   Publicity pub_level,
 610                   TRAPS);
 611 
 612   ~ClassFileParser();
 613 
 614   InstanceKlass* create_instance_klass(bool cf_changed_in_CFLH, TRAPS);
 615 
 616   const ClassFileStream* clone_stream() const;
 617 
 618   void set_klass_to_deallocate(InstanceKlass* klass);
 619 
 620   int static_field_size() const;
 621   int total_oop_map_count() const;
 622   jint layout_size() const;
 623 
 624   int vtable_size() const { return _vtable_size; }
 625   int itable_size() const { return _itable_size; }
 626 
 627   u2 this_class_index() const { return _this_class_index; }
 628 
 629   bool is_unsafe_anonymous() const { return _unsafe_anonymous_host != NULL; }
 630   bool is_interface() const { return _access_flags.is_interface(); }
 631   bool is_value_type() const { return _access_flags.is_value_type(); }
 632   bool is_value_capable_class() const;
 633   bool has_flattenable_fields() const { return _has_flattenable_fields; }
 634 
 635   u2 java_fields_count() const { return _java_fields_count; }
 636 
 637   const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; }
 638   const GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
 639   ClassLoaderData* loader_data() const { return _loader_data; }
 640   const Symbol* class_name() const { return _class_name; }
 641   const InstanceKlass* super_klass() const { return _super_klass; }
 642 
 643   ReferenceType reference_type() const { return _rt; }
 644   AccessFlags access_flags() const { return _access_flags; }
 645 
 646   bool is_internal() const { return INTERNAL == _pub_level; }
 647 
 648   static bool verify_unqualified_name(const char* name, unsigned int length, int type);
 649 
 650 #ifdef ASSERT
 651   static bool is_internal_format(Symbol* class_name);
 652 #endif
 653 
 654 };
 655 
< prev index next >