1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
| instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, ClassLoaderData* loader_data, Handle protection_domain, KlassHandle host_klass, GrowableArray<Handle>* cp_patches, TempNewSymbol& parsed_name, bool verify, TRAPS) {
JvmtiCachedClassFileData *cached_class_file = NULL; Handle class_loader(THREAD, loader_data->class_loader()); bool has_default_methods = false; bool declares_default_methods = false;
ClassFileStream* cfs = stream(); assert(THREAD->is_Java_thread(), "must be a JavaThread"); JavaThread* jt = (JavaThread*) THREAD;
PerfClassTraceTime ctimer(ClassLoader::perf_class_parse_time(), ClassLoader::perf_class_parse_selftime(), NULL, jt->get_thread_stat()->perf_recursion_counts_addr(), jt->get_thread_stat()->perf_timers_addr(), PerfClassTraceTime::PARSE_CLASS);
init_parsed_class_attributes(loader_data);
if (JvmtiExport::should_post_class_file_load_hook()) { JvmtiThreadState *state = jt->jvmti_thread_state(); if (state != NULL) { KlassHandle *h_class_being_redefined = state->get_class_being_redefined(); if (h_class_being_redefined != NULL) { instanceKlassHandle ikh_class_being_redefined = instanceKlassHandle(THREAD, (*h_class_being_redefined)()); cached_class_file = ikh_class_being_redefined->get_cached_class_file(); } }
unsigned char* ptr = cfs->buffer(); unsigned char* end_ptr = cfs->buffer() + cfs->length();
JvmtiExport::post_class_file_load_hook(name, class_loader(), protection_domain, &ptr, &end_ptr, &cached_class_file);
if (ptr != cfs->buffer()) { cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source()); set_stream(cfs); } }
_host_klass = host_klass; _cp_patches = cp_patches;
instanceKlassHandle nullHandle;
if (DumpSharedSpaces) { _need_verify = (verify) ? BytecodeVerificationRemote : BytecodeVerificationLocal; } else { _need_verify = Verifier::should_verify_for(class_loader(), verify); }
cfs->set_verify(_need_verify);
_class_name = (name != NULL) ? name : vmSymbols::unknown_class_name();
cfs->guarantee_more(8, CHECK_(nullHandle)); u4 magic = cfs->get_u4_fast(); guarantee_property(magic == JAVA_CLASSFILE_MAGIC, "Incompatible magic value %u in class file %s", magic, CHECK_(nullHandle));
u2 minor_version = cfs->get_u2_fast(); u2 major_version = cfs->get_u2_fast();
if (DumpSharedSpaces && major_version < JAVA_1_5_VERSION) { ResourceMark rm; warning("Pre JDK 1.5 class not supported by CDS: %u.%u %s", major_version, minor_version, name->as_C_string()); Exceptions::fthrow( THREAD_AND_LOCATION, vmSymbols::java_lang_UnsupportedClassVersionError(), "Unsupported major.minor version for dump time %u.%u", major_version, minor_version); }
if (!is_supported_version(major_version, minor_version)) { if (name == NULL) { Exceptions::fthrow( THREAD_AND_LOCATION, vmSymbols::java_lang_UnsupportedClassVersionError(), "Unsupported class file version %u.%u, " "this version of the Java Runtime only recognizes class file versions up to %u.%u", major_version, minor_version, JAVA_MAX_SUPPORTED_VERSION, JAVA_MAX_SUPPORTED_MINOR_VERSION); } else { ResourceMark rm(THREAD); Exceptions::fthrow( THREAD_AND_LOCATION, vmSymbols::java_lang_UnsupportedClassVersionError(), "%s has been compiled by a more recent version of the Java Runtime (class file version %u.%u), " "this version of the Java Runtime only recognizes class file versions up to %u.%u", name->as_C_string(), major_version, minor_version, JAVA_MAX_SUPPORTED_VERSION, JAVA_MAX_SUPPORTED_MINOR_VERSION); } return nullHandle; }
_major_version = major_version; _minor_version = minor_version;
_relax_verify = relax_format_check_for(_loader_data);
constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle));
int cp_size = cp->length();
cfs->guarantee_more(8, CHECK_(nullHandle));
AccessFlags access_flags; jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) { flags |= JVM_ACC_ABSTRACT; } verify_legal_class_modifiers(flags, CHECK_(nullHandle)); access_flags.set_flags(flags);
_this_class_index = cfs->get_u2_fast(); check_property( valid_cp_range(_this_class_index, cp_size) && cp->tag_at(_this_class_index).is_unresolved_klass(), "Invalid this class index %u in constant pool in class file %s", _this_class_index, CHECK_(nullHandle));
Symbol* class_name = cp->unresolved_klass_at(_this_class_index); assert(class_name != NULL, "class_name can't be null");
parsed_name = class_name; parsed_name->increment_refcount();
_class_name = class_name;
if (_need_verify) { guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY, "Bad class name in class file %s", CHECK_(nullHandle)); }
Klass* preserve_this_klass;
{ HandleMark hm(THREAD);
if (name != NULL && class_name != name) { ResourceMark rm(THREAD); Exceptions::fthrow( THREAD_AND_LOCATION, vmSymbols::java_lang_NoClassDefFoundError(), "%s (wrong name: %s)", name->as_C_string(), class_name->as_C_string() ); return nullHandle; }
if (TraceClassLoadingPreorder) { tty->print("[Loading %s", (name != NULL) ? name->as_klass_external_name() : "NoName"); if (cfs->source() != NULL) tty->print(" from %s", cfs->source()); tty->print_cr("]"); } #if INCLUDE_CDS if (DumpLoadedClassList != NULL && cfs->source() != NULL && classlist_file->is_open()) { if (SystemDictionaryShared::is_sharing_possible(loader_data)) { if (name != NULL) { ResourceMark rm(THREAD); classlist_file->print_cr("%s", name->as_C_string()); classlist_file->flush(); } } } #endif
u2 super_class_index = cfs->get_u2_fast(); instanceKlassHandle super_klass = parse_super_class(super_class_index, CHECK_NULL);
u2 itfs_len = cfs->get_u2_fast(); Array<Klass*>* local_interfaces = parse_interfaces(itfs_len, protection_domain, _class_name, &has_default_methods, CHECK_(nullHandle));
u2 java_fields_count = 0; FieldAllocationCount fac; Array<u2>* fields = parse_fields(class_name, access_flags.is_interface(), &fac, &java_fields_count, CHECK_(nullHandle)); bool has_final_method = false; AccessFlags promoted_flags; promoted_flags.set_flags(0); Array<Method*>* methods = parse_methods(access_flags.is_interface(), &promoted_flags, &has_final_method, &declares_default_methods, CHECK_(nullHandle)); if (declares_default_methods) { has_default_methods = true; }
ClassAnnotationCollector parsed_annotations; parse_classfile_attributes(&parsed_annotations, CHECK_(nullHandle));
create_combined_annotations(CHECK_(nullHandle));
guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
if (_class_name == vmSymbols::java_lang_Object()) { check_property(_local_interfaces == Universe::the_empty_klass_array(), "java.lang.Object cannot implement an interface in class file %s", CHECK_(nullHandle)); } if (super_class_index > 0 && super_klass.is_null()) { Symbol* sk = cp->klass_name_at(super_class_index); if (access_flags.is_interface()) { guarantee_property(sk == vmSymbols::java_lang_Object(), "Interfaces must have java.lang.Object as superclass in class file %s", CHECK_(nullHandle)); } Klass* k = SystemDictionary::resolve_super_or_fail(class_name, sk, class_loader, protection_domain, true, CHECK_(nullHandle));
KlassHandle kh (THREAD, k); super_klass = instanceKlassHandle(THREAD, kh()); } if (super_klass.not_null()) {
if (super_klass->has_default_methods()) { has_default_methods = true; }
if (super_klass->is_interface()) { ResourceMark rm(THREAD); Exceptions::fthrow( THREAD_AND_LOCATION, vmSymbols::java_lang_IncompatibleClassChangeError(), "class %s has interface %s as super class", class_name->as_klass_external_name(), super_klass->external_name() ); return nullHandle; } if (super_klass->is_final()) { THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle); } }
_super_klass = super_klass;
_transitive_interfaces = compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle));
intArray* method_ordering = sort_methods(methods);
access_flags.add_promoted_flags(promoted_flags.as_int());
int vtable_size = 0; int itable_size = 0; int num_miranda_methods = 0;
GrowableArray<Method*> all_mirandas(20);
klassVtable::compute_vtable_size_and_num_mirandas( &vtable_size, &num_miranda_methods, &all_mirandas, super_klass(), methods, access_flags, class_loader, class_name, local_interfaces, CHECK_(nullHandle));
itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(_transitive_interfaces);
FieldLayoutInfo info; layout_fields(class_loader, &fac, &parsed_annotations, &info, CHECK_NULL);
int total_oop_map_size2 = InstanceKlass::nonstatic_oop_map_size(info.total_oop_map_count);
ReferenceType rt; if (super_klass() == NULL) { rt = REF_NONE; } else { rt = super_klass->reference_type(); }
_klass = InstanceKlass::allocate_instance_klass(loader_data, vtable_size, itable_size, info.static_field_size, total_oop_map_size2, rt, access_flags, name, super_klass(), !host_klass.is_null(), CHECK_(nullHandle)); instanceKlassHandle this_klass (THREAD, _klass);
assert(this_klass->static_field_size() == info.static_field_size, "sanity"); assert(this_klass->nonstatic_oop_map_count() == info.total_oop_map_count, "sanity");
this_klass->set_should_verify_class(verify); jint lh = Klass::instance_layout_helper(info.instance_size, false); this_klass->set_layout_helper(lh); assert(this_klass->oop_is_instance(), "layout is correct"); assert(this_klass->size_helper() == info.instance_size, "correct size_helper"); this_klass->set_class_loader_data(loader_data); this_klass->set_nonstatic_field_size(info.nonstatic_field_size); this_klass->set_has_nonstatic_fields(info.has_nonstatic_fields); this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]);
apply_parsed_class_metadata(this_klass, java_fields_count, CHECK_NULL);
if (has_final_method) { this_klass->set_has_final_method(); } this_klass->copy_method_ordering(method_ordering, CHECK_NULL); this_klass->set_initial_method_idnum(methods->length()); this_klass->set_name(cp->klass_name_at(_this_class_index)); if (is_anonymous()) cp->klass_at_put(_this_class_index, this_klass());
this_klass->set_minor_version(minor_version); this_klass->set_major_version(major_version); this_klass->set_has_default_methods(has_default_methods); this_klass->set_declares_default_methods(declares_default_methods);
if (!host_klass.is_null()) { assert (this_klass->is_anonymous(), "should be the same"); this_klass->set_host_klass(host_klass()); }
if (Method::klass_id_for_intrinsics(this_klass()) != vmSymbols::NO_SID) { for (int j = 0; j < methods->length(); j++) { methods->at(j)->init_intrinsic_id(); } }
if (cached_class_file != NULL) { this_klass->set_cached_class_file(cached_class_file); }
if (parsed_annotations.has_any_annotations()) parsed_annotations.apply_to(this_klass); apply_parsed_class_attributes(this_klass);
if ((num_miranda_methods > 0) || (super_klass.not_null() && (super_klass->has_miranda_methods())) ) { this_klass->set_has_miranda_methods(); }
this_klass->initialize_supers(super_klass(), CHECK_(nullHandle));
klassItable::setup_itable_offset_table(this_klass);
fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.nonstatic_oop_counts);
set_precomputed_flags(this_klass);
int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle)); this_klass->set_modifier_flags(computed_modifiers);
check_super_class_access(this_klass, CHECK_(nullHandle));
check_super_interface_access(this_klass, CHECK_(nullHandle));
check_final_method_override(this_klass, CHECK_(nullHandle));
if (this_klass->is_interface()) { if (_major_version < JAVA_8_VERSION) { check_illegal_static_method(this_klass, CHECK_(nullHandle)); } }
java_lang_Class::create_mirror(this_klass, class_loader, protection_domain, CHECK_(nullHandle));
if (has_default_methods ) { DefaultMethods::generate_default_methods( this_klass(), &all_mirandas, CHECK_(nullHandle)); }
ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), false );
if (TraceClassLoading) { ResourceMark rm; if (cfs->source() != NULL) { tty->print("[Loaded %s from %s]\n", this_klass->external_name(), cfs->source()); } else if (class_loader.is_null()) { Klass* caller = THREAD->is_Java_thread() ? ((JavaThread*)THREAD)->security_get_caller_class(1) : NULL; if (caller != NULL) { tty->print("[Loaded %s by instance of %s]\n", this_klass->external_name(), InstanceKlass::cast(caller)->external_name()); } else { tty->print("[Loaded %s]\n", this_klass->external_name()); } } else { tty->print("[Loaded %s from %s]\n", this_klass->external_name(), InstanceKlass::cast(class_loader->klass())->external_name()); } }
if (TraceClassResolution) { ResourceMark rm; const char * from = this_klass()->external_name(); if (this_klass->java_super() != NULL) { tty->print("RESOLVE %s %s (super)\n", from, InstanceKlass::cast(this_klass->java_super())->external_name()); } Array<Klass*>* local_interfaces = this_klass->local_interfaces(); if (local_interfaces != NULL) { int length = local_interfaces->length(); for (int i = 0; i < length; i++) { Klass* k = local_interfaces->at(i); InstanceKlass* to_class = InstanceKlass::cast(k); const char * to = to_class->external_name(); tty->print("RESOLVE %s %s (interface)\n", from, to); } } }
preserve_this_klass = this_klass(); }
JFR_ONLY(INIT_ID(preserve_this_klass);)
instanceKlassHandle this_klass (THREAD, preserve_this_klass); debug_only(this_klass->verify();)
_klass = NULL; return this_klass; }
|