Skip to content

Commit 9b92f37

Browse files
Espresso: Add MaxJavaStackTraceDepth option
1 parent 6bb56df commit 9b92f37

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public final class EspressoLanguage extends TruffleLanguage<EspressoContext> imp
147147
@CompilationFinal private boolean useEspressoLibs;
148148
@CompilationFinal private boolean continuum;
149149
@CompilationFinal private boolean useTRegex;
150+
@CompilationFinal private int maxStackTraceDepth;
150151
// endregion Options
151152

152153
// region Allocation
@@ -246,6 +247,7 @@ private void initializeOptions(final TruffleLanguage.Env env) {
246247
whiteBoxEnabled = env.getOptions().get(EspressoOptions.WhiteBoxAPI);
247248
internalJvmciEnabled = env.getOptions().get(EspressoOptions.EnableJVMCI);
248249
continuum = env.getOptions().get(EspressoOptions.Continuum);
250+
maxStackTraceDepth = env.getOptions().get(EspressoOptions.MaxJavaStackTraceDepth);
249251

250252
useTRegex = env.getOptions().get(EspressoOptions.UseTRegex);
251253
if (useTRegex && !env.getInternalLanguages().containsKey("regex")) {
@@ -351,7 +353,8 @@ protected boolean areOptionsCompatible(OptionValues oldOptions, OptionValues new
351353
isOptionCompatible(newOptions, oldOptions, EspressoOptions.Continuum) &&
352354
isOptionCompatible(newOptions, oldOptions, EspressoOptions.UseTRegex) &&
353355
isOptionCompatible(newOptions, oldOptions, EspressoOptions.GuestFieldOffsetStrategy) &&
354-
isOptionCompatible(newOptions, oldOptions, EspressoOptions.UseEspressoLibs);
356+
isOptionCompatible(newOptions, oldOptions, EspressoOptions.UseEspressoLibs) &&
357+
isOptionCompatible(newOptions, oldOptions, EspressoOptions.MaxJavaStackTraceDepth);
355358
}
356359

357360
private static boolean isOptionCompatible(OptionValues oldOptions, OptionValues newOptions, OptionKey<?> option) {
@@ -748,6 +751,10 @@ public DisableSingleStepping disableStepping() {
748751
return new DisableSingleStepping();
749752
}
750753

754+
public int getMaxStackTraceDepth() {
755+
return maxStackTraceDepth;
756+
}
757+
751758
public final class DisableSingleStepping implements AutoCloseable {
752759

753760
private final boolean steppingDisabled;

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,13 @@ public enum MemoryAccessOption {
769769
usageSyntax = "false|true") //
770770
public static final OptionKey<Boolean> EnableAdvancedRedefinition = new OptionKey<>(false);
771771

772+
@Option(help = "The maximum number of lines in the stack trace for Java exceptions", //
773+
category = OptionCategory.EXPERT, //
774+
stability = OptionStability.EXPERIMENTAL, //
775+
usageSyntax = "<depth>>") //
776+
// HotSpot's MaxJavaStackTraceDepth is 1024 by default
777+
public static final OptionKey<Integer> MaxJavaStackTraceDepth = new OptionKey<>(32);
778+
772779
/**
773780
* Property used to force liveness analysis to also be applied by the interpreter. For testing
774781
* purpose only. Use a host property rather than an option. An option would slow interpreter

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/EspressoContext.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@
129129

130130
import sun.misc.SignalHandler;
131131

132-
public final class EspressoContext
133-
implements RuntimeAccess<Klass, Method, Field> {
134-
// MaxJavaStackTraceDepth is 1024 by default
135-
public static final int DEFAULT_STACK_SIZE = 32;
132+
public final class EspressoContext implements RuntimeAccess<Klass, Method, Field> {
136133

137134
private static final DebugTimer SPAWN_VM = DebugTimer.create("spawnVM");
138135
private static final DebugTimer SYSTEM_INIT = DebugTimer.create("system init", SPAWN_VM);

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/vm/InterpreterToVM.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ public static StaticObject fillInStackTraceLazy(@JavaType(Throwable.class) Stati
614614

615615
// Recursion depth = 4
616616
public static StaticObject fillInStackTrace(@JavaType(Throwable.class) StaticObject throwable, Meta meta) {
617-
VM.StackTrace frames = getStackTrace(new FillInStackTraceFramesFilter(), EspressoContext.DEFAULT_STACK_SIZE);
617+
int maxDepth = meta.getLanguage().getMaxStackTraceDepth();
618+
VM.StackTrace frames = getStackTrace(new FillInStackTraceFramesFilter(), maxDepth);
618619
meta.HIDDEN_FRAMES.setHiddenObject(throwable, frames);
619620
meta.java_lang_Throwable_backtrace.setObject(throwable, throwable);
620621
if (meta.getJavaVersion().java9OrLater()) {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/vm/VM.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import static com.oracle.truffle.espresso.jni.JniEnv.JNI_OK;
3333
import static com.oracle.truffle.espresso.meta.EspressoError.cat;
3434
import static com.oracle.truffle.espresso.runtime.Classpath.JAVA_BASE;
35-
import static com.oracle.truffle.espresso.runtime.EspressoContext.DEFAULT_STACK_SIZE;
3635
import static com.oracle.truffle.espresso.substitutions.standard.Target_java_lang_invoke_MethodHandleNatives.Constants.ACCESS_VM_ANNOTATIONS;
3736
import static com.oracle.truffle.espresso.substitutions.standard.Target_java_lang_invoke_MethodHandleNatives.Constants.HIDDEN_CLASS;
3837
import static com.oracle.truffle.espresso.substitutions.standard.Target_java_lang_invoke_MethodHandleNatives.Constants.NESTMATE_CLASS;
@@ -1784,7 +1783,7 @@ public static class StackTrace {
17841783
private boolean hiddenTop;
17851784

17861785
public StackTrace() {
1787-
this(DEFAULT_STACK_SIZE);
1786+
this(32);
17881787
}
17891788

17901789
private StackTrace(int size) {

0 commit comments

Comments
 (0)