< prev index next >

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

Print this page

 59 
 60 /**
 61  * The test runs <code>THRD_COUNT</code> instances of <code>strace008Thread</code>,
 62  * that recursively invoke a native method. After arriving at defined depth
 63  * <code>DEPTH</code> of recursion, the test calls
 64  * <code>java.lang.Thread.getStackTrace()</code> and
 65  * <code>java.lang.Thread.getAllStackTraces()</code> methods and checks their results.
 66  * <p>
 67  * It is expected that these methods return the same stack traces. Each stack frame
 68  * for both stack traces must be corresponded to invocation of one of the methods
 69  * defined by the <code>EXPECTED_METHODS</code> array.</p>
 70  */
 71 public class strace008 {
 72 
 73     static final int DEPTH = 100;
 74     static final int THRD_COUNT = 50;
 75     static final int SLEEP_TIME = 50;
 76     static final String NATIVE_LIB = "strace008";
 77     static final String[] EXPECTED_METHODS = {
 78             "java.lang.Thread.sleep",









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

143         }
144     }
145 
146     static boolean makeSnapshot() {
147 
148         display("making all threads snapshots...");
149         Map traces = Thread.getAllStackTraces();
150         int count = ((StackTraceElement[]) traces.get(threads[0])).length;
151 
152         display("making snapshots of each thread...");
153         StackTraceElement[][] elements = new StackTraceElement[THRD_COUNT][];
154         for (int i = 0; i < THRD_COUNT; i++) {
155             elements[i] = threads[i].getStackTrace();
156         }
157 
158         display("checking lengths of stack traces...");
159         StackTraceElement[] all;
160         for (int i = 1; i < THRD_COUNT; i++) {
161             all = (StackTraceElement[]) traces.get(threads[i]);
162             int k = all.length;
163             if (count - k > 2) {
164                 complain("wrong lengths of stack traces:\n\t"
165                         + threads[0].getName() + ": " + count
166                         + "\t"
167                         + threads[i].getName() + ": " + k);
168                 return false;
169             }
170         }
171 
172         display("checking stack traces...");
173         boolean res = true;
174         for (int i = 0; i < THRD_COUNT; i++) {
175             all = (StackTraceElement[]) traces.get(threads[i]);
176             if (!checkTraces(threads[i].getName(), elements[i], all)) {
177                 res = false;
178             }
179         }
180         return res;
181     }
182 
183     static boolean checkTraces(String threadName, StackTraceElement[] threadSnap,

191             if (!checkElement(threadSnap[j])) {
192                 complain("Unexpected " + j + "-element:");
193                 complain("\tmethod name: " + threadSnap[j].getMethodName());
194                 complain("\tclass name: " + threadSnap[j].getClassName());
195                 if (threadSnap[j].isNativeMethod()) {
196                     complain("\tline number: (native method)");
197                 } else {
198                     complain("\tline number: " + threadSnap[j].getLineNumber());
199                     complain("\tfile name: " + threadSnap[j].getFileName());
200                 }
201                 complain("");
202                 res = false;
203             }
204         }
205         return res;
206     }
207 
208     static boolean checkElement(StackTraceElement element) {
209         String name = element.getClassName() + "." + element.getMethodName();
210         for (int i = 0; i < EXPECTED_METHODS.length; i++) {
211             if (EXPECTED_METHODS[i].compareTo(name) == 0)
212                 return true;
213         }
214         return false;
215     }
216 
217     static void finishThreads() {
218         isSnapshotDone = true;
219 /*        try {
220             for (int i=0; i<threads.length; i++) {
221                 if (threads[i].isAlive()) {
222                     display("waiting for finish " + threads[i].getName());
223                     threads[i].join(waitTime);
224                 }
225             }
226         } catch (InterruptedException e) {
227             display(e);
228         }
229  */
230         isSnapshotDone = false;
231     }

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

152         }
153     }
154 
155     static boolean makeSnapshot() {
156 
157         display("making all threads snapshots...");
158         Map traces = Thread.getAllStackTraces();
159         int count = ((StackTraceElement[]) traces.get(threads[0])).length;
160 
161         display("making snapshots of each thread...");
162         StackTraceElement[][] elements = new StackTraceElement[THRD_COUNT][];
163         for (int i = 0; i < THRD_COUNT; i++) {
164             elements[i] = threads[i].getStackTrace();
165         }
166 
167         display("checking lengths of stack traces...");
168         StackTraceElement[] all;
169         for (int i = 1; i < THRD_COUNT; i++) {
170             all = (StackTraceElement[]) traces.get(threads[i]);
171             int k = all.length;
172             if (count - k > 4) {
173                 complain("wrong lengths of stack traces:\n\t"
174                         + threads[0].getName() + ": " + count
175                         + "\t"
176                         + threads[i].getName() + ": " + k);
177                 return false;
178             }
179         }
180 
181         display("checking stack traces...");
182         boolean res = true;
183         for (int i = 0; i < THRD_COUNT; i++) {
184             all = (StackTraceElement[]) traces.get(threads[i]);
185             if (!checkTraces(threads[i].getName(), elements[i], all)) {
186                 res = false;
187             }
188         }
189         return res;
190     }
191 
192     static boolean checkTraces(String threadName, StackTraceElement[] threadSnap,

200             if (!checkElement(threadSnap[j])) {
201                 complain("Unexpected " + j + "-element:");
202                 complain("\tmethod name: " + threadSnap[j].getMethodName());
203                 complain("\tclass name: " + threadSnap[j].getClassName());
204                 if (threadSnap[j].isNativeMethod()) {
205                     complain("\tline number: (native method)");
206                 } else {
207                     complain("\tline number: " + threadSnap[j].getLineNumber());
208                     complain("\tfile name: " + threadSnap[j].getFileName());
209                 }
210                 complain("");
211                 res = false;
212             }
213         }
214         return res;
215     }
216 
217     static boolean checkElement(StackTraceElement element) {
218         String name = element.getClassName() + "." + element.getMethodName();
219         for (int i = 0; i < EXPECTED_METHODS.length; i++) {
220             if (name.startsWith(EXPECTED_METHODS[i]))
221                 return true;
222         }
223         return false;
224     }
225 
226     static void finishThreads() {
227         isSnapshotDone = true;
228 /*        try {
229             for (int i=0; i<threads.length; i++) {
230                 if (threads[i].isAlive()) {
231                     display("waiting for finish " + threads[i].getName());
232                     threads[i].join(waitTime);
233                 }
234             }
235         } catch (InterruptedException e) {
236             display(e);
237         }
238  */
239         isSnapshotDone = false;
240     }
< prev index next >