summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-06-05 14:53:58 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-06-05 14:53:58 +0000
commit4ef16d3ab2ab50a9d04623018187d716f6cb434e (patch)
treefb02ca185f4739d929ace09586fcf12b1e37d509 /src
parentd32c3a0ac0504e420d54aab03df72efd2b9861d2 (diff)
downloadjavassist-4ef16d3ab2ab50a9d04623018187d716f6cb434e.tar.gz
javassist-4ef16d3ab2ab50a9d04623018187d716f6cb434e.zip
fixed JASSIST-168
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@631 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/bytecode/analysis/ControlFlow.java20
-rw-r--r--src/test/javassist/JvstTest.java3
-rw-r--r--src/test/test/javassist/bytecode/analysis/DomTreePrinter.java1
-rw-r--r--src/test/test/javassist/bytecode/analysis/DomTreeTest.java59
4 files changed, 71 insertions, 12 deletions
diff --git a/src/main/javassist/bytecode/analysis/ControlFlow.java b/src/main/javassist/bytecode/analysis/ControlFlow.java
index 38b59130..0560be6b 100644
--- a/src/main/javassist/bytecode/analysis/ControlFlow.java
+++ b/src/main/javassist/bytecode/analysis/ControlFlow.java
@@ -149,12 +149,10 @@ public class ControlFlow {
BasicBlock[] entrances(Node n) { return n.block.entrances; }
};
nodes[0].makeDepth1stTree(null, visited, 0, distance, access);
- for (int i = 0; i < size; i++)
- visited[i] = false;
-
- while (nodes[0].makeDominatorTree(visited, distance, access))
- ;
-
+ do {
+ for (int i = 0; i < size; i++)
+ visited[i] = false;
+ } while (nodes[0].makeDominatorTree(visited, distance, access));
Node.setChildren(nodes);
return nodes;
}
@@ -202,11 +200,11 @@ public class ControlFlow {
if (nodes[i].block.exits() == 0)
counter = nodes[i].makeDepth1stTree(null, visited, counter, distance, access);
- for (int i = 0; i < size; i++)
- visited[i] = false;
-
boolean changed;
do {
+ for (int i = 0; i < size; i++)
+ visited[i] = false;
+
changed = false;
for (int i = 0; i < size; i++)
if (nodes[i].block.exits() == 0)
@@ -245,7 +243,7 @@ public class ControlFlow {
protected void toString2(StringBuffer sbuf) {
super.toString2(sbuf);
- sbuf.append(", incomping{");
+ sbuf.append(", incoming{");
for (int i = 0; i < entrances.length; i++)
sbuf.append(entrances[i].position).append(", ");
@@ -280,7 +278,7 @@ public class ControlFlow {
public int incomings() { return incoming; }
/**
- * Returns the blocks that the control may jump into this block from.
+ * Returns the block that the control may jump into this block from.
*/
public Block incoming(int n) {
return entrances[n];
diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java
index f4ccaf6c..f646506b 100644
--- a/src/test/javassist/JvstTest.java
+++ b/src/test/javassist/JvstTest.java
@@ -1126,6 +1126,9 @@ public class JvstTest extends JvstTestRoot {
suite.addTestSuite(test.javassist.proxy.ProxyFactoryCompatibilityTest.class);
suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class);
suite.addTestSuite(test.javassist.proxy.ProxySimpleTest.class);
+ suite.addTestSuite(test.javassist.bytecode.analysis.AnalyzerTest.class);
+ suite.addTestSuite(test.javassist.convert.ArrayAccessReplaceTest.class);
+ suite.addTestSuite(test.javassist.bytecode.analysis.DomTreeTest.class);
return suite;
}
}
diff --git a/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java b/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java
index 481c8abb..2ada4acd 100644
--- a/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java
+++ b/src/test/test/javassist/bytecode/analysis/DomTreePrinter.java
@@ -20,7 +20,6 @@ public class DomTreePrinter {
Node[] pdom = cf.postDominatorTree();
for (int i = 0; i < pdom.length; i++)
System.out.println(i + ": " + pdom[i]);
-
}
public int dummy(int n, int[] array) {
diff --git a/src/test/test/javassist/bytecode/analysis/DomTreeTest.java b/src/test/test/javassist/bytecode/analysis/DomTreeTest.java
new file mode 100644
index 00000000..dd348d01
--- /dev/null
+++ b/src/test/test/javassist/bytecode/analysis/DomTreeTest.java
@@ -0,0 +1,59 @@
+package test.javassist.bytecode.analysis;
+
+import javassist.ClassPool;
+import javassist.bytecode.analysis.ControlFlow;
+import javassist.bytecode.analysis.ControlFlow.Block;
+import javassist.bytecode.analysis.ControlFlow.Node;
+import junit.framework.TestCase;
+
+public class DomTreeTest extends TestCase {
+ private ClassPool pool = ClassPool.getDefault();
+
+ public void testDomtree() throws Exception {
+ ControlFlow cf = new ControlFlow(pool.get(DomTreeTest.class.getName()).getDeclaredMethod("test1"));
+ Block[] blocks = cf.basicBlocks();
+ // for (int i = 0; i < blocks.length; i++)
+ // System.out.println(i + ": " + blocks[i]);
+ testBlock(blocks[0], new int[] {}, new int[] { 11, 6 } );
+ testBlock(blocks[1], new int[] { 0 }, new int[] { 17, 11 } );
+ testBlock(blocks[2], new int[] { 0, 6 }, new int[] { 19, 17 });
+ testBlock(blocks[3], new int[] { 6, 11 }, new int[] { 19 });
+ testBlock(blocks[4], new int[] { 11, 17 }, new int[] {});
+
+ Node[] dom = cf.dominatorTree();
+ assertNull(dom[0].parent());
+ assertEquals(0, dom[1].parent().block().position());
+ assertEquals(0, dom[2].parent().block().position());
+ assertEquals(0, dom[3].parent().block().position());
+ assertEquals(0, dom[4].parent().block().position());
+
+ Node[] pdom = cf.postDominatorTree();
+ assertEquals(19, pdom[0].parent().block().position());
+ assertEquals(19, pdom[1].parent().block().position());
+ assertEquals(19, pdom[2].parent().block().position());
+ assertEquals(19, pdom[3].parent().block().position());
+ assertNull(pdom[4].parent());
+ }
+
+ private void testBlock(Block b, int[] incoming, int[] outgoing) {
+ int i = 0;
+ for (int index: incoming)
+ assertEquals(index, b.incoming(i++).position());
+ i = 0;
+ for (int index: outgoing)
+ assertEquals(index, b.exit(i++).position());
+ }
+
+ private void testNode(Node n, int[] incoming, int[] outgoing) {
+ int i = 0;
+ for (int index: incoming)
+ assertEquals(index, n.parent().block().index());
+ }
+
+ public void test1(){
+ int k=0;
+ if (k != 0 && k!=2 || k < 7) {
+ k = 3 ;
+ }
+ }
+}