src/share/vm/classfile/classFileParser.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 866
a45484ea312d
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Parser for for .class files
duke@435 26 //
duke@435 27 // The bytes describing the class file structure is read from a Stream object
duke@435 28
duke@435 29 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
duke@435 30 private:
duke@435 31 bool _need_verify;
duke@435 32 bool _relax_verify;
duke@435 33 u2 _major_version;
duke@435 34 u2 _minor_version;
duke@435 35 symbolHandle _class_name;
duke@435 36
duke@435 37 bool _has_finalizer;
duke@435 38 bool _has_empty_finalizer;
duke@435 39 bool _has_vanilla_constructor;
duke@435 40
duke@435 41 enum { fixed_buffer_size = 128 };
duke@435 42 u_char linenumbertable_buffer[fixed_buffer_size];
duke@435 43
duke@435 44 ClassFileStream* _stream; // Actual input stream
duke@435 45
duke@435 46 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
duke@435 47
duke@435 48 // Accessors
duke@435 49 ClassFileStream* stream() { return _stream; }
duke@435 50 void set_stream(ClassFileStream* st) { _stream = st; }
duke@435 51
duke@435 52 // Constant pool parsing
duke@435 53 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
duke@435 54
duke@435 55 constantPoolHandle parse_constant_pool(TRAPS);
duke@435 56
duke@435 57 // Interface parsing
duke@435 58 objArrayHandle parse_interfaces(constantPoolHandle cp,
duke@435 59 int length,
duke@435 60 Handle class_loader,
duke@435 61 Handle protection_domain,
duke@435 62 PerfTraceTime* vmtimer,
duke@435 63 symbolHandle class_name,
duke@435 64 TRAPS);
duke@435 65
duke@435 66 // Field parsing
duke@435 67 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count,
duke@435 68 bool is_static, u2 signature_index,
duke@435 69 u2* constantvalue_index_addr,
duke@435 70 bool* is_synthetic_addr,
duke@435 71 u2* generic_signature_index_addr,
duke@435 72 typeArrayHandle* field_annotations, TRAPS);
duke@435 73 typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface,
duke@435 74 struct FieldAllocationCount *fac,
duke@435 75 objArrayHandle* fields_annotations, TRAPS);
duke@435 76
duke@435 77 // Method parsing
duke@435 78 methodHandle parse_method(constantPoolHandle cp, bool is_interface,
duke@435 79 AccessFlags* promoted_flags,
duke@435 80 typeArrayHandle* method_annotations,
duke@435 81 typeArrayHandle* method_parameter_annotations,
duke@435 82 typeArrayHandle* method_default_annotations,
duke@435 83 TRAPS);
duke@435 84 objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface,
duke@435 85 AccessFlags* promoted_flags,
duke@435 86 bool* has_final_method,
duke@435 87 objArrayOop* methods_annotations_oop,
duke@435 88 objArrayOop* methods_parameter_annotations_oop,
duke@435 89 objArrayOop* methods_default_annotations_oop,
duke@435 90 TRAPS);
duke@435 91 typeArrayHandle sort_methods (objArrayHandle methods,
duke@435 92 objArrayHandle methods_annotations,
duke@435 93 objArrayHandle methods_parameter_annotations,
duke@435 94 objArrayHandle methods_default_annotations,
duke@435 95 TRAPS);
duke@435 96 typeArrayHandle parse_exception_table(u4 code_length, u4 exception_table_length,
duke@435 97 constantPoolHandle cp, TRAPS);
duke@435 98 void parse_linenumber_table(
duke@435 99 u4 code_attribute_length, u4 code_length,
duke@435 100 CompressedLineNumberWriteStream** write_stream, TRAPS);
duke@435 101 u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
duke@435 102 constantPoolHandle cp, u2* localvariable_table_length,
duke@435 103 bool isLVTT, TRAPS);
duke@435 104 u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
duke@435 105 constantPoolHandle cp, TRAPS);
duke@435 106 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
duke@435 107 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS);
duke@435 108 typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS);
duke@435 109
duke@435 110 // Classfile attribute parsing
duke@435 111 void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 112 void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
duke@435 113 instanceKlassHandle k, int length, TRAPS);
duke@435 114 u2 parse_classfile_inner_classes_attribute(constantPoolHandle cp,
duke@435 115 instanceKlassHandle k, TRAPS);
duke@435 116 void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 117 void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 118 void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 119
duke@435 120 // Annotations handling
duke@435 121 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations,
duke@435 122 int runtime_visible_annotations_length,
duke@435 123 u1* runtime_invisible_annotations,
duke@435 124 int runtime_invisible_annotations_length, TRAPS);
duke@435 125
duke@435 126 // Final setup
duke@435 127 int compute_oop_map_size(instanceKlassHandle super, int nonstatic_oop_count,
duke@435 128 int first_nonstatic_oop_offset);
duke@435 129 void fill_oop_maps(instanceKlassHandle k, int nonstatic_oop_map_count,
duke@435 130 u2* nonstatic_oop_offsets, u2* nonstatic_oop_length);
duke@435 131 void set_precomputed_flags(instanceKlassHandle k);
duke@435 132 objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
duke@435 133 objArrayHandle local_ifs, TRAPS);
duke@435 134
duke@435 135 // Special handling for certain classes.
duke@435 136 // Add the "discovered" field to java.lang.ref.Reference if
duke@435 137 // it does not exist.
duke@435 138 void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
duke@435 139 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS);
duke@435 140 // Adjust the field allocation counts for java.lang.Class to add
duke@435 141 // fake fields.
duke@435 142 void java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
duke@435 143 FieldAllocationCount *fac_ptr, TRAPS);
duke@435 144 // Adjust the next_nonstatic_oop_offset to place the fake fields
duke@435 145 // before any Java fields.
duke@435 146 void java_lang_Class_fix_post(int* next_nonstatic_oop_offset);
duke@435 147
duke@435 148 // Format checker methods
duke@435 149 void classfile_parse_error(const char* msg, TRAPS);
duke@435 150 void classfile_parse_error(const char* msg, int index, TRAPS);
duke@435 151 void classfile_parse_error(const char* msg, const char *name, TRAPS);
duke@435 152 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
duke@435 153 inline void guarantee_property(bool b, const char* msg, TRAPS) {
duke@435 154 if (!b) { classfile_parse_error(msg, CHECK); }
duke@435 155 }
duke@435 156
duke@435 157 inline void assert_property(bool b, const char* msg, TRAPS) {
duke@435 158 #ifdef ASSERT
duke@435 159 if (!b) { fatal(msg); }
duke@435 160 #endif
duke@435 161 }
duke@435 162
duke@435 163 inline void check_property(bool property, const char* msg, int index, TRAPS) {
duke@435 164 if (_need_verify) {
duke@435 165 guarantee_property(property, msg, index, CHECK);
duke@435 166 } else {
duke@435 167 assert_property(property, msg, CHECK);
duke@435 168 }
duke@435 169 }
duke@435 170
duke@435 171 inline void check_property(bool property, const char* msg, TRAPS) {
duke@435 172 if (_need_verify) {
duke@435 173 guarantee_property(property, msg, CHECK);
duke@435 174 } else {
duke@435 175 assert_property(property, msg, CHECK);
duke@435 176 }
duke@435 177 }
duke@435 178
duke@435 179 inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
duke@435 180 if (!b) { classfile_parse_error(msg, index, CHECK); }
duke@435 181 }
duke@435 182 inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
duke@435 183 if (!b) { classfile_parse_error(msg, name, CHECK); }
duke@435 184 }
duke@435 185 inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
duke@435 186 if (!b) { classfile_parse_error(msg, index, name, CHECK); }
duke@435 187 }
duke@435 188
duke@435 189 bool is_supported_version(u2 major, u2 minor);
duke@435 190 bool has_illegal_visibility(jint flags);
duke@435 191
duke@435 192 void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
duke@435 193 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
duke@435 194 void verify_legal_class_name(symbolHandle name, TRAPS);
duke@435 195 void verify_legal_field_name(symbolHandle name, TRAPS);
duke@435 196 void verify_legal_method_name(symbolHandle name, TRAPS);
duke@435 197 void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
duke@435 198 int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
duke@435 199 void verify_legal_class_modifiers(jint flags, TRAPS);
duke@435 200 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
duke@435 201 void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
duke@435 202 bool verify_unqualified_name(char* name, unsigned int length, int type);
duke@435 203 char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
duke@435 204 char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
duke@435 205
duke@435 206 public:
duke@435 207 // Constructor
duke@435 208 ClassFileParser(ClassFileStream* st) { set_stream(st); }
duke@435 209
duke@435 210 // Parse .class file and return new klassOop. The klassOop is not hooked up
duke@435 211 // to the system dictionary or any other structures, so a .class file can
duke@435 212 // be loaded several times if desired.
duke@435 213 // The system dictionary hookup is done by the caller.
duke@435 214 //
duke@435 215 // "parsed_name" is updated by this method, and is the name found
duke@435 216 // while parsing the stream.
duke@435 217 instanceKlassHandle parseClassFile(symbolHandle name,
duke@435 218 Handle class_loader,
duke@435 219 Handle protection_domain,
duke@435 220 symbolHandle& parsed_name,
duke@435 221 TRAPS);
duke@435 222
duke@435 223 // Verifier checks
duke@435 224 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
duke@435 225 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
duke@435 226 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
duke@435 227 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
duke@435 228 };

mercurial