getallthreads.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Test JVMTI GetAllThreads
  2. import java.util.ArrayList;
  3. public class getallthreads extends Thread
  4. {
  5. public static int thread_num;
  6. public static ArrayList threads;
  7. public int ex_frames;
  8. public boolean done = false;
  9. public static native void do_getallthreads_tests ();
  10. public void run ()
  11. {
  12. ex_frames = thread_num;
  13. thread_num++;
  14. if (ex_frames > 0)
  15. {
  16. if ((ex_frames % 2) == 0)
  17. placeholder ();
  18. else
  19. natPlaceholder ();
  20. }
  21. else
  22. runner ();
  23. }
  24. public native void natPlaceholder ();
  25. public native void natRunner ();
  26. public void placeholder ()
  27. {
  28. ex_frames--;
  29. if (ex_frames > 0)
  30. {
  31. if ((thread_num % 2) == 0)
  32. placeholder ();
  33. else
  34. natPlaceholder ();
  35. }
  36. else
  37. runner ();
  38. }
  39. public void runner ()
  40. {
  41. done = true;
  42. while (done)
  43. yield ();
  44. }
  45. public static void main (String[] args)
  46. {
  47. System.out.println ("JVMTI GetAllThreads tests");
  48. threads = new ArrayList (20);
  49. getallthreads t;
  50. for (int i = 0; i < 20; i++)
  51. {
  52. t = new getallthreads ();
  53. threads.add (t);
  54. t.start ();
  55. while (!t.done)
  56. yield ();
  57. }
  58. do_getallthreads_tests ();
  59. for (int i = 0; i < 20; i++)
  60. {
  61. t = (getallthreads) threads.get(i);
  62. t.done = false;
  63. }
  64. }
  65. }