aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cflow
diff options
context:
space:
mode:
authoraclement <aclement>2004-10-11 18:39:06 +0000
committeraclement <aclement>2004-10-11 18:39:06 +0000
commit5c996fc559581581e9dde60a6f555aa3ff7cc042 (patch)
treed3f307672d856355aa3b0d8fbf5b81fb9c18f451 /tests/cflow
parent7fe9492cbb9b857e45531f6c74fbd15f8c551b25 (diff)
downloadaspectj-5c996fc559581581e9dde60a6f555aa3ff7cc042.tar.gz
aspectj-5c996fc559581581e9dde60a6f555aa3ff7cc042.zip
76030 - cflow optimizations. Part 1 fix - use counters rather than stacks when we can.
Diffstat (limited to 'tests/cflow')
-rw-r--r--tests/cflow/CounterTest01.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/cflow/CounterTest01.java b/tests/cflow/CounterTest01.java
new file mode 100644
index 000000000..1578ea0f8
--- /dev/null
+++ b/tests/cflow/CounterTest01.java
@@ -0,0 +1,68 @@
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class CounterTest01 {
+
+ public static void main(String []argv) {
+ new CounterTest01().sayMessage();
+ int ctrs = ReflectionHelper.howManyCflowCounterFields(Cflow1.aspectOf());
+ if (ctrs!=2) {
+ throw new RuntimeException("Should be two cflow counters, but found: "+ctrs);
+ }
+ int stacks = ReflectionHelper.howManyCflowStackFields(Cflow1.aspectOf());
+ if (stacks!=1) {
+ throw new RuntimeException("Should be one cflow stacks, but found: "+stacks);
+ }
+ }
+
+ public void sayMessage() {
+ print("Hello ");
+ print("World\n");
+ }
+
+ public void print(String msg) {
+ System.out.print(msg);
+ }
+}
+
+aspect Cflow1 {
+ before(): execution(* print(..)) && cflow(execution(* main(..))) {
+ // Managed by a CflowCounter
+ }
+
+ before(): execution(* print(..)) && cflow(execution(* main(..))) {
+ // Managed by a CflowCounter
+ }
+
+ before(Object o): execution(* print(..)) && cflow(execution(* main(..)) && target(o)) {
+ // Managed by a CflowStack - since state is exposed
+ }
+}
+
+class ReflectionHelper {
+ public static List getCflowfields(Object o,boolean includeCounters,boolean includeStacks) {
+ List res = new ArrayList();
+ Class clazz = o.getClass();
+ Field[] fs = clazz.getDeclaredFields();
+ for (int i = 0; i < fs.length; i++) {
+ Field f = fs[i];
+ if ((f.getType().getName().endsWith("CFlowCounter") && includeCounters) ||
+ (f.getType().getName().endsWith("CFlowStack") && includeStacks)) {
+ res.add(f.getType().getName()+":"+f.getName());
+ }
+ }
+ return res;
+ }
+
+ public static int howManyCflowCounterFields(Object o) {
+ return getCflowfields(o,true,false).size();
+ }
+
+ public static int howManyCflowStackFields(Object o) {
+ return getCflowfields(o,false,true).size();
+ }
+
+}