From 22f6227efb878d67bd811637a735e29c02b495ee Mon Sep 17 00:00:00 2001 From: kheradmand Date: Fri, 6 Feb 2015 17:40:44 -0600 Subject: [PATCH] added debug info to aspecj template --- src/main/java/replaymop/Main.java | 2 +- src/main/java/replaymop/Parameters.java | 3 ++- .../replaymop/output/AspectJGenerator.java | 15 ++++++++++--- src/main/resources/AspectJTemplate.aj | 21 +++++++++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/replaymop/Main.java b/src/main/java/replaymop/Main.java index bd538c7..651a158 100644 --- a/src/main/java/replaymop/Main.java +++ b/src/main/java/replaymop/Main.java @@ -36,7 +36,7 @@ public static void main(String[] args){ parseArguments(args); File inputFile = new File(parameters.inputFile.get(0)); ReplaySpecification spec = RSParser.parse(inputFile); - Aspect aspect = AspectJGenerator.generate(spec); + Aspect aspect = AspectJGenerator.generate(spec, parameters); File outputFile = new File(inputFile.getParent() + File.separator + aspect.name + ".aj"); PrintWriter writer = new PrintWriter(outputFile); writer.println(aspect.toString()); diff --git a/src/main/java/replaymop/Parameters.java b/src/main/java/replaymop/Parameters.java index 514ee54..eac5114 100644 --- a/src/main/java/replaymop/Parameters.java +++ b/src/main/java/replaymop/Parameters.java @@ -1,6 +1,5 @@ package replaymop; -import java.io.File; import java.util.List; import com.beust.jcommander.*; @@ -9,6 +8,8 @@ public class Parameters { @Parameter(description = "Input file") public List inputFile; + @Parameter(names = "-debug-runtime", description = "Causes the replayed program to print debug info") + public boolean debug_runtime = true; } diff --git a/src/main/java/replaymop/output/AspectJGenerator.java b/src/main/java/replaymop/output/AspectJGenerator.java index 6236794..bc7a1bc 100644 --- a/src/main/java/replaymop/output/AspectJGenerator.java +++ b/src/main/java/replaymop/output/AspectJGenerator.java @@ -4,15 +4,18 @@ import java.util.List; import java.util.StringJoiner; +import replaymop.Parameters; import replaymop.output.aspectj.Aspect; import replaymop.parser.rs.ReplaySpecification; public class AspectJGenerator { ReplaySpecification spec; Aspect aspect; + Parameters params; - private AspectJGenerator(ReplaySpecification spec) { + private AspectJGenerator(ReplaySpecification spec, Parameters params) { this.spec = spec; + this.params = params; aspect = new Aspect(spec.fileName + "Aspect"); } @@ -67,6 +70,11 @@ void generateThreadSchedule() { printList(counts)); } + + void handleDebugInfo(){ + aspect.setParameter("DEBUG_BEGIN", params.debug_runtime ? "" : "\\*"); + aspect.setParameter("DEBUG_END", params.debug_runtime ? "" : "/*"); + } void startGeneration() { generateThreadCreationOrder(); @@ -75,11 +83,12 @@ void startGeneration() { generateBeforeSyncPointCut(); generateAfterSyncPointCut(); generateThreadSchedule(); + handleDebugInfo(); } - public static Aspect generate(ReplaySpecification spec) { - AspectJGenerator generator = new AspectJGenerator(spec); + public static Aspect generate(ReplaySpecification spec, Parameters params) { + AspectJGenerator generator = new AspectJGenerator(spec, params); generator.startGeneration(); return generator.aspect; } diff --git a/src/main/resources/AspectJTemplate.aj b/src/main/resources/AspectJTemplate.aj index a9bbbd2..ec59921 100644 --- a/src/main/resources/AspectJTemplate.aj +++ b/src/main/resources/AspectJTemplate.aj @@ -86,7 +86,7 @@ public aspect %NAME% { schedule_count[threadScheduleIndex]--; if (schedule_count[threadScheduleIndex] == 0){ threadScheduleIndex++; - this.notifyAll(); + threadScheduleLock.notifyAll(); } } } @@ -94,6 +94,23 @@ public aspect %NAME% { //===========================sched enforce end=========================== - + //============================debug info begin=========================== + + %DEBUG_BEGIN% + before(): beforeSync() && !cflow(adviceexecution()) { + printThread(); + } + + after(): afterSync() && !cflow(adviceexecution()){ + printThread(); + } + + void printThread(){ + System.out.printf("%d sync event\n", Thread.currentThread().getId()); + } + %DEBUG_END% + + + //============================debug info begin=========================== } \ No newline at end of file