Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution tracer refactor #223

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified microbat/lib/instrumentator.jar
Binary file not shown.
36 changes: 18 additions & 18 deletions microbat_instrumentator/.classpath
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry exported="true" kind="lib" path="lib/sqlite-jdbc-3.32.3.2.jar" sourcepath="C:/Users/YUNLIN~1/AppData/Local/Temp/.org.sf.feeling.decompiler1623741800067/source/sqlite-jdbc-3.32.3.2-sources.jar"/>
<classpathentry kind="src" path="src/core"/>
<classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
<classpathentry kind="lib" path="lib/javassist.jar"/>
<classpathentry kind="lib" path="lib/sav.commons.simplified.jar" sourcepath="/sav.commons"/>
<classpathentry kind="lib" path="lib/commons-io-1.3.2.jar"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.44-bin.jar" sourcepath="lib/mysql-connector-java-5.1.44.zip"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.12.jar"/>
<classpathentry kind="lib" path="lib/bcel-6.0.jar" sourcepath="lib/bcel-6.0-sources.jar"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry exported="true" kind="lib" path="lib/sqlite-jdbc-3.32.3.2.jar" sourcepath="C:/Users/YUNLIN~1/AppData/Local/Temp/.org.sf.feeling.decompiler1623741800067/source/sqlite-jdbc-3.32.3.2-sources.jar"/>
<classpathentry kind="src" path="src/core"/>
<classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
<classpathentry kind="lib" path="lib/javassist.jar"/>
<classpathentry kind="lib" path="lib/sav.commons.simplified.jar" sourcepath="/sav.commons"/>
<classpathentry kind="lib" path="lib/commons-io-1.3.2.jar"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.44-bin.jar" sourcepath="lib/mysql-connector-java-5.1.44.zip"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.12.jar"/>
<classpathentry kind="lib" path="lib/bcel-6.0.jar" sourcepath="lib/bcel-6.0-sources.jar"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 3 additions & 3 deletions microbat_instrumentator/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8
Binary file modified microbat_instrumentator/lib/instrumentator_agent_v02.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import microbat.instrumentation.cfgcoverage.CoverageAgentParams;
import microbat.instrumentation.filter.GlobalFilterChecker;
import microbat.instrumentation.runtime.ExecutionTracer;
import microbat.instrumentation.runtime.ExecutionTrace;
import microbat.instrumentation.runtime.IExecutionTracer;

/**
Expand Down Expand Up @@ -59,7 +60,7 @@ public void run() {
*/
public static void _exitProgram(String programMsg) {
if(Thread.currentThread().getName().equals("main")) {
ExecutionTracer.getMainThreadStore().lock();
ExecutionTrace.getMainThreadStore().lock();
Agent.programMsg = programMsg;

boolean allInterestedThreadsStop = false;
Expand All @@ -72,15 +73,15 @@ public static void _exitProgram(String programMsg) {

boolean needToConitnue = false;

for(IExecutionTracer tracer: ExecutionTracer.getAllThreadStore()) {
for(IExecutionTracer tracer: ExecutionTrace.getAllThreadStore()) {
if(tracer instanceof ExecutionTracer) {
ExecutionTracer eTracer = (ExecutionTracer)tracer;

if(eTracer.getThreadName().equals("main") || eTracer.getTrace().size()==0) {
continue;
}

if(!ExecutionTracer.stoppedThreads.contains(eTracer.getThreadId())) {
if(!ExecutionTrace.stoppedThreads.contains(eTracer.getThreadId())) {
needToConitnue = true;
break;

Expand All @@ -92,15 +93,15 @@ public static void _exitProgram(String programMsg) {
}

stop();
ExecutionTracer.getMainThreadStore().unLock();
ExecutionTrace.getMainThreadStore().unLock();
Runtime.getRuntime().exit(1); // force program to exit to avoid getting stuck by background running threads.
}
else {
/**
* we do not record the thread any more
*/
// long threadId = Thread.currentThread().getId();
ExecutionTracer.stopRecordingCurrendThread();
ExecutionTrace.stopRecordingCurrendThread();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

import microbat.instrumentation.AgentParams.LogType;
import microbat.instrumentation.runtime.ExecutionTracer;
import microbat.instrumentation.runtime.ExecutionTrace;

public class AgentLogger {
private static boolean enableDebug;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static void info(String msg) {

public static void printProgress(int curStep) {
if (printProgress) {
int totalSteps = ExecutionTracer.expectedSteps == Integer.MAX_VALUE? ExecutionTracer.stepLimit : ExecutionTracer.expectedSteps;
int totalSteps = ExecutionTrace.getExpectedSteps() == Integer.MAX_VALUE? ExecutionTrace.getStepLimit() : ExecutionTrace.getExpectedSteps();
System.out.println(new StringBuffer().append(AgentConstants.PROGRESS_HEADER)
.append(curStep).append(" ").append(totalSteps).append(" ").toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import microbat.instrumentation.filter.GlobalFilterChecker;
import microbat.instrumentation.filter.OverLongMethodFilter;
import microbat.instrumentation.instr.TraceTransformer;
import microbat.instrumentation.runtime.ExecutionTracer;
import microbat.instrumentation.runtime.ExecutionTrace;
import microbat.instrumentation.runtime.IExecutionTracer;
import microbat.model.trace.Trace;
import microbat.model.trace.TraceNode;
Expand All @@ -31,9 +31,9 @@ public void startup(long vmStartupTime, long agentPreStartup) {
/* init filter */
AppJavaClassPath appPath = agentParams.initAppClassPath();
GlobalFilterChecker.setup(appPath, agentParams.getIncludesExpression(), agentParams.getExcludesExpression());
ExecutionTracer.appJavaClassPath = appPath;
ExecutionTracer.variableLayer = agentParams.getVariableLayer();
ExecutionTracer.setStepLimit(agentParams.getStepLimit());
ExecutionTrace.setAppJavaClassPath(appPath);
ExecutionTrace.setVariableLayer(agentParams.getVariableLayer());
ExecutionTrace.setStepLimit(agentParams.getStepLimit());
if (!agentParams.isRequireMethodSplit()) {
agentParams.getUserFilters().register(new OverLongMethodFilter(agentParams.getOverlongMethods()));
}
Expand All @@ -42,32 +42,26 @@ public void startup(long vmStartupTime, long agentPreStartup) {
agentParams.getUserFilters().register(new CodeRangeUserFilter(agentParams.getCodeRanges()));
}

ExecutionTracer.setExpectedSteps(agentParams.getExpectedSteps());
ExecutionTracer.avoidProxyToString = agentParams.isAvoidProxyToString();
ExecutionTrace.setExpectedSteps(agentParams.getExpectedSteps());
ExecutionTrace.setAvoidProxyToString(agentParams.isAvoidProxyToString());
}

public void shutdown() throws Exception {
ExecutionTracer.shutdown();
ExecutionTrace.shutdown();
/* collect trace & store */
AgentLogger.debug("Building trace dependencies ...");
timer.newPoint("Building trace dependencies");
// FIXME -mutithread LINYUN [3]
// LLT: only trace of main thread is recorded.
List<IExecutionTracer> tracers = ExecutionTracer.getAllThreadStore();

int size = tracers.size();
List<Trace> traceList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {

ExecutionTracer tracer = (ExecutionTracer) tracers.get(i);

Trace trace = tracer.getTrace();
trace.setThreadId(tracer.getThreadId());
trace.setThreadName(tracer.getThreadName());
trace.setMain(ExecutionTracer.getMainThreadStore().equals(tracer));

List<IExecutionTracer> tracers = ExecutionTrace.getAllThreadStore();

List<Trace> traceList = ExecutionTrace.getTraceList();
for (Trace trace : traceList) {
// TODO: check for name and Id and main to be initialized in tracer
// trace.setThreadId(tracer.getThreadId());
// trace.setThreadName(tracer.getThreadName());
// trace.setMain(ExecutionTrace.getMainThreadStore().equals(tracer));
constructTrace(trace);
traceList.add(trace);
}

timer.newPoint("Saving trace");
Expand All @@ -80,7 +74,7 @@ public void constructTrace(Trace trace) {
GlobalFilterChecker.addFilterInfo(trace);

StepMismatchChecker.logNormalSteps(trace);
ExecutionTracer.dispose(); // clear cache
ExecutionTrace.dispose(); // clear cache
long t1 = System.currentTimeMillis();
AgentLogger.debug("create VirtualDataRelation....");
createVirtualDataRelation(trace);
Expand Down Expand Up @@ -182,14 +176,14 @@ public AgentParams getAgentParams() {

@Override
public void startTest(String junitClass, String junitMethod) {
ExecutionTracer._start();
ExecutionTracer.appJavaClassPath.setOptionalTestClass(junitClass);
ExecutionTracer.appJavaClassPath.setOptionalTestMethod(junitMethod);
ExecutionTrace._start();
ExecutionTrace.setAppJavaClassPathOptionalTestClass(junitClass);
ExecutionTrace.setAppJavaClassPathOptionalTestMethod(junitMethod);
}

@Override
public void finishTest(String junitClass, String junitMethod) {
ExecutionTracer.shutdown();
ExecutionTrace.shutdown();
}

@Override
Expand All @@ -210,6 +204,6 @@ public void exitTest(String testResultMsg, String junitClass, String junitMethod

@Override
public boolean isInstrumentationActive() {
return !ExecutionTracer.isShutdown();
return !ExecutionTrace.isShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Set;

import microbat.instrumentation.runtime.ExecutionTrace;
import microbat.instrumentation.runtime.ExecutionTracer;
import microbat.model.trace.Trace;
import sav.common.core.utils.StringUtils;
Expand All @@ -31,7 +32,7 @@ public static GlobalFilterChecker getInstance() {
public void startup(AppJavaClassPath appClasspath, String includeExpression, String excludeExpression) {
extLibs = new ArrayList<>();
appBinFolders = new ArrayList<>();
ExecutionTracer.appJavaClassPath = appClasspath;
ExecutionTrace.setAppJavaClassPath(appClasspath);
String workingDir = getPath(appClasspath.getWorkingDirectory());
for (String cp : appClasspath.getClasspaths()) {
String path = getPath(cp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.security.ProtectionDomain;

import microbat.instrumentation.AgentLogger;
import microbat.instrumentation.runtime.ExecutionTracer;
import microbat.instrumentation.runtime.ExecutionTrace;
import microbat.instrumentation.runtime.IExecutionTracer;
import sav.common.core.utils.FileUtils;

Expand All @@ -16,10 +16,10 @@ public abstract class AbstractTransformer implements ClassFileTransformer {
@Override
public final byte[] transform(ClassLoader loader, String classFName, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (ExecutionTracer.isShutdown()) {
if (ExecutionTrace.isShutdown()) {
return null;
}
IExecutionTracer tracer = ExecutionTracer.getCurrentThreadStore();
IExecutionTracer tracer = ExecutionTrace.getCurrentThreadStore();
/*
* The reason we need to lock and unlock the tracer:
* when a method which is being traced invoke a another method which class is required to be loaded,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package microbat.instrumentation.runtime;

import microbat.model.trace.Trace;

public class EmptyExecutionTracer implements IExecutionTracer {
private static final IExecutionTracer instance = new EmptyExecutionTracer();

Expand Down Expand Up @@ -119,4 +121,9 @@ public void setThreadName(String threadName) {

}

@Override
public Trace getTrace() {
return null;
}

}
Loading