< prev index next >

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

Print this page

 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         Thread.sleep(100);


 78 
 79         // this is too fragile, implementation can change at any time.
 80         checkFrames(vThread1, false, 14);
 81         LockSupport.unpark(vThread1);
 82         vThread1.join();
 83 
 84         // Test GetFrameCount on live platform thread
 85         Thread pThread = Thread.ofPlatform().name("PlatformThread-Live").start(() -> {
 86             checkFrames(Thread.currentThread(), false, 5);
 87         });
 88         pThread.join();
 89 
 90         // Test GetFrameCount on parked platform thread
 91         Thread pThread1 = Thread.ofPlatform().name("PlatformThread-Parked").start(() -> {
 92                 pThread1Started = true;
 93                 LockSupport.park();
 94         });
 95         while (!pThread1Started) {
 96             Thread.sleep(1);
 97         }
 98         Thread.sleep(10);



 99         checkFrames(pThread1, false, 5);
100         LockSupport.unpark(pThread1);
101         pThread1.join();
102 
103 
104         // Test GetFrameCount on some depth stack fixed by sync
105         FixedDepthThread.checkFrameCount(0);
106         FixedDepthThread.checkFrameCount(500);
107     }
108 }
109 
110 class FixedDepthThread implements Runnable {
111     int depth;
112     Object startedFlag;
113     Object checkFlag;
114     Thread thread;
115 
116     // Each stack has 2 frames additional to expected depth
117     // 0: FixedDepthThread: run()V
118     // 1: java/lang/Thread: run()V

 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
< prev index next >