8158507: JShell: new jdk.jshell.MemoryFileManager(StandardJavaFileManager, JShell) creates a jdk.jshell.MemoryFileManager$REPLClassLoader classloader, which should be performed within a doPrivileged block
Summary: Remove the ClassLoader and other unused code in support of in-process execution. This is now supported through the SPI.
Reviewed-by: jlahoda
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java Mon Aug 29 15:53:03 2016 +0200
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java Mon Aug 29 08:17:14 2016 -0700
@@ -71,8 +71,6 @@
private ClassFileCreationListener classListener = null;
- private final ClassLoader loader = new REPLClassLoader();
-
private final JShell proc;
// Upcoming Jigsaw
@@ -168,21 +166,6 @@
}
}
- // For restoring process-local execution support
- class REPLClassLoader extends ClassLoader {
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- OutputMemoryJavaFileObject fo = classObjects.get(name);
- proc.debug(DBG_FMGR, "findClass %s = %s\n", name, fo);
- if (fo == null) {
- throw new ClassNotFoundException("Not ours");
- }
- byte[] b = fo.getBytes();
- return super.defineClass(name, b, 0, b.length, null);
- }
- }
-
public MemoryFileManager(StandardJavaFileManager standardManager, JShell proc) {
this.stdFileManager = standardManager;
this.proc = proc;
@@ -199,33 +182,6 @@
}
}
- // For restoring process-local execution support
- public Class<?> findGeneratedClass(String genClassFullName) throws ClassNotFoundException {
- for (OutputMemoryJavaFileObject co : generatedClasses()) {
- if (co.className.equals(genClassFullName)) {
- Class<?> klass = loadClass(co.className);
- proc.debug(DBG_FMGR, "Loaded %s\n", klass);
- return klass;
- }
- }
- return null;
- }
-
- // For restoring process-local execution support
- public byte[] findGeneratedBytes(String genClassFullName) throws ClassNotFoundException {
- for (OutputMemoryJavaFileObject co : generatedClasses()) {
- if (co.className.equals(genClassFullName)) {
- return co.getBytes();
- }
- }
- return null;
- }
-
- // For restoring process-local execution support
- public Class<?> loadClass(String name) throws ClassNotFoundException {
- return getClassLoader(null).loadClass(name);
- }
-
public JavaFileObject createSourceFileObject(Object origin, String name, String code) {
return new SourceMemoryJavaFileObject(origin, name, code);
}
@@ -288,7 +244,7 @@
@Override @DefinedBy(Api.COMPILER)
public ClassLoader getClassLoader(JavaFileManager.Location location) {
proc.debug(DBG_FMGR, "getClassLoader: location\n", location);
- return loader;
+ return stdFileManager.getClassLoader(location);
}
/**