Commit 62408d43 authored by František Haas's avatar František Haas

completed dispatch tests

added evaluation server to disl.py
added dispatch example
parent ff824b3e
......@@ -84,6 +84,14 @@ values of local variables, object instance in member methods, method arguments
or current exceptions.
--------------------------------------------------------------------------------
-- dispatch
--------------------------------------------------------------------------------
This example shows how to evaluate instrumented code on evaluation jvm. For
more details try running this example directly using disl.py and supplying
'c_out' and 'e_out' options.
================================================================================
= HOW TO RUN THE EXAMPLE
================================================================================
......
lib.path=../../../build
dislserver.path=${lib.path}/disl-server.jar
dislre.server.path=${lib.path}/dislre-server.jar
dislre.dispatch.path=${lib.path}/dislre-dispatch.jar
asm.lib=asm-debug-all-4.0.jar
asm.path=${lib.path}/${asm.lib}
......
<project name="disl-example" default="run" basedir=".">
<target name="clean">
<ant antfile="dispatch/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="dynamic/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="guard/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="marker/build.xml" target="clean" useNativeBasedir="true" />
......@@ -9,6 +10,7 @@
</target>
<target name="run">
<ant antfile="dispatch/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="dynamic/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="guard/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="marker/build.xml" target="run" useNativeBasedir="true" />
......
This diff is collapsed.
<project name="example-app" default="package" basedir=".">
<target name="compile">
<mkdir dir="bin" />
<javac srcdir="src" destdir="bin" debug="true" includeAntRuntime="false">
</javac>
</target>
<target name="package" depends="compile">
<mkdir dir="build" />
<jar basedir="bin" destfile="build/example-app.jar">
<manifest>
<attribute name="Main-Class" value="Main" />
</manifest>
</jar>
</target>
<target name="clean">
<delete dir="bin" />
<delete dir="build" />
</target>
</project>
public class Main {
public void empty() {
}
public static void main(String[] args) {
System.out.println("app: main");
Main m = new Main();
m.empty();
}
}
<project name="disl-example" default="prepare-all" basedir=".">
<target name="prepare-all">
<ant antfile="app/build.xml" target="package" useNativeBasedir="true" />
<ant antfile="instr/build.xml" target="package" useNativeBasedir="true" />
</target>
<target name="clean">
<ant antfile="app/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="instr/build.xml" target="clean" useNativeBasedir="true" />
</target>
<target name="run" depends="prepare-all">
<exec executable="../disl.py">
<arg value="-cse" />
<!-- <arg value="-c_out=client.out" /> -->
<!-- <arg value="-e_out=evaluation.out" /> -->
<arg value="--" />
<arg value="instr/build/disl-instr.jar" />
<arg value="-jar" />
<arg value="app/build/example-app.jar" />
</exec>
</target>
</project>
<project name="example-disl" default="package" basedir=".">
<property file="../../build.properties" />
<path id="buildpath">
<pathelement location="${asm.path}" />
<pathelement location="${dislserver.path}" />
<pathelement location="${dislre.server.path}" />
<pathelement location="${dislre.dispatch.path}" />
</path>
<target name="compile">
<mkdir dir="bin" />
<javac srcdir="src" destdir="bin" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
</target>
<target name="package" depends="compile" description="create instrumentation package">
<mkdir dir="build"/>
<jar jarfile="build/${instr.jar.name}"
basedir="bin"
excludes="MANIFEST.MF"
manifest="src/MANIFEST.MF">
</jar>
</target>
<target name="clean">
<delete dir="bin" />
<delete dir="build" />
</target>
</project>
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 {
long totalExecutedBytecodes = 0;
public void bytecodesExecuted(final int count) {
totalExecutedBytecodes += count;
}
// FIXME
//public void testingBasic(final boolean b, final byte by, final char c, final short s, final int i, final long l,
// final float f, final double d) {
public void testingBasic(final boolean b, final byte by, final char c, final short s, final int i, final long l) {
if(b != true) {
throw new RuntimeException("Incorect transfer of boolean");
}
if(by != (byte) 125) {
throw new RuntimeException("Incorect transfer of byte");
}
if(c != 's') {
throw new RuntimeException("Incorect transfer of char");
}
if(s != (short) 50000) {
throw new RuntimeException("Incorect transfer of short");
}
if(i != 100000) {
throw new RuntimeException("Incorect transfer of int");
}
if(l != 10000000000L) {
throw new RuntimeException("Incorect transfer of long");
}
// FIXME
//if(f != 1.5F) {
// throw new RuntimeException("Incorect transfer of float");
//}
// FIXME
//if(d != 2.5) {
// throw new RuntimeException("Incorect transfer of double");
//}
}
public static void testingAdvanced(final ShadowObject s, final ShadowObject o, final ShadowObject c, final ShadowObject t) {
if(! (s instanceof ShadowString)) {
throw new RuntimeException("This string should be transfered as string");
}
if(! s.toString().equals("Corect transfer of String")) {
throw new RuntimeException("Incorect transfer of String");
}
// object id should be non 0
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 string");
}
if(((ShadowString)o).toString() != null) {
throw new RuntimeException("This string should be transfered without data");
}
if(! (c instanceof ShadowClass)) {
throw new RuntimeException("This class should be transfered as class");
}
if(! (t instanceof ShadowThread)) {
throw new RuntimeException("This thread should be transfered as thread");
}
System.out.println("Received thread: " + ((ShadowThread) t).getName() + " is deamon " + ((ShadowThread) t).isDaemon());
}
public static void printClassInfo(final ShadowClass sc) {
if(sc == null) {
System.out.println("null");
return;
}
System.out.println("name: " + sc.getName());
}
public static void testingAdvanced2(final ShadowObject o1, final ShadowObject o2,
final ShadowObject o3, final ShadowObject o4, final ShadowClass class1,
final ShadowClass class2, final ShadowClass class3, final ShadowClass class4) {
System.out.println("* o1 class *");
printClassInfo(o1.getShadowClass());
System.out.println("* o2 class *");
printClassInfo(o2.getShadowClass());
System.out.println("* o3 class *");
printClassInfo(o3.getShadowClass());
System.out.println("* o4 class *");
printClassInfo(o4.getShadowClass());
System.out.println("* class 1 *");
printClassInfo(class1);
System.out.println("* class 2 *");
printClassInfo(class2);
System.out.println("* class 3 *");
printClassInfo(class3);
System.out.println("* class 4 *");
printClassInfo(class4);
}
public static void testingNull(final ShadowString s, final ShadowObject o, final ShadowClass c) {
if(s != null) {
throw new RuntimeException("String is not null");
}
if(o != null) {
throw new RuntimeException("Object is not null");
}
if(c != null) {
throw new RuntimeException("Class is not null");
}
}
@Override
public void atExit() {
System.out.println("Total number of executed bytecodes: "
+ totalExecutedBytecodes);
}
@Override
public void objectFree(final ShadowObject netRef) {
System.out.println("Object free for id " + netRef.getId());
}
}
import ch.usi.dag.dislre.REDispatch;
// Optimally, this class is automatically created on analysis machine
// and redefines during loading the CodeExecuted class on the client vm
// Even more optimally, this is automatically generated native class with same
// functionality
public class CodeExecutedRE {
private static short beId = REDispatch.registerMethod(
"CodeExecuted.bytecodesExecuted");
private static short tbId = REDispatch.registerMethod(
"CodeExecuted.testingBasic");
private static short taId = REDispatch.registerMethod(
"CodeExecuted.testingAdvanced");
private static short ta2Id = REDispatch.registerMethod(
"CodeExecuted.testingAdvanced2");
private static short tnId = REDispatch.registerMethod(
"CodeExecuted.testingNull");
public static void bytecodesExecuted(final int count) {
final byte orderingid = 1;
REDispatch.analysisStart(beId, orderingid);
REDispatch.sendInt(count);
REDispatch.analysisEnd();
}
public static void testingBasic(final boolean b, final byte by, final char c, final short s, final int i,
final long l) {
REDispatch.analysisStart(tbId);
REDispatch.sendBoolean(b);
REDispatch.sendByte(by);
REDispatch.sendChar(c);
REDispatch.sendShort(s);
REDispatch.sendInt(i);
REDispatch.sendLong(l);
REDispatch.analysisEnd();
}
public static void testingAdvanced(final String s, final Object o, final Class<?> c,
final Thread t) {
REDispatch.analysisStart(taId);
REDispatch.sendObjectPlusData(s);
REDispatch.sendObject(o);
REDispatch.sendObject(c);
REDispatch.sendObjectPlusData(t);
REDispatch.analysisEnd();
}
public static void testingAdvanced2(final Object o1, final Object o2, final Object o3,
final Object o4, final Class<?> class1, final Class<?> class2,
final Class<?> class3, final Class<?> class4) {
REDispatch.analysisStart(ta2Id);
REDispatch.sendObject(o1);
REDispatch.sendObject(o2);
REDispatch.sendObject(o3);
REDispatch.sendObject(o4);
REDispatch.sendObject(class1);
REDispatch.sendObject(class2);
REDispatch.sendObject(class3);
REDispatch.sendObject(class4);
REDispatch.analysisEnd();
}
public static void testingNull(final String s, final Object o, final Class<?> c) {
REDispatch.analysisStart(tnId);
REDispatch.sendObjectPlusData(s);
REDispatch.sendObject(o);
REDispatch.sendObject(c);
REDispatch.analysisEnd();
}
}
import org.objectweb.asm.tree.AbstractInsnNode;
import ch.usi.dag.disl.staticcontext.AbstractStaticContext;
public class CodeLengthSC extends AbstractStaticContext {
public int methodSize() {
return staticContextData.getMethodNode().instructions.size();
}
public int codeSize() {
AbstractInsnNode ain = staticContextData.getRegionStart();
int size = 0;
// count the size until the first end
while(ain != null && ain != staticContextData.getRegionEnds().get(0)) {
++size;
ain = ain.getNext();
}
if(ain == null) {
size = 0;
}
return size;
}
}
import java.util.LinkedList;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.marker.BasicBlockMarker;
import ch.usi.dag.disl.marker.BodyMarker;
public class DiSLClass {
@After(marker = BasicBlockMarker.class, scope = "Main.*")
public static void invokedInstr(final CodeLengthSC clsc) {
CodeExecutedRE.bytecodesExecuted(clsc.codeSize());
}
@After(marker = BodyMarker.class, scope = "Main.main")
public static void testing() {
CodeExecutedRE.testingBasic(true, (byte) 125, 's', (short) 50000, 100000, 10000000000L);
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, int.class, LinkedList.class,
LinkedList.class.getClass());
CodeExecutedRE.testingNull(null, null, null);
}
}
Manifest-Version: 1.0
DiSL-Classes: DiSLClass
\ No newline at end of file
......@@ -10,53 +10,56 @@ import ch.usi.dag.dislreserver.shadow.ShadowThread;
public class CodeExecuted extends RemoteAnalysis {
long totalExecutedBytecodes = 0;
public void bytecodesExecuted(int count) {
public void bytecodesExecuted(final int count) {
totalExecutedBytecodes += count;
}
public void testingBasic(boolean b, byte by, char c, short s, int i, long l,
float f, double d) {
// FIXME
//public void testingBasic(final boolean b, final byte by, final char c, final short s, final int i, final long l,
// final float f, final double d) {
public void testingBasic(final boolean b, final byte by, final char c, final short s, final int i, final long l) {
if(b != true) {
throw new RuntimeException("Incorect transfer of boolean");
}
if(by != (byte) 125) {
throw new RuntimeException("Incorect transfer of byte");
}
if(c != 's') {
throw new RuntimeException("Incorect transfer of char");
}
if(s != (short) 50000) {
throw new RuntimeException("Incorect transfer of short");
}
if(i != 100000) {
throw new RuntimeException("Incorect transfer of int");
}
if(l != 10000000000L) {
throw new RuntimeException("Incorect transfer of long");
}
if(f != 1.5F) {
throw new RuntimeException("Incorect transfer of float");
}
if(d != 2.5) {
throw new RuntimeException("Incorect transfer of double");
}
// FIXME
//if(f != 1.5F) {
// throw new RuntimeException("Incorect transfer of float");
//}
// FIXME
//if(d != 2.5) {
// throw new RuntimeException("Incorect transfer of double");
//}
}
public static void testingAdvanced(ShadowObject s, ShadowObject o, ShadowObject c, ShadowObject t) {
public static void testingAdvanced(final ShadowObject s, final ShadowObject o, final ShadowObject c, final ShadowObject t) {
if(! (s instanceof ShadowString)) {
throw new RuntimeException("This string should be transfered as string");
}
if(! s.toString().equals("Corect transfer of String")) {
throw new RuntimeException("Incorect transfer of String");
}
......@@ -65,89 +68,91 @@ public class CodeExecuted extends RemoteAnalysis {
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 string");
}
if(((ShadowString)o).toString() != null) {
throw new RuntimeException("This string should be transfered without data");
}
if(! (c instanceof ShadowClass)) {
throw new RuntimeException("This class should be transfered as class");
}
if(! (t instanceof ShadowThread)) {
throw new RuntimeException("This thread should be transfered as thread");
}
System.out.println("Received thread: " + ((ShadowThread) t).getName() + " is deamon " + ((ShadowThread) t).isDaemon());
}
public static void printClassInfo(ShadowClass sc) {
public static void printClassInfo(final ShadowClass sc) {
if(sc == null) {
System.out.println("null");
return;
}
System.out.println("name: " + sc.getName());
}
public static void testingAdvanced2(ShadowObject o1, ShadowObject o2,
ShadowObject o3, ShadowObject o4, ShadowClass class1,
ShadowClass class2, ShadowClass class3, ShadowClass class4) {
public static void testingAdvanced2(final ShadowObject o1, final ShadowObject o2,
final ShadowObject o3, final ShadowObject o4, final ShadowClass class1,
final ShadowClass class2, final ShadowClass class3, final ShadowClass class4) {
System.out.println("* o1 class *");
printClassInfo(o1.getShadowClass());
System.out.println("* o2 class *");
printClassInfo(o2.getShadowClass());
System.out.println("* o3 class *");
printClassInfo(o3.getShadowClass());
System.out.println("* o4 class *");
printClassInfo(o4.getShadowClass());
System.out.println("* class 1 *");
printClassInfo(class1);
System.out.println("* class 2 *");
printClassInfo(class2);
System.out.println("* class 3 *");
printClassInfo(class3);
System.out.println("* class 4 *");
printClassInfo(class4);
}
public static void testingNull(ShadowString s, ShadowObject o, ShadowClass c) {
public static void testingNull(final ShadowString s, final ShadowObject o, final ShadowClass c) {
if(s != null) {
throw new RuntimeException("String is not null");
}
if(o != null) {
throw new RuntimeException("Object is not null");
}
if(c != null) {
throw new RuntimeException("Class is not null");
}
}
public void atExit() {
@Override
public void atExit() {
System.out.println("Total number of executed bytecodes: "
+ totalExecutedBytecodes);
}
public void objectFree(ShadowObject netRef) {
@Override
public void objectFree(final ShadowObject netRef) {
System.out.println("Object free for id " + netRef.getId());
}
}
......@@ -10,66 +10,70 @@ import ch.usi.dag.dislre.REDispatch;
public class CodeExecutedRE {
private static short beId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.bytecodesExecuted");
"ch.usi.dag.disl.test2.suite.dispatch.instr.CodeExecuted.bytecodesExecuted");
private static short tbId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingBasic");
"ch.usi.dag.disl.test2.suite.dispatch.instr.CodeExecuted.testingBasic");
private static short taId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingAdvanced");
"ch.usi.dag.disl.test2.suite.dispatch.instr.CodeExecuted.testingAdvanced");
private static short ta2Id = REDispatch.registerMethod(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingAdvanced2");
"ch.usi.dag.disl.test2.suite.dispatch.instr.CodeExecuted.testingAdvanced2");
private static short tnId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.dispatch.CodeExecuted.testingNull");
public static void bytecodesExecuted(int count) {
"ch.usi.dag.disl.test2.suite.dispatch.instr.CodeExecuted.testingNull");
public static void bytecodesExecuted(final int count) {
final byte orderingid = 1;
REDispatch.analysisStart(beId, orderingid);
REDispatch.sendInt(count);
REDispatch.analysisEnd();
}
public static void testingBasic(boolean b, byte by, char c, short s, int i,
long l, float f, double d) {
// FIXME
//public static void testingBasic(final boolean b, final byte by, final char c, final short s, final int i,
// final long l, final float f, final double d) {