Commit 3556f0a1 authored by Lukáš Marek's avatar Lukáš Marek

REDispatch now supports sending objects with or without additional data

Improved sendig of additional data for String and Thread
Fixed and improved dispatch test
parent 48ece151
This diff is collapsed.
......@@ -9,129 +9,6 @@ extern "C" {
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved);
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: registerMethod
* Signature: (Ljava/lang/String;)S
*/
JNIEXPORT jshort JNICALL Java_ch_usi_dag_dislre_REDispatch_registerMethod
(JNIEnv *, jclass, jstring);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: analysisStart
* Signature: (S)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisStart__S
(JNIEnv *, jclass, jshort);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: analysisStart
* Signature: (SB)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisStart__SB
(JNIEnv *, jclass, jshort, jbyte);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: analysisEnd
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_analysisEnd
(JNIEnv *, jclass);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendBoolean
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendBoolean
(JNIEnv *, jclass, jboolean);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendByte
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendByte
(JNIEnv *, jclass, jbyte);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendChar
* Signature: (C)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendChar
(JNIEnv *, jclass, jchar);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendShort
* Signature: (S)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendShort
(JNIEnv *, jclass, jshort);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendInt
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendInt
(JNIEnv *, jclass, jint);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendLong
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendLong
(JNIEnv *, jclass, jlong);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendFloatAsInt
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendFloatAsInt
(JNIEnv *, jclass, jint);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendDoubleAsLong
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendDoubleAsLong
(JNIEnv *, jclass, jlong);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendString
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendString
(JNIEnv *, jclass, jstring);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendObject
* Signature: (Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendObject
(JNIEnv *, jclass, jobject);
/*
* Class: ch_usi_dag_dislre_REDispatch
* Method: sendClass
* Signature: (Ljava/lang/Class;)V
*/
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendClass
(JNIEnv *, jclass, jclass);
#ifdef __cplusplus
}
#endif
......
......@@ -22,10 +22,14 @@ static volatile jint avail_class_id;
// should be in sync with NetReference on the server
// format of net reference looks like this
// HIGHEST (1 bit spec, 23 bits class id, 40 bits object id)
// format of net reference looks like this (from HIGHEST)
// 1 bit data trans., 1 bit class instance, 23 bits class id, 40 bits object id
// bit field not used because there is no guarantee of alignment
// TODO rename SPEC
// SPEC flag is used to indicate if some additional data for this object where
// transfered to the server
static const uint8_t OBJECT_ID_POS = 0;
static const uint8_t CLASS_ID_POS = 40;
static const uint8_t CLASS_INSTANCE_POS = 62;
......@@ -141,15 +145,6 @@ static int _object_is_class(jvmtiEnv * jvmti_env, jobject obj) {
return TRUE;
}
static jvmtiError _try_get_threadinfo(jvmtiEnv * jvmti_env, jobject obj,
jvmtiThreadInfo *info_ptr) {
// TODO isn't there better way?
jvmtiError error = (*jvmti_env)->GetThreadInfo(jvmti_env, obj, info_ptr);
return error;
}
// does not increment any counter - just sets the values
static jlong _set_net_reference(jvmtiEnv * jvmti_env, jobject obj,
jlong object_id, jint class_id, unsigned char spec, unsigned char cbit) {
......@@ -193,24 +188,6 @@ static void _pack_class_info(buffer * buff, jlong class_net_ref,
}
static void _pack_thread_info(buffer * buff, jlong net_ref, const char *name,
jboolean isDaemon) {
// pack thread info message
// msg id
pack_byte(buff, MSG_THREAD_INFO);
// object id
pack_long(buff, net_ref);
// thread name
pack_string_utf8(buff, name, strlen(name));
// is daemon thread
pack_boolean(buff, isDaemon);
}
static jlong _set_net_reference_for_class(JNIEnv * jni_env,
jvmtiEnv * jvmti_env, buffer * buff, jclass klass) {
......@@ -311,14 +288,6 @@ static jlong _set_net_reference_for_object(JNIEnv * jni_env,
jlong net_ref =
_set_net_reference(jvmti_env, obj, avail_object_id, class_id, 0, 0);
jvmtiThreadInfo info;
jvmtiError error;
if ((error = _try_get_threadinfo(jvmti_env, obj, &info))
== JVMTI_ERROR_NONE) {
_pack_thread_info(buff, net_ref, info.name, info.is_daemon);
}
// increment object id counter
++avail_object_id;
......
......@@ -42,9 +42,8 @@ public class REDispatch {
public static native void sendLong(long longToSend);
public static native void sendFloatAsInt(int floatAsIntToSend);
public static native void sendDoubleAsLong(long doubleAsLongToSend);
public static native void sendString(String stringToSend);
public static native void sendObject(Object objToSend);
public static native void sendClass(Class<?> classToSend);
public static native void sendObjectPlusData(Object objToSend);
// helper methods for sending float and double
// for proper conversion, we would still need to call ...Bits methods
......
......@@ -4,6 +4,7 @@ import ch.usi.dag.dislreserver.remoteanalysis.RemoteAnalysis;
import ch.usi.dag.dislreserver.shadow.ShadowClass;
import ch.usi.dag.dislreserver.shadow.ShadowObject;
import ch.usi.dag.dislreserver.shadow.ShadowString;
import ch.usi.dag.dislreserver.shadow.ShadowThread;
// NOTE that this class is not static anymore
public class CodeExecuted extends RemoteAnalysis {
......@@ -50,27 +51,43 @@ public class CodeExecuted extends RemoteAnalysis {
}
}
public static void testingAdvanced(ShadowString s, ShadowObject o, ShadowClass c) {
public static void testingAdvanced(ShadowObject s, ShadowObject o, ShadowObject c, ShadowObject t) {
if(! s.toString().equals("Corect transfer of String")) {
throw new RuntimeException("Incorect transfer of String");
}
long objId = ((ShadowObject)o).getId();
if(! (s instanceof ShadowObject)) {
throw new RuntimeException("This string should be transfered as string");
}
// object id should be non 0
if(! (o instanceof ShadowObject) || objId == 0) {
throw new RuntimeException("Incorect transfer of Object");
if(o.getId() == 0) {
throw new RuntimeException("Object id should not be null");
}
System.out.println("Received object id: " + o.getId());
if(o instanceof ShadowString) {
throw new RuntimeException("This string should be transfered as object");
}
System.out.println("Received object id: " + objId);
if(! (c instanceof ShadowClass)) {
throw new RuntimeException("This class should be transfered as class");
}
// class id should be non 0
if(! (c instanceof ShadowClass) || c.getClassId() == 0) {
throw new RuntimeException("Incorect transfer of Class");
if(((ShadowClass) c).getClassId() == 0) {
throw new RuntimeException("Class id should not be null");
}
System.out.println("Received class id: " + ((ShadowClass) c).getClassId());
if(! (t instanceof ShadowThread)) {
throw new RuntimeException("This thread should be transfered as thread");
}
System.out.println("Received class id: " + c.getClassId());
System.out.println("Received thread: " + ((ShadowThread) t).getName() + " is deamon " + ((ShadowThread) t).isDaemon());
}
public static void printClassInfo(ShadowClass sc) {
......@@ -88,16 +105,16 @@ public class CodeExecuted extends RemoteAnalysis {
ShadowClass class2, ShadowClass class3, ShadowClass class4) {
System.out.println("* o1 class *");
printClassInfo(((ShadowObject)o1).getShadowClass());
printClassInfo(o1.getShadowClass());
System.out.println("* o2 class *");
printClassInfo(o2.getShadowClass());
System.out.println("* o3 class *");
printClassInfo(((ShadowObject)o3).getShadowClass());
printClassInfo(o3.getShadowClass());
System.out.println("* o4 class *");
printClassInfo(((ShadowObject)o4).getShadowClass());
printClassInfo(o4.getShadowClass());
System.out.println("* class 1 *");
printClassInfo(class1);
......
......@@ -52,21 +52,21 @@ public class CodeExecutedRE {
}
public static void testingAdvanced(String s, Object o, Class<?> c,
int classID) {
Thread t) {
REDispatch.analysisStart(taId);
REDispatch.sendString(s);
REDispatch.sendObjectPlusData(s);
REDispatch.sendObject(o);
REDispatch.sendClass(c);
// class_id ignored
REDispatch.sendObject(c);
REDispatch.sendObjectPlusData(t);
REDispatch.analysisEnd();
}
public static void testingAdvanced2(Object o1, Object o2, Object o3,
Object o4, Class<?> class1, int cid1, Class<?> class2, int cid2,
Class<?> class3, int cid3, Class<?> class4, int cid4) {
Object o4, Class<?> class1, Class<?> class2,
Class<?> class3, Class<?> class4) {
REDispatch.analysisStart(ta2Id);
......@@ -74,14 +74,10 @@ public class CodeExecutedRE {
REDispatch.sendObject(o2);
REDispatch.sendObject(o3);
REDispatch.sendObject(o4);
REDispatch.sendClass(class1);
// class_id ignored
REDispatch.sendClass(class2);
// class_id ignored
REDispatch.sendClass(class3);
// class_id ignored
REDispatch.sendClass(class4);
// class_id ignored
REDispatch.sendObject(class1);
REDispatch.sendObject(class2);
REDispatch.sendObject(class3);
REDispatch.sendObject(class4);
REDispatch.analysisEnd();
}
......@@ -90,9 +86,9 @@ public class CodeExecutedRE {
REDispatch.analysisStart(tnId);
REDispatch.sendString(s);
REDispatch.sendObjectPlusData(s);
REDispatch.sendObject(o);
REDispatch.sendClass(c);
REDispatch.sendObject(c);
REDispatch.analysisEnd();
}
......
......@@ -20,12 +20,12 @@ public class DiSLClass {
CodeExecutedRE.testingBasic(true, (byte) 125, 's', (short) 50000,
100000, 10000000000L, 1.5F, 2.5);
CodeExecutedRE.testingAdvanced("Corect transfer of String", new Object(), Object.class, 0);
CodeExecutedRE.testingAdvanced("Corect transfer of String", "test", Object.class, Thread.currentThread());
CodeExecutedRE.testingAdvanced2(new LinkedList<String>(),
new LinkedList<Integer>(), new LinkedList[0], new int[0],
int[].class, 0, int.class, 0, LinkedList.class, 0,
LinkedList.class.getClass(), 0);
int[].class, int.class, LinkedList.class,
LinkedList.class.getClass());
CodeExecutedRE.testingNull(null, null, null);
}
......
Markdown is supported
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