Skip to content

Commit 3276008

Browse files
committed
re-enable lazy fn loader
1 parent 201a0dd commit 3276008

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,7 @@ static public class FnExpr extends ObjExpr{
37453745
IPersistentCollection methods;
37463746
private boolean hasPrimSigs;
37473747
private boolean hasMeta;
3748+
private boolean hasEnclosingMethod;
37483749
// String superName = null;
37493750

37503751
public FnExpr(Object tag){
@@ -3790,6 +3791,7 @@ static Expr parse(C context, ISeq form, String name) {
37903791
FnExpr fn = new FnExpr(tagOf(form));
37913792
fn.src = form;
37923793
ObjMethod enclosingMethod = (ObjMethod) METHOD.deref();
3794+
fn.hasEnclosingMethod = enclosingMethod != null;
37933795
if(((IMeta) form.first()).meta() != null)
37943796
{
37953797
fn.onceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), Keyword.intern(null, "once")));
@@ -3936,18 +3938,20 @@ public final IPersistentCollection methods(){
39363938
}
39373939

39383940
public void emitForDefn(ObjExpr objx, GeneratorAdapter gen){
3939-
// if(!hasPrimSigs && closes.count() == 0)
3940-
// {
3941-
// Type thunkType = Type.getType(FnLoaderThunk.class);
3942-
//// presumes var on stack
3943-
// gen.dup();
3944-
// gen.newInstance(thunkType);
3945-
// gen.dupX1();
3946-
// gen.swap();
3947-
// gen.push(internalName.replace('/','.'));
3948-
// gen.invokeConstructor(thunkType,Method.getMethod("void <init>(clojure.lang.Var,String)"));
3949-
// }
3950-
// else
3941+
if(!hasEnclosingMethod && !hasPrimSigs && closes.count() == 0)
3942+
{
3943+
String iname = internalName.replace('/','.');
3944+
// System.out.println("emit var for defn: " + name + ", iname: " + iname);
3945+
Type thunkType = Type.getType(FnLoaderThunk.class);
3946+
// presumes var on stack
3947+
gen.dup();
3948+
gen.newInstance(thunkType);
3949+
gen.dupX1();
3950+
gen.swap();
3951+
gen.push(iname);
3952+
gen.invokeConstructor(thunkType,Method.getMethod("void <init>(clojure.lang.Var,String)"));
3953+
}
3954+
else
39513955
emit(C.EXPRESSION,objx,gen);
39523956
}
39533957
}

src/jvm/clojure/lang/FnLoaderThunk.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ private void load() {
5151
{
5252
try
5353
{
54+
// long start = System.nanoTime();
5455
fn = (IFn) Class.forName(fnClassName,true,loader).newInstance();
56+
// long ns = System.nanoTime() - start;
57+
// System.out.println("Lazily loaded: " + fnClassName + ", in: " + ns/1000 + "μs");
5558
}
5659
catch(Exception e)
5760
{

src/jvm/clojure/lang/RT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ static void compile(String cljfile) throws IOException{
408408
}
409409

410410
static public void load(String scriptbase) throws IOException, ClassNotFoundException{
411+
// long start = System.nanoTime();
411412
load(scriptbase, true);
413+
// long ns = System.nanoTime() - start;
414+
// System.out.println("loaded script: " + scriptbase + ", in: " + ns/1000000 + "ms");
412415
}
413416

414417
static public void load(String scriptbase, boolean failIfNotFound) throws IOException, ClassNotFoundException{

0 commit comments

Comments
 (0)