20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classFileParser.hpp"
27 #include "classfile/classLoader.hpp"
28 #include "classfile/classLoaderData.inline.hpp"
29 #include "classfile/javaAssertions.hpp"
30 #include "classfile/javaClasses.hpp"
31 #include "classfile/javaClasses.inline.hpp"
32 #include "classfile/moduleEntry.hpp"
33 #include "classfile/modules.hpp"
34 #include "classfile/packageEntry.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/symbolTable.hpp"
37 #include "classfile/systemDictionary.hpp"
38 #include "classfile/vmSymbols.hpp"
39 #include "logging/log.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "oops/instanceKlass.hpp"
42 #include "runtime/arguments.hpp"
43 #include "runtime/handles.inline.hpp"
44 #include "runtime/javaCalls.hpp"
45 #include "runtime/reflection.hpp"
46 #include "utilities/stringUtils.hpp"
47 #include "utilities/utf8.hpp"
48
49 static bool verify_module_name(const char *module_name) {
50 if (module_name == NULL) return false;
51 int len = (int)strlen(module_name);
52 return (len > 0 && len <= Symbol::max_length());
53 }
54
55 bool Modules::verify_package_name(const char* package_name) {
56 if (package_name == NULL) return false;
57 int len = (int)strlen(package_name);
58 return (len > 0 && len <= Symbol::max_length() &&
59 UTF8::is_legal_utf8((const unsigned char *)package_name, len, false) &&
418 // by SymbolTable::new_symbol and as well by the PackageEntry creation.
419 pkg_list->at(y)->decrement_refcount();
420 }
421
422 // Store pointer to ModuleEntry record in java.lang.Module object.
423 java_lang_Module::set_module_entry(module_handle(), module_entry);
424 }
425 }
426 } // Release the lock
427
428 // any errors ?
429 if (dupl_modules) {
430 THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
431 err_msg("Module %s is already defined", module_name));
432 } else if (existing_pkg != NULL) {
433 throw_dup_pkg_exception(module_name, existing_pkg, CHECK);
434 }
435
436 log_info(module, load)("%s location: %s", module_name,
437 module_location != NULL ? module_location : "NULL");
438 if (log_is_enabled(Debug, module)) {
439 outputStream* logst = Log(module)::debug_stream();
440 logst->print("define_module(): creation of module: %s, version: %s, location: %s, ",
441 module_name, module_version != NULL ? module_version : "NULL",
442 module_location != NULL ? module_location : "NULL");
443 loader_data->print_value_on(logst);
444 logst->print_cr(", package #: %d", pkg_list->length());
445 for (int y = 0; y < pkg_list->length(); y++) {
446 log_trace(module)("define_module(): creation of package %s for module %s",
447 (pkg_list->at(y))->as_C_string(), module_name);
448 }
449 }
450
451 // If the module is defined to the boot loader and an exploded build is being
452 // used, prepend <java.home>/modules/modules_name to the system boot class path.
453 if (loader == NULL && !ClassLoader::has_jrt_entry()) {
454 ClassLoader::add_to_exploded_build_list(module_symbol, CHECK);
455 }
456 }
457
458 void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) {
459 ResourceMark rm(THREAD);
460
461 if (module == NULL) {
462 THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
463 }
464 Handle module_handle(THREAD, JNIHandles::resolve(module));
605
606 if (clazz == NULL) {
607 THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
608 "class is null", JNI_FALSE);
609 }
610 oop mirror = JNIHandles::resolve_non_null(clazz);
611 if (mirror == NULL) {
612 log_debug(module)("get_module(): no mirror, returning NULL");
613 return NULL;
614 }
615 if (!java_lang_Class::is_instance(mirror)) {
616 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
617 "Invalid class", JNI_FALSE);
618 }
619
620 oop module = java_lang_Class::module(mirror);
621
622 assert(module != NULL, "java.lang.Class module field not set");
623 assert(java_lang_Module::is_instance(module), "module is not an instance of type java.lang.Module");
624
625 if (log_is_enabled(Debug, module)) {
626 ResourceMark rm(THREAD);
627 outputStream* logst = Log(module)::debug_stream();
628 Klass* klass = java_lang_Class::as_Klass(mirror);
629 oop module_name = java_lang_Module::name(module);
630 if (module_name != NULL) {
631 logst->print("get_module(): module ");
632 java_lang_String::print(module_name, tty);
633 } else {
634 logst->print("get_module(): Unamed Module");
635 }
636 if (klass != NULL) {
637 logst->print_cr(" for class %s", klass->external_name());
638 } else {
639 logst->print_cr(" for primitive class");
640 }
641 }
642
643 return JNIHandles::make_local(THREAD, module);
644 }
645
646 jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
647 assert(ModuleEntryTable::javabase_defined(),
648 "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
649 assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()),
650 "Class loader is not a subclass of java.lang.ClassLoader");
651 assert(package_name != NULL, "the package_name should not be NULL");
652
653 if (strlen(package_name) == 0) {
654 return NULL;
655 }
656 TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL);
657 const PackageEntry* const pkg_entry =
658 get_package_entry_by_name(package_sym, h_loader, THREAD);
659 const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL);
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classFileParser.hpp"
27 #include "classfile/classLoader.hpp"
28 #include "classfile/classLoaderData.inline.hpp"
29 #include "classfile/javaAssertions.hpp"
30 #include "classfile/javaClasses.hpp"
31 #include "classfile/javaClasses.inline.hpp"
32 #include "classfile/moduleEntry.hpp"
33 #include "classfile/modules.hpp"
34 #include "classfile/packageEntry.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/symbolTable.hpp"
37 #include "classfile/systemDictionary.hpp"
38 #include "classfile/vmSymbols.hpp"
39 #include "logging/log.hpp"
40 #include "logging/logStream.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "oops/instanceKlass.hpp"
43 #include "runtime/arguments.hpp"
44 #include "runtime/handles.inline.hpp"
45 #include "runtime/javaCalls.hpp"
46 #include "runtime/reflection.hpp"
47 #include "utilities/stringUtils.hpp"
48 #include "utilities/utf8.hpp"
49
50 static bool verify_module_name(const char *module_name) {
51 if (module_name == NULL) return false;
52 int len = (int)strlen(module_name);
53 return (len > 0 && len <= Symbol::max_length());
54 }
55
56 bool Modules::verify_package_name(const char* package_name) {
57 if (package_name == NULL) return false;
58 int len = (int)strlen(package_name);
59 return (len > 0 && len <= Symbol::max_length() &&
60 UTF8::is_legal_utf8((const unsigned char *)package_name, len, false) &&
419 // by SymbolTable::new_symbol and as well by the PackageEntry creation.
420 pkg_list->at(y)->decrement_refcount();
421 }
422
423 // Store pointer to ModuleEntry record in java.lang.Module object.
424 java_lang_Module::set_module_entry(module_handle(), module_entry);
425 }
426 }
427 } // Release the lock
428
429 // any errors ?
430 if (dupl_modules) {
431 THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
432 err_msg("Module %s is already defined", module_name));
433 } else if (existing_pkg != NULL) {
434 throw_dup_pkg_exception(module_name, existing_pkg, CHECK);
435 }
436
437 log_info(module, load)("%s location: %s", module_name,
438 module_location != NULL ? module_location : "NULL");
439 LogTarget(Debug, module) lt;
440 if (lt.is_enabled()) {
441 LogStream ls(lt);
442 ls.print("define_module(): creation of module: %s, version: %s, location: %s, ",
443 module_name, module_version != NULL ? module_version : "NULL",
444 module_location != NULL ? module_location : "NULL");
445 loader_data->print_value_on(&ls);
446 ls.print_cr(", package #: %d", pkg_list->length());
447 for (int y = 0; y < pkg_list->length(); y++) {
448 log_trace(module)("define_module(): creation of package %s for module %s",
449 (pkg_list->at(y))->as_C_string(), module_name);
450 }
451 }
452
453 // If the module is defined to the boot loader and an exploded build is being
454 // used, prepend <java.home>/modules/modules_name to the system boot class path.
455 if (loader == NULL && !ClassLoader::has_jrt_entry()) {
456 ClassLoader::add_to_exploded_build_list(module_symbol, CHECK);
457 }
458 }
459
460 void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) {
461 ResourceMark rm(THREAD);
462
463 if (module == NULL) {
464 THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
465 }
466 Handle module_handle(THREAD, JNIHandles::resolve(module));
607
608 if (clazz == NULL) {
609 THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
610 "class is null", JNI_FALSE);
611 }
612 oop mirror = JNIHandles::resolve_non_null(clazz);
613 if (mirror == NULL) {
614 log_debug(module)("get_module(): no mirror, returning NULL");
615 return NULL;
616 }
617 if (!java_lang_Class::is_instance(mirror)) {
618 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
619 "Invalid class", JNI_FALSE);
620 }
621
622 oop module = java_lang_Class::module(mirror);
623
624 assert(module != NULL, "java.lang.Class module field not set");
625 assert(java_lang_Module::is_instance(module), "module is not an instance of type java.lang.Module");
626
627 LogTarget(Debug,module) lt;
628 if (lt.is_enabled()) {
629 ResourceMark rm(THREAD);
630 LogStream ls(lt);
631 Klass* klass = java_lang_Class::as_Klass(mirror);
632 oop module_name = java_lang_Module::name(module);
633 if (module_name != NULL) {
634 ls.print("get_module(): module ");
635 java_lang_String::print(module_name, tty);
636 } else {
637 ls.print("get_module(): Unamed Module");
638 }
639 if (klass != NULL) {
640 ls.print_cr(" for class %s", klass->external_name());
641 } else {
642 ls.print_cr(" for primitive class");
643 }
644 }
645
646 return JNIHandles::make_local(THREAD, module);
647 }
648
649 jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
650 assert(ModuleEntryTable::javabase_defined(),
651 "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
652 assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()),
653 "Class loader is not a subclass of java.lang.ClassLoader");
654 assert(package_name != NULL, "the package_name should not be NULL");
655
656 if (strlen(package_name) == 0) {
657 return NULL;
658 }
659 TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL);
660 const PackageEntry* const pkg_entry =
661 get_package_entry_by_name(package_sym, h_loader, THREAD);
662 const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL);
|