mirror of
https://github.com/corda/corda.git
synced 2025-02-04 02:01:13 +00:00
add Thread.getStackTrace test
This commit is contained in:
parent
69501a05b8
commit
69af8a13aa
89
test/Trace.java
Normal file
89
test/Trace.java
Normal file
@ -0,0 +1,89 @@
|
||||
public class Trace implements Runnable {
|
||||
private volatile boolean alive = true;
|
||||
|
||||
private static void throwSomething() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
private void bar(Object o) {
|
||||
o.toString();
|
||||
}
|
||||
|
||||
private void foo() {
|
||||
{ long a = 42;
|
||||
long b = 25;
|
||||
long c = a / b;
|
||||
}
|
||||
|
||||
try {
|
||||
long a = 42;
|
||||
long b = 0;
|
||||
long c = a / b;
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
throw new Exception();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
throwSomething();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
Trace.class.getMethod("bar", Object.class).invoke(this, this);
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
|
||||
private static void dummy() {
|
||||
byte[] a = new byte[10];
|
||||
byte[] b = new byte[10];
|
||||
System.arraycopy(a, 0, b, 0, 10);
|
||||
}
|
||||
|
||||
private static void tail1(int a, int b, int c, int d, int e, int f) {
|
||||
dummy();
|
||||
}
|
||||
|
||||
private static void tail2() {
|
||||
tail1(1, 2, 3, 4, 5, 6);
|
||||
tail1(1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
private static void test(Trace trace) {
|
||||
tail1(1, 2, 3, 4, 5, 6);
|
||||
tail2();
|
||||
trace.foo();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
try {
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
test(this);
|
||||
}
|
||||
} finally {
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Trace trace = new Trace();
|
||||
Thread thread = new Thread(trace);
|
||||
|
||||
synchronized (trace) {
|
||||
thread.start();
|
||||
trace.wait();
|
||||
|
||||
int count = 0;
|
||||
while (trace.alive) {
|
||||
thread.getStackTrace();
|
||||
++ count;
|
||||
}
|
||||
|
||||
System.out.println("got " + count + " traces");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user