diff --git a/src/main/java/javamop/JavaMOPMain.java b/src/main/java/javamop/JavaMOPMain.java index 61d2b41e..92b9abdd 100644 --- a/src/main/java/javamop/JavaMOPMain.java +++ b/src/main/java/javamop/JavaMOPMain.java @@ -52,8 +52,6 @@ private JavaMOPMain() { public static boolean empty_advicebody = false; - public static boolean inline = false; - private static final List listFilePairs = new ArrayList(); private static final List listRVMFiles = new ArrayList(); diff --git a/src/main/java/javamop/output/combinedaspect/CombinedAspect.java b/src/main/java/javamop/output/combinedaspect/CombinedAspect.java index e429c946..ffd23555 100644 --- a/src/main/java/javamop/output/combinedaspect/CombinedAspect.java +++ b/src/main/java/javamop/output/combinedaspect/CombinedAspect.java @@ -70,8 +70,6 @@ public String toString() { ret += "public aspect " + this.name + " implements com.runtimeverification.rvmonitor.java.rt.RVMObject {\n"; - ret += this.statManager.fieldDecl(); - // Constructor ret += "public " + this.name + "(){\n"; diff --git a/src/main/java/javamop/output/combinedaspect/MOPStatManager.java b/src/main/java/javamop/output/combinedaspect/MOPStatManager.java index e0a84d9b..ae5515fc 100644 --- a/src/main/java/javamop/output/combinedaspect/MOPStatManager.java +++ b/src/main/java/javamop/output/combinedaspect/MOPStatManager.java @@ -138,25 +138,6 @@ public String constructor() { return ret; } - /** - * Field declarations for the global statistics. - * @return Java code with field declarations. - */ - public String fieldDecl() { - String ret = ""; - - if (!JavaMOPMain.options.statistics) - return ret; - - ret += "// Declarations for Statistics \n"; - for (MOPStatistics stat : stats.values()) { - ret += stat.fieldDecl(); - } - ret += "\n"; - - return ret; - } - /** * AspectJ advice code for all of the managed statistics. * @return AspectJ code. diff --git a/src/main/java/javamop/output/combinedaspect/MOPStatistics.java b/src/main/java/javamop/output/combinedaspect/MOPStatistics.java index 969061a9..996cada2 100644 --- a/src/main/java/javamop/output/combinedaspect/MOPStatistics.java +++ b/src/main/java/javamop/output/combinedaspect/MOPStatistics.java @@ -1,4 +1,4 @@ -// Copyright (c) 2002-2014 JavaMOP Team. All Rights Reserved. +// Copyright (c) 2002-2014 JavaMOP Team. All Rights Reserved. package javamop.output.combinedaspect; import java.util.HashMap; @@ -14,11 +14,13 @@ * Statistics for a single property. */ public class MOPStatistics { - private final String aspectName; - - private final MOPVariable numMonitor; - private final MOPVariable collectedMonitor; - private final MOPVariable terminatedMonitor; + + private final String totalMonitorMethodName = "getTotalMonitorCount"; + private final String collectedMonitorMethodName = "getCollectedMonitorCount"; + private final String terminatedMonitorMethodName = "getTerminatedMonitorCount"; + private final String eventCountersMethodName = "getEventCounters"; + private final String categoryCountersMethodName = "getCategoryCounters"; + private final HashMap eventVars = new HashMap(); private final HashMap> categoryVars = new HashMap>(); @@ -26,6 +28,7 @@ public class MOPStatistics { new HashMap(); private final String specName; + private final boolean isRaw; /** * Construct statistics variables for a single property. @@ -33,11 +36,8 @@ public class MOPStatistics { * @param mopSpec The specification that has statistics being collected on it. */ public MOPStatistics(final String name, final JavaMOPSpec mopSpec) { - this.aspectName = name + "MonitorAspect"; this.specName = mopSpec.getName(); - this.numMonitor = new MOPVariable(mopSpec.getName() + "_Monitor_num"); - this.collectedMonitor = new MOPVariable(mopSpec.getName() + "_CollectedMonitor_num"); - this.terminatedMonitor = new MOPVariable(mopSpec.getName() + "_TerminatedMonitor_num"); + this.isRaw = mopSpec.isRaw(); for (EventDefinition event : mopSpec.getEvents()) { MOPVariable eventVar = new MOPVariable(mopSpec.getName() + "_" + event.getId() + @@ -62,107 +62,6 @@ public MOPStatistics(final String name, final JavaMOPSpec mopSpec) { } } - /** - * Fields used in maintaining statistics for this property. - * @return Java source code declarations for maintaining statistics. - */ - public String fieldDecl() { - String ret = ""; - if (!JavaMOPMain.options.statistics) - return ret; - - ret += "static long " + numMonitor + " = 0;\n"; - ret += "static long " + collectedMonitor + " = 0;\n"; - ret += "static long " + terminatedMonitor + " = 0;\n"; - - for (MOPVariable eventVar : eventVars.values()) { - ret += "static long " + eventVar + " = 0;\n"; - } - - for (HashMap categoryVarsforProp : categoryVars.values()) { - for (MOPVariable categoryVar : categoryVarsforProp.values()) { - ret += "static long " + categoryVar + " = 0;\n"; - } - } - - return ret; - } - - public String paramInc(final MOPParameter param) { - return ""; - } - - /** - * Code to increment the counter for an event. - * @param eventName The name of the event that was incremented. - * @return Java source code to increment the counter for receiving events. - */ - public String eventInc(final String eventName) { - String ret = ""; - if (!JavaMOPMain.options.statistics) - return ret; - - MOPVariable eventVar = eventVars.get(eventName); - - ret += eventVar + "++;\n"; - - return ret; - } - - public String categoryInc(final PropertyAndHandlers prop, final String category) { - String ret = ""; - if (!JavaMOPMain.options.statistics) - return ret; - - MOPVariable categoryVar = categoryVars.get(prop).get(category); - - ret += aspectName + "." + categoryVar + "++;\n"; - - return ret; - } - - /** - * Code to increment the counter for number of monitors generated. - * @return Java code to increment the counter for a monitor being generated. - */ - public String incNumMonitor() { - String ret = ""; - if (!JavaMOPMain.options.statistics) - return ret; - - ret += aspectName + "." + numMonitor + "++;\n"; - - return ret; - } - - /** - * Code to increment the counter for collected monitors. - * @return Java code to increment the counter for a monitor being collected. - */ - public String incCollectedMonitor() { - String ret = ""; - if (!JavaMOPMain.options.statistics) - return ret; - - ret += aspectName + "." + collectedMonitor + "++;\n"; - - return ret; - } - - /** - * Code to increment the counter for terminated monitors. - * @return Java code to increment the counter for a monitor being terminated. - */ - public String incTerminatedMonitor() { - String ret = ""; - if (!JavaMOPMain.options.statistics) - return ret; - - ret += aspectName + "." + terminatedMonitor + "++;\n"; - - return ret; - } - /** * AspectJ advice code to display the statistics after termination of the program. * @return AspectJ/Java source code displaying statistics. @@ -171,23 +70,30 @@ public String advice() { String ret = ""; if (!JavaMOPMain.options.statistics) return ret; - + + String monitorName = specName + (isRaw ? "Raw" : "") + "Monitor"; + ret += "after () : execution(* *.main(..)) {\n"; ret += "System.err.println(\"== " + this.specName + " ==\");\n"; - ret += "System.err.println(\"#monitors: \" + " + numMonitor + ");\n"; + + ret += "System.err.println(\"#monitors: \" + " + monitorName + "." + this.totalMonitorMethodName + "());\n"; + ret += "System.err.println(\"#collected monitors: \" + " + monitorName + "." + + this.collectedMonitorMethodName + "());\n"; + ret += "System.err.println(\"#terminated monitors: \" + " + monitorName + "." + + this.terminatedMonitorMethodName + "());\n"; for (String eventName : eventVars.keySet()) { - MOPVariable eventVar = eventVars.get(eventName); - ret += "System.err.println(\"#event - " + eventName + ": \" + " + eventVar + ");\n"; + ret += "System.err.println(\"#event - " + eventName + ": \" + " + monitorName + "." + + this.eventCountersMethodName + "()" + ".get(\"" + eventName + "\")" +");\n"; } for (PropertyAndHandlers prop : categoryVars.keySet()) { HashMap categoryVarsforProp = categoryVars.get(prop); for (String categoryName : categoryVarsforProp.keySet()) { - MOPVariable categoryVar = categoryVarsforProp.get(categoryName); - ret += "System.err.println(\"#category - prop " + prop.getPropertyId() + " - " + - categoryName + ": \" + " + categoryVar + ");\n"; + ret += "System.err.println(\"#category - prop " + prop.getPropertyId() + " - " + + categoryName + ": \" + " + monitorName + "." + + this.categoryCountersMethodName + "()" + ".get(\"" + categoryName + "\")" +");\n"; } } @@ -201,5 +107,5 @@ public String advice() { return ret; } - + } diff --git a/src/main/java/javamop/output/combinedaspect/event/advice/AdviceAndPointCut.java b/src/main/java/javamop/output/combinedaspect/event/advice/AdviceAndPointCut.java index e4003289..1ebea94b 100644 --- a/src/main/java/javamop/output/combinedaspect/event/advice/AdviceAndPointCut.java +++ b/src/main/java/javamop/output/combinedaspect/event/advice/AdviceAndPointCut.java @@ -182,123 +182,6 @@ public boolean addEvent(final JavaMOPSpec mopSpec, final EventDefinition event, return true; } - /** - * The generated advice code for this event. - * @return Generated advice code. - */ - protected String adviceBody(){ - String ret = ""; - - if(JavaMOPMain.empty_advicebody){ - ret += "System.out.print(\"\");\n"; - - Iterator iter; - if(this.pos.equals("before")) - iter = this.events.descendingIterator(); - else - iter = this.events.iterator(); - - if (this.beCounted) { - ret += "++" + this.pointcutName + "_count;\n"; - } - - while(iter.hasNext()){ - EventDefinition event = iter.next(); - - AdviceBody advice = advices.get(event); - - if(advices.size() > 1){ - ret += "//" + advice.mopSpec.getName() + "_" + event.getUniqueId() + "\n"; - } - } - } else { - for (MOPParameter threadVar : threadVars) { - ret += "Thread " + threadVar.getName() + " = Thread.currentThread();\n"; - } - - for(JavaMOPSpec spec : specsForActivation){ - ret += activatorsManager.getActivator(spec) + " = true;\n"; - } - - if (isSync) { - ret += "while (!" + globalLock.getName() + ".tryLock()) {\n"; - ret += "Thread.yield();\n"; - ret += "}\n"; - } - - Iterator iter; - if(this.pos.equals("before")) - iter = this.events.descendingIterator(); - else - iter = this.events.iterator(); - - if (this.beCounted) { - ret += "++" + this.pointcutName + "_count;\n"; - } - - while(iter.hasNext()){ - EventDefinition event = iter.next(); - - AdviceBody advice = advices.get(event); - - ret += this.statManager.incEvent(advice.mopSpec, event); - - if(specsForChecking.contains(advice.mopSpec)){ - if(advices.size() > 1){ - ret += "//" + advice.mopSpec.getName() + "_" + event.getUniqueId() + "\n"; - } - - ret += "if (" + activatorsManager.getActivator(advice.mopSpec) + ") {\n"; - } else { - if(advices.size() > 1){ - ret += "//" + advice.mopSpec.getName() + "_" + event.getUniqueId() + "\n"; - ret += "{\n"; - } - } - - if (JavaMOPMain.options.statistics) { - MOPStatistics stat = this.statManager.getStat(advice.mopSpec); - - ret += stat.eventInc(event.getId()); - - for (MOPParameter param : event.getMOPParametersOnSpec()) { - ret += stat.paramInc(param); - } - - ret += "\n"; - } - - // add check count condition here - String countCond = event.getCountCond(); - - if (countCond != null && countCond.length() != 0) { - countCond = countCond.replaceAll("count", this.pointcutName + "_count"); - ret += "if (" + countCond + ") {\n"; - } - ret += advice; - - if (countCond != null && countCond.length() != 0) { - ret += "}\n"; - } - - if(specsForChecking.contains(advice.mopSpec)){ - ret += "}\n"; - } else { - if(advices.size() > 1){ - ret += "}\n"; - } - } - } - - if (isSync) { - ret += globalLock.getName() + ".unlock();\n"; - } - - } - - return ret; - } - /** * Generated Java/AspectJ complete source code for this advice and pointcut as code that works * together with RV-Monitor generated code. @@ -308,23 +191,8 @@ protected String adviceBody(){ public String toString() { String ret = ""; String pointcutStr = pointcut.toString(); - - // Do we need to handle inline? - if(JavaMOPMain.inline && !isAround){ - ret += "void " + inlineFuncName + "(" + inlineParameters.parameterDeclString(); - if(hasThisJoinPoint){ - if(inlineParameters.size() > 0) - ret += ", "; - ret += "JoinPoint thisJoinPoint"; - } - ret += ") {\n"; - - ret += adviceBody(); - - ret += "}\n"; - } - - + + ret += "pointcut " + pointcutName; ret += "("; ret += parameters.parameterDeclString(); @@ -359,105 +227,92 @@ public String toString() { if (aroundLocalDecl != null) ret += aroundLocalDecl; - - if(JavaMOPMain.inline && !isAround){ - ret += inlineFuncName + "(" + inlineParameters.parameterString(); - if(hasThisJoinPoint){ - if(inlineParameters.size() > 0) - ret += ", "; - ret += "thisJoinPoint"; + + + // Call method here MOPNameRuntimeMonitor.nameEvent() + // If there's thread var, replace with t (currentThread), + // and also generate Thread t = currentThread before it + // If there's return/ throw pointcut, cat in the end + + for (MOPParameter threadVar : threadVars) { + ret += "Thread " + threadVar.getName() + " = Thread.currentThread();\n"; + } + + Iterator iter; + if (this.pos.equals("before")) + iter = this.events.descendingIterator(); + else + iter = this.events.iterator(); + + while (iter.hasNext()) { + EventDefinition event = iter.next(); + + AdviceBody advice = advices.get(event); + + if (advices.size() > 1) { + ret += "//" + advice.mopSpec.getName() + "_" + + event.getUniqueId() + "\n"; } - ret += ");\n"; - } else { - - // Call method here MOPNameRuntimeMonitor.nameEvent() - // If there's thread var, replace with t (currentThread), - // and also generate Thread t = currentThread before it - // If there's return/ throw pointcut, cat in the end - - for (MOPParameter threadVar : threadVars) { - ret += "Thread " + threadVar.getName() + " = Thread.currentThread();\n"; + + String countCond = event.getCountCond(); + + if (countCond != null && countCond.length() != 0) { + ret += "++" + this.pointcutName + "_count;\n"; + countCond = countCond.replaceAll("count", this.pointcutName + + "_count"); + ret += "if (" + countCond + ") {\n"; } - - Iterator iter; - if(this.pos.equals("before")) - iter = this.events.descendingIterator(); - else - iter = this.events.iterator(); - - while (iter.hasNext()) { - EventDefinition event = iter.next(); - - AdviceBody advice = advices.get(event); - - if (advices.size() > 1) { - ret += "//" + advice.mopSpec.getName() + "_" - + event.getUniqueId() + "\n"; - } - - String countCond = event.getCountCond(); - - if (countCond != null && countCond.length() != 0) { - ret += "++" + this.pointcutName+ "_count;\n"; - countCond = countCond.replaceAll("count", this.pointcutName - + "_count"); - ret += "if (" + countCond + ") {\n"; - } - - ret += EventManager.EventMethodHelper.methodName(advice.mopSpec, event, + + ret += EventManager.EventMethodHelper.methodName(advice.mopSpec, event, this.fileName); - ret += "("; - - // Parameters - // Original (including threadVar) - String original = event.getParameters().parameterString(); - ret += original; - - // Parameters in returning pointcut - if (event.getRetVal() != null && event.getRetVal().size() > 0) { - String retParameters = event.getRetVal().parameterString(); - if (retParameters.length() > 0) { - if (original == null || original.length() == 0) - { - ret += retParameters; - } else { - ret += ", " + retParameters; - } - } - } - - // Parameters in throwing pointcut - if (event.getThrowVal() != null && event.getThrowVal().size() > 0) { - String throwParameters = event.getThrowVal().parameterString(); - if (throwParameters.length() > 0) { - if (original == null || original.length() == 0) - { - ret += throwParameters; - } else { - ret += ", " + throwParameters; - } + ret += "("; + + // Parameters + // Original (including threadVar) + String original = event.getParameters().parameterString(); + ret += original; + + // Parameters in returning pointcut + if (event.getRetVal() != null && event.getRetVal().size() > 0) { + String retParameters = event.getRetVal().parameterString(); + if (retParameters.length() > 0) { + if (original == null || original.length() == 0) { + ret += retParameters; + } else { + ret += ", " + retParameters; } } - - // __STATICSIG should be passed as an argument because rv-monitor cannot infer - if (event.has__STATICSIG()) { - String staticsig = "thisJoinPoint.getStaticPart().getSignature()"; - if (original == null || original.length() == 0) - { - ret += staticsig; + } + + // Parameters in throwing pointcut + if (event.getThrowVal() != null && event.getThrowVal().size() > 0) { + String throwParameters = event.getThrowVal().parameterString(); + if (throwParameters.length() > 0) { + if (original == null || original.length() == 0) { + ret += throwParameters; } else { - ret += ", " + staticsig; + ret += ", " + throwParameters; } } - - ret += ");\n"; - - if (countCond != null && countCond.length() != 0) { - ret += "}\n"; + } + + // __STATICSIG should be passed as an argument because rv-monitor cannot infer + if (event.has__STATICSIG()) { + String staticsig = "thisJoinPoint.getStaticPart().getSignature()"; + if (original == null || original.length() == 0) { + ret += staticsig; + } else { + ret += ", " + staticsig; } } + + ret += ");\n"; + + if (countCond != null && countCond.length() != 0) { + ret += "}\n"; + } } - + if (aroundAdviceReturn != null) ret += aroundAdviceReturn;