|
48 | 48 |
|
49 | 49 | import java.io.File;
|
50 | 50 | import java.io.IOException;
|
51 |
| -import java.lang.ref.ReferenceQueue; |
52 | 51 | import java.lang.ref.WeakReference;
|
53 | 52 | import java.net.URI;
|
54 | 53 | import java.net.URISyntaxException;
|
|
64 | 63 | import java.util.concurrent.TimeUnit;
|
65 | 64 | import java.util.concurrent.atomic.AtomicInteger;
|
66 | 65 |
|
67 |
| -import org.junit.Assume; |
| 66 | +import com.oracle.truffle.api.test.SubprocessTestUtils; |
| 67 | +import org.graalvm.nativeimage.ImageInfo; |
68 | 68 | import org.junit.BeforeClass;
|
69 | 69 | import org.junit.Test;
|
70 | 70 |
|
@@ -218,21 +218,25 @@ public void testUncachedAreNotInterned() {
|
218 | 218 | }
|
219 | 219 |
|
220 | 220 | @Test
|
221 |
| - public void testSourceInterning() { |
222 |
| - Assume.assumeFalse("This test is too slow in fastdebug.", System.getProperty("java.vm.version").contains("fastdebug")); |
223 |
| - |
224 |
| - byte[] bytes = new byte[16 * 1024 * 1024]; |
225 |
| - byte byteValue = (byte) 'a'; |
226 |
| - Arrays.fill(bytes, byteValue); |
227 |
| - String testString = new String(bytes); // big string |
228 |
| - |
229 |
| - ReferenceQueue<Object> queue = new ReferenceQueue<>(); |
230 |
| - List<WeakReference<Object>> sources = new ArrayList<>(); |
231 |
| - for (int i = 0; i < GCUtils.GC_TEST_ITERATIONS; i++) { |
232 |
| - sources.add(new WeakReference<>(createTestSource(testString, i), queue)); |
233 |
| - } |
| 221 | + public void testSourceInterning() throws IOException, InterruptedException { |
| 222 | + Runnable action = () -> { |
| 223 | + byte[] bytes = new byte[16 * 1024 * 1024]; |
| 224 | + byte byteValue = (byte) 'a'; |
| 225 | + Arrays.fill(bytes, byteValue); |
| 226 | + String testString = new String(bytes); // big string |
| 227 | + |
| 228 | + List<WeakReference<Object>> sources = new ArrayList<>(); |
| 229 | + for (int i = 0; i < GCUtils.GC_TEST_ITERATIONS; i++) { |
| 230 | + sources.add(new WeakReference<>(createTestSource(testString, i))); |
| 231 | + } |
234 | 232 |
|
235 |
| - GCUtils.assertGc(testString, sources); |
| 233 | + GCUtils.assertGc("Sources not referenced from a language must be collected", sources); |
| 234 | + }; |
| 235 | + if (ImageInfo.inImageCode()) { |
| 236 | + action.run(); |
| 237 | + } else { |
| 238 | + SubprocessTestUtils.newBuilder(SourceInternalizationTest.class, action).run(); |
| 239 | + } |
236 | 240 | }
|
237 | 241 |
|
238 | 242 | private static Object createTestSource(String testString, int i) {
|
|
0 commit comments