Skip to content

Commit

Permalink
bugfix: use BytecodeFunc.class.getClassLoader() for FuncClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Yueming Liu committed May 31, 2018
1 parent ee53447 commit 6d5ac8d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/symjava/examples/ExampleMultiThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package symjava.examples;

import static symjava.symbolic.Symbol.x;
import static symjava.symbolic.Symbol.y;
import symjava.bytecode.BytecodeFunc;
import symjava.symbolic.Expr;
import symjava.symbolic.utils.JIT;

/**
* test class loader for multi thread case
* @author yueming.liu
*
*/
public class ExampleMultiThread {

public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Expr R = 0.127-(x*0.194/(y+0.194));
Expr Rdy = R.diff(y);
System.out.println(Rdy);

//Just-In-Time compile the symbolic expression to native code
BytecodeFunc func = JIT.compile(new Expr[]{x,y}, Rdy);
System.out.println(func.apply(0.362, 0.556)); //Scala function call operator
System.out.println(func.call(0.362, 0.556)); //Groovy function call operator

}
});
t.start();
t.join();
}

}
7 changes: 6 additions & 1 deletion src/symjava/symbolic/utils/FuncClassLoader.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package symjava.symbolic.utils;

import symjava.bytecode.BytecodeFunc;

import com.sun.org.apache.bcel.internal.generic.ClassGen;

public class FuncClassLoader<T> extends ClassLoader {

public FuncClassLoader() {
super(Thread.currentThread().getContextClassLoader());
//super(Thread.currentThread().getContextClassLoader());
//https://blogs.oracle.com/sundararajan/understanding-java-class-loading
//super(java.lang.ClassLoader.getSystemClassLoader());
super(BytecodeFunc.class.getClassLoader());
}
//
// public FuncClassLoader(ClassLoader parent) {
Expand Down

0 comments on commit 6d5ac8d

Please sign in to comment.