src/share/vm/classfile/classFileParser.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 8856
ac27a9c85bea
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
aoqi@0 26 #define SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
aoqi@0 27
aoqi@0 28 #include "classfile/classFileStream.hpp"
aoqi@0 29 #include "memory/resourceArea.hpp"
aoqi@0 30 #include "oops/oop.inline.hpp"
aoqi@0 31 #include "oops/typeArrayOop.hpp"
aoqi@0 32 #include "runtime/handles.inline.hpp"
aoqi@0 33 #include "utilities/accessFlags.hpp"
aoqi@0 34 #include "classfile/symbolTable.hpp"
aoqi@0 35
aoqi@0 36 class FieldAllocationCount;
aoqi@0 37 class FieldLayoutInfo;
aoqi@0 38
aoqi@0 39
aoqi@0 40 // Parser for for .class files
aoqi@0 41 //
aoqi@0 42 // The bytes describing the class file structure is read from a Stream object
aoqi@0 43
aoqi@0 44 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
aoqi@0 45 private:
aoqi@0 46 bool _need_verify;
aoqi@0 47 bool _relax_verify;
aoqi@0 48 u2 _major_version;
aoqi@0 49 u2 _minor_version;
aoqi@0 50 Symbol* _class_name;
aoqi@0 51 ClassLoaderData* _loader_data;
aoqi@0 52 KlassHandle _host_klass;
aoqi@0 53 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
aoqi@0 54
aoqi@0 55 // precomputed flags
aoqi@0 56 bool _has_finalizer;
aoqi@0 57 bool _has_empty_finalizer;
aoqi@0 58 bool _has_vanilla_constructor;
aoqi@0 59 int _max_bootstrap_specifier_index; // detects BSS values
aoqi@0 60
aoqi@0 61 // class attributes parsed before the instance klass is created:
aoqi@0 62 bool _synthetic_flag;
aoqi@0 63 int _sde_length;
aoqi@0 64 char* _sde_buffer;
aoqi@0 65 u2 _sourcefile_index;
aoqi@0 66 u2 _generic_signature_index;
aoqi@0 67
aoqi@0 68 // Metadata created before the instance klass is created. Must be deallocated
aoqi@0 69 // if not transferred to the InstanceKlass upon successful class loading
aoqi@0 70 // in which case these pointers have been set to NULL.
aoqi@0 71 instanceKlassHandle _super_klass;
aoqi@0 72 ConstantPool* _cp;
aoqi@0 73 Array<u2>* _fields;
aoqi@0 74 Array<Method*>* _methods;
aoqi@0 75 Array<u2>* _inner_classes;
aoqi@0 76 Array<Klass*>* _local_interfaces;
aoqi@0 77 Array<Klass*>* _transitive_interfaces;
stefank@7417 78 Annotations* _combined_annotations;
aoqi@0 79 AnnotationArray* _annotations;
aoqi@0 80 AnnotationArray* _type_annotations;
aoqi@0 81 Array<AnnotationArray*>* _fields_annotations;
aoqi@0 82 Array<AnnotationArray*>* _fields_type_annotations;
aoqi@0 83 InstanceKlass* _klass; // InstanceKlass once created.
aoqi@0 84
aoqi@0 85 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
aoqi@0 86 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
aoqi@0 87 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
aoqi@0 88 void set_class_sde_buffer(char* x, int len) { _sde_buffer = x; _sde_length = len; }
aoqi@0 89
stefank@7417 90 void create_combined_annotations(TRAPS);
stefank@7417 91
aoqi@0 92 void init_parsed_class_attributes(ClassLoaderData* loader_data) {
aoqi@0 93 _loader_data = loader_data;
aoqi@0 94 _synthetic_flag = false;
aoqi@0 95 _sourcefile_index = 0;
aoqi@0 96 _generic_signature_index = 0;
aoqi@0 97 _sde_buffer = NULL;
aoqi@0 98 _sde_length = 0;
aoqi@0 99 // initialize the other flags too:
aoqi@0 100 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
aoqi@0 101 _max_bootstrap_specifier_index = -1;
aoqi@0 102 clear_class_metadata();
aoqi@0 103 _klass = NULL;
aoqi@0 104 }
aoqi@0 105 void apply_parsed_class_attributes(instanceKlassHandle k); // update k
aoqi@0 106 void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS);
aoqi@0 107 void clear_class_metadata() {
aoqi@0 108 // metadata created before the instance klass is created. Must be
aoqi@0 109 // deallocated if classfile parsing returns an error.
aoqi@0 110 _cp = NULL;
aoqi@0 111 _fields = NULL;
aoqi@0 112 _methods = NULL;
aoqi@0 113 _inner_classes = NULL;
aoqi@0 114 _local_interfaces = NULL;
aoqi@0 115 _transitive_interfaces = NULL;
stefank@7417 116 _combined_annotations = NULL;
aoqi@0 117 _annotations = _type_annotations = NULL;
aoqi@0 118 _fields_annotations = _fields_type_annotations = NULL;
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 class AnnotationCollector {
aoqi@0 122 public:
aoqi@0 123 enum Location { _in_field, _in_method, _in_class };
aoqi@0 124 enum ID {
aoqi@0 125 _unknown = 0,
aoqi@0 126 _method_CallerSensitive,
aoqi@0 127 _method_ForceInline,
aoqi@0 128 _method_DontInline,
vlivanov@7890 129 _method_InjectedProfile,
aoqi@0 130 _method_LambdaForm_Compiled,
aoqi@0 131 _method_LambdaForm_Hidden,
aoqi@0 132 _sun_misc_Contended,
aoqi@0 133 _field_Stable,
aoqi@0 134 _annotation_LIMIT
aoqi@0 135 };
aoqi@0 136 const Location _location;
aoqi@0 137 int _annotations_present;
aoqi@0 138 u2 _contended_group;
aoqi@0 139
aoqi@0 140 AnnotationCollector(Location location)
aoqi@0 141 : _location(location), _annotations_present(0)
aoqi@0 142 {
aoqi@0 143 assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
aoqi@0 144 }
aoqi@0 145 // If this annotation name has an ID, report it (or _none).
aoqi@0 146 ID annotation_index(ClassLoaderData* loader_data, Symbol* name);
aoqi@0 147 // Set the annotation name:
aoqi@0 148 void set_annotation(ID id) {
aoqi@0 149 assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
aoqi@0 150 _annotations_present |= nth_bit((int)id);
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 void remove_annotation(ID id) {
aoqi@0 154 assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
aoqi@0 155 _annotations_present &= ~nth_bit((int)id);
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 // Report if the annotation is present.
aoqi@0 159 bool has_any_annotations() const { return _annotations_present != 0; }
aoqi@0 160 bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
aoqi@0 161
aoqi@0 162 void set_contended_group(u2 group) { _contended_group = group; }
aoqi@0 163 u2 contended_group() const { return _contended_group; }
aoqi@0 164
aoqi@0 165 bool is_contended() const { return has_annotation(_sun_misc_Contended); }
aoqi@0 166
aoqi@0 167 void set_stable(bool stable) { set_annotation(_field_Stable); }
aoqi@0 168 bool is_stable() const { return has_annotation(_field_Stable); }
aoqi@0 169 };
aoqi@0 170
aoqi@0 171 // This class also doubles as a holder for metadata cleanup.
aoqi@0 172 class FieldAnnotationCollector: public AnnotationCollector {
aoqi@0 173 ClassLoaderData* _loader_data;
aoqi@0 174 AnnotationArray* _field_annotations;
aoqi@0 175 AnnotationArray* _field_type_annotations;
aoqi@0 176 public:
aoqi@0 177 FieldAnnotationCollector(ClassLoaderData* loader_data) :
aoqi@0 178 AnnotationCollector(_in_field),
aoqi@0 179 _loader_data(loader_data),
aoqi@0 180 _field_annotations(NULL),
aoqi@0 181 _field_type_annotations(NULL) {}
aoqi@0 182 void apply_to(FieldInfo* f);
aoqi@0 183 ~FieldAnnotationCollector();
aoqi@0 184 AnnotationArray* field_annotations() { return _field_annotations; }
aoqi@0 185 AnnotationArray* field_type_annotations() { return _field_type_annotations; }
aoqi@0 186
aoqi@0 187 void set_field_annotations(AnnotationArray* a) { _field_annotations = a; }
aoqi@0 188 void set_field_type_annotations(AnnotationArray* a) { _field_type_annotations = a; }
aoqi@0 189 };
aoqi@0 190
aoqi@0 191 class MethodAnnotationCollector: public AnnotationCollector {
aoqi@0 192 public:
aoqi@0 193 MethodAnnotationCollector() : AnnotationCollector(_in_method) { }
aoqi@0 194 void apply_to(methodHandle m);
aoqi@0 195 };
aoqi@0 196 class ClassAnnotationCollector: public AnnotationCollector {
aoqi@0 197 public:
aoqi@0 198 ClassAnnotationCollector() : AnnotationCollector(_in_class) { }
aoqi@0 199 void apply_to(instanceKlassHandle k);
aoqi@0 200 };
aoqi@0 201
aoqi@0 202 enum { fixed_buffer_size = 128 };
aoqi@0 203 u_char linenumbertable_buffer[fixed_buffer_size];
aoqi@0 204
aoqi@0 205 ClassFileStream* _stream; // Actual input stream
aoqi@0 206
aoqi@0 207 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
aoqi@0 208
aoqi@0 209 // Accessors
aoqi@0 210 ClassFileStream* stream() { return _stream; }
aoqi@0 211 void set_stream(ClassFileStream* st) { _stream = st; }
aoqi@0 212
aoqi@0 213 // Constant pool parsing
aoqi@0 214 void parse_constant_pool_entries(int length, TRAPS);
aoqi@0 215
aoqi@0 216 constantPoolHandle parse_constant_pool(TRAPS);
aoqi@0 217
aoqi@0 218 // Interface parsing
aoqi@0 219 Array<Klass*>* parse_interfaces(int length,
aoqi@0 220 Handle protection_domain,
aoqi@0 221 Symbol* class_name,
aoqi@0 222 bool* has_default_methods,
aoqi@0 223 TRAPS);
aoqi@0 224 void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS);
aoqi@0 225
aoqi@0 226 instanceKlassHandle parse_super_class(int super_class_index, TRAPS);
aoqi@0 227 // Field parsing
aoqi@0 228 void parse_field_attributes(u2 attributes_count,
aoqi@0 229 bool is_static, u2 signature_index,
aoqi@0 230 u2* constantvalue_index_addr,
aoqi@0 231 bool* is_synthetic_addr,
aoqi@0 232 u2* generic_signature_index_addr,
aoqi@0 233 FieldAnnotationCollector* parsed_annotations,
aoqi@0 234 TRAPS);
aoqi@0 235 Array<u2>* parse_fields(Symbol* class_name,
aoqi@0 236 bool is_interface,
aoqi@0 237 FieldAllocationCount *fac,
aoqi@0 238 u2* java_fields_count_ptr, TRAPS);
aoqi@0 239
aoqi@0 240 void print_field_layout(Symbol* name,
aoqi@0 241 Array<u2>* fields,
aoqi@0 242 constantPoolHandle cp,
aoqi@0 243 int instance_size,
aoqi@0 244 int instance_fields_start,
aoqi@0 245 int instance_fields_end,
aoqi@0 246 int static_fields_end);
aoqi@0 247
aoqi@0 248 // Method parsing
aoqi@0 249 methodHandle parse_method(bool is_interface,
aoqi@0 250 AccessFlags* promoted_flags,
aoqi@0 251 TRAPS);
aoqi@0 252 Array<Method*>* parse_methods(bool is_interface,
aoqi@0 253 AccessFlags* promoted_flags,
aoqi@0 254 bool* has_final_method,
acorn@7290 255 bool* declares_default_methods,
aoqi@0 256 TRAPS);
aoqi@0 257 intArray* sort_methods(Array<Method*>* methods);
aoqi@0 258
aoqi@0 259 u2* parse_exception_table(u4 code_length, u4 exception_table_length,
aoqi@0 260 TRAPS);
aoqi@0 261 void parse_linenumber_table(
aoqi@0 262 u4 code_attribute_length, u4 code_length,
aoqi@0 263 CompressedLineNumberWriteStream** write_stream, TRAPS);
aoqi@0 264 u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
aoqi@0 265 u2* localvariable_table_length,
aoqi@0 266 bool isLVTT, TRAPS);
aoqi@0 267 u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
aoqi@0 268 TRAPS);
aoqi@0 269 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
aoqi@0 270 u1* u1_array, u2* u2_array, TRAPS);
aoqi@0 271 u1* parse_stackmap_table(u4 code_attribute_length, TRAPS);
aoqi@0 272
aoqi@0 273 // Classfile attribute parsing
aoqi@0 274 u2 parse_generic_signature_attribute(TRAPS);
aoqi@0 275 void parse_classfile_sourcefile_attribute(TRAPS);
aoqi@0 276 void parse_classfile_source_debug_extension_attribute(int length, TRAPS);
aoqi@0 277 u2 parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start,
aoqi@0 278 bool parsed_enclosingmethod_attribute,
aoqi@0 279 u2 enclosing_method_class_index,
aoqi@0 280 u2 enclosing_method_method_index,
aoqi@0 281 TRAPS);
aoqi@0 282 void parse_classfile_attributes(ClassAnnotationCollector* parsed_annotations,
aoqi@0 283 TRAPS);
aoqi@0 284 void parse_classfile_synthetic_attribute(TRAPS);
aoqi@0 285 void parse_classfile_signature_attribute(TRAPS);
aoqi@0 286 void parse_classfile_bootstrap_methods_attribute(u4 attribute_length, TRAPS);
aoqi@0 287
aoqi@0 288 // Annotations handling
aoqi@0 289 AnnotationArray* assemble_annotations(u1* runtime_visible_annotations,
aoqi@0 290 int runtime_visible_annotations_length,
aoqi@0 291 u1* runtime_invisible_annotations,
aoqi@0 292 int runtime_invisible_annotations_length, TRAPS);
aoqi@0 293 int skip_annotation(u1* buffer, int limit, int index);
aoqi@0 294 int skip_annotation_value(u1* buffer, int limit, int index);
aoqi@0 295 void parse_annotations(u1* buffer, int limit,
aoqi@0 296 /* Results (currently, only one result is supported): */
aoqi@0 297 AnnotationCollector* result,
aoqi@0 298 TRAPS);
aoqi@0 299
aoqi@0 300 // Final setup
aoqi@0 301 unsigned int compute_oop_map_count(instanceKlassHandle super,
aoqi@0 302 unsigned int nonstatic_oop_count,
aoqi@0 303 int first_nonstatic_oop_offset);
aoqi@0 304 void fill_oop_maps(instanceKlassHandle k,
aoqi@0 305 unsigned int nonstatic_oop_map_count,
aoqi@0 306 int* nonstatic_oop_offsets,
aoqi@0 307 unsigned int* nonstatic_oop_counts);
aoqi@0 308 void set_precomputed_flags(instanceKlassHandle k);
aoqi@0 309 Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super,
aoqi@0 310 Array<Klass*>* local_ifs, TRAPS);
aoqi@0 311
aoqi@0 312 // Format checker methods
aoqi@0 313 void classfile_parse_error(const char* msg, TRAPS);
aoqi@0 314 void classfile_parse_error(const char* msg, int index, TRAPS);
aoqi@0 315 void classfile_parse_error(const char* msg, const char *name, TRAPS);
aoqi@0 316 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
shshahma@8761 317 void classfile_parse_error(const char* msg, const char* name, const char* signature, TRAPS);
aoqi@0 318 inline void guarantee_property(bool b, const char* msg, TRAPS) {
aoqi@0 319 if (!b) { classfile_parse_error(msg, CHECK); }
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 PRAGMA_DIAG_PUSH
aoqi@0 323 PRAGMA_FORMAT_NONLITERAL_IGNORED
aoqi@0 324 inline void assert_property(bool b, const char* msg, TRAPS) {
aoqi@0 325 #ifdef ASSERT
aoqi@0 326 if (!b) {
aoqi@0 327 ResourceMark rm(THREAD);
aoqi@0 328 fatal(err_msg(msg, _class_name->as_C_string()));
aoqi@0 329 }
aoqi@0 330 #endif
aoqi@0 331 }
aoqi@0 332
aoqi@0 333 inline void assert_property(bool b, const char* msg, int index, TRAPS) {
aoqi@0 334 #ifdef ASSERT
aoqi@0 335 if (!b) {
aoqi@0 336 ResourceMark rm(THREAD);
aoqi@0 337 fatal(err_msg(msg, index, _class_name->as_C_string()));
aoqi@0 338 }
aoqi@0 339 #endif
aoqi@0 340 }
aoqi@0 341 PRAGMA_DIAG_POP
aoqi@0 342
aoqi@0 343 inline void check_property(bool property, const char* msg, int index, TRAPS) {
aoqi@0 344 if (_need_verify) {
aoqi@0 345 guarantee_property(property, msg, index, CHECK);
aoqi@0 346 } else {
aoqi@0 347 assert_property(property, msg, index, CHECK);
aoqi@0 348 }
aoqi@0 349 }
aoqi@0 350
aoqi@0 351 inline void check_property(bool property, const char* msg, TRAPS) {
aoqi@0 352 if (_need_verify) {
aoqi@0 353 guarantee_property(property, msg, CHECK);
aoqi@0 354 } else {
aoqi@0 355 assert_property(property, msg, CHECK);
aoqi@0 356 }
aoqi@0 357 }
aoqi@0 358
aoqi@0 359 inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
aoqi@0 360 if (!b) { classfile_parse_error(msg, index, CHECK); }
aoqi@0 361 }
aoqi@0 362 inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
aoqi@0 363 if (!b) { classfile_parse_error(msg, name, CHECK); }
aoqi@0 364 }
aoqi@0 365 inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
aoqi@0 366 if (!b) { classfile_parse_error(msg, index, name, CHECK); }
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 void throwIllegalSignature(
aoqi@0 370 const char* type, Symbol* name, Symbol* sig, TRAPS);
aoqi@0 371
aoqi@0 372 bool is_supported_version(u2 major, u2 minor);
aoqi@0 373 bool has_illegal_visibility(jint flags);
aoqi@0 374
aoqi@0 375 void verify_constantvalue(int constantvalue_index, int signature_index, TRAPS);
aoqi@0 376 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
aoqi@0 377 void verify_legal_class_name(Symbol* name, TRAPS);
aoqi@0 378 void verify_legal_field_name(Symbol* name, TRAPS);
aoqi@0 379 void verify_legal_method_name(Symbol* name, TRAPS);
aoqi@0 380 void verify_legal_field_signature(Symbol* fieldname, Symbol* signature, TRAPS);
aoqi@0 381 int verify_legal_method_signature(Symbol* methodname, Symbol* signature, TRAPS);
aoqi@0 382 void verify_legal_class_modifiers(jint flags, TRAPS);
aoqi@0 383 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
aoqi@0 384 void verify_legal_method_modifiers(jint flags, bool is_interface, Symbol* name, TRAPS);
aoqi@0 385 bool verify_unqualified_name(char* name, unsigned int length, int type);
aoqi@0 386 char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
aoqi@0 387 char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
aoqi@0 388
aoqi@0 389 bool is_anonymous() {
aoqi@0 390 assert(EnableInvokeDynamic || _host_klass.is_null(), "");
aoqi@0 391 return _host_klass.not_null();
aoqi@0 392 }
aoqi@0 393 bool has_cp_patch_at(int index) {
aoqi@0 394 assert(EnableInvokeDynamic, "");
aoqi@0 395 assert(index >= 0, "oob");
aoqi@0 396 return (_cp_patches != NULL
aoqi@0 397 && index < _cp_patches->length()
aoqi@0 398 && _cp_patches->adr_at(index)->not_null());
aoqi@0 399 }
aoqi@0 400 Handle cp_patch_at(int index) {
aoqi@0 401 assert(has_cp_patch_at(index), "oob");
aoqi@0 402 return _cp_patches->at(index);
aoqi@0 403 }
aoqi@0 404 Handle clear_cp_patch_at(int index) {
aoqi@0 405 Handle patch = cp_patch_at(index);
aoqi@0 406 _cp_patches->at_put(index, Handle());
aoqi@0 407 assert(!has_cp_patch_at(index), "");
aoqi@0 408 return patch;
aoqi@0 409 }
aoqi@0 410 void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS);
aoqi@0 411
aoqi@0 412 // Wrapper for constantTag.is_klass_[or_]reference.
aoqi@0 413 // In older versions of the VM, Klass*s cannot sneak into early phases of
aoqi@0 414 // constant pool construction, but in later versions they can.
aoqi@0 415 // %%% Let's phase out the old is_klass_reference.
aoqi@0 416 bool valid_klass_reference_at(int index) {
aoqi@0 417 return _cp->is_within_bounds(index) &&
aoqi@0 418 (EnableInvokeDynamic
aoqi@0 419 ? _cp->tag_at(index).is_klass_or_reference()
aoqi@0 420 : _cp->tag_at(index).is_klass_reference());
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 // Checks that the cpool index is in range and is a utf8
aoqi@0 424 bool valid_symbol_at(int cpool_index) {
aoqi@0 425 return (_cp->is_within_bounds(cpool_index) &&
aoqi@0 426 _cp->tag_at(cpool_index).is_utf8());
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 void copy_localvariable_table(ConstMethod* cm, int lvt_cnt,
aoqi@0 430 u2* localvariable_table_length,
aoqi@0 431 u2** localvariable_table_start,
aoqi@0 432 int lvtt_cnt,
aoqi@0 433 u2* localvariable_type_table_length,
aoqi@0 434 u2** localvariable_type_table_start,
aoqi@0 435 TRAPS);
aoqi@0 436
aoqi@0 437 void copy_method_annotations(ConstMethod* cm,
aoqi@0 438 u1* runtime_visible_annotations,
aoqi@0 439 int runtime_visible_annotations_length,
aoqi@0 440 u1* runtime_invisible_annotations,
aoqi@0 441 int runtime_invisible_annotations_length,
aoqi@0 442 u1* runtime_visible_parameter_annotations,
aoqi@0 443 int runtime_visible_parameter_annotations_length,
aoqi@0 444 u1* runtime_invisible_parameter_annotations,
aoqi@0 445 int runtime_invisible_parameter_annotations_length,
aoqi@0 446 u1* runtime_visible_type_annotations,
aoqi@0 447 int runtime_visible_type_annotations_length,
aoqi@0 448 u1* runtime_invisible_type_annotations,
aoqi@0 449 int runtime_invisible_type_annotations_length,
aoqi@0 450 u1* annotation_default,
aoqi@0 451 int annotation_default_length,
aoqi@0 452 TRAPS);
aoqi@0 453
aoqi@0 454 // lays out fields in class and returns the total oopmap count
aoqi@0 455 void layout_fields(Handle class_loader, FieldAllocationCount* fac,
aoqi@0 456 ClassAnnotationCollector* parsed_annotations,
aoqi@0 457 FieldLayoutInfo* info, TRAPS);
aoqi@0 458
aoqi@0 459 public:
aoqi@0 460 // Constructor
aoqi@0 461 ClassFileParser(ClassFileStream* st) { set_stream(st); }
aoqi@0 462 ~ClassFileParser();
aoqi@0 463
aoqi@0 464 // Parse .class file and return new Klass*. The Klass* is not hooked up
aoqi@0 465 // to the system dictionary or any other structures, so a .class file can
aoqi@0 466 // be loaded several times if desired.
aoqi@0 467 // The system dictionary hookup is done by the caller.
aoqi@0 468 //
aoqi@0 469 // "parsed_name" is updated by this method, and is the name found
aoqi@0 470 // while parsing the stream.
aoqi@0 471 instanceKlassHandle parseClassFile(Symbol* name,
aoqi@0 472 ClassLoaderData* loader_data,
aoqi@0 473 Handle protection_domain,
aoqi@0 474 TempNewSymbol& parsed_name,
aoqi@0 475 bool verify,
aoqi@0 476 TRAPS) {
aoqi@0 477 KlassHandle no_host_klass;
aoqi@0 478 return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
aoqi@0 479 }
aoqi@0 480 instanceKlassHandle parseClassFile(Symbol* name,
aoqi@0 481 ClassLoaderData* loader_data,
aoqi@0 482 Handle protection_domain,
aoqi@0 483 KlassHandle host_klass,
aoqi@0 484 GrowableArray<Handle>* cp_patches,
aoqi@0 485 TempNewSymbol& parsed_name,
aoqi@0 486 bool verify,
aoqi@0 487 TRAPS);
aoqi@0 488
aoqi@0 489 // Verifier checks
aoqi@0 490 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
aoqi@0 491 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
aoqi@0 492 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
aoqi@0 493 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
aoqi@0 494 };
aoqi@0 495
aoqi@0 496 #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP

mercurial