Skip to content

Commit 6d5ac8d

Browse files
author
Yueming Liu
committed
bugfix: use BytecodeFunc.class.getClassLoader() for FuncClassLoader
1 parent ee53447 commit 6d5ac8d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package symjava.examples;
2+
3+
import static symjava.symbolic.Symbol.x;
4+
import static symjava.symbolic.Symbol.y;
5+
import symjava.bytecode.BytecodeFunc;
6+
import symjava.symbolic.Expr;
7+
import symjava.symbolic.utils.JIT;
8+
9+
/**
10+
* test class loader for multi thread case
11+
* @author yueming.liu
12+
*
13+
*/
14+
public class ExampleMultiThread {
15+
16+
public static void main(String[] args) throws InterruptedException {
17+
Thread t = new Thread(new Runnable() {
18+
@Override
19+
public void run() {
20+
Expr R = 0.127-(x*0.194/(y+0.194));
21+
Expr Rdy = R.diff(y);
22+
System.out.println(Rdy);
23+
24+
//Just-In-Time compile the symbolic expression to native code
25+
BytecodeFunc func = JIT.compile(new Expr[]{x,y}, Rdy);
26+
System.out.println(func.apply(0.362, 0.556)); //Scala function call operator
27+
System.out.println(func.call(0.362, 0.556)); //Groovy function call operator
28+
29+
}
30+
});
31+
t.start();
32+
t.join();
33+
}
34+
35+
}

src/symjava/symbolic/utils/FuncClassLoader.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package symjava.symbolic.utils;
22

3+
import symjava.bytecode.BytecodeFunc;
4+
35
import com.sun.org.apache.bcel.internal.generic.ClassGen;
46

57
public class FuncClassLoader<T> extends ClassLoader {
68

79
public FuncClassLoader() {
8-
super(Thread.currentThread().getContextClassLoader());
10+
//super(Thread.currentThread().getContextClassLoader());
11+
//https://blogs.oracle.com/sundararajan/understanding-java-class-loading
12+
//super(java.lang.ClassLoader.getSystemClassLoader());
13+
super(BytecodeFunc.class.getClassLoader());
914
}
1015
//
1116
// public FuncClassLoader(ClassLoader parent) {

0 commit comments

Comments
 (0)