Skip to content

Commit

Permalink
further improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarv committed Jan 29, 2018
1 parent a1cdd69 commit a918aec
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 38 deletions.
3 changes: 2 additions & 1 deletion examples/falo.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ groupBy: ENTRY

# store dot files and coverage matrix
# writeTo: DOT
writeTo: DOT,TRACE,COVERAGE,DD_DOT,LINES,COMBINED_DOT
# writeTo: DOT,TRACE,COVERAGE,DD_DOT,LINES,COMBINED_DOT
writeTo: DOT,TRACE,COVERAGE,DD_DOT,COMBINED_DOT
# writeTo: DOT,TRACE,COVERAGE,LINES
# writeTo: DOT,DD_DOT,LINES

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class FastFieldAccessRecorder {
private static final boolean needCombined;
private static final int SIZE = 10;
private static final int[] HASH_CACHE = new int[SIZE];
private static final String[] CACHE = new String[SIZE];
private static final String[] FIELD_CACHE = new String[SIZE];
private static final String[] METHOD_CACHE = new String[SIZE];
private static int POS = SIZE - 1;

static {
Expand All @@ -66,32 +67,28 @@ public class FastFieldAccessRecorder {
}
}

public static void write(String fromClass, String fromMethod, int lineNumber, String fieldClass,
String fieldName) {
int hash = 31 * fieldClass.hashCode() + fieldName.hashCode();
public static void write(String method, String field) {
int hash = field.hashCode();
for (int i = 0; i < SIZE; i++) {
if (HASH_CACHE[i] == hash) {
HASH_CACHE[i] = -1;
CACHE[i] = null;
FIELD_CACHE[i] = null;
METHOD_CACHE[i] = null;
}
}

try {
StackItem item = StackItemCache.get(fromClass, fromMethod, lineNumber, false);
GRAPH.addWrite(item, fieldClass + "::" + fieldName);
GRAPH.addWrite(method, field);
} catch (Exception e) {
LOG.error("Error in write", e);
}
}

public static void read(String fromClass, String fromMethod, int lineNumber, String fieldClass,
String fieldName) {
int hash = 31 * fieldClass.hashCode() + fieldName.hashCode();
public static void read(String method, String field) {
int hash = field.hashCode();
for (int j = 0, i = POS; j < SIZE; j++, i = (i + 1) % SIZE) {
if (HASH_CACHE[i] == hash) {
String s =
fromClass + "%" + fromMethod + "%" + lineNumber + "%" + fieldClass + "%" + fieldName;
if (s.equals(CACHE[i])) {
if (method.equals(METHOD_CACHE[i]) && field.equals(FIELD_CACHE[i])) {
// we already saw this read recently
return;
}
Expand All @@ -101,8 +98,8 @@ public static void read(String fromClass, String fromMethod, int lineNumber, Str
// store in cache
POS = (POS - 1 + SIZE) % SIZE;
HASH_CACHE[POS] = hash;
CACHE[POS] =
fromClass + "%" + fromMethod + "%" + lineNumber + "%" + fieldClass + "%" + fieldName;
METHOD_CACHE[POS] = method;
FIELD_CACHE[POS] = field;

try {
// Does not work with multithreading, we have to migrate it too
Expand All @@ -112,8 +109,7 @@ public static void read(String fromClass, String fromMethod, int lineNumber, Str
//} else {
// callGraph = null;
//}
StackItem item = StackItemCache.get(fromClass, fromMethod, lineNumber, false);
GRAPH.addRead(item, fieldClass + "::" + fieldName, null);
GRAPH.addRead(method, field, null);
} catch (Exception e) {
LOG.error("Error in read", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,25 @@ public class FieldAccessRecorder {
}
}

public static void write(String fromClass, String fromMethod, int lineNumber, String fieldClass,
String fieldName) {
public static void write(String method, String field) {
try {
LOG.trace("Write to {}::{} from {}::{}", fieldClass, fieldName, fromClass, fromMethod);
StackItem item = StackItemCache.get(fromClass, fromMethod, lineNumber, false);
GRAPH.addWrite(item, fieldClass + "::" + fieldName);
LOG.trace("Write to {} from {}", field, method);
GRAPH.addWrite(method, field);
} catch (Exception e) {
LOG.error("Error in write", e);
}
}

public static void read(String fromClass, String fromMethod, int lineNumber, String fieldClass,
String fieldName) {
public static void read(String method, String field) {
try {
LOG.trace("Read to {}::{} from {}::{}", fieldClass, fieldName, fromClass, fromMethod);
LOG.trace("Read to {} from {}", field, method);
//CallGraph callGraph;
//if (needCombined) {
// callGraph = CallTask.GRAPHS.get(Thread.currentThread().getId());
//} else {
// callGraph = null;
//}
StackItem item = StackItemCache.get(fromClass, fromMethod, lineNumber, false);
GRAPH.addRead(item, fieldClass + "::" + fieldName, null);
GRAPH.addRead(method, field, null);
} catch (Exception e) {
LOG.error("Error in read", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.dkarv.jdcallgraph.util.config.Config;
import com.dkarv.jdcallgraph.util.log.Logger;
import com.dkarv.jdcallgraph.util.options.Formatter;
import javassist.CannotCompileException;
import javassist.CtBehavior;
import javassist.NotFoundException;
Expand Down Expand Up @@ -98,12 +99,12 @@ public final void edit(FieldAccess f) throws CannotCompileException {
} catch (NotFoundException e) {
methodName = "<error>";
}
String from = "\"" + className + "\",\"" + methodName + "\"," + lineNumber;
String from = '"' + Formatter.format(className, methodName, lineNumber) + "\",";

boolean isWrite = f.isWriter();
boolean isStatic = f.isStatic();
if (isStatic) {
String field = ",\"" + f.getClassName() + "\",\"" + f.getFieldName() + "\"";
String field = "\"" + f.getClassName() + "::" + f.getFieldName() + "\"";
if (isWrite) {
f.replace("{ $proceed($$); " +
TARGET + ".write(" + from + field + "); }");
Expand All @@ -112,9 +113,9 @@ public final void edit(FieldAccess f) throws CannotCompileException {
TARGET + ".read(" + from + field + "); }");
}
} else {
String field = ",\"" + f.getClassName() + "@\"" +
String field = '"' + f.getClassName() + "@\"" +
"+ java.lang.Integer.toHexString(java.lang.System.identityHashCode($0))" +
",\"" + f.getFieldName() + "\"";
"+ \"::" + f.getFieldName() + "\"";
if (isWrite) {
if (IGNORE_THIS.matcher(f.getFieldName()).find()) {
LOG.debug("Ignore write to this in {} from {}", f.getClassName(), from);
Expand Down
6 changes: 3 additions & 3 deletions jdcallgraph/src/main/java/com/dkarv/jdcallgraph/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ void enhanceMethod(CtBehavior method, String className)
LOG.debug("subtest detection enabled on {}::{}", className, mName);
srcBefore.append(Formatter.class.getCanonicalName()).append(".formatTest(")
.append("getClass().getCanonicalName(),\"").append(mName).append("\",").append(lineNumber)
.append(",true);");
srcAfter.append(Formatter.class.getCanonicalName()).append(".format(")
.append("),true);");
srcAfter.append(Formatter.class.getCanonicalName()).append(".formatTest(")
.append("getClass().getCanonicalName(),\"").append(mName).append("\",").append(lineNumber)
.append(",true);");
.append("),true);");
} else {
srcBefore.append('"').append(Formatter.format(className, mName, lineNumber))
.append("\",false);");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ static GraphWriter createWriter(Target t, boolean multiGraph) {
return new CsvCoverageFileWriter();
case TRACE:
return new CsvTraceFileWriter();
case LINES:
return new LineNumberFileWriter();
//case LINES:
// return new LineNumberFileWriter();
default:
throw new IllegalArgumentException("Unknown writeTo: " + t);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public void called(String method) throws IOException {
calls.push(method);
for (GraphWriter w : writers) {
w.start(identifier);
w.node(method);
w.node(method, false);
}
} else {
LOG.info("Skip first node {} because start condition not fulfilled", method);
Expand Down

0 comments on commit a918aec

Please sign in to comment.