< prev index next >

test/hotspot/jtreg/serviceability/jvmti/thread/GetFrameCount/framecnt01/framecnt01.java

Print this page

 44 public class framecnt01 {
 45 
 46     native static boolean checkFrames0(Thread thread, boolean shouldSuspend, int expected);
 47 
 48     static void checkFrames(Thread thread, boolean shouldSuspend, int expected) {
 49         if(!checkFrames0(thread, shouldSuspend, expected)) {
 50             throw new RuntimeException("Check failed for " + thread + " " + shouldSuspend + " " + expected);
 51         }
 52     }
 53 
 54     static {
 55         System.loadLibrary("framecnt01");
 56     }
 57     static volatile boolean vThread1Started = false;
 58     static volatile boolean pThread1Started = false;
 59 
 60     public static void main(String args[]) throws Exception {
 61 
 62         // Test GetFrameCount on virtual live thread
 63         Thread vThread = Thread.ofVirtual().name("VirtualThread-Live").start(() -> {
 64            checkFrames(Thread.currentThread(), false, 9);
 65         });
 66         vThread.join();
 67 
 68         // Test GetFrameCount on virtual frozen thread
 69         Thread vThread1 = Thread.ofVirtual().name("VirtualThread-Frozen").start(() -> {
 70             vThread1Started = true;
 71             LockSupport.park();
 72         });
 73         while (!vThread1Started) {
 74             Thread.sleep(1);
 75         }
 76         // Let vthread1 to park
 77         while(vThread1.getState() != Thread.State.WAITING) {
 78             Thread.sleep(1);
 79         }
 80 
 81         // this is too fragile, implementation can change at any time.
 82         checkFrames(vThread1, false, 14);
 83         LockSupport.unpark(vThread1);
 84         vThread1.join();
 85 
 86         // Test GetFrameCount on live platform thread
 87         Thread pThread = Thread.ofPlatform().name("PlatformThread-Live").start(() -> {
 88             checkFrames(Thread.currentThread(), false, 5);
 89         });
 90         pThread.join();
 91 
 92         // Test GetFrameCount on parked platform thread
 93         Thread pThread1 = Thread.ofPlatform().name("PlatformThread-Parked").start(() -> {
 94                 pThread1Started = true;
 95                 LockSupport.park();
 96         });
 97         while (!pThread1Started) {
 98             Thread.sleep(1);
 99         }
100 
101         while(pThread1.getState() != Thread.State.WAITING) {
102             Thread.sleep(1);
103         }
104         checkFrames(pThread1, false, 5);
105         LockSupport.unpark(pThread1);
106         pThread1.join();
107 
108 
109         // Test GetFrameCount on some depth stack fixed by sync
110         FixedDepthThread.checkFrameCount(0);
111         FixedDepthThread.checkFrameCount(500);
112     }
113 }
114 
115 class FixedDepthThread implements Runnable {
116     int depth;
117     Object startedFlag;
118     Object checkFlag;
119     Thread thread;
120 
121     // Each stack has 2 frames additional to expected depth
122     // 0: FixedDepthThread: run()V
123     // 1: java/lang/Thread: run()V
124     static final int ADDITIONAL_STACK_COUNT = 2;

125 
126     private FixedDepthThread(String name, int depth, Object checkFlag) {
127         this.thread = Thread.ofPlatform().name(name).unstarted(this);
128         this.depth = depth;
129         this.startedFlag = new Object();
130         this.checkFlag = checkFlag;
131     }
132 
133     private void startAndWait() {
134         synchronized(startedFlag) {
135             thread.start();
136             try {
137                 startedFlag.wait();
138 
139             } catch(InterruptedException e) {}
140 
141         }
142     }
143 
144     public void run() {

 44 public class framecnt01 {
 45 
 46     native static boolean checkFrames0(Thread thread, boolean shouldSuspend, int expected);
 47 
 48     static void checkFrames(Thread thread, boolean shouldSuspend, int expected) {
 49         if(!checkFrames0(thread, shouldSuspend, expected)) {
 50             throw new RuntimeException("Check failed for " + thread + " " + shouldSuspend + " " + expected);
 51         }
 52     }
 53 
 54     static {
 55         System.loadLibrary("framecnt01");
 56     }
 57     static volatile boolean vThread1Started = false;
 58     static volatile boolean pThread1Started = false;
 59 
 60     public static void main(String args[]) throws Exception {
 61 
 62         // Test GetFrameCount on virtual live thread
 63         Thread vThread = Thread.ofVirtual().name("VirtualThread-Live").start(() -> {
 64            checkFrames(Thread.currentThread(), false, 10);
 65         });
 66         vThread.join();
 67 
 68         // Test GetFrameCount on virtual frozen thread
 69         Thread vThread1 = Thread.ofVirtual().name("VirtualThread-Frozen").start(() -> {
 70             vThread1Started = true;
 71             LockSupport.park();
 72         });
 73         while (!vThread1Started) {
 74             Thread.sleep(1);
 75         }
 76         // Let vthread1 to park
 77         while(vThread1.getState() != Thread.State.WAITING) {
 78             Thread.sleep(1);
 79         }
 80 
 81         // this is too fragile, implementation can change at any time.
 82         checkFrames(vThread1, false, 15);
 83         LockSupport.unpark(vThread1);
 84         vThread1.join();
 85 
 86         // Test GetFrameCount on live platform thread
 87         Thread pThread = Thread.ofPlatform().name("PlatformThread-Live").start(() -> {
 88             checkFrames(Thread.currentThread(), false, 6);
 89         });
 90         pThread.join();
 91 
 92         // Test GetFrameCount on parked platform thread
 93         Thread pThread1 = Thread.ofPlatform().name("PlatformThread-Parked").start(() -> {
 94                 pThread1Started = true;
 95                 LockSupport.park();
 96         });
 97         while (!pThread1Started) {
 98             Thread.sleep(1);
 99         }
100 
101         while(pThread1.getState() != Thread.State.WAITING) {
102             Thread.sleep(1);
103         }
104         checkFrames(pThread1, false, 6);
105         LockSupport.unpark(pThread1);
106         pThread1.join();
107 
108 
109         // Test GetFrameCount on some depth stack fixed by sync
110         FixedDepthThread.checkFrameCount(0);
111         FixedDepthThread.checkFrameCount(500);
112     }
113 }
114 
115 class FixedDepthThread implements Runnable {
116     int depth;
117     Object startedFlag;
118     Object checkFlag;
119     Thread thread;
120 
121     // Each stack has 3 frames additional to expected depth
122     // 0: FixedDepthThread: run()V
123     // 1: java/lang/Thread: run()V
124     // 2: java/lang/Thread: runWith()V
125     static final int ADDITIONAL_STACK_COUNT = 3;
126 
127     private FixedDepthThread(String name, int depth, Object checkFlag) {
128         this.thread = Thread.ofPlatform().name(name).unstarted(this);
129         this.depth = depth;
130         this.startedFlag = new Object();
131         this.checkFlag = checkFlag;
132     }
133 
134     private void startAndWait() {
135         synchronized(startedFlag) {
136             thread.start();
137             try {
138                 startedFlag.wait();
139 
140             } catch(InterruptedException e) {}
141 
142         }
143     }
144 
145     public void run() {
< prev index next >