374 fatal(msg, index, _class_name->as_C_string());
375 }
376 PRAGMA_DIAG_POP
377 #endif
378
379 void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
380 ConstantPool* const cp,
381 const int length,
382 TRAPS) {
383 assert(cp != NULL, "invariant");
384 assert(stream != NULL, "invariant");
385
386 // parsing constant pool entries
387 parse_constant_pool_entries(stream, cp, length, CHECK);
388 if (class_bad_constant_seen() != 0) {
389 // a bad CP entry has been detected previously so stop parsing and just return.
390 return;
391 }
392
393 int index = 1; // declared outside of loops for portability
394
395 // first verification pass - validate cross references
396 // and fixup class and string constants
397 for (index = 1; index < length; index++) { // Index 0 is unused
398 const jbyte tag = cp->tag_at(index).value();
399 switch (tag) {
400 case JVM_CONSTANT_Class: {
401 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present
402 break;
403 }
404 case JVM_CONSTANT_Fieldref:
405 // fall through
406 case JVM_CONSTANT_Methodref:
407 // fall through
408 case JVM_CONSTANT_InterfaceMethodref: {
409 if (!_need_verify) break;
410 const int klass_ref_index = cp->klass_ref_index_at(index);
411 const int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
412 check_property(valid_klass_reference_at(klass_ref_index),
413 "Invalid constant pool index %u in class file %s",
442 check_property(valid_symbol_at(name_ref_index),
443 "Invalid constant pool index %u in class file %s",
444 name_ref_index, CHECK);
445 check_property(valid_symbol_at(signature_ref_index),
446 "Invalid constant pool index %u in class file %s",
447 signature_ref_index, CHECK);
448 break;
449 }
450 case JVM_CONSTANT_Utf8:
451 break;
452 case JVM_CONSTANT_UnresolvedClass: // fall-through
453 case JVM_CONSTANT_UnresolvedClassInError: {
454 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present
455 break;
456 }
457 case JVM_CONSTANT_ClassIndex: {
458 const int class_index = cp->klass_index_at(index);
459 check_property(valid_symbol_at(class_index),
460 "Invalid constant pool index %u in class file %s",
461 class_index, CHECK);
462 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index));
463 break;
464 }
465 case JVM_CONSTANT_StringIndex: {
466 const int string_index = cp->string_index_at(index);
467 check_property(valid_symbol_at(string_index),
468 "Invalid constant pool index %u in class file %s",
469 string_index, CHECK);
470 Symbol* const sym = cp->symbol_at(string_index);
471 cp->unresolved_string_at_put(index, sym);
472 break;
473 }
474 case JVM_CONSTANT_MethodHandle: {
475 const int ref_index = cp->method_handle_index_at(index);
476 check_property(valid_cp_range(ref_index, length),
477 "Invalid constant pool index %u in class file %s",
478 ref_index, CHECK);
479 const constantTag tag = cp->tag_at(ref_index);
480 const int ref_kind = cp->method_handle_ref_kind_at(index);
481
482 switch (ref_kind) {
533 case JVM_CONSTANT_InvokeDynamic: {
534 const int name_and_type_ref_index =
535 cp->invoke_dynamic_name_and_type_ref_index_at(index);
536
537 check_property(valid_cp_range(name_and_type_ref_index, length) &&
538 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
539 "Invalid constant pool index %u in class file %s",
540 name_and_type_ref_index, CHECK);
541 // bootstrap specifier index must be checked later,
542 // when BootstrapMethods attr is available
543 break;
544 }
545 default: {
546 fatal("bad constant pool tag value %u", cp->tag_at(index).value());
547 ShouldNotReachHere();
548 break;
549 }
550 } // switch(tag)
551 } // end of for
552
553 if (_cp_patches != NULL) {
554 // need to treat this_class specially...
555 int this_class_index;
556 {
557 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
558 const u1* const mark = stream->current();
559 stream->skip_u2_fast(1); // skip flags
560 this_class_index = stream->get_u2_fast();
561 stream->set_current(mark); // revert to mark
562 }
563
564 for (index = 1; index < length; index++) { // Index 0 is unused
565 if (has_cp_patch_at(index)) {
566 guarantee_property(index != this_class_index,
567 "Illegal constant pool patch to self at %d in class file %s",
568 index, CHECK);
569 patch_constant_pool(cp, index, cp_patch_at(index), CHECK);
570 }
571 }
572 }
573
574 if (!_need_verify) {
684 }
685 break;
686 }
687 // Other ref_kinds are already fully checked in previous pass.
688 } // switch(ref_kind)
689 break;
690 }
691 case JVM_CONSTANT_MethodType: {
692 const Symbol* const no_name = vmSymbols::type_name(); // place holder
693 const Symbol* const signature = cp->method_type_signature_at(index);
694 verify_legal_method_signature(no_name, signature, CHECK);
695 break;
696 }
697 case JVM_CONSTANT_Utf8: {
698 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");
699 }
700 } // switch(tag)
701 } // end of for
702 }
703
704 void ClassFileParser::patch_constant_pool(ConstantPool* cp,
705 int index,
706 Handle patch,
707 TRAPS) {
708 assert(cp != NULL, "invariant");
709
710 BasicType patch_type = T_VOID;
711
712 switch (cp->tag_at(index).value()) {
713
714 case JVM_CONSTANT_UnresolvedClass: {
715 // Patching a class means pre-resolving it.
716 // The name in the constant pool is ignored.
717 if (java_lang_Class::is_instance(patch())) {
718 guarantee_property(!java_lang_Class::is_primitive(patch()),
719 "Illegal class patch at %d in class file %s",
720 index, CHECK);
721 cp->klass_at_put(index, java_lang_Class::as_Klass(patch()));
722 } else {
723 guarantee_property(java_lang_String::is_instance(patch()),
724 "Illegal class patch at %d in class file %s",
725 index, CHECK);
726 Symbol* const name = java_lang_String::as_symbol(patch(), CHECK);
727 cp->unresolved_klass_at_put(index, name);
728 }
729 break;
730 }
731
732 case JVM_CONSTANT_String: {
733 // skip this patch and don't clear it. Needs the oop array for resolved
734 // references to be created first.
735 return;
736 }
737 case JVM_CONSTANT_Integer: patch_type = T_INT; goto patch_prim;
738 case JVM_CONSTANT_Float: patch_type = T_FLOAT; goto patch_prim;
739 case JVM_CONSTANT_Long: patch_type = T_LONG; goto patch_prim;
740 case JVM_CONSTANT_Double: patch_type = T_DOUBLE; goto patch_prim;
741 patch_prim:
742 {
743 jvalue value;
744 BasicType value_type = java_lang_boxing_object::get_value(patch(), &value);
745 guarantee_property(value_type == patch_type,
746 "Illegal primitive patch at %d in class file %s",
747 index, CHECK);
5324 assert(NULL == _local_interfaces, "invariant");
5325 assert(NULL == _transitive_interfaces, "invariant");
5326 assert(NULL == _combined_annotations, "invariant");
5327
5328 if (_has_final_method) {
5329 ik->set_has_final_method();
5330 }
5331
5332 ik->copy_method_ordering(_method_ordering, CHECK);
5333 // The InstanceKlass::_methods_jmethod_ids cache
5334 // is managed on the assumption that the initial cache
5335 // size is equal to the number of methods in the class. If
5336 // that changes, then InstanceKlass::idnum_can_increment()
5337 // has to be changed accordingly.
5338 ik->set_initial_method_idnum(ik->methods()->length());
5339
5340 ik->set_name(_class_name);
5341
5342 if (is_anonymous()) {
5343 // I am well known to myself
5344 ik->constants()->klass_at_put(_this_class_index, ik); // eagerly resolve
5345 }
5346
5347 ik->set_minor_version(_minor_version);
5348 ik->set_major_version(_major_version);
5349 ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5350 ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5351
5352 if (_host_klass != NULL) {
5353 assert (ik->is_anonymous(), "should be the same");
5354 ik->set_host_klass(_host_klass);
5355 }
5356
5357 // Set PackageEntry for this_klass
5358 oop cl = ik->class_loader();
5359 Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5360 ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5361 ik->set_package(cld, CHECK);
5362
5363 const Array<Method*>* const methods = ik->methods();
5364 assert(methods != NULL, "invariant");
5560 // verifyAll
5561 (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
5562 // verifyRemote
5563 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
5564 return !need_verify;
5565 }
5566
5567 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5568 Symbol* name,
5569 ClassLoaderData* loader_data,
5570 Handle protection_domain,
5571 const InstanceKlass* host_klass,
5572 GrowableArray<Handle>* cp_patches,
5573 Publicity pub_level,
5574 TRAPS) :
5575 _stream(stream),
5576 _requested_name(name),
5577 _loader_data(loader_data),
5578 _host_klass(host_klass),
5579 _cp_patches(cp_patches),
5580 _super_klass(),
5581 _cp(NULL),
5582 _fields(NULL),
5583 _methods(NULL),
5584 _inner_classes(NULL),
5585 _local_interfaces(NULL),
5586 _transitive_interfaces(NULL),
5587 _combined_annotations(NULL),
5588 _annotations(NULL),
5589 _type_annotations(NULL),
5590 _fields_annotations(NULL),
5591 _fields_type_annotations(NULL),
5592 _klass(NULL),
5593 _klass_to_deallocate(NULL),
5594 _parsed_annotations(NULL),
5595 _fac(NULL),
5596 _field_info(NULL),
5597 _method_ordering(NULL),
5598 _all_mirandas(NULL),
5599 _vtable_size(0),
5630 assert(THREAD->is_Java_thread(), "invariant");
5631 assert(_loader_data != NULL, "invariant");
5632 assert(stream != NULL, "invariant");
5633 assert(_stream != NULL, "invariant");
5634 assert(_stream->buffer() == _stream->current(), "invariant");
5635 assert(_class_name != NULL, "invariant");
5636 assert(0 == _access_flags.as_int(), "invariant");
5637
5638 // Figure out whether we can skip format checking (matching classic VM behavior)
5639 if (DumpSharedSpaces) {
5640 // verify == true means it's a 'remote' class (i.e., non-boot class)
5641 // Verification decision is based on BytecodeVerificationRemote flag
5642 // for those classes.
5643 _need_verify = (stream->need_verify()) ? BytecodeVerificationRemote :
5644 BytecodeVerificationLocal;
5645 }
5646 else {
5647 _need_verify = Verifier::should_verify_for(_loader_data->class_loader(),
5648 stream->need_verify());
5649 }
5650
5651 // synch back verification state to stream
5652 stream->set_verify(_need_verify);
5653
5654 // Check if verification needs to be relaxed for this class file
5655 // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
5656 _relax_verify = relax_format_check_for(_loader_data);
5657
5658 parse_stream(stream, CHECK);
5659
5660 post_process_parsed_stream(stream, _cp, CHECK);
5661 }
5662
5663 void ClassFileParser::clear_class_metadata() {
5664 // metadata created before the instance klass is created. Must be
5665 // deallocated if classfile parsing returns an error.
5666 _cp = NULL;
5667 _fields = NULL;
5668 _methods = NULL;
5669 _inner_classes = NULL;
5759 _minor_version);
5760 }
5761
5762 // Check version numbers - we check this even with verifier off
5763 if (!is_supported_version(_major_version, _minor_version)) {
5764 ResourceMark rm(THREAD);
5765 Exceptions::fthrow(
5766 THREAD_AND_LOCATION,
5767 vmSymbols::java_lang_UnsupportedClassVersionError(),
5768 "%s has been compiled by a more recent version of the Java Runtime (class file version %u.%u), "
5769 "this version of the Java Runtime only recognizes class file versions up to %u.%u",
5770 _class_name->as_C_string(),
5771 _major_version,
5772 _minor_version,
5773 JAVA_MAX_SUPPORTED_VERSION,
5774 JAVA_MAX_SUPPORTED_MINOR_VERSION);
5775 return;
5776 }
5777
5778 stream->guarantee_more(3, CHECK); // length, first cp tag
5779 const u2 cp_size = stream->get_u2_fast();
5780
5781 guarantee_property(
5782 cp_size >= 1, "Illegal constant pool size %u in class file %s",
5783 cp_size, CHECK);
5784
5785 _cp = ConstantPool::allocate(_loader_data,
5786 cp_size,
5787 CHECK);
5788
5789 ConstantPool* const cp = _cp;
5790
5791 parse_constant_pool(stream, cp, cp_size, CHECK);
5792
5793 assert(cp_size == (const u2)cp->length(), "invariant");
5794
5795 // ACCESS FLAGS
5796 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
5797
5798 // Access flags
5799 jint flags;
5800 // JVM_ACC_MODULE is defined in JDK-9 and later.
5801 if (_major_version >= JAVA_9_VERSION) {
5802 flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
5803 } else {
5804 flags = stream->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
5805 }
5806
5807 if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
5808 // Set abstract bit for old class files for backward compatibility
5809 flags |= JVM_ACC_ABSTRACT;
5810 }
5811
|
374 fatal(msg, index, _class_name->as_C_string());
375 }
376 PRAGMA_DIAG_POP
377 #endif
378
379 void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
380 ConstantPool* const cp,
381 const int length,
382 TRAPS) {
383 assert(cp != NULL, "invariant");
384 assert(stream != NULL, "invariant");
385
386 // parsing constant pool entries
387 parse_constant_pool_entries(stream, cp, length, CHECK);
388 if (class_bad_constant_seen() != 0) {
389 // a bad CP entry has been detected previously so stop parsing and just return.
390 return;
391 }
392
393 int index = 1; // declared outside of loops for portability
394 int num_klasses = 0;
395
396 // first verification pass - validate cross references
397 // and fixup class and string constants
398 for (index = 1; index < length; index++) { // Index 0 is unused
399 const jbyte tag = cp->tag_at(index).value();
400 switch (tag) {
401 case JVM_CONSTANT_Class: {
402 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present
403 break;
404 }
405 case JVM_CONSTANT_Fieldref:
406 // fall through
407 case JVM_CONSTANT_Methodref:
408 // fall through
409 case JVM_CONSTANT_InterfaceMethodref: {
410 if (!_need_verify) break;
411 const int klass_ref_index = cp->klass_ref_index_at(index);
412 const int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
413 check_property(valid_klass_reference_at(klass_ref_index),
414 "Invalid constant pool index %u in class file %s",
443 check_property(valid_symbol_at(name_ref_index),
444 "Invalid constant pool index %u in class file %s",
445 name_ref_index, CHECK);
446 check_property(valid_symbol_at(signature_ref_index),
447 "Invalid constant pool index %u in class file %s",
448 signature_ref_index, CHECK);
449 break;
450 }
451 case JVM_CONSTANT_Utf8:
452 break;
453 case JVM_CONSTANT_UnresolvedClass: // fall-through
454 case JVM_CONSTANT_UnresolvedClassInError: {
455 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present
456 break;
457 }
458 case JVM_CONSTANT_ClassIndex: {
459 const int class_index = cp->klass_index_at(index);
460 check_property(valid_symbol_at(class_index),
461 "Invalid constant pool index %u in class file %s",
462 class_index, CHECK);
463 cp->unresolved_klass_at_put(index, class_index, num_klasses++);
464 break;
465 }
466 case JVM_CONSTANT_StringIndex: {
467 const int string_index = cp->string_index_at(index);
468 check_property(valid_symbol_at(string_index),
469 "Invalid constant pool index %u in class file %s",
470 string_index, CHECK);
471 Symbol* const sym = cp->symbol_at(string_index);
472 cp->unresolved_string_at_put(index, sym);
473 break;
474 }
475 case JVM_CONSTANT_MethodHandle: {
476 const int ref_index = cp->method_handle_index_at(index);
477 check_property(valid_cp_range(ref_index, length),
478 "Invalid constant pool index %u in class file %s",
479 ref_index, CHECK);
480 const constantTag tag = cp->tag_at(ref_index);
481 const int ref_kind = cp->method_handle_ref_kind_at(index);
482
483 switch (ref_kind) {
534 case JVM_CONSTANT_InvokeDynamic: {
535 const int name_and_type_ref_index =
536 cp->invoke_dynamic_name_and_type_ref_index_at(index);
537
538 check_property(valid_cp_range(name_and_type_ref_index, length) &&
539 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
540 "Invalid constant pool index %u in class file %s",
541 name_and_type_ref_index, CHECK);
542 // bootstrap specifier index must be checked later,
543 // when BootstrapMethods attr is available
544 break;
545 }
546 default: {
547 fatal("bad constant pool tag value %u", cp->tag_at(index).value());
548 ShouldNotReachHere();
549 break;
550 }
551 } // switch(tag)
552 } // end of for
553
554 _first_patched_klass_resolved_index = num_klasses;
555 cp->allocate_resolved_klasses(_loader_data, num_klasses + _max_num_patched_klasses, CHECK);
556
557 if (_cp_patches != NULL) {
558 // need to treat this_class specially...
559
560 // Add dummy utf8 entries in the space reserved for names of patched classes. We'll use "*"
561 // for now. These will be replaced with actual names of the patched classes in patch_class().
562 Symbol* s = vmSymbols::star_name();
563 for (int n=_orig_cp_size; n<cp->length(); n++) {
564 cp->symbol_at_put(n, s);
565 }
566
567 int this_class_index;
568 {
569 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
570 const u1* const mark = stream->current();
571 stream->skip_u2_fast(1); // skip flags
572 this_class_index = stream->get_u2_fast();
573 stream->set_current(mark); // revert to mark
574 }
575
576 for (index = 1; index < length; index++) { // Index 0 is unused
577 if (has_cp_patch_at(index)) {
578 guarantee_property(index != this_class_index,
579 "Illegal constant pool patch to self at %d in class file %s",
580 index, CHECK);
581 patch_constant_pool(cp, index, cp_patch_at(index), CHECK);
582 }
583 }
584 }
585
586 if (!_need_verify) {
696 }
697 break;
698 }
699 // Other ref_kinds are already fully checked in previous pass.
700 } // switch(ref_kind)
701 break;
702 }
703 case JVM_CONSTANT_MethodType: {
704 const Symbol* const no_name = vmSymbols::type_name(); // place holder
705 const Symbol* const signature = cp->method_type_signature_at(index);
706 verify_legal_method_signature(no_name, signature, CHECK);
707 break;
708 }
709 case JVM_CONSTANT_Utf8: {
710 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");
711 }
712 } // switch(tag)
713 } // end of for
714 }
715
716 void ClassFileParser::patch_class(ConstantPool* cp, int class_index, Klass* k, Symbol* name) {
717 int name_index = _orig_cp_size + _num_patched_klasses;
718 int resolved_klass_index = _first_patched_klass_resolved_index + _num_patched_klasses;
719
720 cp->klass_at_put(class_index, name_index, resolved_klass_index, k, name);
721 _num_patched_klasses ++;
722 }
723
724 void ClassFileParser::patch_constant_pool(ConstantPool* cp,
725 int index,
726 Handle patch,
727 TRAPS) {
728 assert(cp != NULL, "invariant");
729
730 BasicType patch_type = T_VOID;
731
732 switch (cp->tag_at(index).value()) {
733
734 case JVM_CONSTANT_UnresolvedClass: {
735 // Patching a class means pre-resolving it.
736 // The name in the constant pool is ignored.
737 if (java_lang_Class::is_instance(patch())) {
738 guarantee_property(!java_lang_Class::is_primitive(patch()),
739 "Illegal class patch at %d in class file %s",
740 index, CHECK);
741 Klass* k = java_lang_Class::as_Klass(patch());
742 patch_class(cp, index, k, k->name());
743 } else {
744 guarantee_property(java_lang_String::is_instance(patch()),
745 "Illegal class patch at %d in class file %s",
746 index, CHECK);
747 Symbol* const name = java_lang_String::as_symbol(patch(), CHECK);
748 patch_class(cp, index, NULL, name);
749 }
750 break;
751 }
752
753 case JVM_CONSTANT_String: {
754 // skip this patch and don't clear it. Needs the oop array for resolved
755 // references to be created first.
756 return;
757 }
758 case JVM_CONSTANT_Integer: patch_type = T_INT; goto patch_prim;
759 case JVM_CONSTANT_Float: patch_type = T_FLOAT; goto patch_prim;
760 case JVM_CONSTANT_Long: patch_type = T_LONG; goto patch_prim;
761 case JVM_CONSTANT_Double: patch_type = T_DOUBLE; goto patch_prim;
762 patch_prim:
763 {
764 jvalue value;
765 BasicType value_type = java_lang_boxing_object::get_value(patch(), &value);
766 guarantee_property(value_type == patch_type,
767 "Illegal primitive patch at %d in class file %s",
768 index, CHECK);
5345 assert(NULL == _local_interfaces, "invariant");
5346 assert(NULL == _transitive_interfaces, "invariant");
5347 assert(NULL == _combined_annotations, "invariant");
5348
5349 if (_has_final_method) {
5350 ik->set_has_final_method();
5351 }
5352
5353 ik->copy_method_ordering(_method_ordering, CHECK);
5354 // The InstanceKlass::_methods_jmethod_ids cache
5355 // is managed on the assumption that the initial cache
5356 // size is equal to the number of methods in the class. If
5357 // that changes, then InstanceKlass::idnum_can_increment()
5358 // has to be changed accordingly.
5359 ik->set_initial_method_idnum(ik->methods()->length());
5360
5361 ik->set_name(_class_name);
5362
5363 if (is_anonymous()) {
5364 // I am well known to myself
5365 patch_class(ik->constants(), _this_class_index, ik, ik->name()); // eagerly resolve
5366 }
5367
5368 ik->set_minor_version(_minor_version);
5369 ik->set_major_version(_major_version);
5370 ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5371 ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5372
5373 if (_host_klass != NULL) {
5374 assert (ik->is_anonymous(), "should be the same");
5375 ik->set_host_klass(_host_klass);
5376 }
5377
5378 // Set PackageEntry for this_klass
5379 oop cl = ik->class_loader();
5380 Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5381 ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5382 ik->set_package(cld, CHECK);
5383
5384 const Array<Method*>* const methods = ik->methods();
5385 assert(methods != NULL, "invariant");
5581 // verifyAll
5582 (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
5583 // verifyRemote
5584 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
5585 return !need_verify;
5586 }
5587
5588 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5589 Symbol* name,
5590 ClassLoaderData* loader_data,
5591 Handle protection_domain,
5592 const InstanceKlass* host_klass,
5593 GrowableArray<Handle>* cp_patches,
5594 Publicity pub_level,
5595 TRAPS) :
5596 _stream(stream),
5597 _requested_name(name),
5598 _loader_data(loader_data),
5599 _host_klass(host_klass),
5600 _cp_patches(cp_patches),
5601 _num_patched_klasses(0),
5602 _max_num_patched_klasses(0),
5603 _orig_cp_size(0),
5604 _first_patched_klass_resolved_index(0),
5605 _super_klass(),
5606 _cp(NULL),
5607 _fields(NULL),
5608 _methods(NULL),
5609 _inner_classes(NULL),
5610 _local_interfaces(NULL),
5611 _transitive_interfaces(NULL),
5612 _combined_annotations(NULL),
5613 _annotations(NULL),
5614 _type_annotations(NULL),
5615 _fields_annotations(NULL),
5616 _fields_type_annotations(NULL),
5617 _klass(NULL),
5618 _klass_to_deallocate(NULL),
5619 _parsed_annotations(NULL),
5620 _fac(NULL),
5621 _field_info(NULL),
5622 _method_ordering(NULL),
5623 _all_mirandas(NULL),
5624 _vtable_size(0),
5655 assert(THREAD->is_Java_thread(), "invariant");
5656 assert(_loader_data != NULL, "invariant");
5657 assert(stream != NULL, "invariant");
5658 assert(_stream != NULL, "invariant");
5659 assert(_stream->buffer() == _stream->current(), "invariant");
5660 assert(_class_name != NULL, "invariant");
5661 assert(0 == _access_flags.as_int(), "invariant");
5662
5663 // Figure out whether we can skip format checking (matching classic VM behavior)
5664 if (DumpSharedSpaces) {
5665 // verify == true means it's a 'remote' class (i.e., non-boot class)
5666 // Verification decision is based on BytecodeVerificationRemote flag
5667 // for those classes.
5668 _need_verify = (stream->need_verify()) ? BytecodeVerificationRemote :
5669 BytecodeVerificationLocal;
5670 }
5671 else {
5672 _need_verify = Verifier::should_verify_for(_loader_data->class_loader(),
5673 stream->need_verify());
5674 }
5675 // reserve space for names of the patches classes
5676 if (is_anonymous()) {
5677 _max_num_patched_klasses ++; // for patching the <this> class index
5678 }
5679 if (_cp_patches != NULL) {
5680 int len = _cp_patches->length();
5681 for (int i=0; i<len; i++) {
5682 if (has_cp_patch_at(i)) {
5683 Handle patch = cp_patch_at(i);
5684 if (java_lang_String::is_instance(patch()) || java_lang_Class::is_instance(patch())) {
5685 // We need to append the names of the patched classes to the end of the constant pool,
5686 // because a patched class may have a Utf8 name that's not already included in the
5687 // original constant pool.
5688 //
5689 // Note that a String in cp_patch_at(i) may be used to patch a Utf8, a String, or a Class.
5690 // At this point, we don't know the tag for index i yet, because we haven't parsed the
5691 // constant pool. So we can only assume the worst -- every String is used to patch a Class.
5692 _max_num_patched_klasses ++;
5693 }
5694 }
5695 }
5696 }
5697
5698 // synch back verification state to stream
5699 stream->set_verify(_need_verify);
5700
5701 // Check if verification needs to be relaxed for this class file
5702 // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
5703 _relax_verify = relax_format_check_for(_loader_data);
5704
5705 parse_stream(stream, CHECK);
5706
5707 post_process_parsed_stream(stream, _cp, CHECK);
5708 }
5709
5710 void ClassFileParser::clear_class_metadata() {
5711 // metadata created before the instance klass is created. Must be
5712 // deallocated if classfile parsing returns an error.
5713 _cp = NULL;
5714 _fields = NULL;
5715 _methods = NULL;
5716 _inner_classes = NULL;
5806 _minor_version);
5807 }
5808
5809 // Check version numbers - we check this even with verifier off
5810 if (!is_supported_version(_major_version, _minor_version)) {
5811 ResourceMark rm(THREAD);
5812 Exceptions::fthrow(
5813 THREAD_AND_LOCATION,
5814 vmSymbols::java_lang_UnsupportedClassVersionError(),
5815 "%s has been compiled by a more recent version of the Java Runtime (class file version %u.%u), "
5816 "this version of the Java Runtime only recognizes class file versions up to %u.%u",
5817 _class_name->as_C_string(),
5818 _major_version,
5819 _minor_version,
5820 JAVA_MAX_SUPPORTED_VERSION,
5821 JAVA_MAX_SUPPORTED_MINOR_VERSION);
5822 return;
5823 }
5824
5825 stream->guarantee_more(3, CHECK); // length, first cp tag
5826 u2 cp_size = stream->get_u2_fast();
5827
5828 guarantee_property(
5829 cp_size >= 1, "Illegal constant pool size %u in class file %s",
5830 cp_size, CHECK);
5831
5832 _orig_cp_size = cp_size;
5833 if (int(cp_size) + _max_num_patched_klasses > 0xffff) {
5834 THROW_MSG(vmSymbols::java_lang_InternalError(), "not enough space for patched classes");
5835 }
5836 cp_size += _max_num_patched_klasses;
5837
5838 _cp = ConstantPool::allocate(_loader_data,
5839 cp_size,
5840 CHECK);
5841
5842 ConstantPool* const cp = _cp;
5843
5844 parse_constant_pool(stream, cp, _orig_cp_size, CHECK);
5845
5846 assert(cp_size == (const u2)cp->length(), "invariant");
5847
5848 // ACCESS FLAGS
5849 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
5850
5851 // Access flags
5852 jint flags;
5853 // JVM_ACC_MODULE is defined in JDK-9 and later.
5854 if (_major_version >= JAVA_9_VERSION) {
5855 flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
5856 } else {
5857 flags = stream->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
5858 }
5859
5860 if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
5861 // Set abstract bit for old class files for backward compatibility
5862 flags |= JVM_ACC_ABSTRACT;
5863 }
5864
|