Merge

Thu, 11 Dec 2014 10:38:17 +0000

author
stefank
date
Thu, 11 Dec 2014 10:38:17 +0000
changeset 7418
8c08b28b7eee
parent 7416
b5eb829bbce1
parent 7417
0fa1f71a905b
child 7419
d3f3f7677537

Merge

     1.1 --- a/src/share/vm/classfile/classFileParser.cpp	Tue Dec 09 12:25:38 2014 -0800
     1.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Thu Dec 11 10:38:17 2014 +0000
     1.3 @@ -3058,21 +3058,39 @@
     1.4    }
     1.5  }
     1.6  
     1.7 -// Transfer ownership of metadata allocated to the InstanceKlass.
     1.8 -void ClassFileParser::apply_parsed_class_metadata(
     1.9 -                                            instanceKlassHandle this_klass,
    1.10 -                                            int java_fields_count, TRAPS) {
    1.11 -  // Assign annotations if needed
    1.12 -  if (_annotations != NULL || _type_annotations != NULL ||
    1.13 -      _fields_annotations != NULL || _fields_type_annotations != NULL) {
    1.14 +// Create the Annotations object that will
    1.15 +// hold the annotations array for the Klass.
    1.16 +void ClassFileParser::create_combined_annotations(TRAPS) {
    1.17 +    if (_annotations == NULL &&
    1.18 +        _type_annotations == NULL &&
    1.19 +        _fields_annotations == NULL &&
    1.20 +        _fields_type_annotations == NULL) {
    1.21 +      // Don't create the Annotations object unnecessarily.
    1.22 +      return;
    1.23 +    }
    1.24 +
    1.25      Annotations* annotations = Annotations::allocate(_loader_data, CHECK);
    1.26      annotations->set_class_annotations(_annotations);
    1.27      annotations->set_class_type_annotations(_type_annotations);
    1.28      annotations->set_fields_annotations(_fields_annotations);
    1.29      annotations->set_fields_type_annotations(_fields_type_annotations);
    1.30 -    this_klass->set_annotations(annotations);
    1.31 -  }
    1.32 -
    1.33 +
    1.34 +    // This is the Annotations object that will be
    1.35 +    // assigned to InstanceKlass being constructed.
    1.36 +    _combined_annotations = annotations;
    1.37 +
    1.38 +    // The annotations arrays below has been transfered the
    1.39 +    // _combined_annotations so these fields can now be cleared.
    1.40 +    _annotations             = NULL;
    1.41 +    _type_annotations        = NULL;
    1.42 +    _fields_annotations      = NULL;
    1.43 +    _fields_type_annotations = NULL;
    1.44 +}
    1.45 +
    1.46 +// Transfer ownership of metadata allocated to the InstanceKlass.
    1.47 +void ClassFileParser::apply_parsed_class_metadata(
    1.48 +                                            instanceKlassHandle this_klass,
    1.49 +                                            int java_fields_count, TRAPS) {
    1.50    _cp->set_pool_holder(this_klass());
    1.51    this_klass->set_constants(_cp);
    1.52    this_klass->set_fields(_fields, java_fields_count);
    1.53 @@ -3080,6 +3098,7 @@
    1.54    this_klass->set_inner_classes(_inner_classes);
    1.55    this_klass->set_local_interfaces(_local_interfaces);
    1.56    this_klass->set_transitive_interfaces(_transitive_interfaces);
    1.57 +  this_klass->set_annotations(_combined_annotations);
    1.58  
    1.59    // Clear out these fields so they don't get deallocated by the destructor
    1.60    clear_class_metadata();
    1.61 @@ -3939,6 +3958,10 @@
    1.62      ClassAnnotationCollector parsed_annotations;
    1.63      parse_classfile_attributes(&parsed_annotations, CHECK_(nullHandle));
    1.64  
    1.65 +    // Finalize the Annotations metadata object,
    1.66 +    // now that all annotation arrays have been created.
    1.67 +    create_combined_annotations(CHECK_(nullHandle));
    1.68 +
    1.69      // Make sure this is the end of class file stream
    1.70      guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
    1.71  
    1.72 @@ -4239,10 +4262,27 @@
    1.73    InstanceKlass::deallocate_interfaces(_loader_data, _super_klass(),
    1.74                                         _local_interfaces, _transitive_interfaces);
    1.75  
    1.76 -  MetadataFactory::free_array<u1>(_loader_data, _annotations);
    1.77 -  MetadataFactory::free_array<u1>(_loader_data, _type_annotations);
    1.78 -  Annotations::free_contents(_loader_data, _fields_annotations);
    1.79 -  Annotations::free_contents(_loader_data, _fields_type_annotations);
    1.80 +  if (_combined_annotations != NULL) {
    1.81 +    // After all annotations arrays have been created, they are installed into the
    1.82 +    // Annotations object that will be assigned to the InstanceKlass being created.
    1.83 +
    1.84 +    // Deallocate the Annotations object and the installed annotations arrays.
    1.85 +    _combined_annotations->deallocate_contents(_loader_data);
    1.86 +
    1.87 +    // If the _combined_annotations pointer is non-NULL,
    1.88 +    // then the other annotations fields should have been cleared.
    1.89 +    assert(_annotations             == NULL, "Should have been cleared");
    1.90 +    assert(_type_annotations        == NULL, "Should have been cleared");
    1.91 +    assert(_fields_annotations      == NULL, "Should have been cleared");
    1.92 +    assert(_fields_type_annotations == NULL, "Should have been cleared");
    1.93 +  } else {
    1.94 +    // If the annotations arrays were not installed into the Annotations object,
    1.95 +    // then they have to be deallocated explicitly.
    1.96 +    MetadataFactory::free_array<u1>(_loader_data, _annotations);
    1.97 +    MetadataFactory::free_array<u1>(_loader_data, _type_annotations);
    1.98 +    Annotations::free_contents(_loader_data, _fields_annotations);
    1.99 +    Annotations::free_contents(_loader_data, _fields_type_annotations);
   1.100 +  }
   1.101  
   1.102    clear_class_metadata();
   1.103  
     2.1 --- a/src/share/vm/classfile/classFileParser.hpp	Tue Dec 09 12:25:38 2014 -0800
     2.2 +++ b/src/share/vm/classfile/classFileParser.hpp	Thu Dec 11 10:38:17 2014 +0000
     2.3 @@ -75,6 +75,7 @@
     2.4    Array<u2>*       _inner_classes;
     2.5    Array<Klass*>*   _local_interfaces;
     2.6    Array<Klass*>*   _transitive_interfaces;
     2.7 +  Annotations*     _combined_annotations;
     2.8    AnnotationArray* _annotations;
     2.9    AnnotationArray* _type_annotations;
    2.10    Array<AnnotationArray*>* _fields_annotations;
    2.11 @@ -86,6 +87,8 @@
    2.12    void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
    2.13    void set_class_sde_buffer(char* x, int len)  { _sde_buffer = x; _sde_length = len; }
    2.14  
    2.15 +  void create_combined_annotations(TRAPS);
    2.16 +
    2.17    void init_parsed_class_attributes(ClassLoaderData* loader_data) {
    2.18      _loader_data = loader_data;
    2.19      _synthetic_flag = false;
    2.20 @@ -110,6 +113,7 @@
    2.21      _inner_classes = NULL;
    2.22      _local_interfaces = NULL;
    2.23      _transitive_interfaces = NULL;
    2.24 +    _combined_annotations = NULL;
    2.25      _annotations = _type_annotations = NULL;
    2.26      _fields_annotations = _fields_type_annotations = NULL;
    2.27    }

mercurial