/test/kilim/test/ex/ExBasicBlock.java

http://github.com/kilim/kilim · Java · 75 lines · 67 code · 8 blank · 0 comment · 7 complexity · 7436b354d0968046db237799565a3e62 MD5 · raw file

  1. package kilim.test.ex;
  2. import kilim.Pausable;
  3. import kilim.Task;
  4. public class ExBasicBlock {
  5. void noop() throws ArrayIndexOutOfBoundsException {
  6. }
  7. static void pausable() throws Pausable {
  8. "afakflkaflakd".getBytes();
  9. }
  10. static int testFiber(Object testArgs1, Object[] testArgs) throws Pausable {
  11. Task.getCurrentTask();
  12. int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0;
  13. for (int i = 0; i < g; i++) {
  14. g = a + b + c + d + e + f;
  15. }
  16. return g;
  17. }
  18. int loop() throws Pausable {
  19. int sum = 0;
  20. for (int i = 0; i < 10; i++) {
  21. sum++;
  22. }
  23. return sum;
  24. }
  25. void nestedloop() throws Pausable {
  26. for (int i = 0; i < 100; i++) {
  27. while (i > 10) {
  28. i--;
  29. }
  30. }
  31. }
  32. void exception() throws Pausable {
  33. try {
  34. try {
  35. pausable();
  36. } catch (ArrayIndexOutOfBoundsException e) {
  37. try {
  38. e.printStackTrace();
  39. } catch (Throwable t) {
  40. noop();
  41. }
  42. }
  43. } finally {
  44. noop();
  45. }
  46. }
  47. void complex() throws Pausable {
  48. double d = 10.0;
  49. Object o = new Object();
  50. for (int i = 0; i < 100; i++) {
  51. try {
  52. if (d > 10.3 && d < 10.5) {
  53. d = 20.0;
  54. try {
  55. synchronized(o) {
  56. o.hashCode();
  57. }
  58. } catch (RuntimeException re) {
  59. throw new Error(re.toString());
  60. }
  61. }
  62. } finally {
  63. d = 100.0;
  64. }
  65. }
  66. }
  67. }