Skip to content

Commit 67dcf2b

Browse files
committed
[GR-71295] Build/UnitTest Job Failure: Timeout/Thread Block Detected in Truffle Suite.
PullRequest: graal/22701
2 parents cce08d2 + b9f9f82 commit 67dcf2b

File tree

7 files changed

+362
-253
lines changed

7 files changed

+362
-253
lines changed

truffle/src/com.oracle.truffle.api.debug.test/src/com/oracle/truffle/api/debug/test/DebuggerSessionTest.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
import java.util.zip.ZipEntry;
6464
import java.util.zip.ZipOutputStream;
6565

66+
import com.oracle.truffle.api.test.SubprocessTestUtils;
6667
import org.graalvm.collections.Pair;
68+
import org.graalvm.nativeimage.ImageInfo;
6769
import org.graalvm.polyglot.Context;
6870
import org.graalvm.polyglot.Engine;
6971
import org.graalvm.polyglot.Instrument;
@@ -1010,27 +1012,43 @@ private static void checkResolvedSourceSection(SourceSection sourceSection, int
10101012
}
10111013

10121014
@Test
1013-
public void testDebuggedSourcesCanBeReleasedAbsolute() {
1014-
testDebuggedSourcesCanBeReleased(() -> {
1015-
return Source.newBuilder(InstrumentationTestLanguage.ID, "STATEMENT", "file").cached(false).buildLiteral();
1015+
public void testDebuggedSourcesCanBeReleasedAbsolute() throws IOException, InterruptedException {
1016+
runInSubprocess(() -> {
1017+
testDebuggedSourcesCanBeReleased(() -> {
1018+
return Source.newBuilder(InstrumentationTestLanguage.ID, "STATEMENT", "file").cached(false).buildLiteral();
1019+
});
10161020
});
10171021
}
10181022

10191023
@Test
1020-
public void testDebuggedSourcesCanBeReleasedRelative() throws IOException {
1021-
String sourceContent = "\n relative source\nVarA";
1022-
String relativePath = "relative/test.file";
1023-
Path testSourcePath = Files.createTempDirectory("testPath").toRealPath();
1024-
Files.createDirectory(testSourcePath.resolve("relative"));
1025-
Path filePath = testSourcePath.resolve(relativePath);
1026-
Files.write(filePath, sourceContent.getBytes());
1027-
testDebuggedSourcesCanBeReleased(() -> {
1028-
TestDebugNoContentLanguage language = new TestDebugNoContentLanguage(relativePath, true, true);
1029-
ProxyLanguage.setDelegate(language);
1030-
return Source.newBuilder(ProxyLanguage.ID, sourceContent, "file").cached(false).buildLiteral();
1024+
public void testDebuggedSourcesCanBeReleasedRelative() throws IOException, InterruptedException {
1025+
runInSubprocess(() -> {
1026+
String sourceContent = "\n relative source\nVarA";
1027+
String relativePath = "relative/test.file";
1028+
try {
1029+
Path testSourcePath = Files.createTempDirectory("testPath").toRealPath();
1030+
Files.createDirectory(testSourcePath.resolve("relative"));
1031+
Path filePath = testSourcePath.resolve(relativePath);
1032+
Files.write(filePath, sourceContent.getBytes());
1033+
} catch (IOException ioe) {
1034+
throw new AssertionError(ioe);
1035+
}
1036+
testDebuggedSourcesCanBeReleased(() -> {
1037+
TestDebugNoContentLanguage language = new TestDebugNoContentLanguage(relativePath, true, true);
1038+
ProxyLanguage.setDelegate(language);
1039+
return Source.newBuilder(ProxyLanguage.ID, sourceContent, "file").cached(false).buildLiteral();
1040+
});
10311041
});
10321042
}
10331043

1044+
private static void runInSubprocess(Runnable runnable) throws IOException, InterruptedException {
1045+
if (ImageInfo.inImageCode()) {
1046+
runnable.run();
1047+
} else {
1048+
SubprocessTestUtils.newBuilder(DebuggerSessionTest.class, runnable).run();
1049+
}
1050+
}
1051+
10341052
private void testDebuggedSourcesCanBeReleased(Supplier<Source> sourceFactory) {
10351053
try (DebuggerSession session = tester.startSession()) {
10361054
GCUtils.assertObjectsCollectible(iteration -> {

truffle/src/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/WeakCachedTest.java

Lines changed: 99 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@
4242

4343
import static org.junit.Assert.assertNotNull;
4444

45+
import java.io.IOException;
4546
import java.lang.ref.WeakReference;
4647
import java.util.List;
4748
import java.util.concurrent.Semaphore;
4849

50+
import com.oracle.truffle.api.test.SubprocessTestUtils;
51+
import org.graalvm.nativeimage.ImageInfo;
4952
import org.junit.Test;
5053

5154
import com.oracle.truffle.api.CompilerDirectives;
@@ -73,13 +76,23 @@
7376
public class WeakCachedTest extends AbstractPolyglotTest {
7477

7578
@Test
76-
public void testWeakSimpleNode() {
77-
WeakSimpleNode node = WeakSimpleNodeGen.create();
78-
Object o = new String("");
79-
WeakReference<Object> ref = new WeakReference<>(o);
80-
node.execute(o);
81-
o = null;
82-
GCUtils.assertGc("Reference is not collected", ref);
79+
public void testWeakSimpleNode() throws IOException, InterruptedException {
80+
runInSubprocess(() -> {
81+
WeakSimpleNode node = WeakSimpleNodeGen.create();
82+
Object o = new String("");
83+
WeakReference<Object> ref = new WeakReference<>(o);
84+
node.execute(o);
85+
o = null;
86+
GCUtils.assertGc("Reference is not collected", ref);
87+
});
88+
}
89+
90+
private static void runInSubprocess(Runnable runnable) throws IOException, InterruptedException {
91+
if (ImageInfo.inImageCode()) {
92+
runnable.run();
93+
} else {
94+
SubprocessTestUtils.newBuilder(WeakCachedTest.class, runnable).run();
95+
}
8396
}
8497

8598
@GenerateUncached
@@ -96,26 +109,28 @@ Object s0(String arg,
96109
}
97110

98111
@Test
99-
public void testWeakInlineCache() {
100-
WeakInlineCacheNode node = WeakInlineCacheNodeGen.create();
101-
Object o0 = new String("");
102-
Object o1 = new String("");
103-
Object o2 = new String("");
104-
WeakReference<Object> ref0 = new WeakReference<>(o0);
105-
WeakReference<Object> ref1 = new WeakReference<>(o1);
106-
WeakReference<Object> ref2 = new WeakReference<>(o2);
107-
node.execute(o0);
108-
node.execute(o1);
109-
o0 = null;
110-
GCUtils.assertGc("Reference is not collected", ref0);
111-
112-
node.execute(o1);
113-
node.execute(o2);
114-
o1 = null;
115-
o2 = null;
116-
GCUtils.assertGc("Reference is not collected", List.of(ref1, ref2));
117-
118-
assertFails(() -> node.execute(new String("")), UnsupportedSpecializationException.class);
112+
public void testWeakInlineCache() throws IOException, InterruptedException {
113+
runInSubprocess(() -> {
114+
WeakInlineCacheNode node = WeakInlineCacheNodeGen.create();
115+
Object o0 = new String("");
116+
Object o1 = new String("");
117+
Object o2 = new String("");
118+
WeakReference<Object> ref0 = new WeakReference<>(o0);
119+
WeakReference<Object> ref1 = new WeakReference<>(o1);
120+
WeakReference<Object> ref2 = new WeakReference<>(o2);
121+
node.execute(o0);
122+
node.execute(o1);
123+
o0 = null;
124+
GCUtils.assertGc("Reference is not collected", ref0);
125+
126+
node.execute(o1);
127+
node.execute(o2);
128+
o1 = null;
129+
o2 = null;
130+
GCUtils.assertGc("Reference is not collected", List.of(ref1, ref2));
131+
132+
assertFails(() -> node.execute(new String("")), UnsupportedSpecializationException.class);
133+
});
119134
}
120135

121136
@GenerateUncached
@@ -133,26 +148,28 @@ Object s0(String arg,
133148
}
134149

135150
@Test
136-
public void testWeakCachedLibrary() {
137-
WeakCachedLibraryNode node = adoptNode(WeakCachedLibraryNodeGen.create()).get();
138-
Object o0 = new String("");
139-
Object o1 = new String("");
140-
Object o2 = new String("");
141-
WeakReference<Object> ref0 = new WeakReference<>(o0);
142-
WeakReference<Object> ref1 = new WeakReference<>(o1);
143-
WeakReference<Object> ref2 = new WeakReference<>(o2);
144-
node.execute(o0);
145-
node.execute(o1);
146-
o0 = null;
147-
GCUtils.assertGc("Reference is not collected", ref0);
148-
149-
node.execute(o1);
150-
node.execute(o2);
151-
o1 = null;
152-
o2 = null;
153-
GCUtils.assertGc("Reference is not collected", List.of(ref1, ref2));
154-
155-
assertFails(() -> node.execute(new String("")), UnsupportedSpecializationException.class);
151+
public void testWeakCachedLibrary() throws InterruptedException, IOException {
152+
runInSubprocess(() -> {
153+
WeakCachedLibraryNode node = adoptNode(WeakCachedLibraryNodeGen.create()).get();
154+
Object o0 = new String("");
155+
Object o1 = new String("");
156+
Object o2 = new String("");
157+
WeakReference<Object> ref0 = new WeakReference<>(o0);
158+
WeakReference<Object> ref1 = new WeakReference<>(o1);
159+
WeakReference<Object> ref2 = new WeakReference<>(o2);
160+
node.execute(o0);
161+
node.execute(o1);
162+
o0 = null;
163+
GCUtils.assertGc("Reference is not collected", ref0);
164+
165+
node.execute(o1);
166+
node.execute(o2);
167+
o1 = null;
168+
o2 = null;
169+
GCUtils.assertGc("Reference is not collected", List.of(ref1, ref2));
170+
171+
assertFails(() -> node.execute(new String("")), UnsupportedSpecializationException.class);
172+
});
156173
}
157174

158175
@GenerateUncached
@@ -181,14 +198,16 @@ Object s0replace(String arg) {
181198
}
182199

183200
@Test
184-
public void testWeakSharedNode() {
185-
WeakSharedCacheNode node = WeakSharedCacheNodeGen.create();
186-
Object o0 = new String("");
187-
WeakReference<Object> ref1 = new WeakReference<>(o0);
188-
node.execute(o0, false);
189-
o0 = null;
190-
GCUtils.assertGc("Reference is not collected", ref1);
191-
node.execute("", false);
201+
public void testWeakSharedNode() throws IOException, InterruptedException {
202+
runInSubprocess(() -> {
203+
WeakSharedCacheNode node = WeakSharedCacheNodeGen.create();
204+
Object o0 = new String("");
205+
WeakReference<Object> ref1 = new WeakReference<>(o0);
206+
node.execute(o0, false);
207+
o0 = null;
208+
GCUtils.assertGc("Reference is not collected", ref1);
209+
node.execute("", false);
210+
});
192211
}
193212

194213
@GenerateUncached
@@ -217,28 +236,33 @@ Object s1(String arg, boolean expectNull,
217236
* reference cannot get collected.
218237
*/
219238
@Test
220-
public void testConsistentGuardAndSpecialization() throws InterruptedException {
221-
ConsistentGuardAndSpecializationNode node = ConsistentGuardAndSpecializationNodeGen.create();
222-
Object o0 = new String("");
223-
WeakReference<Object> ref1 = new WeakReference<>(o0);
224-
node.execute(o0);
225-
Thread t = new Thread(new Runnable() {
226-
public void run() {
227-
node.locksEnabled = true;
228-
node.execute(new String(""));
239+
public void testConsistentGuardAndSpecialization() throws IOException, InterruptedException {
240+
runInSubprocess(() -> {
241+
ConsistentGuardAndSpecializationNode node = ConsistentGuardAndSpecializationNodeGen.create();
242+
Object o0 = new String("");
243+
WeakReference<Object> ref1 = new WeakReference<>(o0);
244+
node.execute(o0);
245+
Thread t = new Thread(new Runnable() {
246+
public void run() {
247+
node.locksEnabled = true;
248+
node.execute(new String(""));
249+
}
250+
});
251+
t.start();
252+
try {
253+
node.waitForGuard.acquire();
254+
o0 = null;
255+
try {
256+
GCUtils.assertNotGc("Reference is not collected", ref1);
257+
} finally {
258+
node.waitForSpecialization.release();
259+
t.join();
260+
}
261+
} catch (InterruptedException ie) {
262+
throw new AssertionError(ie);
229263
}
264+
GCUtils.assertGc("Reference is not collected", ref1);
230265
});
231-
t.start();
232-
node.waitForGuard.acquire();
233-
o0 = null;
234-
try {
235-
GCUtils.assertNotGc("Reference is not collected", ref1);
236-
} finally {
237-
node.waitForSpecialization.release();
238-
t.join();
239-
}
240-
GCUtils.assertGc("Reference is not collected", ref1);
241-
242266
}
243267

244268
@Test

0 commit comments

Comments
 (0)