annotate src/share/vm/classfile/classFileParser.hpp @ 500:ad8c8ca4ab0f

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