git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@631 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
<property name="target-src.jar" value="javassist-src.jar"/> | <property name="target-src.jar" value="javassist-src.jar"/> | ||||
<property name="lib.dir" value="${basedir}/lib"/> | <property name="lib.dir" value="${basedir}/lib"/> | ||||
<property name="src.dir" value="${basedir}/src/main"/> | <property name="src.dir" value="${basedir}/src/main"/> | ||||
<property name="build.dir" value="${basedir}/build"/> | |||||
<property name="build.dir" value="${basedir}/target"/> | |||||
<property name="build.classes.dir" value="${build.dir}/classes"/> | <property name="build.classes.dir" value="${build.dir}/classes"/> | ||||
<property name="test.src.dir" value="${basedir}/src/test"/> | <property name="test.src.dir" value="${basedir}/src/test"/> | ||||
<property name="test.build.dir" value="${basedir}/build/test-classes"/> | |||||
<property name="test.build.dir" value="${build.dir}/test-classes"/> | |||||
<property name="test.run.dir" value="${basedir}/runtest"/> | <property name="test.run.dir" value="${basedir}/runtest"/> | ||||
<property name="test.reports.dir" value = "${basedir}/build/test-output"/> | |||||
<property name="test.reports.dir" value = "${build.dir}/test-output"/> | |||||
<property name="run.dir" value="${build.classes.dir}"/> | <property name="run.dir" value="${build.classes.dir}"/> | ||||
BasicBlock[] entrances(Node n) { return n.block.entrances; } | BasicBlock[] entrances(Node n) { return n.block.entrances; } | ||||
}; | }; | ||||
nodes[0].makeDepth1stTree(null, visited, 0, distance, access); | 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); | Node.setChildren(nodes); | ||||
return nodes; | return nodes; | ||||
} | } | ||||
if (nodes[i].block.exits() == 0) | if (nodes[i].block.exits() == 0) | ||||
counter = nodes[i].makeDepth1stTree(null, visited, counter, distance, access); | counter = nodes[i].makeDepth1stTree(null, visited, counter, distance, access); | ||||
for (int i = 0; i < size; i++) | |||||
visited[i] = false; | |||||
boolean changed; | boolean changed; | ||||
do { | do { | ||||
for (int i = 0; i < size; i++) | |||||
visited[i] = false; | |||||
changed = false; | changed = false; | ||||
for (int i = 0; i < size; i++) | for (int i = 0; i < size; i++) | ||||
if (nodes[i].block.exits() == 0) | if (nodes[i].block.exits() == 0) | ||||
protected void toString2(StringBuffer sbuf) { | protected void toString2(StringBuffer sbuf) { | ||||
super.toString2(sbuf); | super.toString2(sbuf); | ||||
sbuf.append(", incomping{"); | |||||
sbuf.append(", incoming{"); | |||||
for (int i = 0; i < entrances.length; i++) | for (int i = 0; i < entrances.length; i++) | ||||
sbuf.append(entrances[i].position).append(", "); | sbuf.append(entrances[i].position).append(", "); | ||||
public int incomings() { return incoming; } | 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) { | public Block incoming(int n) { | ||||
return entrances[n]; | return entrances[n]; |
suite.addTestSuite(test.javassist.proxy.ProxyFactoryCompatibilityTest.class); | suite.addTestSuite(test.javassist.proxy.ProxyFactoryCompatibilityTest.class); | ||||
suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class); | suite.addTestSuite(test.javassist.proxy.ProxySerializationTest.class); | ||||
suite.addTestSuite(test.javassist.proxy.ProxySimpleTest.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; | return suite; | ||||
} | } | ||||
} | } |
Node[] pdom = cf.postDominatorTree(); | Node[] pdom = cf.postDominatorTree(); | ||||
for (int i = 0; i < pdom.length; i++) | for (int i = 0; i < pdom.length; i++) | ||||
System.out.println(i + ": " + pdom[i]); | System.out.println(i + ": " + pdom[i]); | ||||
} | } | ||||
public int dummy(int n, int[] array) { | public int dummy(int n, int[] array) { |
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 ; | |||||
} | |||||
} | |||||
} |