Commit c8df0858 authored by Lukáš Marek's avatar Lukáš Marek

Exclusion list moved from DiSLServer to DiSL

Exclusion list has method granularity
parent b703ccfa
......@@ -2,11 +2,13 @@
# available options
# -Ddebug=true \
# -Ddisl.classes="list of disl classes (: - separator)"
# -Ddisl.noexcepthandler=true \
# -Ddisl.exclusionList="path" \
# -Ddislserver.instrumented="path" \
# -Ddislserver.uninstrumented="path" \
# -Ddislserver.port="portNum" \
# -Ddislserver.exclusionList="path"
java -Ddislserver.port="1234" \
$* \
......
......@@ -27,6 +27,7 @@ import ch.usi.dag.disl.exception.InitException;
import ch.usi.dag.disl.exception.ProcessorException;
import ch.usi.dag.disl.exception.ReflectionException;
import ch.usi.dag.disl.exception.StaticContextGenException;
import ch.usi.dag.disl.exclusion.ExclusionSet;
import ch.usi.dag.disl.guard.GuardHelper;
import ch.usi.dag.disl.localvar.SyntheticLocalVar;
import ch.usi.dag.disl.localvar.ThreadLocalVar;
......@@ -35,9 +36,11 @@ import ch.usi.dag.disl.processor.generator.PIResolver;
import ch.usi.dag.disl.processor.generator.ProcGenerator;
import ch.usi.dag.disl.processor.generator.ProcInstance;
import ch.usi.dag.disl.processor.generator.ProcMethodInstance;
import ch.usi.dag.disl.scope.Scope;
import ch.usi.dag.disl.snippet.Shadow;
import ch.usi.dag.disl.snippet.Snippet;
import ch.usi.dag.disl.staticcontext.generator.SCGenerator;
import ch.usi.dag.disl.util.Constants;
import ch.usi.dag.disl.utilinstr.codemerger.CodeMerger;
import ch.usi.dag.disl.utilinstr.tlvinserter.TLVInserter;
import ch.usi.dag.disl.weaver.Weaver;
......@@ -55,7 +58,9 @@ public class DiSL {
private final boolean useDynamicBypass;
List<Snippet> snippets;
private final Set<Scope> exclusionSet;
private final List<Snippet> snippets;
// this method should be called only once
public DiSL(boolean useDynamicBypass) throws Exception {
......@@ -74,6 +79,9 @@ public class DiSL {
+ " and proper manifest");
}
// prepare exclusion set
exclusionSet = ExclusionSet.prepare();
// *** parse disl classes ***
// - create snippets
// - create static context methods
......@@ -161,12 +169,23 @@ public class DiSL {
return false;
}
// TODO jb ! document
// skip finalize method in java.lang.Object
final String METHOD_FINALIZE = "finalize";
if (methodNode.name.equals(METHOD_FINALIZE) &&
classNode.name.equals(Type.getInternalName(Object.class))) {
return false;
String className = classNode.name;
String methodName = methodNode.name;
String methodDesc = methodNode.desc;
// evaluate exclusions
for (Scope exclScope : exclusionSet) {
if (exclScope.matches(className, methodName, methodDesc)) {
if (debug) {
System.out.println("Excluding method: " + className
+ Constants.CLASS_DELIM + methodName + "("
+ methodDesc + ")");
}
return false;
}
}
// *** match snippet scope ***
......@@ -176,7 +195,7 @@ public class DiSL {
for (Snippet snippet : snippets) {
// snippet matching
if (snippet.getScope().matches(classNode.name, methodNode.name, methodNode.desc)) {
if (snippet.getScope().matches(className, methodName, methodDesc)) {
matchedSnippets.add(snippet);
}
}
......@@ -245,8 +264,9 @@ public class DiSL {
piResolver);
if(debug) {
System.out.println("--- instumentation of " + classNode.name + "."
+ methodNode.name);
System.out.println("Instumenting method: " + className
+ Constants.CLASS_DELIM + methodName + "(" + methodDesc
+ ")");
}
return true;
......
package ch.usi.dag.disl.exclusion;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import ch.usi.dag.disl.exception.DiSLIOException;
import ch.usi.dag.disl.exception.ScopeParserException;
import ch.usi.dag.disl.scope.Scope;
import ch.usi.dag.disl.scope.ScopeImpl;
public abstract class ExclusionSet {
private static final String PROP_EXCLIST = "disl.exclusionList";
private static final String excListPath =
System.getProperty(PROP_EXCLIST, null);
public static Set<Scope> prepare() throws DiSLIOException,
ScopeParserException {
Set<Scope> exclSet = defaultExcludes();
exclSet.addAll(instrumentationJar());
exclSet.addAll(readExlusionList());
return exclSet;
}
private static Set<Scope> defaultExcludes() throws ScopeParserException {
Set<Scope> exclSet = new HashSet<Scope>();
// DiSL agent classes
exclSet.add(new ScopeImpl("ch.usi.dag.dislagent.*.*"));
// dynamic bypass classes
exclSet.add(new ScopeImpl("ch.usi.dag.disl.dynamicbypass.*.*"));
// java instrument classes could cause troubles if instrumented
exclSet.add(new ScopeImpl("sun.instrument.*.*"));
// TODO jb - rally has to be excluded ?
// finalize method in java.lang.Object can cause problems
exclSet.add(new ScopeImpl("java.lang.Object.finalize"));
return exclSet;
}
private static Set<Scope> instrumentationJar() {
Set<Scope> exclSet = new HashSet<Scope>();
// TODO jb ! add classes from instrumentation jar
return exclSet;
}
private static Set<Scope> readExlusionList() throws DiSLIOException,
ScopeParserException {
final String COMMENT_START = "#";
try {
Set<Scope> exclSet = new HashSet<Scope>();
// 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(new ScopeImpl(line));
}
}
scanner.close();
}
return exclSet;
} catch(FileNotFoundException e) {
throw new DiSLIOException(e);
}
}
}
package ch.usi.dag.dislserver;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import org.objectweb.asm.Type;
import ch.usi.dag.disl.DiSL;
import ch.usi.dag.disl.exception.DiSLException;
import ch.usi.dag.disl.scope.WildCard;
import ch.usi.dag.disl.util.Constants;
public class Worker extends Thread {
......@@ -23,10 +16,6 @@ public class Worker extends Thread {
private static final boolean debug = Boolean
.getBoolean(DiSLServer.PROP_DEBUG);
private static final String PROP_EXCLIST = "dislserver.exclusionList";
private static final String excListPath =
System.getProperty(PROP_EXCLIST, null);
private static final String PROP_UNINSTR = "dislserver.uninstrumented";
private static final String uninstrPath =
System.getProperty(PROP_UNINSTR, null);
......@@ -35,8 +24,6 @@ public class Worker extends Thread {
private static final String instrPath =
System.getProperty(PROP_INSTR, null);
private static Set<String> exclusionList;
private final NetClassReader sc;
private final DiSL disl;
......@@ -61,92 +48,6 @@ public class Worker extends Thread {
}
}
private boolean filterClass(String className) throws DiSLServerException {
// race condition can be here (invocation from multiple threads)
// but this is not serious problem
if(exclusionList == null) {
exclusionList = readExlusionList();
}
// check the exclusion list for possible matches
for(String pattern : exclusionList) {
if(WildCard.match(className, pattern)) {
// 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");
}
return true;
}
}
return false;
}
private Set<String> readExlusionList() throws DiSLServerException {
final String COMMENT_START = "#";
try {
Set<String> exclSet = new HashSet<String>();
// 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();
}
// add classes that are excluded by default
addDefaultExcludes(exclSet);
return exclSet;
} catch(FileNotFoundException e) {
throw new DiSLServerException(e);
}
}
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(
Constants.PACKAGE_STD_DELIM, Constants.PACKAGE_INTERN_DELIM);
}
private void instrumentationLoop() throws Exception {
try {
......@@ -220,16 +121,6 @@ public class Worker extends Thread {
dump(className, origCode, uninstrPath);
}
// filter
if (filterClass(className)) {
if (debug) {
System.out.println("Excluding " + className);
}
return origCode;
}
// instrument
byte[] instrCode = disl.instrument(origCode);
......
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