< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.java

Print this page

 98 import java.io.PrintStream;
 99 
100 /**
101  * The test check up <code>java.lang.Thread.getStackTrace()</code> method for many threads,
102  * that recursively invoke a native method in running mode ("alive" stack).
103  * <p>
104  * <p>The test creates <code>THRD_COUNT</code> instances of <code>strace003Thread</code>
105  * class, tries to get their stack traces and checks up that returned array contains
106  * correct stack frames. Each stack frame must be corresponded to one of the following
107  * methods defined by the <code>EXPECTED_METHODS</code> array.</p>
108  * <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>
109  */
110 public class strace003 {
111 
112     static final int DEPTH = 100;
113     static final int THRD_COUNT = 100;
114     static final int REPEAT_COUNT = 10;
115     static final String[] EXPECTED_METHODS = {
116             "java.lang.System.arraycopy",
117             "java.lang.Object.wait",



118             "java.lang.Thread.exit",
119             "java.lang.Thread.yield",







120             "java.lang.ThreadGroup.remove",
121             "java.lang.ThreadGroup.threadTerminated",


122             "nsk.stress.strace.strace003Thread.run",
123             "nsk.stress.strace.strace003Thread.recursiveMethod"
124     };
125 
126 
127     static volatile boolean isLocked = false;
128     static PrintStream out;
129     static long waitTime = 2;
130 
131     static Object waitStart = new Object();
132 
133     static strace003Thread[] threads;
134     static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];
135     static Log log;
136 
137     volatile int achivedCount = 0;
138 
139     public static void main(String[] args) {
140         out = System.out;
141         int exitCode = run(args);

249                             + elements[j].getMethodName());
250                     complain("\tat " + j + " position");
251                     if (elements[j].isNativeMethod()) {
252                         complain("\tline number: (native method)");
253                         complain("\tclass name: " + elements[j].getClassName());
254                     } else {
255                         complain("\tline number: " + elements[j].getLineNumber());
256                         complain("\tclass name: " + elements[j].getClassName());
257                         complain("\tfile name: " + elements[j].getFileName());
258                     }
259                     res = false;
260                 }
261             }
262         }
263         return res;
264     }
265 
266     boolean checkElement(StackTraceElement element) {
267         String name = element.getClassName() + "." + element.getMethodName();
268         for (int i = 0; i < EXPECTED_METHODS.length; i++) {
269             if (EXPECTED_METHODS[i].compareTo(name) == 0)
270                 return true;
271         }
272         return false;
273     }
274 
275     void finishThreads() {
276         try {
277             for (int i = 0; i < threads.length; i++) {
278                 if (threads[i].isAlive())
279                     threads[i].join(waitTime / THRD_COUNT);
280             }
281         } catch (InterruptedException e) {
282             complain("" + e);
283         }
284         isLocked = false;
285     }
286 
287     static void display(String message) {
288         log.display(message);
289     }

 98 import java.io.PrintStream;
 99 
100 /**
101  * The test check up <code>java.lang.Thread.getStackTrace()</code> method for many threads,
102  * that recursively invoke a native method in running mode ("alive" stack).
103  * <p>
104  * <p>The test creates <code>THRD_COUNT</code> instances of <code>strace003Thread</code>
105  * class, tries to get their stack traces and checks up that returned array contains
106  * correct stack frames. Each stack frame must be corresponded to one of the following
107  * methods defined by the <code>EXPECTED_METHODS</code> array.</p>
108  * <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>
109  */
110 public class strace003 {
111 
112     static final int DEPTH = 100;
113     static final int THRD_COUNT = 100;
114     static final int REPEAT_COUNT = 10;
115     static final String[] EXPECTED_METHODS = {
116             "java.lang.System.arraycopy",
117             "java.lang.Object.wait",
118             "java.lang.Object.wait0",
119             "java.lang.System$2.headStackableScope",
120             "java.lang.Thread.headStackableScopes",
121             "java.lang.Thread.exit",
122             "java.lang.Thread.yield",
123             "java.lang.Thread.yield0",
124             "java.lang.Thread.clearReferences",
125             "java.lang.Thread.getVirtualThread",
126             "java.lang.Thread.currentCarrierThread",
127             "java.lang.Thread.currentThread",
128             "java.lang.Thread.currentThread0",
129             "java.lang.Thread.threadContainer",
130             "java.lang.ThreadGroup.remove",
131             "java.lang.ThreadGroup.threadTerminated",
132             "jdk.internal.vm.StackableScope.head",
133             "jdk.internal.vm.StackableScope.popAll",
134             "nsk.stress.strace.strace003Thread.run",
135             "nsk.stress.strace.strace003Thread.recursiveMethod"
136     };
137 
138 
139     static volatile boolean isLocked = false;
140     static PrintStream out;
141     static long waitTime = 2;
142 
143     static Object waitStart = new Object();
144 
145     static strace003Thread[] threads;
146     static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];
147     static Log log;
148 
149     volatile int achivedCount = 0;
150 
151     public static void main(String[] args) {
152         out = System.out;
153         int exitCode = run(args);

261                             + elements[j].getMethodName());
262                     complain("\tat " + j + " position");
263                     if (elements[j].isNativeMethod()) {
264                         complain("\tline number: (native method)");
265                         complain("\tclass name: " + elements[j].getClassName());
266                     } else {
267                         complain("\tline number: " + elements[j].getLineNumber());
268                         complain("\tclass name: " + elements[j].getClassName());
269                         complain("\tfile name: " + elements[j].getFileName());
270                     }
271                     res = false;
272                 }
273             }
274         }
275         return res;
276     }
277 
278     boolean checkElement(StackTraceElement element) {
279         String name = element.getClassName() + "." + element.getMethodName();
280         for (int i = 0; i < EXPECTED_METHODS.length; i++) {
281             if (name.startsWith(EXPECTED_METHODS[i]))
282                 return true;
283         }
284         return false;
285     }
286 
287     void finishThreads() {
288         try {
289             for (int i = 0; i < threads.length; i++) {
290                 if (threads[i].isAlive())
291                     threads[i].join(waitTime / THRD_COUNT);
292             }
293         } catch (InterruptedException e) {
294             complain("" + e);
295         }
296         isLocked = false;
297     }
298 
299     static void display(String message) {
300         log.display(message);
301     }
< prev index next >