src/hotspot/share/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff src/hotspot/share/classfile

src/hotspot/share/classfile/classFileParser.cpp

Print this page




3575     // The annotations arrays below has been transfered the
3576     // _combined_annotations so these fields can now be cleared.
3577     _annotations             = NULL;
3578     _type_annotations        = NULL;
3579     _fields_annotations      = NULL;
3580     _fields_type_annotations = NULL;
3581 }
3582 
3583 // Transfer ownership of metadata allocated to the InstanceKlass.
3584 void ClassFileParser::apply_parsed_class_metadata(
3585                                             InstanceKlass* this_klass,
3586                                             int java_fields_count, TRAPS) {
3587   assert(this_klass != NULL, "invariant");
3588 
3589   _cp->set_pool_holder(this_klass);
3590   this_klass->set_constants(_cp);
3591   this_klass->set_fields(_fields, java_fields_count);
3592   this_klass->set_methods(_methods);
3593   this_klass->set_inner_classes(_inner_classes);
3594   this_klass->set_local_interfaces(_local_interfaces);
3595   this_klass->set_transitive_interfaces(_transitive_interfaces);
3596   this_klass->set_annotations(_combined_annotations);






3597 
3598   // Clear out these fields so they don't get deallocated by the destructor
3599   clear_class_metadata();
3600 }
3601 
3602 AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations,
3603                                                        int runtime_visible_annotations_length,
3604                                                        const u1* const runtime_invisible_annotations,
3605                                                        int runtime_invisible_annotations_length,
3606                                                        TRAPS) {
3607   AnnotationArray* annotations = NULL;
3608   if (runtime_visible_annotations != NULL ||
3609       runtime_invisible_annotations != NULL) {
3610     annotations = MetadataFactory::new_array<u1>(_loader_data,
3611                                           runtime_visible_annotations_length +
3612                                           runtime_invisible_annotations_length,
3613                                           CHECK_(annotations));
3614     if (runtime_visible_annotations != NULL) {
3615       for (int i = 0; i < runtime_visible_annotations_length; i++) {
3616         annotations->at_put(i, runtime_visible_annotations[i]);


5445 
5446   // Fill in information already parsed
5447   ik->set_should_verify_class(_need_verify);
5448 
5449   // Not yet: supers are done below to support the new subtype-checking fields
5450   ik->set_nonstatic_field_size(_field_info->nonstatic_field_size);
5451   ik->set_has_nonstatic_fields(_field_info->has_nonstatic_fields);
5452   assert(_fac != NULL, "invariant");
5453   ik->set_static_oop_field_count(_fac->count[STATIC_OOP]);
5454 
5455   // this transfers ownership of a lot of arrays from
5456   // the parser onto the InstanceKlass*
5457   apply_parsed_class_metadata(ik, _java_fields_count, CHECK);
5458 
5459   // note that is not safe to use the fields in the parser from this point on
5460   assert(NULL == _cp, "invariant");
5461   assert(NULL == _fields, "invariant");
5462   assert(NULL == _methods, "invariant");
5463   assert(NULL == _inner_classes, "invariant");
5464   assert(NULL == _local_interfaces, "invariant");
5465   assert(NULL == _transitive_interfaces, "invariant");
5466   assert(NULL == _combined_annotations, "invariant");
5467 
5468   if (_has_final_method) {
5469     ik->set_has_final_method();
5470   }
5471 
5472   ik->copy_method_ordering(_method_ordering, CHECK);
5473   // The InstanceKlass::_methods_jmethod_ids cache
5474   // is managed on the assumption that the initial cache
5475   // size is equal to the number of methods in the class. If
5476   // that changes, then InstanceKlass::idnum_can_increment()
5477   // has to be changed accordingly.
5478   ik->set_initial_method_idnum(ik->methods()->length());
5479 
5480   ik->set_this_class_index(_this_class_index);
5481 
5482   if (is_anonymous()) {
5483     // _this_class_index is a CONSTANT_Class entry that refers to this
5484     // anonymous class itself. If this class needs to refer to its own methods or
5485     // fields, it would use a CONSTANT_MethodRef, etc, which would reference


5512 
5513   check_methods_for_intrinsics(ik, methods);
5514 
5515   // Fill in field values obtained by parse_classfile_attributes
5516   if (_parsed_annotations->has_any_annotations()) {
5517     _parsed_annotations->apply_to(ik);
5518   }
5519 
5520   apply_parsed_class_attributes(ik);
5521 
5522   // Miranda methods
5523   if ((_num_miranda_methods > 0) ||
5524       // if this class introduced new miranda methods or
5525       (_super_klass != NULL && _super_klass->has_miranda_methods())
5526         // super class exists and this class inherited miranda methods
5527      ) {
5528        ik->set_has_miranda_methods(); // then set a flag
5529   }
5530 
5531   // Fill in information needed to compute superclasses.
5532   ik->initialize_supers(const_cast<InstanceKlass*>(_super_klass), CHECK);


5533 
5534   // Initialize itable offset tables
5535   klassItable::setup_itable_offset_table(ik);
5536 
5537   // Compute transitive closure of interfaces this class implements
5538   // Do final class setup
5539   fill_oop_maps(ik,
5540                 _field_info->nonstatic_oop_map_count,
5541                 _field_info->nonstatic_oop_offsets,
5542                 _field_info->nonstatic_oop_counts);
5543 
5544   // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
5545   set_precomputed_flags(ik);
5546 
5547   // check if this class can access its super class
5548   check_super_class_access(ik, CHECK);
5549 
5550   // check if this class can access its superinterfaces
5551   check_super_interface_access(ik, CHECK);
5552 


5817   // synch back verification state to stream
5818   stream->set_verify(_need_verify);
5819 
5820   // Check if verification needs to be relaxed for this class file
5821   // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
5822   _relax_verify = relax_format_check_for(_loader_data);
5823 
5824   parse_stream(stream, CHECK);
5825 
5826   post_process_parsed_stream(stream, _cp, CHECK);
5827 }
5828 
5829 void ClassFileParser::clear_class_metadata() {
5830   // metadata created before the instance klass is created.  Must be
5831   // deallocated if classfile parsing returns an error.
5832   _cp = NULL;
5833   _fields = NULL;
5834   _methods = NULL;
5835   _inner_classes = NULL;
5836   _local_interfaces = NULL;
5837   _transitive_interfaces = NULL;
5838   _combined_annotations = NULL;
5839   _annotations = _type_annotations = NULL;
5840   _fields_annotations = _fields_type_annotations = NULL;
5841 }
5842 
5843 // Destructor to clean up
5844 ClassFileParser::~ClassFileParser() {
5845   if (_cp != NULL) {
5846     MetadataFactory::free_metadata(_loader_data, _cp);
5847   }
5848   if (_fields != NULL) {
5849     MetadataFactory::free_array<u2>(_loader_data, _fields);
5850   }
5851 
5852   if (_methods != NULL) {
5853     // Free methods
5854     InstanceKlass::deallocate_methods(_loader_data, _methods);
5855   }
5856 
5857   // beware of the Universe::empty_blah_array!!


5869 
5870     // Deallocate the Annotations object and the installed annotations arrays.
5871     _combined_annotations->deallocate_contents(_loader_data);
5872 
5873     // If the _combined_annotations pointer is non-NULL,
5874     // then the other annotations fields should have been cleared.
5875     assert(_annotations             == NULL, "Should have been cleared");
5876     assert(_type_annotations        == NULL, "Should have been cleared");
5877     assert(_fields_annotations      == NULL, "Should have been cleared");
5878     assert(_fields_type_annotations == NULL, "Should have been cleared");
5879   } else {
5880     // If the annotations arrays were not installed into the Annotations object,
5881     // then they have to be deallocated explicitly.
5882     MetadataFactory::free_array<u1>(_loader_data, _annotations);
5883     MetadataFactory::free_array<u1>(_loader_data, _type_annotations);
5884     Annotations::free_contents(_loader_data, _fields_annotations);
5885     Annotations::free_contents(_loader_data, _fields_type_annotations);
5886   }
5887 
5888   clear_class_metadata();

5889 
5890   // deallocate the klass if already created.  Don't directly deallocate, but add
5891   // to the deallocate list so that the klass is removed from the CLD::_klasses list
5892   // at a safepoint.
5893   if (_klass_to_deallocate != NULL) {
5894     _loader_data->add_to_deallocate_list(_klass_to_deallocate);
5895   }
5896 }
5897 
5898 void ClassFileParser::parse_stream(const ClassFileStream* const stream,
5899                                    TRAPS) {
5900 
5901   assert(stream != NULL, "invariant");
5902   assert(_class_name != NULL, "invariant");
5903 
5904   // BEGIN STREAM PARSING
5905   stream->guarantee_more(8, CHECK);  // magic, major, minor
5906   // Magic value
5907   const u4 magic = stream->get_u4_fast();
5908   guarantee_property(magic == JAVA_CLASSFILE_MAGIC,




3575     // The annotations arrays below has been transfered the
3576     // _combined_annotations so these fields can now be cleared.
3577     _annotations             = NULL;
3578     _type_annotations        = NULL;
3579     _fields_annotations      = NULL;
3580     _fields_type_annotations = NULL;
3581 }
3582 
3583 // Transfer ownership of metadata allocated to the InstanceKlass.
3584 void ClassFileParser::apply_parsed_class_metadata(
3585                                             InstanceKlass* this_klass,
3586                                             int java_fields_count, TRAPS) {
3587   assert(this_klass != NULL, "invariant");
3588 
3589   _cp->set_pool_holder(this_klass);
3590   this_klass->set_constants(_cp);
3591   this_klass->set_fields(_fields, java_fields_count);
3592   this_klass->set_methods(_methods);
3593   this_klass->set_inner_classes(_inner_classes);
3594   this_klass->set_local_interfaces(_local_interfaces);

3595   this_klass->set_annotations(_combined_annotations);
3596   // Delay the setting of _transitive_interfaces until after initialize_supers() in
3597   // fill_instance_klass(). It is because the _transitive_interfaces may be shared with
3598   // its _super. If an OOM occurs while loading the current klass, its _super field
3599   // may not have been set. When GC tries to free the klass, the _transitive_interfaces
3600   // may be deallocated mistakenly in InstanceKlass::deallocate_interfaces(). Subsequent
3601   // dereferences to the deallocated _transitive_interfaces will result in a crash.
3602 
3603   // Clear out these fields so they don't get deallocated by the destructor
3604   clear_class_metadata();
3605 }
3606 
3607 AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations,
3608                                                        int runtime_visible_annotations_length,
3609                                                        const u1* const runtime_invisible_annotations,
3610                                                        int runtime_invisible_annotations_length,
3611                                                        TRAPS) {
3612   AnnotationArray* annotations = NULL;
3613   if (runtime_visible_annotations != NULL ||
3614       runtime_invisible_annotations != NULL) {
3615     annotations = MetadataFactory::new_array<u1>(_loader_data,
3616                                           runtime_visible_annotations_length +
3617                                           runtime_invisible_annotations_length,
3618                                           CHECK_(annotations));
3619     if (runtime_visible_annotations != NULL) {
3620       for (int i = 0; i < runtime_visible_annotations_length; i++) {
3621         annotations->at_put(i, runtime_visible_annotations[i]);


5450 
5451   // Fill in information already parsed
5452   ik->set_should_verify_class(_need_verify);
5453 
5454   // Not yet: supers are done below to support the new subtype-checking fields
5455   ik->set_nonstatic_field_size(_field_info->nonstatic_field_size);
5456   ik->set_has_nonstatic_fields(_field_info->has_nonstatic_fields);
5457   assert(_fac != NULL, "invariant");
5458   ik->set_static_oop_field_count(_fac->count[STATIC_OOP]);
5459 
5460   // this transfers ownership of a lot of arrays from
5461   // the parser onto the InstanceKlass*
5462   apply_parsed_class_metadata(ik, _java_fields_count, CHECK);
5463 
5464   // note that is not safe to use the fields in the parser from this point on
5465   assert(NULL == _cp, "invariant");
5466   assert(NULL == _fields, "invariant");
5467   assert(NULL == _methods, "invariant");
5468   assert(NULL == _inner_classes, "invariant");
5469   assert(NULL == _local_interfaces, "invariant");

5470   assert(NULL == _combined_annotations, "invariant");
5471 
5472   if (_has_final_method) {
5473     ik->set_has_final_method();
5474   }
5475 
5476   ik->copy_method_ordering(_method_ordering, CHECK);
5477   // The InstanceKlass::_methods_jmethod_ids cache
5478   // is managed on the assumption that the initial cache
5479   // size is equal to the number of methods in the class. If
5480   // that changes, then InstanceKlass::idnum_can_increment()
5481   // has to be changed accordingly.
5482   ik->set_initial_method_idnum(ik->methods()->length());
5483 
5484   ik->set_this_class_index(_this_class_index);
5485 
5486   if (is_anonymous()) {
5487     // _this_class_index is a CONSTANT_Class entry that refers to this
5488     // anonymous class itself. If this class needs to refer to its own methods or
5489     // fields, it would use a CONSTANT_MethodRef, etc, which would reference


5516 
5517   check_methods_for_intrinsics(ik, methods);
5518 
5519   // Fill in field values obtained by parse_classfile_attributes
5520   if (_parsed_annotations->has_any_annotations()) {
5521     _parsed_annotations->apply_to(ik);
5522   }
5523 
5524   apply_parsed_class_attributes(ik);
5525 
5526   // Miranda methods
5527   if ((_num_miranda_methods > 0) ||
5528       // if this class introduced new miranda methods or
5529       (_super_klass != NULL && _super_klass->has_miranda_methods())
5530         // super class exists and this class inherited miranda methods
5531      ) {
5532        ik->set_has_miranda_methods(); // then set a flag
5533   }
5534 
5535   // Fill in information needed to compute superclasses.
5536   ik->initialize_supers(const_cast<InstanceKlass*>(_super_klass), _transitive_interfaces, CHECK);
5537   ik->set_transitive_interfaces(_transitive_interfaces);
5538   _transitive_interfaces = NULL;
5539 
5540   // Initialize itable offset tables
5541   klassItable::setup_itable_offset_table(ik);
5542 
5543   // Compute transitive closure of interfaces this class implements
5544   // Do final class setup
5545   fill_oop_maps(ik,
5546                 _field_info->nonstatic_oop_map_count,
5547                 _field_info->nonstatic_oop_offsets,
5548                 _field_info->nonstatic_oop_counts);
5549 
5550   // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
5551   set_precomputed_flags(ik);
5552 
5553   // check if this class can access its super class
5554   check_super_class_access(ik, CHECK);
5555 
5556   // check if this class can access its superinterfaces
5557   check_super_interface_access(ik, CHECK);
5558 


5823   // synch back verification state to stream
5824   stream->set_verify(_need_verify);
5825 
5826   // Check if verification needs to be relaxed for this class file
5827   // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
5828   _relax_verify = relax_format_check_for(_loader_data);
5829 
5830   parse_stream(stream, CHECK);
5831 
5832   post_process_parsed_stream(stream, _cp, CHECK);
5833 }
5834 
5835 void ClassFileParser::clear_class_metadata() {
5836   // metadata created before the instance klass is created.  Must be
5837   // deallocated if classfile parsing returns an error.
5838   _cp = NULL;
5839   _fields = NULL;
5840   _methods = NULL;
5841   _inner_classes = NULL;
5842   _local_interfaces = NULL;

5843   _combined_annotations = NULL;
5844   _annotations = _type_annotations = NULL;
5845   _fields_annotations = _fields_type_annotations = NULL;
5846 }
5847 
5848 // Destructor to clean up
5849 ClassFileParser::~ClassFileParser() {
5850   if (_cp != NULL) {
5851     MetadataFactory::free_metadata(_loader_data, _cp);
5852   }
5853   if (_fields != NULL) {
5854     MetadataFactory::free_array<u2>(_loader_data, _fields);
5855   }
5856 
5857   if (_methods != NULL) {
5858     // Free methods
5859     InstanceKlass::deallocate_methods(_loader_data, _methods);
5860   }
5861 
5862   // beware of the Universe::empty_blah_array!!


5874 
5875     // Deallocate the Annotations object and the installed annotations arrays.
5876     _combined_annotations->deallocate_contents(_loader_data);
5877 
5878     // If the _combined_annotations pointer is non-NULL,
5879     // then the other annotations fields should have been cleared.
5880     assert(_annotations             == NULL, "Should have been cleared");
5881     assert(_type_annotations        == NULL, "Should have been cleared");
5882     assert(_fields_annotations      == NULL, "Should have been cleared");
5883     assert(_fields_type_annotations == NULL, "Should have been cleared");
5884   } else {
5885     // If the annotations arrays were not installed into the Annotations object,
5886     // then they have to be deallocated explicitly.
5887     MetadataFactory::free_array<u1>(_loader_data, _annotations);
5888     MetadataFactory::free_array<u1>(_loader_data, _type_annotations);
5889     Annotations::free_contents(_loader_data, _fields_annotations);
5890     Annotations::free_contents(_loader_data, _fields_type_annotations);
5891   }
5892 
5893   clear_class_metadata();
5894   _transitive_interfaces = NULL;
5895 
5896   // deallocate the klass if already created.  Don't directly deallocate, but add
5897   // to the deallocate list so that the klass is removed from the CLD::_klasses list
5898   // at a safepoint.
5899   if (_klass_to_deallocate != NULL) {
5900     _loader_data->add_to_deallocate_list(_klass_to_deallocate);
5901   }
5902 }
5903 
5904 void ClassFileParser::parse_stream(const ClassFileStream* const stream,
5905                                    TRAPS) {
5906 
5907   assert(stream != NULL, "invariant");
5908   assert(_class_name != NULL, "invariant");
5909 
5910   // BEGIN STREAM PARSING
5911   stream->guarantee_more(8, CHECK);  // magic, major, minor
5912   // Magic value
5913   const u4 magic = stream->get_u4_fast();
5914   guarantee_property(magic == JAVA_CLASSFILE_MAGIC,


src/hotspot/share/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File