You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DomTreePrinter.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package test.javassist.bytecode.analysis;
  2. import javassist.ClassPool;
  3. import javassist.bytecode.analysis.ControlFlow;
  4. import javassist.bytecode.analysis.ControlFlow.Block;
  5. import javassist.bytecode.analysis.ControlFlow.Node;
  6. public class DomTreePrinter {
  7. public static void main(String[] args) throws Exception {
  8. ClassPool pool = ClassPool.getDefault();
  9. ControlFlow cf = new ControlFlow(pool.get(args[0]).getDeclaredMethod(args[1]));
  10. Block[] blocks = cf.basicBlocks();
  11. for (int i = 0; i < blocks.length; i++)
  12. System.out.println(i + ": " + blocks[i]);
  13. Node[] dom = cf.dominatorTree();
  14. for (int i = 0; i < dom.length; i++)
  15. System.out.println(i + ": " + dom[i]);
  16. Node[] pdom = cf.postDominatorTree();
  17. for (int i = 0; i < pdom.length; i++)
  18. System.out.println(i + ": " + pdom[i]);
  19. }
  20. public int dummy(int n, int[] array) {
  21. for (int i = 0; i < n; i++) {
  22. if (array[i] > 0)
  23. break;
  24. if (array[i] > -1)
  25. continue;
  26. array[0]++;
  27. array[1]++;
  28. }
  29. return array[0];
  30. }
  31. public int dummy2(int n, int[] array) {
  32. int i = 0;
  33. while (i < n) {
  34. if (array[i] > 0)
  35. break;
  36. if (array[i++] > -1)
  37. continue;
  38. array[0]++;
  39. array[1]++;
  40. }
  41. return array[0];
  42. }
  43. public int dummy3(int n, int[] array) {
  44. int i = 0;
  45. do {
  46. if (array[i] > 0)
  47. break;
  48. if (array[i++] > -1)
  49. continue;
  50. array[0]++;
  51. array[1]++;
  52. } while (i < n);
  53. return array[0];
  54. }
  55. public int dummy4(int n, int[] array) {
  56. int i = 0;
  57. do {
  58. if (array[i] > 0)
  59. if (array[i++] > -1)
  60. continue;
  61. else
  62. return 0;
  63. array[0]++;
  64. array[1]++;
  65. } while (i < n);
  66. return array[0];
  67. }
  68. }