Commit 83438b2d authored by Lukáš Marek's avatar Lukáš Marek

Fixed a few bugs in DiSLServer

parent fc2bb03e
......@@ -11,8 +11,11 @@ public class Bootstrap {
public static void completed(Instrumentation instr) {
try {
// get class loader
ClassLoader cl = Bootstrap.class.getClassLoader();
// get system class loader
// this class is loaded by bootstrap classloader which does not help
// system classloader should be able to locate the class because of
// disl agent is there
ClassLoader cl = ClassLoader.getSystemClassLoader();
// find our class in resources
InputStream dbcIS = cl.getResourceAsStream(
......
......@@ -21,7 +21,6 @@ import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.cbloader.ClassByteLoader;
import ch.usi.dag.disl.classparser.ClassParser;
import ch.usi.dag.disl.exception.DiSLException;
import ch.usi.dag.disl.exception.DiSLFatalException;
import ch.usi.dag.disl.exception.DiSLIOException;
import ch.usi.dag.disl.exception.DynamicInfoException;
import ch.usi.dag.disl.exception.InitException;
......@@ -272,10 +271,6 @@ public class DiSL {
// report DiSL exception within our code
try {
if (snippets == null) {
throw new DiSLFatalException("DiSL was not initialized");
}
boolean classChanged = false;
// instrument all methods in a class
......@@ -321,7 +316,7 @@ public class DiSL {
}
}
if(! classChanged) {
if(classChanged) {
return classNode;
}
......
package ch.usi.dag.dislserver;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.atomic.AtomicInteger;
import ch.usi.dag.disl.DiSL;
......@@ -34,15 +35,17 @@ public abstract class DiSLServer {
while (true) {
NetClassReader sc =
new NetClassReader(listenSocket.accept());
Socket newClient = listenSocket.accept();
NetClassReader sc = new NetClassReader(newClient);
aliveWorkers.incrementAndGet();
new Worker(sc, disl).start();
if (debug) {
System.out.println("New connection accepted...");
System.out.println("Accpeting new connection from "
+ newClient.getInetAddress().toString());
}
}
......
......@@ -73,20 +73,23 @@ public class Worker extends Thread {
for(String pattern : exclusionList) {
if(WildCard.match(className, pattern)) {
return false;
}
}
if (debug) {
System.out.println("Excluding class: " + className);
}
// excluding class...
if (debug) {
System.out.println("Excluding class: " + className);
}
if (className.equals(Type.getInternalName(Thread.class))) {
throw new DiSLServerException(Thread.class.getName()
+ " cannot be excluded in exclusion list");
if (className.equals(Type.getInternalName(Thread.class))) {
throw new DiSLServerException(Thread.class.getName()
+ " cannot be excluded in exclusion list");
}
return true;
}
}
return true;
return false;
}
private Set<String> readExlusionList() throws DiSLServerException {
......@@ -125,7 +128,7 @@ public class Worker extends Thread {
Constants.PACKAGE_STD_DELIM, Constants.PACKAGE_INTERN_DELIM);
}
private void instrumentationLoop() throws DiSLServerException, DiSLException {
private void instrumentationLoop() throws Exception {
try {
......@@ -147,19 +150,25 @@ public class Worker extends Thread {
instrClass = instrument(new String(cab.getName()),
cab.getCode());
}
catch (DiSLException e) {
catch (Exception e) {
// instrumentation error
// send the client a description of the server-side error
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
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:
// class name contains the description of the server-side error
// class code is an array of size zero
String errMsg = "Error in class " + cab.getName() + ": "
+ sw.toString();
String errMsg = "Instrumentation error for class "
+ new String(cab.getName()) + ": " + errToReport;
sc.sendClassAsBytes(new ClassAsBytes(errMsg.getBytes(),
new byte[0]));
......@@ -167,7 +176,15 @@ public class Worker extends Thread {
throw e;
}
sc.sendClassAsBytes(new ClassAsBytes(cab.getName(), instrClass));
// default answer - no modification
ClassAsBytes replyData = cab;
// class was modified - send modified data
if(instrClass != null) {
replyData = new ClassAsBytes(cab.getName(), instrClass);
}
sc.sendClassAsBytes(replyData);
}
}
......
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