Wed, 13 Mar 2013 17:34:29 -0400
8003419: NPG: Clean up metadata created during class loading if failure
Summary: Store metadata on ClassFileParser instance to be cleaned up by destructor. This enabled some refactoring of the enormous parseClassFile function.
Reviewed-by: jmasa, acorn
1.1 --- a/src/share/vm/classfile/classFileParser.cpp Wed Mar 13 15:15:56 2013 -0400 1.2 +++ b/src/share/vm/classfile/classFileParser.cpp Wed Mar 13 17:34:29 2013 -0400 1.3 @@ -90,8 +90,7 @@ 1.4 // Extension method support. 1.5 #define JAVA_8_VERSION 52 1.6 1.7 - 1.8 -void ClassFileParser::parse_constant_pool_entries(ClassLoaderData* loader_data, constantPoolHandle cp, int length, TRAPS) { 1.9 +void ClassFileParser::parse_constant_pool_entries(int length, TRAPS) { 1.10 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize 1.11 // this function (_current can be allocated in a register, with scalar 1.12 // replacement of aggregates). The _current pointer is copied back to 1.13 @@ -104,7 +103,7 @@ 1.14 assert(cfs->allocated_on_stack(),"should be local"); 1.15 u1* old_current = cfs0->current(); 1.16 #endif 1.17 - Handle class_loader(THREAD, loader_data->class_loader()); 1.18 + Handle class_loader(THREAD, _loader_data->class_loader()); 1.19 1.20 // Used for batching symbol allocations. 1.21 const char* names[SymbolTable::symbol_alloc_batch_size]; 1.22 @@ -124,7 +123,7 @@ 1.23 { 1.24 cfs->guarantee_more(3, CHECK); // name_index, tag/access_flags 1.25 u2 name_index = cfs->get_u2_fast(); 1.26 - cp->klass_index_at_put(index, name_index); 1.27 + _cp->klass_index_at_put(index, name_index); 1.28 } 1.29 break; 1.30 case JVM_CONSTANT_Fieldref : 1.31 @@ -132,7 +131,7 @@ 1.32 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags 1.33 u2 class_index = cfs->get_u2_fast(); 1.34 u2 name_and_type_index = cfs->get_u2_fast(); 1.35 - cp->field_at_put(index, class_index, name_and_type_index); 1.36 + _cp->field_at_put(index, class_index, name_and_type_index); 1.37 } 1.38 break; 1.39 case JVM_CONSTANT_Methodref : 1.40 @@ -140,7 +139,7 @@ 1.41 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags 1.42 u2 class_index = cfs->get_u2_fast(); 1.43 u2 name_and_type_index = cfs->get_u2_fast(); 1.44 - cp->method_at_put(index, class_index, name_and_type_index); 1.45 + _cp->method_at_put(index, class_index, name_and_type_index); 1.46 } 1.47 break; 1.48 case JVM_CONSTANT_InterfaceMethodref : 1.49 @@ -148,14 +147,14 @@ 1.50 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags 1.51 u2 class_index = cfs->get_u2_fast(); 1.52 u2 name_and_type_index = cfs->get_u2_fast(); 1.53 - cp->interface_method_at_put(index, class_index, name_and_type_index); 1.54 + _cp->interface_method_at_put(index, class_index, name_and_type_index); 1.55 } 1.56 break; 1.57 case JVM_CONSTANT_String : 1.58 { 1.59 cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags 1.60 u2 string_index = cfs->get_u2_fast(); 1.61 - cp->string_index_at_put(index, string_index); 1.62 + _cp->string_index_at_put(index, string_index); 1.63 } 1.64 break; 1.65 case JVM_CONSTANT_MethodHandle : 1.66 @@ -174,11 +173,11 @@ 1.67 cfs->guarantee_more(4, CHECK); // ref_kind, method_index, tag/access_flags 1.68 u1 ref_kind = cfs->get_u1_fast(); 1.69 u2 method_index = cfs->get_u2_fast(); 1.70 - cp->method_handle_index_at_put(index, ref_kind, method_index); 1.71 + _cp->method_handle_index_at_put(index, ref_kind, method_index); 1.72 } else if (tag == JVM_CONSTANT_MethodType) { 1.73 cfs->guarantee_more(3, CHECK); // signature_index, tag/access_flags 1.74 u2 signature_index = cfs->get_u2_fast(); 1.75 - cp->method_type_index_at_put(index, signature_index); 1.76 + _cp->method_type_index_at_put(index, signature_index); 1.77 } else { 1.78 ShouldNotReachHere(); 1.79 } 1.80 @@ -200,21 +199,21 @@ 1.81 u2 name_and_type_index = cfs->get_u2_fast(); 1.82 if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) 1.83 _max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later 1.84 - cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); 1.85 + _cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); 1.86 } 1.87 break; 1.88 case JVM_CONSTANT_Integer : 1.89 { 1.90 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags 1.91 u4 bytes = cfs->get_u4_fast(); 1.92 - cp->int_at_put(index, (jint) bytes); 1.93 + _cp->int_at_put(index, (jint) bytes); 1.94 } 1.95 break; 1.96 case JVM_CONSTANT_Float : 1.97 { 1.98 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags 1.99 u4 bytes = cfs->get_u4_fast(); 1.100 - cp->float_at_put(index, *(jfloat*)&bytes); 1.101 + _cp->float_at_put(index, *(jfloat*)&bytes); 1.102 } 1.103 break; 1.104 case JVM_CONSTANT_Long : 1.105 @@ -225,7 +224,7 @@ 1.106 { 1.107 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags 1.108 u8 bytes = cfs->get_u8_fast(); 1.109 - cp->long_at_put(index, bytes); 1.110 + _cp->long_at_put(index, bytes); 1.111 } 1.112 index++; // Skip entry following eigth-byte constant, see JVM book p. 98 1.113 break; 1.114 @@ -237,7 +236,7 @@ 1.115 { 1.116 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags 1.117 u8 bytes = cfs->get_u8_fast(); 1.118 - cp->double_at_put(index, *(jdouble*)&bytes); 1.119 + _cp->double_at_put(index, *(jdouble*)&bytes); 1.120 } 1.121 index++; // Skip entry following eigth-byte constant, see JVM book p. 98 1.122 break; 1.123 @@ -246,7 +245,7 @@ 1.124 cfs->guarantee_more(5, CHECK); // name_index, signature_index, tag/access_flags 1.125 u2 name_index = cfs->get_u2_fast(); 1.126 u2 signature_index = cfs->get_u2_fast(); 1.127 - cp->name_and_type_at_put(index, name_index, signature_index); 1.128 + _cp->name_and_type_at_put(index, name_index, signature_index); 1.129 } 1.130 break; 1.131 case JVM_CONSTANT_Utf8 : 1.132 @@ -283,11 +282,11 @@ 1.133 indices[names_count] = index; 1.134 hashValues[names_count++] = hash; 1.135 if (names_count == SymbolTable::symbol_alloc_batch_size) { 1.136 - SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); 1.137 + SymbolTable::new_symbols(_loader_data, _cp, names_count, names, lengths, indices, hashValues, CHECK); 1.138 names_count = 0; 1.139 } 1.140 } else { 1.141 - cp->symbol_at_put(index, result); 1.142 + _cp->symbol_at_put(index, result); 1.143 } 1.144 } 1.145 break; 1.146 @@ -300,7 +299,7 @@ 1.147 1.148 // Allocate the remaining symbols 1.149 if (names_count > 0) { 1.150 - SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); 1.151 + SymbolTable::new_symbols(_loader_data, _cp, names_count, names, lengths, indices, hashValues, CHECK); 1.152 } 1.153 1.154 // Copy _current pointer of local copy back to stream(). 1.155 @@ -310,23 +309,6 @@ 1.156 cfs0->set_current(cfs1.current()); 1.157 } 1.158 1.159 -// This class unreferences constant pool symbols if an error has occurred 1.160 -// while parsing the class before it is assigned into the class. 1.161 -// If it gets an error after that it is unloaded and the constant pool will 1.162 -// be cleaned up then. 1.163 -class ConstantPoolCleaner : public StackObj { 1.164 - constantPoolHandle _cphandle; 1.165 - bool _in_error; 1.166 - public: 1.167 - ConstantPoolCleaner(constantPoolHandle cp) : _cphandle(cp), _in_error(true) {} 1.168 - ~ConstantPoolCleaner() { 1.169 - if (_in_error && _cphandle.not_null()) { 1.170 - _cphandle->unreference_symbols(); 1.171 - } 1.172 - } 1.173 - void set_in_error(bool clean) { _in_error = clean; } 1.174 -}; 1.175 - 1.176 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); } 1.177 1.178 inline Symbol* check_symbol_at(constantPoolHandle cp, int index) { 1.179 @@ -336,7 +318,7 @@ 1.180 return NULL; 1.181 } 1.182 1.183 -constantPoolHandle ClassFileParser::parse_constant_pool(ClassLoaderData* loader_data, TRAPS) { 1.184 +constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) { 1.185 ClassFileStream* cfs = stream(); 1.186 constantPoolHandle nullHandle; 1.187 1.188 @@ -345,16 +327,13 @@ 1.189 guarantee_property( 1.190 length >= 1, "Illegal constant pool size %u in class file %s", 1.191 length, CHECK_(nullHandle)); 1.192 - ConstantPool* constant_pool = 1.193 - ConstantPool::allocate(loader_data, 1.194 - length, 1.195 - CHECK_(nullHandle)); 1.196 + ConstantPool* constant_pool = ConstantPool::allocate(_loader_data, length, 1.197 + CHECK_(nullHandle)); 1.198 + _cp = constant_pool; // save in case of errors 1.199 constantPoolHandle cp (THREAD, constant_pool); 1.200 1.201 - ConstantPoolCleaner cp_in_error(cp); // set constant pool to be cleaned up. 1.202 - 1.203 // parsing constant pool entries 1.204 - parse_constant_pool_entries(loader_data, cp, length, CHECK_(nullHandle)); 1.205 + parse_constant_pool_entries(length, CHECK_(nullHandle)); 1.206 1.207 int index = 1; // declared outside of loops for portability 1.208 1.209 @@ -373,8 +352,7 @@ 1.210 if (!_need_verify) break; 1.211 int klass_ref_index = cp->klass_ref_index_at(index); 1.212 int name_and_type_ref_index = cp->name_and_type_ref_index_at(index); 1.213 - check_property(valid_cp_range(klass_ref_index, length) && 1.214 - is_klass_reference(cp, klass_ref_index), 1.215 + check_property(valid_klass_reference_at(klass_ref_index), 1.216 "Invalid constant pool index %u in class file %s", 1.217 klass_ref_index, 1.218 CHECK_(nullHandle)); 1.219 @@ -404,16 +382,12 @@ 1.220 if (!_need_verify) break; 1.221 int name_ref_index = cp->name_ref_index_at(index); 1.222 int signature_ref_index = cp->signature_ref_index_at(index); 1.223 - check_property( 1.224 - valid_cp_range(name_ref_index, length) && 1.225 - cp->tag_at(name_ref_index).is_utf8(), 1.226 - "Invalid constant pool index %u in class file %s", 1.227 - name_ref_index, CHECK_(nullHandle)); 1.228 - check_property( 1.229 - valid_cp_range(signature_ref_index, length) && 1.230 - cp->tag_at(signature_ref_index).is_utf8(), 1.231 - "Invalid constant pool index %u in class file %s", 1.232 - signature_ref_index, CHECK_(nullHandle)); 1.233 + check_property(valid_symbol_at(name_ref_index), 1.234 + "Invalid constant pool index %u in class file %s", 1.235 + name_ref_index, CHECK_(nullHandle)); 1.236 + check_property(valid_symbol_at(signature_ref_index), 1.237 + "Invalid constant pool index %u in class file %s", 1.238 + signature_ref_index, CHECK_(nullHandle)); 1.239 break; 1.240 } 1.241 case JVM_CONSTANT_Utf8 : 1.242 @@ -425,22 +399,18 @@ 1.243 case JVM_CONSTANT_ClassIndex : 1.244 { 1.245 int class_index = cp->klass_index_at(index); 1.246 - check_property( 1.247 - valid_cp_range(class_index, length) && 1.248 - cp->tag_at(class_index).is_utf8(), 1.249 - "Invalid constant pool index %u in class file %s", 1.250 - class_index, CHECK_(nullHandle)); 1.251 + check_property(valid_symbol_at(class_index), 1.252 + "Invalid constant pool index %u in class file %s", 1.253 + class_index, CHECK_(nullHandle)); 1.254 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index)); 1.255 } 1.256 break; 1.257 case JVM_CONSTANT_StringIndex : 1.258 { 1.259 int string_index = cp->string_index_at(index); 1.260 - check_property( 1.261 - valid_cp_range(string_index, length) && 1.262 - cp->tag_at(string_index).is_utf8(), 1.263 - "Invalid constant pool index %u in class file %s", 1.264 - string_index, CHECK_(nullHandle)); 1.265 + check_property(valid_symbol_at(string_index), 1.266 + "Invalid constant pool index %u in class file %s", 1.267 + string_index, CHECK_(nullHandle)); 1.268 Symbol* sym = cp->symbol_at(string_index); 1.269 cp->unresolved_string_at_put(index, sym); 1.270 } 1.271 @@ -491,12 +461,9 @@ 1.272 case JVM_CONSTANT_MethodType : 1.273 { 1.274 int ref_index = cp->method_type_index_at(index); 1.275 - check_property( 1.276 - valid_cp_range(ref_index, length) && 1.277 - cp->tag_at(ref_index).is_utf8() && 1.278 - EnableInvokeDynamic, 1.279 - "Invalid constant pool index %u in class file %s", 1.280 - ref_index, CHECK_(nullHandle)); 1.281 + check_property(valid_symbol_at(ref_index) && EnableInvokeDynamic, 1.282 + "Invalid constant pool index %u in class file %s", 1.283 + ref_index, CHECK_(nullHandle)); 1.284 } 1.285 break; 1.286 case JVM_CONSTANT_InvokeDynamic : 1.287 @@ -541,7 +508,6 @@ 1.288 } 1.289 1.290 if (!_need_verify) { 1.291 - cp_in_error.set_in_error(false); 1.292 return cp; 1.293 } 1.294 1.295 @@ -664,7 +630,6 @@ 1.296 } // end of switch 1.297 } // end of for 1.298 1.299 - cp_in_error.set_in_error(false); 1.300 return cp; 1.301 } 1.302 1.303 @@ -786,93 +751,92 @@ 1.304 } 1.305 1.306 1.307 -Array<Klass*>* ClassFileParser::parse_interfaces(constantPoolHandle cp, 1.308 - int length, 1.309 - ClassLoaderData* loader_data, 1.310 +Array<Klass*>* ClassFileParser::parse_interfaces(int length, 1.311 Handle protection_domain, 1.312 Symbol* class_name, 1.313 bool* has_default_methods, 1.314 TRAPS) { 1.315 - ClassFileStream* cfs = stream(); 1.316 - assert(length > 0, "only called for length>0"); 1.317 - // FIXME: Leak at later OOM. 1.318 - Array<Klass*>* interfaces = MetadataFactory::new_array<Klass*>(loader_data, length, NULL, CHECK_NULL); 1.319 - 1.320 - int index; 1.321 - for (index = 0; index < length; index++) { 1.322 - u2 interface_index = cfs->get_u2(CHECK_NULL); 1.323 - KlassHandle interf; 1.324 - check_property( 1.325 - valid_cp_range(interface_index, cp->length()) && 1.326 - is_klass_reference(cp, interface_index), 1.327 - "Interface name has bad constant pool index %u in class file %s", 1.328 - interface_index, CHECK_NULL); 1.329 - if (cp->tag_at(interface_index).is_klass()) { 1.330 - interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index)); 1.331 - } else { 1.332 - Symbol* unresolved_klass = cp->klass_name_at(interface_index); 1.333 - 1.334 - // Don't need to check legal name because it's checked when parsing constant pool. 1.335 - // But need to make sure it's not an array type. 1.336 - guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, 1.337 - "Bad interface name in class file %s", CHECK_NULL); 1.338 - Handle class_loader(THREAD, loader_data->class_loader()); 1.339 - 1.340 - // Call resolve_super so classcircularity is checked 1.341 - Klass* k = SystemDictionary::resolve_super_or_fail(class_name, 1.342 - unresolved_klass, class_loader, protection_domain, 1.343 - false, CHECK_NULL); 1.344 - interf = KlassHandle(THREAD, k); 1.345 + if (length == 0) { 1.346 + _local_interfaces = Universe::the_empty_klass_array(); 1.347 + } else { 1.348 + ClassFileStream* cfs = stream(); 1.349 + assert(length > 0, "only called for length>0"); 1.350 + _local_interfaces = MetadataFactory::new_array<Klass*>(_loader_data, length, NULL, CHECK_NULL); 1.351 + 1.352 + int index; 1.353 + for (index = 0; index < length; index++) { 1.354 + u2 interface_index = cfs->get_u2(CHECK_NULL); 1.355 + KlassHandle interf; 1.356 + check_property( 1.357 + valid_klass_reference_at(interface_index), 1.358 + "Interface name has bad constant pool index %u in class file %s", 1.359 + interface_index, CHECK_NULL); 1.360 + if (_cp->tag_at(interface_index).is_klass()) { 1.361 + interf = KlassHandle(THREAD, _cp->resolved_klass_at(interface_index)); 1.362 + } else { 1.363 + Symbol* unresolved_klass = _cp->klass_name_at(interface_index); 1.364 + 1.365 + // Don't need to check legal name because it's checked when parsing constant pool. 1.366 + // But need to make sure it's not an array type. 1.367 + guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, 1.368 + "Bad interface name in class file %s", CHECK_NULL); 1.369 + Handle class_loader(THREAD, _loader_data->class_loader()); 1.370 + 1.371 + // Call resolve_super so classcircularity is checked 1.372 + Klass* k = SystemDictionary::resolve_super_or_fail(class_name, 1.373 + unresolved_klass, class_loader, protection_domain, 1.374 + false, CHECK_NULL); 1.375 + interf = KlassHandle(THREAD, k); 1.376 + } 1.377 + 1.378 + if (!interf()->is_interface()) { 1.379 + THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); 1.380 + } 1.381 + if (InstanceKlass::cast(interf())->has_default_methods()) { 1.382 + *has_default_methods = true; 1.383 + } 1.384 + _local_interfaces->at_put(index, interf()); 1.385 } 1.386 1.387 - if (!interf()->is_interface()) { 1.388 - THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); 1.389 + if (!_need_verify || length <= 1) { 1.390 + return _local_interfaces; 1.391 } 1.392 - if (InstanceKlass::cast(interf())->has_default_methods()) { 1.393 - *has_default_methods = true; 1.394 - } 1.395 - interfaces->at_put(index, interf()); 1.396 - } 1.397 - 1.398 - if (!_need_verify || length <= 1) { 1.399 - return interfaces; 1.400 - } 1.401 - 1.402 - // Check if there's any duplicates in interfaces 1.403 - ResourceMark rm(THREAD); 1.404 - NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD( 1.405 - THREAD, NameSigHash*, HASH_ROW_SIZE); 1.406 - initialize_hashtable(interface_names); 1.407 - bool dup = false; 1.408 - { 1.409 - debug_only(No_Safepoint_Verifier nsv;) 1.410 - for (index = 0; index < length; index++) { 1.411 - Klass* k = interfaces->at(index); 1.412 - Symbol* name = InstanceKlass::cast(k)->name(); 1.413 - // If no duplicates, add (name, NULL) in hashtable interface_names. 1.414 - if (!put_after_lookup(name, NULL, interface_names)) { 1.415 - dup = true; 1.416 - break; 1.417 + 1.418 + // Check if there's any duplicates in interfaces 1.419 + ResourceMark rm(THREAD); 1.420 + NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD( 1.421 + THREAD, NameSigHash*, HASH_ROW_SIZE); 1.422 + initialize_hashtable(interface_names); 1.423 + bool dup = false; 1.424 + { 1.425 + debug_only(No_Safepoint_Verifier nsv;) 1.426 + for (index = 0; index < length; index++) { 1.427 + Klass* k = _local_interfaces->at(index); 1.428 + Symbol* name = InstanceKlass::cast(k)->name(); 1.429 + // If no duplicates, add (name, NULL) in hashtable interface_names. 1.430 + if (!put_after_lookup(name, NULL, interface_names)) { 1.431 + dup = true; 1.432 + break; 1.433 + } 1.434 } 1.435 } 1.436 + if (dup) { 1.437 + classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); 1.438 + } 1.439 } 1.440 - if (dup) { 1.441 - classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); 1.442 - } 1.443 - 1.444 - return interfaces; 1.445 + return _local_interfaces; 1.446 } 1.447 1.448 1.449 -void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS) { 1.450 +void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, TRAPS) { 1.451 // Make sure the constant pool entry is of a type appropriate to this field 1.452 guarantee_property( 1.453 (constantvalue_index > 0 && 1.454 - constantvalue_index < cp->length()), 1.455 + constantvalue_index < _cp->length()), 1.456 "Bad initial value index %u in ConstantValue attribute in class file %s", 1.457 constantvalue_index, CHECK); 1.458 - constantTag value_type = cp->tag_at(constantvalue_index); 1.459 - switch ( cp->basic_type_for_signature_at(signature_index) ) { 1.460 + constantTag value_type = _cp->tag_at(constantvalue_index); 1.461 + switch ( _cp->basic_type_for_signature_at(signature_index) ) { 1.462 case T_LONG: 1.463 guarantee_property(value_type.is_long(), "Inconsistent constant value type in class file %s", CHECK); 1.464 break; 1.465 @@ -886,7 +850,7 @@ 1.466 guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK); 1.467 break; 1.468 case T_OBJECT: 1.469 - guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;") 1.470 + guarantee_property((_cp->symbol_at(signature_index)->equals("Ljava/lang/String;") 1.471 && value_type.is_string()), 1.472 "Bad string initial value in class file %s", CHECK); 1.473 break; 1.474 @@ -899,15 +863,11 @@ 1.475 1.476 1.477 // Parse attributes for a field. 1.478 -void ClassFileParser::parse_field_attributes(ClassLoaderData* loader_data, 1.479 - constantPoolHandle cp, 1.480 - u2 attributes_count, 1.481 +void ClassFileParser::parse_field_attributes(u2 attributes_count, 1.482 bool is_static, u2 signature_index, 1.483 u2* constantvalue_index_addr, 1.484 bool* is_synthetic_addr, 1.485 u2* generic_signature_index_addr, 1.486 - AnnotationArray** field_annotations, 1.487 - AnnotationArray** field_type_annotations, 1.488 ClassFileParser::FieldAnnotationCollector* parsed_annotations, 1.489 TRAPS) { 1.490 ClassFileStream* cfs = stream(); 1.491 @@ -927,12 +887,11 @@ 1.492 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length 1.493 u2 attribute_name_index = cfs->get_u2_fast(); 1.494 u4 attribute_length = cfs->get_u4_fast(); 1.495 - check_property(valid_cp_range(attribute_name_index, cp->length()) && 1.496 - cp->tag_at(attribute_name_index).is_utf8(), 1.497 + check_property(valid_symbol_at(attribute_name_index), 1.498 "Invalid field attribute index %u in class file %s", 1.499 attribute_name_index, 1.500 CHECK); 1.501 - Symbol* attribute_name = cp->symbol_at(attribute_name_index); 1.502 + Symbol* attribute_name = _cp->symbol_at(attribute_name_index); 1.503 if (is_static && attribute_name == vmSymbols::tag_constant_value()) { 1.504 // ignore if non-static 1.505 if (constantvalue_index != 0) { 1.506 @@ -944,7 +903,7 @@ 1.507 attribute_length, CHECK); 1.508 constantvalue_index = cfs->get_u2(CHECK); 1.509 if (_need_verify) { 1.510 - verify_constantvalue(constantvalue_index, signature_index, cp, CHECK); 1.511 + verify_constantvalue(constantvalue_index, signature_index, CHECK); 1.512 } 1.513 } else if (attribute_name == vmSymbols::tag_synthetic()) { 1.514 if (attribute_length != 0) { 1.515 @@ -971,10 +930,8 @@ 1.516 runtime_visible_annotations_length = attribute_length; 1.517 runtime_visible_annotations = cfs->get_u1_buffer(); 1.518 assert(runtime_visible_annotations != NULL, "null visible annotations"); 1.519 - parse_annotations(loader_data, 1.520 - runtime_visible_annotations, 1.521 + parse_annotations(runtime_visible_annotations, 1.522 runtime_visible_annotations_length, 1.523 - cp, 1.524 parsed_annotations, 1.525 CHECK); 1.526 cfs->skip_u1(runtime_visible_annotations_length, CHECK); 1.527 @@ -1004,18 +961,18 @@ 1.528 *constantvalue_index_addr = constantvalue_index; 1.529 *is_synthetic_addr = is_synthetic; 1.530 *generic_signature_index_addr = generic_signature_index; 1.531 - *field_annotations = assemble_annotations(loader_data, 1.532 - runtime_visible_annotations, 1.533 + AnnotationArray* a = assemble_annotations(runtime_visible_annotations, 1.534 runtime_visible_annotations_length, 1.535 runtime_invisible_annotations, 1.536 runtime_invisible_annotations_length, 1.537 CHECK); 1.538 - *field_type_annotations = assemble_annotations(loader_data, 1.539 - runtime_visible_type_annotations, 1.540 - runtime_visible_type_annotations_length, 1.541 - runtime_invisible_type_annotations, 1.542 - runtime_invisible_type_annotations_length, 1.543 - CHECK); 1.544 + parsed_annotations->set_field_annotations(a); 1.545 + a = assemble_annotations(runtime_visible_type_annotations, 1.546 + runtime_visible_type_annotations_length, 1.547 + runtime_invisible_type_annotations, 1.548 + runtime_invisible_type_annotations_length, 1.549 + CHECK); 1.550 + parsed_annotations->set_field_type_annotations(a); 1.551 return; 1.552 } 1.553 1.554 @@ -1106,13 +1063,9 @@ 1.555 } 1.556 }; 1.557 1.558 -Array<u2>* ClassFileParser::parse_fields(ClassLoaderData* loader_data, 1.559 - Symbol* class_name, 1.560 - constantPoolHandle cp, 1.561 +Array<u2>* ClassFileParser::parse_fields(Symbol* class_name, 1.562 bool is_interface, 1.563 FieldAllocationCount *fac, 1.564 - Array<AnnotationArray*>** fields_annotations, 1.565 - Array<AnnotationArray*>** fields_type_annotations, 1.566 u2* java_fields_count_ptr, TRAPS) { 1.567 ClassFileStream* cfs = stream(); 1.568 cfs->guarantee_more(2, CHECK_NULL); // length 1.569 @@ -1147,8 +1100,6 @@ 1.570 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD( 1.571 THREAD, u2, total_fields * (FieldInfo::field_slots + 1)); 1.572 1.573 - AnnotationArray* field_annotations = NULL; 1.574 - AnnotationArray* field_type_annotations = NULL; 1.575 // The generic signature slots start after all other fields' data. 1.576 int generic_signature_slot = total_fields * FieldInfo::field_slots; 1.577 int num_generic_signature = 0; 1.578 @@ -1161,53 +1112,52 @@ 1.579 access_flags.set_flags(flags); 1.580 1.581 u2 name_index = cfs->get_u2_fast(); 1.582 - int cp_size = cp->length(); 1.583 - check_property( 1.584 - valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(), 1.585 + int cp_size = _cp->length(); 1.586 + check_property(valid_symbol_at(name_index), 1.587 "Invalid constant pool index %u for field name in class file %s", 1.588 - name_index, CHECK_NULL); 1.589 - Symbol* name = cp->symbol_at(name_index); 1.590 + name_index, 1.591 + CHECK_NULL); 1.592 + Symbol* name = _cp->symbol_at(name_index); 1.593 verify_legal_field_name(name, CHECK_NULL); 1.594 1.595 u2 signature_index = cfs->get_u2_fast(); 1.596 - check_property( 1.597 - valid_cp_range(signature_index, cp_size) && 1.598 - cp->tag_at(signature_index).is_utf8(), 1.599 + check_property(valid_symbol_at(signature_index), 1.600 "Invalid constant pool index %u for field signature in class file %s", 1.601 signature_index, CHECK_NULL); 1.602 - Symbol* sig = cp->symbol_at(signature_index); 1.603 + Symbol* sig = _cp->symbol_at(signature_index); 1.604 verify_legal_field_signature(name, sig, CHECK_NULL); 1.605 1.606 u2 constantvalue_index = 0; 1.607 bool is_synthetic = false; 1.608 u2 generic_signature_index = 0; 1.609 bool is_static = access_flags.is_static(); 1.610 - FieldAnnotationCollector parsed_annotations; 1.611 + FieldAnnotationCollector parsed_annotations(_loader_data); 1.612 1.613 u2 attributes_count = cfs->get_u2_fast(); 1.614 if (attributes_count > 0) { 1.615 - parse_field_attributes(loader_data, 1.616 - cp, attributes_count, is_static, signature_index, 1.617 + parse_field_attributes(attributes_count, is_static, signature_index, 1.618 &constantvalue_index, &is_synthetic, 1.619 - &generic_signature_index, &field_annotations, 1.620 - &field_type_annotations, &parsed_annotations, 1.621 + &generic_signature_index, &parsed_annotations, 1.622 CHECK_NULL); 1.623 - if (field_annotations != NULL) { 1.624 - if (*fields_annotations == NULL) { 1.625 - *fields_annotations = MetadataFactory::new_array<AnnotationArray*>( 1.626 - loader_data, length, NULL, 1.627 + if (parsed_annotations.field_annotations() != NULL) { 1.628 + if (_fields_annotations == NULL) { 1.629 + _fields_annotations = MetadataFactory::new_array<AnnotationArray*>( 1.630 + _loader_data, length, NULL, 1.631 CHECK_NULL); 1.632 } 1.633 - (*fields_annotations)->at_put(n, field_annotations); 1.634 + _fields_annotations->at_put(n, parsed_annotations.field_annotations()); 1.635 + parsed_annotations.set_field_annotations(NULL); 1.636 } 1.637 - if (field_type_annotations != NULL) { 1.638 - if (*fields_type_annotations == NULL) { 1.639 - *fields_type_annotations = MetadataFactory::new_array<AnnotationArray*>( 1.640 - loader_data, length, NULL, 1.641 + if (parsed_annotations.field_type_annotations() != NULL) { 1.642 + if (_fields_type_annotations == NULL) { 1.643 + _fields_type_annotations = MetadataFactory::new_array<AnnotationArray*>( 1.644 + _loader_data, length, NULL, 1.645 CHECK_NULL); 1.646 } 1.647 - (*fields_type_annotations)->at_put(n, field_type_annotations); 1.648 + _fields_type_annotations->at_put(n, parsed_annotations.field_type_annotations()); 1.649 + parsed_annotations.set_field_type_annotations(NULL); 1.650 } 1.651 + 1.652 if (is_synthetic) { 1.653 access_flags.set_is_synthetic(); 1.654 } 1.655 @@ -1224,7 +1174,7 @@ 1.656 name_index, 1.657 signature_index, 1.658 constantvalue_index); 1.659 - BasicType type = cp->basic_type_for_signature_at(signature_index); 1.660 + BasicType type = _cp->basic_type_for_signature_at(signature_index); 1.661 1.662 // Remember how many oops we encountered and compute allocation type 1.663 FieldAllocationType atype = fac->update(is_static, type); 1.664 @@ -1245,8 +1195,8 @@ 1.665 bool duplicate = false; 1.666 for (int i = 0; i < length; i++) { 1.667 FieldInfo* f = FieldInfo::from_field_array(fa, i); 1.668 - if (name == cp->symbol_at(f->name_index()) && 1.669 - signature == cp->symbol_at(f->signature_index())) { 1.670 + if (name == _cp->symbol_at(f->name_index()) && 1.671 + signature == _cp->symbol_at(f->signature_index())) { 1.672 // Symbol is desclared in Java so skip this one 1.673 duplicate = true; 1.674 break; 1.675 @@ -1280,8 +1230,9 @@ 1.676 // fields array is trimed. Also unused slots that were reserved 1.677 // for generic signature indexes are discarded. 1.678 Array<u2>* fields = MetadataFactory::new_array<u2>( 1.679 - loader_data, index * FieldInfo::field_slots + num_generic_signature, 1.680 + _loader_data, index * FieldInfo::field_slots + num_generic_signature, 1.681 CHECK_NULL); 1.682 + _fields = fields; // save in case of error 1.683 { 1.684 int i = 0; 1.685 for (; i < index * FieldInfo::field_slots; i++) { 1.686 @@ -1303,7 +1254,7 @@ 1.687 bool dup = false; 1.688 { 1.689 debug_only(No_Safepoint_Verifier nsv;) 1.690 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 1.691 + for (AllFieldStream fs(fields, _cp); !fs.done(); fs.next()) { 1.692 Symbol* name = fs.name(); 1.693 Symbol* sig = fs.signature(); 1.694 // If no duplicates, add name/signature in hashtable names_and_sigs. 1.695 @@ -1330,10 +1281,8 @@ 1.696 } 1.697 1.698 1.699 -u2* ClassFileParser::parse_exception_table(ClassLoaderData* loader_data, 1.700 - u4 code_length, 1.701 +u2* ClassFileParser::parse_exception_table(u4 code_length, 1.702 u4 exception_table_length, 1.703 - constantPoolHandle cp, 1.704 TRAPS) { 1.705 ClassFileStream* cfs = stream(); 1.706 1.707 @@ -1354,8 +1303,7 @@ 1.708 "Illegal exception table handler in class file %s", 1.709 CHECK_NULL); 1.710 if (catch_type_index != 0) { 1.711 - guarantee_property(valid_cp_range(catch_type_index, cp->length()) && 1.712 - is_klass_reference(cp, catch_type_index), 1.713 + guarantee_property(valid_klass_reference_at(catch_type_index), 1.714 "Catch type in exception table has bad constant type in class file %s", CHECK_NULL); 1.715 } 1.716 } 1.717 @@ -1506,7 +1454,6 @@ 1.718 u2* ClassFileParser::parse_localvariable_table(u4 code_length, 1.719 u2 max_locals, 1.720 u4 code_attribute_length, 1.721 - constantPoolHandle cp, 1.722 u2* localvariable_table_length, 1.723 bool isLVTT, 1.724 TRAPS) { 1.725 @@ -1544,20 +1491,16 @@ 1.726 "Invalid length %u in %s in class file %s", 1.727 length, tbl_name, CHECK_NULL); 1.728 } 1.729 - int cp_size = cp->length(); 1.730 - guarantee_property( 1.731 - valid_cp_range(name_index, cp_size) && 1.732 - cp->tag_at(name_index).is_utf8(), 1.733 + int cp_size = _cp->length(); 1.734 + guarantee_property(valid_symbol_at(name_index), 1.735 "Name index %u in %s has bad constant type in class file %s", 1.736 name_index, tbl_name, CHECK_NULL); 1.737 - guarantee_property( 1.738 - valid_cp_range(descriptor_index, cp_size) && 1.739 - cp->tag_at(descriptor_index).is_utf8(), 1.740 + guarantee_property(valid_symbol_at(descriptor_index), 1.741 "Signature index %u in %s has bad constant type in class file %s", 1.742 descriptor_index, tbl_name, CHECK_NULL); 1.743 1.744 - Symbol* name = cp->symbol_at(name_index); 1.745 - Symbol* sig = cp->symbol_at(descriptor_index); 1.746 + Symbol* name = _cp->symbol_at(name_index); 1.747 + Symbol* sig = _cp->symbol_at(descriptor_index); 1.748 verify_legal_field_name(name, CHECK_NULL); 1.749 u2 extra_slot = 0; 1.750 if (!isLVTT) { 1.751 @@ -1579,7 +1522,7 @@ 1.752 1.753 1.754 void ClassFileParser::parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, 1.755 - u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS) { 1.756 + u1* u1_array, u2* u2_array, TRAPS) { 1.757 ClassFileStream* cfs = stream(); 1.758 u2 index = 0; // index in the array with long/double occupying two slots 1.759 u4 i1 = *u1_index; 1.760 @@ -1591,8 +1534,7 @@ 1.761 index++; 1.762 } else if (tag == ITEM_Object) { 1.763 u2 class_index = u2_array[i2++] = cfs->get_u2(CHECK); 1.764 - guarantee_property(valid_cp_range(class_index, cp->length()) && 1.765 - is_klass_reference(cp, class_index), 1.766 + guarantee_property(valid_klass_reference_at(class_index), 1.767 "Bad class index %u in StackMap in class file %s", 1.768 class_index, CHECK); 1.769 } else if (tag == ITEM_Uninitialized) { 1.770 @@ -1613,8 +1555,7 @@ 1.771 *u2_index = i2; 1.772 } 1.773 1.774 -Array<u1>* ClassFileParser::parse_stackmap_table( 1.775 - ClassLoaderData* loader_data, 1.776 +u1* ClassFileParser::parse_stackmap_table( 1.777 u4 code_attribute_length, TRAPS) { 1.778 if (code_attribute_length == 0) 1.779 return NULL; 1.780 @@ -1629,18 +1570,12 @@ 1.781 if (!_need_verify && !DumpSharedSpaces) { 1.782 return NULL; 1.783 } 1.784 - 1.785 - Array<u1>* stackmap_data = 1.786 - MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); 1.787 - 1.788 - memcpy((void*)stackmap_data->adr_at(0), 1.789 - (void*)stackmap_table_start, code_attribute_length); 1.790 - return stackmap_data; 1.791 + return stackmap_table_start; 1.792 } 1.793 1.794 u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length, 1.795 u4 method_attribute_length, 1.796 - constantPoolHandle cp, TRAPS) { 1.797 + TRAPS) { 1.798 ClassFileStream* cfs = stream(); 1.799 cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length 1.800 *checked_exceptions_length = cfs->get_u2_fast(); 1.801 @@ -1657,8 +1592,7 @@ 1.802 for (int i = 0; i < len; i++) { 1.803 checked_exception = cfs->get_u2_fast(); 1.804 check_property( 1.805 - valid_cp_range(checked_exception, cp->length()) && 1.806 - is_klass_reference(cp, checked_exception), 1.807 + valid_klass_reference_at(checked_exception), 1.808 "Exception name has bad type at constant pool %u in class file %s", 1.809 checked_exception, CHECK_NULL); 1.810 } 1.811 @@ -1735,9 +1669,7 @@ 1.812 } 1.813 1.814 // Sift through annotations, looking for those significant to the VM: 1.815 -void ClassFileParser::parse_annotations(ClassLoaderData* loader_data, 1.816 - u1* buffer, int limit, 1.817 - constantPoolHandle cp, 1.818 +void ClassFileParser::parse_annotations(u1* buffer, int limit, 1.819 ClassFileParser::AnnotationCollector* coll, 1.820 TRAPS) { 1.821 // annotations := do(nann:u2) {annotation} 1.822 @@ -1767,17 +1699,17 @@ 1.823 u1* abase = buffer + index0; 1.824 int atype = Bytes::get_Java_u2(abase + atype_off); 1.825 int count = Bytes::get_Java_u2(abase + count_off); 1.826 - Symbol* aname = check_symbol_at(cp, atype); 1.827 + Symbol* aname = check_symbol_at(_cp, atype); 1.828 if (aname == NULL) break; // invalid annotation name 1.829 Symbol* member = NULL; 1.830 if (count >= 1) { 1.831 int member_index = Bytes::get_Java_u2(abase + member_off); 1.832 - member = check_symbol_at(cp, member_index); 1.833 + member = check_symbol_at(_cp, member_index); 1.834 if (member == NULL) break; // invalid member name 1.835 } 1.836 1.837 // Here is where parsing particular annotations will take place. 1.838 - AnnotationCollector::ID id = coll->annotation_index(loader_data, aname); 1.839 + AnnotationCollector::ID id = coll->annotation_index(_loader_data, aname); 1.840 if (id == AnnotationCollector::_unknown) continue; 1.841 coll->set_annotation(id); 1.842 1.843 @@ -1836,6 +1768,12 @@ 1.844 f->set_contended_group(contended_group()); 1.845 } 1.846 1.847 +ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() { 1.848 + // If there's an error deallocate metadata for field annotations 1.849 + MetadataFactory::free_array<u1>(_loader_data, _field_annotations); 1.850 + MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations); 1.851 +} 1.852 + 1.853 void ClassFileParser::MethodAnnotationCollector::apply_to(methodHandle m) { 1.854 if (has_annotation(_method_ForceInline)) 1.855 m->set_force_inline(true); 1.856 @@ -1894,10 +1832,9 @@ 1.857 && _need_verify 1.858 && _major_version >= JAVA_1_5_VERSION) { 1.859 clear_hashtable(lvt_Hash); 1.860 - ConstantPool* cp = cm->constants(); 1.861 classfile_parse_error("Duplicated LocalVariableTable attribute " 1.862 "entry for '%s' in class file %s", 1.863 - cp->symbol_at(lvt->name_cp_index)->as_utf8(), 1.864 + _cp->symbol_at(lvt->name_cp_index)->as_utf8(), 1.865 CHECK); 1.866 } 1.867 } 1.868 @@ -1916,18 +1853,16 @@ 1.869 if (entry == NULL) { 1.870 if (_need_verify) { 1.871 clear_hashtable(lvt_Hash); 1.872 - ConstantPool* cp = cm->constants(); 1.873 classfile_parse_error("LVTT entry for '%s' in class file %s " 1.874 "does not match any LVT entry", 1.875 - cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 1.876 + _cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 1.877 CHECK); 1.878 } 1.879 } else if (entry->_elem->signature_cp_index != 0 && _need_verify) { 1.880 clear_hashtable(lvt_Hash); 1.881 - ConstantPool* cp = cm->constants(); 1.882 classfile_parse_error("Duplicated LocalVariableTypeTable attribute " 1.883 "entry for '%s' in class file %s", 1.884 - cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 1.885 + _cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), 1.886 CHECK); 1.887 } else { 1.888 // to add generic signatures into LocalVariableTable 1.889 @@ -1939,8 +1874,7 @@ 1.890 } 1.891 1.892 1.893 -void ClassFileParser::copy_method_annotations(ClassLoaderData* loader_data, 1.894 - ConstMethod* cm, 1.895 +void ClassFileParser::copy_method_annotations(ConstMethod* cm, 1.896 u1* runtime_visible_annotations, 1.897 int runtime_visible_annotations_length, 1.898 u1* runtime_invisible_annotations, 1.899 @@ -1961,8 +1895,7 @@ 1.900 1.901 if (runtime_visible_annotations_length + 1.902 runtime_invisible_annotations_length > 0) { 1.903 - a = assemble_annotations(loader_data, 1.904 - runtime_visible_annotations, 1.905 + a = assemble_annotations(runtime_visible_annotations, 1.906 runtime_visible_annotations_length, 1.907 runtime_invisible_annotations, 1.908 runtime_invisible_annotations_length, 1.909 @@ -1972,8 +1905,7 @@ 1.910 1.911 if (runtime_visible_parameter_annotations_length + 1.912 runtime_invisible_parameter_annotations_length > 0) { 1.913 - a = assemble_annotations(loader_data, 1.914 - runtime_visible_parameter_annotations, 1.915 + a = assemble_annotations(runtime_visible_parameter_annotations, 1.916 runtime_visible_parameter_annotations_length, 1.917 runtime_invisible_parameter_annotations, 1.918 runtime_invisible_parameter_annotations_length, 1.919 @@ -1982,8 +1914,7 @@ 1.920 } 1.921 1.922 if (annotation_default_length > 0) { 1.923 - a = assemble_annotations(loader_data, 1.924 - annotation_default, 1.925 + a = assemble_annotations(annotation_default, 1.926 annotation_default_length, 1.927 NULL, 1.928 0, 1.929 @@ -1993,8 +1924,7 @@ 1.930 1.931 if (runtime_visible_type_annotations_length + 1.932 runtime_invisible_type_annotations_length > 0) { 1.933 - a = assemble_annotations(loader_data, 1.934 - runtime_visible_type_annotations, 1.935 + a = assemble_annotations(runtime_visible_type_annotations, 1.936 runtime_visible_type_annotations_length, 1.937 runtime_invisible_type_annotations, 1.938 runtime_invisible_type_annotations_length, 1.939 @@ -2013,9 +1943,7 @@ 1.940 // from the method back up to the containing klass. These flag values 1.941 // are added to klass's access_flags. 1.942 1.943 -methodHandle ClassFileParser::parse_method(ClassLoaderData* loader_data, 1.944 - constantPoolHandle cp, 1.945 - bool is_interface, 1.946 +methodHandle ClassFileParser::parse_method(bool is_interface, 1.947 AccessFlags *promoted_flags, 1.948 TRAPS) { 1.949 ClassFileStream* cfs = stream(); 1.950 @@ -2026,22 +1954,20 @@ 1.951 1.952 int flags = cfs->get_u2_fast(); 1.953 u2 name_index = cfs->get_u2_fast(); 1.954 - int cp_size = cp->length(); 1.955 + int cp_size = _cp->length(); 1.956 check_property( 1.957 - valid_cp_range(name_index, cp_size) && 1.958 - cp->tag_at(name_index).is_utf8(), 1.959 + valid_symbol_at(name_index), 1.960 "Illegal constant pool index %u for method name in class file %s", 1.961 name_index, CHECK_(nullHandle)); 1.962 - Symbol* name = cp->symbol_at(name_index); 1.963 + Symbol* name = _cp->symbol_at(name_index); 1.964 verify_legal_method_name(name, CHECK_(nullHandle)); 1.965 1.966 u2 signature_index = cfs->get_u2_fast(); 1.967 guarantee_property( 1.968 - valid_cp_range(signature_index, cp_size) && 1.969 - cp->tag_at(signature_index).is_utf8(), 1.970 + valid_symbol_at(signature_index), 1.971 "Illegal constant pool index %u for method signature in class file %s", 1.972 signature_index, CHECK_(nullHandle)); 1.973 - Symbol* signature = cp->symbol_at(signature_index); 1.974 + Symbol* signature = _cp->symbol_at(signature_index); 1.975 1.976 AccessFlags access_flags; 1.977 if (name == vmSymbols::class_initializer_name()) { 1.978 @@ -2097,7 +2023,8 @@ 1.979 bool parsed_checked_exceptions_attribute = false; 1.980 bool parsed_stackmap_attribute = false; 1.981 // stackmap attribute - JDK1.5 1.982 - Array<u1>* stackmap_data = NULL; 1.983 + u1* stackmap_data = NULL; 1.984 + int stackmap_data_length = 0; 1.985 u2 generic_signature_index = 0; 1.986 MethodAnnotationCollector parsed_annotations; 1.987 u1* runtime_visible_annotations = NULL; 1.988 @@ -2122,12 +2049,11 @@ 1.989 u2 method_attribute_name_index = cfs->get_u2_fast(); 1.990 u4 method_attribute_length = cfs->get_u4_fast(); 1.991 check_property( 1.992 - valid_cp_range(method_attribute_name_index, cp_size) && 1.993 - cp->tag_at(method_attribute_name_index).is_utf8(), 1.994 + valid_symbol_at(method_attribute_name_index), 1.995 "Invalid method attribute name index %u in class file %s", 1.996 method_attribute_name_index, CHECK_(nullHandle)); 1.997 1.998 - Symbol* method_attribute_name = cp->symbol_at(method_attribute_name_index); 1.999 + Symbol* method_attribute_name = _cp->symbol_at(method_attribute_name_index); 1.1000 if (method_attribute_name == vmSymbols::tag_code()) { 1.1001 // Parse Code attribute 1.1002 if (_need_verify) { 1.1003 @@ -2171,7 +2097,7 @@ 1.1004 exception_table_length = cfs->get_u2_fast(); 1.1005 if (exception_table_length > 0) { 1.1006 exception_table_start = 1.1007 - parse_exception_table(loader_data, code_length, exception_table_length, cp, CHECK_(nullHandle)); 1.1008 + parse_exception_table(code_length, exception_table_length, CHECK_(nullHandle)); 1.1009 } 1.1010 1.1011 // Parse additional attributes in code attribute 1.1012 @@ -2204,19 +2130,18 @@ 1.1013 calculated_attribute_length += code_attribute_length + 1.1014 sizeof(code_attribute_name_index) + 1.1015 sizeof(code_attribute_length); 1.1016 - check_property(valid_cp_range(code_attribute_name_index, cp_size) && 1.1017 - cp->tag_at(code_attribute_name_index).is_utf8(), 1.1018 + check_property(valid_symbol_at(code_attribute_name_index), 1.1019 "Invalid code attribute name index %u in class file %s", 1.1020 code_attribute_name_index, 1.1021 CHECK_(nullHandle)); 1.1022 if (LoadLineNumberTables && 1.1023 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) { 1.1024 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) { 1.1025 // Parse and compress line number table 1.1026 parse_linenumber_table(code_attribute_length, code_length, 1.1027 &linenumber_table, CHECK_(nullHandle)); 1.1028 1.1029 } else if (LoadLocalVariableTables && 1.1030 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) { 1.1031 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) { 1.1032 // Parse local variable table 1.1033 if (!lvt_allocated) { 1.1034 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( 1.1035 @@ -2238,7 +2163,6 @@ 1.1036 parse_localvariable_table(code_length, 1.1037 max_locals, 1.1038 code_attribute_length, 1.1039 - cp, 1.1040 &localvariable_table_length[lvt_cnt], 1.1041 false, // is not LVTT 1.1042 CHECK_(nullHandle)); 1.1043 @@ -2246,7 +2170,7 @@ 1.1044 lvt_cnt++; 1.1045 } else if (LoadLocalVariableTypeTables && 1.1046 _major_version >= JAVA_1_5_VERSION && 1.1047 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) { 1.1048 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) { 1.1049 if (!lvt_allocated) { 1.1050 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( 1.1051 THREAD, u2, INITIAL_MAX_LVT_NUMBER); 1.1052 @@ -2268,19 +2192,19 @@ 1.1053 parse_localvariable_table(code_length, 1.1054 max_locals, 1.1055 code_attribute_length, 1.1056 - cp, 1.1057 &localvariable_type_table_length[lvtt_cnt], 1.1058 true, // is LVTT 1.1059 CHECK_(nullHandle)); 1.1060 lvtt_cnt++; 1.1061 } else if (UseSplitVerifier && 1.1062 _major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION && 1.1063 - cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { 1.1064 + _cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { 1.1065 // Stack map is only needed by the new verifier in JDK1.5. 1.1066 if (parsed_stackmap_attribute) { 1.1067 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle)); 1.1068 } 1.1069 - stackmap_data = parse_stackmap_table(loader_data, code_attribute_length, CHECK_(nullHandle)); 1.1070 + stackmap_data = parse_stackmap_table(code_attribute_length, CHECK_(nullHandle)); 1.1071 + stackmap_data_length = code_attribute_length; 1.1072 parsed_stackmap_attribute = true; 1.1073 } else { 1.1074 // Skip unknown attributes 1.1075 @@ -2301,7 +2225,7 @@ 1.1076 checked_exceptions_start = 1.1077 parse_checked_exceptions(&checked_exceptions_length, 1.1078 method_attribute_length, 1.1079 - cp, CHECK_(nullHandle)); 1.1080 + CHECK_(nullHandle)); 1.1081 } else if (method_attribute_name == vmSymbols::tag_method_parameters()) { 1.1082 // reject multiple method parameters 1.1083 if (method_parameters_seen) { 1.1084 @@ -2359,9 +2283,8 @@ 1.1085 runtime_visible_annotations_length = method_attribute_length; 1.1086 runtime_visible_annotations = cfs->get_u1_buffer(); 1.1087 assert(runtime_visible_annotations != NULL, "null visible annotations"); 1.1088 - parse_annotations(loader_data, 1.1089 - runtime_visible_annotations, 1.1090 - runtime_visible_annotations_length, cp, &parsed_annotations, 1.1091 + parse_annotations(runtime_visible_annotations, 1.1092 + runtime_visible_annotations_length, &parsed_annotations, 1.1093 CHECK_(nullHandle)); 1.1094 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle)); 1.1095 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { 1.1096 @@ -2434,18 +2357,18 @@ 1.1097 0); 1.1098 1.1099 Method* m = Method::allocate( 1.1100 - loader_data, code_length, access_flags, &sizes, 1.1101 + _loader_data, code_length, access_flags, &sizes, 1.1102 ConstMethod::NORMAL, CHECK_(nullHandle)); 1.1103 1.1104 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); 1.1105 1.1106 // Fill in information from fixed part (access_flags already set) 1.1107 - m->set_constants(cp()); 1.1108 + m->set_constants(_cp); 1.1109 m->set_name_index(name_index); 1.1110 m->set_signature_index(signature_index); 1.1111 #ifdef CC_INTERP 1.1112 // hmm is there a gc issue here?? 1.1113 - ResultTypeFinder rtf(cp->symbol_at(signature_index)); 1.1114 + ResultTypeFinder rtf(_cp->symbol_at(signature_index)); 1.1115 m->set_result_index(rtf.type()); 1.1116 #endif 1.1117 1.1118 @@ -2464,7 +2387,10 @@ 1.1119 // Fill in code attribute information 1.1120 m->set_max_stack(max_stack); 1.1121 m->set_max_locals(max_locals); 1.1122 - m->constMethod()->set_stackmap_data(stackmap_data); 1.1123 + if (stackmap_data != NULL) { 1.1124 + m->constMethod()->copy_stackmap_data(_loader_data, stackmap_data, 1.1125 + stackmap_data_length, CHECK_NULL); 1.1126 + } 1.1127 1.1128 // Copy byte codes 1.1129 m->set_code(code_start); 1.1130 @@ -2520,7 +2446,7 @@ 1.1131 parsed_annotations.apply_to(m); 1.1132 1.1133 // Copy annotations 1.1134 - copy_method_annotations(loader_data, m->constMethod(), 1.1135 + copy_method_annotations(m->constMethod(), 1.1136 runtime_visible_annotations, 1.1137 runtime_visible_annotations_length, 1.1138 runtime_invisible_annotations, 1.1139 @@ -2560,9 +2486,7 @@ 1.1140 // from the methods back up to the containing klass. These flag values 1.1141 // are added to klass's access_flags. 1.1142 1.1143 -Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data, 1.1144 - constantPoolHandle cp, 1.1145 - bool is_interface, 1.1146 +Array<Method*>* ClassFileParser::parse_methods(bool is_interface, 1.1147 AccessFlags* promoted_flags, 1.1148 bool* has_final_method, 1.1149 bool* has_default_methods, 1.1150 @@ -2571,15 +2495,13 @@ 1.1151 cfs->guarantee_more(2, CHECK_NULL); // length 1.1152 u2 length = cfs->get_u2_fast(); 1.1153 if (length == 0) { 1.1154 - return Universe::the_empty_method_array(); 1.1155 + _methods = Universe::the_empty_method_array(); 1.1156 } else { 1.1157 - // FIXME: Handle leaks at later failures. 1.1158 - Array<Method*>* methods = MetadataFactory::new_array<Method*>(loader_data, length, NULL, CHECK_NULL); 1.1159 + _methods = MetadataFactory::new_array<Method*>(_loader_data, length, NULL, CHECK_NULL); 1.1160 1.1161 HandleMark hm(THREAD); 1.1162 for (int index = 0; index < length; index++) { 1.1163 - methodHandle method = parse_method(loader_data, 1.1164 - cp, is_interface, 1.1165 + methodHandle method = parse_method(is_interface, 1.1166 promoted_flags, 1.1167 CHECK_NULL); 1.1168 1.1169 @@ -2590,7 +2512,7 @@ 1.1170 // default method 1.1171 *has_default_methods = true; 1.1172 } 1.1173 - methods->at_put(index, method()); 1.1174 + _methods->at_put(index, method()); 1.1175 } 1.1176 1.1177 if (_need_verify && length > 1) { 1.1178 @@ -2603,7 +2525,7 @@ 1.1179 { 1.1180 debug_only(No_Safepoint_Verifier nsv;) 1.1181 for (int i = 0; i < length; i++) { 1.1182 - Method* m = methods->at(i); 1.1183 + Method* m = _methods->at(i); 1.1184 // If no duplicates, add name/signature in hashtable names_and_sigs. 1.1185 if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) { 1.1186 dup = true; 1.1187 @@ -2616,14 +2538,12 @@ 1.1188 CHECK_NULL); 1.1189 } 1.1190 } 1.1191 - return methods; 1.1192 } 1.1193 + return _methods; 1.1194 } 1.1195 1.1196 1.1197 -Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, 1.1198 - Array<Method*>* methods, 1.1199 - TRAPS) { 1.1200 +intArray* ClassFileParser::sort_methods(Array<Method*>* methods) { 1.1201 int length = methods->length(); 1.1202 // If JVMTI original method ordering or sharing is enabled we have to 1.1203 // remember the original class file ordering. 1.1204 @@ -2641,10 +2561,11 @@ 1.1205 // Note that the ordering is not alphabetical, see Symbol::fast_compare 1.1206 Method::sort_methods(methods); 1.1207 1.1208 + intArray* method_ordering = NULL; 1.1209 // If JVMTI original method ordering or sharing is enabled construct int 1.1210 // array remembering the original ordering 1.1211 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { 1.1212 - Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); 1.1213 + method_ordering = new intArray(length); 1.1214 for (int index = 0; index < length; index++) { 1.1215 Method* m = methods->at(index); 1.1216 int old_index = m->vtable_index(); 1.1217 @@ -2652,29 +2573,25 @@ 1.1218 method_ordering->at_put(index, old_index); 1.1219 m->set_vtable_index(Method::invalid_vtable_index); 1.1220 } 1.1221 - return method_ordering; 1.1222 - } else { 1.1223 - return Universe::the_empty_int_array(); 1.1224 } 1.1225 + return method_ordering; 1.1226 } 1.1227 1.1228 1.1229 -void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS) { 1.1230 +void ClassFileParser::parse_classfile_sourcefile_attribute(TRAPS) { 1.1231 ClassFileStream* cfs = stream(); 1.1232 cfs->guarantee_more(2, CHECK); // sourcefile_index 1.1233 u2 sourcefile_index = cfs->get_u2_fast(); 1.1234 check_property( 1.1235 - valid_cp_range(sourcefile_index, cp->length()) && 1.1236 - cp->tag_at(sourcefile_index).is_utf8(), 1.1237 + valid_symbol_at(sourcefile_index), 1.1238 "Invalid SourceFile attribute at constant pool index %u in class file %s", 1.1239 sourcefile_index, CHECK); 1.1240 - set_class_sourcefile(cp->symbol_at(sourcefile_index)); 1.1241 + set_class_sourcefile(_cp->symbol_at(sourcefile_index)); 1.1242 } 1.1243 1.1244 1.1245 1.1246 -void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, 1.1247 - int length, TRAPS) { 1.1248 +void ClassFileParser::parse_classfile_source_debug_extension_attribute(int length, TRAPS) { 1.1249 ClassFileStream* cfs = stream(); 1.1250 u1* sde_buffer = cfs->get_u1_buffer(); 1.1251 assert(sde_buffer != NULL, "null sde buffer"); 1.1252 @@ -2698,12 +2615,10 @@ 1.1253 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC) 1.1254 1.1255 // Return number of classes in the inner classes attribute table 1.1256 -u2 ClassFileParser::parse_classfile_inner_classes_attribute(ClassLoaderData* loader_data, 1.1257 - u1* inner_classes_attribute_start, 1.1258 +u2 ClassFileParser::parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, 1.1259 bool parsed_enclosingmethod_attribute, 1.1260 u2 enclosing_method_class_index, 1.1261 u2 enclosing_method_method_index, 1.1262 - constantPoolHandle cp, 1.1263 TRAPS) { 1.1264 ClassFileStream* cfs = stream(); 1.1265 u1* current_mark = cfs->current(); 1.1266 @@ -2724,33 +2639,31 @@ 1.1267 // enclosing_method_class_index, 1.1268 // enclosing_method_method_index] 1.1269 int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0); 1.1270 - // FIXME: Will leak on exceptions. 1.1271 - Array<u2>* inner_classes = MetadataFactory::new_array<u2>(loader_data, size, CHECK_0); 1.1272 + Array<u2>* inner_classes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0); 1.1273 + _inner_classes = inner_classes; 1.1274 + 1.1275 int index = 0; 1.1276 - int cp_size = cp->length(); 1.1277 + int cp_size = _cp->length(); 1.1278 cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2 1.1279 for (int n = 0; n < length; n++) { 1.1280 // Inner class index 1.1281 u2 inner_class_info_index = cfs->get_u2_fast(); 1.1282 check_property( 1.1283 inner_class_info_index == 0 || 1.1284 - (valid_cp_range(inner_class_info_index, cp_size) && 1.1285 - is_klass_reference(cp, inner_class_info_index)), 1.1286 + valid_klass_reference_at(inner_class_info_index), 1.1287 "inner_class_info_index %u has bad constant type in class file %s", 1.1288 inner_class_info_index, CHECK_0); 1.1289 // Outer class index 1.1290 u2 outer_class_info_index = cfs->get_u2_fast(); 1.1291 check_property( 1.1292 outer_class_info_index == 0 || 1.1293 - (valid_cp_range(outer_class_info_index, cp_size) && 1.1294 - is_klass_reference(cp, outer_class_info_index)), 1.1295 + valid_klass_reference_at(outer_class_info_index), 1.1296 "outer_class_info_index %u has bad constant type in class file %s", 1.1297 outer_class_info_index, CHECK_0); 1.1298 // Inner class name 1.1299 u2 inner_name_index = cfs->get_u2_fast(); 1.1300 check_property( 1.1301 - inner_name_index == 0 || (valid_cp_range(inner_name_index, cp_size) && 1.1302 - cp->tag_at(inner_name_index).is_utf8()), 1.1303 + inner_name_index == 0 || valid_symbol_at(inner_name_index), 1.1304 "inner_name_index %u has bad constant type in class file %s", 1.1305 inner_name_index, CHECK_0); 1.1306 if (_need_verify) { 1.1307 @@ -2794,33 +2707,27 @@ 1.1308 } 1.1309 assert(index == size, "wrong size"); 1.1310 1.1311 - // Update InstanceKlass with inner class info. 1.1312 - set_class_inner_classes(inner_classes); 1.1313 - 1.1314 // Restore buffer's current position. 1.1315 cfs->set_current(current_mark); 1.1316 1.1317 return length; 1.1318 } 1.1319 1.1320 -void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS) { 1.1321 +void ClassFileParser::parse_classfile_synthetic_attribute(TRAPS) { 1.1322 set_class_synthetic_flag(true); 1.1323 } 1.1324 1.1325 -void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS) { 1.1326 +void ClassFileParser::parse_classfile_signature_attribute(TRAPS) { 1.1327 ClassFileStream* cfs = stream(); 1.1328 u2 signature_index = cfs->get_u2(CHECK); 1.1329 check_property( 1.1330 - valid_cp_range(signature_index, cp->length()) && 1.1331 - cp->tag_at(signature_index).is_utf8(), 1.1332 + valid_symbol_at(signature_index), 1.1333 "Invalid constant pool index %u in Signature attribute in class file %s", 1.1334 signature_index, CHECK); 1.1335 - set_class_generic_signature(cp->symbol_at(signature_index)); 1.1336 + set_class_generic_signature(_cp->symbol_at(signature_index)); 1.1337 } 1.1338 1.1339 -void ClassFileParser::parse_classfile_bootstrap_methods_attribute(ClassLoaderData* loader_data, 1.1340 - constantPoolHandle cp, 1.1341 - u4 attribute_byte_length, TRAPS) { 1.1342 +void ClassFileParser::parse_classfile_bootstrap_methods_attribute(u4 attribute_byte_length, TRAPS) { 1.1343 ClassFileStream* cfs = stream(); 1.1344 u1* current_start = cfs->current(); 1.1345 1.1346 @@ -2841,10 +2748,14 @@ 1.1347 // The array begins with a series of short[2] pairs, one for each tuple. 1.1348 int index_size = (attribute_array_length * 2); 1.1349 1.1350 - Array<u2>* operands = MetadataFactory::new_array<u2>(loader_data, index_size + operand_count, CHECK); 1.1351 + Array<u2>* operands = MetadataFactory::new_array<u2>(_loader_data, index_size + operand_count, CHECK); 1.1352 + 1.1353 + // Eagerly assign operands so they will be deallocated with the constant 1.1354 + // pool if there is an error. 1.1355 + _cp->set_operands(operands); 1.1356 1.1357 int operand_fill_index = index_size; 1.1358 - int cp_size = cp->length(); 1.1359 + int cp_size = _cp->length(); 1.1360 1.1361 for (int n = 0; n < attribute_array_length; n++) { 1.1362 // Store a 32-bit offset into the header of the operand array. 1.1363 @@ -2856,7 +2767,7 @@ 1.1364 u2 argument_count = cfs->get_u2_fast(); 1.1365 check_property( 1.1366 valid_cp_range(bootstrap_method_index, cp_size) && 1.1367 - cp->tag_at(bootstrap_method_index).is_method_handle(), 1.1368 + _cp->tag_at(bootstrap_method_index).is_method_handle(), 1.1369 "bootstrap_method_index %u has bad constant type in class file %s", 1.1370 bootstrap_method_index, 1.1371 CHECK); 1.1372 @@ -2868,7 +2779,7 @@ 1.1373 u2 argument_index = cfs->get_u2_fast(); 1.1374 check_property( 1.1375 valid_cp_range(argument_index, cp_size) && 1.1376 - cp->tag_at(argument_index).is_loadable_constant(), 1.1377 + _cp->tag_at(argument_index).is_loadable_constant(), 1.1378 "argument_index %u has bad constant type in class file %s", 1.1379 argument_index, 1.1380 CHECK); 1.1381 @@ -2883,17 +2794,13 @@ 1.1382 guarantee_property(current_end == current_start + attribute_byte_length, 1.1383 "Bad length on BootstrapMethods in class file %s", 1.1384 CHECK); 1.1385 - 1.1386 - cp->set_operands(operands); 1.1387 } 1.1388 1.1389 -void ClassFileParser::parse_classfile_attributes(ClassLoaderData* loader_data, 1.1390 - constantPoolHandle cp, 1.1391 - ClassFileParser::ClassAnnotationCollector* parsed_annotations, 1.1392 +void ClassFileParser::parse_classfile_attributes(ClassFileParser::ClassAnnotationCollector* parsed_annotations, 1.1393 TRAPS) { 1.1394 ClassFileStream* cfs = stream(); 1.1395 // Set inner classes attribute to default sentinel 1.1396 - set_class_inner_classes(Universe::the_empty_short_array()); 1.1397 + _inner_classes = Universe::the_empty_short_array(); 1.1398 cfs->guarantee_more(2, CHECK); // attributes_count 1.1399 u2 attributes_count = cfs->get_u2_fast(); 1.1400 bool parsed_sourcefile_attribute = false; 1.1401 @@ -2918,11 +2825,10 @@ 1.1402 u2 attribute_name_index = cfs->get_u2_fast(); 1.1403 u4 attribute_length = cfs->get_u4_fast(); 1.1404 check_property( 1.1405 - valid_cp_range(attribute_name_index, cp->length()) && 1.1406 - cp->tag_at(attribute_name_index).is_utf8(), 1.1407 + valid_symbol_at(attribute_name_index), 1.1408 "Attribute name has bad constant pool index %u in class file %s", 1.1409 attribute_name_index, CHECK); 1.1410 - Symbol* tag = cp->symbol_at(attribute_name_index); 1.1411 + Symbol* tag = _cp->symbol_at(attribute_name_index); 1.1412 if (tag == vmSymbols::tag_source_file()) { 1.1413 // Check for SourceFile tag 1.1414 if (_need_verify) { 1.1415 @@ -2933,10 +2839,10 @@ 1.1416 } else { 1.1417 parsed_sourcefile_attribute = true; 1.1418 } 1.1419 - parse_classfile_sourcefile_attribute(cp, CHECK); 1.1420 + parse_classfile_sourcefile_attribute(CHECK); 1.1421 } else if (tag == vmSymbols::tag_source_debug_extension()) { 1.1422 // Check for SourceDebugExtension tag 1.1423 - parse_classfile_source_debug_extension_attribute(cp, (int)attribute_length, CHECK); 1.1424 + parse_classfile_source_debug_extension_attribute((int)attribute_length, CHECK); 1.1425 } else if (tag == vmSymbols::tag_inner_classes()) { 1.1426 // Check for InnerClasses tag 1.1427 if (parsed_innerclasses_attribute) { 1.1428 @@ -2955,7 +2861,7 @@ 1.1429 "Invalid Synthetic classfile attribute length %u in class file %s", 1.1430 attribute_length, CHECK); 1.1431 } 1.1432 - parse_classfile_synthetic_attribute(cp, CHECK); 1.1433 + parse_classfile_synthetic_attribute(CHECK); 1.1434 } else if (tag == vmSymbols::tag_deprecated()) { 1.1435 // Check for Deprecatd tag - 4276120 1.1436 if (attribute_length != 0) { 1.1437 @@ -2970,15 +2876,13 @@ 1.1438 "Wrong Signature attribute length %u in class file %s", 1.1439 attribute_length, CHECK); 1.1440 } 1.1441 - parse_classfile_signature_attribute(cp, CHECK); 1.1442 + parse_classfile_signature_attribute(CHECK); 1.1443 } else if (tag == vmSymbols::tag_runtime_visible_annotations()) { 1.1444 runtime_visible_annotations_length = attribute_length; 1.1445 runtime_visible_annotations = cfs->get_u1_buffer(); 1.1446 assert(runtime_visible_annotations != NULL, "null visible annotations"); 1.1447 - parse_annotations(loader_data, 1.1448 - runtime_visible_annotations, 1.1449 + parse_annotations(runtime_visible_annotations, 1.1450 runtime_visible_annotations_length, 1.1451 - cp, 1.1452 parsed_annotations, 1.1453 CHECK); 1.1454 cfs->skip_u1(runtime_visible_annotations_length, CHECK); 1.1455 @@ -3000,13 +2904,11 @@ 1.1456 classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK); 1.1457 } 1.1458 // Validate the constant pool indices and types 1.1459 - if (!cp->is_within_bounds(enclosing_method_class_index) || 1.1460 - !is_klass_reference(cp, enclosing_method_class_index)) { 1.1461 - classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK); 1.1462 - } 1.1463 + check_property(valid_klass_reference_at(enclosing_method_class_index), 1.1464 + "Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK); 1.1465 if (enclosing_method_method_index != 0 && 1.1466 - (!cp->is_within_bounds(enclosing_method_method_index) || 1.1467 - !cp->tag_at(enclosing_method_method_index).is_name_and_type())) { 1.1468 + (!_cp->is_within_bounds(enclosing_method_method_index) || 1.1469 + !_cp->tag_at(enclosing_method_method_index).is_name_and_type())) { 1.1470 classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK); 1.1471 } 1.1472 } else if (tag == vmSymbols::tag_bootstrap_methods() && 1.1473 @@ -3014,7 +2916,7 @@ 1.1474 if (parsed_bootstrap_methods_attribute) 1.1475 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); 1.1476 parsed_bootstrap_methods_attribute = true; 1.1477 - parse_classfile_bootstrap_methods_attribute(loader_data, cp, attribute_length, CHECK); 1.1478 + parse_classfile_bootstrap_methods_attribute(attribute_length, CHECK); 1.1479 } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { 1.1480 runtime_visible_type_annotations_length = attribute_length; 1.1481 runtime_visible_type_annotations = cfs->get_u1_buffer(); 1.1482 @@ -3035,29 +2937,24 @@ 1.1483 cfs->skip_u1(attribute_length, CHECK); 1.1484 } 1.1485 } 1.1486 - AnnotationArray* annotations = assemble_annotations(loader_data, 1.1487 - runtime_visible_annotations, 1.1488 - runtime_visible_annotations_length, 1.1489 - runtime_invisible_annotations, 1.1490 - runtime_invisible_annotations_length, 1.1491 - CHECK); 1.1492 - set_class_annotations(annotations); 1.1493 - AnnotationArray* type_annotations = assemble_annotations(loader_data, 1.1494 - runtime_visible_type_annotations, 1.1495 - runtime_visible_type_annotations_length, 1.1496 - runtime_invisible_type_annotations, 1.1497 - runtime_invisible_type_annotations_length, 1.1498 - CHECK); 1.1499 - set_class_type_annotations(type_annotations); 1.1500 + _annotations = assemble_annotations(runtime_visible_annotations, 1.1501 + runtime_visible_annotations_length, 1.1502 + runtime_invisible_annotations, 1.1503 + runtime_invisible_annotations_length, 1.1504 + CHECK); 1.1505 + _type_annotations = assemble_annotations(runtime_visible_type_annotations, 1.1506 + runtime_visible_type_annotations_length, 1.1507 + runtime_invisible_type_annotations, 1.1508 + runtime_invisible_type_annotations_length, 1.1509 + CHECK); 1.1510 1.1511 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { 1.1512 u2 num_of_classes = parse_classfile_inner_classes_attribute( 1.1513 - loader_data, 1.1514 inner_classes_attribute_start, 1.1515 parsed_innerclasses_attribute, 1.1516 enclosing_method_class_index, 1.1517 enclosing_method_method_index, 1.1518 - cp, CHECK); 1.1519 + CHECK); 1.1520 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) { 1.1521 guarantee_property( 1.1522 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes, 1.1523 @@ -3085,18 +2982,43 @@ 1.1524 if (_sde_buffer != NULL) { 1.1525 k->set_source_debug_extension(_sde_buffer, _sde_length); 1.1526 } 1.1527 - k->set_inner_classes(_inner_classes); 1.1528 } 1.1529 1.1530 -AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data, 1.1531 - u1* runtime_visible_annotations, 1.1532 +// Transfer ownership of metadata allocated to the InstanceKlass. 1.1533 +void ClassFileParser::apply_parsed_class_metadata( 1.1534 + instanceKlassHandle this_klass, 1.1535 + int java_fields_count, TRAPS) { 1.1536 + // Assign annotations if needed 1.1537 + if (_annotations != NULL || _type_annotations != NULL || 1.1538 + _fields_annotations != NULL || _fields_type_annotations != NULL) { 1.1539 + Annotations* annotations = Annotations::allocate(_loader_data, CHECK); 1.1540 + annotations->set_class_annotations(_annotations); 1.1541 + annotations->set_class_type_annotations(_type_annotations); 1.1542 + annotations->set_fields_annotations(_fields_annotations); 1.1543 + annotations->set_fields_type_annotations(_fields_type_annotations); 1.1544 + this_klass->set_annotations(annotations); 1.1545 + } 1.1546 + 1.1547 + _cp->set_pool_holder(this_klass()); 1.1548 + this_klass->set_constants(_cp); 1.1549 + this_klass->set_fields(_fields, java_fields_count); 1.1550 + this_klass->set_methods(_methods); 1.1551 + this_klass->set_inner_classes(_inner_classes); 1.1552 + this_klass->set_local_interfaces(_local_interfaces); 1.1553 + this_klass->set_transitive_interfaces(_transitive_interfaces); 1.1554 + 1.1555 + // Clear out these fields so they don't get deallocated by the destructor 1.1556 + clear_class_metadata(); 1.1557 +} 1.1558 + 1.1559 +AnnotationArray* ClassFileParser::assemble_annotations(u1* runtime_visible_annotations, 1.1560 int runtime_visible_annotations_length, 1.1561 u1* runtime_invisible_annotations, 1.1562 int runtime_invisible_annotations_length, TRAPS) { 1.1563 AnnotationArray* annotations = NULL; 1.1564 if (runtime_visible_annotations != NULL || 1.1565 runtime_invisible_annotations != NULL) { 1.1566 - annotations = MetadataFactory::new_array<u1>(loader_data, 1.1567 + annotations = MetadataFactory::new_array<u1>(_loader_data, 1.1568 runtime_visible_annotations_length + 1.1569 runtime_invisible_annotations_length, 1.1570 CHECK_(annotations)); 1.1571 @@ -3144,6 +3066,581 @@ 1.1572 #endif // ndef PRODUCT 1.1573 1.1574 1.1575 +instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index, 1.1576 + TRAPS) { 1.1577 + instanceKlassHandle super_klass; 1.1578 + if (super_class_index == 0) { 1.1579 + check_property(_class_name == vmSymbols::java_lang_Object(), 1.1580 + "Invalid superclass index %u in class file %s", 1.1581 + super_class_index, 1.1582 + CHECK_NULL); 1.1583 + } else { 1.1584 + check_property(valid_klass_reference_at(super_class_index), 1.1585 + "Invalid superclass index %u in class file %s", 1.1586 + super_class_index, 1.1587 + CHECK_NULL); 1.1588 + // The class name should be legal because it is checked when parsing constant pool. 1.1589 + // However, make sure it is not an array type. 1.1590 + bool is_array = false; 1.1591 + if (_cp->tag_at(super_class_index).is_klass()) { 1.1592 + super_klass = instanceKlassHandle(THREAD, _cp->resolved_klass_at(super_class_index)); 1.1593 + if (_need_verify) 1.1594 + is_array = super_klass->oop_is_array(); 1.1595 + } else if (_need_verify) { 1.1596 + is_array = (_cp->unresolved_klass_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY); 1.1597 + } 1.1598 + if (_need_verify) { 1.1599 + guarantee_property(!is_array, 1.1600 + "Bad superclass name in class file %s", CHECK_NULL); 1.1601 + } 1.1602 + } 1.1603 + return super_klass; 1.1604 +} 1.1605 + 1.1606 + 1.1607 +// Values needed for oopmap and InstanceKlass creation 1.1608 +class FieldLayoutInfo : public StackObj { 1.1609 + public: 1.1610 + int* nonstatic_oop_offsets; 1.1611 + unsigned int* nonstatic_oop_counts; 1.1612 + unsigned int nonstatic_oop_map_count; 1.1613 + unsigned int total_oop_map_count; 1.1614 + int instance_size; 1.1615 + int nonstatic_field_size; 1.1616 + int static_field_size; 1.1617 + bool has_nonstatic_fields; 1.1618 +}; 1.1619 + 1.1620 +// Layout fields and fill in FieldLayoutInfo. Could use more refactoring! 1.1621 +void ClassFileParser::layout_fields(Handle class_loader, 1.1622 + FieldAllocationCount* fac, 1.1623 + ClassAnnotationCollector* parsed_annotations, 1.1624 + FieldLayoutInfo* info, 1.1625 + TRAPS) { 1.1626 + 1.1627 + // get the padding width from the option 1.1628 + // TODO: Ask VM about specific CPU we are running on 1.1629 + int pad_size = ContendedPaddingWidth; 1.1630 + 1.1631 + // Field size and offset computation 1.1632 + int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); 1.1633 +#ifndef PRODUCT 1.1634 + int orig_nonstatic_field_size = 0; 1.1635 +#endif 1.1636 + int next_static_oop_offset; 1.1637 + int next_static_double_offset; 1.1638 + int next_static_word_offset; 1.1639 + int next_static_short_offset; 1.1640 + int next_static_byte_offset; 1.1641 + int next_nonstatic_oop_offset; 1.1642 + int next_nonstatic_double_offset; 1.1643 + int next_nonstatic_word_offset; 1.1644 + int next_nonstatic_short_offset; 1.1645 + int next_nonstatic_byte_offset; 1.1646 + int next_nonstatic_type_offset; 1.1647 + int first_nonstatic_oop_offset; 1.1648 + int first_nonstatic_field_offset; 1.1649 + int next_nonstatic_field_offset; 1.1650 + int next_nonstatic_padded_offset; 1.1651 + 1.1652 + // Count the contended fields by type. 1.1653 + int nonstatic_contended_count = 0; 1.1654 + FieldAllocationCount fac_contended; 1.1655 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 1.1656 + FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 1.1657 + if (fs.is_contended()) { 1.1658 + fac_contended.count[atype]++; 1.1659 + if (!fs.access_flags().is_static()) { 1.1660 + nonstatic_contended_count++; 1.1661 + } 1.1662 + } 1.1663 + } 1.1664 + int contended_count = nonstatic_contended_count; 1.1665 + 1.1666 + 1.1667 + // Calculate the starting byte offsets 1.1668 + next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); 1.1669 + next_static_double_offset = next_static_oop_offset + 1.1670 + ((fac->count[STATIC_OOP]) * heapOopSize); 1.1671 + if ( fac->count[STATIC_DOUBLE] && 1.1672 + (Universe::field_type_should_be_aligned(T_DOUBLE) || 1.1673 + Universe::field_type_should_be_aligned(T_LONG)) ) { 1.1674 + next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong); 1.1675 + } 1.1676 + 1.1677 + next_static_word_offset = next_static_double_offset + 1.1678 + ((fac->count[STATIC_DOUBLE]) * BytesPerLong); 1.1679 + next_static_short_offset = next_static_word_offset + 1.1680 + ((fac->count[STATIC_WORD]) * BytesPerInt); 1.1681 + next_static_byte_offset = next_static_short_offset + 1.1682 + ((fac->count[STATIC_SHORT]) * BytesPerShort); 1.1683 + 1.1684 + first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 1.1685 + nonstatic_field_size * heapOopSize; 1.1686 + 1.1687 + // class is contended, pad before all the fields 1.1688 + if (parsed_annotations->is_contended()) { 1.1689 + first_nonstatic_field_offset += pad_size; 1.1690 + } 1.1691 + 1.1692 + next_nonstatic_field_offset = first_nonstatic_field_offset; 1.1693 + 1.1694 + unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; 1.1695 + unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; 1.1696 + unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; 1.1697 + unsigned int nonstatic_byte_count = fac->count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; 1.1698 + unsigned int nonstatic_oop_count = fac->count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; 1.1699 + 1.1700 + bool super_has_nonstatic_fields = 1.1701 + (_super_klass() != NULL && _super_klass->has_nonstatic_fields()); 1.1702 + bool has_nonstatic_fields = super_has_nonstatic_fields || 1.1703 + ((nonstatic_double_count + nonstatic_word_count + 1.1704 + nonstatic_short_count + nonstatic_byte_count + 1.1705 + nonstatic_oop_count) != 0); 1.1706 + 1.1707 + 1.1708 + // Prepare list of oops for oop map generation. 1.1709 + int* nonstatic_oop_offsets; 1.1710 + unsigned int* nonstatic_oop_counts; 1.1711 + unsigned int nonstatic_oop_map_count = 0; 1.1712 + 1.1713 + nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( 1.1714 + THREAD, int, nonstatic_oop_count + 1); 1.1715 + nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( 1.1716 + THREAD, unsigned int, nonstatic_oop_count + 1); 1.1717 + 1.1718 + first_nonstatic_oop_offset = 0; // will be set for first oop field 1.1719 + 1.1720 +#ifndef PRODUCT 1.1721 + if( PrintCompactFieldsSavings ) { 1.1722 + next_nonstatic_double_offset = next_nonstatic_field_offset + 1.1723 + (nonstatic_oop_count * heapOopSize); 1.1724 + if ( nonstatic_double_count > 0 ) { 1.1725 + next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong); 1.1726 + } 1.1727 + next_nonstatic_word_offset = next_nonstatic_double_offset + 1.1728 + (nonstatic_double_count * BytesPerLong); 1.1729 + next_nonstatic_short_offset = next_nonstatic_word_offset + 1.1730 + (nonstatic_word_count * BytesPerInt); 1.1731 + next_nonstatic_byte_offset = next_nonstatic_short_offset + 1.1732 + (nonstatic_short_count * BytesPerShort); 1.1733 + next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset + 1.1734 + nonstatic_byte_count ), heapOopSize ); 1.1735 + orig_nonstatic_field_size = nonstatic_field_size + 1.1736 + ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize); 1.1737 + } 1.1738 +#endif 1.1739 + bool compact_fields = CompactFields; 1.1740 + int allocation_style = FieldsAllocationStyle; 1.1741 + if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? 1.1742 + assert(false, "0 <= FieldsAllocationStyle <= 2"); 1.1743 + allocation_style = 1; // Optimistic 1.1744 + } 1.1745 + 1.1746 + // The next classes have predefined hard-coded fields offsets 1.1747 + // (see in JavaClasses::compute_hard_coded_offsets()). 1.1748 + // Use default fields allocation order for them. 1.1749 + if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() && 1.1750 + (_class_name == vmSymbols::java_lang_AssertionStatusDirectives() || 1.1751 + _class_name == vmSymbols::java_lang_Class() || 1.1752 + _class_name == vmSymbols::java_lang_ClassLoader() || 1.1753 + _class_name == vmSymbols::java_lang_ref_Reference() || 1.1754 + _class_name == vmSymbols::java_lang_ref_SoftReference() || 1.1755 + _class_name == vmSymbols::java_lang_StackTraceElement() || 1.1756 + _class_name == vmSymbols::java_lang_String() || 1.1757 + _class_name == vmSymbols::java_lang_Throwable() || 1.1758 + _class_name == vmSymbols::java_lang_Boolean() || 1.1759 + _class_name == vmSymbols::java_lang_Character() || 1.1760 + _class_name == vmSymbols::java_lang_Float() || 1.1761 + _class_name == vmSymbols::java_lang_Double() || 1.1762 + _class_name == vmSymbols::java_lang_Byte() || 1.1763 + _class_name == vmSymbols::java_lang_Short() || 1.1764 + _class_name == vmSymbols::java_lang_Integer() || 1.1765 + _class_name == vmSymbols::java_lang_Long())) { 1.1766 + allocation_style = 0; // Allocate oops first 1.1767 + compact_fields = false; // Don't compact fields 1.1768 + } 1.1769 + 1.1770 + if( allocation_style == 0 ) { 1.1771 + // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields 1.1772 + next_nonstatic_oop_offset = next_nonstatic_field_offset; 1.1773 + next_nonstatic_double_offset = next_nonstatic_oop_offset + 1.1774 + (nonstatic_oop_count * heapOopSize); 1.1775 + } else if( allocation_style == 1 ) { 1.1776 + // Fields order: longs/doubles, ints, shorts/chars, bytes, oops, padded fields 1.1777 + next_nonstatic_double_offset = next_nonstatic_field_offset; 1.1778 + } else if( allocation_style == 2 ) { 1.1779 + // Fields allocation: oops fields in super and sub classes are together. 1.1780 + if( nonstatic_field_size > 0 && _super_klass() != NULL && 1.1781 + _super_klass->nonstatic_oop_map_size() > 0 ) { 1.1782 + unsigned int map_count = _super_klass->nonstatic_oop_map_count(); 1.1783 + OopMapBlock* first_map = _super_klass->start_of_nonstatic_oop_maps(); 1.1784 + OopMapBlock* last_map = first_map + map_count - 1; 1.1785 + int next_offset = last_map->offset() + (last_map->count() * heapOopSize); 1.1786 + if (next_offset == next_nonstatic_field_offset) { 1.1787 + allocation_style = 0; // allocate oops first 1.1788 + next_nonstatic_oop_offset = next_nonstatic_field_offset; 1.1789 + next_nonstatic_double_offset = next_nonstatic_oop_offset + 1.1790 + (nonstatic_oop_count * heapOopSize); 1.1791 + } 1.1792 + } 1.1793 + if( allocation_style == 2 ) { 1.1794 + allocation_style = 1; // allocate oops last 1.1795 + next_nonstatic_double_offset = next_nonstatic_field_offset; 1.1796 + } 1.1797 + } else { 1.1798 + ShouldNotReachHere(); 1.1799 + } 1.1800 + 1.1801 + int nonstatic_oop_space_count = 0; 1.1802 + int nonstatic_word_space_count = 0; 1.1803 + int nonstatic_short_space_count = 0; 1.1804 + int nonstatic_byte_space_count = 0; 1.1805 + int nonstatic_oop_space_offset; 1.1806 + int nonstatic_word_space_offset; 1.1807 + int nonstatic_short_space_offset; 1.1808 + int nonstatic_byte_space_offset; 1.1809 + 1.1810 + if( nonstatic_double_count > 0 ) { 1.1811 + int offset = next_nonstatic_double_offset; 1.1812 + next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); 1.1813 + if( compact_fields && offset != next_nonstatic_double_offset ) { 1.1814 + // Allocate available fields into the gap before double field. 1.1815 + int length = next_nonstatic_double_offset - offset; 1.1816 + assert(length == BytesPerInt, ""); 1.1817 + nonstatic_word_space_offset = offset; 1.1818 + if( nonstatic_word_count > 0 ) { 1.1819 + nonstatic_word_count -= 1; 1.1820 + nonstatic_word_space_count = 1; // Only one will fit 1.1821 + length -= BytesPerInt; 1.1822 + offset += BytesPerInt; 1.1823 + } 1.1824 + nonstatic_short_space_offset = offset; 1.1825 + while( length >= BytesPerShort && nonstatic_short_count > 0 ) { 1.1826 + nonstatic_short_count -= 1; 1.1827 + nonstatic_short_space_count += 1; 1.1828 + length -= BytesPerShort; 1.1829 + offset += BytesPerShort; 1.1830 + } 1.1831 + nonstatic_byte_space_offset = offset; 1.1832 + while( length > 0 && nonstatic_byte_count > 0 ) { 1.1833 + nonstatic_byte_count -= 1; 1.1834 + nonstatic_byte_space_count += 1; 1.1835 + length -= 1; 1.1836 + } 1.1837 + // Allocate oop field in the gap if there are no other fields for that. 1.1838 + nonstatic_oop_space_offset = offset; 1.1839 + if( length >= heapOopSize && nonstatic_oop_count > 0 && 1.1840 + allocation_style != 0 ) { // when oop fields not first 1.1841 + nonstatic_oop_count -= 1; 1.1842 + nonstatic_oop_space_count = 1; // Only one will fit 1.1843 + length -= heapOopSize; 1.1844 + offset += heapOopSize; 1.1845 + } 1.1846 + } 1.1847 + } 1.1848 + 1.1849 + next_nonstatic_word_offset = next_nonstatic_double_offset + 1.1850 + (nonstatic_double_count * BytesPerLong); 1.1851 + next_nonstatic_short_offset = next_nonstatic_word_offset + 1.1852 + (nonstatic_word_count * BytesPerInt); 1.1853 + next_nonstatic_byte_offset = next_nonstatic_short_offset + 1.1854 + (nonstatic_short_count * BytesPerShort); 1.1855 + next_nonstatic_padded_offset = next_nonstatic_byte_offset + 1.1856 + nonstatic_byte_count; 1.1857 + 1.1858 + // let oops jump before padding with this allocation style 1.1859 + if( allocation_style == 1 ) { 1.1860 + next_nonstatic_oop_offset = next_nonstatic_padded_offset; 1.1861 + if( nonstatic_oop_count > 0 ) { 1.1862 + next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, heapOopSize); 1.1863 + } 1.1864 + next_nonstatic_padded_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize); 1.1865 + } 1.1866 + 1.1867 + // Iterate over fields again and compute correct offsets. 1.1868 + // The field allocation type was temporarily stored in the offset slot. 1.1869 + // oop fields are located before non-oop fields (static and non-static). 1.1870 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 1.1871 + 1.1872 + // skip already laid out fields 1.1873 + if (fs.is_offset_set()) continue; 1.1874 + 1.1875 + // contended instance fields are handled below 1.1876 + if (fs.is_contended() && !fs.access_flags().is_static()) continue; 1.1877 + 1.1878 + int real_offset; 1.1879 + FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 1.1880 + 1.1881 + // pack the rest of the fields 1.1882 + switch (atype) { 1.1883 + case STATIC_OOP: 1.1884 + real_offset = next_static_oop_offset; 1.1885 + next_static_oop_offset += heapOopSize; 1.1886 + break; 1.1887 + case STATIC_BYTE: 1.1888 + real_offset = next_static_byte_offset; 1.1889 + next_static_byte_offset += 1; 1.1890 + break; 1.1891 + case STATIC_SHORT: 1.1892 + real_offset = next_static_short_offset; 1.1893 + next_static_short_offset += BytesPerShort; 1.1894 + break; 1.1895 + case STATIC_WORD: 1.1896 + real_offset = next_static_word_offset; 1.1897 + next_static_word_offset += BytesPerInt; 1.1898 + break; 1.1899 + case STATIC_DOUBLE: 1.1900 + real_offset = next_static_double_offset; 1.1901 + next_static_double_offset += BytesPerLong; 1.1902 + break; 1.1903 + case NONSTATIC_OOP: 1.1904 + if( nonstatic_oop_space_count > 0 ) { 1.1905 + real_offset = nonstatic_oop_space_offset; 1.1906 + nonstatic_oop_space_offset += heapOopSize; 1.1907 + nonstatic_oop_space_count -= 1; 1.1908 + } else { 1.1909 + real_offset = next_nonstatic_oop_offset; 1.1910 + next_nonstatic_oop_offset += heapOopSize; 1.1911 + } 1.1912 + // Update oop maps 1.1913 + if( nonstatic_oop_map_count > 0 && 1.1914 + nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == 1.1915 + real_offset - 1.1916 + int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * 1.1917 + heapOopSize ) { 1.1918 + // Extend current oop map 1.1919 + nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; 1.1920 + } else { 1.1921 + // Create new oop map 1.1922 + nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 1.1923 + nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 1.1924 + nonstatic_oop_map_count += 1; 1.1925 + if( first_nonstatic_oop_offset == 0 ) { // Undefined 1.1926 + first_nonstatic_oop_offset = real_offset; 1.1927 + } 1.1928 + } 1.1929 + break; 1.1930 + case NONSTATIC_BYTE: 1.1931 + if( nonstatic_byte_space_count > 0 ) { 1.1932 + real_offset = nonstatic_byte_space_offset; 1.1933 + nonstatic_byte_space_offset += 1; 1.1934 + nonstatic_byte_space_count -= 1; 1.1935 + } else { 1.1936 + real_offset = next_nonstatic_byte_offset; 1.1937 + next_nonstatic_byte_offset += 1; 1.1938 + } 1.1939 + break; 1.1940 + case NONSTATIC_SHORT: 1.1941 + if( nonstatic_short_space_count > 0 ) { 1.1942 + real_offset = nonstatic_short_space_offset; 1.1943 + nonstatic_short_space_offset += BytesPerShort; 1.1944 + nonstatic_short_space_count -= 1; 1.1945 + } else { 1.1946 + real_offset = next_nonstatic_short_offset; 1.1947 + next_nonstatic_short_offset += BytesPerShort; 1.1948 + } 1.1949 + break; 1.1950 + case NONSTATIC_WORD: 1.1951 + if( nonstatic_word_space_count > 0 ) { 1.1952 + real_offset = nonstatic_word_space_offset; 1.1953 + nonstatic_word_space_offset += BytesPerInt; 1.1954 + nonstatic_word_space_count -= 1; 1.1955 + } else { 1.1956 + real_offset = next_nonstatic_word_offset; 1.1957 + next_nonstatic_word_offset += BytesPerInt; 1.1958 + } 1.1959 + break; 1.1960 + case NONSTATIC_DOUBLE: 1.1961 + real_offset = next_nonstatic_double_offset; 1.1962 + next_nonstatic_double_offset += BytesPerLong; 1.1963 + break; 1.1964 + default: 1.1965 + ShouldNotReachHere(); 1.1966 + } 1.1967 + fs.set_offset(real_offset); 1.1968 + } 1.1969 + 1.1970 + 1.1971 + // Handle the contended cases. 1.1972 + // 1.1973 + // Each contended field should not intersect the cache line with another contended field. 1.1974 + // In the absence of alignment information, we end up with pessimistically separating 1.1975 + // the fields with full-width padding. 1.1976 + // 1.1977 + // Additionally, this should not break alignment for the fields, so we round the alignment up 1.1978 + // for each field. 1.1979 + if (contended_count > 0) { 1.1980 + 1.1981 + // if there is at least one contended field, we need to have pre-padding for them 1.1982 + if (nonstatic_contended_count > 0) { 1.1983 + next_nonstatic_padded_offset += pad_size; 1.1984 + } 1.1985 + 1.1986 + // collect all contended groups 1.1987 + BitMap bm(_cp->size()); 1.1988 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 1.1989 + // skip already laid out fields 1.1990 + if (fs.is_offset_set()) continue; 1.1991 + 1.1992 + if (fs.is_contended()) { 1.1993 + bm.set_bit(fs.contended_group()); 1.1994 + } 1.1995 + } 1.1996 + 1.1997 + int current_group = -1; 1.1998 + while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { 1.1999 + 1.2000 + for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 1.2001 + 1.2002 + // skip already laid out fields 1.2003 + if (fs.is_offset_set()) continue; 1.2004 + 1.2005 + // skip non-contended fields and fields from different group 1.2006 + if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; 1.2007 + 1.2008 + // handle statics below 1.2009 + if (fs.access_flags().is_static()) continue; 1.2010 + 1.2011 + int real_offset; 1.2012 + FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 1.2013 + 1.2014 + switch (atype) { 1.2015 + case NONSTATIC_BYTE: 1.2016 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, 1); 1.2017 + real_offset = next_nonstatic_padded_offset; 1.2018 + next_nonstatic_padded_offset += 1; 1.2019 + break; 1.2020 + 1.2021 + case NONSTATIC_SHORT: 1.2022 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerShort); 1.2023 + real_offset = next_nonstatic_padded_offset; 1.2024 + next_nonstatic_padded_offset += BytesPerShort; 1.2025 + break; 1.2026 + 1.2027 + case NONSTATIC_WORD: 1.2028 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerInt); 1.2029 + real_offset = next_nonstatic_padded_offset; 1.2030 + next_nonstatic_padded_offset += BytesPerInt; 1.2031 + break; 1.2032 + 1.2033 + case NONSTATIC_DOUBLE: 1.2034 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerLong); 1.2035 + real_offset = next_nonstatic_padded_offset; 1.2036 + next_nonstatic_padded_offset += BytesPerLong; 1.2037 + break; 1.2038 + 1.2039 + case NONSTATIC_OOP: 1.2040 + next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); 1.2041 + real_offset = next_nonstatic_padded_offset; 1.2042 + next_nonstatic_padded_offset += heapOopSize; 1.2043 + 1.2044 + // Create new oop map 1.2045 + nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 1.2046 + nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 1.2047 + nonstatic_oop_map_count += 1; 1.2048 + if( first_nonstatic_oop_offset == 0 ) { // Undefined 1.2049 + first_nonstatic_oop_offset = real_offset; 1.2050 + } 1.2051 + break; 1.2052 + 1.2053 + default: 1.2054 + ShouldNotReachHere(); 1.2055 + } 1.2056 + 1.2057 + if (fs.contended_group() == 0) { 1.2058 + // Contended group defines the equivalence class over the fields: 1.2059 + // the fields within the same contended group are not inter-padded. 1.2060 + // The only exception is default group, which does not incur the 1.2061 + // equivalence, and so requires intra-padding. 1.2062 + next_nonstatic_padded_offset += pad_size; 1.2063 + } 1.2064 + 1.2065 + fs.set_offset(real_offset); 1.2066 + } // for 1.2067 + 1.2068 + // Start laying out the next group. 1.2069 + // Note that this will effectively pad the last group in the back; 1.2070 + // this is expected to alleviate memory contention effects for 1.2071 + // subclass fields and/or adjacent object. 1.2072 + // If this was the default group, the padding is already in place. 1.2073 + if (current_group != 0) { 1.2074 + next_nonstatic_padded_offset += pad_size; 1.2075 + } 1.2076 + } 1.2077 + 1.2078 + // handle static fields 1.2079 + } 1.2080 + 1.2081 + // Size of instances 1.2082 + int notaligned_offset = next_nonstatic_padded_offset; 1.2083 + 1.2084 + // Entire class is contended, pad in the back. 1.2085 + // This helps to alleviate memory contention effects for subclass fields 1.2086 + // and/or adjacent object. 1.2087 + if (parsed_annotations->is_contended()) { 1.2088 + notaligned_offset += pad_size; 1.2089 + } 1.2090 + 1.2091 + int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); 1.2092 + int static_field_size = (next_static_type_offset - 1.2093 + InstanceMirrorKlass::offset_of_static_fields()) / wordSize; 1.2094 + 1.2095 + next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); 1.2096 + nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset 1.2097 + - first_nonstatic_field_offset)/heapOopSize); 1.2098 + 1.2099 + next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); 1.2100 + int instance_size = align_object_size(next_nonstatic_type_offset / wordSize); 1.2101 + 1.2102 + assert(instance_size == align_object_size(align_size_up( 1.2103 + (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations->is_contended()) ? pad_size : 0)), 1.2104 + wordSize) / wordSize), "consistent layout helper value"); 1.2105 + 1.2106 + // Number of non-static oop map blocks allocated at end of klass. 1.2107 + const unsigned int total_oop_map_count = 1.2108 + compute_oop_map_count(_super_klass, nonstatic_oop_map_count, 1.2109 + first_nonstatic_oop_offset); 1.2110 + 1.2111 +#ifndef PRODUCT 1.2112 + if( PrintCompactFieldsSavings ) { 1.2113 + ResourceMark rm; 1.2114 + if( nonstatic_field_size < orig_nonstatic_field_size ) { 1.2115 + tty->print("[Saved %d of %d bytes in %s]\n", 1.2116 + (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, 1.2117 + orig_nonstatic_field_size*heapOopSize, 1.2118 + _class_name); 1.2119 + } else if( nonstatic_field_size > orig_nonstatic_field_size ) { 1.2120 + tty->print("[Wasted %d over %d bytes in %s]\n", 1.2121 + (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize, 1.2122 + orig_nonstatic_field_size*heapOopSize, 1.2123 + _class_name); 1.2124 + } 1.2125 + } 1.2126 + 1.2127 + if (PrintFieldLayout) { 1.2128 + print_field_layout(_class_name, 1.2129 + _fields, 1.2130 + _cp, 1.2131 + instance_size, 1.2132 + first_nonstatic_field_offset, 1.2133 + next_nonstatic_field_offset, 1.2134 + next_static_type_offset); 1.2135 + } 1.2136 + 1.2137 +#endif 1.2138 + // Pass back information needed for InstanceKlass creation 1.2139 + info->nonstatic_oop_offsets = nonstatic_oop_offsets; 1.2140 + info->nonstatic_oop_counts = nonstatic_oop_counts; 1.2141 + info->nonstatic_oop_map_count = nonstatic_oop_map_count; 1.2142 + info->total_oop_map_count = total_oop_map_count; 1.2143 + info->instance_size = instance_size; 1.2144 + info->static_field_size = static_field_size; 1.2145 + info->nonstatic_field_size = nonstatic_field_size; 1.2146 + info->has_nonstatic_fields = has_nonstatic_fields; 1.2147 +} 1.2148 + 1.2149 + 1.2150 instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, 1.2151 ClassLoaderData* loader_data, 1.2152 Handle protection_domain, 1.2153 @@ -3176,7 +3673,7 @@ 1.2154 jt->get_thread_stat()->perf_timers_addr(), 1.2155 PerfClassTraceTime::PARSE_CLASS); 1.2156 1.2157 - init_parsed_class_attributes(); 1.2158 + init_parsed_class_attributes(loader_data); 1.2159 1.2160 if (JvmtiExport::should_post_class_file_load_hook()) { 1.2161 // Get the cached class file bytes (if any) from the class that 1.2162 @@ -3271,8 +3768,7 @@ 1.2163 _relax_verify = Verifier::relax_verify_for(class_loader()); 1.2164 1.2165 // Constant pool 1.2166 - constantPoolHandle cp = parse_constant_pool(loader_data, CHECK_(nullHandle)); 1.2167 - ConstantPoolCleaner error_handler(cp); // set constant pool to be cleaned up. 1.2168 + constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle)); 1.2169 1.2170 int cp_size = cp->length(); 1.2171 1.2172 @@ -3290,7 +3786,6 @@ 1.2173 access_flags.set_flags(flags); 1.2174 1.2175 // This class and superclass 1.2176 - instanceKlassHandle super_klass; 1.2177 u2 this_class_index = cfs->get_u2_fast(); 1.2178 check_property( 1.2179 valid_cp_range(this_class_index, cp_size) && 1.2180 @@ -3345,59 +3840,27 @@ 1.2181 } 1.2182 1.2183 u2 super_class_index = cfs->get_u2_fast(); 1.2184 - if (super_class_index == 0) { 1.2185 - check_property(class_name == vmSymbols::java_lang_Object(), 1.2186 - "Invalid superclass index %u in class file %s", 1.2187 - super_class_index, 1.2188 - CHECK_(nullHandle)); 1.2189 - } else { 1.2190 - check_property(valid_cp_range(super_class_index, cp_size) && 1.2191 - is_klass_reference(cp, super_class_index), 1.2192 - "Invalid superclass index %u in class file %s", 1.2193 - super_class_index, 1.2194 - CHECK_(nullHandle)); 1.2195 - // The class name should be legal because it is checked when parsing constant pool. 1.2196 - // However, make sure it is not an array type. 1.2197 - bool is_array = false; 1.2198 - if (cp->tag_at(super_class_index).is_klass()) { 1.2199 - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index)); 1.2200 - if (_need_verify) 1.2201 - is_array = super_klass->oop_is_array(); 1.2202 - } else if (_need_verify) { 1.2203 - is_array = (cp->unresolved_klass_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY); 1.2204 - } 1.2205 - if (_need_verify) { 1.2206 - guarantee_property(!is_array, 1.2207 - "Bad superclass name in class file %s", CHECK_(nullHandle)); 1.2208 - } 1.2209 - } 1.2210 + instanceKlassHandle super_klass = parse_super_class(super_class_index, 1.2211 + CHECK_NULL); 1.2212 1.2213 // Interfaces 1.2214 u2 itfs_len = cfs->get_u2_fast(); 1.2215 - Array<Klass*>* local_interfaces; 1.2216 - if (itfs_len == 0) { 1.2217 - local_interfaces = Universe::the_empty_klass_array(); 1.2218 - } else { 1.2219 - local_interfaces = parse_interfaces( 1.2220 - cp, itfs_len, loader_data, protection_domain, _class_name, 1.2221 - &has_default_methods, CHECK_(nullHandle)); 1.2222 - } 1.2223 + Array<Klass*>* local_interfaces = 1.2224 + parse_interfaces(itfs_len, protection_domain, _class_name, 1.2225 + &has_default_methods, CHECK_(nullHandle)); 1.2226 1.2227 u2 java_fields_count = 0; 1.2228 // Fields (offsets are filled in later) 1.2229 FieldAllocationCount fac; 1.2230 - Array<AnnotationArray*>* fields_annotations = NULL; 1.2231 - Array<AnnotationArray*>* fields_type_annotations = NULL; 1.2232 - Array<u2>* fields = parse_fields(loader_data, class_name, cp, access_flags.is_interface(), &fac, &fields_annotations, 1.2233 - &fields_type_annotations, 1.2234 - &java_fields_count, 1.2235 - CHECK_(nullHandle)); 1.2236 + Array<u2>* fields = parse_fields(class_name, 1.2237 + access_flags.is_interface(), 1.2238 + &fac, &java_fields_count, 1.2239 + CHECK_(nullHandle)); 1.2240 // Methods 1.2241 bool has_final_method = false; 1.2242 AccessFlags promoted_flags; 1.2243 promoted_flags.set_flags(0); 1.2244 - Array<Method*>* methods = parse_methods(loader_data, 1.2245 - cp, access_flags.is_interface(), 1.2246 + Array<Method*>* methods = parse_methods(access_flags.is_interface(), 1.2247 &promoted_flags, 1.2248 &has_final_method, 1.2249 &has_default_methods, 1.2250 @@ -3405,7 +3868,7 @@ 1.2251 1.2252 // Additional attributes 1.2253 ClassAnnotationCollector parsed_annotations; 1.2254 - parse_classfile_attributes(loader_data, cp, &parsed_annotations, CHECK_(nullHandle)); 1.2255 + parse_classfile_attributes(&parsed_annotations, CHECK_(nullHandle)); 1.2256 1.2257 // Make sure this is the end of class file stream 1.2258 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); 1.2259 @@ -3452,13 +3915,15 @@ 1.2260 } 1.2261 } 1.2262 1.2263 + // save super klass for error handling. 1.2264 + _super_klass = super_klass; 1.2265 + 1.2266 // Compute the transitive list of all unique interfaces implemented by this class 1.2267 - Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle)); 1.2268 + _transitive_interfaces = 1.2269 + compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle)); 1.2270 1.2271 // sort methods 1.2272 - Array<int>* method_ordering = sort_methods(loader_data, 1.2273 - methods, 1.2274 - CHECK_(nullHandle)); 1.2275 + intArray* method_ordering = sort_methods(methods); 1.2276 1.2277 // promote flags from parse_methods() to the klass' flags 1.2278 access_flags.add_promoted_flags(promoted_flags.as_int()); 1.2279 @@ -3476,495 +3941,14 @@ 1.2280 CHECK_(nullHandle)); 1.2281 1.2282 // Size of Java itable (in words) 1.2283 - itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces); 1.2284 - 1.2285 - // get the padding width from the option 1.2286 - // TODO: Ask VM about specific CPU we are running on 1.2287 - int pad_size = ContendedPaddingWidth; 1.2288 - 1.2289 - // Field size and offset computation 1.2290 - int nonstatic_field_size = super_klass() == NULL ? 0 : super_klass->nonstatic_field_size(); 1.2291 -#ifndef PRODUCT 1.2292 - int orig_nonstatic_field_size = 0; 1.2293 -#endif 1.2294 - int next_static_oop_offset; 1.2295 - int next_static_double_offset; 1.2296 - int next_static_word_offset; 1.2297 - int next_static_short_offset; 1.2298 - int next_static_byte_offset; 1.2299 - int next_nonstatic_oop_offset; 1.2300 - int next_nonstatic_double_offset; 1.2301 - int next_nonstatic_word_offset; 1.2302 - int next_nonstatic_short_offset; 1.2303 - int next_nonstatic_byte_offset; 1.2304 - int next_nonstatic_type_offset; 1.2305 - int first_nonstatic_oop_offset; 1.2306 - int first_nonstatic_field_offset; 1.2307 - int next_nonstatic_field_offset; 1.2308 - int next_nonstatic_padded_offset; 1.2309 - 1.2310 - // Count the contended fields by type. 1.2311 - int nonstatic_contended_count = 0; 1.2312 - FieldAllocationCount fac_contended; 1.2313 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 1.2314 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 1.2315 - if (fs.is_contended()) { 1.2316 - fac_contended.count[atype]++; 1.2317 - if (!fs.access_flags().is_static()) { 1.2318 - nonstatic_contended_count++; 1.2319 - } 1.2320 - } 1.2321 - } 1.2322 - int contended_count = nonstatic_contended_count; 1.2323 - 1.2324 - 1.2325 - // Calculate the starting byte offsets 1.2326 - next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); 1.2327 - 1.2328 - next_static_double_offset = next_static_oop_offset + 1.2329 - ((fac.count[STATIC_OOP]) * heapOopSize); 1.2330 - if ( fac.count[STATIC_DOUBLE] && 1.2331 - (Universe::field_type_should_be_aligned(T_DOUBLE) || 1.2332 - Universe::field_type_should_be_aligned(T_LONG)) ) { 1.2333 - next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong); 1.2334 - } 1.2335 - 1.2336 - next_static_word_offset = next_static_double_offset + 1.2337 - ((fac.count[STATIC_DOUBLE]) * BytesPerLong); 1.2338 - next_static_short_offset = next_static_word_offset + 1.2339 - ((fac.count[STATIC_WORD]) * BytesPerInt); 1.2340 - next_static_byte_offset = next_static_short_offset + 1.2341 - ((fac.count[STATIC_SHORT]) * BytesPerShort); 1.2342 - 1.2343 - first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 1.2344 - nonstatic_field_size * heapOopSize; 1.2345 - 1.2346 - // class is contended, pad before all the fields 1.2347 - if (parsed_annotations.is_contended()) { 1.2348 - first_nonstatic_field_offset += pad_size; 1.2349 - } 1.2350 - 1.2351 - next_nonstatic_field_offset = first_nonstatic_field_offset; 1.2352 - 1.2353 - unsigned int nonstatic_double_count = fac.count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; 1.2354 - unsigned int nonstatic_word_count = fac.count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; 1.2355 - unsigned int nonstatic_short_count = fac.count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; 1.2356 - unsigned int nonstatic_byte_count = fac.count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; 1.2357 - unsigned int nonstatic_oop_count = fac.count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; 1.2358 - 1.2359 - bool super_has_nonstatic_fields = 1.2360 - (super_klass() != NULL && super_klass->has_nonstatic_fields()); 1.2361 - bool has_nonstatic_fields = super_has_nonstatic_fields || 1.2362 - ((nonstatic_double_count + nonstatic_word_count + 1.2363 - nonstatic_short_count + nonstatic_byte_count + 1.2364 - nonstatic_oop_count) != 0); 1.2365 - 1.2366 - 1.2367 - // Prepare list of oops for oop map generation. 1.2368 - int* nonstatic_oop_offsets; 1.2369 - unsigned int* nonstatic_oop_counts; 1.2370 - unsigned int nonstatic_oop_map_count = 0; 1.2371 - 1.2372 - nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( 1.2373 - THREAD, int, nonstatic_oop_count + 1); 1.2374 - nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( 1.2375 - THREAD, unsigned int, nonstatic_oop_count + 1); 1.2376 - 1.2377 - first_nonstatic_oop_offset = 0; // will be set for first oop field 1.2378 - 1.2379 -#ifndef PRODUCT 1.2380 - if( PrintCompactFieldsSavings ) { 1.2381 - next_nonstatic_double_offset = next_nonstatic_field_offset + 1.2382 - (nonstatic_oop_count * heapOopSize); 1.2383 - if ( nonstatic_double_count > 0 ) { 1.2384 - next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong); 1.2385 - } 1.2386 - next_nonstatic_word_offset = next_nonstatic_double_offset + 1.2387 - (nonstatic_double_count * BytesPerLong); 1.2388 - next_nonstatic_short_offset = next_nonstatic_word_offset + 1.2389 - (nonstatic_word_count * BytesPerInt); 1.2390 - next_nonstatic_byte_offset = next_nonstatic_short_offset + 1.2391 - (nonstatic_short_count * BytesPerShort); 1.2392 - next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset + 1.2393 - nonstatic_byte_count ), heapOopSize ); 1.2394 - orig_nonstatic_field_size = nonstatic_field_size + 1.2395 - ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize); 1.2396 - } 1.2397 -#endif 1.2398 - bool compact_fields = CompactFields; 1.2399 - int allocation_style = FieldsAllocationStyle; 1.2400 - if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? 1.2401 - assert(false, "0 <= FieldsAllocationStyle <= 2"); 1.2402 - allocation_style = 1; // Optimistic 1.2403 - } 1.2404 - 1.2405 - // The next classes have predefined hard-coded fields offsets 1.2406 - // (see in JavaClasses::compute_hard_coded_offsets()). 1.2407 - // Use default fields allocation order for them. 1.2408 - if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() && 1.2409 - (class_name == vmSymbols::java_lang_AssertionStatusDirectives() || 1.2410 - class_name == vmSymbols::java_lang_Class() || 1.2411 - class_name == vmSymbols::java_lang_ClassLoader() || 1.2412 - class_name == vmSymbols::java_lang_ref_Reference() || 1.2413 - class_name == vmSymbols::java_lang_ref_SoftReference() || 1.2414 - class_name == vmSymbols::java_lang_StackTraceElement() || 1.2415 - class_name == vmSymbols::java_lang_String() || 1.2416 - class_name == vmSymbols::java_lang_Throwable() || 1.2417 - class_name == vmSymbols::java_lang_Boolean() || 1.2418 - class_name == vmSymbols::java_lang_Character() || 1.2419 - class_name == vmSymbols::java_lang_Float() || 1.2420 - class_name == vmSymbols::java_lang_Double() || 1.2421 - class_name == vmSymbols::java_lang_Byte() || 1.2422 - class_name == vmSymbols::java_lang_Short() || 1.2423 - class_name == vmSymbols::java_lang_Integer() || 1.2424 - class_name == vmSymbols::java_lang_Long())) { 1.2425 - allocation_style = 0; // Allocate oops first 1.2426 - compact_fields = false; // Don't compact fields 1.2427 - } 1.2428 - 1.2429 - if( allocation_style == 0 ) { 1.2430 - // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields 1.2431 - next_nonstatic_oop_offset = next_nonstatic_field_offset; 1.2432 - next_nonstatic_double_offset = next_nonstatic_oop_offset + 1.2433 - (nonstatic_oop_count * heapOopSize); 1.2434 - } else if( allocation_style == 1 ) { 1.2435 - // Fields order: longs/doubles, ints, shorts/chars, bytes, oops, padded fields 1.2436 - next_nonstatic_double_offset = next_nonstatic_field_offset; 1.2437 - } else if( allocation_style == 2 ) { 1.2438 - // Fields allocation: oops fields in super and sub classes are together. 1.2439 - if( nonstatic_field_size > 0 && super_klass() != NULL && 1.2440 - super_klass->nonstatic_oop_map_size() > 0 ) { 1.2441 - int map_count = super_klass->nonstatic_oop_map_count(); 1.2442 - OopMapBlock* first_map = super_klass->start_of_nonstatic_oop_maps(); 1.2443 - OopMapBlock* last_map = first_map + map_count - 1; 1.2444 - int next_offset = last_map->offset() + (last_map->count() * heapOopSize); 1.2445 - if (next_offset == next_nonstatic_field_offset) { 1.2446 - allocation_style = 0; // allocate oops first 1.2447 - next_nonstatic_oop_offset = next_nonstatic_field_offset; 1.2448 - next_nonstatic_double_offset = next_nonstatic_oop_offset + 1.2449 - (nonstatic_oop_count * heapOopSize); 1.2450 - } 1.2451 - } 1.2452 - if( allocation_style == 2 ) { 1.2453 - allocation_style = 1; // allocate oops last 1.2454 - next_nonstatic_double_offset = next_nonstatic_field_offset; 1.2455 - } 1.2456 - } else { 1.2457 - ShouldNotReachHere(); 1.2458 - } 1.2459 - 1.2460 - int nonstatic_oop_space_count = 0; 1.2461 - int nonstatic_word_space_count = 0; 1.2462 - int nonstatic_short_space_count = 0; 1.2463 - int nonstatic_byte_space_count = 0; 1.2464 - int nonstatic_oop_space_offset; 1.2465 - int nonstatic_word_space_offset; 1.2466 - int nonstatic_short_space_offset; 1.2467 - int nonstatic_byte_space_offset; 1.2468 - 1.2469 - if( nonstatic_double_count > 0 ) { 1.2470 - int offset = next_nonstatic_double_offset; 1.2471 - next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); 1.2472 - if( compact_fields && offset != next_nonstatic_double_offset ) { 1.2473 - // Allocate available fields into the gap before double field. 1.2474 - int length = next_nonstatic_double_offset - offset; 1.2475 - assert(length == BytesPerInt, ""); 1.2476 - nonstatic_word_space_offset = offset; 1.2477 - if( nonstatic_word_count > 0 ) { 1.2478 - nonstatic_word_count -= 1; 1.2479 - nonstatic_word_space_count = 1; // Only one will fit 1.2480 - length -= BytesPerInt; 1.2481 - offset += BytesPerInt; 1.2482 - } 1.2483 - nonstatic_short_space_offset = offset; 1.2484 - while( length >= BytesPerShort && nonstatic_short_count > 0 ) { 1.2485 - nonstatic_short_count -= 1; 1.2486 - nonstatic_short_space_count += 1; 1.2487 - length -= BytesPerShort; 1.2488 - offset += BytesPerShort; 1.2489 - } 1.2490 - nonstatic_byte_space_offset = offset; 1.2491 - while( length > 0 && nonstatic_byte_count > 0 ) { 1.2492 - nonstatic_byte_count -= 1; 1.2493 - nonstatic_byte_space_count += 1; 1.2494 - length -= 1; 1.2495 - } 1.2496 - // Allocate oop field in the gap if there are no other fields for that. 1.2497 - nonstatic_oop_space_offset = offset; 1.2498 - if( length >= heapOopSize && nonstatic_oop_count > 0 && 1.2499 - allocation_style != 0 ) { // when oop fields not first 1.2500 - nonstatic_oop_count -= 1; 1.2501 - nonstatic_oop_space_count = 1; // Only one will fit 1.2502 - length -= heapOopSize; 1.2503 - offset += heapOopSize; 1.2504 - } 1.2505 - } 1.2506 - } 1.2507 - 1.2508 - next_nonstatic_word_offset = next_nonstatic_double_offset + 1.2509 - (nonstatic_double_count * BytesPerLong); 1.2510 - next_nonstatic_short_offset = next_nonstatic_word_offset + 1.2511 - (nonstatic_word_count * BytesPerInt); 1.2512 - next_nonstatic_byte_offset = next_nonstatic_short_offset + 1.2513 - (nonstatic_short_count * BytesPerShort); 1.2514 - next_nonstatic_padded_offset = next_nonstatic_byte_offset + 1.2515 - nonstatic_byte_count; 1.2516 - 1.2517 - // let oops jump before padding with this allocation style 1.2518 - if( allocation_style == 1 ) { 1.2519 - next_nonstatic_oop_offset = next_nonstatic_padded_offset; 1.2520 - if( nonstatic_oop_count > 0 ) { 1.2521 - next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, heapOopSize); 1.2522 - } 1.2523 - next_nonstatic_padded_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize); 1.2524 - } 1.2525 - 1.2526 - // Iterate over fields again and compute correct offsets. 1.2527 - // The field allocation type was temporarily stored in the offset slot. 1.2528 - // oop fields are located before non-oop fields (static and non-static). 1.2529 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 1.2530 - 1.2531 - // skip already laid out fields 1.2532 - if (fs.is_offset_set()) continue; 1.2533 - 1.2534 - // contended instance fields are handled below 1.2535 - if (fs.is_contended() && !fs.access_flags().is_static()) continue; 1.2536 - 1.2537 - int real_offset; 1.2538 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 1.2539 - 1.2540 - // pack the rest of the fields 1.2541 - switch (atype) { 1.2542 - case STATIC_OOP: 1.2543 - real_offset = next_static_oop_offset; 1.2544 - next_static_oop_offset += heapOopSize; 1.2545 - break; 1.2546 - case STATIC_BYTE: 1.2547 - real_offset = next_static_byte_offset; 1.2548 - next_static_byte_offset += 1; 1.2549 - break; 1.2550 - case STATIC_SHORT: 1.2551 - real_offset = next_static_short_offset; 1.2552 - next_static_short_offset += BytesPerShort; 1.2553 - break; 1.2554 - case STATIC_WORD: 1.2555 - real_offset = next_static_word_offset; 1.2556 - next_static_word_offset += BytesPerInt; 1.2557 - break; 1.2558 - case STATIC_DOUBLE: 1.2559 - real_offset = next_static_double_offset; 1.2560 - next_static_double_offset += BytesPerLong; 1.2561 - break; 1.2562 - case NONSTATIC_OOP: 1.2563 - if( nonstatic_oop_space_count > 0 ) { 1.2564 - real_offset = nonstatic_oop_space_offset; 1.2565 - nonstatic_oop_space_offset += heapOopSize; 1.2566 - nonstatic_oop_space_count -= 1; 1.2567 - } else { 1.2568 - real_offset = next_nonstatic_oop_offset; 1.2569 - next_nonstatic_oop_offset += heapOopSize; 1.2570 - } 1.2571 - // Update oop maps 1.2572 - if( nonstatic_oop_map_count > 0 && 1.2573 - nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == 1.2574 - real_offset - 1.2575 - int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * 1.2576 - heapOopSize ) { 1.2577 - // Extend current oop map 1.2578 - nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; 1.2579 - } else { 1.2580 - // Create new oop map 1.2581 - nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 1.2582 - nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 1.2583 - nonstatic_oop_map_count += 1; 1.2584 - if( first_nonstatic_oop_offset == 0 ) { // Undefined 1.2585 - first_nonstatic_oop_offset = real_offset; 1.2586 - } 1.2587 - } 1.2588 - break; 1.2589 - case NONSTATIC_BYTE: 1.2590 - if( nonstatic_byte_space_count > 0 ) { 1.2591 - real_offset = nonstatic_byte_space_offset; 1.2592 - nonstatic_byte_space_offset += 1; 1.2593 - nonstatic_byte_space_count -= 1; 1.2594 - } else { 1.2595 - real_offset = next_nonstatic_byte_offset; 1.2596 - next_nonstatic_byte_offset += 1; 1.2597 - } 1.2598 - break; 1.2599 - case NONSTATIC_SHORT: 1.2600 - if( nonstatic_short_space_count > 0 ) { 1.2601 - real_offset = nonstatic_short_space_offset; 1.2602 - nonstatic_short_space_offset += BytesPerShort; 1.2603 - nonstatic_short_space_count -= 1; 1.2604 - } else { 1.2605 - real_offset = next_nonstatic_short_offset; 1.2606 - next_nonstatic_short_offset += BytesPerShort; 1.2607 - } 1.2608 - break; 1.2609 - case NONSTATIC_WORD: 1.2610 - if( nonstatic_word_space_count > 0 ) { 1.2611 - real_offset = nonstatic_word_space_offset; 1.2612 - nonstatic_word_space_offset += BytesPerInt; 1.2613 - nonstatic_word_space_count -= 1; 1.2614 - } else { 1.2615 - real_offset = next_nonstatic_word_offset; 1.2616 - next_nonstatic_word_offset += BytesPerInt; 1.2617 - } 1.2618 - break; 1.2619 - case NONSTATIC_DOUBLE: 1.2620 - real_offset = next_nonstatic_double_offset; 1.2621 - next_nonstatic_double_offset += BytesPerLong; 1.2622 - break; 1.2623 - default: 1.2624 - ShouldNotReachHere(); 1.2625 - } 1.2626 - fs.set_offset(real_offset); 1.2627 - } 1.2628 - 1.2629 - 1.2630 - // Handle the contended cases. 1.2631 - // 1.2632 - // Each contended field should not intersect the cache line with another contended field. 1.2633 - // In the absence of alignment information, we end up with pessimistically separating 1.2634 - // the fields with full-width padding. 1.2635 - // 1.2636 - // Additionally, this should not break alignment for the fields, so we round the alignment up 1.2637 - // for each field. 1.2638 - if (contended_count > 0) { 1.2639 - 1.2640 - // if there is at least one contended field, we need to have pre-padding for them 1.2641 - if (nonstatic_contended_count > 0) { 1.2642 - next_nonstatic_padded_offset += pad_size; 1.2643 - } 1.2644 - 1.2645 - // collect all contended groups 1.2646 - BitMap bm(cp->size()); 1.2647 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 1.2648 - // skip already laid out fields 1.2649 - if (fs.is_offset_set()) continue; 1.2650 - 1.2651 - if (fs.is_contended()) { 1.2652 - bm.set_bit(fs.contended_group()); 1.2653 - } 1.2654 - } 1.2655 - 1.2656 - int current_group = -1; 1.2657 - while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { 1.2658 - 1.2659 - for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { 1.2660 - 1.2661 - // skip already laid out fields 1.2662 - if (fs.is_offset_set()) continue; 1.2663 - 1.2664 - // skip non-contended fields and fields from different group 1.2665 - if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; 1.2666 - 1.2667 - // handle statics below 1.2668 - if (fs.access_flags().is_static()) continue; 1.2669 - 1.2670 - int real_offset; 1.2671 - FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); 1.2672 - 1.2673 - switch (atype) { 1.2674 - case NONSTATIC_BYTE: 1.2675 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, 1); 1.2676 - real_offset = next_nonstatic_padded_offset; 1.2677 - next_nonstatic_padded_offset += 1; 1.2678 - break; 1.2679 - 1.2680 - case NONSTATIC_SHORT: 1.2681 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerShort); 1.2682 - real_offset = next_nonstatic_padded_offset; 1.2683 - next_nonstatic_padded_offset += BytesPerShort; 1.2684 - break; 1.2685 - 1.2686 - case NONSTATIC_WORD: 1.2687 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerInt); 1.2688 - real_offset = next_nonstatic_padded_offset; 1.2689 - next_nonstatic_padded_offset += BytesPerInt; 1.2690 - break; 1.2691 - 1.2692 - case NONSTATIC_DOUBLE: 1.2693 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerLong); 1.2694 - real_offset = next_nonstatic_padded_offset; 1.2695 - next_nonstatic_padded_offset += BytesPerLong; 1.2696 - break; 1.2697 - 1.2698 - case NONSTATIC_OOP: 1.2699 - next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); 1.2700 - real_offset = next_nonstatic_padded_offset; 1.2701 - next_nonstatic_padded_offset += heapOopSize; 1.2702 - 1.2703 - // Create new oop map 1.2704 - nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 1.2705 - nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 1.2706 - nonstatic_oop_map_count += 1; 1.2707 - if( first_nonstatic_oop_offset == 0 ) { // Undefined 1.2708 - first_nonstatic_oop_offset = real_offset; 1.2709 - } 1.2710 - break; 1.2711 - 1.2712 - default: 1.2713 - ShouldNotReachHere(); 1.2714 - } 1.2715 - 1.2716 - if (fs.contended_group() == 0) { 1.2717 - // Contended group defines the equivalence class over the fields: 1.2718 - // the fields within the same contended group are not inter-padded. 1.2719 - // The only exception is default group, which does not incur the 1.2720 - // equivalence, and so requires intra-padding. 1.2721 - next_nonstatic_padded_offset += pad_size; 1.2722 - } 1.2723 - 1.2724 - fs.set_offset(real_offset); 1.2725 - } // for 1.2726 - 1.2727 - // Start laying out the next group. 1.2728 - // Note that this will effectively pad the last group in the back; 1.2729 - // this is expected to alleviate memory contention effects for 1.2730 - // subclass fields and/or adjacent object. 1.2731 - // If this was the default group, the padding is already in place. 1.2732 - if (current_group != 0) { 1.2733 - next_nonstatic_padded_offset += pad_size; 1.2734 - } 1.2735 - } 1.2736 - 1.2737 - // handle static fields 1.2738 - 1.2739 - } // handle contended 1.2740 - 1.2741 - // Size of instances 1.2742 - int instance_size; 1.2743 - 1.2744 - int notaligned_offset = next_nonstatic_padded_offset; 1.2745 - 1.2746 - // Entire class is contended, pad in the back. 1.2747 - // This helps to alleviate memory contention effects for subclass fields 1.2748 - // and/or adjacent object. 1.2749 - if (parsed_annotations.is_contended()) { 1.2750 - notaligned_offset += pad_size; 1.2751 - } 1.2752 - 1.2753 - int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); 1.2754 - int static_field_size = (next_static_type_offset - 1.2755 - InstanceMirrorKlass::offset_of_static_fields()) / wordSize; 1.2756 - 1.2757 - next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); 1.2758 - nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset 1.2759 - - first_nonstatic_field_offset)/heapOopSize); 1.2760 - 1.2761 - next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); 1.2762 - instance_size = align_object_size(next_nonstatic_type_offset / wordSize); 1.2763 - 1.2764 - assert(instance_size == align_object_size(align_size_up( 1.2765 - (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations.is_contended()) ? pad_size : 0)), 1.2766 - wordSize) / wordSize), "consistent layout helper value"); 1.2767 - 1.2768 - // Number of non-static oop map blocks allocated at end of klass. 1.2769 - const unsigned int total_oop_map_count = 1.2770 - compute_oop_map_count(super_klass, nonstatic_oop_map_count, 1.2771 - first_nonstatic_oop_offset); 1.2772 + itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(_transitive_interfaces); 1.2773 + 1.2774 + FieldLayoutInfo info; 1.2775 + layout_fields(class_loader, &fac, &parsed_annotations, &info, CHECK_NULL); 1.2776 + 1.2777 + int total_oop_map_size2 = 1.2778 + InstanceKlass::nonstatic_oop_map_size(info.total_oop_map_count); 1.2779 + 1.2780 // Compute reference type 1.2781 ReferenceType rt; 1.2782 if (super_klass() == NULL) { 1.2783 @@ -3974,53 +3958,42 @@ 1.2784 } 1.2785 1.2786 // We can now create the basic Klass* for this klass 1.2787 - int total_oop_map_size2 = 1.2788 - InstanceKlass::nonstatic_oop_map_size(total_oop_map_count); 1.2789 - 1.2790 - Klass* ik = InstanceKlass::allocate_instance_klass(loader_data, 1.2791 - vtable_size, 1.2792 - itable_size, 1.2793 - static_field_size, 1.2794 - total_oop_map_size2, 1.2795 - rt, 1.2796 - access_flags, 1.2797 - name, 1.2798 - super_klass(), 1.2799 - !host_klass.is_null(), 1.2800 - CHECK_(nullHandle)); 1.2801 - 1.2802 - // Add all classes to our internal class loader list here, 1.2803 - // including classes in the bootstrap (NULL) class loader. 1.2804 - loader_data->add_class(ik); 1.2805 - 1.2806 - instanceKlassHandle this_klass (THREAD, ik); 1.2807 - 1.2808 - assert(this_klass->static_field_size() == static_field_size, "sanity"); 1.2809 - assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count, 1.2810 + _klass = InstanceKlass::allocate_instance_klass(loader_data, 1.2811 + vtable_size, 1.2812 + itable_size, 1.2813 + info.static_field_size, 1.2814 + total_oop_map_size2, 1.2815 + rt, 1.2816 + access_flags, 1.2817 + name, 1.2818 + super_klass(), 1.2819 + !host_klass.is_null(), 1.2820 + CHECK_(nullHandle)); 1.2821 + instanceKlassHandle this_klass (THREAD, _klass); 1.2822 + 1.2823 + assert(this_klass->static_field_size() == info.static_field_size, "sanity"); 1.2824 + assert(this_klass->nonstatic_oop_map_count() == info.total_oop_map_count, 1.2825 "sanity"); 1.2826 1.2827 // Fill in information already parsed 1.2828 this_klass->set_should_verify_class(verify); 1.2829 - jint lh = Klass::instance_layout_helper(instance_size, false); 1.2830 + jint lh = Klass::instance_layout_helper(info.instance_size, false); 1.2831 this_klass->set_layout_helper(lh); 1.2832 assert(this_klass->oop_is_instance(), "layout is correct"); 1.2833 - assert(this_klass->size_helper() == instance_size, "correct size_helper"); 1.2834 + assert(this_klass->size_helper() == info.instance_size, "correct size_helper"); 1.2835 // Not yet: supers are done below to support the new subtype-checking fields 1.2836 //this_klass->set_super(super_klass()); 1.2837 this_klass->set_class_loader_data(loader_data); 1.2838 - this_klass->set_nonstatic_field_size(nonstatic_field_size); 1.2839 - this_klass->set_has_nonstatic_fields(has_nonstatic_fields); 1.2840 + this_klass->set_nonstatic_field_size(info.nonstatic_field_size); 1.2841 + this_klass->set_has_nonstatic_fields(info.has_nonstatic_fields); 1.2842 this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]); 1.2843 - cp->set_pool_holder(this_klass()); 1.2844 - error_handler.set_in_error(false); // turn off error handler for cp 1.2845 - this_klass->set_constants(cp()); 1.2846 - this_klass->set_local_interfaces(local_interfaces); 1.2847 - this_klass->set_fields(fields, java_fields_count); 1.2848 - this_klass->set_methods(methods); 1.2849 + 1.2850 + apply_parsed_class_metadata(this_klass, java_fields_count, CHECK_NULL); 1.2851 + 1.2852 if (has_final_method) { 1.2853 this_klass->set_has_final_method(); 1.2854 } 1.2855 - this_klass->set_method_ordering(method_ordering); 1.2856 + this_klass->copy_method_ordering(method_ordering, CHECK_NULL); 1.2857 // The InstanceKlass::_methods_jmethod_ids cache and the 1.2858 // InstanceKlass::_methods_cached_itable_indices cache are 1.2859 // both managed on the assumption that the initial cache 1.2860 @@ -4032,17 +4005,6 @@ 1.2861 if (is_anonymous()) // I am well known to myself 1.2862 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve 1.2863 1.2864 - // Assign allocations if needed 1.2865 - if (_annotations != NULL || _type_annotations != NULL || 1.2866 - fields_annotations != NULL || fields_type_annotations != NULL) { 1.2867 - Annotations* annotations = Annotations::allocate(loader_data, CHECK_NULL); 1.2868 - annotations->set_class_annotations(_annotations); 1.2869 - annotations->set_class_type_annotations(_type_annotations); 1.2870 - annotations->set_fields_annotations(fields_annotations); 1.2871 - annotations->set_fields_type_annotations(fields_type_annotations); 1.2872 - this_klass->set_annotations(annotations); 1.2873 - } 1.2874 - 1.2875 this_klass->set_minor_version(minor_version); 1.2876 this_klass->set_major_version(major_version); 1.2877 this_klass->set_has_default_methods(has_default_methods); 1.2878 @@ -4077,8 +4039,6 @@ 1.2879 this_klass->set_has_miranda_methods(); // then set a flag 1.2880 } 1.2881 1.2882 - this_klass->set_transitive_interfaces(transitive_interfaces); 1.2883 - 1.2884 // Fill in information needed to compute superclasses. 1.2885 this_klass->initialize_supers(super_klass(), CHECK_(nullHandle)); 1.2886 1.2887 @@ -4087,7 +4047,7 @@ 1.2888 1.2889 // Compute transitive closure of interfaces this class implements 1.2890 // Do final class setup 1.2891 - fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts); 1.2892 + fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.nonstatic_oop_counts); 1.2893 1.2894 // Fill in has_finalizer, has_vanilla_constructor, and layout_helper 1.2895 set_precomputed_flags(this_klass); 1.2896 @@ -4186,35 +4146,6 @@ 1.2897 } 1.2898 } 1.2899 1.2900 -#ifndef PRODUCT 1.2901 - if( PrintCompactFieldsSavings ) { 1.2902 - ResourceMark rm; 1.2903 - if( nonstatic_field_size < orig_nonstatic_field_size ) { 1.2904 - tty->print("[Saved %d of %d bytes in %s]\n", 1.2905 - (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, 1.2906 - orig_nonstatic_field_size*heapOopSize, 1.2907 - this_klass->external_name()); 1.2908 - } else if( nonstatic_field_size > orig_nonstatic_field_size ) { 1.2909 - tty->print("[Wasted %d over %d bytes in %s]\n", 1.2910 - (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize, 1.2911 - orig_nonstatic_field_size*heapOopSize, 1.2912 - this_klass->external_name()); 1.2913 - } 1.2914 - } 1.2915 -#endif 1.2916 - 1.2917 -#ifndef PRODUCT 1.2918 - if (PrintFieldLayout) { 1.2919 - print_field_layout(name, 1.2920 - fields, 1.2921 - cp, 1.2922 - instance_size, 1.2923 - first_nonstatic_field_offset, 1.2924 - next_nonstatic_field_offset, 1.2925 - next_static_type_offset); 1.2926 - } 1.2927 -#endif 1.2928 - 1.2929 // preserve result across HandleMark 1.2930 preserve_this_klass = this_klass(); 1.2931 } 1.2932 @@ -4224,9 +4155,40 @@ 1.2933 instanceKlassHandle this_klass (THREAD, preserve_this_klass); 1.2934 debug_only(this_klass->verify();) 1.2935 1.2936 + // Clear class if no error has occurred so destructor doesn't deallocate it 1.2937 + _klass = NULL; 1.2938 return this_klass; 1.2939 } 1.2940 1.2941 +// Destructor to clean up if there's an error 1.2942 +ClassFileParser::~ClassFileParser() { 1.2943 + MetadataFactory::free_metadata(_loader_data, _cp); 1.2944 + MetadataFactory::free_array<u2>(_loader_data, _fields); 1.2945 + 1.2946 + // Free methods 1.2947 + InstanceKlass::deallocate_methods(_loader_data, _methods); 1.2948 + 1.2949 + // beware of the Universe::empty_blah_array!! 1.2950 + if (_inner_classes != Universe::the_empty_short_array()) { 1.2951 + MetadataFactory::free_array<u2>(_loader_data, _inner_classes); 1.2952 + } 1.2953 + 1.2954 + // Free interfaces 1.2955 + InstanceKlass::deallocate_interfaces(_loader_data, _super_klass(), 1.2956 + _local_interfaces, _transitive_interfaces); 1.2957 + 1.2958 + MetadataFactory::free_array<u1>(_loader_data, _annotations); 1.2959 + MetadataFactory::free_array<u1>(_loader_data, _type_annotations); 1.2960 + Annotations::free_contents(_loader_data, _fields_annotations); 1.2961 + Annotations::free_contents(_loader_data, _fields_type_annotations); 1.2962 + 1.2963 + clear_class_metadata(); 1.2964 + 1.2965 + // deallocate the klass if already created. 1.2966 + MetadataFactory::free_metadata(_loader_data, _klass); 1.2967 + _klass = NULL; 1.2968 +} 1.2969 + 1.2970 void ClassFileParser::print_field_layout(Symbol* name, 1.2971 Array<u2>* fields, 1.2972 constantPoolHandle cp, 1.2973 @@ -4418,7 +4380,7 @@ 1.2974 } 1.2975 } 1.2976 1.2977 -// utility method for appending and array with check for duplicates 1.2978 +// utility methods for appending an array with check for duplicates 1.2979 1.2980 void append_interfaces(GrowableArray<Klass*>* result, Array<Klass*>* ifs) { 1.2981 // iterate over new interfaces 1.2982 @@ -4430,8 +4392,9 @@ 1.2983 } 1.2984 } 1.2985 1.2986 - 1.2987 -Array<Klass*>* ClassFileParser::compute_transitive_interfaces(ClassLoaderData* loader_data, instanceKlassHandle super, Array<Klass*>* local_ifs, TRAPS) { 1.2988 +Array<Klass*>* ClassFileParser::compute_transitive_interfaces( 1.2989 + instanceKlassHandle super, 1.2990 + Array<Klass*>* local_ifs, TRAPS) { 1.2991 // Compute maximum size for transitive interfaces 1.2992 int max_transitive_size = 0; 1.2993 int super_size = 0; 1.2994 @@ -4478,7 +4441,7 @@ 1.2995 // length will be less than the max_transitive_size if duplicates were removed 1.2996 int length = result->length(); 1.2997 assert(length <= max_transitive_size, "just checking"); 1.2998 - Array<Klass*>* new_result = MetadataFactory::new_array<Klass*>(loader_data, length, CHECK_NULL); 1.2999 + Array<Klass*>* new_result = MetadataFactory::new_array<Klass*>(_loader_data, length, CHECK_NULL); 1.3000 for (int i = 0; i < length; i++) { 1.3001 Klass* e = result->at(i); 1.3002 assert(e != NULL, "just checking"); 1.3003 @@ -4488,7 +4451,6 @@ 1.3004 } 1.3005 } 1.3006 1.3007 - 1.3008 void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) { 1.3009 Klass* super = this_klass->super(); 1.3010 if ((super != NULL) &&
2.1 --- a/src/share/vm/classfile/classFileParser.hpp Wed Mar 13 15:15:56 2013 -0400 2.2 +++ b/src/share/vm/classfile/classFileParser.hpp Wed Mar 13 17:34:29 2013 -0400 2.3 @@ -34,6 +34,7 @@ 2.4 #include "classfile/symbolTable.hpp" 2.5 2.6 class FieldAllocationCount; 2.7 +class FieldLayoutInfo; 2.8 2.9 2.10 // Parser for for .class files 2.11 @@ -47,6 +48,7 @@ 2.12 u2 _major_version; 2.13 u2 _minor_version; 2.14 Symbol* _class_name; 2.15 + ClassLoaderData* _loader_data; 2.16 KlassHandle _host_klass; 2.17 GrowableArray<Handle>* _cp_patches; // overrides for CP entries 2.18 2.19 @@ -58,33 +60,59 @@ 2.20 2.21 // class attributes parsed before the instance klass is created: 2.22 bool _synthetic_flag; 2.23 + int _sde_length; 2.24 + char* _sde_buffer; 2.25 Symbol* _sourcefile; 2.26 Symbol* _generic_signature; 2.27 - char* _sde_buffer; 2.28 - int _sde_length; 2.29 - Array<u2>* _inner_classes; 2.30 + 2.31 + // Metadata created before the instance klass is created. Must be deallocated 2.32 + // if not transferred to the InstanceKlass upon successful class loading 2.33 + // in which case these pointers have been set to NULL. 2.34 + instanceKlassHandle _super_klass; 2.35 + ConstantPool* _cp; 2.36 + Array<u2>* _fields; 2.37 + Array<Method*>* _methods; 2.38 + Array<u2>* _inner_classes; 2.39 + Array<Klass*>* _local_interfaces; 2.40 + Array<Klass*>* _transitive_interfaces; 2.41 AnnotationArray* _annotations; 2.42 AnnotationArray* _type_annotations; 2.43 + Array<AnnotationArray*>* _fields_annotations; 2.44 + Array<AnnotationArray*>* _fields_type_annotations; 2.45 + InstanceKlass* _klass; // InstanceKlass once created. 2.46 2.47 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; } 2.48 void set_class_sourcefile(Symbol* x) { _sourcefile = x; } 2.49 void set_class_generic_signature(Symbol* x) { _generic_signature = x; } 2.50 void set_class_sde_buffer(char* x, int len) { _sde_buffer = x; _sde_length = len; } 2.51 - void set_class_inner_classes(Array<u2>* x) { _inner_classes = x; } 2.52 - void set_class_annotations(AnnotationArray* x) { _annotations = x; } 2.53 - void set_class_type_annotations(AnnotationArray* x) { _type_annotations = x; } 2.54 - void init_parsed_class_attributes() { 2.55 + 2.56 + void init_parsed_class_attributes(ClassLoaderData* loader_data) { 2.57 + _loader_data = loader_data; 2.58 _synthetic_flag = false; 2.59 _sourcefile = NULL; 2.60 _generic_signature = NULL; 2.61 _sde_buffer = NULL; 2.62 _sde_length = 0; 2.63 - _annotations = _type_annotations = NULL; 2.64 // initialize the other flags too: 2.65 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false; 2.66 _max_bootstrap_specifier_index = -1; 2.67 + clear_class_metadata(); 2.68 + _klass = NULL; 2.69 } 2.70 void apply_parsed_class_attributes(instanceKlassHandle k); // update k 2.71 + void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS); 2.72 + void clear_class_metadata() { 2.73 + // metadata created before the instance klass is created. Must be 2.74 + // deallocated if classfile parsing returns an error. 2.75 + _cp = NULL; 2.76 + _fields = NULL; 2.77 + _methods = NULL; 2.78 + _inner_classes = NULL; 2.79 + _local_interfaces = NULL; 2.80 + _transitive_interfaces = NULL; 2.81 + _annotations = _type_annotations = NULL; 2.82 + _fields_annotations = _fields_type_annotations = NULL; 2.83 + } 2.84 2.85 class AnnotationCollector { 2.86 public: 2.87 @@ -124,11 +152,27 @@ 2.88 void set_contended(bool contended) { set_annotation(_sun_misc_Contended); } 2.89 bool is_contended() { return has_annotation(_sun_misc_Contended); } 2.90 }; 2.91 + 2.92 + // This class also doubles as a holder for metadata cleanup. 2.93 class FieldAnnotationCollector: public AnnotationCollector { 2.94 + ClassLoaderData* _loader_data; 2.95 + AnnotationArray* _field_annotations; 2.96 + AnnotationArray* _field_type_annotations; 2.97 public: 2.98 - FieldAnnotationCollector() : AnnotationCollector(_in_field) { } 2.99 + FieldAnnotationCollector(ClassLoaderData* loader_data) : 2.100 + AnnotationCollector(_in_field), 2.101 + _loader_data(loader_data), 2.102 + _field_annotations(NULL), 2.103 + _field_type_annotations(NULL) {} 2.104 void apply_to(FieldInfo* f); 2.105 + ~FieldAnnotationCollector(); 2.106 + AnnotationArray* field_annotations() { return _field_annotations; } 2.107 + AnnotationArray* field_type_annotations() { return _field_type_annotations; } 2.108 + 2.109 + void set_field_annotations(AnnotationArray* a) { _field_annotations = a; } 2.110 + void set_field_type_annotations(AnnotationArray* a) { _field_type_annotations = a; } 2.111 }; 2.112 + 2.113 class MethodAnnotationCollector: public AnnotationCollector { 2.114 public: 2.115 MethodAnnotationCollector() : AnnotationCollector(_in_method) { } 2.116 @@ -152,38 +196,30 @@ 2.117 void set_stream(ClassFileStream* st) { _stream = st; } 2.118 2.119 // Constant pool parsing 2.120 - void parse_constant_pool_entries(ClassLoaderData* loader_data, 2.121 - constantPoolHandle cp, int length, TRAPS); 2.122 + void parse_constant_pool_entries(int length, TRAPS); 2.123 2.124 - constantPoolHandle parse_constant_pool(ClassLoaderData* loader_data, TRAPS); 2.125 + constantPoolHandle parse_constant_pool(TRAPS); 2.126 2.127 // Interface parsing 2.128 - Array<Klass*>* parse_interfaces(constantPoolHandle cp, 2.129 - int length, 2.130 - ClassLoaderData* loader_data, 2.131 + Array<Klass*>* parse_interfaces(int length, 2.132 Handle protection_domain, 2.133 Symbol* class_name, 2.134 bool* has_default_methods, 2.135 TRAPS); 2.136 void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS); 2.137 2.138 + instanceKlassHandle parse_super_class(int super_class_index, TRAPS); 2.139 // Field parsing 2.140 - void parse_field_attributes(ClassLoaderData* loader_data, 2.141 - constantPoolHandle cp, u2 attributes_count, 2.142 + void parse_field_attributes(u2 attributes_count, 2.143 bool is_static, u2 signature_index, 2.144 u2* constantvalue_index_addr, 2.145 bool* is_synthetic_addr, 2.146 u2* generic_signature_index_addr, 2.147 - AnnotationArray** field_annotations, 2.148 - AnnotationArray** field_type_annotations, 2.149 FieldAnnotationCollector* parsed_annotations, 2.150 TRAPS); 2.151 - Array<u2>* parse_fields(ClassLoaderData* loader_data, 2.152 - Symbol* class_name, 2.153 - constantPoolHandle cp, bool is_interface, 2.154 + Array<u2>* parse_fields(Symbol* class_name, 2.155 + bool is_interface, 2.156 FieldAllocationCount *fac, 2.157 - Array<AnnotationArray*>** fields_annotations, 2.158 - Array<AnnotationArray*>** fields_type_annotations, 2.159 u2* java_fields_count_ptr, TRAPS); 2.160 2.161 void print_field_layout(Symbol* name, 2.162 @@ -195,65 +231,52 @@ 2.163 int static_fields_end); 2.164 2.165 // Method parsing 2.166 - methodHandle parse_method(ClassLoaderData* loader_data, 2.167 - constantPoolHandle cp, 2.168 - bool is_interface, 2.169 + methodHandle parse_method(bool is_interface, 2.170 AccessFlags* promoted_flags, 2.171 TRAPS); 2.172 - Array<Method*>* parse_methods(ClassLoaderData* loader_data, 2.173 - constantPoolHandle cp, 2.174 - bool is_interface, 2.175 + Array<Method*>* parse_methods(bool is_interface, 2.176 AccessFlags* promoted_flags, 2.177 bool* has_final_method, 2.178 bool* has_default_method, 2.179 TRAPS); 2.180 - Array<int>* sort_methods(ClassLoaderData* loader_data, 2.181 - Array<Method*>* methods, 2.182 - TRAPS); 2.183 - u2* parse_exception_table(ClassLoaderData* loader_data, 2.184 - u4 code_length, u4 exception_table_length, 2.185 - constantPoolHandle cp, TRAPS); 2.186 + intArray* sort_methods(Array<Method*>* methods); 2.187 + 2.188 + u2* parse_exception_table(u4 code_length, u4 exception_table_length, 2.189 + TRAPS); 2.190 void parse_linenumber_table( 2.191 u4 code_attribute_length, u4 code_length, 2.192 CompressedLineNumberWriteStream** write_stream, TRAPS); 2.193 u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length, 2.194 - constantPoolHandle cp, u2* localvariable_table_length, 2.195 + u2* localvariable_table_length, 2.196 bool isLVTT, TRAPS); 2.197 u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length, 2.198 - constantPoolHandle cp, TRAPS); 2.199 + TRAPS); 2.200 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, 2.201 - u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS); 2.202 - Array<u1>* parse_stackmap_table(ClassLoaderData* loader_data, u4 code_attribute_length, TRAPS); 2.203 + u1* u1_array, u2* u2_array, TRAPS); 2.204 + u1* parse_stackmap_table(u4 code_attribute_length, TRAPS); 2.205 2.206 // Classfile attribute parsing 2.207 - void parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS); 2.208 - void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, 2.209 - int length, TRAPS); 2.210 - u2 parse_classfile_inner_classes_attribute(ClassLoaderData* loader_data, 2.211 - u1* inner_classes_attribute_start, 2.212 + void parse_classfile_sourcefile_attribute(TRAPS); 2.213 + void parse_classfile_source_debug_extension_attribute(int length, TRAPS); 2.214 + u2 parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, 2.215 bool parsed_enclosingmethod_attribute, 2.216 u2 enclosing_method_class_index, 2.217 u2 enclosing_method_method_index, 2.218 - constantPoolHandle cp, 2.219 TRAPS); 2.220 - void parse_classfile_attributes(ClassLoaderData* loader_data, 2.221 - constantPoolHandle cp, 2.222 - ClassAnnotationCollector* parsed_annotations, 2.223 + void parse_classfile_attributes(ClassAnnotationCollector* parsed_annotations, 2.224 TRAPS); 2.225 - void parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS); 2.226 - void parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS); 2.227 - void parse_classfile_bootstrap_methods_attribute(ClassLoaderData* loader_data, constantPoolHandle cp, u4 attribute_length, TRAPS); 2.228 + void parse_classfile_synthetic_attribute(TRAPS); 2.229 + void parse_classfile_signature_attribute(TRAPS); 2.230 + void parse_classfile_bootstrap_methods_attribute(u4 attribute_length, TRAPS); 2.231 2.232 // Annotations handling 2.233 - AnnotationArray* assemble_annotations(ClassLoaderData* loader_data, 2.234 - u1* runtime_visible_annotations, 2.235 + AnnotationArray* assemble_annotations(u1* runtime_visible_annotations, 2.236 int runtime_visible_annotations_length, 2.237 u1* runtime_invisible_annotations, 2.238 int runtime_invisible_annotations_length, TRAPS); 2.239 int skip_annotation(u1* buffer, int limit, int index); 2.240 int skip_annotation_value(u1* buffer, int limit, int index); 2.241 - void parse_annotations(ClassLoaderData* loader_data, 2.242 - u1* buffer, int limit, constantPoolHandle cp, 2.243 + void parse_annotations(u1* buffer, int limit, 2.244 /* Results (currently, only one result is supported): */ 2.245 AnnotationCollector* result, 2.246 TRAPS); 2.247 @@ -267,8 +290,7 @@ 2.248 int* nonstatic_oop_offsets, 2.249 unsigned int* nonstatic_oop_counts); 2.250 void set_precomputed_flags(instanceKlassHandle k); 2.251 - Array<Klass*>* compute_transitive_interfaces(ClassLoaderData* loader_data, 2.252 - instanceKlassHandle super, 2.253 + Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super, 2.254 Array<Klass*>* local_ifs, TRAPS); 2.255 2.256 // Format checker methods 2.257 @@ -318,7 +340,7 @@ 2.258 bool is_supported_version(u2 major, u2 minor); 2.259 bool has_illegal_visibility(jint flags); 2.260 2.261 - void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS); 2.262 + void verify_constantvalue(int constantvalue_index, int signature_index, TRAPS); 2.263 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS); 2.264 void verify_legal_class_name(Symbol* name, TRAPS); 2.265 void verify_legal_field_name(Symbol* name, TRAPS); 2.266 @@ -359,10 +381,17 @@ 2.267 // In older versions of the VM, Klass*s cannot sneak into early phases of 2.268 // constant pool construction, but in later versions they can. 2.269 // %%% Let's phase out the old is_klass_reference. 2.270 - bool is_klass_reference(constantPoolHandle cp, int index) { 2.271 - return (EnableInvokeDynamic 2.272 - ? cp->tag_at(index).is_klass_or_reference() 2.273 - : cp->tag_at(index).is_klass_reference()); 2.274 + bool valid_klass_reference_at(int index) { 2.275 + return _cp->is_within_bounds(index) && 2.276 + (EnableInvokeDynamic 2.277 + ? _cp->tag_at(index).is_klass_or_reference() 2.278 + : _cp->tag_at(index).is_klass_reference()); 2.279 + } 2.280 + 2.281 + // Checks that the cpool index is in range and is a utf8 2.282 + bool valid_symbol_at(int cpool_index) { 2.283 + return (_cp->is_within_bounds(cpool_index) && 2.284 + _cp->tag_at(cpool_index).is_utf8()); 2.285 } 2.286 2.287 void copy_localvariable_table(ConstMethod* cm, int lvt_cnt, 2.288 @@ -373,8 +402,7 @@ 2.289 u2** localvariable_type_table_start, 2.290 TRAPS); 2.291 2.292 - void copy_method_annotations(ClassLoaderData* loader_data, 2.293 - ConstMethod* cm, 2.294 + void copy_method_annotations(ConstMethod* cm, 2.295 u1* runtime_visible_annotations, 2.296 int runtime_visible_annotations_length, 2.297 u1* runtime_invisible_annotations, 2.298 @@ -391,9 +419,15 @@ 2.299 int annotation_default_length, 2.300 TRAPS); 2.301 2.302 + // lays out fields in class and returns the total oopmap count 2.303 + void layout_fields(Handle class_loader, FieldAllocationCount* fac, 2.304 + ClassAnnotationCollector* parsed_annotations, 2.305 + FieldLayoutInfo* info, TRAPS); 2.306 + 2.307 public: 2.308 // Constructor 2.309 ClassFileParser(ClassFileStream* st) { set_stream(st); } 2.310 + ~ClassFileParser(); 2.311 2.312 // Parse .class file and return new Klass*. The Klass* is not hooked up 2.313 // to the system dictionary or any other structures, so a .class file can
3.1 --- a/src/share/vm/oops/constMethod.cpp Wed Mar 13 15:15:56 2013 -0400 3.2 +++ b/src/share/vm/oops/constMethod.cpp Wed Mar 13 17:34:29 2013 -0400 3.3 @@ -67,6 +67,12 @@ 3.4 set_size_of_parameters(0); 3.5 } 3.6 3.7 +// Accessor that copies to metadata. 3.8 +void ConstMethod::copy_stackmap_data(ClassLoaderData* loader_data, 3.9 + u1* sd, int length, TRAPS) { 3.10 + _stackmap_data = MetadataFactory::new_array<u1>(loader_data, length, CHECK); 3.11 + memcpy((void*)_stackmap_data->adr_at(0), (void*)sd, length); 3.12 +} 3.13 3.14 // Deallocate metadata fields associated with ConstMethod* 3.15 void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
4.1 --- a/src/share/vm/oops/constMethod.hpp Wed Mar 13 15:15:56 2013 -0400 4.2 +++ b/src/share/vm/oops/constMethod.hpp Wed Mar 13 17:34:29 2013 -0400 4.3 @@ -280,6 +280,7 @@ 4.4 // stackmap table data 4.5 Array<u1>* stackmap_data() const { return _stackmap_data; } 4.6 void set_stackmap_data(Array<u1>* sd) { _stackmap_data = sd; } 4.7 + void copy_stackmap_data(ClassLoaderData* loader_data, u1* sd, int length, TRAPS); 4.8 bool has_stackmap_table() const { return _stackmap_data != NULL; } 4.9 4.10 void init_fingerprint() {
5.1 --- a/src/share/vm/oops/instanceKlass.cpp Wed Mar 13 15:15:56 2013 -0400 5.2 +++ b/src/share/vm/oops/instanceKlass.cpp Wed Mar 13 17:34:29 2013 -0400 5.3 @@ -165,7 +165,8 @@ 5.4 5.5 volatile int InstanceKlass::_total_instanceKlass_count = 0; 5.6 5.7 -Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data, 5.8 +InstanceKlass* InstanceKlass::allocate_instance_klass( 5.9 + ClassLoaderData* loader_data, 5.10 int vtable_len, 5.11 int itable_len, 5.12 int static_field_size, 5.13 @@ -207,10 +208,35 @@ 5.14 access_flags, is_anonymous); 5.15 } 5.16 5.17 + // Check for pending exception before adding to the loader data and incrementing 5.18 + // class count. Can get OOM here. 5.19 + if (HAS_PENDING_EXCEPTION) { 5.20 + return NULL; 5.21 + } 5.22 + 5.23 + // Add all classes to our internal class loader list here, 5.24 + // including classes in the bootstrap (NULL) class loader. 5.25 + loader_data->add_class(ik); 5.26 + 5.27 Atomic::inc(&_total_instanceKlass_count); 5.28 return ik; 5.29 } 5.30 5.31 + 5.32 +// copy method ordering from resource area to Metaspace 5.33 +void InstanceKlass::copy_method_ordering(intArray* m, TRAPS) { 5.34 + if (m != NULL) { 5.35 + // allocate a new array and copy contents (memcpy?) 5.36 + _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK); 5.37 + for (int i = 0; i < m->length(); i++) { 5.38 + _method_ordering->at_put(i, m->at(i)); 5.39 + } 5.40 + } else { 5.41 + _method_ordering = Universe::the_empty_int_array(); 5.42 + } 5.43 +} 5.44 + 5.45 + 5.46 InstanceKlass::InstanceKlass(int vtable_len, 5.47 int itable_len, 5.48 int static_field_size, 5.49 @@ -223,9 +249,6 @@ 5.50 int iksize = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, 5.51 access_flags.is_interface(), is_anonymous); 5.52 5.53 - // The sizes of these these three variables are used for determining the 5.54 - // size of the instanceKlassOop. It is critical that these are set to the right 5.55 - // sizes before the first GC, i.e., when we allocate the mirror. 5.56 set_vtable_length(vtable_len); 5.57 set_itable_length(itable_len); 5.58 set_static_field_size(static_field_size); 5.59 @@ -288,12 +311,51 @@ 5.60 } 5.61 5.62 5.63 +void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data, 5.64 + Array<Method*>* methods) { 5.65 + if (methods != NULL && methods != Universe::the_empty_method_array()) { 5.66 + for (int i = 0; i < methods->length(); i++) { 5.67 + Method* method = methods->at(i); 5.68 + if (method == NULL) continue; // maybe null if error processing 5.69 + // Only want to delete methods that are not executing for RedefineClasses. 5.70 + // The previous version will point to them so they're not totally dangling 5.71 + assert (!method->on_stack(), "shouldn't be called with methods on stack"); 5.72 + MetadataFactory::free_metadata(loader_data, method); 5.73 + } 5.74 + MetadataFactory::free_array<Method*>(loader_data, methods); 5.75 + } 5.76 +} 5.77 + 5.78 +void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data, 5.79 + Klass* super_klass, 5.80 + Array<Klass*>* local_interfaces, 5.81 + Array<Klass*>* transitive_interfaces) { 5.82 + // Only deallocate transitive interfaces if not empty, same as super class 5.83 + // or same as local interfaces. See code in parseClassFile. 5.84 + Array<Klass*>* ti = transitive_interfaces; 5.85 + if (ti != Universe::the_empty_klass_array() && ti != local_interfaces) { 5.86 + // check that the interfaces don't come from super class 5.87 + Array<Klass*>* sti = (super_klass == NULL) ? NULL : 5.88 + InstanceKlass::cast(super_klass)->transitive_interfaces(); 5.89 + if (ti != sti) { 5.90 + MetadataFactory::free_array<Klass*>(loader_data, ti); 5.91 + } 5.92 + } 5.93 + 5.94 + // local interfaces can be empty 5.95 + if (local_interfaces != Universe::the_empty_klass_array()) { 5.96 + MetadataFactory::free_array<Klass*>(loader_data, local_interfaces); 5.97 + } 5.98 +} 5.99 + 5.100 // This function deallocates the metadata and C heap pointers that the 5.101 // InstanceKlass points to. 5.102 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { 5.103 5.104 // Orphan the mirror first, CMS thinks it's still live. 5.105 - java_lang_Class::set_klass(java_mirror(), NULL); 5.106 + if (java_mirror() != NULL) { 5.107 + java_lang_Class::set_klass(java_mirror(), NULL); 5.108 + } 5.109 5.110 // Need to take this class off the class loader data list. 5.111 loader_data->remove_class(this); 5.112 @@ -308,17 +370,7 @@ 5.113 // reference counting symbol names. 5.114 release_C_heap_structures(); 5.115 5.116 - Array<Method*>* ms = methods(); 5.117 - if (ms != Universe::the_empty_method_array()) { 5.118 - for (int i = 0; i <= methods()->length() -1 ; i++) { 5.119 - Method* method = methods()->at(i); 5.120 - // Only want to delete methods that are not executing for RedefineClasses. 5.121 - // The previous version will point to them so they're not totally dangling 5.122 - assert (!method->on_stack(), "shouldn't be called with methods on stack"); 5.123 - MetadataFactory::free_metadata(loader_data, method); 5.124 - } 5.125 - MetadataFactory::free_array<Method*>(loader_data, methods()); 5.126 - } 5.127 + deallocate_methods(loader_data, methods()); 5.128 set_methods(NULL); 5.129 5.130 if (method_ordering() != Universe::the_empty_int_array()) { 5.131 @@ -335,24 +387,8 @@ 5.132 } 5.133 set_secondary_supers(NULL); 5.134 5.135 - // Only deallocate transitive interfaces if not empty, same as super class 5.136 - // or same as local interfaces. See code in parseClassFile. 5.137 - Array<Klass*>* ti = transitive_interfaces(); 5.138 - if (ti != Universe::the_empty_klass_array() && ti != local_interfaces()) { 5.139 - // check that the interfaces don't come from super class 5.140 - Array<Klass*>* sti = (super() == NULL) ? NULL : 5.141 - InstanceKlass::cast(super())->transitive_interfaces(); 5.142 - if (ti != sti) { 5.143 - MetadataFactory::free_array<Klass*>(loader_data, ti); 5.144 - } 5.145 - } 5.146 + deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces()); 5.147 set_transitive_interfaces(NULL); 5.148 - 5.149 - // local interfaces can be empty 5.150 - Array<Klass*>* li = local_interfaces(); 5.151 - if (li != Universe::the_empty_klass_array()) { 5.152 - MetadataFactory::free_array<Klass*>(loader_data, li); 5.153 - } 5.154 set_local_interfaces(NULL); 5.155 5.156 MetadataFactory::free_array<jushort>(loader_data, fields()); 5.157 @@ -360,9 +396,11 @@ 5.158 5.159 // If a method from a redefined class is using this constant pool, don't 5.160 // delete it, yet. The new class's previous version will point to this. 5.161 - assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); 5.162 - MetadataFactory::free_metadata(loader_data, constants()); 5.163 - set_constants(NULL); 5.164 + if (constants() != NULL) { 5.165 + assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); 5.166 + MetadataFactory::free_metadata(loader_data, constants()); 5.167 + set_constants(NULL); 5.168 + } 5.169 5.170 if (inner_classes() != Universe::the_empty_short_array()) { 5.171 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
6.1 --- a/src/share/vm/oops/instanceKlass.hpp Wed Mar 13 15:15:56 2013 -0400 6.2 +++ b/src/share/vm/oops/instanceKlass.hpp Wed Mar 13 17:34:29 2013 -0400 6.3 @@ -147,7 +147,8 @@ 6.4 AccessFlags access_flags, 6.5 bool is_anonymous); 6.6 public: 6.7 - static Klass* allocate_instance_klass(ClassLoaderData* loader_data, 6.8 + static InstanceKlass* allocate_instance_klass( 6.9 + ClassLoaderData* loader_data, 6.10 int vtable_len, 6.11 int itable_len, 6.12 int static_field_size, 6.13 @@ -266,7 +267,6 @@ 6.14 u1 _init_state; // state of class 6.15 u1 _reference_type; // reference type 6.16 6.17 - 6.18 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration 6.19 6.20 NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies 6.21 @@ -358,16 +358,19 @@ 6.22 // method ordering 6.23 Array<int>* method_ordering() const { return _method_ordering; } 6.24 void set_method_ordering(Array<int>* m) { _method_ordering = m; } 6.25 + void copy_method_ordering(intArray* m, TRAPS); 6.26 6.27 // interfaces 6.28 Array<Klass*>* local_interfaces() const { return _local_interfaces; } 6.29 void set_local_interfaces(Array<Klass*>* a) { 6.30 guarantee(_local_interfaces == NULL || a == NULL, "Just checking"); 6.31 _local_interfaces = a; } 6.32 + 6.33 Array<Klass*>* transitive_interfaces() const { return _transitive_interfaces; } 6.34 void set_transitive_interfaces(Array<Klass*>* a) { 6.35 guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking"); 6.36 - _transitive_interfaces = a; } 6.37 + _transitive_interfaces = a; 6.38 + } 6.39 6.40 private: 6.41 friend class fieldDescriptor; 6.42 @@ -383,10 +386,9 @@ 6.43 int java_fields_count() const { return (int)_java_fields_count; } 6.44 6.45 Array<u2>* fields() const { return _fields; } 6.46 - 6.47 void set_fields(Array<u2>* f, u2 java_fields_count) { 6.48 guarantee(_fields == NULL || f == NULL, "Just checking"); 6.49 - _fields = f; 6.50 + _fields = f; 6.51 _java_fields_count = java_fields_count; 6.52 } 6.53 6.54 @@ -916,8 +918,15 @@ 6.55 void clean_method_data(BoolObjectClosure* is_alive); 6.56 6.57 // Explicit metaspace deallocation of fields 6.58 - // For RedefineClasses, we need to deallocate instanceKlasses 6.59 + // For RedefineClasses and class file parsing errors, we need to deallocate 6.60 + // instanceKlasses and the metadata they point to. 6.61 void deallocate_contents(ClassLoaderData* loader_data); 6.62 + static void deallocate_methods(ClassLoaderData* loader_data, 6.63 + Array<Method*>* methods); 6.64 + void static deallocate_interfaces(ClassLoaderData* loader_data, 6.65 + Klass* super_klass, 6.66 + Array<Klass*>* local_interfaces, 6.67 + Array<Klass*>* transitive_interfaces); 6.68 6.69 // The constant pool is on stack if any of the methods are executing or 6.70 // referenced by handles.