src/share/vm/classfile/classFileParser.hpp

changeset 435
a61af66fc99e
child 866
a45484ea312d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/classfile/classFileParser.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,228 @@
     1.4 +/*
     1.5 + * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// Parser for for .class files
    1.29 +//
    1.30 +// The bytes describing the class file structure is read from a Stream object
    1.31 +
    1.32 +class ClassFileParser VALUE_OBJ_CLASS_SPEC {
    1.33 + private:
    1.34 +  bool _need_verify;
    1.35 +  bool _relax_verify;
    1.36 +  u2   _major_version;
    1.37 +  u2   _minor_version;
    1.38 +  symbolHandle _class_name;
    1.39 +
    1.40 +  bool _has_finalizer;
    1.41 +  bool _has_empty_finalizer;
    1.42 +  bool _has_vanilla_constructor;
    1.43 +
    1.44 +  enum { fixed_buffer_size = 128 };
    1.45 +  u_char linenumbertable_buffer[fixed_buffer_size];
    1.46 +
    1.47 +  ClassFileStream* _stream;              // Actual input stream
    1.48 +
    1.49 +  enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
    1.50 +
    1.51 +  // Accessors
    1.52 +  ClassFileStream* stream()                        { return _stream; }
    1.53 +  void set_stream(ClassFileStream* st)             { _stream = st; }
    1.54 +
    1.55 +  // Constant pool parsing
    1.56 +  void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
    1.57 +
    1.58 +  constantPoolHandle parse_constant_pool(TRAPS);
    1.59 +
    1.60 +  // Interface parsing
    1.61 +  objArrayHandle parse_interfaces(constantPoolHandle cp,
    1.62 +                                  int length,
    1.63 +                                  Handle class_loader,
    1.64 +                                  Handle protection_domain,
    1.65 +                                  PerfTraceTime* vmtimer,
    1.66 +                                  symbolHandle class_name,
    1.67 +                                  TRAPS);
    1.68 +
    1.69 +  // Field parsing
    1.70 +  void parse_field_attributes(constantPoolHandle cp, u2 attributes_count,
    1.71 +                              bool is_static, u2 signature_index,
    1.72 +                              u2* constantvalue_index_addr,
    1.73 +                              bool* is_synthetic_addr,
    1.74 +                              u2* generic_signature_index_addr,
    1.75 +                              typeArrayHandle* field_annotations, TRAPS);
    1.76 +  typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface,
    1.77 +                               struct FieldAllocationCount *fac,
    1.78 +                               objArrayHandle* fields_annotations, TRAPS);
    1.79 +
    1.80 +  // Method parsing
    1.81 +  methodHandle parse_method(constantPoolHandle cp, bool is_interface,
    1.82 +                            AccessFlags* promoted_flags,
    1.83 +                            typeArrayHandle* method_annotations,
    1.84 +                            typeArrayHandle* method_parameter_annotations,
    1.85 +                            typeArrayHandle* method_default_annotations,
    1.86 +                            TRAPS);
    1.87 +  objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface,
    1.88 +                                AccessFlags* promoted_flags,
    1.89 +                                bool* has_final_method,
    1.90 +                                objArrayOop* methods_annotations_oop,
    1.91 +                                objArrayOop* methods_parameter_annotations_oop,
    1.92 +                                objArrayOop* methods_default_annotations_oop,
    1.93 +                                TRAPS);
    1.94 +  typeArrayHandle sort_methods (objArrayHandle methods,
    1.95 +                                objArrayHandle methods_annotations,
    1.96 +                                objArrayHandle methods_parameter_annotations,
    1.97 +                                objArrayHandle methods_default_annotations,
    1.98 +                                TRAPS);
    1.99 +  typeArrayHandle parse_exception_table(u4 code_length, u4 exception_table_length,
   1.100 +                                        constantPoolHandle cp, TRAPS);
   1.101 +  void parse_linenumber_table(
   1.102 +      u4 code_attribute_length, u4 code_length,
   1.103 +      CompressedLineNumberWriteStream** write_stream, TRAPS);
   1.104 +  u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
   1.105 +                                constantPoolHandle cp, u2* localvariable_table_length,
   1.106 +                                bool isLVTT, TRAPS);
   1.107 +  u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
   1.108 +                               constantPoolHandle cp, TRAPS);
   1.109 +  void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
   1.110 +                        u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS);
   1.111 +  typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS);
   1.112 +
   1.113 +  // Classfile attribute parsing
   1.114 +  void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
   1.115 +  void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
   1.116 +                                                instanceKlassHandle k, int length, TRAPS);
   1.117 +  u2   parse_classfile_inner_classes_attribute(constantPoolHandle cp,
   1.118 +                                               instanceKlassHandle k, TRAPS);
   1.119 +  void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
   1.120 +  void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
   1.121 +  void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
   1.122 +
   1.123 +  // Annotations handling
   1.124 +  typeArrayHandle assemble_annotations(u1* runtime_visible_annotations,
   1.125 +                                       int runtime_visible_annotations_length,
   1.126 +                                       u1* runtime_invisible_annotations,
   1.127 +                                       int runtime_invisible_annotations_length, TRAPS);
   1.128 +
   1.129 +  // Final setup
   1.130 +  int  compute_oop_map_size(instanceKlassHandle super, int nonstatic_oop_count,
   1.131 +                            int first_nonstatic_oop_offset);
   1.132 +  void fill_oop_maps(instanceKlassHandle k, int nonstatic_oop_map_count,
   1.133 +                     u2* nonstatic_oop_offsets, u2* nonstatic_oop_length);
   1.134 +  void set_precomputed_flags(instanceKlassHandle k);
   1.135 +  objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
   1.136 +                                               objArrayHandle local_ifs, TRAPS);
   1.137 +
   1.138 +  // Special handling for certain classes.
   1.139 +  // Add the "discovered" field to java.lang.ref.Reference if
   1.140 +  // it does not exist.
   1.141 +  void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
   1.142 +    constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS);
   1.143 +  // Adjust the field allocation counts for java.lang.Class to add
   1.144 +  // fake fields.
   1.145 +  void java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
   1.146 +    FieldAllocationCount *fac_ptr, TRAPS);
   1.147 +  // Adjust the next_nonstatic_oop_offset to place the fake fields
   1.148 +  // before any Java fields.
   1.149 +  void java_lang_Class_fix_post(int* next_nonstatic_oop_offset);
   1.150 +
   1.151 +  // Format checker methods
   1.152 +  void classfile_parse_error(const char* msg, TRAPS);
   1.153 +  void classfile_parse_error(const char* msg, int index, TRAPS);
   1.154 +  void classfile_parse_error(const char* msg, const char *name, TRAPS);
   1.155 +  void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
   1.156 +  inline void guarantee_property(bool b, const char* msg, TRAPS) {
   1.157 +    if (!b) { classfile_parse_error(msg, CHECK); }
   1.158 +  }
   1.159 +
   1.160 +  inline void assert_property(bool b, const char* msg, TRAPS) {
   1.161 +#ifdef ASSERT
   1.162 +    if (!b) { fatal(msg); }
   1.163 +#endif
   1.164 +  }
   1.165 +
   1.166 +  inline void check_property(bool property, const char* msg, int index, TRAPS) {
   1.167 +    if (_need_verify) {
   1.168 +      guarantee_property(property, msg, index, CHECK);
   1.169 +    } else {
   1.170 +      assert_property(property, msg, CHECK);
   1.171 +    }
   1.172 +  }
   1.173 +
   1.174 +  inline void check_property(bool property, const char* msg, TRAPS) {
   1.175 +    if (_need_verify) {
   1.176 +      guarantee_property(property, msg, CHECK);
   1.177 +    } else {
   1.178 +      assert_property(property, msg, CHECK);
   1.179 +    }
   1.180 +  }
   1.181 +
   1.182 +  inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
   1.183 +    if (!b) { classfile_parse_error(msg, index, CHECK); }
   1.184 +  }
   1.185 +  inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
   1.186 +    if (!b) { classfile_parse_error(msg, name, CHECK); }
   1.187 +  }
   1.188 +  inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
   1.189 +    if (!b) { classfile_parse_error(msg, index, name, CHECK); }
   1.190 +  }
   1.191 +
   1.192 +  bool is_supported_version(u2 major, u2 minor);
   1.193 +  bool has_illegal_visibility(jint flags);
   1.194 +
   1.195 +  void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
   1.196 +  void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
   1.197 +  void verify_legal_class_name(symbolHandle name, TRAPS);
   1.198 +  void verify_legal_field_name(symbolHandle name, TRAPS);
   1.199 +  void verify_legal_method_name(symbolHandle name, TRAPS);
   1.200 +  void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
   1.201 +  int  verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
   1.202 +  void verify_legal_class_modifiers(jint flags, TRAPS);
   1.203 +  void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
   1.204 +  void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
   1.205 +  bool verify_unqualified_name(char* name, unsigned int length, int type);
   1.206 +  char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
   1.207 +  char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
   1.208 +
   1.209 + public:
   1.210 +  // Constructor
   1.211 +  ClassFileParser(ClassFileStream* st) { set_stream(st); }
   1.212 +
   1.213 +  // Parse .class file and return new klassOop. The klassOop is not hooked up
   1.214 +  // to the system dictionary or any other structures, so a .class file can
   1.215 +  // be loaded several times if desired.
   1.216 +  // The system dictionary hookup is done by the caller.
   1.217 +  //
   1.218 +  // "parsed_name" is updated by this method, and is the name found
   1.219 +  // while parsing the stream.
   1.220 +  instanceKlassHandle parseClassFile(symbolHandle name,
   1.221 +                                     Handle class_loader,
   1.222 +                                     Handle protection_domain,
   1.223 +                                     symbolHandle& parsed_name,
   1.224 +                                     TRAPS);
   1.225 +
   1.226 +  // Verifier checks
   1.227 +  static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
   1.228 +  static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
   1.229 +  static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
   1.230 +  static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
   1.231 +};

mercurial