mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8185853: Generate readability graph at link time and other startup improvements
Reviewed-by: mchung
This commit is contained in:
parent
39960027c3
commit
df5b632f58
27 changed files with 2125 additions and 1308 deletions
|
@ -25,9 +25,7 @@
|
|||
|
||||
package java.lang.module;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AccessController;
|
||||
import java.security.Permission;
|
||||
import java.security.PrivilegedAction;
|
||||
|
@ -40,10 +38,8 @@ import java.util.Objects;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.module.ModuleBootstrap;
|
||||
import jdk.internal.module.ModulePatcher;
|
||||
import jdk.internal.module.ModulePath;
|
||||
import jdk.internal.module.SystemModuleFinder;
|
||||
import jdk.internal.module.SystemModuleFinders;
|
||||
|
||||
/**
|
||||
* A finder of modules. A {@code ModuleFinder} is used to find modules during
|
||||
|
@ -157,52 +153,13 @@ public interface ModuleFinder {
|
|||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("accessSystemModules"));
|
||||
PrivilegedAction<ModuleFinder> pa = ModuleFinder::privilegedOfSystem;
|
||||
PrivilegedAction<ModuleFinder> pa = SystemModuleFinders::ofSystem;
|
||||
return AccessController.doPrivileged(pa);
|
||||
} else {
|
||||
return privilegedOfSystem();
|
||||
return SystemModuleFinders.ofSystem();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a module finder that locates the system modules. This method
|
||||
* assumes it has permissions to access the runtime image.
|
||||
*/
|
||||
private static ModuleFinder privilegedOfSystem() {
|
||||
String home = System.getProperty("java.home");
|
||||
Path modules = Paths.get(home, "lib", "modules");
|
||||
if (Files.isRegularFile(modules)) {
|
||||
return SystemModuleFinder.getInstance();
|
||||
} else {
|
||||
Path dir = Paths.get(home, "modules");
|
||||
if (Files.isDirectory(dir)) {
|
||||
return privilegedOf(ModuleBootstrap.patcher(), dir);
|
||||
} else {
|
||||
throw new InternalError("Unable to detect the run-time image");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a module finder that locates the system modules in an exploded
|
||||
* image. The image may be patched.
|
||||
*/
|
||||
private static ModuleFinder privilegedOf(ModulePatcher patcher, Path dir) {
|
||||
ModuleFinder finder = ModulePath.of(patcher, dir);
|
||||
return new ModuleFinder() {
|
||||
@Override
|
||||
public Optional<ModuleReference> find(String name) {
|
||||
PrivilegedAction<Optional<ModuleReference>> pa = () -> finder.find(name);
|
||||
return AccessController.doPrivileged(pa);
|
||||
}
|
||||
@Override
|
||||
public Set<ModuleReference> findAll() {
|
||||
PrivilegedAction<Set<ModuleReference>> pa = finder::findAll;
|
||||
return AccessController.doPrivileged(pa);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a module finder that locates modules on the file system by
|
||||
* searching a sequence of directories and/or packaged modules.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue