Commit ea0a877b authored by Lukáš Marek's avatar Lukáš Marek
Browse files

Analysis method is now transfered as string

parent c30e9c25
......@@ -59,10 +59,7 @@
</javac>
</target>
<target name="compile-test" depends="compile-disl,compile-dislre-dispatch">
<javac srcdir="${src.dislre.server}" includes="ch/usi/dag/dislreserver/remoteanalysis/** ch/usi/dag/dislreserver/netreference/** ch/usi/dag/dislreserver/classid/**" destdir="bin" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
<target name="compile-test" depends="compile-disl,compile-dislre-server,compile-dislre-dispatch">
<javac srcdir="${src.test}" destdir="bin" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
......
......@@ -674,7 +674,7 @@ static void pack_class(buffer * buff, jclass to_send, JNIEnv * jni_env) {
// ******************* analysis helper methods *******************
static jint analysis_start(jint analysis_method_id, JNIEnv * jni_env) {
static jint analysis_start(jstring analysis_method_desc, JNIEnv * jni_env) {
if(thread_id == 0) {
......@@ -689,8 +689,8 @@ static jint analysis_start(jint analysis_method_id, JNIEnv * jni_env) {
// analysis msg
pack_int(buff, MSG_ANALYZE);
// method id
pack_int(buff, analysis_method_id);
// analysis method desc
pack_string_java(buff, analysis_method_desc, jni_env);
// TODO
// thread id
......@@ -869,9 +869,9 @@ JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
// ******************* REDispatch methods *******************
JNIEXPORT jint JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisStart
(JNIEnv * jni_env, jclass this_class, jint analysis_method_id) {
(JNIEnv * jni_env, jclass this_class, jstring analysis_method_desc) {
return analysis_start(analysis_method_id, jni_env);
return analysis_start(analysis_method_desc, jni_env);
}
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisEnd
......
......@@ -15,10 +15,10 @@ extern "C" {
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: analysisStart
* Signature: (I)I
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisStart
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jstring);
/*
* Class: ch_usi_dag_dislre_REDispatch
......
......@@ -10,8 +10,7 @@ public class REDispatch {
*
* @return session id for consequent send
*/
// TODO re - allow strings with remote string cache support?
public static native int analysisStart(int analysisMethodID);
public static native int analysisStart(String analysisMethodDesc);
/**
* Announce end of an analysis transmission
......
......@@ -24,11 +24,12 @@ public class AnalysisHandler implements RequestHandler {
// *** retrieve method ***
// read method id from network
int analysisMethodId = is.readInt();
// read method string id from network
NetReference analysisMethodStrNR = new NetReference(is.readLong());
// retrieve method
AnalysisMethodHolder amh = AnalysisResolver.getMethod(analysisMethodId);
AnalysisMethodHolder amh = AnalysisResolver.getMethod(
analysisMethodStrNR.getObjectId());
if(debug) {
System.out.println("Processing analysis "
......
......@@ -6,14 +6,20 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import ch.usi.dag.dislreserver.exception.DiSLREServerException;
import ch.usi.dag.dislreserver.exception.DiSLREServerFatalException;
import ch.usi.dag.dislreserver.remoteanalysis.RemoteAnalysis;
import ch.usi.dag.dislreserver.stringcache.StringCache;
public class AnalysisResolver {
private static final Map<Integer, AnalysisMethodHolder> methodMap =
new HashMap<Integer, AnalysisMethodHolder>();
private static final Map<Long, AnalysisMethodHolder> methodMap =
new HashMap<Long, AnalysisMethodHolder>();
private static final Map<String, RemoteAnalysis> analysisMap =
new HashMap<String, RemoteAnalysis>();
// for fast set access - contains all values from analysisMap
private static final Set<RemoteAnalysis> analysisSet =
new HashSet<RemoteAnalysis>();
......@@ -37,11 +43,78 @@ public class AnalysisResolver {
return analysisMethod;
}
}
public static AnalysisMethodHolder getMethod(int methodId) {
private static AnalysisMethodHolder resolveMethod(long methodId)
throws DiSLREServerException {
try {
final String METHOD_DELIM = ".";
String methodStr = StringCache.resolve(methodId);
int classNameEnd = methodStr.lastIndexOf(METHOD_DELIM);
// without METHOD_DELIM
String className = methodStr.substring(0, classNameEnd);
String methodName = methodStr.substring(classNameEnd + 1);
// resolve analysis instance
RemoteAnalysis raInst = analysisMap.get(className);
if(raInst == null) {
// resolve class
Class<?> raClass = Class.forName(className);
// create instance
raInst = (RemoteAnalysis) raClass.newInstance();
analysisMap.put(className, raInst);
analysisSet.add(raInst);
}
// resolve analysis method
Class<?> raClass = raInst.getClass();
Method raMethod = null;
for(Method m : raClass.getMethods()) {
if(m.getName().equals(methodName)) {
// TODO re - check for other methods with same name
// TODO re - write to docs - RemoteAnalysis.class
raMethod = m;
}
}
// TODO re - check that method has after each Class<?> arg, int arg
return new AnalysisMethodHolder(raInst, raMethod);
}
catch (ClassNotFoundException e) {
throw new DiSLREServerException(e);
} catch (InstantiationException e) {
throw new DiSLREServerException(e);
} catch (IllegalAccessException e) {
throw new DiSLREServerException(e);
}
}
public static AnalysisMethodHolder getMethod(long methodId)
throws DiSLREServerException {
AnalysisMethodHolder result = methodMap.get(methodId);
if(result == null) {
result = resolveMethod(methodId);
methodMap.put(methodId, result);
}
if(result == null) {
throw new DiSLREServerFatalException("Unknow method id");
}
......@@ -52,70 +125,4 @@ public class AnalysisResolver {
public static Set<RemoteAnalysis> getAllAnalyses() {
return analysisSet;
}
public static void registerMethod(int methodId,
AnalysisMethodHolder analysisMethod) {
// register method
methodMap.put(methodId, analysisMethod);
// register analysis instance
analysisSet.add(analysisMethod.getAnalysisInstance());
}
static {
// TODO re - should not be hardcoded
// TODO re - after is not hardcoded change build
// in compile-dislre-server
// - no dependency
// in compile-test
// - ,compile-dislre-server,compile-dislre-dispatch should be added to dependences
// - no first javac
try {
Class<? extends RemoteAnalysis> clazz = getClass("ch.usi.dag.disl.test.dispatch.CodeExecuted");
RemoteAnalysis instance = clazz.newInstance();
Method m1 = clazz.getMethod("bytecodesExecuted", int.class);
registerMethod(1, new AnalysisMethodHolder(instance, m1));
Method m2 = clazz.getMethod("testingBasic",
boolean.class, byte.class, char.class, short.class,
int.class, long.class, float.class, double.class);
registerMethod(2, new AnalysisMethodHolder(instance, m2));
Method m3 = clazz.getMethod("testingAdvanced",
String.class, Object.class, Class.class, int.class);
registerMethod(3, new AnalysisMethodHolder(instance, m3));
Method m4 = clazz.getMethod("testingAdvanced2",
Object.class, Object.class, Object.class, Object.class,
Class.class, int.class, Class.class, int.class,
Class.class, int.class, Class.class, int.class);
registerMethod(4, new AnalysisMethodHolder(instance, m4));
} catch (Exception e) {
System.err.println("[AnalysisResolver.<clinit>] " + e);
System.err.flush();
}
try {
Class<? extends RemoteAnalysis> clazz = getClass("ch.usi.dag.disl.example.codeCov.CodeCoverage");
RemoteAnalysis instance2 = clazz.newInstance();
Method m5 = clazz.getMethod("onConstructor", Class.class);
registerMethod(5, new AnalysisMethodHolder(instance2, m5));
Method m6 = clazz.getMethod("onBB", String.class, int.class);
registerMethod(6, new AnalysisMethodHolder(instance2, m6));
} catch (Exception e) {
System.err.println("[AnalysisResolver.<clinit>] " + e);
System.err.flush();
}
}
private static Class<? extends RemoteAnalysis> getClass(String className) throws ClassNotFoundException, ClassCastException {
Class<?> clazz = Class.forName(className);
return clazz.asSubclass(RemoteAnalysis.class);
}
}
......@@ -11,7 +11,8 @@ public class CodeExecutedRE {
public static void bytecodesExecuted(int count) {
int sid = REDispatch.analysisStart(1);
int sid = REDispatch.analysisStart(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.bytecodesExecuted");
REDispatch.sendInt(sid, count);
......@@ -21,7 +22,8 @@ public class CodeExecutedRE {
public static void testingBasic(boolean b, byte by, char c, short s, int i,
long l, float f, double d) {
int sid = REDispatch.analysisStart(2);
int sid = REDispatch.analysisStart(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingBasic");
REDispatch.sendBoolean(sid, b);
REDispatch.sendByte(sid, by);
......@@ -38,7 +40,8 @@ public class CodeExecutedRE {
public static void testingAdvanced(String s, Object o, Class<?> c,
int classID) {
int sid = REDispatch.analysisStart(3);
int sid = REDispatch.analysisStart(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingAdvanced");
REDispatch.sendString(sid, s);
REDispatch.sendObject(sid, o);
......@@ -52,7 +55,8 @@ public class CodeExecutedRE {
Object o4, Class<?> class1, int cid1, Class<?> class2, int cid2,
Class<?> class3, int cid3, Class<?> class4, int cid4) {
int sid = REDispatch.analysisStart(4);
int sid = REDispatch.analysisStart(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingAdvanced2");
REDispatch.sendObject(sid, o1);
REDispatch.sendObject(sid, o2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment