|
30 | 30 | * @requires (vm.compMode == "Xmixed") |
31 | 31 | * @run build TestScaffold VMConnection TargetListener TargetAdapter |
32 | 32 | * @run compile -g ThreadMemoryLeakTest.java |
33 | | - * @comment run with -Xmx6m so any leak will quickly produce OOME |
34 | | - * @run main/othervm -Xmx6m ThreadMemoryLeakTest |
| 33 | + * @comment run with -Xmx7m so any leak will quickly produce OOME |
| 34 | + * @run main/othervm -Xmx7m ThreadMemoryLeakTest |
35 | 35 | */ |
36 | 36 | import com.sun.jdi.*; |
37 | 37 | import com.sun.jdi.event.*; |
@@ -95,30 +95,23 @@ public static void main(String[] args) throws Exception { |
95 | 95 |
|
96 | 96 | /********** event handlers **********/ |
97 | 97 |
|
98 | | - static int threadStartCount; |
99 | | - static int threadDeathCount; |
100 | | - private static List<ThreadReference> threads = |
101 | | - Collections.synchronizedList(new ArrayList<ThreadReference>()); |
| 98 | + static LongAdder threadStartCount = new LongAdder(); |
| 99 | + static LongAdder threadDeathCount = new LongAdder(); |
102 | 100 |
|
103 | 101 | public void threadStarted(ThreadStartEvent event) { |
104 | | - threadStartCount++; |
105 | | - if ((threadStartCount % 1000) == 0) { |
| 102 | + threadStartCount.increment(); |
| 103 | + if ((threadStartCount.sum() % 1000) == 0) { |
106 | 104 | println("Got ThreadStartEvent #" + threadStartCount + |
107 | | - " threads:" + threads.size()); |
| 105 | + " threads:" + (threadStartCount.sum() - threadDeathCount.sum())); |
108 | 106 | } |
109 | | - ThreadStartEvent tse = (ThreadStartEvent)event; |
110 | | - threads.add(tse.thread()); |
111 | 107 | } |
112 | 108 |
|
113 | 109 | public void threadDied(ThreadDeathEvent event) { |
114 | | - threadDeathCount++; |
115 | | - if ((threadDeathCount % 1000) == 0) { |
| 110 | + threadDeathCount.increment(); |
| 111 | + if ((threadDeathCount.sum() % 1000) == 0) { |
116 | 112 | println("Got ThreadDeathEvent #" + threadDeathCount + |
117 | | - " threads:" + threads.size()); |
| 113 | + " threads:" + (threadStartCount.sum() - threadDeathCount.sum())); |
118 | 114 | } |
119 | | - ThreadDeathEvent tde = (ThreadDeathEvent)event; |
120 | | - ThreadReference thread = tde.thread(); |
121 | | - threads.remove(thread); |
122 | 115 | } |
123 | 116 |
|
124 | 117 | public void vmDied(VMDeathEvent event) { |
|
0 commit comments