Commit 1f7c8e57 authored by Lukáš Marek's avatar Lukáš Marek

Additional bugfixes and improvements to the DiSLServer

Tests are working
parent 83438b2d
asm.path=lib/asm-debug-all-4.0.jar
asm.lib=asm-debug-all-4.0.jar
asm.path=lib/${asm.lib}
src.disl=src
src.dynbypass=src-dynbypass
......
<project name="disl" default="package" basedir=".">
<project name="disl" default="prepare-all" basedir=".">
<property file="build.properties" />
<property file="disl.version" />
......@@ -61,7 +61,7 @@
excludes="ch/usi/dag/disl/test/**,ch/usi/dag/disl/testtools/**">
<manifest>
<attribute name="Class-Path" value="${instr.jar.name}" />
<attribute name="Class-Path" value="${asm.lib} ${instr.jar.name}" />
<attribute name="Main-Class" value="ch.usi.dag.dislserver.DiSLServer" />
</manifest>
</jar>
......@@ -86,6 +86,7 @@
<manifest>
<attribute name="Class-Path" value="${instr.jar.name}" />
<attribute name="Premain-Class" value="ch.usi.dag.dislagent.DiSLAgent" />
<attribute name="Can-Redefine-Classes" value="true" />
</manifest>
<!-- include after bootstrap class -->
......@@ -116,6 +117,12 @@
<target name="eclipse" depends="eclipse-dynamicbypass,eclipse-agent" />
<target name="copy-asm">
<copy file="${asm.path}" tofile="${build}/${asm.lib}" />
</target>
<target name="prepare-all" depends="package,eclipse,compile-test,copy-asm" />
<target name="clean">
<delete dir="${bin}" />
<delete dir="${build}" />
......
#!/bin/bash
OS=`uname`
if [ "${OS}" = "Darwin" ]; then
JBORAT_AGENT="src-agent-c/libdislagent.jnilib"
else
JBORAT_AGENT="src-agent-c/libdislagent.so"
fi
# ipc.socket is the default communication
# to enable shared memory, remove ",ipc.socket" from the options
JBORAT_AGENT_OPTS="1234,localhost,ipc.socket"
java -XX:MaxPermSize=128m \
-Xmx2G \
-javaagent:build/dislagent-unspec.jar \
-Xbootclasspath/p:build/dislagent-unspec.jar \
-agentpath:${JBORAT_AGENT}=${JBORAT_AGENT_OPTS} \
-cp ./bin \
$*
#!/bin/sh
# available options
# -Ddebug=true \
# -Ddisl.noexcepthandler=true \
# -Ddislserver.instrumented="path" \
# -Ddislserver.uninstrumented="path" \
# -Ddislserver.port="portNum" \
# -Ddislserver.exclusionList="path"
java -Ddislserver.port="1234" \
$* \
-jar build/dislserver-unspec.jar \
&
echo $! > ${SERVER_FILE}
# /bin/sh
EXPECTED_ARGS=1
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` test-case"
exit
fi
SERVER_FILE=.server.pid
export SERVER_FILE
# kill running server
if [ -e ${SERVER_FILE} ]
then
kill -KILL `cat ${SERVER_FILE}`
rm .server.pid
fi
DISL_CLASS="./bin/ch/usi/dag/disl/test/$1/DiSLClass.class"
TARGET_CLASS="ch.usi.dag.disl.test.$1.TargetClass"
# start server and take pid
./runServer.sh -Ddisl.classes=${DISL_CLASS}
# wait for server startup
sleep 3
# run client
./runClient.sh ${TARGET_CLASS}
# wait for server shutdown
sleep 1
# kill server
kill -KILL `cat ${SERVER_FILE}` 2> /dev/null
rm .server.pid
......@@ -5,7 +5,7 @@ public class DynamicBypassCheck {
// this version is executed after bootstrap phase
// and is it the replacement for version in src-dynbypass directory
public static boolean executeUninstrumente() {
public static boolean executeUninstrumented() {
return DynamicBypass.isActivated();
}
}
......@@ -35,7 +35,6 @@ public abstract class CodeMerger {
boolean methodAbstract = (instrMN.access & Opcodes.ACC_ABSTRACT) != 0;
boolean methodNative = (instrMN.access & Opcodes.ACC_NATIVE) != 0;
// TODO jb ! test
boolean methodFinalizeInObject = instrumentedCN.name.equals(Type
.getInternalName(Object.class))
&& instrMN.name.equals(METHOD_FINALIZE);
......
......@@ -28,8 +28,12 @@ public class NetClassReader {
// bytes[cnl] - class name
// bytes[cl] - class code
int nameLength = is.readInt();
int codeLength = is.readInt();
// TODO jb !
//int nameLength = is.readInt();
//int codeLength = is.readInt();
int nameLength = readInt(is);
int codeLength = readInt(is);
// end of communication
if(nameLength == 0 && codeLength == 0) {
......@@ -61,10 +65,56 @@ public class NetClassReader {
// bytes[cnl] - class name
// bytes[cl] - class code
os.write(cab.getName().length);
os.write(cab.getCode().length);
// TODO jb !
//os.write(cab.getName().length);
//os.write(cab.getCode().length);
writeInt(os, cab.getName().length);
writeInt(os, cab.getCode().length);
os.write(cab.getName());
os.write(cab.getCode());
os.flush();
}
// TODO jb ! remove all below ===
private static int readInt(DataInputStream dis) throws IOException {
byte[] data = new byte[4];
dis.read(data);
return byteArrayToInt(data);
}
private static void writeInt(OutputStream os, int value) throws IOException {
os.write(intToByteArray(value));
}
private static int byteArrayToInt(byte[] b) {
int value = 0;
// REVERT THE VALUE OF THE PART CONTAINING THE INT
byte[] mybuf = new byte[4];
for (int i = 0; i < 4; i++) {
mybuf[i] = b[3 - i];
}
for (int i = 0; i < 4; i++) {
int shift = (4 - 1 - i) * 8;
// value += (mybuf[i + offset] & 0x000000FF) << shift;
value += (mybuf[i] & 0x000000FF) << shift;
}
return value;
}
private static byte[] intToByteArray(int value) {
byte[] dest = new byte[4];
for (int idx = 0; idx < 4; idx++) {
dest[idx] = ((byte) (value >>> (idx * 8)));
}
return dest;
}
}
......@@ -100,20 +100,25 @@ public class Worker extends Thread {
Set<String> exclSet = new HashSet<String>();
// read exclusion list line by line
Scanner scanner = new Scanner(new FileInputStream(excListPath));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(! line.startsWith(COMMENT_START)) {
exclSet.add(internClassName(line));
// if exclusion list path exits
if(excListPath != null) {
// read exclusion list line by line
Scanner scanner = new Scanner(new FileInputStream(excListPath));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(! line.startsWith(COMMENT_START)) {
exclSet.add(internClassName(line));
}
}
scanner.close();
}
scanner.close();
// TODO jb ! add classes from agent and instrumentation jar
// add classes that are excluded by default
addDefaultExcludes(exclSet);
return exclSet;
......@@ -122,6 +127,20 @@ public class Worker extends Thread {
}
}
private void addDefaultExcludes(Set<String> exclSet) {
// all DiSL agent classes
exclSet.add(internClassName("ch.usi.dag.dislagent.*"));
// all dynamic bypass classes
exclSet.add(internClassName("ch.usi.dag.disl.dynamicbypass.*"));
// all java instrument classes
exclSet.add(internClassName("sun.instrument.*"));
// TODO jb ! add classes from instrumentation jar
}
private String internClassName(String normalClassName) {
return normalClassName.replace(
......
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