|
13 | 13 | *******************************************************************************/ |
14 | 14 | package org.eclipse.e4.ui.internal.workbench.swt; |
15 | 15 |
|
| 16 | +import java.util.Locale; |
16 | 17 | import org.eclipse.core.runtime.Assert; |
17 | 18 | import org.eclipse.core.runtime.OperationCanceledException; |
18 | 19 | import org.eclipse.core.runtime.jobs.Job; |
@@ -115,24 +116,61 @@ public void testingStarting() { |
115 | 116 | @Override |
116 | 117 | public void runTest(Runnable testRunnable) { |
117 | 118 | Assert.isNotNull(workbench); |
118 | | - display.syncExec( |
119 | | - () -> { |
120 | | - display.addListener(SWT.Dispose, |
121 | | - e -> { |
122 | | - // lambda block to allow breakpoint for debugging |
123 | | - displayCheck = new Exception("Display is disposed"); |
124 | | - }); |
125 | | - |
126 | | - // Run actual test |
127 | | - testRunnable.run(); |
128 | | - |
129 | | - while (display.readAndDispatch()) { |
130 | | - // process all pending tasks |
131 | | - } |
132 | | - |
133 | | - // Display should be still there |
134 | | - checkDisplay(); |
135 | | - }); |
| 119 | + display.syncExec(new TestExecutionRunnable(testRunnable)); |
| 120 | + } |
| 121 | + |
| 122 | + private final class TestExecutionRunnable implements Runnable { |
| 123 | + private final Runnable testRunnable; |
| 124 | + |
| 125 | + private TestExecutionRunnable(Runnable testRunnable) { |
| 126 | + this.testRunnable = testRunnable; |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public void run() { |
| 131 | + display.addListener(SWT.Dispose, |
| 132 | + e -> { |
| 133 | + // lambda block to allow breakpoint for debugging |
| 134 | + displayCheck = new Exception("Display is disposed"); |
| 135 | + }); |
| 136 | + |
| 137 | + try { |
| 138 | + // Run actual test |
| 139 | + testRunnable.run(); |
| 140 | + } catch (OutOfMemoryError e) { |
| 141 | + try { |
| 142 | + e.printStackTrace(System.out); |
| 143 | + printMemoryUse(); |
| 144 | + } finally { |
| 145 | + System.out.println("Calling System.exit() after OutOfMemoryError"); |
| 146 | + System.exit(1); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + while (display.readAndDispatch()) { |
| 151 | + // process all pending tasks |
| 152 | + } |
| 153 | + |
| 154 | + // Display should be still there |
| 155 | + checkDisplay(); |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + private static void printMemoryUse() { |
| 160 | + System.gc(); |
| 161 | + System.runFinalization(); |
| 162 | + System.gc(); |
| 163 | + System.runFinalization(); |
| 164 | + long max = Runtime.getRuntime().maxMemory(); |
| 165 | + long total = Runtime.getRuntime().totalMemory(); |
| 166 | + long free = Runtime.getRuntime().freeMemory(); |
| 167 | + long used = total - free; |
| 168 | + System.out.print("\n########### Memory usage reported by JVM ########"); |
| 169 | + System.out.printf(Locale.GERMAN, "%n%,16d bytes max heap", max); |
| 170 | + System.out.printf(Locale.GERMAN, "%n%,16d bytes heap allocated", total); |
| 171 | + System.out.printf(Locale.GERMAN, "%n%,16d bytes free heap", free); |
| 172 | + System.out.printf(Locale.GERMAN, "%n%,16d bytes used heap", used); |
| 173 | + System.out.println("\n#################################################\n"); |
136 | 174 | } |
137 | 175 |
|
138 | 176 | /** |
|
0 commit comments