Commit 9939566f authored by Lukáš Marek's avatar Lukáš Marek

Added skeleton for remote evaluation

parent 279a88e3
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-re-server"/>
<classpathentry kind="src" path="src-agent-java"/>
<classpathentry kind="src" path="src-test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
......
......@@ -5,6 +5,7 @@ src.disl=src
src.dynbypass=src-dynbypass
src.dynbypass.act=src-dynbypass-act
src.agent.java=src-agent-java
src.dislre=src-re-server
src.test=src-test
bin=bin
......
......@@ -47,13 +47,19 @@
</javac>
</target>
<target name="compile-dislre">
<javac srcdir="${src.dislre}" destdir="${bin}" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
</target>
<target name="compile-test" depends="compile-disl">
<javac srcdir="${src.test}" destdir="bin" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
</target>
<target name="compile" depends="compile-disl,compile-agent-java,compile-test" />
<target name="compile" depends="compile-disl,compile-agent-java,compile-test,compile-dislre" />
<target name="package-dislserver" depends="compile-disl">
<jar basedir="${bin}" destfile="${build}/dislserver-${disl.version}.jar"
......@@ -67,6 +73,17 @@
</jar>
</target>
<target name="package-dislreserver" depends="compile-dislre">
<jar basedir="${bin}" destfile="${build}/dislreserver-${disl.version}.jar"
includes="ch/usi/dag/dislreserver/**">
<manifest>
<attribute name="Class-Path" value="${asm.lib} ${instr.jar.name}" />
<attribute name="Main-Class" value="ch.usi.dag.dislreserver.DiSLREServer" />
</manifest>
</jar>
</target>
<target name="compile-dynamicbypass-afterbootstrap">
<mkdir dir="${build.afterbootstrap}" />
<javac srcdir="${src.dynbypass.act}" destdir="${build.afterbootstrap}" debug="true" includeAntRuntime="false">
......@@ -97,7 +114,7 @@
<delete dir="${build.afterbootstrap}" />
</target>
<target name="package" depends="package-dislserver,package-dislagent-java" />
<target name="package" depends="package-dislserver,package-dislagent-java,package-dislreserver" />
<target name="eclipse-agent" description="creates simple agent jar file for eclipse">
<mkdir dir="build" />
......
......@@ -4,13 +4,16 @@ OS=`uname`
if [ "${OS}" = "Darwin" ]; then
C_AGENT="src-agent-c/libdislagent.jnilib"
RE_AGENT="src-re-agent/libdislreagent.jnilib"
else
C_AGENT="src-agent-c/libdislagent.so"
RE_AGENT="src-re-agent/libdislreagent.so"
fi
# ipc.socket is the default communication
# to enable shared memory, remove ",ipc.socket" from the options
java -agentpath:${C_AGENT} \
-agentpath:${RE_AGENT} \
-javaagent:build/dislagent-unspec.jar \
-Xbootclasspath/a:build/dislagent-unspec.jar:build/dislinstr.jar \
-cp bin/ \
......
#!/bin/sh
# available options
# -Ddebug=true \
# -Ddislserver.port="portNum" \
java -Ddebug=true \
$* \
-jar build/dislreserver-unspec.jar \
&
echo $! > re_${SERVER_FILE}
......@@ -8,14 +8,16 @@ then
exit
fi
SERVER_FILE=.server.pid
SERVER_FILE=server.pid
export SERVER_FILE
# kill running server
if [ -e ${SERVER_FILE} ]
then
kill -KILL `cat ${SERVER_FILE}`
rm .server.pid
kill -KILL `cat re_${SERVER_FILE}` 2> /dev/null
rm ${SERVER_FILE}
rm re_${SERVER_FILE}
fi
DISL_CLASS="./bin/ch/usi/dag/disl/test/$1/DiSLClass.class"
......@@ -25,6 +27,7 @@ TARGET_CLASS="ch.usi.dag.disl.test.$1.TargetClass"
# suppress output
ant package-test -Dtest.name=$1 > /dev/null
./runServer.sh
./runREServer.sh
# wait for server startup
sleep 3
......@@ -35,6 +38,8 @@ sleep 3
# wait for server shutdown
sleep 1
# kill server
# kill servers
kill -KILL `cat ${SERVER_FILE}` 2> /dev/null
rm .server.pid
kill -KILL `cat re_${SERVER_FILE}` 2> /dev/null
rm ${SERVER_FILE}
rm re_${SERVER_FILE}
# if there is Makefile.local file then include it
ifneq (, $(wildcard Makefile.local))
include Makefile.local
endif
# Source lists
LIBNAME=dislreagent
SOURCES=dislreagent.c
# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.o)
# Library name and options needed to build it
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
LIBRARY=lib$(LIBNAME).so
endif
ifeq ($(UNAME), Darwin)
LIBRARY=lib$(LIBNAME).jnilib
endif
# Building a shared library
LINK_SHARED=$(LINK.c) -shared -o $@
# GNU Compiler options needed to build it
COMMON_FLAGS=-fPIC
# Options that help find errors
COMMON_FLAGS+= -W -Wall -Wextra -O3 -Wno-unused-parameter
CFLAGS += $(COMMON_FLAGS)
CFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
all: $(LIBRARY)
# Build native library
$(LIBRARY): $(OBJECTS)
$(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
# Cleanup the built bits
clean:
rm -f $(LIBRARY) $(OBJECTS)
# rename this file to Makefile.local to take effect
# if variable is not defined autodetection or default is used
JAVA_HOME = /etc/alternatives/java_sdk/
# rename this file to Makefile.local to take effect
# if variable is not defined autodetection or default is used
#JAVA_HOME = /etc/alternatives/java_sdk/
This diff is collapsed.
#include <jvmti.h>
#ifndef _DISLAGENT_H
#define _DISLAGENT_H
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved);
#ifdef __cplusplus
}
#endif
#endif /* _DISLAGENT_H */
package ch.usi.dag.dislreserver;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import ch.usi.dag.dislreserver.reqdispatch.RequestDispatcher;
public abstract class DiSLREServer {
public static final String PROP_DEBUG = "debug";
private static final boolean debug = Boolean.getBoolean(PROP_DEBUG);
private static final String PROP_PORT = "dislreserver.port";
private static final int DEFAULT_PORT = 11218;
private static final int port = Integer.getInteger(PROP_PORT, DEFAULT_PORT);
public static void main(String args[]) {
try {
if (debug) {
System.out.println("DiSL-RE server is starting on port "
+ port);
}
ServerSocket listenSocket = new ServerSocket(port);
Socket socket = listenSocket.accept();
if (debug) {
System.out.println("Accpeting new connection from "
+ socket.getInetAddress().toString());
}
analysisLoop(socket);
socket.close();
if (debug) {
System.out.println("DiSL-RE server is shutting down");
}
} catch (Exception e) {
reportError(e);
}
}
private static void analysisLoop(Socket sock) throws DiSLREServerException {
try {
final DataInputStream is = new DataInputStream(
new BufferedInputStream(sock.getInputStream()));
final DataOutputStream os = new DataOutputStream(
new BufferedOutputStream(sock.getOutputStream()));
boolean exit = false;
do {
int requestNo = is.readInt();
exit = RequestDispatcher.dispatch(requestNo, is, os, debug);
} while(! exit);
} catch (IOException e) {
throw new DiSLREServerException(e);
}
}
private static void reportError(Throwable e) {
if (e instanceof DiSLREServerException) {
System.err.println("DiSL-RE server error: " + e.getMessage());
if (debug) {
e.printStackTrace();
}
}
// fatal exception (unexpected)
System.err.println("Fatal error: " + e.getMessage());
e.printStackTrace();
}
}
package ch.usi.dag.dislreserver;
public class DiSLREServerException extends Exception {
private static final long serialVersionUID = 5272000884539359236L;
public DiSLREServerException() {
super();
}
public DiSLREServerException(String message, Throwable cause) {
super(message, cause);
}
public DiSLREServerException(String message) {
super(message);
}
public DiSLREServerException(Throwable cause) {
super(cause);
}
}
package ch.usi.dag.dislreserver.msg.close;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
public class CloseHandler implements RequestHandler {
public void handle(DataInputStream is, DataOutputStream os, boolean debug) {
// Nothing to do
}
}
package ch.usi.dag.dislreserver.msg.instr;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import ch.usi.dag.dislreserver.DiSLREServerException;
import ch.usi.dag.dislreserver.msg.instr.InstrMsgReader.InstrClassMessage;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
public abstract class AbstractInstrumentation implements RequestHandler {
// used for replays
private static final byte[] emptyByteArray = new byte[0];
public void handle(DataInputStream is, DataOutputStream os, boolean debug)
throws DiSLREServerException {
try {
InstrClassMessage nm = InstrMsgReader.readMessage(is);
byte[] instrClass;
try {
instrClass = instrument(new String(nm.getControl()),
nm.getClassCode());
}
catch (DiSLREServerException e) {
// instrumentation error
// send the client a description of the server-side error
String errToReport = e.getMessage();
// during debug send the whole message
if(debug) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
errToReport = sw.toString();
}
// error protocol:
// control contains the description of the server-side error
// class code is an array of size zero
String errMsg = "Instrumentation error for class "
+ new String(nm.getControl()) + ": " + errToReport;
InstrMsgReader.sendMessage(os, new InstrClassMessage(errMsg
.getBytes(), emptyByteArray));
throw e;
}
InstrClassMessage replyData = null;
if(instrClass != null) {
// class was modified - send modified data
replyData = new InstrClassMessage(emptyByteArray, instrClass);
}
else {
// zero length means no modification
replyData = new InstrClassMessage(emptyByteArray, emptyByteArray);
}
InstrMsgReader.sendMessage(os, replyData);
}
catch (IOException e) {
throw new DiSLREServerException(e);
}
}
protected abstract byte[] instrument(String string, byte[] classCode)
throws DiSLREServerException;
}
package ch.usi.dag.dislreserver.msg.instr;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class InstrMsgReader {
public static class InstrClassMessage {
private byte[] control;
private byte[] classCode;
public InstrClassMessage(byte[] control, byte[] classCode) {
this.control = control;
this.classCode = classCode;
}
public byte[] getControl() {
return control;
}
public byte[] getClassCode() {
return classCode;
}
}
public static InstrClassMessage readMessage(DataInputStream is) throws IOException {
// protocol:
// java int - control string length (ctl)
// java int - class code length (ccl)
// bytes[ctl] - control string (contains class name)
// bytes[ccl] - class code
int controlLength = is.readInt();
int classCodeLength = is.readInt();
// allocate buffer for class reading
byte[] control = new byte[controlLength];
byte[] classCode = new byte[classCodeLength];
// read class
is.readFully(control);
is.readFully(classCode);
return new InstrClassMessage(control, classCode);
}
public static void sendMessage(DataOutputStream os, InstrClassMessage icm)
throws IOException {
// protocol:
// java int - control string (ctl)
// java int - class code length (ccl)
// bytes[ctl] - control string
// bytes[ccl] - class code
os.writeInt(icm.getControl().length);
os.writeInt(icm.getClassCode().length);
os.write(icm.getControl());
os.write(icm.getClassCode());
os.flush();
}
}
package ch.usi.dag.dislreserver.reqdispatch;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.HashMap;
import java.util.Map;
import ch.usi.dag.dislreserver.DiSLREServerException;
import ch.usi.dag.dislreserver.msg.close.CloseHandler;
public class RequestDispatcher {
private static final Map<Integer, RequestHandler> requestMap;
static {
requestMap = new HashMap<Integer, RequestHandler>();
// Messages - should be in sync with c agent
// close
requestMap.put(0, new CloseHandler());
// TODO analysis eval
}
public static boolean dispatch(int requestNo, DataInputStream is,
DataOutputStream os, boolean debug) throws DiSLREServerException {
// request handler
RequestHandler rh = requestMap.get(requestNo);
// process request
rh.handle(is, os, debug);
// if close handler is there then exit
return rh instanceof CloseHandler;
}
}
package ch.usi.dag.dislreserver.reqdispatch;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import ch.usi.dag.dislreserver.DiSLREServerException;
public interface RequestHandler {
void handle(DataInputStream is, DataOutputStream os, boolean debug)
throws DiSLREServerException;
}
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