Search in sources :

Example 1 with ModuleEntry

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);
}
Also used : PackageEntry(com.oracle.truffle.espresso.impl.PackageTable.PackageEntry) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry)

Example 2 with ModuleEntry

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);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with ModuleEntry

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);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EntryTable(com.oracle.truffle.espresso.impl.EntryTable) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) PackageTable(com.oracle.truffle.espresso.impl.PackageTable) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 4 with ModuleEntry

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()));
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 5 with ModuleEntry

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);
    }
}
Also used : ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

ModuleEntry (com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)3 Meta (com.oracle.truffle.espresso.meta.Meta)3 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 EntryTable (com.oracle.truffle.espresso.impl.EntryTable)2 PackageTable (com.oracle.truffle.espresso.impl.PackageTable)2 PackageEntry (com.oracle.truffle.espresso.impl.PackageTable.PackageEntry)2 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)1 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)1 ClassRegistry (com.oracle.truffle.espresso.impl.ClassRegistry)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 Method (com.oracle.truffle.espresso.impl.Method)1 ModuleTable (com.oracle.truffle.espresso.impl.ModuleTable)1 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)1 ArrayList (java.util.ArrayList)1