src/share/vm/classfile/classFileParser.cpp

changeset 1373
b37c246bf7ce
parent 1314
494244ae0171
child 1374
9eebd3ac74cf
     1.1 --- a/src/share/vm/classfile/classFileParser.cpp	Mon Aug 24 13:52:42 2009 -0700
     1.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Tue Aug 11 15:37:23 2009 -0700
     1.3 @@ -2924,12 +2924,12 @@
     1.4  
     1.5      // Prepare list of oops for oop maps generation.
     1.6      u2* nonstatic_oop_offsets;
     1.7 -    u2* nonstatic_oop_length;
     1.8 +    u2* nonstatic_oop_counts;
     1.9      int nonstatic_oop_map_count = 0;
    1.10  
    1.11      nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD(
    1.12                THREAD, u2,  nonstatic_oop_count+1);
    1.13 -    nonstatic_oop_length  = NEW_RESOURCE_ARRAY_IN_THREAD(
    1.14 +    nonstatic_oop_counts  = NEW_RESOURCE_ARRAY_IN_THREAD(
    1.15                THREAD, u2,  nonstatic_oop_count+1);
    1.16  
    1.17      // Add fake fields for java.lang.Class instances (also see above).
    1.18 @@ -2939,7 +2939,7 @@
    1.19        nonstatic_oop_offsets[0] = (u2)first_nonstatic_field_offset;
    1.20        int fake_oop_count       = (( next_nonstatic_field_offset -
    1.21                                      first_nonstatic_field_offset ) / heapOopSize);
    1.22 -      nonstatic_oop_length [0] = (u2)fake_oop_count;
    1.23 +      nonstatic_oop_counts [0] = (u2)fake_oop_count;
    1.24        nonstatic_oop_map_count  = 1;
    1.25        nonstatic_oop_count     -= fake_oop_count;
    1.26        first_nonstatic_oop_offset = first_nonstatic_field_offset;
    1.27 @@ -3119,13 +3119,13 @@
    1.28            // Update oop maps
    1.29            if( nonstatic_oop_map_count > 0 &&
    1.30                nonstatic_oop_offsets[nonstatic_oop_map_count - 1] ==
    1.31 -              (u2)(real_offset - nonstatic_oop_length[nonstatic_oop_map_count - 1] * heapOopSize) ) {
    1.32 +              (u2)(real_offset - nonstatic_oop_counts[nonstatic_oop_map_count - 1] * heapOopSize) ) {
    1.33              // Extend current oop map
    1.34 -            nonstatic_oop_length[nonstatic_oop_map_count - 1] += 1;
    1.35 +            nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1;
    1.36            } else {
    1.37              // Create new oop map
    1.38              nonstatic_oop_offsets[nonstatic_oop_map_count] = (u2)real_offset;
    1.39 -            nonstatic_oop_length [nonstatic_oop_map_count] = 1;
    1.40 +            nonstatic_oop_counts [nonstatic_oop_map_count] = 1;
    1.41              nonstatic_oop_map_count += 1;
    1.42              if( first_nonstatic_oop_offset == 0 ) { // Undefined
    1.43                first_nonstatic_oop_offset = real_offset;
    1.44 @@ -3182,8 +3182,10 @@
    1.45  
    1.46      assert(instance_size == align_object_size(align_size_up((instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), wordSize) / wordSize), "consistent layout helper value");
    1.47  
    1.48 -    // Size of non-static oop map blocks (in words) allocated at end of klass
    1.49 -    int nonstatic_oop_map_size = compute_oop_map_size(super_klass, nonstatic_oop_map_count, first_nonstatic_oop_offset);
    1.50 +    // Number of non-static oop map blocks allocated at end of klass.
    1.51 +    int total_oop_map_count = compute_oop_map_count(super_klass,
    1.52 +                                                    nonstatic_oop_map_count,
    1.53 +                                                    first_nonstatic_oop_offset);
    1.54  
    1.55      // Compute reference type
    1.56      ReferenceType rt;
    1.57 @@ -3196,12 +3198,13 @@
    1.58      // We can now create the basic klassOop for this klass
    1.59      klassOop ik = oopFactory::new_instanceKlass(
    1.60                                      vtable_size, itable_size,
    1.61 -                                    static_field_size, nonstatic_oop_map_size,
    1.62 +                                    static_field_size, total_oop_map_count,
    1.63                                      rt, CHECK_(nullHandle));
    1.64      instanceKlassHandle this_klass (THREAD, ik);
    1.65  
    1.66 -    assert(this_klass->static_field_size() == static_field_size &&
    1.67 -           this_klass->nonstatic_oop_map_size() == nonstatic_oop_map_size, "sanity check");
    1.68 +    assert(this_klass->static_field_size() == static_field_size, "sanity");
    1.69 +    assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count,
    1.70 +           "sanity");
    1.71  
    1.72      // Fill in information already parsed
    1.73      this_klass->set_access_flags(access_flags);
    1.74 @@ -3282,7 +3285,7 @@
    1.75      klassItable::setup_itable_offset_table(this_klass);
    1.76  
    1.77      // Do final class setup
    1.78 -    fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_length);
    1.79 +    fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
    1.80  
    1.81      set_precomputed_flags(this_klass);
    1.82  
    1.83 @@ -3375,66 +3378,71 @@
    1.84  }
    1.85  
    1.86  
    1.87 -int ClassFileParser::compute_oop_map_size(instanceKlassHandle super, int nonstatic_oop_map_count, int first_nonstatic_oop_offset) {
    1.88 -  int map_size = super.is_null() ? 0 : super->nonstatic_oop_map_size();
    1.89 +int ClassFileParser::compute_oop_map_count(instanceKlassHandle super,
    1.90 +                                           int nonstatic_oop_map_count,
    1.91 +                                           int first_nonstatic_oop_offset) {
    1.92 +  int map_count = super.is_null() ? 0 : super->nonstatic_oop_map_count();
    1.93    if (nonstatic_oop_map_count > 0) {
    1.94      // We have oops to add to map
    1.95 -    if (map_size == 0) {
    1.96 -      map_size = nonstatic_oop_map_count;
    1.97 +    if (map_count == 0) {
    1.98 +      map_count = nonstatic_oop_map_count;
    1.99      } else {
   1.100 -      // Check whether we should add a new map block or whether the last one can be extended
   1.101 -      OopMapBlock* first_map = super->start_of_nonstatic_oop_maps();
   1.102 -      OopMapBlock* last_map = first_map + map_size - 1;
   1.103 -
   1.104 -      int next_offset = last_map->offset() + (last_map->length() * heapOopSize);
   1.105 +      // Check whether we should add a new map block or whether the last one can
   1.106 +      // be extended
   1.107 +      OopMapBlock* const first_map = super->start_of_nonstatic_oop_maps();
   1.108 +      OopMapBlock* const last_map = first_map + map_count - 1;
   1.109 +
   1.110 +      int next_offset = last_map->offset() + last_map->count() * heapOopSize;
   1.111        if (next_offset == first_nonstatic_oop_offset) {
   1.112          // There is no gap bettwen superklass's last oop field and first
   1.113          // local oop field, merge maps.
   1.114          nonstatic_oop_map_count -= 1;
   1.115        } else {
   1.116          // Superklass didn't end with a oop field, add extra maps
   1.117 -        assert(next_offset<first_nonstatic_oop_offset, "just checking");
   1.118 +        assert(next_offset < first_nonstatic_oop_offset, "just checking");
   1.119        }
   1.120 -      map_size += nonstatic_oop_map_count;
   1.121 +      map_count += nonstatic_oop_map_count;
   1.122      }
   1.123    }
   1.124 -  return map_size;
   1.125 +  return map_count;
   1.126  }
   1.127  
   1.128  
   1.129  void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
   1.130 -                        int nonstatic_oop_map_count,
   1.131 -                        u2* nonstatic_oop_offsets, u2* nonstatic_oop_length) {
   1.132 +                                    int nonstatic_oop_map_count,
   1.133 +                                    u2* nonstatic_oop_offsets,
   1.134 +                                    u2* nonstatic_oop_counts) {
   1.135    OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps();
   1.136 -  OopMapBlock* last_oop_map = this_oop_map + k->nonstatic_oop_map_size();
   1.137 -  instanceKlass* super = k->superklass();
   1.138 -  if (super != NULL) {
   1.139 -    int super_oop_map_size     = super->nonstatic_oop_map_size();
   1.140 +  const instanceKlass* const super = k->superklass();
   1.141 +  const int super_count = super != NULL ? super->nonstatic_oop_map_count() : 0;
   1.142 +  if (super_count > 0) {
   1.143 +    // Copy maps from superklass
   1.144      OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps();
   1.145 -    // Copy maps from superklass
   1.146 -    while (super_oop_map_size-- > 0) {
   1.147 +    for (int i = 0; i < super_count; ++i) {
   1.148        *this_oop_map++ = *super_oop_map++;
   1.149      }
   1.150    }
   1.151 +
   1.152    if (nonstatic_oop_map_count > 0) {
   1.153 -    if (this_oop_map + nonstatic_oop_map_count > last_oop_map) {
   1.154 -      // Calculated in compute_oop_map_size() number of oop maps is less then
   1.155 -      // collected oop maps since there is no gap between superklass's last oop
   1.156 -      // field and first local oop field. Extend the last oop map copied
   1.157 +    if (super_count + nonstatic_oop_map_count > k->nonstatic_oop_map_count()) {
   1.158 +      // The counts differ because there is no gap between superklass's last oop
   1.159 +      // field and the first local oop field.  Extend the last oop map copied
   1.160        // from the superklass instead of creating new one.
   1.161        nonstatic_oop_map_count--;
   1.162        nonstatic_oop_offsets++;
   1.163        this_oop_map--;
   1.164 -      this_oop_map->set_length(this_oop_map->length() + *nonstatic_oop_length++);
   1.165 +      this_oop_map->set_count(this_oop_map->count() + *nonstatic_oop_counts++);
   1.166        this_oop_map++;
   1.167      }
   1.168 -    assert((this_oop_map + nonstatic_oop_map_count) == last_oop_map, "just checking");
   1.169 +
   1.170      // Add new map blocks, fill them
   1.171      while (nonstatic_oop_map_count-- > 0) {
   1.172        this_oop_map->set_offset(*nonstatic_oop_offsets++);
   1.173 -      this_oop_map->set_length(*nonstatic_oop_length++);
   1.174 +      this_oop_map->set_count(*nonstatic_oop_counts++);
   1.175        this_oop_map++;
   1.176      }
   1.177 +    assert(k->start_of_nonstatic_oop_maps() + k->nonstatic_oop_map_count() ==
   1.178 +           this_oop_map, "sanity");
   1.179    }
   1.180  }
   1.181  

mercurial