use of com.oracle.truffle.espresso.impl.ModuleTable in project graal by oracle.
the class VM method defineModule.
@SuppressWarnings("try")
public void defineModule(StaticObject module, String moduleName, boolean is_open, String[] packages, SubstitutionProfiler profiler) {
Meta meta = getMeta();
StaticObject loader = meta.java_lang_Module_loader.getObject(module);
if (loader != nonReflectionClassLoader(loader)) {
profiler.profile(15);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader is an invalid delegating class loader");
}
// Prepare variables
ClassRegistry registry = getRegistries().getClassRegistry(loader);
assert registry != null;
PackageTable packageTable = registry.packages();
ModuleTable moduleTable = registry.modules();
assert moduleTable != null && packageTable != null;
boolean loaderIsBootOrPlatform = ClassRegistry.loaderIsBootOrPlatform(loader, meta);
ArrayList<Symbol<Name>> pkgSymbols = new ArrayList<>();
try (EntryTable.BlockLock block = packageTable.write()) {
for (String str : packages) {
// Extract the package symbols. Also checks for duplicates.
if (!loaderIsBootOrPlatform && (str.equals("java") || str.startsWith("java/"))) {
// Only modules defined to either the boot or platform class loader, can define
// a "java/" package.
profiler.profile(14);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, cat("Class loader (", loader.getKlass().getType(), ") tried to define prohibited package name: ", str));
}
Symbol<Name> symbol = getNames().getOrCreate(str);
if (packageTable.lookup(symbol) != null) {
profiler.profile(13);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, cat("Package ", str, " is already defined."));
}
pkgSymbols.add(symbol);
}
Symbol<Name> moduleSymbol = getNames().getOrCreate(moduleName);
// Try define module
ModuleEntry moduleEntry = moduleTable.createAndAddEntry(moduleSymbol, registry, is_open, module);
if (moduleEntry == null) {
// Module already defined
profiler.profile(12);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, cat("Module ", moduleName, " is already defined"));
}
// Register packages
for (Symbol<Name> pkgSymbol : pkgSymbols) {
PackageEntry pkgEntry = packageTable.createAndAddEntry(pkgSymbol, moduleEntry);
// should have been checked before
assert pkgEntry != null;
}
// Link guest module to its host representation
meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, moduleEntry);
}
if (StaticObject.isNull(loader) && getContext().getVmProperties().bootClassPathType().isExplodedModule()) {
profiler.profile(11);
// If we have an exploded build, and the module is defined to the bootloader, prepend a
// class path entry for this module.
prependModuleClasspath(moduleName);
}
}
Aggregations