Skip to content

Commit

Permalink
get rid of root classloader. Establish dynamic context classloader fo…
Browse files Browse the repository at this point in the history
…r repl thread. Default true for *use-context-classloader*
  • Loading branch information
richhickey committed May 27, 2009
1 parent d0fe0d1 commit b045a37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/clj/clojure/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
read, eval, or print throws an exception or error
default: repl-caught"
[& options]
(let [cl (.getContextClassLoader (Thread/currentThread))]
(.setContextClassLoader (Thread/currentThread) (clojure.lang.DynamicClassLoader. cl)))
(let [{:keys [init need-prompt prompt flush read eval print caught]
:or {init #()
need-prompt (if (instance? LineNumberingPushbackReader *in*)
Expand Down
19 changes: 6 additions & 13 deletions src/jvm/clojure/lang/RT.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class RT{
static Keyword LINE_KEY = Keyword.intern(null, "line");
static Keyword FILE_KEY = Keyword.intern(null, "file");
final static public Var USE_CONTEXT_CLASSLOADER =
Var.intern(CLOJURE_NS, Symbol.create("*use-context-classloader*"), null);
Var.intern(CLOJURE_NS, Symbol.create("*use-context-classloader*"), T);
//final static public Var CURRENT_MODULE = Var.intern(Symbol.create("clojure.core", "current-module"),
// Module.findOrCreateModule("clojure/user"));

Expand Down Expand Up @@ -236,11 +236,14 @@ public int compare(Object o1, Object o2){
};

static AtomicInteger id = new AtomicInteger(1);
private static DynamicClassLoader ROOT_CLASSLOADER = null;

static public void addURL(Object url) throws Exception{
URL u = (url instanceof String) ? (new URL((String) url)) : (URL) url;
getRootClassLoader().addURL(u);
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
if(ccl instanceof DynamicClassLoader)
((DynamicClassLoader)ccl).addURL(u);
else
throw new IllegalAccessError("Context classloader is not a DynamicClassLoader");
}

final static public Object EOS = new Object();
Expand Down Expand Up @@ -1485,8 +1488,6 @@ static public ClassLoader baseLoader(){
return (ClassLoader) Compiler.LOADER.deref();
else if(booleanCast(USE_CONTEXT_CLASSLOADER.deref()))
return Thread.currentThread().getContextClassLoader();
else if(ROOT_CLASSLOADER != null)
return ROOT_CLASSLOADER;
return Compiler.class.getClassLoader();
}

Expand Down Expand Up @@ -1673,12 +1674,4 @@ static public int alength(Object xs){
return Array.getLength(xs);
}




synchronized public static DynamicClassLoader getRootClassLoader(){
if(ROOT_CLASSLOADER == null)
ROOT_CLASSLOADER = new DynamicClassLoader();
return ROOT_CLASSLOADER;
}
}

0 comments on commit b045a37

Please sign in to comment.