src/share/vm/classfile/classFileParser.hpp

Sat, 30 Oct 2010 13:08:23 -0700

author
jrose
date
Sat, 30 Oct 2010 13:08:23 -0700
changeset 2268
3b2dea75431e
parent 2264
d2e35ffae982
child 2314
f95d63e2154a
permissions
-rw-r--r--

6984311: JSR 292 needs optional bootstrap method parameters
Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands.
Reviewed-by: twisti

duke@435 1 /*
twisti@2264 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * 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;
jrose@1145 36 KlassHandle _host_klass;
jrose@866 37 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
duke@435 38
duke@435 39 bool _has_finalizer;
duke@435 40 bool _has_empty_finalizer;
duke@435 41 bool _has_vanilla_constructor;
duke@435 42
duke@435 43 enum { fixed_buffer_size = 128 };
duke@435 44 u_char linenumbertable_buffer[fixed_buffer_size];
duke@435 45
duke@435 46 ClassFileStream* _stream; // Actual input stream
duke@435 47
duke@435 48 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
duke@435 49
duke@435 50 // Accessors
duke@435 51 ClassFileStream* stream() { return _stream; }
duke@435 52 void set_stream(ClassFileStream* st) { _stream = st; }
duke@435 53
duke@435 54 // Constant pool parsing
duke@435 55 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
duke@435 56
duke@435 57 constantPoolHandle parse_constant_pool(TRAPS);
duke@435 58
jrose@2268 59 static int start_operand_group(GrowableArray<int>* &operands, int op_count, TRAPS);
jrose@2268 60 static void store_operand_array(GrowableArray<int>* operands, constantPoolHandle cp, TRAPS);
jrose@2268 61
duke@435 62 // Interface parsing
duke@435 63 objArrayHandle parse_interfaces(constantPoolHandle cp,
duke@435 64 int length,
duke@435 65 Handle class_loader,
duke@435 66 Handle protection_domain,
duke@435 67 symbolHandle class_name,
duke@435 68 TRAPS);
duke@435 69
duke@435 70 // Field parsing
duke@435 71 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count,
duke@435 72 bool is_static, u2 signature_index,
duke@435 73 u2* constantvalue_index_addr,
duke@435 74 bool* is_synthetic_addr,
duke@435 75 u2* generic_signature_index_addr,
duke@435 76 typeArrayHandle* field_annotations, TRAPS);
duke@435 77 typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface,
duke@435 78 struct FieldAllocationCount *fac,
duke@435 79 objArrayHandle* fields_annotations, TRAPS);
duke@435 80
duke@435 81 // Method parsing
duke@435 82 methodHandle parse_method(constantPoolHandle cp, bool is_interface,
duke@435 83 AccessFlags* promoted_flags,
duke@435 84 typeArrayHandle* method_annotations,
duke@435 85 typeArrayHandle* method_parameter_annotations,
duke@435 86 typeArrayHandle* method_default_annotations,
duke@435 87 TRAPS);
duke@435 88 objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface,
duke@435 89 AccessFlags* promoted_flags,
duke@435 90 bool* has_final_method,
duke@435 91 objArrayOop* methods_annotations_oop,
duke@435 92 objArrayOop* methods_parameter_annotations_oop,
duke@435 93 objArrayOop* methods_default_annotations_oop,
duke@435 94 TRAPS);
duke@435 95 typeArrayHandle sort_methods (objArrayHandle methods,
duke@435 96 objArrayHandle methods_annotations,
duke@435 97 objArrayHandle methods_parameter_annotations,
duke@435 98 objArrayHandle methods_default_annotations,
duke@435 99 TRAPS);
duke@435 100 typeArrayHandle parse_exception_table(u4 code_length, u4 exception_table_length,
duke@435 101 constantPoolHandle cp, TRAPS);
duke@435 102 void parse_linenumber_table(
duke@435 103 u4 code_attribute_length, u4 code_length,
duke@435 104 CompressedLineNumberWriteStream** write_stream, TRAPS);
duke@435 105 u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
duke@435 106 constantPoolHandle cp, u2* localvariable_table_length,
duke@435 107 bool isLVTT, TRAPS);
duke@435 108 u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
duke@435 109 constantPoolHandle cp, TRAPS);
duke@435 110 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
duke@435 111 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS);
duke@435 112 typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS);
duke@435 113
duke@435 114 // Classfile attribute parsing
duke@435 115 void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 116 void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
duke@435 117 instanceKlassHandle k, int length, TRAPS);
duke@435 118 u2 parse_classfile_inner_classes_attribute(constantPoolHandle cp,
duke@435 119 instanceKlassHandle k, TRAPS);
duke@435 120 void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 121 void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 122 void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
duke@435 123
duke@435 124 // Annotations handling
duke@435 125 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations,
duke@435 126 int runtime_visible_annotations_length,
duke@435 127 u1* runtime_invisible_annotations,
duke@435 128 int runtime_invisible_annotations_length, TRAPS);
duke@435 129
duke@435 130 // Final setup
jcoomes@1374 131 unsigned int compute_oop_map_count(instanceKlassHandle super,
jcoomes@1374 132 unsigned int nonstatic_oop_count,
jcoomes@1374 133 int first_nonstatic_oop_offset);
jcoomes@1374 134 void fill_oop_maps(instanceKlassHandle k,
jcoomes@1374 135 unsigned int nonstatic_oop_map_count,
jcoomes@1374 136 int* nonstatic_oop_offsets,
jcoomes@1374 137 unsigned int* nonstatic_oop_counts);
duke@435 138 void set_precomputed_flags(instanceKlassHandle k);
duke@435 139 objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
duke@435 140 objArrayHandle local_ifs, TRAPS);
duke@435 141
duke@435 142 // Special handling for certain classes.
duke@435 143 // Add the "discovered" field to java.lang.ref.Reference if
duke@435 144 // it does not exist.
duke@435 145 void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
duke@435 146 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS);
duke@435 147 // Adjust the field allocation counts for java.lang.Class to add
duke@435 148 // fake fields.
duke@435 149 void java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
duke@435 150 FieldAllocationCount *fac_ptr, TRAPS);
duke@435 151 // Adjust the next_nonstatic_oop_offset to place the fake fields
duke@435 152 // before any Java fields.
duke@435 153 void java_lang_Class_fix_post(int* next_nonstatic_oop_offset);
jrose@1145 154 // Adjust the field allocation counts for java.dyn.MethodHandle to add
jrose@1145 155 // a fake address (void*) field.
jrose@1145 156 void java_dyn_MethodHandle_fix_pre(constantPoolHandle cp,
twisti@2264 157 typeArrayHandle fields,
jrose@1145 158 FieldAllocationCount *fac_ptr, TRAPS);
duke@435 159
duke@435 160 // Format checker methods
duke@435 161 void classfile_parse_error(const char* msg, TRAPS);
duke@435 162 void classfile_parse_error(const char* msg, int index, TRAPS);
duke@435 163 void classfile_parse_error(const char* msg, const char *name, TRAPS);
duke@435 164 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
duke@435 165 inline void guarantee_property(bool b, const char* msg, TRAPS) {
duke@435 166 if (!b) { classfile_parse_error(msg, CHECK); }
duke@435 167 }
duke@435 168
duke@435 169 inline void assert_property(bool b, const char* msg, TRAPS) {
duke@435 170 #ifdef ASSERT
duke@435 171 if (!b) { fatal(msg); }
duke@435 172 #endif
duke@435 173 }
duke@435 174
duke@435 175 inline void check_property(bool property, const char* msg, int index, TRAPS) {
duke@435 176 if (_need_verify) {
duke@435 177 guarantee_property(property, msg, index, CHECK);
duke@435 178 } else {
duke@435 179 assert_property(property, msg, CHECK);
duke@435 180 }
duke@435 181 }
duke@435 182
duke@435 183 inline void check_property(bool property, const char* msg, TRAPS) {
duke@435 184 if (_need_verify) {
duke@435 185 guarantee_property(property, msg, CHECK);
duke@435 186 } else {
duke@435 187 assert_property(property, msg, CHECK);
duke@435 188 }
duke@435 189 }
duke@435 190
duke@435 191 inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
duke@435 192 if (!b) { classfile_parse_error(msg, index, CHECK); }
duke@435 193 }
duke@435 194 inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
duke@435 195 if (!b) { classfile_parse_error(msg, name, CHECK); }
duke@435 196 }
duke@435 197 inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
duke@435 198 if (!b) { classfile_parse_error(msg, index, name, CHECK); }
duke@435 199 }
duke@435 200
kamg@1941 201 void throwIllegalSignature(
kamg@1941 202 const char* type, symbolHandle name, symbolHandle sig, TRAPS);
kamg@1941 203
duke@435 204 bool is_supported_version(u2 major, u2 minor);
duke@435 205 bool has_illegal_visibility(jint flags);
duke@435 206
duke@435 207 void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
duke@435 208 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
duke@435 209 void verify_legal_class_name(symbolHandle name, TRAPS);
duke@435 210 void verify_legal_field_name(symbolHandle name, TRAPS);
duke@435 211 void verify_legal_method_name(symbolHandle name, TRAPS);
duke@435 212 void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
duke@435 213 int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
duke@435 214 void verify_legal_class_modifiers(jint flags, TRAPS);
duke@435 215 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
duke@435 216 void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
duke@435 217 bool verify_unqualified_name(char* name, unsigned int length, int type);
duke@435 218 char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
duke@435 219 char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
duke@435 220
jrose@1145 221 bool is_anonymous() {
jrose@1145 222 assert(AnonymousClasses || _host_klass.is_null(), "");
jrose@1145 223 return _host_klass.not_null();
jrose@1145 224 }
jrose@866 225 bool has_cp_patch_at(int index) {
jrose@866 226 assert(AnonymousClasses, "");
jrose@866 227 assert(index >= 0, "oob");
jrose@866 228 return (_cp_patches != NULL
jrose@866 229 && index < _cp_patches->length()
jrose@866 230 && _cp_patches->adr_at(index)->not_null());
jrose@866 231 }
jrose@866 232 Handle cp_patch_at(int index) {
jrose@866 233 assert(has_cp_patch_at(index), "oob");
jrose@866 234 return _cp_patches->at(index);
jrose@866 235 }
jrose@866 236 Handle clear_cp_patch_at(int index) {
jrose@866 237 Handle patch = cp_patch_at(index);
jrose@866 238 _cp_patches->at_put(index, Handle());
jrose@866 239 assert(!has_cp_patch_at(index), "");
jrose@866 240 return patch;
jrose@866 241 }
jrose@866 242 void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS);
jrose@866 243
jrose@866 244 // Wrapper for constantTag.is_klass_[or_]reference.
jrose@866 245 // In older versions of the VM, klassOops cannot sneak into early phases of
jrose@866 246 // constant pool construction, but in later versions they can.
jrose@866 247 // %%% Let's phase out the old is_klass_reference.
jrose@866 248 bool is_klass_reference(constantPoolHandle cp, int index) {
jrose@866 249 return ((LinkWellKnownClasses || AnonymousClasses)
jrose@866 250 ? cp->tag_at(index).is_klass_or_reference()
jrose@866 251 : cp->tag_at(index).is_klass_reference());
jrose@866 252 }
jrose@866 253
duke@435 254 public:
duke@435 255 // Constructor
duke@435 256 ClassFileParser(ClassFileStream* st) { set_stream(st); }
duke@435 257
duke@435 258 // Parse .class file and return new klassOop. The klassOop is not hooked up
duke@435 259 // to the system dictionary or any other structures, so a .class file can
duke@435 260 // be loaded several times if desired.
duke@435 261 // The system dictionary hookup is done by the caller.
duke@435 262 //
duke@435 263 // "parsed_name" is updated by this method, and is the name found
duke@435 264 // while parsing the stream.
duke@435 265 instanceKlassHandle parseClassFile(symbolHandle name,
duke@435 266 Handle class_loader,
duke@435 267 Handle protection_domain,
duke@435 268 symbolHandle& parsed_name,
acorn@1408 269 bool verify,
jrose@866 270 TRAPS) {
jrose@1145 271 KlassHandle no_host_klass;
acorn@1408 272 return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
jrose@866 273 }
jrose@866 274 instanceKlassHandle parseClassFile(symbolHandle name,
jrose@866 275 Handle class_loader,
jrose@866 276 Handle protection_domain,
jrose@1145 277 KlassHandle host_klass,
jrose@866 278 GrowableArray<Handle>* cp_patches,
jrose@866 279 symbolHandle& parsed_name,
acorn@1408 280 bool verify,
duke@435 281 TRAPS);
duke@435 282
duke@435 283 // Verifier checks
duke@435 284 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
duke@435 285 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
duke@435 286 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
duke@435 287 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
duke@435 288 };

mercurial