summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.jvmti/interp/getstacktrace.java
blob: 21a21f0fbb10765e67757e276adf22b12419434e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
public class getstacktrace
  extends Thread
{
  public boolean done = false;

  // num_frames is the number of frames > the original run () call so if
  // num_frames = 1, the thread will have 2 frames, the original Thread.run
  // call, plus one additional
  public int num_frames, thread_num;

  public static int num_threads = 1;

  static
    {
      System.loadLibrary("natgetstacktrace");
    }

  public void run ()
  {
    thread_num = num_threads++;
    num_frames = thread_num;

    if (num_frames <= 1)
      {
        natRunner ();
      }
    else
      {
        if (thread_num % 2 == 0)
          natPlaceholder ();
        else
          placeholder ();
      }
  }

  public void placeholder ()
  {
    num_frames--;
    if (num_frames <= 1)
      {
        if (thread_num % 2 == 1)
          natRunner ();
        else
          runner ();
      }
    else
      {
        if (thread_num % 2 == 0)
          natPlaceholder ();
        else
          placeholder ();
      }
  }
  
  public void runner ()
  {
    done = true;
    while (done)
      yield ();
  }

  public native void natPlaceholder ();
  public native void natRunner ();

  public static native int do_getstacktrace_tests (Thread[] threads);

  public static void main (String[] args)
  {
    System.out.println ("JVMTI GetStackTrace Interpreted Test");

    getstacktrace[] threads = new getstacktrace[10];

    for (int i = 0; i < threads.length; i++)
      {
        threads[i] = new getstacktrace ();
        threads[i].start ();
        while (!threads[i].done)
          yield ();
      }

    do_getstacktrace_tests (threads);

    for (int i = 0; i < threads.length; i++)
      {
        threads[i].done = false;
      }
  }
}