hotspot/src/share/vm/classfile/classFileParser.hpp
changeset 34666 1c7168ea0034
parent 34272 1b277b5ee6e3
child 36508 5f9eee6b383b
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp	Tue Dec 08 05:50:46 2015 -0800
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp	Tue Dec 08 20:04:03 2015 +0100
@@ -25,33 +25,123 @@
 #ifndef SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
 #define SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
 
-#include "classfile/classFileStream.hpp"
-#include "classfile/symbolTable.hpp"
-#include "oops/annotations.hpp"
+#include "memory/referenceType.hpp"
+#include "runtime/handles.inline.hpp"
 #include "oops/constantPool.hpp"
 #include "oops/typeArrayOop.hpp"
 #include "utilities/accessFlags.hpp"
 
+class Annotations;
+template <typename T>
+class Array;
+class ClassFileStream;
+class ClassLoaderData;
 class CompressedLineNumberWriteStream;
-class FieldAllocationCount;
+class ConstMethod;
 class FieldInfo;
-class FieldLayoutInfo;
-
+template <typename T>
+class GrowableArray;
+class InstanceKlass;
+class intArray;
+class Symbol;
+class TempNewSymbol;
 
 // Parser for for .class files
 //
 // The bytes describing the class file structure is read from a Stream object
 
 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
+
+ class ClassAnnotationCollector;
+ class FieldAllocationCount;
+ class FieldAnnotationCollector;
+ class FieldLayoutInfo;
+
+ public:
+  // The ClassFileParser has an associated "publicity" level
+  // It is used to control which subsystems (if any)
+  // will observe the parsing (logging, events, tracing).
+  // Default level is "BROADCAST", which is equivalent to
+  // a "public" parsing attempt.
+  //
+  // "INTERNAL" level should be entirely private to the
+  // caller - this allows for internal reuse of ClassFileParser
+  //
+  enum Publicity {
+    INTERNAL,
+    BROADCAST,
+    NOF_PUBLICITY_LEVELS
+  };
+
  private:
+  const ClassFileStream* _stream; // Actual input stream
+  const Symbol* _requested_name;
+  Symbol* _class_name;
+  mutable ClassLoaderData* _loader_data;
+  const Klass* _host_klass;
+  GrowableArray<Handle>* _cp_patches; // overrides for CP entries
+  TempNewSymbol* _parsed_name;
+
+  // Metadata created before the instance klass is created.  Must be deallocated
+  // if not transferred to the InstanceKlass upon successful class loading
+  // in which case these pointers have been set to NULL.
+  const InstanceKlass* _super_klass;
+  ConstantPool* _cp;
+  Array<u2>* _fields;
+  Array<Method*>* _methods;
+  Array<u2>* _inner_classes;
+  Array<Klass*>* _local_interfaces;
+  Array<Klass*>* _transitive_interfaces;
+  Annotations* _combined_annotations;
+  AnnotationArray* _annotations;
+  AnnotationArray* _type_annotations;
+  Array<AnnotationArray*>* _fields_annotations;
+  Array<AnnotationArray*>* _fields_type_annotations;
+  InstanceKlass* _klass;  // InstanceKlass* once created.
+  InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
+
+  ClassAnnotationCollector* _parsed_annotations;
+  FieldAllocationCount* _fac;
+  FieldLayoutInfo* _field_info;
+  const intArray* _method_ordering;
+  GrowableArray<Method*>* _all_mirandas;
+
+  enum { fixed_buffer_size = 128 };
+  u_char _linenumbertable_buffer[fixed_buffer_size];
+
+  // Size of Java vtable (in words)
+  int _vtable_size;
+  int _itable_size;
+
+  int _num_miranda_methods;
+
+  ReferenceType _rt;
+  Handle _protection_domain;
+  AccessFlags _access_flags;
+
+  // for tracing and notifications
+  Publicity _pub_level;
+
+  // class attributes parsed before the instance klass is created:
+  bool _synthetic_flag;
+  int _sde_length;
+  const char* _sde_buffer;
+  u2 _sourcefile_index;
+  u2 _generic_signature_index;
+
+  u2 _major_version;
+  u2 _minor_version;
+  u2 _this_class_index;
+  u2 _super_class_index;
+  u2 _itfs_len;
+  u2 _java_fields_count;
+
   bool _need_verify;
   bool _relax_verify;
-  u2   _major_version;
-  u2   _minor_version;
-  Symbol* _class_name;
-  ClassLoaderData* _loader_data;
-  KlassHandle _host_klass;
-  GrowableArray<Handle>* _cp_patches; // overrides for CP entries
+
+  bool _has_default_methods;
+  bool _declares_default_methods;
+  bool _has_final_method;
 
   // precomputed flags
   bool _has_finalizer;
@@ -59,270 +149,164 @@
   bool _has_vanilla_constructor;
   int _max_bootstrap_specifier_index;  // detects BSS values
 
-  // class attributes parsed before the instance klass is created:
-  bool       _synthetic_flag;
-  int        _sde_length;
-  char*      _sde_buffer;
-  u2         _sourcefile_index;
-  u2         _generic_signature_index;
+  void parse_stream(const ClassFileStream* const stream, TRAPS);
 
-  // Metadata created before the instance klass is created.  Must be deallocated
-  // if not transferred to the InstanceKlass upon successful class loading
-  // in which case these pointers have been set to NULL.
-  instanceKlassHandle _super_klass;
-  ConstantPool*    _cp;
-  Array<u2>*       _fields;
-  Array<Method*>*  _methods;
-  Array<u2>*       _inner_classes;
-  Array<Klass*>*   _local_interfaces;
-  Array<Klass*>*   _transitive_interfaces;
-  Annotations*     _combined_annotations;
-  AnnotationArray* _annotations;
-  AnnotationArray* _type_annotations;
-  Array<AnnotationArray*>* _fields_annotations;
-  Array<AnnotationArray*>* _fields_type_annotations;
-  InstanceKlass*   _klass;  // InstanceKlass once created.
+  void post_process_parsed_stream(const ClassFileStream* const stream,
+                                  ConstantPool* cp,
+                                  TRAPS);
+
+  void fill_instance_klass(InstanceKlass* ik, TRAPS);
+  void set_klass(InstanceKlass* instance);
 
   void set_class_synthetic_flag(bool x)        { _synthetic_flag = x; }
   void set_class_sourcefile_index(u2 x)        { _sourcefile_index = x; }
   void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
-  void set_class_sde_buffer(char* x, int len)  { _sde_buffer = x; _sde_length = len; }
+  void set_class_sde_buffer(const char* x, int len)  { _sde_buffer = x; _sde_length = len; }
 
   void create_combined_annotations(TRAPS);
-
-  void init_parsed_class_attributes(ClassLoaderData* loader_data) {
-    _loader_data = loader_data;
-    _synthetic_flag = false;
-    _sourcefile_index = 0;
-    _generic_signature_index = 0;
-    _sde_buffer = NULL;
-    _sde_length = 0;
-    // initialize the other flags too:
-    _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
-    _max_bootstrap_specifier_index = -1;
-    clear_class_metadata();
-    _klass = NULL;
-  }
-  void apply_parsed_class_attributes(instanceKlassHandle k);  // update k
-  void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS);
-  void clear_class_metadata() {
-    // metadata created before the instance klass is created.  Must be
-    // deallocated if classfile parsing returns an error.
-    _cp = NULL;
-    _fields = NULL;
-    _methods = NULL;
-    _inner_classes = NULL;
-    _local_interfaces = NULL;
-    _transitive_interfaces = NULL;
-    _combined_annotations = NULL;
-    _annotations = _type_annotations = NULL;
-    _fields_annotations = _fields_type_annotations = NULL;
-  }
-
-  class AnnotationCollector {
-  public:
-    enum Location { _in_field, _in_method, _in_class };
-    enum ID {
-      _unknown = 0,
-      _method_CallerSensitive,
-      _method_ForceInline,
-      _method_DontInline,
-      _method_InjectedProfile,
-      _method_LambdaForm_Compiled,
-      _method_LambdaForm_Hidden,
-      _method_HotSpotIntrinsicCandidate,
-      _jdk_internal_vm_annotation_Contended,
-      _field_Stable,
-      _annotation_LIMIT
-    };
-    const Location _location;
-    int _annotations_present;
-    u2 _contended_group;
-
-    AnnotationCollector(Location location)
-    : _location(location), _annotations_present(0)
-    {
-      assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
-    }
-    // If this annotation name has an ID, report it (or _none).
-    ID annotation_index(ClassLoaderData* loader_data, Symbol* name);
-    // Set the annotation name:
-    void set_annotation(ID id) {
-      assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
-      _annotations_present |= nth_bit((int)id);
-    }
-
-    void remove_annotation(ID id) {
-      assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
-      _annotations_present &= ~nth_bit((int)id);
-    }
-
-    // Report if the annotation is present.
-    bool has_any_annotations() const { return _annotations_present != 0; }
-    bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
-
-    void set_contended_group(u2 group) { _contended_group = group; }
-    u2 contended_group() const { return _contended_group; }
-
-    bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
-
-    void set_stable(bool stable) { set_annotation(_field_Stable); }
-    bool is_stable() const { return has_annotation(_field_Stable); }
-  };
-
-  // This class also doubles as a holder for metadata cleanup.
-  class FieldAnnotationCollector: public AnnotationCollector {
-    ClassLoaderData* _loader_data;
-    AnnotationArray* _field_annotations;
-    AnnotationArray* _field_type_annotations;
-  public:
-    FieldAnnotationCollector(ClassLoaderData* loader_data) :
-                                 AnnotationCollector(_in_field),
-                                 _loader_data(loader_data),
-                                 _field_annotations(NULL),
-                                 _field_type_annotations(NULL) {}
-    void apply_to(FieldInfo* f);
-    ~FieldAnnotationCollector();
-    AnnotationArray* field_annotations()      { return _field_annotations; }
-    AnnotationArray* field_type_annotations() { return _field_type_annotations; }
-
-    void set_field_annotations(AnnotationArray* a)      { _field_annotations = a; }
-    void set_field_type_annotations(AnnotationArray* a) { _field_type_annotations = a; }
-  };
-
-  class MethodAnnotationCollector: public AnnotationCollector {
-  public:
-    MethodAnnotationCollector() : AnnotationCollector(_in_method) { }
-    void apply_to(methodHandle m);
-  };
-  class ClassAnnotationCollector: public AnnotationCollector {
-  public:
-    ClassAnnotationCollector() : AnnotationCollector(_in_class) { }
-    void apply_to(instanceKlassHandle k);
-  };
-
-  enum { fixed_buffer_size = 128 };
-  u_char linenumbertable_buffer[fixed_buffer_size];
-
-  ClassFileStream* _stream;              // Actual input stream
-
-  enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
-
-  // Accessors
-  ClassFileStream* stream()                        { return _stream; }
-  void set_stream(ClassFileStream* st)             { _stream = st; }
+  void apply_parsed_class_attributes(InstanceKlass* k);  // update k
+  void apply_parsed_class_metadata(InstanceKlass* k, int fields_count, TRAPS);
+  void clear_class_metadata();
 
   // Constant pool parsing
-  void parse_constant_pool_entries(int length, TRAPS);
+  void parse_constant_pool_entries(const ClassFileStream* const stream,
+                                   ConstantPool* cp,
+                                   const int length,
+                                   TRAPS);
 
-  constantPoolHandle parse_constant_pool(TRAPS);
+  void parse_constant_pool(const ClassFileStream* const cfs,
+                           ConstantPool* const cp,
+                           const int length,
+                           TRAPS);
 
   // Interface parsing
-  Array<Klass*>* parse_interfaces(int length,
-                                  Handle protection_domain,
-                                  Symbol* class_name,
-                                  bool* has_default_methods,
-                                  TRAPS);
-  void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS);
+  void parse_interfaces(const ClassFileStream* const stream,
+                        const int itfs_len,
+                        ConstantPool* const cp,
+                        bool* has_default_methods,
+                        TRAPS);
 
-  instanceKlassHandle parse_super_class(int super_class_index, TRAPS);
+  const InstanceKlass* parse_super_class(ConstantPool* const cp,
+                                         const int super_class_index,
+                                         const bool need_verify,
+                                         TRAPS);
+
   // Field parsing
-  void parse_field_attributes(u2 attributes_count,
-                              bool is_static, u2 signature_index,
-                              u2* constantvalue_index_addr,
-                              bool* is_synthetic_addr,
-                              u2* generic_signature_index_addr,
+  void parse_field_attributes(const ClassFileStream* const cfs,
+                              u2 attributes_count,
+                              bool is_static,
+                              u2 signature_index,
+                              u2* const constantvalue_index_addr,
+                              bool* const is_synthetic_addr,
+                              u2* const generic_signature_index_addr,
                               FieldAnnotationCollector* parsed_annotations,
                               TRAPS);
-  Array<u2>* parse_fields(Symbol* class_name,
-                          bool is_interface,
-                          FieldAllocationCount *fac,
-                          u2* java_fields_count_ptr, TRAPS);
 
-  void print_field_layout(Symbol* name,
-                          Array<u2>* fields,
-                          const constantPoolHandle& cp,
-                          int instance_size,
-                          int instance_fields_start,
-                          int instance_fields_end,
-                          int static_fields_end);
+  void parse_fields(const ClassFileStream* const cfs,
+                    bool is_interface,
+                    FieldAllocationCount* const fac,
+                    ConstantPool* cp,
+                    const int cp_size,
+                    u2* const java_fields_count_ptr,
+                    TRAPS);
 
   // Method parsing
-  methodHandle parse_method(bool is_interface,
-                            AccessFlags* promoted_flags,
-                            TRAPS);
-  Array<Method*>* parse_methods(bool is_interface,
-                                AccessFlags* promoted_flags,
-                                bool* has_final_method,
-                                bool* declares_default_methods,
-                                TRAPS);
-  intArray* sort_methods(Array<Method*>* methods);
+  Method* parse_method(const ClassFileStream* const cfs,
+                       bool is_interface,
+                       const ConstantPool* cp,
+                       AccessFlags* const promoted_flags,
+                       TRAPS);
+
+  void parse_methods(const ClassFileStream* const cfs,
+                     bool is_interface,
+                     AccessFlags* const promoted_flags,
+                     bool* const has_final_method,
+                     bool* const declares_default_methods,
+                     TRAPS);
+
+  const u2* parse_exception_table(const ClassFileStream* const stream,
+                                  u4 code_length,
+                                  u4 exception_table_length,
+                                  TRAPS);
 
-  u2* parse_exception_table(u4 code_length, u4 exception_table_length,
-                            TRAPS);
-  void parse_linenumber_table(
-      u4 code_attribute_length, u4 code_length,
-      CompressedLineNumberWriteStream** write_stream, TRAPS);
-  u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
-                                u2* localvariable_table_length,
-                                bool isLVTT, TRAPS);
-  u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
-                               TRAPS);
-  void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
-                        u1* u1_array, u2* u2_array, TRAPS);
-  u1* parse_stackmap_table(u4 code_attribute_length, TRAPS);
+  void parse_linenumber_table(u4 code_attribute_length,
+                              u4 code_length,
+                              CompressedLineNumberWriteStream**const write_stream,
+                              TRAPS);
+
+  const u2* parse_localvariable_table(const ClassFileStream* const cfs,
+                                      u4 code_length,
+                                      u2 max_locals,
+                                      u4 code_attribute_length,
+                                      u2* const localvariable_table_length,
+                                      bool isLVTT,
+                                      TRAPS);
+
+  const u2* parse_checked_exceptions(const ClassFileStream* const cfs,
+                                     u2* const checked_exceptions_length,
+                                     u4 method_attribute_length,
+                                     TRAPS);
+
+  void parse_type_array(u2 array_length,
+                        u4 code_length,
+                        u4* const u1_index,
+                        u4* const u2_index,
+                        u1* const u1_array,
+                        u2* const u2_array,
+                        TRAPS);
 
   // Classfile attribute parsing
-  u2 parse_generic_signature_attribute(TRAPS);
-  void parse_classfile_sourcefile_attribute(TRAPS);
-  void parse_classfile_source_debug_extension_attribute(int length, TRAPS);
-  u2   parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start,
+  u2 parse_generic_signature_attribute(const ClassFileStream* const cfs, TRAPS);
+  void parse_classfile_sourcefile_attribute(const ClassFileStream* const cfs, TRAPS);
+  void parse_classfile_source_debug_extension_attribute(const ClassFileStream* const cfs,
+                                                        int length,
+                                                        TRAPS);
+
+  u2   parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs,
+                                               const u1* const inner_classes_attribute_start,
                                                bool parsed_enclosingmethod_attribute,
                                                u2 enclosing_method_class_index,
                                                u2 enclosing_method_method_index,
                                                TRAPS);
-  void parse_classfile_attributes(ClassAnnotationCollector* parsed_annotations,
+
+  void parse_classfile_attributes(const ClassFileStream* const cfs,
+                                  ConstantPool* cp,
+                                  ClassAnnotationCollector* parsed_annotations,
                                   TRAPS);
+
   void parse_classfile_synthetic_attribute(TRAPS);
-  void parse_classfile_signature_attribute(TRAPS);
-  void parse_classfile_bootstrap_methods_attribute(u4 attribute_length, TRAPS);
+  void parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS);
+  void parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs,
+                                                   ConstantPool* cp,
+                                                   u4 attribute_length,
+                                                   TRAPS);
 
   // Annotations handling
-  AnnotationArray* assemble_annotations(u1* runtime_visible_annotations,
+  AnnotationArray* assemble_annotations(const u1* const runtime_visible_annotations,
                                         int runtime_visible_annotations_length,
-                                        u1* runtime_invisible_annotations,
-                                        int runtime_invisible_annotations_length, TRAPS);
-  int skip_annotation(u1* buffer, int limit, int index);
-  int skip_annotation_value(u1* buffer, int limit, int index);
-  void parse_annotations(u1* buffer, int limit,
-                         /* Results (currently, only one result is supported): */
-                         AnnotationCollector* result);
+                                        const u1* const runtime_invisible_annotations,
+                                        int runtime_invisible_annotations_length,
+                                        TRAPS);
 
-  // Final setup
-  unsigned int compute_oop_map_count(instanceKlassHandle super,
-                                     unsigned int nonstatic_oop_count,
-                                     int first_nonstatic_oop_offset);
-  void fill_oop_maps(instanceKlassHandle k,
-                     unsigned int nonstatic_oop_map_count,
-                     int* nonstatic_oop_offsets,
-                     unsigned int* nonstatic_oop_counts);
-  void set_precomputed_flags(instanceKlassHandle k);
-  Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super,
-                                               Array<Klass*>* local_ifs, TRAPS);
+  void set_precomputed_flags(InstanceKlass* k);
 
   // Format checker methods
-  void classfile_parse_error(const char* msg, TRAPS);
-  void classfile_parse_error(const char* msg, int index, TRAPS);
-  void classfile_parse_error(const char* msg, const char *name, TRAPS);
-  void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
-  inline void guarantee_property(bool b, const char* msg, TRAPS) {
+  void classfile_parse_error(const char* msg, TRAPS) const;
+  void classfile_parse_error(const char* msg, int index, TRAPS) const;
+  void classfile_parse_error(const char* msg, const char *name, TRAPS) const;
+  void classfile_parse_error(const char* msg,
+                             int index,
+                             const char *name,
+                             TRAPS) const;
+
+  inline void guarantee_property(bool b, const char* msg, TRAPS) const {
     if (!b) { classfile_parse_error(msg, CHECK); }
   }
 
-  void report_assert_property_failure(const char* msg, TRAPS) PRODUCT_RETURN;
-  void report_assert_property_failure(const char* msg, int index, TRAPS) PRODUCT_RETURN;
+  void report_assert_property_failure(const char* msg, TRAPS) const PRODUCT_RETURN;
+  void report_assert_property_failure(const char* msg, int index, TRAPS) const PRODUCT_RETURN;
 
-  inline void assert_property(bool b, const char* msg, TRAPS) {
+  inline void assert_property(bool b, const char* msg, TRAPS) const {
 #ifdef ASSERT
     if (!b) {
       report_assert_property_failure(msg, THREAD);
@@ -330,7 +314,7 @@
 #endif
   }
 
-  inline void assert_property(bool b, const char* msg, int index, TRAPS) {
+  inline void assert_property(bool b, const char* msg, int index, TRAPS) const {
 #ifdef ASSERT
     if (!b) {
       report_assert_property_failure(msg, index, THREAD);
@@ -338,7 +322,10 @@
 #endif
   }
 
-  inline void check_property(bool property, const char* msg, int index, TRAPS) {
+  inline void check_property(bool property,
+                             const char* msg,
+                             int index,
+                             TRAPS) const {
     if (_need_verify) {
       guarantee_property(property, msg, index, CHECK);
     } else {
@@ -346,7 +333,7 @@
     }
   }
 
-  inline void check_property(bool property, const char* msg, TRAPS) {
+  inline void check_property(bool property, const char* msg, TRAPS) const {
     if (_need_verify) {
       guarantee_property(property, msg, CHECK);
     } else {
@@ -354,136 +341,177 @@
     }
   }
 
-  inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
+  inline void guarantee_property(bool b,
+                                 const char* msg,
+                                 int index,
+                                 TRAPS) const {
     if (!b) { classfile_parse_error(msg, index, CHECK); }
   }
-  inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
+
+  inline void guarantee_property(bool b,
+                                 const char* msg,
+                                 const char *name,
+                                 TRAPS) const {
     if (!b) { classfile_parse_error(msg, name, CHECK); }
   }
-  inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
+
+  inline void guarantee_property(bool b,
+                                 const char* msg,
+                                 int index,
+                                 const char *name,
+                                 TRAPS) const {
     if (!b) { classfile_parse_error(msg, index, name, CHECK); }
   }
 
-  void throwIllegalSignature(
-      const char* type, Symbol* name, Symbol* sig, TRAPS);
+  void throwIllegalSignature(const char* type,
+                             const Symbol* name,
+                             const Symbol* sig,
+                             TRAPS) const;
 
-  bool is_supported_version(u2 major, u2 minor);
-  bool has_illegal_visibility(jint flags);
+  void verify_constantvalue(const ConstantPool* const cp,
+                            int constantvalue_index,
+                            int signature_index,
+                            TRAPS) const;
+
+  void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const;
+  void verify_legal_class_name(const Symbol* name, TRAPS) const;
+  void verify_legal_field_name(const Symbol* name, TRAPS) const;
+  void verify_legal_method_name(const Symbol* name, TRAPS) const;
 
-  void verify_constantvalue(int constantvalue_index, int signature_index, TRAPS);
-  void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
-  void verify_legal_class_name(Symbol* name, TRAPS);
-  void verify_legal_field_name(Symbol* name, TRAPS);
-  void verify_legal_method_name(Symbol* name, TRAPS);
-  void verify_legal_field_signature(Symbol* fieldname, Symbol* signature, TRAPS);
-  int  verify_legal_method_signature(Symbol* methodname, Symbol* signature, TRAPS);
-  void verify_legal_class_modifiers(jint flags, TRAPS);
-  void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
-  void verify_legal_method_modifiers(jint flags, bool is_interface, Symbol* name, TRAPS);
-  bool verify_unqualified_name(char* name, unsigned int length, int type);
-  char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
-  char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
+  void verify_legal_field_signature(const Symbol* fieldname,
+                                    const Symbol* signature,
+                                    TRAPS) const;
+  int  verify_legal_method_signature(const Symbol* methodname,
+                                     const Symbol* signature,
+                                     TRAPS) const;
 
-  bool is_anonymous() {
-    return _host_klass.not_null();
-  }
-  bool has_cp_patch_at(int index) {
+  void verify_legal_class_modifiers(jint flags, TRAPS) const;
+  void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS) const;
+  void verify_legal_method_modifiers(jint flags,
+                                     bool is_interface,
+                                     const Symbol* name,
+                                     TRAPS) const;
+
+  const char* skip_over_field_signature(const char* signature,
+                                        bool void_ok,
+                                        unsigned int length,
+                                        TRAPS) const;
+
+  bool has_cp_patch_at(int index) const {
     assert(index >= 0, "oob");
     return (_cp_patches != NULL
             && index < _cp_patches->length()
             && _cp_patches->adr_at(index)->not_null());
   }
-  Handle cp_patch_at(int index) {
+
+  Handle cp_patch_at(int index) const {
     assert(has_cp_patch_at(index), "oob");
     return _cp_patches->at(index);
   }
+
   Handle clear_cp_patch_at(int index) {
     Handle patch = cp_patch_at(index);
     _cp_patches->at_put(index, Handle());
     assert(!has_cp_patch_at(index), "");
     return patch;
   }
-  void patch_constant_pool(const constantPoolHandle& cp, int index, Handle patch, TRAPS);
+
+  void patch_constant_pool(ConstantPool* cp,
+                           int index,
+                           Handle patch,
+                           TRAPS);
 
   // Wrapper for constantTag.is_klass_[or_]reference.
   // In older versions of the VM, Klass*s cannot sneak into early phases of
   // constant pool construction, but in later versions they can.
   // %%% Let's phase out the old is_klass_reference.
-  bool valid_klass_reference_at(int index) {
-    return _cp->is_within_bounds(index) && _cp->tag_at(index).is_klass_or_reference();
+  bool valid_klass_reference_at(int index) const {
+    return _cp->is_within_bounds(index) &&
+             _cp->tag_at(index).is_klass_or_reference();
   }
 
   // Checks that the cpool index is in range and is a utf8
-  bool valid_symbol_at(int cpool_index) {
-    return (_cp->is_within_bounds(cpool_index) &&
-            _cp->tag_at(cpool_index).is_utf8());
+  bool valid_symbol_at(int cpool_index) const {
+    return _cp->is_within_bounds(cpool_index) &&
+             _cp->tag_at(cpool_index).is_utf8();
   }
 
-  void copy_localvariable_table(ConstMethod* cm, int lvt_cnt,
-                                u2* localvariable_table_length,
-                                u2** localvariable_table_start,
+  void copy_localvariable_table(const ConstMethod* cm,
+                                int lvt_cnt,
+                                u2* const localvariable_table_length,
+                                const u2**const localvariable_table_start,
                                 int lvtt_cnt,
-                                u2* localvariable_type_table_length,
-                                u2** localvariable_type_table_start,
+                                u2* const localvariable_type_table_length,
+                                const u2** const localvariable_type_table_start,
                                 TRAPS);
 
   void copy_method_annotations(ConstMethod* cm,
-                               u1* runtime_visible_annotations,
+                               const u1* runtime_visible_annotations,
                                int runtime_visible_annotations_length,
-                               u1* runtime_invisible_annotations,
+                               const u1* runtime_invisible_annotations,
                                int runtime_invisible_annotations_length,
-                               u1* runtime_visible_parameter_annotations,
+                               const u1* runtime_visible_parameter_annotations,
                                int runtime_visible_parameter_annotations_length,
-                               u1* runtime_invisible_parameter_annotations,
+                               const u1* runtime_invisible_parameter_annotations,
                                int runtime_invisible_parameter_annotations_length,
-                               u1* runtime_visible_type_annotations,
+                               const u1* runtime_visible_type_annotations,
                                int runtime_visible_type_annotations_length,
-                               u1* runtime_invisible_type_annotations,
+                               const u1* runtime_invisible_type_annotations,
                                int runtime_invisible_type_annotations_length,
-                               u1* annotation_default,
+                               const u1* annotation_default,
                                int annotation_default_length,
                                TRAPS);
 
   // lays out fields in class and returns the total oopmap count
-  void layout_fields(Handle class_loader, FieldAllocationCount* fac,
-                     ClassAnnotationCollector* parsed_annotations,
-                     FieldLayoutInfo* info, TRAPS);
+  void layout_fields(ConstantPool* cp,
+                     const FieldAllocationCount* fac,
+                     const ClassAnnotationCollector* parsed_annotations,
+                     FieldLayoutInfo* info,
+                     TRAPS);
 
  public:
-  // Constructor
-  ClassFileParser(ClassFileStream* st) { set_stream(st); }
+  ClassFileParser(ClassFileStream* stream,
+                  Symbol* name,
+                  ClassLoaderData* loader_data,
+                  Handle protection_domain,
+                  TempNewSymbol* parsed_name,
+                  const Klass* host_klass,
+                  GrowableArray<Handle>* cp_patches,
+                  Publicity pub_level,
+                  TRAPS);
+
   ~ClassFileParser();
 
-  // Parse .class file and return new Klass*. The Klass* is not hooked up
-  // to the system dictionary or any other structures, so a .class file can
-  // be loaded several times if desired.
-  // The system dictionary hookup is done by the caller.
-  //
-  // "parsed_name" is updated by this method, and is the name found
-  // while parsing the stream.
-  instanceKlassHandle parseClassFile(Symbol* name,
-                                     ClassLoaderData* loader_data,
-                                     Handle protection_domain,
-                                     TempNewSymbol& parsed_name,
-                                     bool verify,
-                                     TRAPS) {
-    KlassHandle no_host_klass;
-    return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
-  }
-  instanceKlassHandle parseClassFile(Symbol* name,
-                                     ClassLoaderData* loader_data,
-                                     Handle protection_domain,
-                                     KlassHandle host_klass,
-                                     GrowableArray<Handle>* cp_patches,
-                                     TempNewSymbol& parsed_name,
-                                     bool verify,
-                                     TRAPS);
+  InstanceKlass* create_instance_klass(TRAPS);
+
+  const ClassFileStream* clone_stream() const;
+
+  void set_klass_to_deallocate(InstanceKlass* klass);
+
+  int static_field_size() const;
+  int total_oop_map_count() const;
+  jint layout_size() const;
+
+  int vtable_size() const { return _vtable_size; }
+  int itable_size() const { return _itable_size; }
 
-  // Verifier checks
-  static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
-  static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
-  static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
-  static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
+  u2 this_class_index() const { return _this_class_index; }
+  u2 super_class_index() const { return _super_class_index; }
+
+  bool is_anonymous() const { return _host_klass != NULL; }
+  bool is_interface() const { return _access_flags.is_interface(); }
+
+  const Klass* host_klass() const { return _host_klass; }
+  const GrowableArray<Handle>* cp_patches() const { return _cp_patches; }
+  ClassLoaderData* loader_data() const { return _loader_data; }
+  const Symbol* class_name() const { return _class_name; }
+  const Klass* super_klass() const { return _super_klass; }
+
+  ReferenceType reference_type() const { return _rt; }
+  AccessFlags access_flags() const { return _access_flags; }
+
+  bool is_internal() const { return INTERNAL == _pub_level; }
+
 };
 
 #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP