648 switch (tag) {
649 case JVM_CONSTANT_UnresolvedClass: {
650 const Symbol* const class_name = cp->klass_name_at(index);
651 // check the name, even if _cp_patches will overwrite it
652 verify_legal_class_name(class_name, CHECK);
653 break;
654 }
655 case JVM_CONSTANT_NameAndType: {
656 if (_need_verify) {
657 const int sig_index = cp->signature_ref_index_at(index);
658 const int name_index = cp->name_ref_index_at(index);
659 const Symbol* const name = cp->symbol_at(name_index);
660 const Symbol* const sig = cp->symbol_at(sig_index);
661 guarantee_property(sig->utf8_length() != 0,
662 "Illegal zero length constant pool entry at %d in class %s",
663 sig_index, CHECK);
664 guarantee_property(name->utf8_length() != 0,
665 "Illegal zero length constant pool entry at %d in class %s",
666 name_index, CHECK);
667
668 if (sig->char_at(0) == JVM_SIGNATURE_FUNC) {
669 // Format check method name and signature
670 verify_legal_method_name(name, CHECK);
671 verify_legal_method_signature(name, sig, CHECK);
672 } else {
673 // Format check field name and signature
674 verify_legal_field_name(name, CHECK);
675 verify_legal_field_signature(name, sig, CHECK);
676 }
677 }
678 break;
679 }
680 case JVM_CONSTANT_Dynamic: {
681 const int name_and_type_ref_index =
682 cp->name_and_type_ref_index_at(index);
683 // already verified to be utf8
684 const int name_ref_index =
685 cp->name_ref_index_at(name_and_type_ref_index);
686 // already verified to be utf8
687 const int signature_ref_index =
688 cp->signature_ref_index_at(name_and_type_ref_index);
689 const Symbol* const name = cp->symbol_at(name_ref_index);
690 const Symbol* const signature = cp->symbol_at(signature_ref_index);
691 if (_need_verify) {
692 // CONSTANT_Dynamic's name and signature are verified above, when iterating NameAndType_info.
693 // Need only to be sure signature is non-zero length and the right type.
694 if (signature->utf8_length() == 0 ||
695 signature->char_at(0) == JVM_SIGNATURE_FUNC) {
696 throwIllegalSignature("CONSTANT_Dynamic", name, signature, CHECK);
697 }
698 }
699 break;
700 }
701 case JVM_CONSTANT_InvokeDynamic:
702 case JVM_CONSTANT_Fieldref:
703 case JVM_CONSTANT_Methodref:
704 case JVM_CONSTANT_InterfaceMethodref: {
705 const int name_and_type_ref_index =
706 cp->name_and_type_ref_index_at(index);
707 // already verified to be utf8
708 const int name_ref_index =
709 cp->name_ref_index_at(name_and_type_ref_index);
710 // already verified to be utf8
711 const int signature_ref_index =
712 cp->signature_ref_index_at(name_and_type_ref_index);
713 const Symbol* const name = cp->symbol_at(name_ref_index);
714 const Symbol* const signature = cp->symbol_at(signature_ref_index);
715 if (tag == JVM_CONSTANT_Fieldref) {
716 if (_need_verify) {
717 // Field name and signature are verified above, when iterating NameAndType_info.
718 // Need only to be sure signature is non-zero length and the right type.
719 if (signature->utf8_length() == 0 ||
720 signature->char_at(0) == JVM_SIGNATURE_FUNC) {
721 throwIllegalSignature("Field", name, signature, CHECK);
722 }
723 }
724 } else {
725 if (_need_verify) {
726 // Method name and signature are verified above, when iterating NameAndType_info.
727 // Need only to be sure signature is non-zero length and the right type.
728 if (signature->utf8_length() == 0 ||
729 signature->char_at(0) != JVM_SIGNATURE_FUNC) {
730 throwIllegalSignature("Method", name, signature, CHECK);
731 }
732 }
733 // 4509014: If a class method name begins with '<', it must be "<init>"
734 const unsigned int name_len = name->utf8_length();
735 if (tag == JVM_CONSTANT_Methodref &&
736 name_len != 0 &&
737 name->char_at(0) == JVM_SIGNATURE_SPECIAL &&
738 name != vmSymbols::object_initializer_name()) {
739 classfile_parse_error(
740 "Bad method name at constant pool index %u in class file %s",
741 name_ref_index, CHECK);
742 }
743 }
744 break;
745 }
746 case JVM_CONSTANT_MethodHandle: {
747 const int ref_index = cp->method_handle_index_at(index);
748 const int ref_kind = cp->method_handle_ref_kind_at(index);
749 switch (ref_kind) {
1706 if (name == cp->symbol_at(f->name_index()) &&
1707 signature == cp->symbol_at(f->signature_index())) {
1708 // Symbol is desclared in Java so skip this one
1709 duplicate = true;
1710 break;
1711 }
1712 }
1713 if (duplicate) {
1714 // These will be removed from the field array at the end
1715 continue;
1716 }
1717 }
1718
1719 // Injected field
1720 FieldInfo* const field = FieldInfo::from_field_array(fa, index);
1721 field->initialize(JVM_ACC_FIELD_INTERNAL,
1722 injected[n].name_index,
1723 injected[n].signature_index,
1724 0);
1725
1726 const BasicType type = FieldType::basic_type(injected[n].signature());
1727
1728 // Remember how many oops we encountered and compute allocation type
1729 const FieldAllocationType atype = fac->update(false, type);
1730 field->set_allocation_type(atype);
1731 index++;
1732 }
1733 }
1734
1735 assert(NULL == _fields, "invariant");
1736
1737 _fields =
1738 MetadataFactory::new_array<u2>(_loader_data,
1739 index * FieldInfo::field_slots + num_generic_signature,
1740 CHECK);
1741 // Sometimes injected fields already exist in the Java source so
1742 // the fields array could be too long. In that case the
1743 // fields array is trimed. Also unused slots that were reserved
1744 // for generic signature indexes are discarded.
1745 {
1746 int i = 0;
2779 runtime_visible_parameter_annotations_length +
2780 runtime_invisible_parameter_annotations_length,
2781 runtime_visible_type_annotations_length +
2782 runtime_invisible_type_annotations_length,
2783 annotation_default_length,
2784 0);
2785
2786 Method* const m = Method::allocate(_loader_data,
2787 code_length,
2788 access_flags,
2789 &sizes,
2790 ConstMethod::NORMAL,
2791 CHECK_NULL);
2792
2793 ClassLoadingService::add_class_method_size(m->size()*wordSize);
2794
2795 // Fill in information from fixed part (access_flags already set)
2796 m->set_constants(_cp);
2797 m->set_name_index(name_index);
2798 m->set_signature_index(signature_index);
2799
2800 ResultTypeFinder rtf(cp->symbol_at(signature_index));
2801 m->constMethod()->set_result_type(rtf.type());
2802
2803 if (args_size >= 0) {
2804 m->set_size_of_parameters(args_size);
2805 } else {
2806 m->compute_size_of_parameters(THREAD);
2807 }
2808 #ifdef ASSERT
2809 if (args_size >= 0) {
2810 m->compute_size_of_parameters(THREAD);
2811 assert(args_size == m->size_of_parameters(), "");
2812 }
2813 #endif
2814
2815 // Fill in code attribute information
2816 m->set_max_stack(max_stack);
2817 m->set_max_locals(max_locals);
2818 if (stackmap_data != NULL) {
2819 m->constMethod()->copy_stackmap_data(_loader_data,
2820 (u1*)stackmap_data,
2821 stackmap_data_length,
2822 CHECK_NULL);
2823 }
2824
2825 // Copy byte codes
2826 m->set_code((u1*)code_start);
2827
2828 // Copy line number table
2829 if (linenumber_table != NULL) {
2830 memcpy(m->compressed_linenumber_table(),
2831 linenumber_table->buffer(),
2832 linenumber_table_length);
2833 }
|
648 switch (tag) {
649 case JVM_CONSTANT_UnresolvedClass: {
650 const Symbol* const class_name = cp->klass_name_at(index);
651 // check the name, even if _cp_patches will overwrite it
652 verify_legal_class_name(class_name, CHECK);
653 break;
654 }
655 case JVM_CONSTANT_NameAndType: {
656 if (_need_verify) {
657 const int sig_index = cp->signature_ref_index_at(index);
658 const int name_index = cp->name_ref_index_at(index);
659 const Symbol* const name = cp->symbol_at(name_index);
660 const Symbol* const sig = cp->symbol_at(sig_index);
661 guarantee_property(sig->utf8_length() != 0,
662 "Illegal zero length constant pool entry at %d in class %s",
663 sig_index, CHECK);
664 guarantee_property(name->utf8_length() != 0,
665 "Illegal zero length constant pool entry at %d in class %s",
666 name_index, CHECK);
667
668 if (Signature::is_method(sig)) {
669 // Format check method name and signature
670 verify_legal_method_name(name, CHECK);
671 verify_legal_method_signature(name, sig, CHECK);
672 } else {
673 // Format check field name and signature
674 verify_legal_field_name(name, CHECK);
675 verify_legal_field_signature(name, sig, CHECK);
676 }
677 }
678 break;
679 }
680 case JVM_CONSTANT_Dynamic: {
681 const int name_and_type_ref_index =
682 cp->name_and_type_ref_index_at(index);
683 // already verified to be utf8
684 const int name_ref_index =
685 cp->name_ref_index_at(name_and_type_ref_index);
686 // already verified to be utf8
687 const int signature_ref_index =
688 cp->signature_ref_index_at(name_and_type_ref_index);
689 const Symbol* const name = cp->symbol_at(name_ref_index);
690 const Symbol* const signature = cp->symbol_at(signature_ref_index);
691 if (_need_verify) {
692 // CONSTANT_Dynamic's name and signature are verified above, when iterating NameAndType_info.
693 // Need only to be sure signature is the right type.
694 if (Signature::is_method(signature)) {
695 throwIllegalSignature("CONSTANT_Dynamic", name, signature, CHECK);
696 }
697 }
698 break;
699 }
700 case JVM_CONSTANT_InvokeDynamic:
701 case JVM_CONSTANT_Fieldref:
702 case JVM_CONSTANT_Methodref:
703 case JVM_CONSTANT_InterfaceMethodref: {
704 const int name_and_type_ref_index =
705 cp->name_and_type_ref_index_at(index);
706 // already verified to be utf8
707 const int name_ref_index =
708 cp->name_ref_index_at(name_and_type_ref_index);
709 // already verified to be utf8
710 const int signature_ref_index =
711 cp->signature_ref_index_at(name_and_type_ref_index);
712 const Symbol* const name = cp->symbol_at(name_ref_index);
713 const Symbol* const signature = cp->symbol_at(signature_ref_index);
714 if (tag == JVM_CONSTANT_Fieldref) {
715 if (_need_verify) {
716 // Field name and signature are verified above, when iterating NameAndType_info.
717 // Need only to be sure signature is non-zero length and the right type.
718 if (Signature::is_method(signature)) {
719 throwIllegalSignature("Field", name, signature, CHECK);
720 }
721 }
722 } else {
723 if (_need_verify) {
724 // Method name and signature are verified above, when iterating NameAndType_info.
725 // Need only to be sure signature is non-zero length and the right type.
726 if (!Signature::is_method(signature)) {
727 throwIllegalSignature("Method", name, signature, CHECK);
728 }
729 }
730 // 4509014: If a class method name begins with '<', it must be "<init>"
731 const unsigned int name_len = name->utf8_length();
732 if (tag == JVM_CONSTANT_Methodref &&
733 name_len != 0 &&
734 name->char_at(0) == JVM_SIGNATURE_SPECIAL &&
735 name != vmSymbols::object_initializer_name()) {
736 classfile_parse_error(
737 "Bad method name at constant pool index %u in class file %s",
738 name_ref_index, CHECK);
739 }
740 }
741 break;
742 }
743 case JVM_CONSTANT_MethodHandle: {
744 const int ref_index = cp->method_handle_index_at(index);
745 const int ref_kind = cp->method_handle_ref_kind_at(index);
746 switch (ref_kind) {
1703 if (name == cp->symbol_at(f->name_index()) &&
1704 signature == cp->symbol_at(f->signature_index())) {
1705 // Symbol is desclared in Java so skip this one
1706 duplicate = true;
1707 break;
1708 }
1709 }
1710 if (duplicate) {
1711 // These will be removed from the field array at the end
1712 continue;
1713 }
1714 }
1715
1716 // Injected field
1717 FieldInfo* const field = FieldInfo::from_field_array(fa, index);
1718 field->initialize(JVM_ACC_FIELD_INTERNAL,
1719 injected[n].name_index,
1720 injected[n].signature_index,
1721 0);
1722
1723 const BasicType type = Signature::basic_type(injected[n].signature());
1724
1725 // Remember how many oops we encountered and compute allocation type
1726 const FieldAllocationType atype = fac->update(false, type);
1727 field->set_allocation_type(atype);
1728 index++;
1729 }
1730 }
1731
1732 assert(NULL == _fields, "invariant");
1733
1734 _fields =
1735 MetadataFactory::new_array<u2>(_loader_data,
1736 index * FieldInfo::field_slots + num_generic_signature,
1737 CHECK);
1738 // Sometimes injected fields already exist in the Java source so
1739 // the fields array could be too long. In that case the
1740 // fields array is trimed. Also unused slots that were reserved
1741 // for generic signature indexes are discarded.
1742 {
1743 int i = 0;
2776 runtime_visible_parameter_annotations_length +
2777 runtime_invisible_parameter_annotations_length,
2778 runtime_visible_type_annotations_length +
2779 runtime_invisible_type_annotations_length,
2780 annotation_default_length,
2781 0);
2782
2783 Method* const m = Method::allocate(_loader_data,
2784 code_length,
2785 access_flags,
2786 &sizes,
2787 ConstMethod::NORMAL,
2788 CHECK_NULL);
2789
2790 ClassLoadingService::add_class_method_size(m->size()*wordSize);
2791
2792 // Fill in information from fixed part (access_flags already set)
2793 m->set_constants(_cp);
2794 m->set_name_index(name_index);
2795 m->set_signature_index(signature_index);
2796 m->compute_from_signature(cp->symbol_at(signature_index));
2797 assert(args_size < 0 || args_size == m->size_of_parameters(), "");
2798
2799 // Fill in code attribute information
2800 m->set_max_stack(max_stack);
2801 m->set_max_locals(max_locals);
2802 if (stackmap_data != NULL) {
2803 m->constMethod()->copy_stackmap_data(_loader_data,
2804 (u1*)stackmap_data,
2805 stackmap_data_length,
2806 CHECK_NULL);
2807 }
2808
2809 // Copy byte codes
2810 m->set_code((u1*)code_start);
2811
2812 // Copy line number table
2813 if (linenumber_table != NULL) {
2814 memcpy(m->compressed_linenumber_table(),
2815 linenumber_table->buffer(),
2816 linenumber_table_length);
2817 }
|