Skip to content

Commit 16673af

Browse files
committed
Truffle tests flood the output.
1 parent 6076f9d commit 16673af

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

truffle/mx.truffle/mx_truffle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ def apply(self, config):
321321

322322
# Disable VirtualThread warning
323323
vmArgs = vmArgs + ['-Dpolyglot.engine.WarnVirtualThreadSupport=false']
324+
# Print only a single close on context collected error
325+
vmArgs = vmArgs + ['-Dpolyglot.engine.CloseOnGCFailureAction=PrintOnce']
324326
enable_truffle_native_access(vmArgs)
325327
enable_sun_misc_unsafe(vmArgs)
326328
return (vmArgs, mainClass, mainClassArgs)

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineImpl.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,25 +2445,35 @@ static void logCloseOnCollectedError(PolyglotEngineImpl engine, String reason, T
24452445
switch (engine.getEngineOptionValues().get(PolyglotEngineOptions.CloseOnGCFailureAction)) {
24462446
case Ignore -> {
24472447
}
2448-
case Print -> {
2449-
StringWriter message = new StringWriter();
2450-
try (PrintWriter errWriter = new PrintWriter(message)) {
2451-
errWriter.printf("""
2452-
[engine] WARNING: %s
2453-
To customize the behavior of this warning, use 'engine.CloseOnGCFailureAction' option or the 'polyglot.engine.CloseOnGCFailureAction' system property.
2454-
The accepted values are:
2455-
- Ignore: Do not print this warning.
2456-
- Print: Print this warning (default value).
2457-
- Throw: Throw an exception instead of printing this warning.
2458-
""", reason);
2459-
exception.printStackTrace(errWriter);
2448+
case PrintOnce -> {
2449+
if (closeOnCollectedErrorLogged.compareAndSet(false, true)) {
2450+
logCloseOnCollectedError(reason, exception);
24602451
}
2461-
logFallback(message.toString());
24622452
}
2453+
case Print -> logCloseOnCollectedError(reason, exception);
24632454
case Throw -> throw new RuntimeException(reason, exception);
24642455
}
24652456
}
24662457

2458+
private static final AtomicBoolean closeOnCollectedErrorLogged = new AtomicBoolean();
2459+
2460+
private static void logCloseOnCollectedError(String reason, Throwable exception) {
2461+
StringWriter message = new StringWriter();
2462+
try (PrintWriter errWriter = new PrintWriter(message)) {
2463+
errWriter.printf("""
2464+
[engine] WARNING: %s
2465+
To customize the behavior of this warning, use 'engine.CloseOnGCFailureAction' option or the 'polyglot.engine.CloseOnGCFailureAction' system property.
2466+
The accepted values are:
2467+
- Ignore: Do not print this warning.
2468+
- PrintOnce: Print this warning only for the first occurrence; suppress subsequent ones.
2469+
- Print: Print this warning (default value).
2470+
- Throw: Throw an exception instead of printing this warning.
2471+
""", reason);
2472+
exception.printStackTrace(errWriter);
2473+
}
2474+
logFallback(message.toString());
2475+
}
2476+
24672477
static final class StableLocalLocations {
24682478

24692479
@CompilationFinal(dimensions = 1) final LocalLocation[] locations;

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,15 @@ public StaticObjectStorageStrategies apply(String s) {
191191

192192
enum CloseOnGCExceptionAction {
193193
Ignore,
194+
PrintOnce,
194195
Print,
195196
Throw;
196197

197-
private static final String HELP = "Specifies the action to take when closing a garbage collected engine or context fails.%n" +
198+
private static final String HELP = "Specifies the action to take when closing a garbage-collected engine or context fails.%n" +
198199
"The accepted values are:%n" +
199-
" Ignore: Do not print this warning.%n" +
200-
" Print: Print this warning (default value).%n" +
201-
" Throw: Throw an exception instead of printing this warning.";
200+
" Ignore: Ignore the exception that occurs during close.%n" +
201+
" PrintOnce: Log the failure only for the first occurrence; suppress subsequent ones.%n" +
202+
" Print: Log each failure (default value).%n" +
203+
" Throw: Throw an exception instead of logging the failure.";
202204
}
203205
}

0 commit comments

Comments
 (0)