hotspot/src/share/vm/classfile/classFileParser.cpp
changeset 12772 d317e5e08194
parent 12587 8f819769ca1b
child 13282 9872915dd78d
child 13195 be27e1b6a4b9
child 13291 9de3b1387cb8
equal deleted inserted replaced
12724:1e3d7ca55ffc 12772:d317e5e08194
  1080   u2 length = cfs->get_u2_fast();
  1080   u2 length = cfs->get_u2_fast();
  1081   *java_fields_count_ptr = length;
  1081   *java_fields_count_ptr = length;
  1082 
  1082 
  1083   int num_injected = 0;
  1083   int num_injected = 0;
  1084   InjectedField* injected = JavaClasses::get_injected(class_name, &num_injected);
  1084   InjectedField* injected = JavaClasses::get_injected(class_name, &num_injected);
  1085 
  1085   int total_fields = length + num_injected;
  1086   // Tuples of shorts [access, name index, sig index, initial value index, byte offset, generic signature index]
  1086 
  1087   typeArrayOop new_fields = oopFactory::new_permanent_shortArray((length + num_injected) * FieldInfo::field_slots, CHECK_(nullHandle));
  1087   // The field array starts with tuples of shorts
  1088   typeArrayHandle fields(THREAD, new_fields);
  1088   // [access, name index, sig index, initial value index, byte offset].
       
  1089   // A generic signature slot only exists for field with generic
       
  1090   // signature attribute. And the access flag is set with
       
  1091   // JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE for that field. The generic
       
  1092   // signature slots are at the end of the field array and after all
       
  1093   // other fields data.
       
  1094   //
       
  1095   //   f1: [access, name index, sig index, initial value index, low_offset, high_offset]
       
  1096   //   f2: [access, name index, sig index, initial value index, low_offset, high_offset]
       
  1097   //       ...
       
  1098   //   fn: [access, name index, sig index, initial value index, low_offset, high_offset]
       
  1099   //       [generic signature index]
       
  1100   //       [generic signature index]
       
  1101   //       ...
       
  1102   //
       
  1103   // Allocate a temporary resource array for field data. For each field,
       
  1104   // a slot is reserved in the temporary array for the generic signature
       
  1105   // index. After parsing all fields, the data are copied to a permanent
       
  1106   // array and any unused slots will be discarded.
       
  1107   ResourceMark rm(THREAD);
       
  1108   u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD(
       
  1109              THREAD, u2, total_fields * (FieldInfo::field_slots + 1));
  1089 
  1110 
  1090   typeArrayHandle field_annotations;
  1111   typeArrayHandle field_annotations;
       
  1112   // The generic signature slots start after all other fields' data.
       
  1113   int generic_signature_slot = total_fields * FieldInfo::field_slots;
       
  1114   int num_generic_signature = 0;
  1091   for (int n = 0; n < length; n++) {
  1115   for (int n = 0; n < length; n++) {
  1092     cfs->guarantee_more(8, CHECK_(nullHandle));  // access_flags, name_index, descriptor_index, attributes_count
  1116     cfs->guarantee_more(8, CHECK_(nullHandle));  // access_flags, name_index, descriptor_index, attributes_count
  1093 
  1117 
  1094     AccessFlags access_flags;
  1118     AccessFlags access_flags;
  1095     jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS;
  1119     jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS;
  1133         (*fields_annotations)->obj_at_put(n, field_annotations());
  1157         (*fields_annotations)->obj_at_put(n, field_annotations());
  1134       }
  1158       }
  1135       if (is_synthetic) {
  1159       if (is_synthetic) {
  1136         access_flags.set_is_synthetic();
  1160         access_flags.set_is_synthetic();
  1137       }
  1161       }
  1138     }
  1162       if (generic_signature_index != 0) {
  1139 
  1163         access_flags.set_field_has_generic_signature();
  1140     FieldInfo* field = FieldInfo::from_field_array(fields(), n);
  1164         fa[generic_signature_slot] = generic_signature_index;
       
  1165         generic_signature_slot ++;
       
  1166         num_generic_signature ++;
       
  1167       }
       
  1168     }
       
  1169 
       
  1170     FieldInfo* field = FieldInfo::from_field_array(fa, n);
  1141     field->initialize(access_flags.as_short(),
  1171     field->initialize(access_flags.as_short(),
  1142                       name_index,
  1172                       name_index,
  1143                       signature_index,
  1173                       signature_index,
  1144                       constantvalue_index,
  1174                       constantvalue_index,
  1145                       generic_signature_index,
       
  1146                       0);
  1175                       0);
  1147 
  1176 
  1148     BasicType type = cp->basic_type_for_signature_at(signature_index);
  1177     BasicType type = cp->basic_type_for_signature_at(signature_index);
  1149 
  1178 
  1150     // Remember how many oops we encountered and compute allocation type
  1179     // Remember how many oops we encountered and compute allocation type
  1153     // The correct offset is computed later (all oop fields will be located together)
  1182     // The correct offset is computed later (all oop fields will be located together)
  1154     // We temporarily store the allocation type in the offset field
  1183     // We temporarily store the allocation type in the offset field
  1155     field->set_offset(atype);
  1184     field->set_offset(atype);
  1156   }
  1185   }
  1157 
  1186 
       
  1187   int index = length;
  1158   if (num_injected != 0) {
  1188   if (num_injected != 0) {
  1159     int index = length;
       
  1160     for (int n = 0; n < num_injected; n++) {
  1189     for (int n = 0; n < num_injected; n++) {
  1161       // Check for duplicates
  1190       // Check for duplicates
  1162       if (injected[n].may_be_java) {
  1191       if (injected[n].may_be_java) {
  1163         Symbol* name      = injected[n].name();
  1192         Symbol* name      = injected[n].name();
  1164         Symbol* signature = injected[n].signature();
  1193         Symbol* signature = injected[n].signature();
  1165         bool duplicate = false;
  1194         bool duplicate = false;
  1166         for (int i = 0; i < length; i++) {
  1195         for (int i = 0; i < length; i++) {
  1167           FieldInfo* f = FieldInfo::from_field_array(fields(), i);
  1196           FieldInfo* f = FieldInfo::from_field_array(fa, i);
  1168           if (name      == cp->symbol_at(f->name_index()) &&
  1197           if (name      == cp->symbol_at(f->name_index()) &&
  1169               signature == cp->symbol_at(f->signature_index())) {
  1198               signature == cp->symbol_at(f->signature_index())) {
  1170             // Symbol is desclared in Java so skip this one
  1199             // Symbol is desclared in Java so skip this one
  1171             duplicate = true;
  1200             duplicate = true;
  1172             break;
  1201             break;
  1177           continue;
  1206           continue;
  1178         }
  1207         }
  1179       }
  1208       }
  1180 
  1209 
  1181       // Injected field
  1210       // Injected field
  1182       FieldInfo* field = FieldInfo::from_field_array(fields(), index);
  1211       FieldInfo* field = FieldInfo::from_field_array(fa, index);
  1183       field->initialize(JVM_ACC_FIELD_INTERNAL,
  1212       field->initialize(JVM_ACC_FIELD_INTERNAL,
  1184                         injected[n].name_index,
  1213                         injected[n].name_index,
  1185                         injected[n].signature_index,
  1214                         injected[n].signature_index,
  1186                         0,
  1215                         0,
  1187                         0,
       
  1188                         0);
  1216                         0);
  1189 
  1217 
  1190       BasicType type = FieldType::basic_type(injected[n].signature());
  1218       BasicType type = FieldType::basic_type(injected[n].signature());
  1191 
  1219 
  1192       // Remember how many oops we encountered and compute allocation type
  1220       // Remember how many oops we encountered and compute allocation type
  1195       // The correct offset is computed later (all oop fields will be located together)
  1223       // The correct offset is computed later (all oop fields will be located together)
  1196       // We temporarily store the allocation type in the offset field
  1224       // We temporarily store the allocation type in the offset field
  1197       field->set_offset(atype);
  1225       field->set_offset(atype);
  1198       index++;
  1226       index++;
  1199     }
  1227     }
  1200 
  1228   }
  1201     if (index < length + num_injected) {
  1229 
  1202       // sometimes injected fields already exist in the Java source so
  1230   // Now copy the fields' data from the temporary resource array.
  1203       // the fields array could be too long.  In that case trim the
  1231   // Sometimes injected fields already exist in the Java source so
  1204       // fields array.
  1232   // the fields array could be too long.  In that case the
  1205       new_fields = oopFactory::new_permanent_shortArray(index * FieldInfo::field_slots, CHECK_(nullHandle));
  1233   // fields array is trimed. Also unused slots that were reserved
  1206       for (int i = 0; i < index * FieldInfo::field_slots; i++) {
  1234   // for generic signature indexes are discarded.
  1207         new_fields->short_at_put(i, fields->short_at(i));
  1235   typeArrayOop new_fields = oopFactory::new_permanent_shortArray(
  1208       }
  1236     index * FieldInfo::field_slots + num_generic_signature,
  1209       fields = new_fields;
  1237     CHECK_(nullHandle));
  1210     }
  1238   typeArrayHandle fields(THREAD, new_fields);
       
  1239   {
       
  1240     int i = 0;
       
  1241     for (; i < index * FieldInfo::field_slots; i++) {
       
  1242       new_fields->short_at_put(i, fa[i]);
       
  1243     }
       
  1244     for (int j = total_fields * FieldInfo::field_slots;
       
  1245          j < generic_signature_slot; j++) {
       
  1246       new_fields->short_at_put(i++, fa[j]);
       
  1247     }
       
  1248     assert(i == new_fields->length(), "");
  1211   }
  1249   }
  1212 
  1250 
  1213   if (_need_verify && length > 1) {
  1251   if (_need_verify && length > 1) {
  1214     // Check duplicated fields
  1252     // Check duplicated fields
  1215     ResourceMark rm(THREAD);
  1253     ResourceMark rm(THREAD);