getstacktrace.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. public class getstacktrace
  2. extends Thread
  3. {
  4. public boolean done = false;
  5. // num_frames is the number of frames > the original run () call so if
  6. // num_frames = 1, the thread will have 2 frames, the original Thread.run
  7. // call, plus one additional
  8. public int num_frames, thread_num;
  9. public static int num_threads = 1;
  10. static
  11. {
  12. System.loadLibrary("natgetstacktrace");
  13. }
  14. public void run ()
  15. {
  16. thread_num = num_threads++;
  17. num_frames = thread_num;
  18. if (num_frames <= 1)
  19. {
  20. natRunner ();
  21. }
  22. else
  23. {
  24. if (thread_num % 2 == 0)
  25. natPlaceholder ();
  26. else
  27. placeholder ();
  28. }
  29. }
  30. public void placeholder ()
  31. {
  32. num_frames--;
  33. if (num_frames <= 1)
  34. {
  35. if (thread_num % 2 == 1)
  36. natRunner ();
  37. else
  38. runner ();
  39. }
  40. else
  41. {
  42. if (thread_num % 2 == 0)
  43. natPlaceholder ();
  44. else
  45. placeholder ();
  46. }
  47. }
  48. public void runner ()
  49. {
  50. done = true;
  51. while (done)
  52. yield ();
  53. }
  54. public native void natPlaceholder ();
  55. public native void natRunner ();
  56. public static native int do_getstacktrace_tests (Thread[] threads);
  57. public static void main (String[] args)
  58. {
  59. System.out.println ("JVMTI GetStackTrace Interpreted Test");
  60. getstacktrace[] threads = new getstacktrace[10];
  61. for (int i = 0; i < threads.length; i++)
  62. {
  63. threads[i] = new getstacktrace ();
  64. threads[i].start ();
  65. while (!threads[i].done)
  66. yield ();
  67. }
  68. do_getstacktrace_tests (threads);
  69. for (int i = 0; i < threads.length; i++)
  70. {
  71. threads[i].done = false;
  72. }
  73. }
  74. }