use of com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry in project graal by oracle.
the class Klass method doModuleAccessChecks.
public static boolean doModuleAccessChecks(Klass klass, Klass accessingKlass, EspressoContext context) {
ModuleEntry moduleFrom = accessingKlass.module();
ModuleEntry moduleTo = klass.module();
if (moduleFrom == moduleTo) {
return true;
}
/*
* Acceptable access to a type in an unnamed module. Note that since unnamed modules can
* read all unnamed modules, this also handles the case where module_from is also unnamed
* but in a different class loader.
*/
if (!moduleTo.isNamed() && (moduleFrom.canReadAllUnnamed() || moduleFrom.canRead(moduleTo, context))) {
return true;
}
// Establish readability, check if moduleFrom is allowed to read moduleTo.
if (!moduleFrom.canRead(moduleTo, context)) {
return false;
}
// exported
if (moduleTo.isOpen()) {
return true;
}
PackageEntry packageTo = klass.packageEntry();
/*
* Once readability is established, if module_to exports T unqualifiedly, (to all modules),
* then whether module_from is in the unnamed module or not does not matter, access is
* allowed.
*/
if (packageTo.isUnqualifiedExported()) {
return true;
}
/*-
* Access is allowed if both 1 & 2 hold:
* 1. Readability, module_from can read module_to (established above).
* 2. Either module_to exports T to module_from qualifiedly.
* or
* module_to exports T to all unnamed modules and module_from is unnamed.
* or
* module_to exports T unqualifiedly to all modules (checked above).
*/
return packageTo.isQualifiedExportTo(moduleFrom);
}
use of com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry in project graal by oracle.
the class VM method JVM_SetBootLoaderUnnamedModule.
@VmImpl(isJni = true)
@TruffleBoundary
public void JVM_SetBootLoaderUnnamedModule(@JavaType(internalName = "Ljava/lang/Module;") StaticObject module) {
Meta meta = getMeta();
if (StaticObject.isNull(module)) {
throw meta.throwNullPointerException();
}
if (!meta.java_lang_Module.isAssignableFrom(module.getKlass())) {
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "module is not an instance of java.lang.module");
}
if (!StaticObject.isNull(meta.java_lang_Module_name.getObject(module))) {
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "boot loader unnamed module has a name");
}
if (!StaticObject.isNull(meta.java_lang_Module_loader.getObject(module))) {
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader must be the boot class loader");
}
ModuleEntry bootUnnamed = getRegistries().getBootClassRegistry().getUnnamedModule();
bootUnnamed.setModule(module);
meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, bootUnnamed);
}
use of com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry in project graal by oracle.
the class VM method defineJavaBaseModule.
@SuppressWarnings("try")
public void defineJavaBaseModule(StaticObject module, String[] packages, SubstitutionProfiler profiler) {
Meta meta = getMeta();
StaticObject loader = meta.java_lang_Module_loader.getObject(module);
if (!StaticObject.isNull(loader)) {
profiler.profile(10);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader must be the bootclass loader");
}
PackageTable pkgTable = getRegistries().getBootClassRegistry().packages();
ModuleEntry javaBaseEntry = getRegistries().getJavaBaseModule();
try (EntryTable.BlockLock block = pkgTable.write()) {
if (getRegistries().javaBaseDefined()) {
profiler.profile(9);
throw meta.throwException(meta.java_lang_InternalError);
}
for (String pkg : packages) {
Symbol<Name> pkgName = getNames().getOrCreate(pkg);
if (pkgTable.lookup(pkgName) == null) {
pkgTable.createAndAddEntry(pkgName, javaBaseEntry);
}
}
javaBaseEntry.setModule(module);
meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, javaBaseEntry);
getRegistries().processFixupList(module);
}
}
use of com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry in project graal by oracle.
the class VM method fillInElement.
private void fillInElement(@JavaType(StackTraceElement.class) StaticObject ste, VM.StackElement element, Method classGetName) {
Method m = element.getMethod();
Klass k = m.getDeclaringKlass();
StaticObject guestClass = k.mirror();
StaticObject loader = k.getDefiningClassLoader();
ModuleEntry module = k.module();
// Fill in class name
getMeta().java_lang_StackTraceElement_declaringClass.setObject(ste, classGetName.invokeDirect(guestClass));
getMeta().java_lang_StackTraceElement_declaringClassObject.setObject(ste, guestClass);
// Fill in loader name
if (!StaticObject.isNull(loader)) {
StaticObject loaderName = getMeta().java_lang_ClassLoader_name.getObject(loader);
if (!StaticObject.isNull(loader)) {
getMeta().java_lang_StackTraceElement_classLoaderName.setObject(ste, loaderName);
}
}
// Fill in method name
Symbol<Name> mname = m.getName();
getMeta().java_lang_StackTraceElement_methodName.setObject(ste, getMeta().toGuestString(mname));
// Fill in module
if (module.isNamed()) {
getMeta().java_lang_StackTraceElement_moduleName.setObject(ste, getMeta().toGuestString(module.getName()));
// TODO: module version
}
// Fill in source information
getMeta().java_lang_StackTraceElement_fileName.setObject(ste, getMeta().toGuestString(m.getSourceFile()));
getMeta().java_lang_StackTraceElement_lineNumber.setInt(ste, m.bciToLineNumber(element.getBCI()));
}
use of com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry in project graal by oracle.
the class VM method JVM_AddReadsModule.
@VmImpl(isJni = true)
@TruffleBoundary
public void JVM_AddReadsModule(@JavaType(internalName = "Ljava/lang/Module;") StaticObject from_module, @JavaType(internalName = "Ljava/lang/Module;") StaticObject source_module, @Inject SubstitutionProfiler profiler) {
ModuleEntry fromEntry = ModulesHelperVM.extractFromModuleEntry(from_module, getMeta(), profiler);
ModuleEntry toEntry = ModulesHelperVM.extractToModuleEntry(source_module, getMeta(), profiler);
if (fromEntry != toEntry && fromEntry.isNamed()) {
fromEntry.addReads(toEntry);
}
}
Aggregations