src/share/vm/classfile/classFileParser.cpp

changeset 3137
e6b1331a51d2
parent 2983
498c6cf70f7e
child 3360
4ceaf61479fc
child 3373
cd5d8cafcc84
     1.1 --- a/src/share/vm/classfile/classFileParser.cpp	Sat Sep 10 00:11:04 2011 -0700
     1.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Sat Sep 10 17:29:02 2011 -0700
     1.3 @@ -36,6 +36,7 @@
     1.4  #include "memory/oopFactory.hpp"
     1.5  #include "memory/universe.inline.hpp"
     1.6  #include "oops/constantPoolOop.hpp"
     1.7 +#include "oops/fieldStreams.hpp"
     1.8  #include "oops/instanceKlass.hpp"
     1.9  #include "oops/instanceMirrorKlass.hpp"
    1.10  #include "oops/klass.inline.hpp"
    1.11 @@ -991,42 +992,98 @@
    1.12    STATIC_BYTE,          // Boolean, Byte, char
    1.13    STATIC_SHORT,         // shorts
    1.14    STATIC_WORD,          // ints
    1.15 -  STATIC_DOUBLE,        // long or double
    1.16 -  STATIC_ALIGNED_DOUBLE,// aligned long or double
    1.17 +  STATIC_DOUBLE,        // aligned long or double
    1.18    NONSTATIC_OOP,
    1.19    NONSTATIC_BYTE,
    1.20    NONSTATIC_SHORT,
    1.21    NONSTATIC_WORD,
    1.22    NONSTATIC_DOUBLE,
    1.23 -  NONSTATIC_ALIGNED_DOUBLE
    1.24 +  MAX_FIELD_ALLOCATION_TYPE,
    1.25 +  BAD_ALLOCATION_TYPE = -1
    1.26  };
    1.27  
    1.28 -
    1.29 -struct FieldAllocationCount {
    1.30 -  unsigned int static_oop_count;
    1.31 -  unsigned int static_byte_count;
    1.32 -  unsigned int static_short_count;
    1.33 -  unsigned int static_word_count;
    1.34 -  unsigned int static_double_count;
    1.35 -  unsigned int nonstatic_oop_count;
    1.36 -  unsigned int nonstatic_byte_count;
    1.37 -  unsigned int nonstatic_short_count;
    1.38 -  unsigned int nonstatic_word_count;
    1.39 -  unsigned int nonstatic_double_count;
    1.40 +static FieldAllocationType _basic_type_to_atype[2 * (T_CONFLICT + 1)] = {
    1.41 +  BAD_ALLOCATION_TYPE, // 0
    1.42 +  BAD_ALLOCATION_TYPE, // 1
    1.43 +  BAD_ALLOCATION_TYPE, // 2
    1.44 +  BAD_ALLOCATION_TYPE, // 3
    1.45 +  NONSTATIC_BYTE ,     // T_BOOLEAN  =  4,
    1.46 +  NONSTATIC_SHORT,     // T_CHAR     =  5,
    1.47 +  NONSTATIC_WORD,      // T_FLOAT    =  6,
    1.48 +  NONSTATIC_DOUBLE,    // T_DOUBLE   =  7,
    1.49 +  NONSTATIC_BYTE,      // T_BYTE     =  8,
    1.50 +  NONSTATIC_SHORT,     // T_SHORT    =  9,
    1.51 +  NONSTATIC_WORD,      // T_INT      = 10,
    1.52 +  NONSTATIC_DOUBLE,    // T_LONG     = 11,
    1.53 +  NONSTATIC_OOP,       // T_OBJECT   = 12,
    1.54 +  NONSTATIC_OOP,       // T_ARRAY    = 13,
    1.55 +  BAD_ALLOCATION_TYPE, // T_VOID     = 14,
    1.56 +  BAD_ALLOCATION_TYPE, // T_ADDRESS  = 15,
    1.57 +  BAD_ALLOCATION_TYPE, // T_NARROWOOP= 16,
    1.58 +  BAD_ALLOCATION_TYPE, // T_CONFLICT = 17,
    1.59 +  BAD_ALLOCATION_TYPE, // 0
    1.60 +  BAD_ALLOCATION_TYPE, // 1
    1.61 +  BAD_ALLOCATION_TYPE, // 2
    1.62 +  BAD_ALLOCATION_TYPE, // 3
    1.63 +  STATIC_BYTE ,        // T_BOOLEAN  =  4,
    1.64 +  STATIC_SHORT,        // T_CHAR     =  5,
    1.65 +  STATIC_WORD,          // T_FLOAT    =  6,
    1.66 +  STATIC_DOUBLE,       // T_DOUBLE   =  7,
    1.67 +  STATIC_BYTE,         // T_BYTE     =  8,
    1.68 +  STATIC_SHORT,        // T_SHORT    =  9,
    1.69 +  STATIC_WORD,         // T_INT      = 10,
    1.70 +  STATIC_DOUBLE,       // T_LONG     = 11,
    1.71 +  STATIC_OOP,          // T_OBJECT   = 12,
    1.72 +  STATIC_OOP,          // T_ARRAY    = 13,
    1.73 +  BAD_ALLOCATION_TYPE, // T_VOID     = 14,
    1.74 +  BAD_ALLOCATION_TYPE, // T_ADDRESS  = 15,
    1.75 +  BAD_ALLOCATION_TYPE, // T_NARROWOOP= 16,
    1.76 +  BAD_ALLOCATION_TYPE, // T_CONFLICT = 17,
    1.77  };
    1.78  
    1.79 -typeArrayHandle ClassFileParser::parse_fields(constantPoolHandle cp, bool is_interface,
    1.80 -                                              struct FieldAllocationCount *fac,
    1.81 -                                              objArrayHandle* fields_annotations, TRAPS) {
    1.82 +static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) {
    1.83 +  assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values");
    1.84 +  FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)];
    1.85 +  assert(result != BAD_ALLOCATION_TYPE, "bad type");
    1.86 +  return result;
    1.87 +}
    1.88 +
    1.89 +class FieldAllocationCount: public ResourceObj {
    1.90 + public:
    1.91 +  unsigned int count[MAX_FIELD_ALLOCATION_TYPE];
    1.92 +
    1.93 +  FieldAllocationCount() {
    1.94 +    for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
    1.95 +      count[i] = 0;
    1.96 +    }
    1.97 +  }
    1.98 +
    1.99 +  FieldAllocationType update(bool is_static, BasicType type) {
   1.100 +    FieldAllocationType atype = basic_type_to_atype(is_static, type);
   1.101 +    count[atype]++;
   1.102 +    return atype;
   1.103 +  }
   1.104 +};
   1.105 +
   1.106 +
   1.107 +typeArrayHandle ClassFileParser::parse_fields(Symbol* class_name,
   1.108 +                                              constantPoolHandle cp, bool is_interface,
   1.109 +                                              FieldAllocationCount *fac,
   1.110 +                                              objArrayHandle* fields_annotations,
   1.111 +                                              int* java_fields_count_ptr, TRAPS) {
   1.112    ClassFileStream* cfs = stream();
   1.113    typeArrayHandle nullHandle;
   1.114    cfs->guarantee_more(2, CHECK_(nullHandle));  // length
   1.115    u2 length = cfs->get_u2_fast();
   1.116 +  *java_fields_count_ptr = length;
   1.117 +
   1.118 +  int num_injected = 0;
   1.119 +  InjectedField* injected = JavaClasses::get_injected(class_name, &num_injected);
   1.120 +
   1.121    // Tuples of shorts [access, name index, sig index, initial value index, byte offset, generic signature index]
   1.122 -  typeArrayOop new_fields = oopFactory::new_permanent_shortArray(length*instanceKlass::next_offset, CHECK_(nullHandle));
   1.123 +  typeArrayOop new_fields = oopFactory::new_permanent_shortArray((length + num_injected) * FieldInfo::field_slots, CHECK_(nullHandle));
   1.124    typeArrayHandle fields(THREAD, new_fields);
   1.125  
   1.126 -  int index = 0;
   1.127    typeArrayHandle field_annotations;
   1.128    for (int n = 0; n < length; n++) {
   1.129      cfs->guarantee_more(8, CHECK_(nullHandle));  // access_flags, name_index, descriptor_index, attributes_count
   1.130 @@ -1077,93 +1134,77 @@
   1.131        }
   1.132      }
   1.133  
   1.134 -    fields->short_at_put(index++, access_flags.as_short());
   1.135 -    fields->short_at_put(index++, name_index);
   1.136 -    fields->short_at_put(index++, signature_index);
   1.137 -    fields->short_at_put(index++, constantvalue_index);
   1.138 +    FieldInfo* field = FieldInfo::from_field_array(fields(), n);
   1.139 +    field->initialize(access_flags.as_short(),
   1.140 +                      name_index,
   1.141 +                      signature_index,
   1.142 +                      constantvalue_index,
   1.143 +                      generic_signature_index,
   1.144 +                      0);
   1.145 +
   1.146 +    BasicType type = cp->basic_type_for_signature_at(signature_index);
   1.147  
   1.148      // Remember how many oops we encountered and compute allocation type
   1.149 -    BasicType type = cp->basic_type_for_signature_at(signature_index);
   1.150 -    FieldAllocationType atype;
   1.151 -    if ( is_static ) {
   1.152 -      switch ( type ) {
   1.153 -        case  T_BOOLEAN:
   1.154 -        case  T_BYTE:
   1.155 -          fac->static_byte_count++;
   1.156 -          atype = STATIC_BYTE;
   1.157 -          break;
   1.158 -        case  T_LONG:
   1.159 -        case  T_DOUBLE:
   1.160 -          if (Universe::field_type_should_be_aligned(type)) {
   1.161 -            atype = STATIC_ALIGNED_DOUBLE;
   1.162 -          } else {
   1.163 -            atype = STATIC_DOUBLE;
   1.164 -          }
   1.165 -          fac->static_double_count++;
   1.166 -          break;
   1.167 -        case  T_CHAR:
   1.168 -        case  T_SHORT:
   1.169 -          fac->static_short_count++;
   1.170 -          atype = STATIC_SHORT;
   1.171 -          break;
   1.172 -        case  T_FLOAT:
   1.173 -        case  T_INT:
   1.174 -          fac->static_word_count++;
   1.175 -          atype = STATIC_WORD;
   1.176 -          break;
   1.177 -        case  T_ARRAY:
   1.178 -        case  T_OBJECT:
   1.179 -          fac->static_oop_count++;
   1.180 -          atype = STATIC_OOP;
   1.181 -          break;
   1.182 -        case  T_ADDRESS:
   1.183 -        case  T_VOID:
   1.184 -        default:
   1.185 -          assert(0, "bad field type");
   1.186 -      }
   1.187 -    } else {
   1.188 -      switch ( type ) {
   1.189 -        case  T_BOOLEAN:
   1.190 -        case  T_BYTE:
   1.191 -          fac->nonstatic_byte_count++;
   1.192 -          atype = NONSTATIC_BYTE;
   1.193 -          break;
   1.194 -        case  T_LONG:
   1.195 -        case  T_DOUBLE:
   1.196 -          if (Universe::field_type_should_be_aligned(type)) {
   1.197 -            atype = NONSTATIC_ALIGNED_DOUBLE;
   1.198 -          } else {
   1.199 -            atype = NONSTATIC_DOUBLE;
   1.200 -          }
   1.201 -          fac->nonstatic_double_count++;
   1.202 -          break;
   1.203 -        case  T_CHAR:
   1.204 -        case  T_SHORT:
   1.205 -          fac->nonstatic_short_count++;
   1.206 -          atype = NONSTATIC_SHORT;
   1.207 -          break;
   1.208 -        case  T_FLOAT:
   1.209 -        case  T_INT:
   1.210 -          fac->nonstatic_word_count++;
   1.211 -          atype = NONSTATIC_WORD;
   1.212 -          break;
   1.213 -        case  T_ARRAY:
   1.214 -        case  T_OBJECT:
   1.215 -          fac->nonstatic_oop_count++;
   1.216 -          atype = NONSTATIC_OOP;
   1.217 -          break;
   1.218 -        case  T_ADDRESS:
   1.219 -        case  T_VOID:
   1.220 -        default:
   1.221 -          assert(0, "bad field type");
   1.222 -      }
   1.223 -    }
   1.224 +    FieldAllocationType atype = fac->update(is_static, type);
   1.225  
   1.226      // The correct offset is computed later (all oop fields will be located together)
   1.227      // We temporarily store the allocation type in the offset field
   1.228 -    fields->short_at_put(index++, atype);
   1.229 -    fields->short_at_put(index++, 0);  // Clear out high word of byte offset
   1.230 -    fields->short_at_put(index++, generic_signature_index);
   1.231 +    field->set_offset(atype);
   1.232 +  }
   1.233 +
   1.234 +  if (num_injected != 0) {
   1.235 +    int index = length;
   1.236 +    for (int n = 0; n < num_injected; n++) {
   1.237 +      // Check for duplicates
   1.238 +      if (injected[n].may_be_java) {
   1.239 +        Symbol* name      = injected[n].name();
   1.240 +        Symbol* signature = injected[n].signature();
   1.241 +        bool duplicate = false;
   1.242 +        for (int i = 0; i < length; i++) {
   1.243 +          FieldInfo* f = FieldInfo::from_field_array(fields(), i);
   1.244 +          if (name      == cp->symbol_at(f->name_index()) &&
   1.245 +              signature == cp->symbol_at(f->signature_index())) {
   1.246 +            // Symbol is desclared in Java so skip this one
   1.247 +            duplicate = true;
   1.248 +            break;
   1.249 +          }
   1.250 +        }
   1.251 +        if (duplicate) {
   1.252 +          // These will be removed from the field array at the end
   1.253 +          continue;
   1.254 +        }
   1.255 +      }
   1.256 +
   1.257 +      // Injected field
   1.258 +      FieldInfo* field = FieldInfo::from_field_array(fields(), index);
   1.259 +      field->initialize(JVM_ACC_FIELD_INTERNAL,
   1.260 +                        injected[n].name_index,
   1.261 +                        injected[n].signature_index,
   1.262 +                        0,
   1.263 +                        0,
   1.264 +                        0);
   1.265 +
   1.266 +      BasicType type = FieldType::basic_type(injected[n].signature());
   1.267 +
   1.268 +      // Remember how many oops we encountered and compute allocation type
   1.269 +      FieldAllocationType atype = fac->update(false, type);
   1.270 +
   1.271 +      // The correct offset is computed later (all oop fields will be located together)
   1.272 +      // We temporarily store the allocation type in the offset field
   1.273 +      field->set_offset(atype);
   1.274 +      index++;
   1.275 +    }
   1.276 +
   1.277 +    if (index < length + num_injected) {
   1.278 +      // sometimes injected fields already exist in the Java source so
   1.279 +      // the fields array could be too long.  In that case trim the
   1.280 +      // fields array.
   1.281 +      new_fields = oopFactory::new_permanent_shortArray(index * FieldInfo::field_slots, CHECK_(nullHandle));
   1.282 +      for (int i = 0; i < index * FieldInfo::field_slots; i++) {
   1.283 +        new_fields->short_at_put(i, fields->short_at(i));
   1.284 +      }
   1.285 +      fields = new_fields;
   1.286 +    }
   1.287    }
   1.288  
   1.289    if (_need_verify && length > 1) {
   1.290 @@ -1175,11 +1216,9 @@
   1.291      bool dup = false;
   1.292      {
   1.293        debug_only(No_Safepoint_Verifier nsv;)
   1.294 -      for (int i = 0; i < length*instanceKlass::next_offset; i += instanceKlass::next_offset) {
   1.295 -        int name_index = fields->ushort_at(i + instanceKlass::name_index_offset);
   1.296 -        Symbol* name = cp->symbol_at(name_index);
   1.297 -        int sig_index = fields->ushort_at(i + instanceKlass::signature_index_offset);
   1.298 -        Symbol* sig = cp->symbol_at(sig_index);
   1.299 +      for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) {
   1.300 +        Symbol* name = fs.name();
   1.301 +        Symbol* sig = fs.signature();
   1.302          // If no duplicates, add name/signature in hashtable names_and_sigs.
   1.303          if (!put_after_lookup(name, sig, names_and_sigs)) {
   1.304            dup = true;
   1.305 @@ -2592,227 +2631,6 @@
   1.306  }
   1.307  
   1.308  
   1.309 -void ClassFileParser::java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
   1.310 -  constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS) {
   1.311 -  // This code is for compatibility with earlier jdk's that do not
   1.312 -  // have the "discovered" field in java.lang.ref.Reference.  For 1.5
   1.313 -  // the check for the "discovered" field should issue a warning if
   1.314 -  // the field is not found.  For 1.6 this code should be issue a
   1.315 -  // fatal error if the "discovered" field is not found.
   1.316 -  //
   1.317 -  // Increment fac.nonstatic_oop_count so that the start of the
   1.318 -  // next type of non-static oops leaves room for the fake oop.
   1.319 -  // Do not increment next_nonstatic_oop_offset so that the
   1.320 -  // fake oop is place after the java.lang.ref.Reference oop
   1.321 -  // fields.
   1.322 -  //
   1.323 -  // Check the fields in java.lang.ref.Reference for the "discovered"
   1.324 -  // field.  If it is not present, artifically create a field for it.
   1.325 -  // This allows this VM to run on early JDK where the field is not
   1.326 -  // present.
   1.327 -  int reference_sig_index = 0;
   1.328 -  int reference_name_index = 0;
   1.329 -  int reference_index = 0;
   1.330 -  int extra = java_lang_ref_Reference::number_of_fake_oop_fields;
   1.331 -  const int n = (*fields_ptr)()->length();
   1.332 -  for (int i = 0; i < n; i += instanceKlass::next_offset ) {
   1.333 -    int name_index =
   1.334 -    (*fields_ptr)()->ushort_at(i + instanceKlass::name_index_offset);
   1.335 -    int sig_index  =
   1.336 -      (*fields_ptr)()->ushort_at(i + instanceKlass::signature_index_offset);
   1.337 -    Symbol* f_name = cp->symbol_at(name_index);
   1.338 -    Symbol* f_sig  = cp->symbol_at(sig_index);
   1.339 -    if (f_sig == vmSymbols::reference_signature() && reference_index == 0) {
   1.340 -      // Save the index for reference signature for later use.
   1.341 -      // The fake discovered field does not entries in the
   1.342 -      // constant pool so the index for its signature cannot
   1.343 -      // be extracted from the constant pool.  It will need
   1.344 -      // later, however.  It's signature is vmSymbols::reference_signature()
   1.345 -      // so same an index for that signature.
   1.346 -      reference_sig_index = sig_index;
   1.347 -      reference_name_index = name_index;
   1.348 -      reference_index = i;
   1.349 -    }
   1.350 -    if (f_name == vmSymbols::reference_discovered_name() &&
   1.351 -      f_sig == vmSymbols::reference_signature()) {
   1.352 -      // The values below are fake but will force extra
   1.353 -      // non-static oop fields and a corresponding non-static
   1.354 -      // oop map block to be allocated.
   1.355 -      extra = 0;
   1.356 -      break;
   1.357 -    }
   1.358 -  }
   1.359 -  if (extra != 0) {
   1.360 -    fac_ptr->nonstatic_oop_count += extra;
   1.361 -    // Add the additional entry to "fields" so that the klass
   1.362 -    // contains the "discoverd" field and the field will be initialized
   1.363 -    // in instances of the object.
   1.364 -    int fields_with_fix_length = (*fields_ptr)()->length() +
   1.365 -      instanceKlass::next_offset;
   1.366 -    typeArrayOop ff = oopFactory::new_permanent_shortArray(
   1.367 -                                                fields_with_fix_length, CHECK);
   1.368 -    typeArrayHandle fields_with_fix(THREAD, ff);
   1.369 -
   1.370 -    // Take everything from the original but the length.
   1.371 -    for (int idx = 0; idx < (*fields_ptr)->length(); idx++) {
   1.372 -      fields_with_fix->ushort_at_put(idx, (*fields_ptr)->ushort_at(idx));
   1.373 -    }
   1.374 -
   1.375 -    // Add the fake field at the end.
   1.376 -    int i = (*fields_ptr)->length();
   1.377 -    // There is no name index for the fake "discovered" field nor
   1.378 -    // signature but a signature is needed so that the field will
   1.379 -    // be properly initialized.  Use one found for
   1.380 -    // one of the other reference fields. Be sure the index for the
   1.381 -    // name is 0.  In fieldDescriptor::initialize() the index of the
   1.382 -    // name is checked.  That check is by passed for the last nonstatic
   1.383 -    // oop field in a java.lang.ref.Reference which is assumed to be
   1.384 -    // this artificial "discovered" field.  An assertion checks that
   1.385 -    // the name index is 0.
   1.386 -    assert(reference_index != 0, "Missing signature for reference");
   1.387 -
   1.388 -    int j;
   1.389 -    for (j = 0; j < instanceKlass::next_offset; j++) {
   1.390 -      fields_with_fix->ushort_at_put(i + j,
   1.391 -        (*fields_ptr)->ushort_at(reference_index +j));
   1.392 -    }
   1.393 -    // Clear the public access flag and set the private access flag.
   1.394 -    short flags;
   1.395 -    flags =
   1.396 -      fields_with_fix->ushort_at(i + instanceKlass::access_flags_offset);
   1.397 -    assert(!(flags & JVM_RECOGNIZED_FIELD_MODIFIERS), "Unexpected access flags set");
   1.398 -    flags = flags & (~JVM_ACC_PUBLIC);
   1.399 -    flags = flags | JVM_ACC_PRIVATE;
   1.400 -    AccessFlags access_flags;
   1.401 -    access_flags.set_flags(flags);
   1.402 -    assert(!access_flags.is_public(), "Failed to clear public flag");
   1.403 -    assert(access_flags.is_private(), "Failed to set private flag");
   1.404 -    fields_with_fix->ushort_at_put(i + instanceKlass::access_flags_offset,
   1.405 -      flags);
   1.406 -
   1.407 -    assert(fields_with_fix->ushort_at(i + instanceKlass::name_index_offset)
   1.408 -      == reference_name_index, "The fake reference name is incorrect");
   1.409 -    assert(fields_with_fix->ushort_at(i + instanceKlass::signature_index_offset)
   1.410 -      == reference_sig_index, "The fake reference signature is incorrect");
   1.411 -    // The type of the field is stored in the low_offset entry during
   1.412 -    // parsing.
   1.413 -    assert(fields_with_fix->ushort_at(i + instanceKlass::low_offset) ==
   1.414 -      NONSTATIC_OOP, "The fake reference type is incorrect");
   1.415 -
   1.416 -    // "fields" is allocated in the permanent generation.  Disgard
   1.417 -    // it and let it be collected.
   1.418 -    (*fields_ptr) = fields_with_fix;
   1.419 -  }
   1.420 -  return;
   1.421 -}
   1.422 -
   1.423 -
   1.424 -void ClassFileParser::java_lang_Class_fix_pre(int* nonstatic_field_size,
   1.425 -                                              FieldAllocationCount *fac_ptr) {
   1.426 -  // Add fake fields for java.lang.Class instances
   1.427 -  //
   1.428 -  // This is not particularly nice. We should consider adding a
   1.429 -  // private transient object field at the Java level to
   1.430 -  // java.lang.Class. Alternatively we could add a subclass of
   1.431 -  // instanceKlass which provides an accessor and size computer for
   1.432 -  // this field, but that appears to be more code than this hack.
   1.433 -  //
   1.434 -  // NOTE that we wedge these in at the beginning rather than the
   1.435 -  // end of the object because the Class layout changed between JDK
   1.436 -  // 1.3 and JDK 1.4 with the new reflection implementation; some
   1.437 -  // nonstatic oop fields were added at the Java level. The offsets
   1.438 -  // of these fake fields can't change between these two JDK
   1.439 -  // versions because when the offsets are computed at bootstrap
   1.440 -  // time we don't know yet which version of the JDK we're running in.
   1.441 -
   1.442 -  // The values below are fake but will force three non-static oop fields and
   1.443 -  // a corresponding non-static oop map block to be allocated.
   1.444 -  const int extra = java_lang_Class::number_of_fake_oop_fields;
   1.445 -  fac_ptr->nonstatic_oop_count += extra;
   1.446 -
   1.447 -  // Reserve some leading space for fake ints
   1.448 -  *nonstatic_field_size += align_size_up(java_lang_Class::hc_number_of_fake_int_fields * BytesPerInt, heapOopSize) / heapOopSize;
   1.449 -}
   1.450 -
   1.451 -
   1.452 -void ClassFileParser::java_lang_Class_fix_post(int* next_nonstatic_oop_offset_ptr) {
   1.453 -  // Cause the extra fake fields in java.lang.Class to show up before
   1.454 -  // the Java fields for layout compatibility between 1.3 and 1.4
   1.455 -  // Incrementing next_nonstatic_oop_offset here advances the
   1.456 -  // location where the real java fields are placed.
   1.457 -  const int extra = java_lang_Class::number_of_fake_oop_fields;
   1.458 -  (*next_nonstatic_oop_offset_ptr) += (extra * heapOopSize);
   1.459 -}
   1.460 -
   1.461 -
   1.462 -// Force MethodHandle.vmentry to be an unmanaged pointer.
   1.463 -// There is no way for a classfile to express this, so we must help it.
   1.464 -void ClassFileParser::java_lang_invoke_MethodHandle_fix_pre(constantPoolHandle cp,
   1.465 -                                                    typeArrayHandle fields,
   1.466 -                                                    FieldAllocationCount *fac_ptr,
   1.467 -                                                    TRAPS) {
   1.468 -  // Add fake fields for java.lang.invoke.MethodHandle instances
   1.469 -  //
   1.470 -  // This is not particularly nice, but since there is no way to express
   1.471 -  // a native wordSize field in Java, we must do it at this level.
   1.472 -
   1.473 -  if (!EnableInvokeDynamic)  return;
   1.474 -
   1.475 -  int word_sig_index = 0;
   1.476 -  const int cp_size = cp->length();
   1.477 -  for (int index = 1; index < cp_size; index++) {
   1.478 -    if (cp->tag_at(index).is_utf8() &&
   1.479 -        cp->symbol_at(index) == vmSymbols::machine_word_signature()) {
   1.480 -      word_sig_index = index;
   1.481 -      break;
   1.482 -    }
   1.483 -  }
   1.484 -
   1.485 -  if (word_sig_index == 0)
   1.486 -    THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
   1.487 -              "missing I or J signature (for vmentry) in java.lang.invoke.MethodHandle");
   1.488 -
   1.489 -  // Find vmentry field and change the signature.
   1.490 -  bool found_vmentry = false;
   1.491 -  for (int i = 0; i < fields->length(); i += instanceKlass::next_offset) {
   1.492 -    int name_index = fields->ushort_at(i + instanceKlass::name_index_offset);
   1.493 -    int sig_index  = fields->ushort_at(i + instanceKlass::signature_index_offset);
   1.494 -    int acc_flags  = fields->ushort_at(i + instanceKlass::access_flags_offset);
   1.495 -    Symbol* f_name = cp->symbol_at(name_index);
   1.496 -    Symbol* f_sig  = cp->symbol_at(sig_index);
   1.497 -    if (f_name == vmSymbols::vmentry_name() && (acc_flags & JVM_ACC_STATIC) == 0) {
   1.498 -      if (f_sig == vmSymbols::machine_word_signature()) {
   1.499 -        // If the signature of vmentry is already changed, we're done.
   1.500 -        found_vmentry = true;
   1.501 -        break;
   1.502 -      }
   1.503 -      else if (f_sig == vmSymbols::byte_signature()) {
   1.504 -        // Adjust the field type from byte to an unmanaged pointer.
   1.505 -        assert(fac_ptr->nonstatic_byte_count > 0, "");
   1.506 -        fac_ptr->nonstatic_byte_count -= 1;
   1.507 -
   1.508 -        fields->ushort_at_put(i + instanceKlass::signature_index_offset, word_sig_index);
   1.509 -        assert(wordSize == longSize || wordSize == jintSize, "ILP32 or LP64");
   1.510 -        if (wordSize == longSize)  fac_ptr->nonstatic_double_count += 1;
   1.511 -        else                       fac_ptr->nonstatic_word_count   += 1;
   1.512 -
   1.513 -        FieldAllocationType atype = (FieldAllocationType) fields->ushort_at(i + instanceKlass::low_offset);
   1.514 -        assert(atype == NONSTATIC_BYTE, "");
   1.515 -        FieldAllocationType new_atype = (wordSize == longSize) ? NONSTATIC_DOUBLE : NONSTATIC_WORD;
   1.516 -        fields->ushort_at_put(i + instanceKlass::low_offset, new_atype);
   1.517 -
   1.518 -        found_vmentry = true;
   1.519 -        break;
   1.520 -      }
   1.521 -    }
   1.522 -  }
   1.523 -
   1.524 -  if (!found_vmentry)
   1.525 -    THROW_MSG(vmSymbols::java_lang_VirtualMachineError(),
   1.526 -              "missing vmentry byte field in java.lang.invoke.MethodHandle");
   1.527 -}
   1.528 -
   1.529 -
   1.530  instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
   1.531                                                      Handle class_loader,
   1.532                                                      Handle protection_domain,
   1.533 @@ -3025,10 +2843,13 @@
   1.534        local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
   1.535      }
   1.536  
   1.537 +    int java_fields_count = 0;
   1.538      // Fields (offsets are filled in later)
   1.539 -    struct FieldAllocationCount fac = {0,0,0,0,0,0,0,0,0,0};
   1.540 +    FieldAllocationCount fac;
   1.541      objArrayHandle fields_annotations;
   1.542 -    typeArrayHandle fields = parse_fields(cp, access_flags.is_interface(), &fac, &fields_annotations, CHECK_(nullHandle));
   1.543 +    typeArrayHandle fields = parse_fields(class_name, cp, access_flags.is_interface(), &fac, &fields_annotations,
   1.544 +                                          &java_fields_count,
   1.545 +                                          CHECK_(nullHandle));
   1.546      // Methods
   1.547      bool has_final_method = false;
   1.548      AccessFlags promoted_flags;
   1.549 @@ -3146,51 +2967,33 @@
   1.550      // Calculate the starting byte offsets
   1.551      next_static_oop_offset      = instanceMirrorKlass::offset_of_static_fields();
   1.552      next_static_double_offset   = next_static_oop_offset +
   1.553 -                                  (fac.static_oop_count * heapOopSize);
   1.554 -    if ( fac.static_double_count &&
   1.555 +                                  (fac.count[STATIC_OOP] * heapOopSize);
   1.556 +    if ( fac.count[STATIC_DOUBLE] &&
   1.557           (Universe::field_type_should_be_aligned(T_DOUBLE) ||
   1.558            Universe::field_type_should_be_aligned(T_LONG)) ) {
   1.559        next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong);
   1.560      }
   1.561  
   1.562      next_static_word_offset     = next_static_double_offset +
   1.563 -                                  (fac.static_double_count * BytesPerLong);
   1.564 +                                  (fac.count[STATIC_DOUBLE] * BytesPerLong);
   1.565      next_static_short_offset    = next_static_word_offset +
   1.566 -                                  (fac.static_word_count * BytesPerInt);
   1.567 +                                  (fac.count[STATIC_WORD] * BytesPerInt);
   1.568      next_static_byte_offset     = next_static_short_offset +
   1.569 -                                  (fac.static_short_count * BytesPerShort);
   1.570 +                                  (fac.count[STATIC_SHORT] * BytesPerShort);
   1.571      next_static_type_offset     = align_size_up((next_static_byte_offset +
   1.572 -                                  fac.static_byte_count ), wordSize );
   1.573 +                                  fac.count[STATIC_BYTE] ), wordSize );
   1.574      static_field_size           = (next_static_type_offset -
   1.575                                    next_static_oop_offset) / wordSize;
   1.576  
   1.577 -    // Add fake fields for java.lang.Class instances (also see below)
   1.578 -    if (class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) {
   1.579 -      java_lang_Class_fix_pre(&nonstatic_field_size, &fac);
   1.580 -    }
   1.581 -
   1.582      first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() +
   1.583                                     nonstatic_field_size * heapOopSize;
   1.584      next_nonstatic_field_offset = first_nonstatic_field_offset;
   1.585  
   1.586 -    // adjust the vmentry field declaration in java.lang.invoke.MethodHandle
   1.587 -    if (EnableInvokeDynamic && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) {
   1.588 -      java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle));
   1.589 -    }
   1.590 -
   1.591 -    // Add a fake "discovered" field if it is not present
   1.592 -    // for compatibility with earlier jdk's.
   1.593 -    if (class_name == vmSymbols::java_lang_ref_Reference()
   1.594 -      && class_loader.is_null()) {
   1.595 -      java_lang_ref_Reference_fix_pre(&fields, cp, &fac, CHECK_(nullHandle));
   1.596 -    }
   1.597 -    // end of "discovered" field compactibility fix
   1.598 -
   1.599 -    unsigned int nonstatic_double_count = fac.nonstatic_double_count;
   1.600 -    unsigned int nonstatic_word_count   = fac.nonstatic_word_count;
   1.601 -    unsigned int nonstatic_short_count  = fac.nonstatic_short_count;
   1.602 -    unsigned int nonstatic_byte_count   = fac.nonstatic_byte_count;
   1.603 -    unsigned int nonstatic_oop_count    = fac.nonstatic_oop_count;
   1.604 +    unsigned int nonstatic_double_count = fac.count[NONSTATIC_DOUBLE];
   1.605 +    unsigned int nonstatic_word_count   = fac.count[NONSTATIC_WORD];
   1.606 +    unsigned int nonstatic_short_count  = fac.count[NONSTATIC_SHORT];
   1.607 +    unsigned int nonstatic_byte_count   = fac.count[NONSTATIC_BYTE];
   1.608 +    unsigned int nonstatic_oop_count    = fac.count[NONSTATIC_OOP];
   1.609  
   1.610      bool super_has_nonstatic_fields =
   1.611              (super_klass() != NULL && super_klass->has_nonstatic_fields());
   1.612 @@ -3210,20 +3013,7 @@
   1.613      nonstatic_oop_counts  = NEW_RESOURCE_ARRAY_IN_THREAD(
   1.614                THREAD, unsigned int, nonstatic_oop_count + 1);
   1.615  
   1.616 -    // Add fake fields for java.lang.Class instances (also see above).
   1.617 -    // FieldsAllocationStyle and CompactFields values will be reset to default.
   1.618 -    if(class_name == vmSymbols::java_lang_Class() && class_loader.is_null()) {
   1.619 -      java_lang_Class_fix_post(&next_nonstatic_field_offset);
   1.620 -      nonstatic_oop_offsets[0] = first_nonstatic_field_offset;
   1.621 -      const uint fake_oop_count = (next_nonstatic_field_offset -
   1.622 -                                   first_nonstatic_field_offset) / heapOopSize;
   1.623 -      nonstatic_oop_counts[0] = fake_oop_count;
   1.624 -      nonstatic_oop_map_count = 1;
   1.625 -      nonstatic_oop_count -= fake_oop_count;
   1.626 -      first_nonstatic_oop_offset = first_nonstatic_field_offset;
   1.627 -    } else {
   1.628 -      first_nonstatic_oop_offset = 0; // will be set for first oop field
   1.629 -    }
   1.630 +    first_nonstatic_oop_offset = 0; // will be set for first oop field
   1.631  
   1.632  #ifndef PRODUCT
   1.633      if( PrintCompactFieldsSavings ) {
   1.634 @@ -3378,10 +3168,9 @@
   1.635      // Iterate over fields again and compute correct offsets.
   1.636      // The field allocation type was temporarily stored in the offset slot.
   1.637      // oop fields are located before non-oop fields (static and non-static).
   1.638 -    int len = fields->length();
   1.639 -    for (int i = 0; i < len; i += instanceKlass::next_offset) {
   1.640 +    for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) {
   1.641        int real_offset;
   1.642 -      FieldAllocationType atype = (FieldAllocationType) fields->ushort_at(i + instanceKlass::low_offset);
   1.643 +      FieldAllocationType atype = (FieldAllocationType) fs.offset();
   1.644        switch (atype) {
   1.645          case STATIC_OOP:
   1.646            real_offset = next_static_oop_offset;
   1.647 @@ -3399,7 +3188,6 @@
   1.648            real_offset = next_static_word_offset;
   1.649            next_static_word_offset += BytesPerInt;
   1.650            break;
   1.651 -        case STATIC_ALIGNED_DOUBLE:
   1.652          case STATIC_DOUBLE:
   1.653            real_offset = next_static_double_offset;
   1.654            next_static_double_offset += BytesPerLong;
   1.655 @@ -3461,7 +3249,6 @@
   1.656              next_nonstatic_word_offset += BytesPerInt;
   1.657            }
   1.658            break;
   1.659 -        case NONSTATIC_ALIGNED_DOUBLE:
   1.660          case NONSTATIC_DOUBLE:
   1.661            real_offset = next_nonstatic_double_offset;
   1.662            next_nonstatic_double_offset += BytesPerLong;
   1.663 @@ -3469,8 +3256,7 @@
   1.664          default:
   1.665            ShouldNotReachHere();
   1.666        }
   1.667 -      fields->short_at_put(i + instanceKlass::low_offset,  extract_low_short_from_int(real_offset));
   1.668 -      fields->short_at_put(i + instanceKlass::high_offset, extract_high_short_from_int(real_offset));
   1.669 +      fs.set_offset(real_offset);
   1.670      }
   1.671  
   1.672      // Size of instances
   1.673 @@ -3517,12 +3303,12 @@
   1.674      this_klass->set_class_loader(class_loader());
   1.675      this_klass->set_nonstatic_field_size(nonstatic_field_size);
   1.676      this_klass->set_has_nonstatic_fields(has_nonstatic_fields);
   1.677 -    this_klass->set_static_oop_field_count(fac.static_oop_count);
   1.678 +    this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]);
   1.679      cp->set_pool_holder(this_klass());
   1.680      error_handler.set_in_error(false);   // turn off error handler for cp
   1.681      this_klass->set_constants(cp());
   1.682      this_klass->set_local_interfaces(local_interfaces());
   1.683 -    this_klass->set_fields(fields());
   1.684 +    this_klass->set_fields(fields(), java_fields_count);
   1.685      this_klass->set_methods(methods());
   1.686      if (has_final_method) {
   1.687        this_klass->set_has_final_method();

mercurial