462 TRAPS) { 463 assert(SystemDictionary::is_system_class_loader(class_loader()), "unexpected class loader"); 464 // get_package_name() returns a NULL handle if the class is in unnamed package 465 Handle pkgname_string = get_package_name(class_name, CHECK); 466 if (pkgname_string.not_null()) { 467 Klass* app_classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); 468 JavaValue result(T_OBJECT); 469 JavaCallArguments args(3); 470 args.set_receiver(class_loader); 471 args.push_oop(pkgname_string); 472 args.push_oop(manifest); 473 args.push_oop(url); 474 JavaCalls::call_virtual(&result, app_classLoader_klass, 475 vmSymbols::defineOrCheckPackage_name(), 476 vmSymbols::defineOrCheckPackage_signature(), 477 &args, 478 CHECK); 479 } 480 } 481 482 // Define Package for shared app/platform classes from named module 483 void SystemDictionaryShared::define_shared_package(Symbol* class_name, 484 Handle class_loader, 485 ModuleEntry* mod_entry, 486 TRAPS) { 487 assert(mod_entry != NULL, "module_entry should not be NULL"); 488 Handle module_handle(THREAD, mod_entry->module()); 489 490 Handle pkg_name = get_package_name(class_name, CHECK); 491 assert(pkg_name.not_null(), "Package should not be null for class in named module"); 492 493 Klass* classLoader_klass; 494 if (SystemDictionary::is_system_class_loader(class_loader())) { 495 classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); 496 } else { 497 assert(SystemDictionary::is_platform_class_loader(class_loader()), "unexpected classloader"); 498 classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass(); 499 } 500 501 JavaValue result(T_OBJECT); 502 JavaCallArguments args(2); 503 args.set_receiver(class_loader); 504 args.push_oop(pkg_name); 505 args.push_oop(module_handle); 506 JavaCalls::call_virtual(&result, classLoader_klass, 507 vmSymbols::definePackage_name(), 508 vmSymbols::definePackage_signature(), 509 &args, 510 CHECK); 511 } 512 513 // Get the ProtectionDomain associated with the CodeSource from the classloader. 514 Handle SystemDictionaryShared::get_protection_domain_from_classloader(Handle class_loader, 515 Handle url, TRAPS) { 516 // CodeSource cs = new CodeSource(url, null); 517 Handle cs = JavaCalls::construct_new_instance(SystemDictionary::CodeSource_klass(), 518 vmSymbols::url_code_signer_array_void_signature(), 519 url, Handle(), CHECK_NH); 520 521 // protection_domain = SecureClassLoader.getProtectionDomain(cs); 522 Klass* secureClassLoader_klass = SystemDictionary::SecureClassLoader_klass(); 523 JavaValue obj_result(T_OBJECT); 524 JavaCalls::call_virtual(&obj_result, class_loader, secureClassLoader_klass, 525 vmSymbols::getProtectionDomain_name(), 526 vmSymbols::getProtectionDomain_signature(), 527 cs, CHECK_NH); 528 return Handle(THREAD, (oop)obj_result.get_jobject()); 529 } 530 531 // Returns the ProtectionDomain associated with the JAR file identified by the url. 532 Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader, 581 assert(protection_domain.not_null(), "sanity"); 582 return protection_domain; 583 } 584 585 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with 586 // the given InstanceKlass. 587 // Returns the ProtectionDomain for the InstanceKlass. 588 Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) { 589 Handle pd; 590 591 if (ik != NULL) { 592 int index = ik->shared_classpath_index(); 593 assert(index >= 0, "Sanity"); 594 SharedClassPathEntry* ent = FileMapInfo::shared_path(index); 595 Symbol* class_name = ik->name(); 596 597 if (ent->is_modules_image()) { 598 // For shared app/platform classes originated from the run-time image: 599 // The ProtectionDomains are cached in the corresponding ModuleEntries 600 // for fast access by the VM. 601 if (pkg_entry != NULL) { 602 ModuleEntry* mod_entry = pkg_entry->module(); 603 pd = get_shared_protection_domain(class_loader, mod_entry, THREAD); 604 define_shared_package(class_name, class_loader, mod_entry, CHECK_(pd)); 605 } 606 } else { 607 // For shared app/platform classes originated from JAR files on the class path: 608 // Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length 609 // as the shared classpath table in the shared archive (see 610 // FileMap::_shared_path_table in filemap.hpp for details). 611 // 612 // If a shared InstanceKlass k is loaded from the class path, let 613 // 614 // index = k->shared_classpath_index(): 615 // 616 // FileMap::_shared_path_table[index] identifies the JAR file that contains k. 617 // 618 // k's protection domain is: 619 // 620 // ProtectionDomain pd = _shared_protection_domains[index]; 621 // 622 // and k's Package is initialized using 623 // 624 // manifest = _shared_jar_manifests[index]; 625 // url = _shared_jar_urls[index]; | 462 TRAPS) { 463 assert(SystemDictionary::is_system_class_loader(class_loader()), "unexpected class loader"); 464 // get_package_name() returns a NULL handle if the class is in unnamed package 465 Handle pkgname_string = get_package_name(class_name, CHECK); 466 if (pkgname_string.not_null()) { 467 Klass* app_classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); 468 JavaValue result(T_OBJECT); 469 JavaCallArguments args(3); 470 args.set_receiver(class_loader); 471 args.push_oop(pkgname_string); 472 args.push_oop(manifest); 473 args.push_oop(url); 474 JavaCalls::call_virtual(&result, app_classLoader_klass, 475 vmSymbols::defineOrCheckPackage_name(), 476 vmSymbols::defineOrCheckPackage_signature(), 477 &args, 478 CHECK); 479 } 480 } 481 482 // Get the ProtectionDomain associated with the CodeSource from the classloader. 483 Handle SystemDictionaryShared::get_protection_domain_from_classloader(Handle class_loader, 484 Handle url, TRAPS) { 485 // CodeSource cs = new CodeSource(url, null); 486 Handle cs = JavaCalls::construct_new_instance(SystemDictionary::CodeSource_klass(), 487 vmSymbols::url_code_signer_array_void_signature(), 488 url, Handle(), CHECK_NH); 489 490 // protection_domain = SecureClassLoader.getProtectionDomain(cs); 491 Klass* secureClassLoader_klass = SystemDictionary::SecureClassLoader_klass(); 492 JavaValue obj_result(T_OBJECT); 493 JavaCalls::call_virtual(&obj_result, class_loader, secureClassLoader_klass, 494 vmSymbols::getProtectionDomain_name(), 495 vmSymbols::getProtectionDomain_signature(), 496 cs, CHECK_NH); 497 return Handle(THREAD, (oop)obj_result.get_jobject()); 498 } 499 500 // Returns the ProtectionDomain associated with the JAR file identified by the url. 501 Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader, 550 assert(protection_domain.not_null(), "sanity"); 551 return protection_domain; 552 } 553 554 // Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with 555 // the given InstanceKlass. 556 // Returns the ProtectionDomain for the InstanceKlass. 557 Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) { 558 Handle pd; 559 560 if (ik != NULL) { 561 int index = ik->shared_classpath_index(); 562 assert(index >= 0, "Sanity"); 563 SharedClassPathEntry* ent = FileMapInfo::shared_path(index); 564 Symbol* class_name = ik->name(); 565 566 if (ent->is_modules_image()) { 567 // For shared app/platform classes originated from the run-time image: 568 // The ProtectionDomains are cached in the corresponding ModuleEntries 569 // for fast access by the VM. 570 // all packages from module image are already created during VM bootstrap in 571 // Modules::define_module(). 572 assert(pkg_entry != NULL, "archived class in module image cannot be from unnamed package"); 573 ModuleEntry* mod_entry = pkg_entry->module(); 574 pd = get_shared_protection_domain(class_loader, mod_entry, THREAD); 575 } else { 576 // For shared app/platform classes originated from JAR files on the class path: 577 // Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length 578 // as the shared classpath table in the shared archive (see 579 // FileMap::_shared_path_table in filemap.hpp for details). 580 // 581 // If a shared InstanceKlass k is loaded from the class path, let 582 // 583 // index = k->shared_classpath_index(): 584 // 585 // FileMap::_shared_path_table[index] identifies the JAR file that contains k. 586 // 587 // k's protection domain is: 588 // 589 // ProtectionDomain pd = _shared_protection_domains[index]; 590 // 591 // and k's Package is initialized using 592 // 593 // manifest = _shared_jar_manifests[index]; 594 // url = _shared_jar_urls[index]; |