Skip to content
Snippets Groups Projects
Commit c78f1949 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

dispose all debug handlers when an RContext is disposed

parent 5191e737
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,6 @@ import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.ExecutableNode;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
......@@ -82,7 +81,6 @@ import com.oracle.truffle.r.runtime.RSource;
import com.oracle.truffle.r.runtime.RType;
import com.oracle.truffle.r.runtime.ReturnException;
import com.oracle.truffle.r.runtime.RootWithBody;
import com.oracle.truffle.r.runtime.SubstituteVirtualFrame;
import com.oracle.truffle.r.runtime.ThreadTimings;
import com.oracle.truffle.r.runtime.Utils;
import com.oracle.truffle.r.runtime.Utils.DebugExitException;
......@@ -571,7 +569,6 @@ final class REngine implements Engine, Engine.Timings {
private static final class AnonymousRootNode extends RootNode implements RootWithBody {
private final ValueProfile frameTypeProfile = ValueProfile.createClassProfile();
private final ConditionProfile isVirtualFrameProfile = ConditionProfile.createBinaryProfile();
private final String description;
private final boolean printResult;
......@@ -602,14 +599,7 @@ final class REngine implements Engine, Engine.Timings {
}
private VirtualFrame prepareFrame(VirtualFrame frame) {
VirtualFrame vf;
MaterializedFrame originalFrame = (MaterializedFrame) frameTypeProfile.profile(frame.getArguments()[0]);
if (isVirtualFrameProfile.profile(originalFrame instanceof VirtualFrame)) {
vf = (VirtualFrame) originalFrame;
} else {
vf = SubstituteVirtualFrame.create(originalFrame);
}
return vf;
return (MaterializedFrame) frameTypeProfile.profile(frame.getArguments()[0]);
}
@Override
......
......@@ -42,6 +42,7 @@ import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.CyclicAssumption;
import com.oracle.truffle.r.nodes.builtin.helpers.BrowserInteractNodeGen;
import com.oracle.truffle.r.nodes.control.AbstractLoopNode;
import com.oracle.truffle.r.nodes.function.FunctionDefinitionNode;
import com.oracle.truffle.r.nodes.instrumentation.RInstrumentation;
......@@ -56,6 +57,7 @@ import com.oracle.truffle.r.runtime.conn.StdConnections;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.context.RContext.ConsoleIO;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.instrument.InstrumentationState;
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
import com.oracle.truffle.r.runtime.nodes.RSyntaxCall;
import com.oracle.truffle.r.runtime.nodes.RSyntaxConstant;
......@@ -140,17 +142,6 @@ public class DebugHandling {
return fser != null && (!fser.disabled() || fser.parentListener != null && !fser.parentListener.disabled());
}
/**
*
*/
public static void dispose() {
for (ExecutionEventListener l : RContext.getInstance().stateInstrumentation.getDebugListeners()) {
if (l instanceof DebugEventListener) {
((DebugEventListener) l).dispose();
}
}
}
private static FunctionStatementsEventListener getFunctionStatementsEventListener(RFunction func) {
return (FunctionStatementsEventListener) RContext.getInstance().stateInstrumentation.getDebugListener(RInstrumentation.getSourceSection(func));
}
......@@ -215,7 +206,7 @@ public class DebugHandling {
return fser;
}
private abstract static class DebugEventListener implements ExecutionEventListener {
private abstract static class DebugEventListener implements InstrumentationState.DisposableExecutionEventListener {
private EventBinding<? extends DebugEventListener> binding;
......@@ -260,6 +251,7 @@ public class DebugHandling {
this.binding = binding;
}
@Override
public void dispose() {
if (binding != null && !binding.isDisposed()) {
binding.dispose();
......
......@@ -182,6 +182,11 @@ public final class InstrumentationState implements RContext.ContextState {
void cleanup(int status);
}
public interface DisposableExecutionEventListener extends ExecutionEventListener {
void dispose();
}
private InstrumentationState(Instrumenter instrumenter) {
this.instrumenter = instrumenter;
}
......@@ -268,6 +273,15 @@ public final class InstrumentationState implements RContext.ContextState {
return debugGloballyDisabled;
}
@Override
public void beforeDispose(RContext context) {
for (ExecutionEventListener l : getDebugListeners()) {
if (l instanceof DisposableExecutionEventListener) {
((DisposableExecutionEventListener) l).dispose();
}
}
}
public static InstrumentationState newContextState(Instrumenter instrumenter) {
return new InstrumentationState(instrumenter);
}
......
......@@ -22,7 +22,6 @@
*/
package com.oracle.truffle.r.test.library.utils;
import com.oracle.truffle.r.nodes.builtin.helpers.DebugHandling;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
......@@ -32,8 +31,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import com.oracle.truffle.r.test.TestBase;
import org.junit.After;
import static com.oracle.truffle.r.test.generate.FastRSession.execInContext;
// Checkstyle: stop line length check
public class TestInteractiveDebug extends TestBase {
......@@ -47,19 +44,6 @@ public class TestInteractiveDebug extends TestBase {
Files.write(debugFile, content.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
@After
public void cleanupDebugListeners() {
try (org.graalvm.polyglot.Context context = org.graalvm.polyglot.Context.newBuilder("R", "llvm").build()) {
// a context has to be around when calling DebugHandling.dispose();
execInContext(context, () -> {
DebugHandling.dispose();
return null;
});
}
}
@Test
public void testSimple() {
assertEval("f <- function(x) {\n t <- x + 1\n print(t)\n t}\ndebug(f)\nf(5)\nx\nn\nn\nt\nn\nn");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment