298 if (k != NULL) { 299 if (k->local_interfaces()->length() != _interfaces->length()) { 300 print_specified_interfaces(); 301 print_actual_interfaces(k); 302 error("The number of interfaces (%d) specified in class list does not match the class file (%d)", 303 _interfaces->length(), k->local_interfaces()->length()); 304 } 305 306 if (!SystemDictionaryShared::add_non_builtin_klass(class_name, ClassLoaderData::the_null_class_loader_data(), 307 k, THREAD)) { 308 error("Duplicated class %s", _class_name); 309 } 310 311 // This tells JVM_FindLoadedClass to not find this class. 312 k->set_shared_classpath_index(UNREGISTERED_INDEX); 313 } 314 315 return k; 316 } 317 318 InstanceKlass* ClassListParser::load_current_class(TRAPS) { 319 TempNewSymbol class_name_symbol = SymbolTable::new_symbol(_class_name, THREAD); 320 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); 321 322 InstanceKlass *klass = NULL; 323 if (!is_loading_from_source()) { 324 if (is_super_specified()) { 325 error("If source location is not specified, super class must not be specified"); 326 } 327 if (are_interfaces_specified()) { 328 error("If source location is not specified, interface(s) must not be specified"); 329 } 330 331 bool non_array = !FieldType::is_array(class_name_symbol); 332 333 Handle s = java_lang_String::create_from_symbol(class_name_symbol, CHECK_0); 334 // Translate to external class name format, i.e., convert '/' chars to '.' 335 Handle string = java_lang_String::externalize_classname(s, CHECK_0); 336 JavaValue result(T_OBJECT); 337 InstanceKlass* spec_klass = non_array ? 338 SystemDictionary::ClassLoader_klass() : SystemDictionary::Class_klass(); 339 Symbol* method_name = non_array ? 340 vmSymbols::loadClass_name() : vmSymbols::forName_name(); 341 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); 342 343 if (non_array) { 344 JavaCalls::call_virtual(&result, 345 loader, //SystemDictionary::java_system_loader(), 346 spec_klass, 347 method_name, //vmSymbols::loadClass_name(), 348 vmSymbols::string_class_signature(), 349 string, 350 THREAD); 351 } else { 352 JavaCalls::call_static(&result, 353 spec_klass, 354 method_name, 355 vmSymbols::string_class_signature(), 356 string, 357 CHECK_NULL); 358 } 359 assert(result.get_type() == T_OBJECT, "just checking"); 360 oop obj = (oop) result.get_jobject(); 361 if (!HAS_PENDING_EXCEPTION && (obj != NULL)) { 362 if (non_array) { 363 klass = InstanceKlass::cast(java_lang_Class::as_Klass(obj)); 364 } else { 365 klass = static_cast<InstanceKlass*>(java_lang_Class::array_klass_acquire(obj)); 366 } 367 } else { // load classes in bootclasspath/a 368 if (HAS_PENDING_EXCEPTION) { 369 CLEAR_PENDING_EXCEPTION; 370 } 371 372 if (non_array) { 373 Klass* k = SystemDictionary::resolve_or_null(class_name_symbol, CHECK_NULL); 374 if (k != NULL) { 375 klass = InstanceKlass::cast(k); 376 } else { 377 if (!HAS_PENDING_EXCEPTION) { 378 THROW_NULL(vmSymbols::java_lang_ClassNotFoundException()); 379 } 380 } 381 } 382 } 383 } else { 384 // If "source:" tag is specified, all super class and super interfaces must be specified in the 385 // class list file. 386 if (UseAppCDS) { 387 klass = load_class_from_source(class_name_symbol, CHECK_NULL); 388 } 389 } 390 391 if (klass != NULL && is_id_specified()) { 392 int id = this->id(); 393 SystemDictionaryShared::update_shared_entry(klass, id); 394 InstanceKlass* old = table()->lookup(id); 395 if (old != NULL && old != klass) { 396 error("Duplicated ID %d for class %s", id, _class_name); 397 } 398 table()->add(id, klass); 399 } 400 401 return klass; 402 } 403 404 bool ClassListParser::is_loading_from_source() { 405 return (_source != NULL); 406 } 407 408 InstanceKlass* ClassListParser::lookup_class_by_id(int id) { 409 InstanceKlass* klass = table()->lookup(id); 410 if (klass == NULL) { 411 error("Class ID %d has not been defined", id); 412 } 413 return klass; 414 } 415 416 417 InstanceKlass* ClassListParser::lookup_super_for_current_class(Symbol* super_name) { 418 if (!is_loading_from_source()) { | 298 if (k != NULL) { 299 if (k->local_interfaces()->length() != _interfaces->length()) { 300 print_specified_interfaces(); 301 print_actual_interfaces(k); 302 error("The number of interfaces (%d) specified in class list does not match the class file (%d)", 303 _interfaces->length(), k->local_interfaces()->length()); 304 } 305 306 if (!SystemDictionaryShared::add_non_builtin_klass(class_name, ClassLoaderData::the_null_class_loader_data(), 307 k, THREAD)) { 308 error("Duplicated class %s", _class_name); 309 } 310 311 // This tells JVM_FindLoadedClass to not find this class. 312 k->set_shared_classpath_index(UNREGISTERED_INDEX); 313 } 314 315 return k; 316 } 317 318 Klass* ClassListParser::load_current_class(TRAPS) { 319 TempNewSymbol class_name_symbol = SymbolTable::new_symbol(_class_name, THREAD); 320 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); 321 322 Klass *klass = NULL; 323 if (!is_loading_from_source()) { 324 // Load classes for the boot/platform/app loaders only. 325 if (is_super_specified()) { 326 error("If source location is not specified, super class must not be specified"); 327 } 328 if (are_interfaces_specified()) { 329 error("If source location is not specified, interface(s) must not be specified"); 330 } 331 332 bool non_array = !FieldType::is_array(class_name_symbol); 333 334 JavaValue result(T_OBJECT); 335 if (non_array) { 336 // At this point, we are executing in the context of the boot loader. We 337 // cannot call Class.forName because that is context dependent and 338 // would load only classes for the boot loader. 339 // 340 // Instead, let's call java_system_loader().loadClass() directly, which will 341 // delegate to the correct loader (boot, platform or app) depending on 342 // the class name. 343 344 Handle s = java_lang_String::create_from_symbol(class_name_symbol, CHECK_0); 345 // ClassLoader.loadClass() wants external class name format, i.e., convert '/' chars to '.' 346 Handle ext_class_name = java_lang_String::externalize_classname(s, CHECK_0); 347 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); 348 349 JavaCalls::call_virtual(&result, 350 loader, //SystemDictionary::java_system_loader(), 351 SystemDictionary::ClassLoader_klass(), 352 vmSymbols::loadClass_name(), 353 vmSymbols::string_class_signature(), 354 ext_class_name, 355 THREAD); 356 } else { 357 // array classes are not supported in class list. 358 THROW_NULL(vmSymbols::java_lang_ClassNotFoundException()); 359 } 360 assert(result.get_type() == T_OBJECT, "just checking"); 361 oop obj = (oop) result.get_jobject(); 362 if (!HAS_PENDING_EXCEPTION && (obj != NULL)) { 363 klass = java_lang_Class::as_Klass(obj); 364 } else { // load classes in bootclasspath/a 365 if (HAS_PENDING_EXCEPTION) { 366 CLEAR_PENDING_EXCEPTION; 367 } 368 369 if (non_array) { 370 Klass* k = SystemDictionary::resolve_or_null(class_name_symbol, CHECK_NULL); 371 if (k != NULL) { 372 klass = k; 373 } else { 374 if (!HAS_PENDING_EXCEPTION) { 375 THROW_NULL(vmSymbols::java_lang_ClassNotFoundException()); 376 } 377 } 378 } 379 } 380 } else { 381 // If "source:" tag is specified, all super class and super interfaces must be specified in the 382 // class list file. 383 if (UseAppCDS) { 384 klass = load_class_from_source(class_name_symbol, CHECK_NULL); 385 } 386 } 387 388 if (klass != NULL && klass->is_instance_klass() && is_id_specified()) { 389 InstanceKlass* ik = InstanceKlass::cast(klass); 390 int id = this->id(); 391 SystemDictionaryShared::update_shared_entry(ik, id); 392 InstanceKlass* old = table()->lookup(id); 393 if (old != NULL && old != ik) { 394 error("Duplicated ID %d for class %s", id, _class_name); 395 } 396 table()->add(id, ik); 397 } 398 399 return klass; 400 } 401 402 bool ClassListParser::is_loading_from_source() { 403 return (_source != NULL); 404 } 405 406 InstanceKlass* ClassListParser::lookup_class_by_id(int id) { 407 InstanceKlass* klass = table()->lookup(id); 408 if (klass == NULL) { 409 error("Class ID %d has not been defined", id); 410 } 411 return klass; 412 } 413 414 415 InstanceKlass* ClassListParser::lookup_super_for_current_class(Symbol* super_name) { 416 if (!is_loading_from_source()) { |