src/share/vm/classfile/classFileParser.hpp

Tue, 13 Mar 2012 13:50:48 -0400

author
jiangli
date
Tue, 13 Mar 2012 13:50:48 -0400
changeset 3670
f7c4174b33ba
parent 3373
cd5d8cafcc84
child 3686
749b1464aa81
permissions
-rw-r--r--

7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
Summary: Fold instanceKlass::_enclosing_method_class_index and instanceKlass::_enclosing_method_method_index into the instanceKlass::_inner_classes array.
Reviewed-by: never, coleenp
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>

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

mercurial