389 // a bad CP entry has been detected previously so stop parsing and just return. |
389 // a bad CP entry has been detected previously so stop parsing and just return. |
390 return; |
390 return; |
391 } |
391 } |
392 |
392 |
393 int index = 1; // declared outside of loops for portability |
393 int index = 1; // declared outside of loops for portability |
|
394 int num_klasses = 0; |
394 |
395 |
395 // first verification pass - validate cross references |
396 // first verification pass - validate cross references |
396 // and fixup class and string constants |
397 // and fixup class and string constants |
397 for (index = 1; index < length; index++) { // Index 0 is unused |
398 for (index = 1; index < length; index++) { // Index 0 is unused |
398 const jbyte tag = cp->tag_at(index).value(); |
399 const jbyte tag = cp->tag_at(index).value(); |
457 case JVM_CONSTANT_ClassIndex: { |
458 case JVM_CONSTANT_ClassIndex: { |
458 const int class_index = cp->klass_index_at(index); |
459 const int class_index = cp->klass_index_at(index); |
459 check_property(valid_symbol_at(class_index), |
460 check_property(valid_symbol_at(class_index), |
460 "Invalid constant pool index %u in class file %s", |
461 "Invalid constant pool index %u in class file %s", |
461 class_index, CHECK); |
462 class_index, CHECK); |
462 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index)); |
463 cp->unresolved_klass_at_put(index, class_index, num_klasses++); |
463 break; |
464 break; |
464 } |
465 } |
465 case JVM_CONSTANT_StringIndex: { |
466 case JVM_CONSTANT_StringIndex: { |
466 const int string_index = cp->string_index_at(index); |
467 const int string_index = cp->string_index_at(index); |
467 check_property(valid_symbol_at(string_index), |
468 check_property(valid_symbol_at(string_index), |
548 break; |
549 break; |
549 } |
550 } |
550 } // switch(tag) |
551 } // switch(tag) |
551 } // end of for |
552 } // end of for |
552 |
553 |
|
554 _first_patched_klass_resolved_index = num_klasses; |
|
555 cp->allocate_resolved_klasses(_loader_data, num_klasses + _max_num_patched_klasses, CHECK); |
|
556 |
553 if (_cp_patches != NULL) { |
557 if (_cp_patches != NULL) { |
554 // need to treat this_class specially... |
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 |
555 int this_class_index; |
567 int this_class_index; |
556 { |
568 { |
557 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len |
569 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len |
558 const u1* const mark = stream->current(); |
570 const u1* const mark = stream->current(); |
559 stream->skip_u2_fast(1); // skip flags |
571 stream->skip_u2_fast(1); // skip flags |
699 } |
711 } |
700 } // switch(tag) |
712 } // switch(tag) |
701 } // end of for |
713 } // end of for |
702 } |
714 } |
703 |
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 |
704 void ClassFileParser::patch_constant_pool(ConstantPool* cp, |
724 void ClassFileParser::patch_constant_pool(ConstantPool* cp, |
705 int index, |
725 int index, |
706 Handle patch, |
726 Handle patch, |
707 TRAPS) { |
727 TRAPS) { |
708 assert(cp != NULL, "invariant"); |
728 assert(cp != NULL, "invariant"); |
716 // The name in the constant pool is ignored. |
736 // The name in the constant pool is ignored. |
717 if (java_lang_Class::is_instance(patch())) { |
737 if (java_lang_Class::is_instance(patch())) { |
718 guarantee_property(!java_lang_Class::is_primitive(patch()), |
738 guarantee_property(!java_lang_Class::is_primitive(patch()), |
719 "Illegal class patch at %d in class file %s", |
739 "Illegal class patch at %d in class file %s", |
720 index, CHECK); |
740 index, CHECK); |
721 cp->klass_at_put(index, java_lang_Class::as_Klass(patch())); |
741 Klass* k = java_lang_Class::as_Klass(patch()); |
|
742 patch_class(cp, index, k, k->name()); |
722 } else { |
743 } else { |
723 guarantee_property(java_lang_String::is_instance(patch()), |
744 guarantee_property(java_lang_String::is_instance(patch()), |
724 "Illegal class patch at %d in class file %s", |
745 "Illegal class patch at %d in class file %s", |
725 index, CHECK); |
746 index, CHECK); |
726 Symbol* const name = java_lang_String::as_symbol(patch(), CHECK); |
747 Symbol* const name = java_lang_String::as_symbol(patch(), CHECK); |
727 cp->unresolved_klass_at_put(index, name); |
748 patch_class(cp, index, NULL, name); |
728 } |
749 } |
729 break; |
750 break; |
730 } |
751 } |
731 |
752 |
732 case JVM_CONSTANT_String: { |
753 case JVM_CONSTANT_String: { |
5338 ik->set_initial_method_idnum(ik->methods()->length()); |
5359 ik->set_initial_method_idnum(ik->methods()->length()); |
5339 |
5360 |
5340 ik->set_name(_class_name); |
5361 ik->set_name(_class_name); |
5341 |
5362 |
5342 if (is_anonymous()) { |
5363 if (is_anonymous()) { |
5343 // I am well known to myself |
5364 // _this_class_index is a CONSTANT_Class entry that refers to this |
5344 ik->constants()->klass_at_put(_this_class_index, ik); // eagerly resolve |
5365 // anonymous class itself. If this class needs to refer to its own methods or |
|
5366 // fields, it would use a CONSTANT_MethodRef, etc, which would reference |
|
5367 // _this_class_index. However, because this class is anonymous (it's |
|
5368 // not stored in SystemDictionary), _this_class_index cannot be resolved |
|
5369 // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup. |
|
5370 // Therefore, we must eagerly resolve _this_class_index now. |
|
5371 ik->constants()->klass_at_put(_this_class_index, ik); |
5345 } |
5372 } |
5346 |
5373 |
5347 ik->set_minor_version(_minor_version); |
5374 ik->set_minor_version(_minor_version); |
5348 ik->set_major_version(_major_version); |
5375 ik->set_major_version(_major_version); |
5349 ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods); |
5376 ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods); |
5575 _stream(stream), |
5602 _stream(stream), |
5576 _requested_name(name), |
5603 _requested_name(name), |
5577 _loader_data(loader_data), |
5604 _loader_data(loader_data), |
5578 _host_klass(host_klass), |
5605 _host_klass(host_klass), |
5579 _cp_patches(cp_patches), |
5606 _cp_patches(cp_patches), |
|
5607 _num_patched_klasses(0), |
|
5608 _max_num_patched_klasses(0), |
|
5609 _orig_cp_size(0), |
|
5610 _first_patched_klass_resolved_index(0), |
5580 _super_klass(), |
5611 _super_klass(), |
5581 _cp(NULL), |
5612 _cp(NULL), |
5582 _fields(NULL), |
5613 _fields(NULL), |
5583 _methods(NULL), |
5614 _methods(NULL), |
5584 _inner_classes(NULL), |
5615 _inner_classes(NULL), |
5645 } |
5676 } |
5646 else { |
5677 else { |
5647 _need_verify = Verifier::should_verify_for(_loader_data->class_loader(), |
5678 _need_verify = Verifier::should_verify_for(_loader_data->class_loader(), |
5648 stream->need_verify()); |
5679 stream->need_verify()); |
5649 } |
5680 } |
|
5681 if (_cp_patches != NULL) { |
|
5682 int len = _cp_patches->length(); |
|
5683 for (int i=0; i<len; i++) { |
|
5684 if (has_cp_patch_at(i)) { |
|
5685 Handle patch = cp_patch_at(i); |
|
5686 if (java_lang_String::is_instance(patch()) || java_lang_Class::is_instance(patch())) { |
|
5687 // We need to append the names of the patched classes to the end of the constant pool, |
|
5688 // because a patched class may have a Utf8 name that's not already included in the |
|
5689 // original constant pool. These class names are used when patch_constant_pool() |
|
5690 // calls patch_class(). |
|
5691 // |
|
5692 // Note that a String in cp_patch_at(i) may be used to patch a Utf8, a String, or a Class. |
|
5693 // At this point, we don't know the tag for index i yet, because we haven't parsed the |
|
5694 // constant pool. So we can only assume the worst -- every String is used to patch a Class. |
|
5695 _max_num_patched_klasses++; |
|
5696 } |
|
5697 } |
|
5698 } |
|
5699 } |
5650 |
5700 |
5651 // synch back verification state to stream |
5701 // synch back verification state to stream |
5652 stream->set_verify(_need_verify); |
5702 stream->set_verify(_need_verify); |
5653 |
5703 |
5654 // Check if verification needs to be relaxed for this class file |
5704 // Check if verification needs to be relaxed for this class file |
5774 JAVA_MAX_SUPPORTED_MINOR_VERSION); |
5824 JAVA_MAX_SUPPORTED_MINOR_VERSION); |
5775 return; |
5825 return; |
5776 } |
5826 } |
5777 |
5827 |
5778 stream->guarantee_more(3, CHECK); // length, first cp tag |
5828 stream->guarantee_more(3, CHECK); // length, first cp tag |
5779 const u2 cp_size = stream->get_u2_fast(); |
5829 u2 cp_size = stream->get_u2_fast(); |
5780 |
5830 |
5781 guarantee_property( |
5831 guarantee_property( |
5782 cp_size >= 1, "Illegal constant pool size %u in class file %s", |
5832 cp_size >= 1, "Illegal constant pool size %u in class file %s", |
5783 cp_size, CHECK); |
5833 cp_size, CHECK); |
5784 |
5834 |
|
5835 _orig_cp_size = cp_size; |
|
5836 if (int(cp_size) + _max_num_patched_klasses > 0xffff) { |
|
5837 THROW_MSG(vmSymbols::java_lang_InternalError(), "not enough space for patched classes"); |
|
5838 } |
|
5839 cp_size += _max_num_patched_klasses; |
|
5840 |
5785 _cp = ConstantPool::allocate(_loader_data, |
5841 _cp = ConstantPool::allocate(_loader_data, |
5786 cp_size, |
5842 cp_size, |
5787 CHECK); |
5843 CHECK); |
5788 |
5844 |
5789 ConstantPool* const cp = _cp; |
5845 ConstantPool* const cp = _cp; |
5790 |
5846 |
5791 parse_constant_pool(stream, cp, cp_size, CHECK); |
5847 parse_constant_pool(stream, cp, _orig_cp_size, CHECK); |
5792 |
5848 |
5793 assert(cp_size == (const u2)cp->length(), "invariant"); |
5849 assert(cp_size == (const u2)cp->length(), "invariant"); |
5794 |
5850 |
5795 // ACCESS FLAGS |
5851 // ACCESS FLAGS |
5796 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len |
5852 stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len |