Skip to content

Commit 65786d6

Browse files
committed
[GR-64154] Prevent pointless stack walking during LogRecord marshalling.
PullRequest: graal/20524
2 parents 4872b8b + 83fde28 commit 65786d6

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ public abstract <T, G> Iterator<T> mergeHostGuestFrames(Object polyglotEngine, S
762762

763763
public abstract String getFormatKind(LogRecord logRecord);
764764

765+
public abstract boolean isLogRecordCallerClassSet(LogRecord logRecord);
766+
767+
public abstract boolean isLogRecordCallerMethodSet(LogRecord logRecord);
768+
769+
public abstract void logFallback(String s);
770+
765771
public abstract boolean isCurrentThreadPolyglotThread();
766772

767773
public abstract Object getHostNull();

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,21 @@ public String getFormatKind(LogRecord logRecord) {
20232023
return PolyglotLoggers.getFormatKind(logRecord);
20242024
}
20252025

2026+
@Override
2027+
public boolean isLogRecordCallerClassSet(LogRecord logRecord) {
2028+
return PolyglotLoggers.isCallerClassSet(logRecord);
2029+
}
2030+
2031+
@Override
2032+
public boolean isLogRecordCallerMethodSet(LogRecord logRecord) {
2033+
return PolyglotLoggers.isCallerMethodSet(logRecord);
2034+
}
2035+
2036+
@Override
2037+
public void logFallback(String s) {
2038+
PolyglotEngineImpl.logFallback(s);
2039+
}
2040+
20262041
@Override
20272042
public boolean isCurrentThreadPolyglotThread() {
20282043
PolyglotThreadInfo info = PolyglotFastThreadLocals.getCurrentThread(null);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ or use the default runtime (no JIT compilation of polyglot code) by passing -Dtr
25162516
*/
25172517
static void logFallback(String message) {
25182518
PrintStream err = System.err;
2519-
err.println(message);
2519+
err.print(message);
25202520
}
25212521

25222522
private static class MessageTransportProxy implements MessageTransport {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ static String getFormatKind(LogRecord logRecord) {
187187
return (logRecord instanceof ImmutableLogRecord ? ((ImmutableLogRecord) logRecord).getFormatKind() : ImmutableLogRecord.FormatKind.DEFAULT).name();
188188
}
189189

190+
static boolean isCallerClassSet(LogRecord logRecord) {
191+
return logRecord instanceof ImmutableLogRecord && ((ImmutableLogRecord) logRecord).isCallerClassSet();
192+
}
193+
194+
static boolean isCallerMethodSet(LogRecord logRecord) {
195+
return logRecord instanceof ImmutableLogRecord && ((ImmutableLogRecord) logRecord).isCallerMethodSet();
196+
}
197+
190198
static final class LoggerCache {
191199

192200
static final LoggerCache DEFAULT = new LoggerCache(PolyglotLogHandler.INSTANCE, true, null, Collections.emptySet());
@@ -646,6 +654,8 @@ private static final class ImmutableLogRecord extends LogRecord {
646654

647655
private static final long serialVersionUID = 1L;
648656
private final FormatKind formatKind;
657+
private final boolean isCallerClassSet;
658+
private final boolean isCallerMethodSet;
649659

650660
enum FormatKind {
651661
RAW,
@@ -659,9 +669,15 @@ enum FormatKind {
659669
super.setLoggerName(loggerName);
660670
if (className != null) {
661671
super.setSourceClassName(className);
672+
this.isCallerClassSet = true;
673+
} else {
674+
this.isCallerClassSet = false;
662675
}
663676
if (methodName != null) {
664677
super.setSourceMethodName(methodName);
678+
this.isCallerMethodSet = true;
679+
} else {
680+
this.isCallerMethodSet = false;
665681
}
666682
Object[] copy = parameters;
667683
if (parameters != null && parameters.length > 0) {
@@ -741,6 +757,14 @@ FormatKind getFormatKind() {
741757
return formatKind;
742758
}
743759

760+
boolean isCallerClassSet() {
761+
return isCallerClassSet;
762+
}
763+
764+
public boolean isCallerMethodSet() {
765+
return isCallerMethodSet;
766+
}
767+
744768
private static Object safeValue(final Object param) {
745769
if (param == null || EngineAccessor.EngineImpl.isPrimitive(param)) {
746770
return param;

0 commit comments

Comments
 (0)