Skip to content

Commit

Permalink
[GR-38326] Cannot store Auxiliary Engine Cache and use --log.file a…
Browse files Browse the repository at this point in the history
…t the same time.

PullRequest: graal/16600
  • Loading branch information
tzezula committed Jan 31, 2024
2 parents b7711d9 + cc9669a commit f105a80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,12 @@ void finalizeStore() {
this.out = null;
this.err = null;
this.in = null;
this.logHandler = null;
/*
* Note: The 'logHandler' field must not be cleaned until the image persists to facilitate
* the detection and cleanup of all references to the 'logHandler' instance in the image
* heap. The cleanup process is handled by the 'AuxiliaryImageObjectReplacer' registered in
* the 'AuxiliaryEngineCacheSupport'.
*/
AbstractHostLanguageService hostLanguageService = this.host;
if (hostLanguageService != null) {
hostLanguageService.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ static LogHandler asLogHandler(Object logHandlerOrStream) {
/**
* Creates a default {@link Handler} for an engine when a {@link Handler} was not specified.
*
* @param polyglot the polyglot owning the handler
* @param out the {@link OutputStream} to print log messages into
* @param sandboxPolicy the engine's sandbox policy
*/
Expand Down Expand Up @@ -230,7 +229,7 @@ void setOwner(VMObject owner) {
}

static LoggerCache newEngineLoggerCache(PolyglotEngineImpl engine) {
return newEngineLoggerCache(new PolyglotLogHandler(engine.logHandler), engine.logLevels, true, Collections.emptySet());
return newEngineLoggerCache(new PolyglotLogHandler(engine), engine.logLevels, true, Collections.emptySet());
}

static LoggerCache newEngineLoggerCache(LogHandler handler, Map<String, Level> logLevels, boolean useCurrentContext,
Expand Down Expand Up @@ -554,21 +553,22 @@ private static final class PolyglotLogHandler extends LogHandler {

private static final LogHandler INSTANCE = new PolyglotLogHandler();

private final LogHandler fallBackHandler;
private final WeakReference<PolyglotEngineImpl> engineRef;

PolyglotLogHandler() {
this.fallBackHandler = null;
this.engineRef = null;
}

PolyglotLogHandler(LogHandler fallbackHandler) {
this.fallBackHandler = fallbackHandler;
PolyglotLogHandler(PolyglotEngineImpl engine) {
this.engineRef = new WeakReference<>(engine);
}

@Override
public void publish(final LogRecord record) {
LogHandler handler = findDelegate();
if (handler == null) {
handler = fallBackHandler;
PolyglotEngineImpl engine = engineRef != null ? engineRef.get() : null;
handler = engine != null ? engine.logHandler : null;
}
if (handler != null) {
handler.publish(record);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public Object getEngineLock() {
return OptimizedRuntimeAccessor.ENGINE.getEngineLock(this.polyglotEngine);
}

public Object getEngineLogHandler() {
return OptimizedRuntimeAccessor.ENGINE.getEngineLogHandler(this.polyglotEngine);
}

@SuppressWarnings("unchecked")
public <T> T getEngineLocal(Class<T> symbol) {
Map<Class<?>, Object> data = this.engineLocals;
Expand Down

0 comments on commit f105a80

Please sign in to comment.