diff --git a/pom.xml b/pom.xml
index 357f6ef..ee1243b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,42 +79,65 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.5.0
+
+
+ blinky-config-runner
+
+ java
+
+
+
+ compile
+
+
+
+
+
+ org.spideruci.analysis.config.Main
+
+
+ false
+ true
+
+ org.spideruci.analysis.config
+ blinky-config
+
+
+
+
+
+ config.filepath
+ ${basedir}/resources/config.yaml
+
+
+ config.classname
+ org.spideruci.analysis.statik.instrumentation.Config
+
+
+ config.compiledoutput
+ ${basedir}/target/classes
+
+
+ config.profilerclassname
+ org.spideruci.analysis.dynamic.api.EmptyProfiler
+
+
+
+
+
+
+
+
+ org.spideruci.analysis.config
+ blinky-config
+ 0.0.1-SNAPSHOT
+
+
+
@@ -146,51 +169,6 @@
-
- config
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.5.0
-
-
- blinky-config-runner
- compile
-
- java
-
-
-
-
- org.spideruci.analysis.config.Main
-
-
- ${basedir}/../blinky-config/target/blinky-config-0.0.1-SNAPSHOT-jar-with-dependencies.jar
-
-
-
-
- config.filepath
- ${basedir}/resources/config.yaml
-
-
- config.classname
- org.spideruci.analysis.statik.instrumentation.Config
-
-
- config.compiledoutput
- ${basedir}/target/classes
-
-
-
-
-
-
-
-
-
offline
diff --git a/resources/config.yaml b/resources/config.yaml
index 934dece..47d5096 100644
--- a/resources/config.yaml
+++ b/resources/config.yaml
@@ -80,8 +80,6 @@ retransformInclusionList:
# - org/w3c
# - org/xml
-profiler: 'org/spideruci/analysis/dynamic/profilers/CoverageTracker'
-
## FUTURE EXAMPLES (NOT YET TESTED; DO NOT UNCOMMENT):
# name: blinky
# number: !!int 1
diff --git a/run.sh b/run.sh
new file mode 100644
index 0000000..59eeee4
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+pwd
+
+##
+$MAIN_ARGS=
+$TRACES_LOC=
+$INPUT_ID=
+$SUBJECT=
+$BLINKY=
+$ENTRY=
+
+echo "[ENV VARIABLES]"
+echo "MAIN_ARGS: "$MAIN_ARGS
+echo "TRACES_LOC: "$TRACES_LOC
+echo "INPUT_ID: "$INPUT_ID
+echo "SUBJECT: "$SUBJECT
+echo "BLINKY: "$BLINKY
+
+JAVA="/Users/vpalepu/open-source/java/jre1.7.0_60.jre/Contents/Home/bin/java -d64 -Xmx6g"
+
+BLINKYHOME="/Users/vpalepu/phd-open-source/blinky-core"
+BLINKYJAR="$BLINKYHOME/blinky-core/target/blinky-core-0.0.1-SNAPSHOT-jar-with-dependencies.jar"
+
+CONFIG_YAML="$BLINKYHOME/$INPUT_ID-methods.yaml"
+
+
+
+BLINKY="-Xbootclasspath/p:$BLINKYJAR -javaagent:$BLINKYJAR=0,retransform,whitelist,purewhitelist,$ENTRY"
+
+# prepare blinky jar file
+cd $BLINKYHOME
+mvn package -DskipTests -Dconfig.override=$CONFIG_YAML -q
+cd -
+
+$JAVA $BLINKY $SUBJECT $MAIN_ARGS > $TRACES_LOC/$INPUT_ID-full.trc 2> $TRACES_LOC/$INPUT_ID-full.err
\ No newline at end of file
diff --git a/src/org/spideruci/analysis/dynamic/Blinksformer.java b/src/org/spideruci/analysis/dynamic/Blinksformer.java
index c893b96..0538dbb 100755
--- a/src/org/spideruci/analysis/dynamic/Blinksformer.java
+++ b/src/org/spideruci/analysis/dynamic/Blinksformer.java
@@ -75,7 +75,7 @@ static byte[] instrumentClass(String className, byte[] classBytes,
ErrorLogManager.logClassTxStatus(className, isRuntime, FAILD);
instrumentedBytes = classBytes;
}
- TraceLogger.printTraceCount(startTime, className);
+
return instrumentedBytes;
}
diff --git a/src/org/spideruci/analysis/dynamic/Profiler.java b/src/org/spideruci/analysis/dynamic/Profiler.java
index 06898cc..f6c90c9 100755
--- a/src/org/spideruci/analysis/dynamic/Profiler.java
+++ b/src/org/spideruci/analysis/dynamic/Profiler.java
@@ -39,7 +39,7 @@ public class Profiler {
public static boolean logInvokeRuntimeSign = false;
public static boolean logEnterRuntimeSign = false;
- public static boolean log = true;
+ public static boolean log = false;
public static PrintStream REAL_OUT = System.out;
public static PrintStream REAL_ERR = System.err;
@@ -67,7 +67,8 @@ synchronized static public void setLogFlags(final boolean value) {
logSwitch =
// logInvokeRuntimeSign =
logEnterRuntimeSign =
- log = value;
+// log =
+ value;
}
synchronized static public void initProfiler(String args) {
@@ -504,7 +505,12 @@ synchronized static public void unsetGuard1() {
synchronized static public void setGuard1() {
$guard1$ = true;
- TraceLogger.printTraceCount();
+
+ if(TraceLogger.profiler == null) {
+ TraceLogger.printTraceCount();
+ return;
+ }
+
TraceLogger.profiler.endProfiling();
}
diff --git a/src/org/spideruci/analysis/dynamic/TraceLogger.java b/src/org/spideruci/analysis/dynamic/TraceLogger.java
index 6b59cb8..2af8628 100644
--- a/src/org/spideruci/analysis/dynamic/TraceLogger.java
+++ b/src/org/spideruci/analysis/dynamic/TraceLogger.java
@@ -2,9 +2,7 @@
import static org.spideruci.analysis.dynamic.Profiler.REAL_OUT;
-import org.spideruci.analysis.dynamic.api.EmptyProfiler;
import org.spideruci.analysis.dynamic.api.IProfiler;
-import org.spideruci.analysis.dynamic.profilers.TimeAndCountTracker;
import org.spideruci.analysis.statik.instrumentation.Config;
import org.spideruci.analysis.trace.EventBuilder;
import org.spideruci.analysis.trace.EventType;
@@ -100,8 +98,13 @@ synchronized static public void handleEnterLog(String insnId, String tag, EventT
final String runtimeSignature = RuntimeTypeProfiler.getEnterRuntimeSignature(null);
TraceEvent event = EventBuilder.buildEnterExecEvent(++count, tag, insnId,
insnType, vitalState, runtimeSignature);
+
+ if(profiler == null) {
+ printEventlog(event);
+ return;
+ }
+
profiler.profileMethodEntry(event);
- printEventlog(event);
}
synchronized static public void handleInvokeLog(String insnId, String tag, EventType insnType) {
@@ -111,8 +114,13 @@ synchronized static public void handleInvokeLog(String insnId, String tag, Event
RuntimeTypeProfiler.getInvokeRuntimeSignature();
TraceEvent event = EventBuilder.buildInvokeInsnExecEvent(++count, tag,
insnId, insnType, vitalState, runtimeSignature);
+
+ if(profiler == null) {
+ printEventlog(event);
+ return;
+ }
+
profiler.profileMethodInvoke(event);
- printEventlog(event);
}
synchronized static public void handleLog(String insnId, String tag, EventType insnType) {
@@ -120,14 +128,17 @@ synchronized static public void handleLog(String insnId, String tag, EventType i
TraceEvent event = EventBuilder.buildInsnExecEvent(++count, tag, insnId,
insnType, vitalState);
+
+ if(profiler == null) {
+ printEventlog(event);
+ return;
+ }
if (insnType == EventType.$exit$) {
profiler.profileMethodExit(event);
} else {
profiler.profileInsn(event);
}
-
- printEventlog(event);
}
synchronized static public void handleArrayLog(String insnId, String tag, EventType insnType, int arrayrefId, int index, String elementId, int length) {
@@ -135,8 +146,13 @@ synchronized static public void handleArrayLog(String insnId, String tag, EventT
TraceEvent event = EventBuilder.buildArrayInsnExecEvent(++count, tag,
insnId, insnType, vitalState, arrayrefId, index, elementId, length);
+
+ if(profiler == null) {
+ printEventlog(event);
+ return;
+ }
+
profiler.profileArrayInsn(event);
- printEventlog(event);
}
synchronized static public void handleVarLog(String insnId, String tag, String varId) {
@@ -144,8 +160,13 @@ synchronized static public void handleVarLog(String insnId, String tag, String v
TraceEvent event = EventBuilder.buildVarInsnExecEvent(++count, tag,
insnId, EventType.$var$, vitalState, varId);
+
+ if(profiler == null) {
+ printEventlog(event);
+ return;
+ }
+
profiler.profileVarInsn(event);
- printEventlog(event);
}
synchronized static public void handleFieldLog(String insnId, String tag, String fieldId, String fieldOwnerId) {
@@ -153,8 +174,13 @@ synchronized static public void handleFieldLog(String insnId, String tag, String
TraceEvent event = EventBuilder.buildFieldInsnExecEvent(++count, tag,
insnId, EventType.$field$, vitalState, fieldId, fieldOwnerId);
+
+ if(profiler == null) {
+ printEventlog(event);
+ return;
+ }
+
profiler.profileFieldInsn(event);
- printEventlog(event);
}
synchronized static public void handleArgLog(String argType, String index, EventType type, boolean isFirst, boolean isLast) {
diff --git a/src/org/spideruci/analysis/dynamic/api/EmptyProfiler.java b/src/org/spideruci/analysis/dynamic/api/EmptyProfiler.java
index e2d0fef..0c4ac66 100644
--- a/src/org/spideruci/analysis/dynamic/api/EmptyProfiler.java
+++ b/src/org/spideruci/analysis/dynamic/api/EmptyProfiler.java
@@ -12,6 +12,11 @@
*/
public class EmptyProfiler implements IProfiler {
+ @Override
+ public String description() {
+ return "EmptyProfiler";
+ }
+
@Override
public void willProfile() {
// Convenience stub. Subclasses should appropriate implementation.
diff --git a/src/org/spideruci/analysis/dynamic/api/IProfiler.java b/src/org/spideruci/analysis/dynamic/api/IProfiler.java
index c8acfe1..28362e2 100644
--- a/src/org/spideruci/analysis/dynamic/api/IProfiler.java
+++ b/src/org/spideruci/analysis/dynamic/api/IProfiler.java
@@ -3,6 +3,8 @@
import org.spideruci.analysis.trace.TraceEvent;
public interface IProfiler {
+
+ public String description();
public void startProfiling();
public void endProfiling();
diff --git a/src/org/spideruci/analysis/dynamic/profilers/CoverageTracker.java b/src/org/spideruci/analysis/dynamic/profilers/CoverageTracker.java
deleted file mode 100644
index 439b186..0000000
--- a/src/org/spideruci/analysis/dynamic/profilers/CoverageTracker.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.spideruci.analysis.dynamic.profilers;
-
-import static org.spideruci.analysis.dynamic.Profiler.REAL_OUT;
-
-import java.util.HashMap;
-
-import org.spideruci.analysis.dynamic.api.EmptyProfiler;
-import org.spideruci.analysis.dynamic.api.IProfiler;
-import org.spideruci.analysis.trace.EventType;
-import org.spideruci.analysis.trace.TraceEvent;
-
-public class CoverageTracker extends EmptyProfiler implements IProfiler {
-
- HashMap coverageMap;
- HashMap parentMap = new HashMap<>();
-
- @Override
- public void startProfiling() {
- coverageMap = new HashMap<>();
- }
-
- @Override
- public void willInstrumentClass(final String className) {
- REAL_OUT.println("Starting coverage tracker");
- }
-
- @Override
- public void willInstrumentMethod(final TraceEvent e) {
- if (e.getType() != EventType.$$method$$) {
- return;
- }
-
- String methodName = e.getDeclName();
- String className = e.getDeclOwner();
- long id = e.getId();
-
- parentMap.put(id, className + "." + methodName);
- }
-
- @Override
- public void profileInsn(final TraceEvent e) {
- if (e.getExecInsnType() != EventType.$line$) {
- return;
- }
-
- int lineNumber = e.getInsnLine();
- int lineParent = e.getInsnDeclHostId(); // the host method of the line
-
- String lineParentName = parentMap.containsKey(lineParent)
- ? parentMap.get(lineParent)
- : lineParent + " " + lineNumber;
-
- if (coverageMap.containsKey(lineParentName)) {
- int count = coverageMap.get(lineParentName);
- coverageMap.put(lineParentName, count + 1);
- } else {
- coverageMap.put(lineParentName, 1);
- }
- }
-
- @Override
- public void endProfiling() {
- for (String line : this.coverageMap.keySet()) {
- if (line == null || line.isEmpty()) {
- continue;
- }
-
- int counter = coverageMap.get(line);
- REAL_OUT.println("LINE: " + line + ":: Coverage Counter:" + counter);
- }
- }
-}
diff --git a/src/org/spideruci/analysis/dynamic/profilers/TimeAndCountTracker.java b/src/org/spideruci/analysis/dynamic/profilers/TimeAndCountTracker.java
deleted file mode 100644
index c94cf94..0000000
--- a/src/org/spideruci/analysis/dynamic/profilers/TimeAndCountTracker.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package org.spideruci.analysis.dynamic.profilers;
-
-import static org.spideruci.analysis.dynamic.Profiler.REAL_OUT;
-
-import org.spideruci.analysis.dynamic.api.EmptyProfiler;
-import org.spideruci.analysis.trace.EventType;
-import org.spideruci.analysis.trace.TraceEvent;
-
-public class TimeAndCountTracker extends EmptyProfiler {
- public static final int K = 22;
- public static final EventType[] eventTypes = EventType.values();
- public static final int insnStartType = EventType.$enter$.ordinal();
-
- public static long probeTime = 0;
-
- private static long counter = 0L;
- private static long[] timers = new long[K];
- private static long[] counters = new long[K];
-
- private void tick(EventType type, long time) {
- int idx = type.ordinal() - insnStartType;
- long counter = counters[idx];
- counters[idx] = counter + 1;
- TimeAndCountTracker.counter += 1;
-
- long timer = timers[idx];
- timers[idx] = timer + time;
- }
-
- private void tick(final TraceEvent e) {
- EventType type = e.getExecInsnType();
- long time = System.currentTimeMillis() - probeTime;
- tick(type, time);
- }
-
- @Override
- public void startProfiling() {
- for (int i = 0; i < K; i += 1) {
- timers[i] = 0L;
- counters[i] = 0L;
- }
- }
-
- @Override
- public void endProfiling() {
- REAL_OUT.println("Total Event Count:" + counter);
- for (int i = 0; i < K; i += 1) {
- EventType eventType = eventTypes[i + insnStartType];
- final String eventTypeName = eventType.toString();
- REAL_OUT.println(eventTypeName + ":: Event Count:" + counters[i] + "; Event Time:" + timers[i]);
- }
- }
-
- @Override
- public void willProfile() {
- probeTime = System.currentTimeMillis();
- }
-
- @Override
- public void profileMethodEntry(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileMethodArgument(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileMethodInvoke(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileInsn(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileFieldInsn(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileVarInsn(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileArrayInsn(final TraceEvent e) {
- tick(e);
- }
-
- @Override
- public void profileMethodExit(final TraceEvent e) {
- tick(e);
- }
-
-}
diff --git a/src/org/spideruci/analysis/statik/instrumentation/BytecodeClassAdapter.java b/src/org/spideruci/analysis/statik/instrumentation/BytecodeClassAdapter.java
index ef5cc5b..489d3be 100755
--- a/src/org/spideruci/analysis/statik/instrumentation/BytecodeClassAdapter.java
+++ b/src/org/spideruci/analysis/statik/instrumentation/BytecodeClassAdapter.java
@@ -8,6 +8,7 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.spideruci.analysis.dynamic.Profiler;
+import org.spideruci.analysis.dynamic.TraceLogger;
import org.spideruci.analysis.trace.EventBuilder;
import org.spideruci.analysis.trace.MethodDecl;
import org.spideruci.analysis.trace.TraceEvent;
@@ -37,8 +38,7 @@ public MethodVisitor visitMethod(int access, String name, String desc,
mv = cv.visitMethod(access, name, desc, signature, exceptions);
- if (mv != null
- && ((access & Opcodes.ACC_NATIVE) == 0)) {
+ if (mv != null && ((access & Opcodes.ACC_NATIVE) == 0)) {
final String methodName = name + desc;
@@ -48,11 +48,11 @@ public MethodVisitor visitMethod(int access, String name, String desc,
access, methodName);
mv = new BytecodeMethodAdapter(methodDecl, access, name, desc, mv);
+
if (log) {
synchronized (REAL_OUT) {
REAL_OUT.println(methodDecl.getLog());
}
-
}
}
return mv;
diff --git a/src/org/spideruci/analysis/statik/instrumentation/ClassInstrumenter.java b/src/org/spideruci/analysis/statik/instrumentation/ClassInstrumenter.java
index 94aad63..294d974 100755
--- a/src/org/spideruci/analysis/statik/instrumentation/ClassInstrumenter.java
+++ b/src/org/spideruci/analysis/statik/instrumentation/ClassInstrumenter.java
@@ -13,6 +13,7 @@
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.util.CheckClassAdapter;
import org.spideruci.analysis.dynamic.Profiler;
+import org.spideruci.analysis.dynamic.TraceLogger;
public class ClassInstrumenter {
@@ -43,12 +44,15 @@ public byte[] instrument(String className, byte[] bytecode, File classFile) {
e.printStackTrace();
throw e;
}
+
+ if (TraceLogger.profiler != null) {
+ TraceLogger.profiler.willInstrumentClass(className);
+ }
return bytecode2;
}
- protected byte[] writeProbes(String className, byte[] bytecode,
- boolean isControlAdapter) {
+ protected byte[] writeProbes(String className, byte[] bytecode, boolean isControlAdapter) {
byte[] bytecode2 = null;
ClassReader cr = new ClassReader(bytecode);
@@ -61,8 +65,7 @@ protected byte[] writeProbes(String className, byte[] bytecode,
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classAdapter = new ControlDepAdapter(cw, className, false);
} else {
- cw = FRAMES ? new ClassWriter(ClassWriter.COMPUTE_FRAMES)
- : new ClassWriter(ClassWriter.COMPUTE_MAXS);
+ cw = FRAMES ? new ClassWriter(ClassWriter.COMPUTE_FRAMES) : new ClassWriter(ClassWriter.COMPUTE_MAXS);
classAdapter = new BytecodeClassAdapter(cw, className);
}
diff --git a/src/org/spideruci/analysis/statik/instrumentation/Config.java b/src/org/spideruci/analysis/statik/instrumentation/Config.java
index 8e77593..5916c8c 100755
--- a/src/org/spideruci/analysis/statik/instrumentation/Config.java
+++ b/src/org/spideruci/analysis/statik/instrumentation/Config.java
@@ -11,7 +11,7 @@ public class Config {
public static String[] retransformInclusionList;
public static String[] retransformExclusionList;
- public static IProfiler profiler = new EmptyProfiler(); // TODO: set to null so that the blinky-config has a change to override this
+ public static IProfiler profiler;
public static boolean checkInclusionList = false;
public static boolean forceCheckInclusionList = false;
diff --git a/src/org/spideruci/analysis/statik/instrumentation/ControlDepAdapter.java b/src/org/spideruci/analysis/statik/instrumentation/ControlDepAdapter.java
index f10c57f..32a88be 100644
--- a/src/org/spideruci/analysis/statik/instrumentation/ControlDepAdapter.java
+++ b/src/org/spideruci/analysis/statik/instrumentation/ControlDepAdapter.java
@@ -9,6 +9,9 @@
import org.objectweb.asm.tree.analysis.AnalyzerException;
import org.spideruci.analysis.statik.controlflow.ControlFlowAnalyzer;
+/**
+ * Used to mark bytecode indicies.
+ */
public class ControlDepAdapter extends ClassNode {
public static final String BYTECODE_LDC_MARKER = "blinkybytecode@";
diff --git a/src/org/spideruci/analysis/trace/EventBuilder.java b/src/org/spideruci/analysis/trace/EventBuilder.java
index e3a48f9..d5019bb 100644
--- a/src/org/spideruci/analysis/trace/EventBuilder.java
+++ b/src/org/spideruci/analysis/trace/EventBuilder.java
@@ -90,6 +90,11 @@ public static TraceEvent buildMethodDecl(String className, int access, String na
methodDecl.setProp(DeclPropNames.NAME, name);
methodDecl.setProp(DeclPropNames.ACCESS, String.valueOf(access));
methodDecl.setProp(DeclPropNames.OWNER, className);
+
+ if (TraceLogger.profiler != null) {
+ TraceLogger.profiler.willInstrumentMethod(methodDecl);
+ }
+
return methodDecl;
}
@@ -121,8 +126,12 @@ public static String buildInstructionLog(int byteIndex, int lineNum, EventType t
insnEvent.setProp(InsnPropNames.OPERAND3, op3);
String instructionLog = insnEvent.getLog();
+
+ if (TraceLogger.profiler != null) {
+ TraceLogger.profiler.willInstrumentCode(insnEvent);
+ }
+
if(Profiler.log) {
-// TraceLogger.outprintln(instructionLog);
Profiler.REAL_OUT.println(instructionLog);
}