Skip to content

Commit 63d47a1

Browse files
committed
Continuation capture always uses full liveness analysis.
1 parent 224156e commit 63d47a1

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,11 @@ public enum GuestFieldOffsetStrategyEnum {
703703
stability = OptionStability.EXPERIMENTAL, //
704704
usageSyntax = "false|true") public static final OptionKey<Boolean> EagerFrameAnalysis = new OptionKey<>(false);
705705

706-
/** Use a host property rather than an option. An option would slow interpreter considerably. */
706+
/**
707+
* Property used to force liveness analysis to also be applied by the interpreter. For testing
708+
* purpose only. Use a host property rather than an option. An option would slow interpreter
709+
* considerably.
710+
*/
707711
public static final boolean LivenessAnalysisInInterpreter = booleanProperty("espresso.liveness.interpreter", false);
708712

709713
// Properties for FinalizationSupport e.g. --vm.Despresso.finalization.UnsafeOverride=false .

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/analysis/frame/FrameAnalysis.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ public final class FrameAnalysis implements StackMapFrameParser.FrameBuilder<Bui
281281
boolean withStackMaps;
282282

283283
@TruffleBoundary
284-
public static EspressoFrameDescriptor apply(Method.MethodVersion m, int bci) {
284+
public static EspressoFrameDescriptor apply(Method.MethodVersion m, int bci, LivenessAnalysis la) {
285285
try {
286-
return new FrameAnalysis(bci, m).apply();
286+
return new FrameAnalysis(bci, m, la).apply();
287287
} catch (Exception e) {
288288
throw EspressoError.shouldNotReachHere(String.format("Failed suspension during frame analysis of method '%s'", m), e);
289289
}
@@ -301,9 +301,9 @@ public BytecodeStream stream() {
301301
return bs;
302302
}
303303

304-
private FrameAnalysis(int targetBci, Method.MethodVersion m) {
304+
private FrameAnalysis(int targetBci, Method.MethodVersion m, LivenessAnalysis la) {
305305
this.lang = m.getMethod().getLanguage();
306-
this.la = m.getLivenessAnalysis();
306+
this.la = la;
307307
this.bs = new BytecodeStream(m.getOriginalCode());
308308
this.targetBci = targetBci;
309309
this.states = new Builder[bs.endBCI()];

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/analysis/liveness/LivenessAnalysis.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3737
import com.oracle.truffle.api.frame.VirtualFrame;
3838
import com.oracle.truffle.espresso.EspressoLanguage;
39+
import com.oracle.truffle.espresso.EspressoOptions;
3940
import com.oracle.truffle.espresso.analysis.DepthFirstBlockIterator;
4041
import com.oracle.truffle.espresso.analysis.GraphBuilder;
4142
import com.oracle.truffle.espresso.analysis.Util;
@@ -46,6 +47,7 @@
4647
import com.oracle.truffle.espresso.analysis.liveness.actions.NullOutAction;
4748
import com.oracle.truffle.espresso.analysis.liveness.actions.SelectEdgeAction;
4849
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
50+
import com.oracle.truffle.espresso.impl.Klass;
4951
import com.oracle.truffle.espresso.impl.Method;
5052
import com.oracle.truffle.espresso.meta.EspressoError;
5153
import com.oracle.truffle.espresso.classfile.perf.DebugCloseable;
@@ -149,14 +151,15 @@ public boolean isEmpty() {
149151
}
150152

151153
@SuppressWarnings("try")
152-
public static LivenessAnalysis analyze(Method.MethodVersion methodVersion) {
154+
public static LivenessAnalysis analyze(EspressoOptions.LivenessAnalysisMode mode, Method.MethodVersion methodVersion) {
153155

154156
EspressoLanguage language = methodVersion.getMethod().getLanguage();
155-
if (!enableLivenessAnalysis(language, methodVersion)) {
157+
if (!enableLivenessAnalysis(mode, language, methodVersion)) {
156158
return NO_ANALYSIS;
157159
}
158160

159161
Method method = methodVersion.getMethod();
162+
160163
TimerCollection scope = method.getContext().getTimers();
161164
try (DebugCloseable liveness = LIVENESS_TIMER.scope(scope)) {
162165
Graph<? extends LinkedBlock> graph;
@@ -217,11 +220,11 @@ public static LivenessAnalysis analyze(Method.MethodVersion methodVersion) {
217220
}
218221
}
219222

220-
private static boolean enableLivenessAnalysis(EspressoLanguage language, Method.MethodVersion methodVersion) {
223+
private static boolean enableLivenessAnalysis(EspressoOptions.LivenessAnalysisMode mode, EspressoLanguage language, Method.MethodVersion methodVersion) {
221224
if (isExempt(methodVersion.getMethod())) {
222225
return false;
223226
}
224-
switch (language.getLivenessAnalysisMode()) {
227+
switch (mode) {
225228
case NONE:
226229
return false;
227230
case ALL:

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Method.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,11 +1300,17 @@ public StaticObject apply(int j) {
13001300
}
13011301

13021302
private static final class Continuum {
1303+
Continuum(LivenessAnalysis livenessAnalysis) {
1304+
this.livenessAnalysis = livenessAnalysis;
1305+
}
1306+
13031307
private record ContinuumData(int bci, CallTarget continuable, EspressoFrameDescriptor frameDescriptor) {
13041308
}
13051309

13061310
private static final ContinuumData[] EMPTY_DATA = new ContinuumData[0];
13071311

1312+
// Force Liveness Analysis for all method in a continuation frame record.
1313+
private final LivenessAnalysis livenessAnalysis;
13081314
@CompilationFinal(dimensions = 1) //
13091315
private volatile ContinuumData[] continuumData = EMPTY_DATA;
13101316

@@ -1326,7 +1332,7 @@ private ContinuumData getData(MethodVersion mv, int bci) {
13261332
}
13271333
int prevSize = continuumData.length;
13281334
localData = Arrays.copyOf(continuumData, prevSize + 1);
1329-
EspressoFrameDescriptor fd = FrameAnalysis.apply(mv, bci);
1335+
EspressoFrameDescriptor fd = FrameAnalysis.apply(mv, bci, livenessAnalysis);
13301336
CallTarget ct = EspressoRootNode.createContinuable(mv, bci, fd).getCallTarget();
13311337
ContinuumData data = new ContinuumData(bci, ct, fd);
13321338
localData[prevSize] = data;
@@ -1544,9 +1550,19 @@ public CallTarget getCallTarget() {
15441550
private Continuum getContinuum() {
15451551
if (continuum == null) {
15461552
CompilerDirectives.transferToInterpreterAndInvalidate();
1553+
// Compute LA out of lock.
1554+
LivenessAnalysis la = getLivenessAnalysis();
1555+
if (la.isEmpty()) {
1556+
/*
1557+
* Ensure we compute and use a full liveness analysis for all method in the
1558+
* continuation records, so that the frame capture prunes as much unneeded data
1559+
* as possible in order to make the records slimmer.
1560+
*/
1561+
la = LivenessAnalysis.analyze(EspressoOptions.LivenessAnalysisMode.ALL, this);
1562+
}
15471563
synchronized (this) {
15481564
if (continuum == null) {
1549-
Continuum c = new Continuum();
1565+
Continuum c = new Continuum(la);
15501566
VarHandle.releaseFence();
15511567
continuum = c;
15521568
}
@@ -1920,7 +1936,7 @@ public LivenessAnalysis getLivenessAnalysis() {
19201936
synchronized (this) {
19211937
result = this.livenessAnalysis;
19221938
if (result == null) {
1923-
this.livenessAnalysis = result = LivenessAnalysis.analyze(this);
1939+
this.livenessAnalysis = result = LivenessAnalysis.analyze(getLanguage().getLivenessAnalysisMode(), this);
19241940
}
19251941
}
19261942
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/ObjectKlass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ private static void eagerFrameAnalysis(Method m) {
766766
int nextBci = 0;
767767
while (nextBci < bs.endBCI()) {
768768
if (Bytecodes.isInvoke(bs.opcode(nextBci))) {
769-
FrameAnalysis.apply(m.getMethodVersion(), nextBci);
769+
FrameAnalysis.apply(m.getMethodVersion(), nextBci, m.getMethodVersion().getLivenessAnalysis());
770770
}
771771
nextBci = bs.nextBCI(nextBci);
772772
}

0 commit comments

Comments
 (0)