< prev index next >

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

Print this page

 55 import java.io.PrintStream;
 56 import java.util.Map;
 57 
 58 /**
 59  * The test runs <code>THRD_COUNT</code> instances of <code>strace011Thread</code>,
 60  * that recursively invoke a native method. After arriving at defined depth
 61  * <code>DEPTH</code> of recursion, each thread is blocked on entering a monitor.
 62  * Then the test calls <code>java.lang.Thread.getStackTrace()</code> and
 63  * <code>java.lang.Thread.getAllStackTraces()</code> methods and checks their results.
 64  * <p>
 65  * <p>It is expected that these methods return the same stack traces. Each stack frame
 66  * for both stack traces must be corresponded to invocation of one of the methods
 67  * defined by the <code>EXPECTED_METHODS</code> array.</p>
 68  */
 69 public class strace011 {
 70 
 71     static final int DEPTH = 100;
 72     static final int THRD_COUNT = 50;
 73     static final String[] EXPECTED_METHODS = {
 74             "java.lang.Thread.sleep",









 75             "nsk.stress.strace.strace011Thread.run",
 76             "nsk.stress.strace.strace011Thread.recursiveMethod"
 77     };
 78 
 79 
 80     static PrintStream out;
 81     static long waitTime = 2;
 82 
 83     public static Object lockedObject = new Object();
 84     static volatile boolean isLocked = false;
 85 
 86     static volatile int achivedCount = 0;
 87     strace011Thread[] threads;
 88     static Log log;
 89 
 90     public static void main(String[] args) {
 91         out = System.out;
 92         int exitCode = run(args);
 93         System.exit(exitCode + 95);
 94     }

210             if (!checkElement(threadSnap[j])) {
211                 complain("Unexpected " + j + "-element:");
212                 complain("\tmethod name: " + threadSnap[j].getMethodName());
213                 complain("\tclass name: " + threadSnap[j].getClassName());
214                 if (threadSnap[j].isNativeMethod()) {
215                     complain("\tline number: (native method)");
216                 } else {
217                     complain("\tline number: " + threadSnap[j].getLineNumber());
218                     complain("\tfile name: " + threadSnap[j].getFileName());
219                 }
220                 complain("");
221                 res = false;
222             }
223         }
224         return res;
225     }
226 
227     boolean checkElement(StackTraceElement element) {
228         String name = element.getClassName() + "." + element.getMethodName();
229         for (int i = 0; i < EXPECTED_METHODS.length; i++) {
230             if (EXPECTED_METHODS[i].compareTo(name) == 0)
231                 return true;
232         }
233         return false;
234     }
235 
236     void finishThreads() {
237         try {
238             for (int i = 0; i < threads.length; i++) {
239                 if (threads[i].isAlive()) {
240                     display("waiting for finish " + threads[i].getName());
241                     threads[i].join(waitTime);
242                 }
243             }
244         } catch (InterruptedException e) {
245             complain("" + e);
246         }
247         isLocked = false;
248     }
249 
250     static void display(String message) {

 55 import java.io.PrintStream;
 56 import java.util.Map;
 57 
 58 /**
 59  * The test runs <code>THRD_COUNT</code> instances of <code>strace011Thread</code>,
 60  * that recursively invoke a native method. After arriving at defined depth
 61  * <code>DEPTH</code> of recursion, each thread is blocked on entering a monitor.
 62  * Then the test calls <code>java.lang.Thread.getStackTrace()</code> and
 63  * <code>java.lang.Thread.getAllStackTraces()</code> methods and checks their results.
 64  * <p>
 65  * <p>It is expected that these methods return the same stack traces. Each stack frame
 66  * for both stack traces must be corresponded to invocation of one of the methods
 67  * defined by the <code>EXPECTED_METHODS</code> array.</p>
 68  */
 69 public class strace011 {
 70 
 71     static final int DEPTH = 100;
 72     static final int THRD_COUNT = 50;
 73     static final String[] EXPECTED_METHODS = {
 74             "java.lang.Thread.sleep",
 75             "java.lang.Thread.sleep0",
 76             "java.lang.Thread.getVirtualThread",
 77             "jdk.internal.event.ThreadSleepEvent.<clinit>",
 78             "jdk.internal.event.ThreadSleepEvent.isTurnedOn",
 79             "jdk.internal.event.ThreadSleepEvent.isEnabled",
 80             "java.lang.Thread.sleepMillis",
 81             "java.lang.Thread.currentCarrierThread",
 82             "java.lang.Thread.currentThread",
 83             "java.lang.Thread.currentThread0",
 84             "nsk.stress.strace.strace011Thread.run",
 85             "nsk.stress.strace.strace011Thread.recursiveMethod"
 86     };
 87 
 88 
 89     static PrintStream out;
 90     static long waitTime = 2;
 91 
 92     public static Object lockedObject = new Object();
 93     static volatile boolean isLocked = false;
 94 
 95     static volatile int achivedCount = 0;
 96     strace011Thread[] threads;
 97     static Log log;
 98 
 99     public static void main(String[] args) {
100         out = System.out;
101         int exitCode = run(args);
102         System.exit(exitCode + 95);
103     }

219             if (!checkElement(threadSnap[j])) {
220                 complain("Unexpected " + j + "-element:");
221                 complain("\tmethod name: " + threadSnap[j].getMethodName());
222                 complain("\tclass name: " + threadSnap[j].getClassName());
223                 if (threadSnap[j].isNativeMethod()) {
224                     complain("\tline number: (native method)");
225                 } else {
226                     complain("\tline number: " + threadSnap[j].getLineNumber());
227                     complain("\tfile name: " + threadSnap[j].getFileName());
228                 }
229                 complain("");
230                 res = false;
231             }
232         }
233         return res;
234     }
235 
236     boolean checkElement(StackTraceElement element) {
237         String name = element.getClassName() + "." + element.getMethodName();
238         for (int i = 0; i < EXPECTED_METHODS.length; i++) {
239             if (name.startsWith(EXPECTED_METHODS[i]))
240                 return true;
241         }
242         return false;
243     }
244 
245     void finishThreads() {
246         try {
247             for (int i = 0; i < threads.length; i++) {
248                 if (threads[i].isAlive()) {
249                     display("waiting for finish " + threads[i].getName());
250                     threads[i].join(waitTime);
251                 }
252             }
253         } catch (InterruptedException e) {
254             complain("" + e);
255         }
256         isLocked = false;
257     }
258 
259     static void display(String message) {
< prev index next >