< prev index next >

src/share/vm/classfile/modules.cpp

Print this page
rev 13265 : imported patch 8181917-refactor-ul-logstream


  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 "prims/jvm.h"
  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() &&


 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   if (log_is_enabled(Debug, module)) {
 440     outputStream* logst = Log(module)::debug_stream();
 441     logst->print("define_module(): creation of module: %s, version: %s, location: %s, ",

 442                  module_name, module_version != NULL ? module_version : "NULL",
 443                  module_location != NULL ? module_location : "NULL");
 444     loader_data->print_value_on(logst);
 445     logst->print_cr(", package #: %d", pkg_list->length());
 446     for (int y = 0; y < pkg_list->length(); y++) {
 447       log_trace(module)("define_module(): creation of package %s for module %s",
 448                         (pkg_list->at(y))->as_C_string(), module_name);
 449     }
 450   }
 451 
 452   // If the module is defined to the boot loader and an exploded build is being
 453   // used, prepend <java.home>/modules/modules_name to the system boot class path.
 454   if (loader == NULL && !ClassLoader::has_jrt_entry()) {
 455     ClassLoader::add_to_exploded_build_list(module_symbol, CHECK);
 456   }
 457 }
 458 
 459 void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) {
 460   ResourceMark rm(THREAD);
 461 
 462   if (module == NULL) {
 463     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
 464   }
 465   Handle module_handle(THREAD, JNIHandles::resolve(module));


 606 
 607   if (clazz == NULL) {
 608     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
 609                "class is null", JNI_FALSE);
 610   }
 611   oop mirror = JNIHandles::resolve_non_null(clazz);
 612   if (mirror == NULL) {
 613     log_debug(module)("get_module(): no mirror, returning NULL");
 614     return NULL;
 615   }
 616   if (!java_lang_Class::is_instance(mirror)) {
 617     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
 618                "Invalid class", JNI_FALSE);
 619   }
 620 
 621   oop module = java_lang_Class::module(mirror);
 622 
 623   assert(module != NULL, "java.lang.Class module field not set");
 624   assert(java_lang_Module::is_instance(module), "module is not an instance of type java.lang.Module");
 625 
 626   if (log_is_enabled(Debug, module)) {

 627     ResourceMark rm(THREAD);
 628     outputStream* logst = Log(module)::debug_stream();
 629     Klass* klass = java_lang_Class::as_Klass(mirror);
 630     oop module_name = java_lang_Module::name(module);
 631     if (module_name != NULL) {
 632       logst->print("get_module(): module ");
 633       java_lang_String::print(module_name, tty);
 634     } else {
 635       logst->print("get_module(): Unamed Module");
 636     }
 637     if (klass != NULL) {
 638       logst->print_cr(" for class %s", klass->external_name());
 639     } else {
 640       logst->print_cr(" for primitive class");
 641     }
 642   }
 643 
 644   return JNIHandles::make_local(THREAD, module);
 645 }
 646 
 647 jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
 648   assert(ModuleEntryTable::javabase_defined(),
 649          "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
 650   assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()),
 651          "Class loader is not a subclass of java.lang.ClassLoader");
 652   assert(package_name != NULL, "the package_name should not be NULL");
 653 
 654   if (strlen(package_name) == 0) {
 655     return NULL;
 656   }
 657   TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL);
 658   const PackageEntry* const pkg_entry =
 659     get_package_entry_by_name(package_sym, h_loader, THREAD);
 660   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 "prims/jvm.h"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/handles.inline.hpp"
  46 #include "runtime/javaCalls.hpp"
  47 #include "runtime/reflection.hpp"
  48 #include "utilities/stringUtils.hpp"
  49 #include "utilities/utf8.hpp"
  50 
  51 static bool verify_module_name(const char *module_name) {
  52   if (module_name == NULL) return false;
  53   int len = (int)strlen(module_name);
  54   return (len > 0 && len <= Symbol::max_length());
  55 }
  56 
  57 bool Modules::verify_package_name(const char* package_name) {
  58   if (package_name == NULL) return false;
  59   int len = (int)strlen(package_name);
  60   return (len > 0 && len <= Symbol::max_length() &&


 420           // by SymbolTable::new_symbol and as well by the PackageEntry creation.
 421           pkg_list->at(y)->decrement_refcount();
 422         }
 423 
 424         // Store pointer to ModuleEntry record in java.lang.Module object.
 425         java_lang_Module::set_module_entry(module_handle(), module_entry);
 426       }
 427     }
 428   }  // Release the lock
 429 
 430   // any errors ?
 431   if (dupl_modules) {
 432      THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
 433                err_msg("Module %s is already defined", module_name));
 434   } else if (existing_pkg != NULL) {
 435       throw_dup_pkg_exception(module_name, existing_pkg, CHECK);
 436   }
 437 
 438   log_info(module, load)("%s location: %s", module_name,
 439                          module_location != NULL ? module_location : "NULL");
 440   LogTarget(Debug, module) lt;
 441   if (lt.is_enabled()) {
 442     LogStream ls(lt);
 443     ls.print("define_module(): creation of module: %s, version: %s, location: %s, ",
 444                  module_name, module_version != NULL ? module_version : "NULL",
 445                  module_location != NULL ? module_location : "NULL");
 446     loader_data->print_value_on(&ls);
 447     ls.print_cr(", package #: %d", pkg_list->length());
 448     for (int y = 0; y < pkg_list->length(); y++) {
 449       log_trace(module)("define_module(): creation of package %s for module %s",
 450                         (pkg_list->at(y))->as_C_string(), module_name);
 451     }
 452   }
 453 
 454   // If the module is defined to the boot loader and an exploded build is being
 455   // used, prepend <java.home>/modules/modules_name to the system boot class path.
 456   if (loader == NULL && !ClassLoader::has_jrt_entry()) {
 457     ClassLoader::add_to_exploded_build_list(module_symbol, CHECK);
 458   }
 459 }
 460 
 461 void Modules::set_bootloader_unnamed_module(jobject module, TRAPS) {
 462   ResourceMark rm(THREAD);
 463 
 464   if (module == NULL) {
 465     THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Null module object");
 466   }
 467   Handle module_handle(THREAD, JNIHandles::resolve(module));


 608 
 609   if (clazz == NULL) {
 610     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
 611                "class is null", JNI_FALSE);
 612   }
 613   oop mirror = JNIHandles::resolve_non_null(clazz);
 614   if (mirror == NULL) {
 615     log_debug(module)("get_module(): no mirror, returning NULL");
 616     return NULL;
 617   }
 618   if (!java_lang_Class::is_instance(mirror)) {
 619     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
 620                "Invalid class", JNI_FALSE);
 621   }
 622 
 623   oop module = java_lang_Class::module(mirror);
 624 
 625   assert(module != NULL, "java.lang.Class module field not set");
 626   assert(java_lang_Module::is_instance(module), "module is not an instance of type java.lang.Module");
 627 
 628   LogTarget(Debug,module) lt;
 629   if (lt.is_enabled()) {
 630     ResourceMark rm(THREAD);
 631     LogStream ls(lt);
 632     Klass* klass = java_lang_Class::as_Klass(mirror);
 633     oop module_name = java_lang_Module::name(module);
 634     if (module_name != NULL) {
 635       ls.print("get_module(): module ");
 636       java_lang_String::print(module_name, tty);
 637     } else {
 638       ls.print("get_module(): Unamed Module");
 639     }
 640     if (klass != NULL) {
 641       ls.print_cr(" for class %s", klass->external_name());
 642     } else {
 643       ls.print_cr(" for primitive class");
 644     }
 645   }
 646 
 647   return JNIHandles::make_local(THREAD, module);
 648 }
 649 
 650 jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
 651   assert(ModuleEntryTable::javabase_defined(),
 652          "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
 653   assert(h_loader.is_null() || java_lang_ClassLoader::is_subclass(h_loader->klass()),
 654          "Class loader is not a subclass of java.lang.ClassLoader");
 655   assert(package_name != NULL, "the package_name should not be NULL");
 656 
 657   if (strlen(package_name) == 0) {
 658     return NULL;
 659   }
 660   TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL);
 661   const PackageEntry* const pkg_entry =
 662     get_package_entry_by_name(package_sym, h_loader, THREAD);
 663   const ModuleEntry* const module_entry = (pkg_entry != NULL ? pkg_entry->module() : NULL);


< prev index next >