Skip to content

Commit 6de9622

Browse files
committed
[GR-67613] Transient IllegalArgumentException: Unknown language or instrument id com_oracle_truffle_api_test_polyglot_polyglotgctest_valuegclanguage.
PullRequest: graal/22406
2 parents f8888aa + ca90c11 commit 6de9622

File tree

6 files changed

+61
-27
lines changed

6 files changed

+61
-27
lines changed

sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
99
* GR-66817 Make `--polyglot` the default for language launchers, so there is no need to specify it anymore to use other languages in standalones. As a result, `AbstractLanguageLauncher#getDefaultLanguages()` and `Launcher#canPolyglot()` have been deprecated.
1010
* GR-65404 Remove `PolyglotLauncher` as it is no longer used.
1111
* GR-68613: JavaScript polyglot isolate now includes support for the WebAssembly (Wasm) language.
12+
* GR-69590: Closing a garbage-collected engine or context now logs only the first failure by default. To log all failures, use `engine.CloseOnGCFailureAction.PrintAll`.
1213

1314
## Version 25.0.0
1415
* GR-60636 Truffle now stops compiling when the code cache fills up on HotSpot. A warning is printed when that happens.

truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,8 @@ private TruffleLogger getOrCreateLogger(final String loggerName) {
10461046
}
10471047

10481048
private TruffleLogger getOrCreateLogger(final String id, final String loggerName) {
1049-
if (!LanguageAccessor.ENGINE.isKnownLoggerId(id)) {
1050-
throw new IllegalArgumentException("Unknown language or instrument id " + id + ", known ids: " + String.join(", ", LanguageAccessor.ENGINE.getKnownLoggerIds()));
1049+
if (!LanguageAccessor.ENGINE.isKnownLoggerId(loggerCache, id)) {
1050+
throw new IllegalArgumentException("Unknown language or instrument id " + id + ", known ids: " + String.join(", ", LanguageAccessor.ENGINE.getKnownLoggerIds(loggerCache)));
10511051
}
10521052
final String globalLoggerId = loggerName == null || loggerName.isEmpty() ? id : id + '.' + loggerName;
10531053
return getOrCreateLogger(globalLoggerId);

truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ public abstract Thread createThread(Object polyglotLanguageContext, Runnable run
554554

555555
public abstract LogRecord createLogRecord(Object loggerCache, Level level, String loggerName, String message, String className, String methodName, Object[] parameters, Throwable thrown);
556556

557-
public abstract boolean isKnownLoggerId(String id);
557+
public abstract boolean isKnownLoggerId(Object loggerCache, String id);
558558

559-
public abstract Collection<String> getKnownLoggerIds();
559+
public abstract Collection<String> getKnownLoggerIds(Object loggerCache);
560560

561561
public abstract boolean isContextBoundLogger(Object loggerCache);
562562

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,16 +1435,37 @@ public LogRecord createLogRecord(Object loggerCache, Level level, String loggerN
14351435
}
14361436

14371437
@Override
1438-
public boolean isKnownLoggerId(String id) {
1439-
return PolyglotLoggers.getInternalIds().contains(id) || LanguageCache.languages().containsKey(id) || InstrumentCache.load().containsKey(id);
1438+
public boolean isKnownLoggerId(Object loggerCache, String id) {
1439+
if (PolyglotLoggers.getInternalIds().contains(id)) {
1440+
return true;
1441+
}
1442+
if (loggerCache == PolyglotLoggers.LoggerCache.DEFAULT) {
1443+
/*
1444+
* TruffleLogger#getLogger() is invoked from a static initializer, no vmObject
1445+
* anchor is available at this point.
1446+
*/
1447+
return LanguageCache.languages().containsKey(id) || InstrumentCache.load().containsKey(id);
1448+
} else {
1449+
PolyglotEngineImpl polyglotEngine = ((PolyglotLoggers.LoggerCache) loggerCache).getOwner().getEngine();
1450+
return polyglotEngine.idToLanguage.containsKey(id) || polyglotEngine.idToInstrument.containsKey(id);
1451+
}
14401452
}
14411453

14421454
@Override
1443-
public Collection<String> getKnownLoggerIds() {
1444-
List<String> ids = new ArrayList<>();
1445-
ids.addAll(PolyglotLoggers.getInternalIds());
1446-
ids.addAll(LanguageCache.languages().keySet());
1447-
ids.addAll(InstrumentCache.load().keySet());
1455+
public Collection<String> getKnownLoggerIds(Object loggerCache) {
1456+
List<String> ids = new ArrayList<>(PolyglotLoggers.getInternalIds());
1457+
if (loggerCache == PolyglotLoggers.LoggerCache.DEFAULT) {
1458+
/*
1459+
* TruffleLogger#getLogger() is invoked from a static initializer, no vmObject
1460+
* anchor is available at this point.
1461+
*/
1462+
ids.addAll(LanguageCache.languages().keySet());
1463+
ids.addAll(InstrumentCache.load().keySet());
1464+
} else {
1465+
PolyglotEngineImpl polyglotEngine = ((PolyglotLoggers.LoggerCache) loggerCache).getOwner().getEngine();
1466+
ids.addAll(polyglotEngine.idToLanguage.keySet());
1467+
ids.addAll(polyglotEngine.idToInstrument.keySet());
1468+
}
14481469
Collections.sort(ids);
14491470
return ids;
14501471
}

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,24 +2447,34 @@ static void logCloseOnCollectedError(PolyglotEngineImpl engine, String reason, T
24472447
case Ignore -> {
24482448
}
24492449
case Print -> {
2450-
StringWriter message = new StringWriter();
2451-
try (PrintWriter errWriter = new PrintWriter(message)) {
2452-
errWriter.printf("""
2453-
[engine] WARNING: %s
2454-
To customize the behavior of this warning, use 'engine.CloseOnGCFailureAction' option or the 'polyglot.engine.CloseOnGCFailureAction' system property.
2455-
The accepted values are:
2456-
- Ignore: Do not print this warning.
2457-
- Print: Print this warning (default value).
2458-
- Throw: Throw an exception instead of printing this warning.
2459-
""", reason);
2460-
exception.printStackTrace(errWriter);
2450+
if (closeOnCollectedErrorLogged.compareAndSet(false, true)) {
2451+
logCloseOnCollectedError(reason, exception);
24612452
}
2462-
logFallback(message.toString());
24632453
}
2454+
case PrintAll -> logCloseOnCollectedError(reason, exception);
24642455
case Throw -> throw new RuntimeException(reason, exception);
24652456
}
24662457
}
24672458

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

24702480
@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
@@ -192,12 +192,14 @@ public StaticObjectStorageStrategies apply(String s) {
192192
enum CloseOnGCExceptionAction {
193193
Ignore,
194194
Print,
195+
PrintAll,
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+
" Print: Log the failure only for the first occurrence; suppress subsequent ones (default value).%n" +
202+
" PrintAll: Log each failure.%n" +
203+
" Throw: Throw an exception instead of logging the failure.";
202204
}
203205
}

0 commit comments

Comments
 (0)